Skip to content

Commit

Permalink
Allow resetting canvas view background to default
Browse files Browse the repository at this point in the history
By using the Reset button inside the color dialog. Also shows the
preview in a split view, to make it more clear what the reset button
does.
  • Loading branch information
askmeaboutlo0m committed Sep 12, 2023
1 parent 91b99ef commit 102109c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/desktop/dialogs/colordialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "desktop/main.h"
#include <QtColorWidgets/ColorDialog>
#include <QtColorWidgets/ColorPreview>

namespace dialogs {

Expand All @@ -14,6 +15,18 @@ void applyColorDialogSettings(color_widgets::ColorDialog *dlg)
settings.bindColorWheelMirror(dlg, &color_widgets::ColorDialog::setWheelMirrored);
}

void setColorDialogResetColor(color_widgets::ColorDialog *dlg, const QColor &color)
{
color_widgets::ColorPreview *preview = dlg->findChild<color_widgets::ColorPreview *>(
QStringLiteral("preview"), Qt::FindDirectChildrenOnly);
if(preview) {
preview->setComparisonColor(color);
preview->setDisplayMode(color_widgets::ColorPreview::SplitColor);
} else {
qWarning("Preview not found in color dialog, reset color not set");
}
}

color_widgets::ColorDialog *newColorDialog(QWidget *parent)
{
color_widgets::ColorDialog *dlg = new color_widgets::ColorDialog{parent};
Expand Down
5 changes: 5 additions & 0 deletions src/desktop/dialogs/colordialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ namespace dialogs {
// Applies the user's color wheel settings to the given color dialog.
void applyColorDialogSettings(color_widgets::ColorDialog *dlg);

// Sets the color that the Reset button inside the dialog will reset to.
// Also changes the preview to split mode, to make it clear what reset will do.
void setColorDialogResetColor(
color_widgets::ColorDialog *dlg, const QColor &color);

// Makes a color dialog with the user's color wheel settings applied.
color_widgets::ColorDialog *
newColorDialog(QWidget *parent);
Expand Down
1 change: 1 addition & 0 deletions src/desktop/dialogs/settingsdialog/userinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ void UserInterface::pickCanvasBackgroundColor(desktop::settings::Settings &setti
dlg.setColor(settings.canvasViewBackgroundColor());
dlg.setAlphaEnabled(false);
dialogs::applyColorDialogSettings(&dlg);
dialogs::setColorDialogResetColor(&dlg, CANVAS_VIEW_BACKGROUND_COLOR_DEFAULT);
if(dlg.exec() == QDialog::Accepted) {
settings.setCanvasViewBackgroundColor(dlg.color());
}
Expand Down
4 changes: 3 additions & 1 deletion src/desktop/settings_table.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "libclient/settings_table_macros.h"

#define CANVAS_VIEW_BACKGROUND_COLOR_DEFAULT QColor(100, 100, 100)

#ifndef KINETIC_SCROLL_GESTURE_DEFAULT
# ifdef Q_OS_ANDROID
# define KINETIC_SCROLL_GESTURE_DEFAULT KineticScrollGesture::LeftClick
Expand Down Expand Up @@ -34,7 +36,7 @@

SETTING(brushCursor , BrushCursor , "settings/brushcursor" , widgets::CanvasView::BrushCursor::TriangleRight)
SETTING(brushOutlineWidth , BrushOutlineWidth , "settings/brushoutlinewidth" , 1.0)
SETTING(canvasViewBackgroundColor , CanvasViewBackgroundColor , "settings/canvasviewbackgroundcolor" , QColor(100, 100, 100))
SETTING(canvasViewBackgroundColor , CanvasViewBackgroundColor , "settings/canvasviewbackgroundcolor" , CANVAS_VIEW_BACKGROUND_COLOR_DEFAULT)
SETTING(canvasScrollBars , CanvasScrollBars , "settings/canvasscrollbars" , true)
SETTING(canvasShortcuts , CanvasShortcuts , "settings/canvasshortcuts2" , QVariantMap())
#ifdef Q_OS_ANDROID
Expand Down

0 comments on commit 102109c

Please sign in to comment.