Skip to content

Commit

Permalink
feat: option to use light checkerboard by default
Browse files Browse the repository at this point in the history
  • Loading branch information
BLumia committed Oct 10, 2024
1 parent 3a5ead8 commit 470a29c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
9 changes: 5 additions & 4 deletions app/graphicsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "graphicsview.h"

#include "graphicsscene.h"
#include "settings.h"

#include <QDebug>
#include <QMouseEvent>
Expand Down Expand Up @@ -338,16 +339,16 @@ bool GraphicsView::shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) con
void GraphicsView::setCheckerboardEnabled(bool enabled, bool invertColor)
{
m_checkerboardEnabled = enabled;
m_isLastCheckerboardColorInverted = invertColor;
bool isLightCheckerboard = Settings::instance()->useLightCheckerboard() ^ invertColor;
if (m_checkerboardEnabled) {
// Prepare background check-board pattern
QPixmap tilePixmap(0x20, 0x20);
tilePixmap.fill(invertColor ? QColor(220, 220, 220, 170) : QColor(35, 35, 35, 170));
tilePixmap.fill(isLightCheckerboard ? QColor(220, 220, 220, 170) : QColor(35, 35, 35, 170));
QPainter tilePainter(&tilePixmap);
constexpr QColor color(45, 45, 45, 170);
constexpr QColor invertedColor(210, 210, 210, 170);
tilePainter.fillRect(0, 0, 0x10, 0x10, invertColor ? invertedColor : color);
tilePainter.fillRect(0x10, 0x10, 0x10, 0x10, invertColor ? invertedColor : color);
tilePainter.fillRect(0, 0, 0x10, 0x10, isLightCheckerboard ? invertedColor : color);
tilePainter.fillRect(0x10, 0x10, 0x10, 0x10, isLightCheckerboard ? invertedColor : color);
tilePainter.end();

setBackgroundBrush(tilePixmap);
Expand Down
2 changes: 1 addition & 1 deletion app/graphicsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public slots:
bool m_enableFitInView = false;
bool m_avoidResetTransform = false;
bool m_checkerboardEnabled = false;
bool m_isLastCheckerboardColorInverted = false;
bool m_useLightCheckerboard = false;
};

#endif // GRAPHICSVIEW_H
11 changes: 11 additions & 0 deletions app/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ bool Settings::stayOnTop()
return m_qsettings->value("stay_on_top", true).toBool();
}

bool Settings::useLightCheckerboard()
{
return m_qsettings->value("use_light_checkerboard", false).toBool();
}

Settings::DoubleClickBehavior Settings::doubleClickBehavior() const
{
QString result = m_qsettings->value("double_click_behavior", "Close").toString();
Expand Down Expand Up @@ -81,6 +86,12 @@ void Settings::setStayOnTop(bool on)
m_qsettings->sync();
}

void Settings::setUseLightCheckerboard(bool light)
{
m_qsettings->setValue("use_light_checkerboard", light);
m_qsettings->sync();
}

void Settings::setDoubleClickBehavior(DoubleClickBehavior dcb)
{
m_qsettings->setValue("double_click_behavior", QEnumHelper::toString(dcb));
Expand Down
2 changes: 2 additions & 0 deletions app/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ class Settings : public QObject
static Settings *instance();

bool stayOnTop();
bool useLightCheckerboard();
DoubleClickBehavior doubleClickBehavior() const;
MouseWheelBehavior mouseWheelBehavior() const;
WindowSizeBehavior initWindowSizeBehavior() const;
Qt::HighDpiScaleFactorRoundingPolicy hiDpiScaleFactorBehavior() const;

void setStayOnTop(bool on);
void setUseLightCheckerboard(bool light);
void setDoubleClickBehavior(DoubleClickBehavior dcb);
void setMouseWheelBehavior(MouseWheelBehavior mwb);
void setInitWindowSizeBehavior(WindowSizeBehavior wsb);
Expand Down
7 changes: 7 additions & 0 deletions app/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
SettingsDialog::SettingsDialog(QWidget *parent)
: QDialog(parent)
, m_stayOnTop(new QCheckBox)
, m_useLightCheckerboard(new QCheckBox)
, m_doubleClickBehavior(new QComboBox)
, m_mouseWheelBehavior(new QComboBox)
, m_initWindowSizeBehavior(new QComboBox)
Expand Down Expand Up @@ -67,12 +68,14 @@ SettingsDialog::SettingsDialog(QWidget *parent)
}

settingsForm->addRow(tr("Stay on top when start-up"), m_stayOnTop);
settingsForm->addRow(tr("Use light-color checkerboard"), m_useLightCheckerboard);
settingsForm->addRow(tr("Double-click behavior"), m_doubleClickBehavior);
settingsForm->addRow(tr("Mouse wheel behavior"), m_mouseWheelBehavior);
settingsForm->addRow(tr("Default window size"), m_initWindowSizeBehavior);
settingsForm->addRow(tr("HiDPI scale factor rounding policy"), m_hiDpiRoundingPolicyBehavior);

m_stayOnTop->setChecked(Settings::instance()->stayOnTop());
m_useLightCheckerboard->setChecked(Settings::instance()->useLightCheckerboard());
m_doubleClickBehavior->setModel(new QStringListModel(dcbDropDown));
Settings::DoubleClickBehavior dcb = Settings::instance()->doubleClickBehavior();
m_doubleClickBehavior->setCurrentIndex(static_cast<int>(dcb));
Expand All @@ -95,6 +98,10 @@ SettingsDialog::SettingsDialog(QWidget *parent)
Settings::instance()->setStayOnTop(state == Qt::Checked);
});

connect(m_useLightCheckerboard, &QCheckBox::stateChanged, this, [ = ](int state){
Settings::instance()->setUseLightCheckerboard(state == Qt::Checked);
});

connect(m_doubleClickBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
Settings::instance()->setDoubleClickBehavior(_dc_options.at(index).first);
});
Expand Down
1 change: 1 addition & 0 deletions app/settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public slots:

private:
QCheckBox * m_stayOnTop = nullptr;
QCheckBox * m_useLightCheckerboard = nullptr;
QComboBox * m_doubleClickBehavior = nullptr;
QComboBox * m_mouseWheelBehavior = nullptr;
QComboBox * m_initWindowSizeBehavior = nullptr;
Expand Down

0 comments on commit 470a29c

Please sign in to comment.