diff --git a/libs/ui/KisMainWindow.cpp b/libs/ui/KisMainWindow.cpp --- a/libs/ui/KisMainWindow.cpp +++ b/libs/ui/KisMainWindow.cpp @@ -619,6 +619,7 @@ { if (KisDlgPreferences::editPreferences()) { KisConfigNotifier::instance()->notifyConfigChanged(); + KisConfigNotifier::instance()->notifyPixelGridModeChanged(); KisUpdateSchedulerConfigNotifier::instance()->notifyConfigChanged(); // XXX: should this be changed for the views in other windows as well? diff --git a/libs/ui/KisViewManager.h b/libs/ui/KisViewManager.h --- a/libs/ui/KisViewManager.h +++ b/libs/ui/KisViewManager.h @@ -255,6 +255,7 @@ void guiUpdateTimeout(); void changeAuthorProfile(const QString &profileName); void slotUpdateAuthorProfileActions(); + void slotUpdatePixelGridAction(); void slotSaveShowRulersState(bool value); void slotSaveRulersTrackMouseState(bool value); diff --git a/libs/ui/KisViewManager.cpp b/libs/ui/KisViewManager.cpp --- a/libs/ui/KisViewManager.cpp +++ b/libs/ui/KisViewManager.cpp @@ -134,6 +134,7 @@ #include "dialogs/kis_delayed_save_dialog.h" #include #include +#include "kis_signals_blocker.h" class BlockingUserInputEventFilter : public QObject @@ -314,6 +315,7 @@ connect(KisPart::instance(), SIGNAL(sigViewRemoved(KisView*)), SLOT(slotViewRemoved(KisView*))); connect(KisConfigNotifier::instance(), SIGNAL(configChanged()), SLOT(slotUpdateAuthorProfileActions())); + connect(KisConfigNotifier::instance(), SIGNAL(pixelGridModeChanged()), SLOT(slotUpdatePixelGridAction())); KisInputProfileManager::instance()->loadProfiles(); @@ -460,6 +462,8 @@ doc->image()->compositeProgressProxy()->addProxy(d->persistentImageProgressUpdater); d->viewConnections.addUniqueConnection(&d->statusBar, SIGNAL(sigCancellationRequested()), doc->image(), SLOT(requestStrokeCancellation())); + d->viewConnections.addUniqueConnection(d->showPixelGrid, SIGNAL(toggled(bool)), canvasController, SLOT(slotTogglePixelGrid(bool))); + imageView->zoomManager()->setShowRulers(d->showRulersAction->isChecked()); imageView->zoomManager()->setRulersTrackMouse(d->rulersTrackMouseAction->isChecked()); @@ -725,6 +729,8 @@ actionCollection()->addAction("settings_active_author", d->actionAuthor); slotUpdateAuthorProfileActions(); + d->showPixelGrid = actionManager()->createAction("view_pixel_grid"); + slotUpdatePixelGridAction(); } void KisViewManager::setupManagers() @@ -1386,3 +1392,13 @@ d->actionAuthor->setCurrentAction(profileName); } } + +void KisViewManager::slotUpdatePixelGridAction() +{ + KIS_SAFE_ASSERT_RECOVER_RETURN(d->showPixelGrid); + + KisSignalsBlocker b(d->showPixelGrid); + + KisConfig cfg; + d->showPixelGrid->setChecked(cfg.pixelGridEnabled()); +} diff --git a/libs/ui/canvas/kis_canvas_controller.h b/libs/ui/canvas/kis_canvas_controller.h --- a/libs/ui/canvas/kis_canvas_controller.h +++ b/libs/ui/canvas/kis_canvas_controller.h @@ -58,6 +58,7 @@ qreal rotation() const; void resetCanvasRotation(); void slotToggleWrapAroundMode(bool value); + void slotTogglePixelGrid(bool value); void slotToggleLevelOfDetailMode(bool value); Q_SIGNALS: diff --git a/libs/ui/canvas/kis_canvas_controller.cpp b/libs/ui/canvas/kis_canvas_controller.cpp --- a/libs/ui/canvas/kis_canvas_controller.cpp +++ b/libs/ui/canvas/kis_canvas_controller.cpp @@ -34,6 +34,7 @@ #include "krita_utils.h" #include "kis_config.h" #include "kis_signal_compressor_with_param.h" +#include "kis_config_notifier.h" static const int gRulersUpdateDelay = 80 /* ms */; @@ -276,6 +277,14 @@ return kritaCanvas->wrapAroundViewingMode(); } +void KisCanvasController::slotTogglePixelGrid(bool value) +{ + KisConfig cfg; + cfg.enablePixelGrid(value); + + KisConfigNotifier::instance()->notifyPixelGridModeChanged(); +} + void KisCanvasController::slotToggleLevelOfDetailMode(bool value) { KisCanvas2 *kritaCanvas = dynamic_cast(canvas()); diff --git a/libs/ui/kis_config_notifier.h b/libs/ui/kis_config_notifier.h --- a/libs/ui/kis_config_notifier.h +++ b/libs/ui/kis_config_notifier.h @@ -46,13 +46,15 @@ void notifyConfigChanged(void); void notifyDropFramesModeChanged(); + void notifyPixelGridModeChanged(); Q_SIGNALS: /** * This signal is emitted whenever notifyConfigChanged() is called. */ void configChanged(void); void dropFramesModeChanged(); + void pixelGridModeChanged(); private: KisConfigNotifier(const KisConfigNotifier&); KisConfigNotifier operator=(const KisConfigNotifier&); diff --git a/libs/ui/kis_config_notifier.cpp b/libs/ui/kis_config_notifier.cpp --- a/libs/ui/kis_config_notifier.cpp +++ b/libs/ui/kis_config_notifier.cpp @@ -56,3 +56,8 @@ { m_d->dropFramesModeCompressor.start(); } + +void KisConfigNotifier::notifyPixelGridModeChanged() +{ + emit pixelGridModeChanged(); +} diff --git a/libs/ui/kis_paintop_box.h b/libs/ui/kis_paintop_box.h --- a/libs/ui/kis_paintop_box.h +++ b/libs/ui/kis_paintop_box.h @@ -122,7 +122,6 @@ void slotInputDeviceChanged(const KoInputDevice & inputDevice); void slotCanvasResourceChanged(int key, const QVariant& v); void resourceSelected(KoResource* resource); - void slotEnableShowPixelGrid(bool enabled); /// This should take care of creating a new brush preset from scratch /// It will either load the default brush preset for the engine, @@ -207,8 +206,6 @@ KisAction* m_eraseAction; KisAction* m_reloadAction; KisAction* m_disablePressureAction; - KisAction* m_showPixelGridAction; - QString m_currCompositeOpID; KisNodeWSP m_previousNode; diff --git a/libs/ui/kis_paintop_box.cc b/libs/ui/kis_paintop_box.cc --- a/libs/ui/kis_paintop_box.cc +++ b/libs/ui/kis_paintop_box.cc @@ -399,11 +399,6 @@ m_toolOptionsPopup->switchDetached(false); } - // pixel grid - m_showPixelGridAction = m_viewManager->actionManager()->createAction("view_pixel_grid"); - m_showPixelGridAction->setChecked(cfg.pixelGridEnabled()); - connect(m_showPixelGridAction, SIGNAL(toggled(bool)), this, SLOT(slotEnableShowPixelGrid(bool))); - m_savePresetWidget = new KisPresetSaveWidget(this); @@ -744,12 +739,6 @@ } } -void KisPaintopBox::slotEnableShowPixelGrid(bool enabled) -{ - KisConfig cfg; - cfg.enablePixelGrid(enabled); -} - void KisPaintopBox::slotInputDeviceChanged(const KoInputDevice& inputDevice) { TabletToolMap::iterator toolData = m_tabletToolMap.find(inputDevice); diff --git a/libs/ui/opengl/kis_opengl_canvas2.h b/libs/ui/opengl/kis_opengl_canvas2.h --- a/libs/ui/opengl/kis_opengl_canvas2.h +++ b/libs/ui/opengl/kis_opengl_canvas2.h @@ -102,6 +102,7 @@ public Q_SLOTS: void slotConfigChanged(); + void slotPixelGridModeChanged(); protected: // KisCanvasWidgetBase bool callFocusNextPrevChild(bool next) override; diff --git a/libs/ui/opengl/kis_opengl_canvas2.cpp b/libs/ui/opengl/kis_opengl_canvas2.cpp --- a/libs/ui/opengl/kis_opengl_canvas2.cpp +++ b/libs/ui/opengl/kis_opengl_canvas2.cpp @@ -107,6 +107,7 @@ #endif qreal pixelGridDrawingThreshold; + bool pixelGridEnabled; QColor gridColor; QColor cursorColor; @@ -168,7 +169,9 @@ setDisplayFilterImpl(colorConverter->displayFilter(), true); connect(KisConfigNotifier::instance(), SIGNAL(configChanged()), SLOT(slotConfigChanged())); + connect(KisConfigNotifier::instance(), SIGNAL(pixelGridModeChanged()), SLOT(slotPixelGridModeChanged())); slotConfigChanged(); + slotPixelGridModeChanged(); cfg.writeEntry("canvasState", "OPENGL_SUCCESS"); } @@ -783,13 +786,22 @@ d->openGLImageTextures->updateConfig(cfg.useOpenGLTextureBuffer(), cfg.numMipmapLevels()); d->filterMode = (KisOpenGL::FilterMode) cfg.openGLFilteringMode(); - d->pixelGridDrawingThreshold = cfg.getPixelGridDrawingThreshold(); - d->gridColor = cfg.getPixelGridColor(); d->cursorColor = cfg.getCursorMainColor(); notifyConfigChanged(); } +void KisOpenGLCanvas2::slotPixelGridModeChanged() +{ + KisConfig cfg; + + d->pixelGridDrawingThreshold = cfg.getPixelGridDrawingThreshold(); + d->pixelGridEnabled = cfg.pixelGridEnabled(); + d->gridColor = cfg.getPixelGridColor(); + + update(); +} + QVariant KisOpenGLCanvas2::inputMethodQuery(Qt::InputMethodQuery query) const { return processInputMethodQuery(query); @@ -823,10 +835,7 @@ drawCheckers(); drawImage(); - - KisConfig cfg; - - if ((coordinatesConverter()->effectiveZoom() > d->pixelGridDrawingThreshold - 0.00001) && cfg.pixelGridEnabled()) { + if ((coordinatesConverter()->effectiveZoom() > d->pixelGridDrawingThreshold - 0.00001) && d->pixelGridEnabled) { drawGrid(); } if (KisOpenGL::hasOpenGL3()) {