Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Fix (partially) enabled state of the buttons in Palette docker
Dmitry Kazakova21f7f930fa5
diff --git a/plugins/dockers/palettedocker/palettedocker_dock.cpp b/plugins/dockers/palettedocker/palettedocker_dock.cppindex db8fec9bd7..a804bf9635 100644--- a/plugins/dockers/palettedocker/palettedocker_dock.cpp+++ b/plugins/dockers/palettedocker/palettedocker_dock.cpp@@ -142,6 +142,9 @@ PaletteDockerDock::PaletteDockerDock( )m_ui->paletteView->setAllowModification(false);}+ m_ui->bnUndo->setIcon(KisIconUtils::loadIcon("edit-undo"));+ m_ui->bnRedo->setIcon(KisIconUtils::loadIcon("edit-redo"));+//m_ui->bnUndo->setVisible(false);//m_ui->bnRedo->setVisible(false);@@ -290,11 +293,21 @@ void PaletteDockerDock::slotSetColorSet(KoColorSetSP colorSet)m_model->setColorSet(colorSet);m_ui->bnUndo->setEnabled(colorSet->undoStack()->canUndo() && !colorSet->isLocked());- connect(colorSet->undoStack(), SIGNAL(canUndoChanged(bool)), m_ui->bnUndo, SLOT(setEnabled(bool)));+ connect(colorSet->undoStack(),+ &KUndo2Stack::canUndoChanged,+ this,+ [bnUndo = m_ui->bnUndo, colorSet = colorSet](bool canUndo) {+ bnUndo->setEnabled(!colorSet->isLocked() && canUndo);+ });connect(colorSet->undoStack(), SIGNAL(undoTextChanged(QString)), this, SLOT(setUndoToolTip(QString)));m_ui->bnRedo->setEnabled(colorSet->undoStack()->canRedo() && colorSet->isLocked());- connect(colorSet->undoStack(), SIGNAL(canRedoChanged(bool)), m_ui->bnRedo, SLOT(setEnabled(bool)));+ connect(colorSet->undoStack(),+ &KUndo2Stack::canRedoChanged,+ this,+ [bnRedo = m_ui->bnRedo, colorSet = colorSet](bool canRedo) {+ bnRedo->setEnabled(!colorSet->isLocked() && canRedo);+ });connect(colorSet->undoStack(), SIGNAL(redoTextChanged(QString)), this, SLOT(setRedoToolTip(QString)));connect(m_ui->bnUndo, SIGNAL(clicked()), this, SLOT(undo()));@@ -302,16 +315,6 @@ void PaletteDockerDock::slotSetColorSet(KoColorSetSP colorSet)m_ui->bnLock->setChecked(colorSet->isLocked());}- bool state = (bool)colorSet;- if (state != (bool)m_currentColorSet) {- m_ui->bnAdd->setEnabled(state);- m_ui->bnRename->setEnabled(state);- m_ui->bnRemove->setEnabled(state);- m_ui->bnEditPalette->setEnabled(state);- m_ui->bnSavePalette->setEnabled(state);- m_ui->paletteView->setAllowModification(state);- m_ui->bnLock->setEnabled(state);- }m_currentColorSet = colorSet;@@ -325,6 +328,7 @@ void PaletteDockerDock::slotSetColorSet(KoColorSetSP colorSet)m_ui->lblPaletteName->setText("");}slotUpdateLblPaletteName();+ slotLockPalette(!colorSet || colorSet->isLocked());}void PaletteDockerDock::slotEditPalette()@@ -422,16 +426,20 @@ void PaletteDockerDock::slotUpdateLblPaletteName()void PaletteDockerDock::slotLockPalette(bool locked){- m_currentColorSet->setLocked(locked);+ if (m_currentColorSet && m_currentColorSet->isLocked() != locked) {+ m_currentColorSet->setLocked(locked);+ }QIcon icon = locked ? KisIconUtils::loadIcon(koIconName("object-locked")): KisIconUtils::loadIcon(koIconName("object-unlocked"));m_ui->bnLock->setIcon(icon);- m_ui->bnAdd->setEnabled(!locked);- m_ui->bnRename->setEnabled(!locked);- m_ui->bnRemove->setEnabled(!locked);- m_ui->bnEditPalette->setEnabled(!locked);- m_ui->bnSavePalette->setEnabled(!locked);- m_ui->paletteView->setAllowModification(!locked);+ m_ui->bnUndo->setEnabled(!locked && m_currentColorSet && m_currentColorSet->undoStack()->canUndo());+ m_ui->bnRedo->setEnabled(!locked && m_currentColorSet && m_currentColorSet->undoStack()->canRedo());+ m_ui->bnAdd->setEnabled(!locked && m_currentColorSet);+ m_ui->bnRename->setEnabled(!locked && m_currentColorSet);+ m_ui->bnRemove->setEnabled(!locked && m_currentColorSet);+ m_ui->bnEditPalette->setEnabled(!locked && m_currentColorSet);+ m_ui->bnSavePalette->setEnabled(!locked && m_currentColorSet);+ m_ui->paletteView->setAllowModification(!locked && m_currentColorSet);}void PaletteDockerDock::setUndoToolTip(const QString &text)