Commit 95b2c02b authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Fix syncing pixel grid state between windows once again

Summary:
This patch extends commit1a47ae24 and
addresses the following issues:

1) The state of the menu action checkbox was not updated when the other
   window changed the its state
2) There should be **no** access to KisConfig in the OpenGL rendering
   loop (it is slow due to possible disk access).
3) A canvas update call should be issued right after the config changed,
   otherwise the old state of the grid will be visible until one hovers
   the canvas

BUG: 389033

Test Plan:
1) Open multiple Krita windows and zoom both of them to 1000%
2) Change View->Show Pixel Grid in one of the windows
3) The state on the checkbox and the canvas should automatically
   update in the other window

Reviewers: #krita, scottpetrovic

Differential Revision: https://phabricator.kde.org/D10171
parent 2a254dc4
......@@ -619,6 +619,7 @@ void KisMainWindow::slotPreferences()
{
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?
......
......@@ -134,6 +134,7 @@
#include "dialogs/kis_delayed_save_dialog.h"
#include <kis_image.h>
#include <KisMainWindow.h>
#include "kis_signals_blocker.h"
class BlockingUserInputEventFilter : public QObject
......@@ -314,6 +315,7 @@ KisViewManager::KisViewManager(QWidget *parent, KActionCollection *_actionCollec
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 @@ void KisViewManager::setCurrentView(KisView *view)
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 @@ void KisViewManager::createActions()
actionCollection()->addAction("settings_active_author", d->actionAuthor);
slotUpdateAuthorProfileActions();
d->showPixelGrid = actionManager()->createAction("view_pixel_grid");
slotUpdatePixelGridAction();
}
void KisViewManager::setupManagers()
......@@ -1386,3 +1392,13 @@ void KisViewManager::slotUpdateAuthorProfileActions()
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());
}
......@@ -255,6 +255,7 @@ private Q_SLOTS:
void guiUpdateTimeout();
void changeAuthorProfile(const QString &profileName);
void slotUpdateAuthorProfileActions();
void slotUpdatePixelGridAction();
void slotSaveShowRulersState(bool value);
void slotSaveRulersTrackMouseState(bool value);
......
......@@ -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 @@ bool KisCanvasController::wrapAroundMode() const
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<KisCanvas2*>(canvas());
......
......@@ -58,6 +58,7 @@ public Q_SLOTS:
qreal rotation() const;
void resetCanvasRotation();
void slotToggleWrapAroundMode(bool value);
void slotTogglePixelGrid(bool value);
void slotToggleLevelOfDetailMode(bool value);
Q_SIGNALS:
......
......@@ -56,3 +56,8 @@ void KisConfigNotifier::notifyDropFramesModeChanged()
{
m_d->dropFramesModeCompressor.start();
}
void KisConfigNotifier::notifyPixelGridModeChanged()
{
emit pixelGridModeChanged();
}
......@@ -46,6 +46,7 @@ public:
void notifyConfigChanged(void);
void notifyDropFramesModeChanged();
void notifyPixelGridModeChanged();
Q_SIGNALS:
/**
......@@ -53,6 +54,7 @@ Q_SIGNALS:
*/
void configChanged(void);
void dropFramesModeChanged();
void pixelGridModeChanged();
private:
KisConfigNotifier(const KisConfigNotifier&);
KisConfigNotifier operator=(const KisConfigNotifier&);
......
......@@ -399,11 +399,6 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char *
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::slotSetPaintop(const QString& paintOpId)
}
}
void KisPaintopBox::slotEnableShowPixelGrid(bool enabled)
{
KisConfig cfg;
cfg.enablePixelGrid(enabled);
}
void KisPaintopBox::slotInputDeviceChanged(const KoInputDevice& inputDevice)
{
TabletToolMap::iterator toolData = m_tabletToolMap.find(inputDevice);
......
......@@ -122,7 +122,6 @@ public Q_SLOTS:
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 @@ private:
KisAction* m_eraseAction;
KisAction* m_reloadAction;
KisAction* m_disablePressureAction;
KisAction* m_showPixelGridAction;
QString m_currCompositeOpID;
KisNodeWSP m_previousNode;
......
......@@ -107,6 +107,7 @@ public:
#endif
qreal pixelGridDrawingThreshold;
bool pixelGridEnabled;
QColor gridColor;
QColor cursorColor;
......@@ -168,7 +169,9 @@ KisOpenGLCanvas2::KisOpenGLCanvas2(KisCanvas2 *canvas,
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 @@ void KisOpenGLCanvas2::slotConfigChanged()
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 @@ void KisOpenGLCanvas2::renderCanvasGL()
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()) {
......
......@@ -102,6 +102,7 @@ public: // Implement kis_abstract_canvas_widget interface
public Q_SLOTS:
void slotConfigChanged();
void slotPixelGridModeChanged();
protected: // KisCanvasWidgetBase
bool callFocusNextPrevChild(bool next) override;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment