Changeset View
Changeset View
Standalone View
Standalone View
libs/ui/tool/strokes/kis_color_picker_stroke_strategy.cpp
Show All 12 Lines | |||||
13 | * | 13 | * | ||
14 | * You should have received a copy of the GNU General Public License | 14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | #include "kis_color_picker_stroke_strategy.h" | 19 | #include "kis_color_picker_stroke_strategy.h" | ||
20 | 20 | | |||
21 | #include <KoColor.h> | | |||
22 | | ||||
23 | | ||||
24 | #include "kis_debug.h" | | |||
25 | #include "kis_tool_utils.h" | 21 | #include "kis_tool_utils.h" | ||
26 | #include <kis_wrapped_rect.h> | | |||
27 | #include "kis_default_bounds.h" | | |||
28 | #include "kis_paint_device.h" | 22 | #include "kis_paint_device.h" | ||
29 | 23 | | |||
30 | | ||||
31 | struct KisColorPickerStrokeStrategy::Private | 24 | struct KisColorPickerStrokeStrategy::Private | ||
32 | { | 25 | { | ||
33 | Private() : shouldSkipWork(false) {} | 26 | Private() : shouldSkipWork(false) {} | ||
34 | 27 | | |||
35 | bool shouldSkipWork; | 28 | bool shouldSkipWork; | ||
36 | int radius = 1; | 29 | int radius = 1; | ||
30 | int blend = 100; | ||||
37 | }; | 31 | }; | ||
38 | 32 | | |||
39 | KisColorPickerStrokeStrategy::KisColorPickerStrokeStrategy(int lod) | 33 | KisColorPickerStrokeStrategy::KisColorPickerStrokeStrategy(int lod) | ||
40 | : m_d(new Private) | 34 | : m_d(new Private) | ||
41 | { | 35 | { | ||
42 | setSupportsWrapAroundMode(true); | 36 | setSupportsWrapAroundMode(true); | ||
43 | enableJob(KisSimpleStrokeStrategy::JOB_DOSTROKE); | 37 | enableJob(KisSimpleStrokeStrategy::JOB_DOSTROKE); | ||
44 | 38 | | |||
45 | KisToolUtils::ColorPickerConfig config; | 39 | KisToolUtils::ColorPickerConfig config; | ||
46 | config.load(); | 40 | config.load(); | ||
47 | 41 | | |||
48 | m_d->radius = qMax(1, qRound(config.radius * KisLodTransform::lodToScale(lod))); | 42 | m_d->radius = qMax(1, qRound(config.radius * KisLodTransform::lodToScale(lod))); | ||
43 | m_d->blend = config.blend; | ||||
49 | } | 44 | } | ||
50 | 45 | | |||
51 | KisColorPickerStrokeStrategy::~KisColorPickerStrokeStrategy() | 46 | KisColorPickerStrokeStrategy::~KisColorPickerStrokeStrategy() | ||
52 | { | 47 | { | ||
53 | } | 48 | } | ||
54 | 49 | | |||
55 | void KisColorPickerStrokeStrategy::doStrokeCallback(KisStrokeJobData *data) | 50 | void KisColorPickerStrokeStrategy::doStrokeCallback(KisStrokeJobData *data) | ||
56 | { | 51 | { | ||
57 | if (m_d->shouldSkipWork) return; | 52 | if (m_d->shouldSkipWork) return; | ||
58 | 53 | | |||
59 | Data *d = dynamic_cast<Data*>(data); | 54 | Data *d = dynamic_cast<Data*>(data); | ||
60 | KIS_ASSERT_RECOVER_RETURN(d); | 55 | KIS_ASSERT_RECOVER_RETURN(d); | ||
61 | 56 | | |||
62 | KoColor color; | 57 | KoColor color; | ||
63 | bool result = KisToolUtils::pick(d->dev, d->pt, &color, m_d->radius); | 58 | KoColor previous = d->currentColor; | ||
59 | bool result = KisToolUtils::pick(d->dev, d->pt, &color, &previous, m_d->radius, m_d->blend); | ||||
64 | Q_UNUSED(result); | 60 | Q_UNUSED(result); | ||
65 | 61 | | |||
66 | emit sigColorUpdated(color); | 62 | emit sigColorUpdated(color); | ||
67 | } | 63 | } | ||
68 | 64 | | |||
69 | KisStrokeStrategy* KisColorPickerStrokeStrategy::createLodClone(int levelOfDetail) | 65 | KisStrokeStrategy* KisColorPickerStrokeStrategy::createLodClone(int levelOfDetail) | ||
70 | { | 66 | { | ||
71 | m_d->shouldSkipWork = true; | 67 | m_d->shouldSkipWork = true; | ||
72 | 68 | | |||
73 | KisColorPickerStrokeStrategy *lodStrategy = new KisColorPickerStrokeStrategy(levelOfDetail); | 69 | KisColorPickerStrokeStrategy *lodStrategy = new KisColorPickerStrokeStrategy(levelOfDetail); | ||
74 | connect(lodStrategy, &KisColorPickerStrokeStrategy::sigColorUpdated, | 70 | connect(lodStrategy, &KisColorPickerStrokeStrategy::sigColorUpdated, | ||
75 | this, &KisColorPickerStrokeStrategy::sigColorUpdated, | 71 | this, &KisColorPickerStrokeStrategy::sigColorUpdated, | ||
76 | Qt::DirectConnection); | 72 | Qt::DirectConnection); | ||
77 | return lodStrategy; | 73 | return lodStrategy; | ||
78 | } | 74 | } | ||
79 | |