Krita Source Code Documentation
Loading...
Searching...
No Matches
WGCommonColorSet Class Reference

#include <WGCommonColorSet.h>

+ Inheritance diagram for WGCommonColorSet:

Public Slots

void slotUpdateColors ()
 
- Public Slots inherited from KisUniqueColorSet
void clear ()
 

Signals

void sigIdle (bool isIdle)
 
- Signals inherited from KisUniqueColorSet
void sigColorAdded (int position)
 
void sigColorMoved (int from, int to)
 
void sigColorRemoved (int position)
 
void sigReset ()
 

Public Member Functions

void setAutoUpdate (bool enabled)
 
void setColorCount (int count)
 
void setImage (KisImageSP image)
 
 WGCommonColorSet (QObject *parent=0)
 
- Public Member Functions inherited from KisUniqueColorSet
void addColor (const KoColor &color)
 
KoColor color (int index) const
 
 KisUniqueColorSet (QObject *parent=nullptr)
 
int size () const
 
 ~KisUniqueColorSet () override
 

Private Slots

void slotCalculationDone ()
 

Private Attributes

bool m_autoUpdate {false}
 
QSharedPointer< QVector< KoColor > > m_commonColors
 
bool m_idle {true}
 
KisImageSP m_image
 
int m_numColors {10}
 
QTimer m_updateTimer
 

Detailed Description

Definition at line 16 of file WGCommonColorSet.h.

Constructor & Destructor Documentation

◆ WGCommonColorSet()

WGCommonColorSet::WGCommonColorSet ( QObject * parent = 0)
explicit

Definition at line 12 of file WGCommonColorSet.cpp.

13 : KisUniqueColorSet(parent)
15{
16 m_updateTimer.setInterval(2000);
17 m_updateTimer.setSingleShot(true);
18 connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(slotUpdateColors()));
19}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisUniqueColorSet(QObject *parent=nullptr)
QSharedPointer< QVector< KoColor > > m_commonColors

References connect(), m_updateTimer, and slotUpdateColors().

Member Function Documentation

◆ setAutoUpdate()

void WGCommonColorSet::setAutoUpdate ( bool enabled)

Definition at line 35 of file WGCommonColorSet.cpp.

36{
37 if (enabled == m_autoUpdate) {
38 return;
39 }
40
41 m_autoUpdate = enabled;
42
43 if (m_image) {
44 if (enabled) {
45 connect(m_image, SIGNAL(sigImageUpdated(QRect)), &m_updateTimer, SLOT(start()), Qt::UniqueConnection);
46 }
47 else {
48 disconnect(m_image, SIGNAL(sigImageUpdated(QRect)), &m_updateTimer, SLOT(start()));
49 }
50 }
51}

References connect(), m_autoUpdate, m_image, and m_updateTimer.

◆ setColorCount()

void WGCommonColorSet::setColorCount ( int count)
inline

Definition at line 23 of file WGCommonColorSet.h.

23{ m_numColors = count; }

References m_numColors.

◆ setImage()

void WGCommonColorSet::setImage ( KisImageSP image)

Definition at line 21 of file WGCommonColorSet.cpp.

22{
23 if (m_autoUpdate) {
24 if (m_image) {
25 disconnect(m_image, SIGNAL(sigImageUpdated(QRect)), &m_updateTimer, SLOT(start()));
26 }
27 if (image) {
28 connect(image, SIGNAL(sigImageUpdated(QRect)), &m_updateTimer, SLOT(start()), Qt::UniqueConnection);
29 m_updateTimer.start();
30 }
31 }
32 m_image = image;
33}

References connect(), m_autoUpdate, m_image, and m_updateTimer.

◆ sigIdle

void WGCommonColorSet::sigIdle ( bool isIdle)
signal

◆ slotCalculationDone

void WGCommonColorSet::slotCalculationDone ( )
privateslot

Definition at line 74 of file WGCommonColorSet.cpp.

75{
76 blockSignals(true);
77
78 clear();
79 for (const KoColor &color : std::as_const(*m_commonColors)) {
81 }
82
83 blockSignals(false);
84 Q_EMIT sigReset();
85 m_idle = true;
86 Q_EMIT sigIdle(true);
87}
void addColor(const KoColor &color)
KoColor color(int index) const
void sigIdle(bool isIdle)

References KisUniqueColorSet::addColor(), KisUniqueColorSet::clear(), KisUniqueColorSet::color(), m_commonColors, m_idle, sigIdle(), and KisUniqueColorSet::sigReset().

◆ slotUpdateColors

void WGCommonColorSet::slotUpdateColors ( )
slot

Definition at line 53 of file WGCommonColorSet.cpp.

54{
55 if (!m_image) {
56 return;
57 }
58
59 if(!m_idle) {
60 // Previous computation is still running, try again later
61 m_updateTimer.start();
62 return;
63 }
64
65 m_idle = false;
66 Q_EMIT sigIdle(false);
67
68 m_commonColors->clear();
70 connect(runner, SIGNAL(sigDone()), this, SLOT(slotCalculationDone()));
71 QThreadPool::globalInstance()->start(runner);
72}

References connect(), m_commonColors, m_idle, m_image, m_numColors, m_updateTimer, sigIdle(), and slotCalculationDone().

Member Data Documentation

◆ m_autoUpdate

bool WGCommonColorSet::m_autoUpdate {false}
private

Definition at line 36 of file WGCommonColorSet.h.

36{false};

◆ m_commonColors

QSharedPointer<QVector<KoColor> > WGCommonColorSet::m_commonColors
private

Definition at line 32 of file WGCommonColorSet.h.

◆ m_idle

bool WGCommonColorSet::m_idle {true}
private

Definition at line 35 of file WGCommonColorSet.h.

35{true};

◆ m_image

KisImageSP WGCommonColorSet::m_image
private

Definition at line 33 of file WGCommonColorSet.h.

◆ m_numColors

int WGCommonColorSet::m_numColors {10}
private

Definition at line 34 of file WGCommonColorSet.h.

34{10};

◆ m_updateTimer

QTimer WGCommonColorSet::m_updateTimer
private

Definition at line 31 of file WGCommonColorSet.h.


The documentation for this class was generated from the following files: