| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2020 Mathias Wein <[email protected]> |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "WGColorSelectorDock.h" |
| 8 |
|
| 9 |
#include "WGActionManager.h" |
| 10 |
#include "WGColorSelectorSettings.h" |
| 11 |
#include "WGColorPatches.h" |
| 12 |
#include "WGColorPreviewToolTip.h" |
| 13 |
#include "WGCommonColorSet.h" |
| 14 |
#include "WGConfigSelectorTypes.h" |
| 15 |
#include "WGQuickSettingsWidget.h" |
| 16 |
#include "WGShadeSelector.h" |
| 17 |
#include "KisVisualColorSelector.h" |
| 18 |
#include "KisColorSourceToggle.h" |
| 19 |
|
| 20 |
#include <klocalizedstring.h> |
| 21 |
|
| 22 |
#include <kis_icon.h> |
| 23 |
#include <kis_canvas2.h> |
| 24 |
#include <kis_canvas_resource_provider.h> |
| 25 |
#include <kis_config_notifier.h> |
| 26 |
#include <kis_display_color_converter.h> |
| 27 |
#include <kis_signal_compressor.h> |
| 28 |
#include <KisUniqueColorSet.h> |
| 29 |
#include <KisGamutMaskToolbar.h> |
| 30 |
#include <KoCanvasResourceProvider.h> |
| 31 |
|
| 32 |
#include <QBoxLayout> |
| 33 |
#include <QMenu> |
| 34 |
#include <QToolButton> |
| 35 |
#include <QWidgetAction> |
| 36 |
|
| 37 |
#include <QDebug> |
| 38 |
#include <kis_assert.h> |
| 39 |
|
| 40 |
WGColorSelectorDock::WGColorSelectorDock() |
| 41 |
: QDockWidget() |
| 42 |
, m_displayConfig(new WGSelectorDisplayConfig) |
| 43 |
, m_colorChangeCompressor(new KisSignalCompressor(100 /* ms */, KisSignalCompressor::POSTPONE, this)) |
| 44 |
, m_actionManager(new WGActionManager(this)) |
| 45 |
, m_colorTooltip(new WGColorPreviewToolTip(this)) |
| 46 |
, m_colorModelBG(new KisVisualColorModel) |
| 47 |
{ |
| 48 |
setWindowTitle(i18n("Wide Gamut Color Selector")); |
| 49 |
|
| 50 |
QWidget *mainWidget = new QWidget(); |
| 51 |
m_mainWidgetLayout = new QVBoxLayout(mainWidget); |
| 52 |
m_verticalElementsLayout = new QHBoxLayout(); |
| 53 |
m_selectorAreaLayout = new QBoxLayout(QBoxLayout::TopToBottom); |
| 54 |
|
| 55 |
m_selector = new KisVisualColorSelector(mainWidget); |
| 56 |
m_selector->setMinimumSliderWidth(12); |
| 57 |
connect(m_selector, SIGNAL(sigNewColor(KoColor)), SLOT(slotColorSelected(KoColor))); |
| 58 |
connect(m_selector, SIGNAL(sigInteraction(bool)), SLOT(slotColorInteraction(bool))); |
| 59 |
connect(m_colorChangeCompressor, SIGNAL(timeout()), SLOT(slotSetNewColors())); |
| 60 |
m_colorModelFG = m_selector->selectorModel(); |
| 61 |
|
| 62 |
// Header |
| 63 |
QWidget *headerWidget = new QWidget(mainWidget); |
| 64 |
QHBoxLayout *headerLayout = new QHBoxLayout(headerWidget); |
| 65 |
|
| 66 |
m_toggle = new KisColorSourceToggle(mainWidget); |
| 67 |
connect(m_toggle, SIGNAL(toggled(bool)), SLOT(slotColorSourceToggled(bool))); |
| 68 |
headerLayout->addWidget(m_toggle); |
| 69 |
m_gamutToolbar = new KisGamutMaskToolbar(this); |
| 70 |
m_gamutToolbar->setContentsMargins(0, 0, 0, 5); |
| 71 |
m_gamutToolbar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); |
| 72 |
headerLayout->addWidget(m_gamutToolbar); |
| 73 |
headerLayout->addStretch(); |
| 74 |
headerLayout->setContentsMargins(0, 0, 0, 0); |
| 75 |
|
| 76 |
connect(m_selector, SIGNAL(sigGamutMaskSupportChanged(bool)), SLOT(slotShowGamutMaskToolbar(bool))); |
| 77 |
|
| 78 |
m_configButton = new QToolButton(this); |
| 79 |
m_configButton->setIcon(KisIconUtils::loadIcon("view-choose")); |
| 80 |
m_configButton->setAutoRaise(true); |
| 81 |
m_configButton->setPopupMode(QToolButton::InstantPopup); |
| 82 |
headerLayout->addWidget(m_configButton); |
| 83 |
|
| 84 |
m_mainWidgetLayout->addWidget(headerWidget); |
| 85 |
m_mainWidgetLayout->addLayout(m_verticalElementsLayout); |
| 86 |
m_verticalElementsLayout->addLayout(m_selectorAreaLayout); |
| 87 |
|
| 88 |
m_selectorAreaLayout->addWidget(m_selector); |
| 89 |
|
| 90 |
KisVisualColorModelSP model = m_selector->selectorModel(); |
| 91 |
m_shadeSelector = new WGShadeSelector(m_displayConfig, model, this); |
| 92 |
m_selectorAreaLayout->addWidget(m_shadeSelector); |
| 93 |
connect(m_shadeSelector, SIGNAL(sigColorInteraction(bool)), SLOT(slotColorInteraction(bool))); |
| 94 |
|
| 95 |
// eventually it should made be a global history, not specific to any plugin |
| 96 |
m_colorHistory = new KisUniqueColorSet(this); |
| 97 |
|
| 98 |
m_history = new WGColorPatches(m_displayConfig, m_colorHistory, mainWidget); |
| 99 |
m_history->setPreset(WGColorPatches::History); |
| 100 |
connect(m_history, SIGNAL(sigColorChanged(KoColor)), SLOT(slotColorSelected(KoColor))); |
| 101 |
connect(m_history, SIGNAL(sigColorInteraction(bool)), SLOT(slotColorInteraction(bool))); |
| 102 |
|
| 103 |
// Common Colors (Colors from Image) |
| 104 |
m_commonColorSet = new WGCommonColorSet(this); |
| 105 |
|
| 106 |
m_commonColors = new WGColorPatches(m_displayConfig, m_commonColorSet, mainWidget); |
| 107 |
m_commonColors->setPreset(WGColorPatches::CommonColors); |
| 108 |
connect(m_commonColors, SIGNAL(sigColorChanged(KoColor)), SLOT(slotColorSelected(KoColor))); |
| 109 |
connect(m_commonColors, SIGNAL(sigColorInteraction(bool)), SLOT(slotColorInteraction(bool))); |
| 110 |
|
| 111 |
connect(WGConfig::notifier(), SIGNAL(configChanged()), SLOT(slotConfigurationChanged())); |
| 112 |
|
| 113 |
setWidget(mainWidget); |
| 114 |
slotConfigurationChanged(); |
| 115 |
setEnabled(false); |
| 116 |
} |
| 117 |
|
| 118 |
const KisVisualColorModel &WGColorSelectorDock::colorModel() const |
| 119 |
{ |
| 120 |
// currently always return foreground model; |
| 121 |
// do lazy conversion to current HSX model if required |
| 122 |
if (selectingBackground() && m_colorModelBG->isHSXModel()) { |
| 123 |
m_colorModelFG->setRGBColorModel(m_colorModelBG->colorModel()); |
| 124 |
} |
| 125 |
return *(m_colorModelFG); |
| 126 |
} |
| 127 |
|
| 128 |
KisDisplayColorConverter *WGColorSelectorDock::displayColorConverter(bool rawPointer) const |
| 129 |
{ |
| 130 |
KisDisplayColorConverter *converter = nullptr; |
| 131 |
if (m_canvas) { |
| 132 |
converter = m_canvas->displayColorConverter(); |
| 133 |
} |
| 134 |
return (rawPointer || converter) ? converter : KisDisplayColorConverter::dumbConverterInstance(); |
| 135 |
} |
| 136 |
|
| 137 |
bool WGColorSelectorDock::selectingBackground() const |
| 138 |
{ |
| 139 |
return m_toggle->isChecked(); |
| 140 |
} |
| 141 |
|
| 142 |
void WGColorSelectorDock::setChannelValues(const QVector4D &values) |
| 143 |
{ |
| 144 |
// currently always set foreground color |
| 145 |
if (!m_canvas) { |
| 146 |
return; |
| 147 |
} |
| 148 |
|
| 149 |
// This could be nicer...if setting active model, this triggers slotColorSelected() |
| 150 |
// and leaves timer running with NOP, otherwise the resource update is detected as |
| 151 |
// external event and updates UI. |
| 152 |
m_colorModelFG->slotSetChannelValues(values); |
| 153 |
|
| 154 |
m_canvas->resourceManager()->setForegroundColor(m_colorModelFG->currentColor()); |
| 155 |
m_pendingFgUpdate = false; |
| 156 |
} |
| 157 |
|
| 158 |
void WGColorSelectorDock::leaveEvent(QEvent *event) |
| 159 |
{ |
| 160 |
Q_UNUSED(event) |
| 161 |
m_colorTooltip->hide(); |
| 162 |
} |
| 163 |
|
| 164 |
void WGColorSelectorDock::setCanvas(KoCanvasBase *canvas) |
| 165 |
{ |
| 166 |
if (m_canvas.data() == canvas) |
| 167 |
{ |
| 168 |
// not sure why setCanvas gets called 3 times for new canvas, just skip |
| 169 |
return; |
| 170 |
} |
| 171 |
if (m_canvas) { |
| 172 |
disconnectFromCanvas(); |
| 173 |
} |
| 174 |
m_actionManager->setCanvas(qobject_cast<KisCanvas2*>(canvas), m_canvas); |
| 175 |
m_canvas = qobject_cast<KisCanvas2*>(canvas); |
| 176 |
// TODO: unset display converters if canvas is null |
| 177 |
if (m_canvas) { |
| 178 |
KoColorDisplayRendererInterface *dri = m_canvas->displayColorConverter()->displayRendererInterface(); |
| 179 |
KisCanvasResourceProvider *resourceProvider = m_canvas->imageView()->resourceProvider(); |
| 180 |
m_selector->setDisplayRenderer(dri); |
| 181 |
m_displayConfig->setDisplayConverter(m_canvas->displayColorConverter()); |
| 182 |
m_commonColorSet->setImage(m_canvas->image()); |
| 183 |
//m_toggle->setBackgroundColor(dri->toQColor(color)); |
| 184 |
connect(dri, SIGNAL(displayConfigurationChanged()), this, SLOT(slotDisplayConfigurationChanged())); |
| 185 |
connect(m_canvas->resourceManager(), SIGNAL(canvasResourceChanged(int,QVariant)), |
| 186 |
this, SLOT(slotCanvasResourceChanged(int,QVariant))); |
| 187 |
connect(resourceProvider, SIGNAL(sigFGColorUsed(KoColor)), |
| 188 |
this, SLOT(slotFGColorUsed(KoColor)), Qt::UniqueConnection); |
| 189 |
|
| 190 |
// Gamut Mask |
| 191 |
connect(resourceProvider, SIGNAL(sigGamutMaskChanged(KoGamutMaskSP)), |
| 192 |
m_selector, SLOT(slotGamutMaskChanged(KoGamutMaskSP)), Qt::UniqueConnection); |
| 193 |
|
| 194 |
connect(resourceProvider, SIGNAL(sigGamutMaskPreviewUpdate()), |
| 195 |
m_selector, SLOT(slotGamutMaskPreviewUpdate()), Qt::UniqueConnection); |
| 196 |
|
| 197 |
connect(resourceProvider, SIGNAL(sigGamutMaskUnset()), |
| 198 |
m_selector, SLOT(slotGamutMaskUnset()), Qt::UniqueConnection); |
| 199 |
|
| 200 |
connect(resourceProvider, SIGNAL(sigGamutMaskDeactivated()), |
| 201 |
m_selector, SLOT(slotGamutMaskUnset()), Qt::UniqueConnection); |
| 202 |
|
| 203 |
m_gamutToolbar->connectMaskSignals(resourceProvider); |
| 204 |
|
| 205 |
// quirk note: displayConfigurationChanged signal gets sent *before* the new canvas gets |
| 206 |
// passed, through the display converter of the now inactive canvas! So we need to repeat... |
| 207 |
slotDisplayConfigurationChanged(); |
| 208 |
} |
| 209 |
setEnabled(canvas != 0); |
| 210 |
} |
| 211 |
|
| 212 |
void WGColorSelectorDock::unsetCanvas() |
| 213 |
{ |
| 214 |
setEnabled(false); |
| 215 |
m_actionManager->setCanvas(0, 0); |
| 216 |
m_displayConfig->setDisplayConverter(0); |
| 217 |
m_selector->setDisplayRenderer(0); |
| 218 |
m_commonColorSet->setImage(KisImageSP()); |
| 219 |
m_canvas = 0; |
| 220 |
} |
| 221 |
|
| 222 |
void WGColorSelectorDock::setViewManager(KisViewManager *viewManager) |
| 223 |
{ |
| 224 |
m_actionManager->registerActions(viewManager); |
| 225 |
} |
| 226 |
|
| 227 |
void WGColorSelectorDock::disconnectFromCanvas() |
| 228 |
{ |
| 229 |
m_canvas->disconnectCanvasObserver(this); |
| 230 |
m_canvas->displayColorConverter()->displayRendererInterface()->disconnect(this); |
| 231 |
m_canvas->imageView()->resourceProvider()->disconnect(m_selector); |
| 232 |
m_canvas = 0; |
| 233 |
} |
| 234 |
|
| 235 |
void WGColorSelectorDock::updateLayout() |
| 236 |
{ |
| 237 |
WGConfig::Accessor cfg; |
| 238 |
|
| 239 |
bool historyEnabled = cfg.get(WGConfig::colorHistoryEnabled); |
| 240 |
Qt::Orientation historyOrientation = cfg.get(WGConfig::colorHistory.orientation); |
| 241 |
|
| 242 |
m_verticalElementsLayout->removeWidget(m_history); |
| 243 |
m_verticalElementsLayout->removeWidget(m_commonColors); |
| 244 |
m_mainWidgetLayout->removeWidget(m_history); |
| 245 |
m_mainWidgetLayout->removeWidget(m_commonColors); |
| 246 |
|
| 247 |
if (historyEnabled) { |
| 248 |
if (historyOrientation == Qt::Vertical) { |
| 249 |
m_verticalElementsLayout->addWidget(m_history); |
| 250 |
} |
| 251 |
else { |
| 252 |
m_mainWidgetLayout->addWidget(m_history); |
| 253 |
} |
| 254 |
m_history->show(); |
| 255 |
} |
| 256 |
else { |
| 257 |
m_history->hide(); |
| 258 |
} |
| 259 |
|
| 260 |
bool commonColorsEnabled = cfg.get(WGConfig::commonColorsEnabled); |
| 261 |
Qt::Orientation commonColorsOrientation = cfg.get(WGConfig::commonColors.orientation); |
| 262 |
|
| 263 |
if (commonColorsEnabled) { |
| 264 |
if (commonColorsOrientation == Qt::Vertical) { |
| 265 |
m_verticalElementsLayout->addWidget(m_commonColors); |
| 266 |
} |
| 267 |
else { |
| 268 |
m_mainWidgetLayout->addWidget(m_commonColors); |
| 269 |
} |
| 270 |
m_commonColors->show(); |
| 271 |
} |
| 272 |
else { |
| 273 |
m_commonColors->hide(); |
| 274 |
} |
| 275 |
|
| 276 |
bool shadeSelectorEnabled = cfg.get(WGConfig::minimalShadeSelectorEnabled); |
| 277 |
if (shadeSelectorEnabled) { |
| 278 |
m_shadeSelector->show(); |
| 279 |
} |
| 280 |
else { |
| 281 |
m_shadeSelector->hide(); |
| 282 |
} |
| 283 |
|
| 284 |
} |
| 285 |
|
| 286 |
void WGColorSelectorDock::slotConfigurationChanged() |
| 287 |
{ |
| 288 |
WGConfig::Accessor cfg; |
| 289 |
m_selector->setRenderMode(cfg.get(WGConfig::selectorRenderMode)); |
| 290 |
m_selector->selectorModel()->setRGBColorModel(cfg.get(WGConfig::rgbColorModel)); |
| 291 |
KisColorSelectorConfiguration selectorCfg = cfg.colorSelectorConfiguration(); |
| 292 |
m_selector->setConfiguration(&selectorCfg); |
| 293 |
m_CSSource = cfg.get(WGConfig::colorSpaceSource); |
| 294 |
if (m_CSSource == FixedColorSpace) { |
| 295 |
m_customCS = cfg.customSelectionColorSpace(); |
| 296 |
} |
| 297 |
bool proofColors = cfg.get(WGConfig::proofToPaintingColors); |
| 298 |
m_selector->setProofColors(proofColors); |
| 299 |
m_displayConfig->setPreviewInPaintingCS(proofColors); |
| 300 |
m_shadeSelector->updateSettings(); |
| 301 |
m_history->updateSettings(); |
| 302 |
m_commonColors->updateSettings(); |
| 303 |
m_commonColorSet->setAutoUpdate(cfg.get(WGConfig::commonColorsAutoUpdate)); |
| 304 |
// Quick settings menu |
| 305 |
if (cfg.get(WGConfig::quickSettingsEnabled)) { |
| 306 |
if (!m_configButton->menu()) { |
| 307 |
m_configButton->disconnect(this); |
| 308 |
QMenu *configureMenu = new QMenu(this); |
| 309 |
m_quickSettings = new WGQuickSettingsWidget(this, m_selector); |
| 310 |
// prevents hover indicator being stuck on other menu entries |
| 311 |
m_quickSettings->setMouseTracking(true); |
| 312 |
m_quickSettingAction = new QWidgetAction(this); |
| 313 |
m_quickSettingAction->setDefaultWidget(m_quickSettings); |
| 314 |
|
| 315 |
configureMenu->addAction(m_quickSettingAction); |
| 316 |
QAction *cfgAction = configureMenu->addAction(i18nc("Wide Gamut Color Selector", "Configure...")); |
| 317 |
connect(cfgAction, SIGNAL(triggered(bool)), SLOT(slotOpenSettings())); |
| 318 |
m_configButton->setMenu(configureMenu); |
| 319 |
} else { |
| 320 |
// WORKAROUND: force geometry update by re-adding action, all other attempts failed... |
| 321 |
QMenu *menu = m_configButton->menu(); |
| 322 |
menu->removeAction(m_quickSettingAction); |
| 323 |
menu->insertAction(menu->actions().constFirst(), m_quickSettingAction); |
| 324 |
} |
| 325 |
m_quickSettings->loadConfiguration(); |
| 326 |
} else { |
| 327 |
if (m_configButton->menu()) { |
| 328 |
m_configButton->menu()->deleteLater(); |
| 329 |
m_configButton->setMenu(0); |
| 330 |
delete m_quickSettingAction; |
| 331 |
m_quickSettingAction = 0; |
| 332 |
m_quickSettings = 0; |
| 333 |
} |
| 334 |
connect(m_configButton, SIGNAL(clicked(bool)), SLOT(slotOpenSettings()), Qt::UniqueConnection); |
| 335 |
} |
| 336 |
|
| 337 |
updateLayout(); |
| 338 |
|
| 339 |
if (m_canvas) { |
| 340 |
slotDisplayConfigurationChanged(); |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
void WGColorSelectorDock::slotDisplayConfigurationChanged() |
| 345 |
{ |
| 346 |
if (!m_canvas) { |
| 347 |
return; |
| 348 |
} |
| 349 |
|
| 350 |
const KoColorSpace *selectionCS = nullptr; |
| 351 |
|
| 352 |
// Note: displayConfigurationChanged is also emitted on image color space changes, |
| 353 |
// so there's no need to handle extra signals, although it's a bit convoluted |
| 354 |
if (m_CSSource == ImageColorSpace) { |
| 355 |
selectionCS = m_canvas->image()->colorSpace(); |
| 356 |
} else if (m_CSSource == FixedColorSpace) { |
| 357 |
selectionCS = m_customCS; |
| 358 |
} else { |
| 359 |
selectionCS = m_canvas->displayColorConverter()->nodeColorSpace(); |
| 360 |
} |
| 361 |
|
| 362 |
// TODO: use m_viewManager->canvasResourceProvider()->fgColor(); |
| 363 |
KoColor fgColor = m_canvas->resourceManager()->foregroundColor(); |
| 364 |
KoColor bgColor = m_canvas->resourceManager()->backgroundColor(); |
| 365 |
|
| 366 |
bool proof = m_displayConfig->previewInPaintingCS(); |
| 367 |
m_toggle->setForegroundColor(displayColorConverter()->toQColor(fgColor, proof)); |
| 368 |
m_toggle->setBackgroundColor(displayColorConverter()->toQColor(bgColor, proof)); |
| 369 |
KisVisualColorModelSP activeModel = m_selector->selectorModel(); |
| 370 |
|
| 371 |
if (selectionCS && selectionCS != activeModel->colorSpace()) { |
| 372 |
activeModel->slotSetColorSpace(selectionCS); |
| 373 |
activeModel->slotSetColor(activeModel == m_colorModelFG ? fgColor : bgColor); |
| 374 |
} |
| 375 |
} |
| 376 |
|
| 377 |
void WGColorSelectorDock::slotColorSelected(const KoColor &color) |
| 378 |
{ |
| 379 |
QColor displayCol = displayColorConverter()->toQColor(color, m_displayConfig->previewInPaintingCS()); |
| 380 |
m_colorTooltip->setCurrentColor(displayCol); |
| 381 |
if (selectingBackground()) { |
| 382 |
m_toggle->setBackgroundColor(displayCol); |
| 383 |
m_pendingBgUpdate = true; |
| 384 |
m_colorChangeCompressor->start(); |
| 385 |
} |
| 386 |
else { |
| 387 |
m_toggle->setForegroundColor(displayCol); |
| 388 |
m_pendingFgUpdate = true; |
| 389 |
m_colorChangeCompressor->start(); |
| 390 |
} |
| 391 |
if (sender() != m_selector) { |
| 392 |
m_selector->slotSetColor(color); |
| 393 |
} |
| 394 |
} |
| 395 |
|
| 396 |
void WGColorSelectorDock::slotColorSourceToggled(bool selectingBg) |
| 397 |
{ |
| 398 |
if (selectingBg) { |
| 399 |
if (m_colorModelFG->isHSXModel()) { |
| 400 |
m_colorModelBG->setRGBColorModel(m_colorModelFG->colorModel()); |
| 401 |
} |
| 402 |
m_selector->setSelectorModel(m_colorModelBG); |
| 403 |
m_shadeSelector->setModel(m_colorModelBG); |
| 404 |
} |
| 405 |
else { |
| 406 |
if (m_colorModelBG->isHSXModel()) { |
| 407 |
m_colorModelFG->setRGBColorModel(m_colorModelBG->colorModel()); |
| 408 |
} |
| 409 |
m_selector->setSelectorModel(m_colorModelFG); |
| 410 |
m_shadeSelector->setModel(m_colorModelFG); |
| 411 |
} |
| 412 |
// currently, only the color space of the active model is updated, so it may be outdated |
| 413 |
if (m_canvas) { |
| 414 |
slotDisplayConfigurationChanged(); |
| 415 |
} |
| 416 |
} |
| 417 |
|
| 418 |
void WGColorSelectorDock::slotColorInteraction(bool active) |
| 419 |
{ |
| 420 |
if (active) { |
| 421 |
QColor baseCol = m_displayConfig->displayConverter()->toQColor(m_selector->getCurrentColor()); |
| 422 |
m_colorTooltip->setCurrentColor(baseCol); |
| 423 |
m_colorTooltip->setPreviousColor(baseCol); |
| 424 |
if (sender() == m_shadeSelector) { |
| 425 |
m_colorTooltip->show(m_shadeSelector); |
| 426 |
} else { |
| 427 |
m_colorTooltip->show(this); |
| 428 |
} |
| 429 |
} |
| 430 |
} |
| 431 |
|
| 432 |
void WGColorSelectorDock::slotFGColorUsed(const KoColor &color) |
| 433 |
{ |
| 434 |
QColor lastCol = m_displayConfig->displayConverter()->toQColor(color); |
| 435 |
m_colorTooltip->setLastUsedColor(lastCol); |
| 436 |
m_actionManager->setLastUsedColor(color); |
| 437 |
m_colorHistory->addColor(color); |
| 438 |
} |
| 439 |
|
| 440 |
void WGColorSelectorDock::slotSetNewColors() |
| 441 |
{ |
| 442 |
//KIS_SAFE_ASSERT_RECOVER_RETURN(m_pendingFgUpdate || m_pendingBgUpdate); |
| 443 |
if (m_pendingFgUpdate) { |
| 444 |
m_canvas->resourceManager()->setForegroundColor(m_colorModelFG->currentColor()); |
| 445 |
m_pendingFgUpdate = false; |
| 446 |
} |
| 447 |
if (m_pendingBgUpdate) { |
| 448 |
m_canvas->resourceManager()->setBackgroundColor(m_colorModelBG->currentColor()); |
| 449 |
m_pendingBgUpdate = false; |
| 450 |
} |
| 451 |
} |
| 452 |
|
| 453 |
void WGColorSelectorDock::slotCanvasResourceChanged(int key, const QVariant &value) |
| 454 |
{ |
| 455 |
switch (key) { |
| 456 |
case KoCanvasResource::ForegroundColor: |
| 457 |
if (!m_pendingFgUpdate) { |
| 458 |
KoColor color = value.value<KoColor>(); |
| 459 |
m_toggle->setForegroundColor(displayColorConverter()->toQColor(color)); |
| 460 |
m_colorModelFG->slotSetColor(color); |
| 461 |
} |
| 462 |
break; |
| 463 |
case KoCanvasResource::BackgroundColor: |
| 464 |
if (!m_pendingBgUpdate) { |
| 465 |
KoColor color = value.value<KoColor>(); |
| 466 |
m_toggle->setBackgroundColor(displayColorConverter()->toQColor(color)); |
| 467 |
m_colorModelBG->slotSetColor(color); |
| 468 |
} |
| 469 |
default: |
| 470 |
break; |
| 471 |
} |
| 472 |
} |
| 473 |
|
| 474 |
void WGColorSelectorDock::slotOpenSettings() |
| 475 |
{ |
| 476 |
if (!m_canvas) return; |
| 477 |
|
| 478 |
WGColorSelectorSettingsDialog settings; |
| 479 |
if (settings.exec() == QDialog::Accepted) { |
| 480 |
//WGConfig::notifier()->notifyConfigChanged(); |
| 481 |
} |
| 482 |
} |
| 483 |
|
| 484 |
void WGColorSelectorDock::slotShowGamutMaskToolbar(bool show) |
| 485 |
{ |
| 486 |
m_gamutToolbar->setVisible(show); |
| 487 |
} |
| 488 |
|
| 489 |
namespace WGConfig { |
| 490 |
const NumericSetting<WGColorSelectorDock::ColorSpaceSource> colorSpaceSource |
| 491 |
{ |
| 492 |
"colorSpaceSource", WGColorSelectorDock::LayerColorSpace, |
| 493 |
WGColorSelectorDock::LayerColorSpace, WGColorSelectorDock::FixedColorSpace, true |
| 494 |
}; |
| 495 |
} |