Add configurable transparency

Now the opacity of the area outside the selection in the graphical
capture is configurable.
This commit is contained in:
lupoDharkael
2017-12-31 17:46:26 +01:00
parent 4770dd195e
commit 2932e5930d
13 changed files with 148 additions and 44 deletions

View File

@@ -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 \

View File

@@ -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());

View File

@@ -101,6 +101,7 @@ protected:
const QString m_forcedSavePath;
int m_thickness;
int m_opacity;
uint m_id;
NotifierBox *m_notifierBox;

View File

@@ -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 <QIcon>
#include <QVBoxLayout>
#include <QLabel>
@@ -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);
}

View File

@@ -20,11 +20,10 @@
#include <QTabWidget>
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;
};

View File

@@ -25,7 +25,7 @@
#include <QLabel>
#include <QPushButton>
FileNameEditor::FileNameEditor(QWidget *parent) : QGroupBox(parent) {
FileNameEditor::FileNameEditor(QWidget *parent) : QWidget(parent) {
initWidgets();
initLayout();
}

View File

@@ -18,7 +18,7 @@
#ifndef FILENAMEEDITOR_H
#define FILENAMEEDITOR_H
#include <QGroupBox>
#include <QWidget>
#include <QPointer>
class QVBoxLayout;
@@ -27,7 +27,7 @@ class FileNameHandler;
class QPushButton;
class StrftimeChooserWidget;
class FileNameEditor : public QGroupBox
class FileNameEditor : public QWidget
{
Q_OBJECT
public:

View File

@@ -29,7 +29,7 @@
#include <QTextCodec>
#include <QGroupBox>
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);

View File

@@ -18,13 +18,13 @@
#ifndef GENENERALCONF_H
#define GENENERALCONF_H
#include <QGroupBox>
#include <QWidget>
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:

View File

@@ -0,0 +1,69 @@
#include "visualseditor.h"
#include "src/config/buttonlistview.h"
#include "src/config/uicoloreditor.h"
#include "src/utils/confighandler.h"
#include <QSlider>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
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);
}

View File

@@ -0,0 +1,35 @@
#ifndef VISUALSEDITOR_H
#define VISUALSEDITOR_H
#include <QWidget>
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

View File

@@ -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();
}

View File

@@ -63,6 +63,10 @@ public:
bool startupLaunchValue();
void setStartupLaunch(const bool);
int contrastOpacityValue();
void setContrastOpacity(const int);
bool initiatedIsSet();
void setInitiated();
void setNotInitiated();