Skip to content

Commit

Permalink
Fix #1697 and #1726 (#1782)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
veracioux authored Jul 31, 2021
1 parent 216d2a1 commit 8ba06b7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 22 deletions.
26 changes: 17 additions & 9 deletions src/config/configwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@
#include <QFileSystemWatcher>
#include <QIcon>
#include <QKeyEvent>
#include <QTabBar>
#include <QVBoxLayout>

// 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"));

Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/config/configwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GeneralConf;
class QFileSystemWatcher;
class VisualsEditor;

class ConfigWindow : public QTabWidget
class ConfigWindow : public QWidget
{
Q_OBJECT
public:
Expand All @@ -24,6 +24,7 @@ class ConfigWindow : public QTabWidget
void keyPressEvent(QKeyEvent*);

private:
QTabWidget* m_tabs;
FileNameEditor* m_filenameEditor;
ShortcutsWidget* m_shortcuts;
GeneralConf* m_generalConfig;
Expand Down
49 changes: 37 additions & 12 deletions src/config/generalconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QLineEdit>
#include <QMessageBox>
#include <QPushButton>
#include <QSizePolicy>
#include <QSpinBox>
#include <QStandardPaths>
#include <QTextCodec>
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
});
Expand Down
4 changes: 4 additions & 0 deletions src/config/generalconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#pragma once

#include <QScrollArea>
#include <QWidget>

class QVBoxLayout;
Expand Down Expand Up @@ -42,6 +43,7 @@ private slots:
private:
const QString chooseFolder(const QString currentPath = "");

void initScrollArea();
void initShowHelp();
void initShowSidePanelButton();
void initShowDesktopNotification();
Expand All @@ -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;
Expand Down

0 comments on commit 8ba06b7

Please sign in to comment.