Skip to content

Commit

Permalink
HiDPI decorations: simplify code.
Browse files Browse the repository at this point in the history
This adds a seperate function to test for which key got changed inside
the selection decoration so it doesn't constantly update when, say, the color changes.
  • Loading branch information
therahedwig committed Dec 26, 2023
1 parent 44e034a commit d37be27
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
9 changes: 3 additions & 6 deletions libs/ui/KisView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class Q_DECL_HIDDEN KisView::Private
m_connected = false;
}
}

private:
QWidget * m_widget = 0;
int m_stretch;
Expand Down Expand Up @@ -246,11 +247,7 @@ KisView::KisView(KisDocument *document, KisViewManager *viewManager, QWidget *pa
d->paintingAssistantsDecoration->setVisible(true);

d->showFloatingMessage = cfg.showCanvasMessages();
d->zoomManager.updateScreenResolution(this);
if (d->canvas.resourceManager() && d->screenMigrationTracker.currentScreen()) {
int penWidth = qRound(d->screenMigrationTracker.currentScreen()->devicePixelRatio());
d->canvas.resourceManager()->setDecorationThickness(qMax(penWidth, 1));
}
slotScreenOrResolutionChanged();

connect(document, SIGNAL(sigReadWriteChanged(bool)), this, SLOT(slotUpdateDocumentTitle()));
connect(document, SIGNAL(sigRecoveredChanged(bool)), this, SLOT(slotUpdateDocumentTitle()));
Expand Down Expand Up @@ -1227,7 +1224,7 @@ void KisView::slotScreenOrResolutionChanged()
d->zoomManager.updateScreenResolution(this);

if (d->canvas.resourceManager() && d->screenMigrationTracker.currentScreen()) {
int penWidth = d->screenMigrationTracker.currentScreen()->devicePixelRatio();
int penWidth = qRound(d->screenMigrationTracker.currentScreen()->devicePixelRatio());
d->canvas.resourceManager()->setDecorationThickness(qMax(penWidth, 1));
}
}
Expand Down
11 changes: 10 additions & 1 deletion libs/ui/kis_selection_decoration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ KisSelectionDecoration::KisSelectionDecoration(QPointer<KisView>_view)
m_offset(0),
m_mode(Ants)
{
connect(this->view()->canvasBase()->resourceManager(), SIGNAL(canvasResourceChanged(int, const QVariant&)), this, SLOT(initializePens()));
initializePens();
connect(this->view()->canvasBase()->resourceManager(), SIGNAL(canvasResourceChanged(int, const QVariant&)), this, SLOT(slotCanvasResourcesChanged(int, const QVariant&)));

connect(KisConfigNotifier::instance(), SIGNAL(configChanged()), SLOT(slotConfigChanged()));
connect(KisImageConfigNotifier::instance(), SIGNAL(configChanged()), SLOT(slotConfigChanged()));
Expand Down Expand Up @@ -161,6 +162,14 @@ void KisSelectionDecoration::slotConfigChanged()
m_antialiasSelectionOutline = cfg.antialiasSelectionOutline();
}

void KisSelectionDecoration::slotCanvasResourcesChanged(int key, const QVariant &v)
{
Q_UNUSED(v);
if (key == KoCanvasResource::DecorationThickness) {
initializePens();
}
}

void KisSelectionDecoration::antsAttackEvent()
{
KisSelectionSP selection = view()->selection();
Expand Down
1 change: 1 addition & 0 deletions libs/ui/kis_selection_decoration.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class KRITAUI_EXPORT KisSelectionDecoration : public KisCanvasDecoration
private Q_SLOTS:
void slotStartUpdateSelection();
void slotConfigChanged();
void slotCanvasResourcesChanged(int key, const QVariant &v);
void initializePens();

public Q_SLOTS:
Expand Down

0 comments on commit d37be27

Please sign in to comment.