mirror of
https://github.com/fergalmoran/flameshot.git
synced 2025-12-22 09:51:06 +00:00
Add logic dependency to global config
This commit is contained in:
@@ -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<QColor>();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -81,6 +81,9 @@ CaptureWidget::CaptureWidget(QWidget *parent) :
|
||||
// init screenshot
|
||||
createCapture();
|
||||
resize(m_screenshot.size());
|
||||
// initi interface color
|
||||
m_uiColor = QSettings().value("uiColor").value<QColor>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -106,6 +106,8 @@ private:
|
||||
|
||||
Button::Type m_state;
|
||||
ButtonHandler *m_buttonHandler;
|
||||
|
||||
QColor m_uiColor;
|
||||
};
|
||||
|
||||
#endif // CAPTUREWIDGET_H
|
||||
|
||||
@@ -19,16 +19,19 @@
|
||||
#include "capture/capturewidget.h"
|
||||
#include "infowindow.h"
|
||||
#include "configwindow.h"
|
||||
#include "capture/button.h"
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QMenu>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QSettings>
|
||||
#include <QFile>
|
||||
|
||||
// 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<int> >("QList<int>");
|
||||
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<int> buttons;
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
<file>img/buttonIconsWhite/mouse-off.svg</file>
|
||||
<file>img/buttonIconsWhite/mouse.svg</file>
|
||||
<file>img/buttonIconsWhite/pencil.svg</file>
|
||||
<file>styles/button.css</file>
|
||||
<file>img/buttonIconsBlack/cursor-move.svg</file>
|
||||
<file>img/buttonIconsWhite/cursor-move.svg</file>
|
||||
</qresource>
|
||||
|
||||
8
main.cpp
8
main.cpp
@@ -19,19 +19,11 @@
|
||||
#include <QApplication>
|
||||
#include "singleapplication.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user