From d09923790ed18ac8d05effcc4dd0078f44fff27d Mon Sep 17 00:00:00 2001 From: lupoDharkael Date: Mon, 15 May 2017 21:38:34 +0200 Subject: [PATCH] Add logic dependency to global config --- capture/button.cpp | 19 +++++++++++++++++-- capture/button.h | 1 + capture/capturewidget.cpp | 8 +++++--- capture/capturewidget.h | 2 ++ controller.cpp | 14 +++++++++++--- graphics.qrc | 1 - main.cpp | 8 -------- styles/button.css | 13 ------------- 8 files changed, 36 insertions(+), 30 deletions(-) delete mode 100644 styles/button.css diff --git a/capture/button.cpp b/capture/button.cpp index ee7ca9d3..a50b6a6f 100644 --- a/capture/button.cpp +++ b/capture/button.cpp @@ -119,10 +119,25 @@ QIcon Button::getIcon(const Type t, bool isWhite) { } return QIcon(path); } + +QString Button::getStyle() { + QSettings settings; + QColor mainColor = settings.value("uiColor").value(); + QString baseSheet = "Button { border-radius: 15px;" + "background-color: %1; color: white }" + "Button:hover { background-color: %2; }" + "Button:pressed:!hover { " + "background-color: %1; }"; + QColor contrast(mainColor.darker(120)); + if (mainColor.name() < QColor(30,30,30).name()) { + contrast = contrast.lighter(120); + } + return baseSheet.arg(mainColor.name()).arg(contrast.name()); +} // get icon returns the icon for the type of button QIcon Button::getIcon(const Type t) { - // assign the isWhite based on the settings - bool isWhite = true; + QSettings settings; + bool isWhite = settings.value("whiteIconColor").toBool(); return getIcon(t, isWhite); } diff --git a/capture/button.h b/capture/button.h index 3f3aac22..8aaacae1 100644 --- a/capture/button.h +++ b/capture/button.h @@ -53,6 +53,7 @@ public: static QIcon getIcon(const Type); static QIcon getIcon(const Type, bool isWhite); + static QString getStyle(); static size_t getButtonBaseSize(); static Button::Type getTypeByName(QString); static QString getTypeName(Button::Type); diff --git a/capture/capturewidget.cpp b/capture/capturewidget.cpp index d0d8828c..1cf04282 100644 --- a/capture/capturewidget.cpp +++ b/capture/capturewidget.cpp @@ -81,6 +81,9 @@ CaptureWidget::CaptureWidget(QWidget *parent) : // init screenshot createCapture(); resize(m_screenshot.size()); + // initi interface color + m_uiColor = QSettings().value("uiColor").value(); + show(); } @@ -131,14 +134,13 @@ void CaptureWidget::paintEvent(QPaintEvent *) { if (!m_selection.isNull()) { // paint selection rect - QColor purpleColor(136, 0, 170, 220); - painter.setPen(purpleColor); + painter.setPen(m_uiColor); painter.setBrush(Qt::NoBrush); painter.drawRect(r); // paint handlers updateHandles(); - painter.setBrush(purpleColor); + painter.setBrush(m_uiColor); for(auto r: handleMask()) { painter.drawRoundRect(r, 100, 100); } diff --git a/capture/capturewidget.h b/capture/capturewidget.h index 5c99fe67..f4c6628e 100644 --- a/capture/capturewidget.h +++ b/capture/capturewidget.h @@ -106,6 +106,8 @@ private: Button::Type m_state; ButtonHandler *m_buttonHandler; + + QColor m_uiColor; }; #endif // CAPTUREWIDGET_H diff --git a/controller.cpp b/controller.cpp index 380fdd4b..34af752a 100644 --- a/controller.cpp +++ b/controller.cpp @@ -19,16 +19,19 @@ #include "capture/capturewidget.h" #include "infowindow.h" #include "configwindow.h" +#include "capture/button.h" #include #include #include #include #include +#include // Controller is the core component of Flameshot, creates the trayIcon and // launches the capture widget -Controller::Controller(QObject *parent) : QObject(parent) { +Controller::Controller(QObject *parent) : QObject(parent), + m_captureWindow(nullptr) { // required for the button serialization qRegisterMetaTypeStreamOperators >("QList"); createActions(); @@ -36,13 +39,16 @@ Controller::Controller(QObject *parent) : QObject(parent) { m_trayIcon->show(); initDefaults(); + qApp->setQuitOnLastWindowClosed(false); m_nativeEventFilter = new NativeEventFilter(this); qApp->installNativeEventFilter(m_nativeEventFilter); connect(m_nativeEventFilter, &NativeEventFilter::activated, this, &Controller::slotPrintHotkey); - m_captureWindow = nullptr; - qApp->setQuitOnLastWindowClosed(false); + + QString StyleSheet = Button::getStyle(); + qApp->setStyleSheet(StyleSheet); + } // creates the items of the trayIcon @@ -75,10 +81,12 @@ void Controller::createTrayIcon() { // initDefaults inits the global config in the very first run of the program void Controller::initDefaults() { QSettings settings; + //settings.setValue("initiated", false); // testing change if (!settings.value("initiated").toBool()) { settings.setValue("initiated", true); settings.setValue("drawColor", QColor(Qt::red)); settings.setValue("mouseVisible", false); + settings.setValue("whiteIconColor", true); settings.setValue("uiColor", QColor(136, 0, 170)); QList buttons; diff --git a/graphics.qrc b/graphics.qrc index e8fbb7ef..ead06c26 100644 --- a/graphics.qrc +++ b/graphics.qrc @@ -31,7 +31,6 @@ img/buttonIconsWhite/mouse-off.svg img/buttonIconsWhite/mouse.svg img/buttonIconsWhite/pencil.svg - styles/button.css img/buttonIconsBlack/cursor-move.svg img/buttonIconsWhite/cursor-move.svg diff --git a/main.cpp b/main.cpp index 20a7ad53..ff48f824 100644 --- a/main.cpp +++ b/main.cpp @@ -19,19 +19,11 @@ #include #include "singleapplication.h" -#include - int main(int argc, char *argv[]) { SingleApplication app(argc, argv); app.setApplicationName("flameshot"); app.setOrganizationName("Dharkael"); - QFile file(":/styles/button.css"); - if(file.open(QFile::ReadOnly)) { - QString StyleSheet = QLatin1String(file.readAll()); - app.setStyleSheet(StyleSheet); - } - Controller w; return app.exec(); diff --git a/styles/button.css b/styles/button.css deleted file mode 100644 index 23d7d66e..00000000 --- a/styles/button.css +++ /dev/null @@ -1,13 +0,0 @@ -Button { - border-radius: 15px; - background-color: rgb(136, 0, 170); - color: white -} - -Button:hover { - background-color: rgb(166, 0, 200); -} - -Button:pressed:!hover { - background-color: rgb(136, 0, 170); -}