feat: option to use light checkerboard by default

This commit is contained in:
Gary Wang 2024-10-10 22:58:11 +08:00
parent 3a5ead8cc2
commit 470a29c38c
No known key found for this signature in database
GPG Key ID: 5D30A4F15EA78760
6 changed files with 27 additions and 5 deletions

View File

@ -5,6 +5,7 @@
#include "graphicsview.h" #include "graphicsview.h"
#include "graphicsscene.h" #include "graphicsscene.h"
#include "settings.h"
#include <QDebug> #include <QDebug>
#include <QMouseEvent> #include <QMouseEvent>
@ -338,16 +339,16 @@ bool GraphicsView::shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) con
void GraphicsView::setCheckerboardEnabled(bool enabled, bool invertColor) void GraphicsView::setCheckerboardEnabled(bool enabled, bool invertColor)
{ {
m_checkerboardEnabled = enabled; m_checkerboardEnabled = enabled;
m_isLastCheckerboardColorInverted = invertColor; bool isLightCheckerboard = Settings::instance()->useLightCheckerboard() ^ invertColor;
if (m_checkerboardEnabled) { if (m_checkerboardEnabled) {
// Prepare background check-board pattern // Prepare background check-board pattern
QPixmap tilePixmap(0x20, 0x20); 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); QPainter tilePainter(&tilePixmap);
constexpr QColor color(45, 45, 45, 170); constexpr QColor color(45, 45, 45, 170);
constexpr QColor invertedColor(210, 210, 210, 170); constexpr QColor invertedColor(210, 210, 210, 170);
tilePainter.fillRect(0, 0, 0x10, 0x10, invertColor ? invertedColor : color); tilePainter.fillRect(0, 0, 0x10, 0x10, isLightCheckerboard ? invertedColor : color);
tilePainter.fillRect(0x10, 0x10, 0x10, 0x10, invertColor ? invertedColor : color); tilePainter.fillRect(0x10, 0x10, 0x10, 0x10, isLightCheckerboard ? invertedColor : color);
tilePainter.end(); tilePainter.end();
setBackgroundBrush(tilePixmap); setBackgroundBrush(tilePixmap);

View File

@ -70,7 +70,7 @@ private:
bool m_enableFitInView = false; bool m_enableFitInView = false;
bool m_avoidResetTransform = false; bool m_avoidResetTransform = false;
bool m_checkerboardEnabled = false; bool m_checkerboardEnabled = false;
bool m_isLastCheckerboardColorInverted = false; bool m_useLightCheckerboard = false;
}; };
#endif // GRAPHICSVIEW_H #endif // GRAPHICSVIEW_H

View File

@ -47,6 +47,11 @@ bool Settings::stayOnTop()
return m_qsettings->value("stay_on_top", true).toBool(); 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 Settings::DoubleClickBehavior Settings::doubleClickBehavior() const
{ {
QString result = m_qsettings->value("double_click_behavior", "Close").toString(); QString result = m_qsettings->value("double_click_behavior", "Close").toString();
@ -81,6 +86,12 @@ void Settings::setStayOnTop(bool on)
m_qsettings->sync(); m_qsettings->sync();
} }
void Settings::setUseLightCheckerboard(bool light)
{
m_qsettings->setValue("use_light_checkerboard", light);
m_qsettings->sync();
}
void Settings::setDoubleClickBehavior(DoubleClickBehavior dcb) void Settings::setDoubleClickBehavior(DoubleClickBehavior dcb)
{ {
m_qsettings->setValue("double_click_behavior", QEnumHelper::toString(dcb)); m_qsettings->setValue("double_click_behavior", QEnumHelper::toString(dcb));

View File

@ -33,12 +33,14 @@ public:
static Settings *instance(); static Settings *instance();
bool stayOnTop(); bool stayOnTop();
bool useLightCheckerboard();
DoubleClickBehavior doubleClickBehavior() const; DoubleClickBehavior doubleClickBehavior() const;
MouseWheelBehavior mouseWheelBehavior() const; MouseWheelBehavior mouseWheelBehavior() const;
WindowSizeBehavior initWindowSizeBehavior() const; WindowSizeBehavior initWindowSizeBehavior() const;
Qt::HighDpiScaleFactorRoundingPolicy hiDpiScaleFactorBehavior() const; Qt::HighDpiScaleFactorRoundingPolicy hiDpiScaleFactorBehavior() const;
void setStayOnTop(bool on); void setStayOnTop(bool on);
void setUseLightCheckerboard(bool light);
void setDoubleClickBehavior(DoubleClickBehavior dcb); void setDoubleClickBehavior(DoubleClickBehavior dcb);
void setMouseWheelBehavior(MouseWheelBehavior mwb); void setMouseWheelBehavior(MouseWheelBehavior mwb);
void setInitWindowSizeBehavior(WindowSizeBehavior wsb); void setInitWindowSizeBehavior(WindowSizeBehavior wsb);

View File

@ -14,6 +14,7 @@
SettingsDialog::SettingsDialog(QWidget *parent) SettingsDialog::SettingsDialog(QWidget *parent)
: QDialog(parent) : QDialog(parent)
, m_stayOnTop(new QCheckBox) , m_stayOnTop(new QCheckBox)
, m_useLightCheckerboard(new QCheckBox)
, m_doubleClickBehavior(new QComboBox) , m_doubleClickBehavior(new QComboBox)
, m_mouseWheelBehavior(new QComboBox) , m_mouseWheelBehavior(new QComboBox)
, m_initWindowSizeBehavior(new QComboBox) , m_initWindowSizeBehavior(new QComboBox)
@ -67,12 +68,14 @@ SettingsDialog::SettingsDialog(QWidget *parent)
} }
settingsForm->addRow(tr("Stay on top when start-up"), m_stayOnTop); 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("Double-click behavior"), m_doubleClickBehavior);
settingsForm->addRow(tr("Mouse wheel behavior"), m_mouseWheelBehavior); settingsForm->addRow(tr("Mouse wheel behavior"), m_mouseWheelBehavior);
settingsForm->addRow(tr("Default window size"), m_initWindowSizeBehavior); settingsForm->addRow(tr("Default window size"), m_initWindowSizeBehavior);
settingsForm->addRow(tr("HiDPI scale factor rounding policy"), m_hiDpiRoundingPolicyBehavior); settingsForm->addRow(tr("HiDPI scale factor rounding policy"), m_hiDpiRoundingPolicyBehavior);
m_stayOnTop->setChecked(Settings::instance()->stayOnTop()); m_stayOnTop->setChecked(Settings::instance()->stayOnTop());
m_useLightCheckerboard->setChecked(Settings::instance()->useLightCheckerboard());
m_doubleClickBehavior->setModel(new QStringListModel(dcbDropDown)); m_doubleClickBehavior->setModel(new QStringListModel(dcbDropDown));
Settings::DoubleClickBehavior dcb = Settings::instance()->doubleClickBehavior(); Settings::DoubleClickBehavior dcb = Settings::instance()->doubleClickBehavior();
m_doubleClickBehavior->setCurrentIndex(static_cast<int>(dcb)); m_doubleClickBehavior->setCurrentIndex(static_cast<int>(dcb));
@ -95,6 +98,10 @@ SettingsDialog::SettingsDialog(QWidget *parent)
Settings::instance()->setStayOnTop(state == Qt::Checked); 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){ connect(m_doubleClickBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
Settings::instance()->setDoubleClickBehavior(_dc_options.at(index).first); Settings::instance()->setDoubleClickBehavior(_dc_options.at(index).first);
}); });

View File

@ -23,6 +23,7 @@ public slots:
private: private:
QCheckBox * m_stayOnTop = nullptr; QCheckBox * m_stayOnTop = nullptr;
QCheckBox * m_useLightCheckerboard = nullptr;
QComboBox * m_doubleClickBehavior = nullptr; QComboBox * m_doubleClickBehavior = nullptr;
QComboBox * m_mouseWheelBehavior = nullptr; QComboBox * m_mouseWheelBehavior = nullptr;
QComboBox * m_initWindowSizeBehavior = nullptr; QComboBox * m_initWindowSizeBehavior = nullptr;