Krita Source Code Documentation
Loading...
Searching...
No Matches
WGCommonColorSet.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021 Mathias Wein <lynx.mw+kde@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7#include "WGCommonColorSet.h"
8
10#include <QThreadPool>
11
13 : KisUniqueColorSet(parent)
14 , m_commonColors(new QVector<KoColor>)
15{
16 m_updateTimer.setInterval(2000);
17 m_updateTimer.setSingleShot(true);
18 connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(slotUpdateColors()));
19}
20
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}
34
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}
52
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}
73
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}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void addColor(const KoColor &color)
KoColor color(int index) const
void setAutoUpdate(bool enabled)
QSharedPointer< QVector< KoColor > > m_commonColors
void setImage(KisImageSP image)
WGCommonColorSet(QObject *parent=0)
void sigIdle(bool isIdle)