* Fix #1697 and #1726

Changed ConfigWindow to inherit QWidget and moved QTabWidget to be an
attribute. setMinimumSize is no longer necessary in ConfigWindow.

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Create scroll area around checkboxes

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Do not truncate tab bar anymore

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Set parent widget to prevent a memory leak

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>
This commit is contained in:
Haris Gušić
2021-07-31 03:56:00 +02:00
committed by GitHub
parent 216d2a13a5
commit 8ba06b7292
4 changed files with 60 additions and 22 deletions

View File

@@ -14,16 +14,21 @@
#include <QFileSystemWatcher> #include <QFileSystemWatcher>
#include <QIcon> #include <QIcon>
#include <QKeyEvent> #include <QKeyEvent>
#include <QTabBar>
#include <QVBoxLayout> #include <QVBoxLayout>
// ConfigWindow contains the menus where you can configure the application // ConfigWindow contains the menus where you can configure the application
ConfigWindow::ConfigWindow(QWidget* parent) ConfigWindow::ConfigWindow(QWidget* parent)
: QTabWidget(parent) : QWidget(parent)
{ {
// We wrap QTabWidget in a QWidget because of a Qt bug
auto layout = new QVBoxLayout(this);
m_tabs = new QTabWidget(this);
m_tabs->tabBar()->setUsesScrollButtons(false);
layout->addWidget(m_tabs);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
setMinimumSize(GlobalValues::buttonBaseSize() * 15,
GlobalValues::buttonBaseSize() * 18);
setWindowIcon(QIcon(":img/app/flameshot.svg")); setWindowIcon(QIcon(":img/app/flameshot.svg"));
setWindowTitle(tr("Configuration")); setWindowTitle(tr("Configuration"));
@@ -46,21 +51,24 @@ ConfigWindow::ConfigWindow(QWidget* parent)
// visuals // visuals
m_visuals = new VisualsEditor(); m_visuals = new VisualsEditor();
addTab(m_visuals, QIcon(modifier + "graphics.svg"), tr("Interface")); m_tabs->addTab(
m_visuals, QIcon(modifier + "graphics.svg"), tr("Interface"));
// filename // filename
m_filenameEditor = new FileNameEditor(); m_filenameEditor = new FileNameEditor();
addTab(m_filenameEditor, m_tabs->addTab(m_filenameEditor,
QIcon(modifier + "name_edition.svg"), QIcon(modifier + "name_edition.svg"),
tr("Filename Editor")); tr("Filename Editor"));
// general // general
m_generalConfig = new GeneralConf(); m_generalConfig = new GeneralConf();
addTab(m_generalConfig, QIcon(modifier + "config.svg"), tr("General")); m_tabs->addTab(
m_generalConfig, QIcon(modifier + "config.svg"), tr("General"));
// shortcuts // shortcuts
m_shortcuts = new ShortcutsWidget(); m_shortcuts = new ShortcutsWidget();
addTab(m_shortcuts, QIcon(modifier + "shortcut.svg"), tr("Shortcuts")); m_tabs->addTab(
m_shortcuts, QIcon(modifier + "shortcut.svg"), tr("Shortcuts"));
// connect update sigslots // connect update sigslots
connect(this, connect(this,

View File

@@ -11,7 +11,7 @@ class GeneralConf;
class QFileSystemWatcher; class QFileSystemWatcher;
class VisualsEditor; class VisualsEditor;
class ConfigWindow : public QTabWidget class ConfigWindow : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
@@ -24,6 +24,7 @@ protected:
void keyPressEvent(QKeyEvent*); void keyPressEvent(QKeyEvent*);
private: private:
QTabWidget* m_tabs;
FileNameEditor* m_filenameEditor; FileNameEditor* m_filenameEditor;
ShortcutsWidget* m_shortcuts; ShortcutsWidget* m_shortcuts;
GeneralConf* m_generalConfig; GeneralConf* m_generalConfig;

View File

@@ -11,6 +11,7 @@
#include <QLineEdit> #include <QLineEdit>
#include <QMessageBox> #include <QMessageBox>
#include <QPushButton> #include <QPushButton>
#include <QSizePolicy>
#include <QSpinBox> #include <QSpinBox>
#include <QStandardPaths> #include <QStandardPaths>
#include <QTextCodec> #include <QTextCodec>
@@ -23,6 +24,11 @@ GeneralConf::GeneralConf(QWidget* parent)
{ {
m_layout = new QVBoxLayout(this); m_layout = new QVBoxLayout(this);
m_layout->setAlignment(Qt::AlignTop); m_layout->setAlignment(Qt::AlignTop);
// Scroll area adapts the size of the content on small screens.
// It must be initialized before the checkboxes.
initScrollArea();
initShowHelp(); initShowHelp();
initShowSidePanelButton(); initShowSidePanelButton();
initShowDesktopNotification(); initShowDesktopNotification();
@@ -191,6 +197,25 @@ void GeneralConf::setActualFormData()
m_useJpgForClipboard->setChecked(config.useJpgForClipboard()); m_useJpgForClipboard->setChecked(config.useJpgForClipboard());
} }
void GeneralConf::initScrollArea()
{
m_scrollArea = new QScrollArea(this);
m_layout->addWidget(m_scrollArea);
QWidget* content = new QWidget(m_scrollArea);
m_scrollArea->setWidget(content);
m_scrollArea->setWidgetResizable(true);
m_scrollArea->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum);
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
content->setObjectName("content");
m_scrollArea->setObjectName("scrollArea");
m_scrollArea->setStyleSheet(
"#content, #scrollArea { background: transparent; border: 0px; }");
m_scrollAreaLayout = new QVBoxLayout(content);
m_scrollAreaLayout->setContentsMargins(0, 0, 20, 0);
}
void GeneralConf::initShowHelp() void GeneralConf::initShowHelp()
{ {
m_helpMessage = new QCheckBox(tr("Show help message"), this); m_helpMessage = new QCheckBox(tr("Show help message"), this);
@@ -199,7 +224,7 @@ void GeneralConf::initShowHelp()
m_helpMessage->setChecked(checked); m_helpMessage->setChecked(checked);
m_helpMessage->setToolTip(tr("Show the help message at the beginning " m_helpMessage->setToolTip(tr("Show the help message at the beginning "
"in the capture mode.")); "in the capture mode."));
m_layout->addWidget(m_helpMessage); m_scrollAreaLayout->addWidget(m_helpMessage);
connect( connect(
m_helpMessage, &QCheckBox::clicked, this, &GeneralConf::showHelpChanged); m_helpMessage, &QCheckBox::clicked, this, &GeneralConf::showHelpChanged);
@@ -211,7 +236,7 @@ void GeneralConf::initShowSidePanelButton()
m_sidePanelButton->setChecked(ConfigHandler().showSidePanelButtonValue()); m_sidePanelButton->setChecked(ConfigHandler().showSidePanelButtonValue());
m_sidePanelButton->setToolTip( m_sidePanelButton->setToolTip(
tr("Show the side panel toggle button in the capture mode.")); tr("Show the side panel toggle button in the capture mode."));
m_layout->addWidget(m_sidePanelButton); m_scrollAreaLayout->addWidget(m_sidePanelButton);
connect(m_sidePanelButton, connect(m_sidePanelButton,
&QCheckBox::clicked, &QCheckBox::clicked,
@@ -225,7 +250,7 @@ void GeneralConf::initShowDesktopNotification()
bool checked = config.desktopNotificationValue(); bool checked = config.desktopNotificationValue();
m_sysNotifications->setChecked(checked); m_sysNotifications->setChecked(checked);
m_sysNotifications->setToolTip(tr("Show desktop notifications")); m_sysNotifications->setToolTip(tr("Show desktop notifications"));
m_layout->addWidget(m_sysNotifications); m_scrollAreaLayout->addWidget(m_sysNotifications);
connect(m_sysNotifications, connect(m_sysNotifications,
&QCheckBox::clicked, &QCheckBox::clicked,
@@ -240,7 +265,7 @@ void GeneralConf::initShowTrayIcon()
bool checked = !ConfigHandler().disabledTrayIconValue(); bool checked = !ConfigHandler().disabledTrayIconValue();
m_showTray->setChecked(checked); m_showTray->setChecked(checked);
m_showTray->setToolTip(tr("Show the systemtray icon")); m_showTray->setToolTip(tr("Show the systemtray icon"));
m_layout->addWidget(m_showTray); m_scrollAreaLayout->addWidget(m_showTray);
connect(m_showTray, connect(m_showTray,
&QCheckBox::stateChanged, &QCheckBox::stateChanged,
@@ -258,7 +283,7 @@ void GeneralConf::initHistoryConfirmationToDelete()
ConfigHandler().historyConfirmationToDelete()); ConfigHandler().historyConfirmationToDelete());
m_historyConfirmationToDelete->setToolTip( m_historyConfirmationToDelete->setToolTip(
tr("Confirmation required to delete screenshot from the latest uploads")); tr("Confirmation required to delete screenshot from the latest uploads"));
m_layout->addWidget(m_historyConfirmationToDelete); m_scrollAreaLayout->addWidget(m_historyConfirmationToDelete);
connect(m_historyConfirmationToDelete, connect(m_historyConfirmationToDelete,
&QCheckBox::clicked, &QCheckBox::clicked,
@@ -301,7 +326,7 @@ void GeneralConf::initCheckForUpdates()
m_checkForUpdates = new QCheckBox(tr("Automatic check for updates"), this); m_checkForUpdates = new QCheckBox(tr("Automatic check for updates"), this);
m_checkForUpdates->setChecked(ConfigHandler().checkForUpdates()); m_checkForUpdates->setChecked(ConfigHandler().checkForUpdates());
m_checkForUpdates->setToolTip(tr("Automatic check for updates")); m_checkForUpdates->setToolTip(tr("Automatic check for updates"));
m_layout->addWidget(m_checkForUpdates); m_scrollAreaLayout->addWidget(m_checkForUpdates);
connect(m_checkForUpdates, connect(m_checkForUpdates,
&QCheckBox::clicked, &QCheckBox::clicked,
@@ -315,7 +340,7 @@ void GeneralConf::initAutostart()
bool checked = ConfigHandler().startupLaunchValue(); bool checked = ConfigHandler().startupLaunchValue();
m_autostart->setChecked(checked); m_autostart->setChecked(checked);
m_autostart->setToolTip(tr("Launch Flameshot")); m_autostart->setToolTip(tr("Launch Flameshot"));
m_layout->addWidget(m_autostart); m_scrollAreaLayout->addWidget(m_autostart);
connect( connect(
m_autostart, &QCheckBox::clicked, this, &GeneralConf::autostartChanged); m_autostart, &QCheckBox::clicked, this, &GeneralConf::autostartChanged);
@@ -329,7 +354,7 @@ void GeneralConf::initShowStartupLaunchMessage()
bool checked = config.showStartupLaunchMessage(); bool checked = config.showStartupLaunchMessage();
m_showStartupLaunchMessage->setChecked(checked); m_showStartupLaunchMessage->setChecked(checked);
m_showStartupLaunchMessage->setToolTip(tr("Launch Flameshot")); m_showStartupLaunchMessage->setToolTip(tr("Launch Flameshot"));
m_layout->addWidget(m_showStartupLaunchMessage); m_scrollAreaLayout->addWidget(m_showStartupLaunchMessage);
connect(m_showStartupLaunchMessage, &QCheckBox::clicked, [](bool checked) { connect(m_showStartupLaunchMessage, &QCheckBox::clicked, [](bool checked) {
ConfigHandler().setShowStartupLaunchMessage(checked); ConfigHandler().setShowStartupLaunchMessage(checked);
@@ -345,7 +370,7 @@ void GeneralConf::initCopyAndCloseAfterUpload()
config.copyAndCloseAfterUploadEnabled()); config.copyAndCloseAfterUploadEnabled());
m_copyAndCloseAfterUpload->setToolTip( m_copyAndCloseAfterUpload->setToolTip(
tr("Copy URL and close window after upload")); tr("Copy URL and close window after upload"));
m_layout->addWidget(m_copyAndCloseAfterUpload); m_scrollAreaLayout->addWidget(m_copyAndCloseAfterUpload);
connect(m_copyAndCloseAfterUpload, &QCheckBox::clicked, [](bool checked) { connect(m_copyAndCloseAfterUpload, &QCheckBox::clicked, [](bool checked) {
ConfigHandler().setCopyAndCloseAfterUploadEnabled(checked); ConfigHandler().setCopyAndCloseAfterUploadEnabled(checked);
@@ -356,7 +381,7 @@ void GeneralConf::initSaveAfterCopy()
{ {
m_saveAfterCopy = new QCheckBox(tr("Save image after copy"), this); m_saveAfterCopy = new QCheckBox(tr("Save image after copy"), this);
m_saveAfterCopy->setToolTip(tr("Save image file after copying it")); m_saveAfterCopy->setToolTip(tr("Save image file after copying it"));
m_layout->addWidget(m_saveAfterCopy); m_scrollAreaLayout->addWidget(m_saveAfterCopy);
connect(m_saveAfterCopy, connect(m_saveAfterCopy,
&QCheckBox::clicked, &QCheckBox::clicked,
this, this,
@@ -473,7 +498,7 @@ void GeneralConf::initUseJpgForClipboard()
m_useJpgForClipboard->setChecked(checked); m_useJpgForClipboard->setChecked(checked);
m_useJpgForClipboard->setToolTip( m_useJpgForClipboard->setToolTip(
tr("Use JPG format for clipboard (PNG default)")); tr("Use JPG format for clipboard (PNG default)"));
m_layout->addWidget(m_useJpgForClipboard); m_scrollAreaLayout->addWidget(m_useJpgForClipboard);
#if defined(Q_OS_MACOS) #if defined(Q_OS_MACOS)
// FIXME - temporary fix to disable option for MacOS // FIXME - temporary fix to disable option for MacOS
@@ -510,7 +535,7 @@ void GeneralConf::initCopyPathAfterSave()
ConfigHandler config; ConfigHandler config;
m_copyPathAfterSave->setChecked(config.copyPathAfterSaveEnabled()); m_copyPathAfterSave->setChecked(config.copyPathAfterSaveEnabled());
m_copyPathAfterSave->setToolTip(tr("Copy file path after save")); m_copyPathAfterSave->setToolTip(tr("Copy file path after save"));
m_layout->addWidget(m_copyPathAfterSave); m_scrollAreaLayout->addWidget(m_copyPathAfterSave);
connect(m_copyPathAfterSave, &QCheckBox::clicked, [](bool checked) { connect(m_copyPathAfterSave, &QCheckBox::clicked, [](bool checked) {
ConfigHandler().setCopyPathAfterSaveEnabled(checked); ConfigHandler().setCopyPathAfterSaveEnabled(checked);
}); });

View File

@@ -3,6 +3,7 @@
#pragma once #pragma once
#include <QScrollArea>
#include <QWidget> #include <QWidget>
class QVBoxLayout; class QVBoxLayout;
@@ -42,6 +43,7 @@ private slots:
private: private:
const QString chooseFolder(const QString currentPath = ""); const QString chooseFolder(const QString currentPath = "");
void initScrollArea();
void initShowHelp(); void initShowHelp();
void initShowSidePanelButton(); void initShowSidePanelButton();
void initShowDesktopNotification(); void initShowDesktopNotification();
@@ -62,6 +64,8 @@ private:
// class members // class members
QVBoxLayout* m_layout; QVBoxLayout* m_layout;
QVBoxLayout* m_scrollAreaLayout;
QScrollArea* m_scrollArea;
QCheckBox* m_sysNotifications; QCheckBox* m_sysNotifications;
QCheckBox* m_showTray; QCheckBox* m_showTray;
QCheckBox* m_helpMessage; QCheckBox* m_helpMessage;