Skip to content

armgit / krita

Public Imported from GitHub
0

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++

Add grayscale preview to overview docker

Alexandre Morais34ad3c5d4e8e
diff --git a/libs/ui/KisImageThumbnailStrokeStrategy.cpp b/libs/ui/KisImageThumbnailStrokeStrategy.cpp
index 8408c418d3..a4ce59a77c 100644
--- a/libs/ui/KisImageThumbnailStrokeStrategy.cpp
+++ b/libs/ui/KisImageThumbnailStrokeStrategy.cpp
@@ -87,8 +87,18 @@ void KisImageThumbnailStrokeStrategyBase::initStrokeCallback()
runnableJobsInterface()->addRunnableJobs(jobs);
}
+void KisImageThumbnailStrokeStrategy::setGrayscale(bool value)
+{
+ m_grayscale = value;
+}
+
void KisImageThumbnailStrokeStrategy::reportThumbnailGenerationCompleted(KisPaintDeviceSP device, const QRect &rect)
{
+ if (m_grayscale) {
+ // device is the thumbnail's own scaled copy, so converting it in place is safe
+ device->convertTo(KoColorSpaceRegistry::instance()->graya8());
+ }
+
QImage overviewImage;
overviewImage = device->convertToQImage(m_profile,
rect,
diff --git a/libs/ui/KisImageThumbnailStrokeStrategy.h b/libs/ui/KisImageThumbnailStrokeStrategy.h
index a890e28e31..7f6846585f 100644
--- a/libs/ui/KisImageThumbnailStrokeStrategy.h
+++ b/libs/ui/KisImageThumbnailStrokeStrategy.h
@@ -60,6 +60,8 @@ class KRITAUI_EXPORT KisImageThumbnailStrokeStrategy : public KisImageThumbnailS
public:
using KisImageThumbnailStrokeStrategyBase::KisImageThumbnailStrokeStrategyBase;
+ /// Render the thumbnail in shades of gray
+ void setGrayscale(bool value);
protected:
virtual void reportThumbnailGenerationCompleted(KisPaintDeviceSP device, const QRect &rect);
@@ -67,6 +69,9 @@ protected:
Q_SIGNALS:
//Emitted when thumbnail is updated and overviewImage is fully generated.
void thumbnailUpdated(QImage pixmap);
+
+private:
+ bool m_grayscale {false};
};
#endif // KISIMAGETHUMBNAILSTROKESTRATEGY_H
diff --git a/plugins/dockers/overview/overviewdocker_page.cpp b/plugins/dockers/overview/overviewdocker_page.cpp
index cdfdd68660..f51571f13a 100644
--- a/plugins/dockers/overview/overviewdocker_page.cpp
+++ b/plugins/dockers/overview/overviewdocker_page.cpp
@@ -65,6 +65,8 @@ OverviewDockerPage::OverviewDockerPage(QWidget *parent, const char *name, Qt::Wi
KConfigGroup config = KSharedConfig::openConfig()->group("OverviewDocker");
m_pinControls = config.readEntry("pinControls", true);
m_areControlsHidden = !m_pinControls;
+ m_grayscale = config.readEntry("grayscale", false);
+ m_overviewWidget->setGrayscale(m_grayscale);
setEnabled(false);
}
@@ -73,6 +75,7 @@ OverviewDockerPage::~OverviewDockerPage()
{
KConfigGroup config = KSharedConfig::openConfig()->group("OverviewDocker");
config.writeEntry("pinControls", m_pinControls);
+ config.writeEntry("grayscale", m_grayscale);
}
void OverviewDockerPage::setCanvas(KoCanvasBase * canvas)
@@ -112,6 +115,12 @@ void OverviewDockerPage::setCanvas(KoCanvasBase * canvas)
m_pinControlsButton = nullptr;
}
+ if (m_grayscaleButton) {
+ m_controlsSecondRowLayout->removeWidget(m_grayscaleButton);
+ delete m_grayscaleButton;
+ m_grayscaleButton = nullptr;
+ }
+
// Delete the stretch
while (m_controlsSecondRowLayout && m_controlsSecondRowLayout->count() && m_controlsSecondRowLayout->itemAt(0)->spacerItem()) {
delete m_controlsSecondRowLayout->takeAt(0);
@@ -162,11 +171,22 @@ void OverviewDockerPage::setCanvas(KoCanvasBase * canvas)
m_pinControlsButton->setAutoRaise(true);
connect(m_pinControlsButton, SIGNAL(toggled(bool)), SLOT(setPinControls(bool)));
+ m_grayscaleButton = new QToolButton;
+ m_grayscaleButton->setCheckable(true);
+ m_grayscaleButton->setChecked(m_grayscale);
+ m_grayscaleButton->setToolTip(
+ i18nc("Show the overview docker preview in shades of gray", "Grayscale preview")
+ );
+ m_grayscaleButton->setIcon(KisIconUtils::loadIcon("saturation-decrease"));
+ m_grayscaleButton->setAutoRaise(true);
+ connect(m_grayscaleButton, SIGNAL(toggled(bool)), SLOT(setGrayscale(bool)));
+
m_controlsSecondRowLayout = new QHBoxLayout();
m_controlsSecondRowLayout->addWidget(m_rotateAngleSelector);
m_controlsSecondRowLayout->addStretch();
m_controlsSecondRowLayout->addWidget(m_mirrorCanvas);
+ m_controlsSecondRowLayout->addWidget(m_grayscaleButton);
m_controlsSecondRowLayout->addStretch();
m_controlsSecondRowLayout->addWidget(m_pinControlsButton);
m_controlsLayout->addLayout(m_controlsSecondRowLayout);
@@ -223,6 +243,12 @@ void OverviewDockerPage::setPinControls(bool pin)
m_pinControls = pin;
}
+void OverviewDockerPage::setGrayscale(bool grayscale)
+{
+ m_grayscale = grayscale;
+ m_overviewWidget->setGrayscale(grayscale);
+}
+
void OverviewDockerPage::resizeEvent(QResizeEvent*)
{
layoutMainWidgets();
diff --git a/plugins/dockers/overview/overviewdocker_page.h b/plugins/dockers/overview/overviewdocker_page.h
index 2353c44526..67e653afa6 100644
--- a/plugins/dockers/overview/overviewdocker_page.h
+++ b/plugins/dockers/overview/overviewdocker_page.h
@@ -33,6 +33,7 @@ public Q_SLOTS:
void rotateCanvasView(qreal rotation);
void updateRotationSlider(qreal rotation);
void setPinControls(bool pin);
+ void setGrayscale(bool grayscale);
protected:
void resizeEvent(QResizeEvent*) override;
@@ -62,8 +63,10 @@ private:
KisAngleSelector *m_rotateAngleSelector {nullptr};
QToolButton *m_mirrorCanvas {nullptr};
QToolButton *m_pinControlsButton {nullptr};
+ QToolButton *m_grayscaleButton {nullptr};
QPointer<KisCanvas2> m_canvas;
bool m_pinControls {true};
+ bool m_grayscale {false};
bool m_cursorIsHover {false};
bool m_isTouching {false};
bool m_isDraggingWithTouch {false};
diff --git a/plugins/dockers/overview/overviewwidget.cc b/plugins/dockers/overview/overviewwidget.cc
index 34183493e9..9fb5499e86 100644
--- a/plugins/dockers/overview/overviewwidget.cc
+++ b/plugins/dockers/overview/overviewwidget.cc
@@ -94,6 +94,7 @@ KisIdleTasksManager::TaskGuard OverviewWidget::registerIdleTask(KisCanvas2 *canv
KisImageThumbnailStrokeStrategy *strategy =
new KisImageThumbnailStrokeStrategy(image->projection(), image->bounds(), thumbnailSize, isPixelArt(), config.profile, config.intent, config.conversionFlags);
+ strategy->setGrayscale(m_grayscale);
connect(strategy, SIGNAL(thumbnailUpdated(QImage)), this, SLOT(updateThumbnail(QImage)));
@@ -146,6 +147,13 @@ void OverviewWidget::startUpdateCanvasProjection()
triggerCacheUpdate();
}
+void OverviewWidget::setGrayscale(bool value)
+{
+ if (m_grayscale == value) return;
+ m_grayscale = value;
+ triggerCacheUpdate();
+}
+
void OverviewWidget::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
diff --git a/plugins/dockers/overview/overviewwidget.h b/plugins/dockers/overview/overviewwidget.h
index 1fb32cd6fe..f7b0a6dfc4 100644
--- a/plugins/dockers/overview/overviewwidget.h
+++ b/plugins/dockers/overview/overviewwidget.h
@@ -39,6 +39,7 @@ public Q_SLOTS:
void startUpdateCanvasProjection();
void updateThumbnail(QImage pixmap);
void slotThemeChanged();
+ void setGrayscale(bool value);
Q_SIGNALS:
void signalDraggingStarted();
@@ -83,6 +84,7 @@ private:
QSize m_previewSize {QSize(100, 100)};
bool m_dragging {false};
+ bool m_grayscale {false};
QPointF m_lastPos {QPointF(0, 0)};
QColor m_outlineColor;