From 8ba06b7292db8dde4a7a805f58705f3358c29084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Gu=C5=A1i=C4=87?= Date: Sat, 31 Jul 2021 03:56:00 +0200 Subject: [PATCH] Fix #1697 and #1726 (#1782) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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ć * Create scroll area around checkboxes Signed-off-by: Haris Gušić * Do not truncate tab bar anymore Signed-off-by: Haris Gušić * Set parent widget to prevent a memory leak Signed-off-by: Haris Gušić --- src/config/configwindow.cpp | 26 +++++++++++++------- src/config/configwindow.h | 3 ++- src/config/generalconf.cpp | 49 ++++++++++++++++++++++++++++--------- src/config/generalconf.h | 4 +++ 4 files changed, 60 insertions(+), 22 deletions(-) diff --git a/src/config/configwindow.cpp b/src/config/configwindow.cpp index a4dda9a11b..1ce53f0ca4 100644 --- a/src/config/configwindow.cpp +++ b/src/config/configwindow.cpp @@ -14,16 +14,21 @@ #include #include #include +#include #include // ConfigWindow contains the menus where you can configure the application 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); - setMinimumSize(GlobalValues::buttonBaseSize() * 15, - GlobalValues::buttonBaseSize() * 18); setWindowIcon(QIcon(":img/app/flameshot.svg")); setWindowTitle(tr("Configuration")); @@ -46,21 +51,24 @@ ConfigWindow::ConfigWindow(QWidget* parent) // visuals 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 m_filenameEditor = new FileNameEditor(); - addTab(m_filenameEditor, - QIcon(modifier + "name_edition.svg"), - tr("Filename Editor")); + m_tabs->addTab(m_filenameEditor, + QIcon(modifier + "name_edition.svg"), + tr("Filename Editor")); // general 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 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(this, diff --git a/src/config/configwindow.h b/src/config/configwindow.h index 7583bb0b89..905bc5b7dd 100644 --- a/src/config/configwindow.h +++ b/src/config/configwindow.h @@ -11,7 +11,7 @@ class GeneralConf; class QFileSystemWatcher; class VisualsEditor; -class ConfigWindow : public QTabWidget +class ConfigWindow : public QWidget { Q_OBJECT public: @@ -24,6 +24,7 @@ class ConfigWindow : public QTabWidget void keyPressEvent(QKeyEvent*); private: + QTabWidget* m_tabs; FileNameEditor* m_filenameEditor; ShortcutsWidget* m_shortcuts; GeneralConf* m_generalConfig; diff --git a/src/config/generalconf.cpp b/src/config/generalconf.cpp index 0cda8c96c4..a10485de68 100644 --- a/src/config/generalconf.cpp +++ b/src/config/generalconf.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,11 @@ GeneralConf::GeneralConf(QWidget* parent) { m_layout = new QVBoxLayout(this); 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(); initShowSidePanelButton(); initShowDesktopNotification(); @@ -191,6 +197,25 @@ void GeneralConf::setActualFormData() 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() { m_helpMessage = new QCheckBox(tr("Show help message"), this); @@ -199,7 +224,7 @@ void GeneralConf::initShowHelp() m_helpMessage->setChecked(checked); m_helpMessage->setToolTip(tr("Show the help message at the beginning " "in the capture mode.")); - m_layout->addWidget(m_helpMessage); + m_scrollAreaLayout->addWidget(m_helpMessage); connect( m_helpMessage, &QCheckBox::clicked, this, &GeneralConf::showHelpChanged); @@ -211,7 +236,7 @@ void GeneralConf::initShowSidePanelButton() m_sidePanelButton->setChecked(ConfigHandler().showSidePanelButtonValue()); m_sidePanelButton->setToolTip( tr("Show the side panel toggle button in the capture mode.")); - m_layout->addWidget(m_sidePanelButton); + m_scrollAreaLayout->addWidget(m_sidePanelButton); connect(m_sidePanelButton, &QCheckBox::clicked, @@ -225,7 +250,7 @@ void GeneralConf::initShowDesktopNotification() bool checked = config.desktopNotificationValue(); m_sysNotifications->setChecked(checked); m_sysNotifications->setToolTip(tr("Show desktop notifications")); - m_layout->addWidget(m_sysNotifications); + m_scrollAreaLayout->addWidget(m_sysNotifications); connect(m_sysNotifications, &QCheckBox::clicked, @@ -240,7 +265,7 @@ void GeneralConf::initShowTrayIcon() bool checked = !ConfigHandler().disabledTrayIconValue(); m_showTray->setChecked(checked); m_showTray->setToolTip(tr("Show the systemtray icon")); - m_layout->addWidget(m_showTray); + m_scrollAreaLayout->addWidget(m_showTray); connect(m_showTray, &QCheckBox::stateChanged, @@ -258,7 +283,7 @@ void GeneralConf::initHistoryConfirmationToDelete() ConfigHandler().historyConfirmationToDelete()); m_historyConfirmationToDelete->setToolTip( tr("Confirmation required to delete screenshot from the latest uploads")); - m_layout->addWidget(m_historyConfirmationToDelete); + m_scrollAreaLayout->addWidget(m_historyConfirmationToDelete); connect(m_historyConfirmationToDelete, &QCheckBox::clicked, @@ -301,7 +326,7 @@ void GeneralConf::initCheckForUpdates() m_checkForUpdates = new QCheckBox(tr("Automatic check for updates"), this); m_checkForUpdates->setChecked(ConfigHandler().checkForUpdates()); m_checkForUpdates->setToolTip(tr("Automatic check for updates")); - m_layout->addWidget(m_checkForUpdates); + m_scrollAreaLayout->addWidget(m_checkForUpdates); connect(m_checkForUpdates, &QCheckBox::clicked, @@ -315,7 +340,7 @@ void GeneralConf::initAutostart() bool checked = ConfigHandler().startupLaunchValue(); m_autostart->setChecked(checked); m_autostart->setToolTip(tr("Launch Flameshot")); - m_layout->addWidget(m_autostart); + m_scrollAreaLayout->addWidget(m_autostart); connect( m_autostart, &QCheckBox::clicked, this, &GeneralConf::autostartChanged); @@ -329,7 +354,7 @@ void GeneralConf::initShowStartupLaunchMessage() bool checked = config.showStartupLaunchMessage(); m_showStartupLaunchMessage->setChecked(checked); m_showStartupLaunchMessage->setToolTip(tr("Launch Flameshot")); - m_layout->addWidget(m_showStartupLaunchMessage); + m_scrollAreaLayout->addWidget(m_showStartupLaunchMessage); connect(m_showStartupLaunchMessage, &QCheckBox::clicked, [](bool checked) { ConfigHandler().setShowStartupLaunchMessage(checked); @@ -345,7 +370,7 @@ void GeneralConf::initCopyAndCloseAfterUpload() config.copyAndCloseAfterUploadEnabled()); m_copyAndCloseAfterUpload->setToolTip( 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) { ConfigHandler().setCopyAndCloseAfterUploadEnabled(checked); @@ -356,7 +381,7 @@ void GeneralConf::initSaveAfterCopy() { m_saveAfterCopy = new QCheckBox(tr("Save image after copy"), this); m_saveAfterCopy->setToolTip(tr("Save image file after copying it")); - m_layout->addWidget(m_saveAfterCopy); + m_scrollAreaLayout->addWidget(m_saveAfterCopy); connect(m_saveAfterCopy, &QCheckBox::clicked, this, @@ -473,7 +498,7 @@ void GeneralConf::initUseJpgForClipboard() m_useJpgForClipboard->setChecked(checked); m_useJpgForClipboard->setToolTip( tr("Use JPG format for clipboard (PNG default)")); - m_layout->addWidget(m_useJpgForClipboard); + m_scrollAreaLayout->addWidget(m_useJpgForClipboard); #if defined(Q_OS_MACOS) // FIXME - temporary fix to disable option for MacOS @@ -510,7 +535,7 @@ void GeneralConf::initCopyPathAfterSave() ConfigHandler config; m_copyPathAfterSave->setChecked(config.copyPathAfterSaveEnabled()); 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) { ConfigHandler().setCopyPathAfterSaveEnabled(checked); }); diff --git a/src/config/generalconf.h b/src/config/generalconf.h index 54afc0e853..10c2fca395 100644 --- a/src/config/generalconf.h +++ b/src/config/generalconf.h @@ -3,6 +3,7 @@ #pragma once +#include #include class QVBoxLayout; @@ -42,6 +43,7 @@ private slots: private: const QString chooseFolder(const QString currentPath = ""); + void initScrollArea(); void initShowHelp(); void initShowSidePanelButton(); void initShowDesktopNotification(); @@ -62,6 +64,8 @@ private slots: // class members QVBoxLayout* m_layout; + QVBoxLayout* m_scrollAreaLayout; + QScrollArea* m_scrollArea; QCheckBox* m_sysNotifications; QCheckBox* m_showTray; QCheckBox* m_helpMessage;