Skip to content

Commit

Permalink
Allow changing the background color behind canvas
Browse files Browse the repository at this point in the history
Rather than it being fixed to #646464.
  • Loading branch information
askmeaboutlo0m committed Sep 11, 2023
1 parent 1dc8d74 commit 91b99ef
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Unreleased Version 2.2.0-pre
* Feature: Capture volume rocker on Android and bind it to undo and redo by default. Thanks to cl for suggesting.
* Feature: Add compatibility for Drawpile 2.1's broken indirect mode.
* Fix: Make the receive delay not delay your own undos.
* Feature: Add a setting for the background color behind the canvas. Thanks to Nightshade for suggesting.

2023-08-26 Version 2.2.0-beta.7
* Fix: Make classic brushes not go brighter when smudging into transparency. Thanks to cada for reporting.
Expand Down
29 changes: 29 additions & 0 deletions src/desktop/dialogs/settingsdialog/userinterface.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "desktop/dialogs/settingsdialog/userinterface.h"
#include "desktop/dialogs/colordialog.h"
#include "desktop/settings.h"
#include "desktop/utils/sanerformlayout.h"
#include "desktop/utils/widgetutils.h"
#include "desktop/widgets/kis_slider_spin_box.h"
#include <QtColorWidgets/ColorPreview>
#include <QButtonGroup>
#include <QCheckBox>
#include <QComboBox>
Expand Down Expand Up @@ -130,6 +132,21 @@ void UserInterface::initKineticScrolling(
void UserInterface::initMiscellaneous(
desktop::settings::Settings &settings, utils::SanerFormLayout *form)
{
using color_widgets::ColorPreview;
ColorPreview *colorPreview = new ColorPreview;
colorPreview->setDisplayMode(ColorPreview::DisplayMode::NoAlpha);
colorPreview->setToolTip(tr("Background color behind the canvas"));
colorPreview->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
colorPreview->setCursor(Qt::PointingHandCursor);
form->addRow(tr("Color behind canvas:"), colorPreview);
settings.bindCanvasViewBackgroundColor(this, [colorPreview](const QColor &color) {
colorPreview->setColor(color);
});

connect(
colorPreview, &ColorPreview::clicked, this,
[this, &settings] { pickCanvasBackgroundColor(settings); });

QCheckBox *scrollBars = new QCheckBox(tr("Show scroll bars on canvas"));
settings.bindCanvasScrollBars(scrollBars);
form->addRow(tr("Miscellaneous:"), scrollBars);
Expand All @@ -139,5 +156,17 @@ void UserInterface::initMiscellaneous(
form->addRow(nullptr, confirmDelete);
}

void UserInterface::pickCanvasBackgroundColor(desktop::settings::Settings &settings)
{
using color_widgets::ColorDialog;
ColorDialog dlg;
dlg.setColor(settings.canvasViewBackgroundColor());
dlg.setAlphaEnabled(false);
dialogs::applyColorDialogSettings(&dlg);
if(dlg.exec() == QDialog::Accepted) {
settings.setCanvasViewBackgroundColor(dlg.color());
}
}

}
}
1 change: 1 addition & 0 deletions src/desktop/dialogs/settingsdialog/userinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class UserInterface final : public QWidget {
desktop::settings::Settings &settings, utils::SanerFormLayout *form);
void initMiscellaneous(
desktop::settings::Settings &settings, utils::SanerFormLayout *form);
void pickCanvasBackgroundColor(desktop::settings::Settings &settings);
};

}
Expand Down
9 changes: 6 additions & 3 deletions src/desktop/scene/canvasview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ CanvasView::CanvasView(QWidget *parent)
setAcceptDrops(true);
setFrameShape(QFrame::NoFrame);

setBackgroundBrush(QColor(100, 100, 100));
auto &settings = dpApp().settings();
settings.bindCanvasViewBackgroundColor(this, [this](QColor color) {
color.setAlpha(255);
setBackgroundBrush(color);
invalidateScene(QRectF{}, QGraphicsScene::BackgroundLayer);
});

m_notificationBar = new NotificationBar(this);
connect(
Expand Down Expand Up @@ -107,8 +112,6 @@ CanvasView::CanvasView(QWidget *parent)
m_dotcursor = QCursor(dot, 0, 0);
}

auto &settings = dpApp().settings();

settings.bindTabletEvents(this, &widgets::CanvasView::setTabletEnabled);
settings.bindOneFingerDraw(this, &widgets::CanvasView::setTouchDraw);
settings.bindOneFingerScroll(this, &widgets::CanvasView::setTouchScroll);
Expand Down
1 change: 1 addition & 0 deletions src/desktop/settings_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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(canvasScrollBars , CanvasScrollBars , "settings/canvasscrollbars" , true)
SETTING(canvasShortcuts , CanvasShortcuts , "settings/canvasshortcuts2" , QVariantMap())
#ifdef Q_OS_ANDROID
Expand Down

0 comments on commit 91b99ef

Please sign in to comment.