diff --git a/flameshot.pro b/flameshot.pro index 3ebba2cb..585de50a 100644 --- a/flameshot.pro +++ b/flameshot.pro @@ -121,7 +121,8 @@ SOURCES += src/main.cpp \ src/utils/desktopfileparse.cpp \ src/capture/workers/launcher/launcheritemdelegate.cpp \ src/capture/tools/blurtool.cpp \ - src/capture/workers/launcher/terminallauncher.cpp + src/capture/workers/launcher/terminallauncher.cpp \ + src/config/visualseditor.cpp HEADERS += src/capture/widget/buttonhandler.h \ src/infowindow.h \ @@ -175,7 +176,8 @@ HEADERS += src/capture/widget/buttonhandler.h \ src/utils/desktopfileparse.h \ src/capture/workers/launcher/launcheritemdelegate.h \ src/capture/tools/blurtool.h \ - src/capture/workers/launcher/terminallauncher.h + src/capture/workers/launcher/terminallauncher.h \ + src/config/visualseditor.h unix:!macx { SOURCES += src/core/flameshotdbusadapter.cpp \ diff --git a/src/capture/widget/capturewidget.cpp b/src/capture/widget/capturewidget.cpp index 2b93ef98..2f11394d 100644 --- a/src/capture/widget/capturewidget.cpp +++ b/src/capture/widget/capturewidget.cpp @@ -59,6 +59,7 @@ CaptureWidget::CaptureWidget(const uint id, const QString &forcedSavePath, { m_showInitialMsg = m_config.showHelpValue(); m_thickness = m_config.drawThicknessValue(); + m_opacity = m_config.contrastOpacityValue(); setAttribute(Qt::WA_DeleteOnClose); // create selection handlers @@ -179,7 +180,7 @@ void CaptureWidget::paintEvent(QPaintEvent *) { painter.drawPixmap(0, 0, m_screenshot->screenshot()); } - QColor overlayColor(0, 0, 0, 190); + QColor overlayColor(0, 0, 0, m_opacity); painter.setBrush(overlayColor); QRect r = m_selection.normalized().adjusted(0, 0, -1, -1); QRegion grey(rect()); diff --git a/src/capture/widget/capturewidget.h b/src/capture/widget/capturewidget.h index 9058b140..afa739d7 100644 --- a/src/capture/widget/capturewidget.h +++ b/src/capture/widget/capturewidget.h @@ -101,6 +101,7 @@ protected: const QString m_forcedSavePath; int m_thickness; + int m_opacity; uint m_id; NotifierBox *m_notifierBox; diff --git a/src/config/configwindow.cpp b/src/config/configwindow.cpp index c78baf73..b26e8e33 100644 --- a/src/config/configwindow.cpp +++ b/src/config/configwindow.cpp @@ -17,12 +17,11 @@ #include "configwindow.h" #include "src/capture/widget/capturebutton.h" -#include "src/config/buttonlistview.h" -#include "src/config/uicoloreditor.h" #include "src/config/geneneralconf.h" #include "src/config/filenameeditor.h" #include "src/config/strftimechooserwidget.h" #include "src/utils/confighandler.h" +#include "src/config/visualseditor.h" #include #include #include @@ -54,25 +53,8 @@ ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) { QString modifier = isWhite ? ":img/configWhite/" : ":img/configBlack/"; // visuals - auto visuals = new QWidget(); - QVBoxLayout *layoutUI= new QVBoxLayout(); - visuals->setLayout(layoutUI); - m_colorEditor = new UIcolorEditor(); - layoutUI->addWidget(m_colorEditor); - - auto boxButtons = new QGroupBox(); - boxButtons->setTitle(tr("Button Selection")); - auto listLayout = new QVBoxLayout(boxButtons); - m_buttonList = new ButtonListView(); - layoutUI->addWidget(boxButtons); - listLayout->addWidget(m_buttonList); - - QPushButton* setAllButtons = new QPushButton(tr("Select All")); - connect(setAllButtons, &QPushButton::clicked, - m_buttonList, &ButtonListView::selectAll); - listLayout->addWidget(setAllButtons); - - addTab(visuals, QIcon(modifier + "graphics.png"), + m_visuals = new VisualsEditor(); + addTab(m_visuals, QIcon(modifier + "graphics.png"), tr("Interface")); // filename @@ -89,9 +71,7 @@ ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) { connect(this, &ConfigWindow::updateChildren, m_filenameEditor, &FileNameEditor::updateComponents); connect(this, &ConfigWindow::updateChildren, - m_colorEditor, &UIcolorEditor::updateComponents); - connect(this, &ConfigWindow::updateChildren, - m_buttonList, &ButtonListView::updateComponents); + m_visuals, &VisualsEditor::updateComponents); connect(this, &ConfigWindow::updateChildren, m_generalConfig, &GeneneralConf::updateComponents); } diff --git a/src/config/configwindow.h b/src/config/configwindow.h index d15aee1e..8465bbdc 100644 --- a/src/config/configwindow.h +++ b/src/config/configwindow.h @@ -20,11 +20,10 @@ #include -class ButtonListView; -class UIcolorEditor; class FileNameEditor; class GeneneralConf; class QFileSystemWatcher; +class VisualsEditor; class ConfigWindow : public QTabWidget { Q_OBJECT @@ -38,11 +37,9 @@ protected: void keyPressEvent(QKeyEvent *); private: - ButtonListView *m_buttonList; - UIcolorEditor *m_colorEditor; FileNameEditor *m_filenameEditor; GeneneralConf *m_generalConfig; - + VisualsEditor *m_visuals; QFileSystemWatcher *m_configWatcher; }; diff --git a/src/config/filenameeditor.cpp b/src/config/filenameeditor.cpp index 4b12b62d..9adc3054 100644 --- a/src/config/filenameeditor.cpp +++ b/src/config/filenameeditor.cpp @@ -25,7 +25,7 @@ #include #include -FileNameEditor::FileNameEditor(QWidget *parent) : QGroupBox(parent) { +FileNameEditor::FileNameEditor(QWidget *parent) : QWidget(parent) { initWidgets(); initLayout(); } diff --git a/src/config/filenameeditor.h b/src/config/filenameeditor.h index 3a4374e1..0d1c5586 100644 --- a/src/config/filenameeditor.h +++ b/src/config/filenameeditor.h @@ -18,7 +18,7 @@ #ifndef FILENAMEEDITOR_H #define FILENAMEEDITOR_H -#include +#include #include class QVBoxLayout; @@ -27,7 +27,7 @@ class FileNameHandler; class QPushButton; class StrftimeChooserWidget; -class FileNameEditor : public QGroupBox +class FileNameEditor : public QWidget { Q_OBJECT public: diff --git a/src/config/geneneralconf.cpp b/src/config/geneneralconf.cpp index 17850ef1..84646cfc 100644 --- a/src/config/geneneralconf.cpp +++ b/src/config/geneneralconf.cpp @@ -29,7 +29,7 @@ #include #include -GeneneralConf::GeneneralConf(QWidget *parent) : QGroupBox(parent) { +GeneneralConf::GeneneralConf(QWidget *parent) : QWidget(parent) { m_layout = new QVBoxLayout(this); m_layout->setAlignment(Qt::AlignTop); initShowHelp(); @@ -37,7 +37,8 @@ GeneneralConf::GeneneralConf(QWidget *parent) : QGroupBox(parent) { initShowTrayIcon(); initAutostart(); - initConfingButtons(); + // this has to be at the end + initConfingButtons(); updateComponents(); } @@ -46,6 +47,7 @@ void GeneneralConf::updateComponents() { m_helpMessage->setChecked(config.showHelpValue()); m_sysNotifications->setChecked(config.desktopNotificationValue()); m_autostart->setChecked(config.startupLaunchValue()); + #ifdef Q_OS_LINUX m_showTray->setChecked(!config.disabledTrayIconValue()); #endif @@ -92,7 +94,7 @@ void GeneneralConf::importConfiguration() { config.close(); } -void GeneneralConf::exportConfiguration() { +void GeneneralConf::exportFileConfiguration() { QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "flameshot.conf"); QFile::copy(ConfigHandler().configFilePath(), fileName); @@ -106,9 +108,10 @@ void GeneneralConf::resetConfiguration() { QMessageBox::Yes | QMessageBox::No); if (reply == QMessageBox::Yes) { ConfigHandler().setDefaults(); - } + } } + void GeneneralConf::initShowHelp() { m_helpMessage = new QCheckBox(tr("Show help message"), this); ConfigHandler config; @@ -150,7 +153,6 @@ void GeneneralConf::initShowTrayIcon() { } void GeneneralConf::initConfingButtons() { - QHBoxLayout *buttonLayout = new QHBoxLayout(); m_layout->addStretch(); QGroupBox *box = new QGroupBox(tr("Configuration File")); @@ -161,7 +163,7 @@ void GeneneralConf::initConfingButtons() { m_exportButton = new QPushButton(tr("Export")); buttonLayout->addWidget(m_exportButton); connect(m_exportButton, &QPushButton::clicked, this, - &GeneneralConf::exportConfiguration); + &GeneneralConf::exportFileConfiguration); m_importButton = new QPushButton(tr("Import")); buttonLayout->addWidget(m_importButton); diff --git a/src/config/geneneralconf.h b/src/config/geneneralconf.h index a1191da5..09da62be 100644 --- a/src/config/geneneralconf.h +++ b/src/config/geneneralconf.h @@ -18,13 +18,13 @@ #ifndef GENENERALCONF_H #define GENENERALCONF_H -#include +#include class QVBoxLayout; class QCheckBox; class QPushButton; -class GeneneralConf : public QGroupBox { +class GeneneralConf : public QWidget { Q_OBJECT public: GeneneralConf(QWidget *parent = nullptr); @@ -38,7 +38,7 @@ private slots: void showTrayIconChanged(bool checked); void autostartChanged(bool checked); void importConfiguration(); - void exportConfiguration(); + void exportFileConfiguration(); void resetConfiguration(); private: diff --git a/src/config/visualseditor.cpp b/src/config/visualseditor.cpp new file mode 100644 index 00000000..3a25c789 --- /dev/null +++ b/src/config/visualseditor.cpp @@ -0,0 +1,69 @@ +#include "visualseditor.h" +#include "src/config/buttonlistview.h" +#include "src/config/uicoloreditor.h" +#include "src/utils/confighandler.h" +#include +#include +#include +#include + +VisualsEditor::VisualsEditor(QWidget *parent) : QWidget(parent) +{ + m_layout= new QVBoxLayout(); + setLayout(m_layout); + initWidgets(); +} + +void VisualsEditor::updateComponents() { + m_buttonList->updateComponents(); + m_colorEditor->updateComponents(); + m_opacity = ConfigHandler().contrastOpacityValue(); + m_opacitySlider->setValue(m_opacity); +} + +void VisualsEditor::initOpacitySlider() { + QLabel *label = new QLabel(tr("Opacity of area outside selection:")); + m_layout->addWidget(label); + + m_opacitySlider = new QSlider(Qt::Horizontal); + m_opacitySlider->setRange(0, 255); + connect(m_opacitySlider, &QSlider::sliderMoved, + this, &VisualsEditor::updateOpacity); + connect(m_opacitySlider, &QSlider::sliderReleased, + this, &VisualsEditor::saveOpacity); + QHBoxLayout *localLayout = new QHBoxLayout(); + localLayout->addWidget(new QLabel("0%")); + localLayout->addWidget(m_opacitySlider); + localLayout->addWidget(new QLabel("100%")); + m_opacity = ConfigHandler().contrastOpacityValue(); + m_opacitySlider->setValue(m_opacity); + m_layout->addLayout(localLayout); +} + +void VisualsEditor::updateOpacity(int opacity) { + m_opacity = opacity; +} + +void VisualsEditor::saveOpacity() { + ConfigHandler().setContrastOpacity(m_opacity); +} + +void VisualsEditor::initWidgets() { + m_colorEditor = new UIcolorEditor(); + m_layout->addWidget(m_colorEditor); + + initOpacitySlider(); + + auto boxButtons = new QGroupBox(); + boxButtons->setTitle(tr("Button Selection")); + auto listLayout = new QVBoxLayout(boxButtons); + m_buttonList = new ButtonListView(); + m_layout->addWidget(boxButtons); + listLayout->addWidget(m_buttonList); + + QPushButton* setAllButtons = new QPushButton(tr("Select All")); + connect(setAllButtons, &QPushButton::clicked, + m_buttonList, &ButtonListView::selectAll); + listLayout->addWidget(setAllButtons); +} + diff --git a/src/config/visualseditor.h b/src/config/visualseditor.h new file mode 100644 index 00000000..05007bc2 --- /dev/null +++ b/src/config/visualseditor.h @@ -0,0 +1,35 @@ +#ifndef VISUALSEDITOR_H +#define VISUALSEDITOR_H + +#include + +class QSlider; +class QVBoxLayout; +class ButtonListView; +class UIcolorEditor; + +class VisualsEditor : public QWidget +{ + Q_OBJECT +public: + explicit VisualsEditor(QWidget *parent = nullptr); + +public slots: + void updateComponents(); + +private slots: + void updateOpacity(int); + void saveOpacity(); + +private: + int m_opacity; // Slider local value + QVBoxLayout *m_layout; + ButtonListView *m_buttonList; + UIcolorEditor *m_colorEditor; + QSlider *m_opacitySlider; + + void initWidgets(); + void initOpacitySlider(); +}; + +#endif // VISUALSEDITOR_H diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp index 159ada9b..95fa2cd0 100644 --- a/src/utils/confighandler.cpp +++ b/src/utils/confighandler.cpp @@ -158,6 +158,19 @@ void ConfigHandler::setStartupLaunch(const bool start) { #endif } +int ConfigHandler::contrastOpacityValue() { + int opacity = 190; + if (m_settings.contains("contrastOpacity")) { + opacity = m_settings.value("contrastOpacity").toInt(); + opacity = qBound(0, opacity, 255); + } + return opacity; +} + +void ConfigHandler::setContrastOpacity(const int transparency) { + m_settings.setValue("contrastOpacity", transparency); +} + bool ConfigHandler::initiatedIsSet() { return m_settings.value("initiated").toBool(); } diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h index 8902f73b..f3482047 100644 --- a/src/utils/confighandler.h +++ b/src/utils/confighandler.h @@ -63,6 +63,10 @@ public: bool startupLaunchValue(); void setStartupLaunch(const bool); + int contrastOpacityValue(); + void setContrastOpacity(const int); + + bool initiatedIsSet(); void setInitiated(); void setNotInitiated();