From 162bd5f543838bc2d847bc37596dd44f10dc7087 Mon Sep 17 00:00:00 2001 From: lupoDharkael Date: Mon, 31 Jul 2017 01:00:14 +0200 Subject: [PATCH] Add update values slot for config widget --- src/config/buttonlistview.cpp | 34 +++++++++++++++----------- src/config/buttonlistview.h | 2 ++ src/config/configwindow.cpp | 29 +++++++++++++++++----- src/config/configwindow.h | 15 ++++++++++++ src/config/filenameeditor.cpp | 8 +++++-- src/config/filenameeditor.h | 1 + src/config/geneneralconf.cpp | 40 +++++++++++++++++++------------ src/config/geneneralconf.h | 7 ++++++ src/config/uicoloreditor.cpp | 21 ++++++++-------- src/config/uicoloreditor.h | 3 +++ src/core/controller.cpp | 6 +++++ src/core/controller.h | 2 ++ src/core/flameshotdbusadapter.cpp | 1 + src/utils/confighandler.h | 2 -- 14 files changed, 121 insertions(+), 50 deletions(-) diff --git a/src/config/buttonlistview.cpp b/src/config/buttonlistview.cpp index 9db4ebb8..e58d873f 100644 --- a/src/config/buttonlistview.cpp +++ b/src/config/buttonlistview.cpp @@ -19,7 +19,6 @@ #include "src/capture/tools/toolfactory.h" #include "src/utils/confighandler.h" #include -#include #include #include @@ -27,6 +26,7 @@ ButtonListView::ButtonListView(QWidget *parent) : QListWidget(parent) { setMouseTracking(true); setFlow(QListWidget::TopToBottom); initButtonList(); + updateComponents(); connect(this, &QListWidget::itemChanged, this, &ButtonListView::updateActiveButtons); connect(this, &QListWidget::itemClicked, this, @@ -34,7 +34,6 @@ ButtonListView::ButtonListView(QWidget *parent) : QListWidget(parent) { } void ButtonListView::initButtonList() { - m_listButtons = QSettings().value("buttons").value >(); ToolFactory factory; auto listTypes = CaptureButton::getIterableButtonTypes(); @@ -46,7 +45,7 @@ void ButtonListView::initButtonList() { // init the menu option - QListWidgetItem *buttonItem = new QListWidgetItem(this); + QListWidgetItem *m_buttonItem = new QListWidgetItem(this); // when the background is lighter than gray, it uses the white icons QColor bgColor = this->palette().color(QWidget::backgroundRole()); @@ -57,19 +56,14 @@ void ButtonListView::initButtonList() { iconPath = QString(":/img/buttonIcons%1/size_indicator.png") .arg(color); } - buttonItem->setIcon(QIcon(iconPath)); + m_buttonItem->setIcon(QIcon(iconPath)); - buttonItem->setFlags(Qt::ItemIsUserCheckable); + m_buttonItem->setFlags(Qt::ItemIsUserCheckable); QColor foregroundColor = this->palette().color(QWidget::foregroundRole()); - buttonItem->setTextColor(foregroundColor); + m_buttonItem->setTextColor(foregroundColor); - buttonItem->setText(tool->getName()); - buttonItem->setToolTip(tool->getDescription()); - if (m_listButtons.contains(static_cast(t))) { - buttonItem->setCheckState(Qt::Checked); - } else { - buttonItem->setCheckState(Qt::Unchecked); - } + m_buttonItem->setText(tool->getName()); + m_buttonItem->setToolTip(tool->getDescription()); tool->deleteLater(); } } @@ -84,7 +78,6 @@ void ButtonListView::updateActiveButtons(QListWidgetItem *item) { } else { m_listButtons.removeOne(buttonIndex); } - QSettings().setValue("buttons", QVariant::fromValue(m_listButtons)); } @@ -103,3 +96,16 @@ void ButtonListView::selectAll() { item->setCheckState(Qt::Checked); } } + +void ButtonListView::updateComponents() { + m_listButtons = QSettings().value("buttons").value >(); + auto listTypes = CaptureButton::getIterableButtonTypes(); + for(int i = 0; i < this->count(); ++i) { + QListWidgetItem* item = this->item(i); + if (m_listButtons.contains(listTypes.at(i))) { + item->setCheckState(Qt::Checked); + } else { + item->setCheckState(Qt::Unchecked); + } + } +} diff --git a/src/config/buttonlistview.h b/src/config/buttonlistview.h index 352eaac1..84455eb1 100644 --- a/src/config/buttonlistview.h +++ b/src/config/buttonlistview.h @@ -27,6 +27,7 @@ public: public slots: void selectAll(); + void updateComponents(); private slots: void updateActiveButtons(QListWidgetItem *); @@ -38,6 +39,7 @@ protected: private: QList m_listButtons; QMap m_buttonTypeByName; + }; #endif // BUTTONLISTVIEW_H diff --git a/src/config/configwindow.cpp b/src/config/configwindow.cpp index c5c81758..e8b5ee5b 100644 --- a/src/config/configwindow.cpp +++ b/src/config/configwindow.cpp @@ -43,30 +43,47 @@ ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) { auto visuals = new QWidget(); QVBoxLayout *layoutUI= new QVBoxLayout(); visuals->setLayout(layoutUI); - layoutUI->addWidget(new UIcolorEditor()); + m_colorEditor = new UIcolorEditor(); + layoutUI->addWidget(m_colorEditor); auto boxButtons = new QGroupBox(); boxButtons->setTitle(tr("Button Selection")); auto listLayout = new QVBoxLayout(boxButtons); - auto buttonList = new ButtonListView(); + m_buttonList = new ButtonListView(); layoutUI->addWidget(boxButtons); - listLayout->addWidget(buttonList); + listLayout->addWidget(m_buttonList); QPushButton* setAllButtons = new QPushButton(tr("Select All")); connect(setAllButtons, &QPushButton::clicked, - buttonList, &ButtonListView::selectAll); + m_buttonList, &ButtonListView::selectAll); listLayout->addWidget(setAllButtons); addTab(visuals, tr("Interface")); setTabIcon(0, QIcon(modifier + "graphics.png")); // filename - addTab(new FileNameEditor(), tr("Filename Editor")); + m_filenameEditor = new FileNameEditor(); + addTab(m_filenameEditor, tr("Filename Editor")); setTabIcon(1, QIcon(modifier + "name_edition.png")); // general - addTab(new GeneneralConf(), tr("General")); + m_generalConfig = new GeneneralConf(); + addTab(m_generalConfig, tr("General")); setTabIcon(2, QIcon(modifier + "config.png")); + + // connect update sigslots + connect(this, &ConfigWindow::updateChildren, + m_filenameEditor, &FileNameEditor::updateComponents); + connect(this, &ConfigWindow::updateChildren, + m_colorEditor, &UIcolorEditor::updateComponents); + connect(this, &ConfigWindow::updateChildren, + m_buttonList, &ButtonListView::updateComponents); + connect(this, &ConfigWindow::updateChildren, + m_generalConfig, &GeneneralConf::updateComponents); +} + +void ConfigWindow::updateComponents() { + Q_EMIT updateChildren(); } void ConfigWindow::keyPressEvent(QKeyEvent *e) { diff --git a/src/config/configwindow.h b/src/config/configwindow.h index 2c9acc29..1417f830 100644 --- a/src/config/configwindow.h +++ b/src/config/configwindow.h @@ -20,15 +20,30 @@ #include +class ButtonListView; +class UIcolorEditor; +class FileNameEditor; +class GeneneralConf; + class ConfigWindow : public QTabWidget { Q_OBJECT public: explicit ConfigWindow(QWidget *parent = nullptr); +public slots: + void updateComponents(); + +signals: + void updateChildren(); + protected: void keyPressEvent(QKeyEvent *); private: + ButtonListView *m_buttonList; + UIcolorEditor *m_colorEditor; + FileNameEditor *m_filenameEditor; + GeneneralConf *m_generalConfig; }; diff --git a/src/config/filenameeditor.cpp b/src/config/filenameeditor.cpp index 8a4d8686..8bae9b79 100644 --- a/src/config/filenameeditor.cpp +++ b/src/config/filenameeditor.cpp @@ -65,8 +65,7 @@ void FileNameEditor::initWidgets() { connect(m_nameEditor, &QLineEdit::textChanged, this, &FileNameEditor::showParsedPattern); - m_nameEditor->setText(ConfigHandler().getFilenamePattern()); - m_outputLabel->setText(m_nameHandler->getParsedPattern()); + updateComponents(); // helper buttons m_helperButtons = new StrftimeChooserWidget(this); @@ -107,3 +106,8 @@ void FileNameEditor::addToNameEditor(QString s) { m_nameEditor->setText(m_nameEditor->text() + s); m_nameEditor->setFocus(); } + +void FileNameEditor::updateComponents() { + m_nameEditor->setText(ConfigHandler().getFilenamePattern()); + m_outputLabel->setText(m_nameHandler->getParsedPattern()); +} diff --git a/src/config/filenameeditor.h b/src/config/filenameeditor.h index d8968c04..f7da683a 100644 --- a/src/config/filenameeditor.h +++ b/src/config/filenameeditor.h @@ -48,6 +48,7 @@ private: public slots: void addToNameEditor(QString s); + void updateComponents(); private slots: void savePattern(); diff --git a/src/config/geneneralconf.cpp b/src/config/geneneralconf.cpp index bbdbf65e..7845764d 100644 --- a/src/config/geneneralconf.cpp +++ b/src/config/geneneralconf.cpp @@ -27,6 +27,14 @@ GeneneralConf::GeneneralConf(QWidget *parent) : QGroupBox(parent) { initShowHelp(); initShowDesktopNotification(); initShowTrayIcon(); + updateComponents(); +} + +void GeneneralConf::updateComponents() { + ConfigHandler config; + m_helpMessage->setChecked(config.getShowHelp()); + m_showTray->setChecked(!config.getDisabledTrayIcon()); + m_sysNotifications->setChecked(config.getDesktopNotification()); } void GeneneralConf::showHelpChanged(bool checked) { @@ -47,37 +55,39 @@ void GeneneralConf::showTrayIconChanged(bool checked) { } void GeneneralConf::initShowHelp() { - QCheckBox *c = new QCheckBox(tr("Show help message"), this); + m_helpMessage = new QCheckBox(tr("Show help message"), this); ConfigHandler config; bool checked = config.getShowHelp(); - c->setChecked(checked); - c->setToolTip(tr("Show the help message at the beginning " + m_helpMessage->setChecked(checked); + m_helpMessage->setToolTip(tr("Show the help message at the beginning " "in the capture mode.")); - m_layout->addWidget(c); + m_layout->addWidget(m_helpMessage); - connect(c, &QCheckBox::clicked, this, &GeneneralConf::showHelpChanged); + connect(m_helpMessage, &QCheckBox::clicked, this, + &GeneneralConf::showHelpChanged); } void GeneneralConf::initShowDesktopNotification() { - QCheckBox *c = new QCheckBox(tr("Show desktop notifications"), this); + m_sysNotifications = + new QCheckBox(tr("Show desktop notifications"), this); ConfigHandler config; bool checked = config.getDesktopNotification(); - c->setChecked(checked); - c->setToolTip(tr("Show desktop notifications")); - m_layout->addWidget(c); + m_sysNotifications->setChecked(checked); + m_sysNotifications->setToolTip(tr("Show desktop notifications")); + m_layout->addWidget(m_sysNotifications); - connect(c, &QCheckBox::clicked, this, + connect(m_sysNotifications, &QCheckBox::clicked, this, &GeneneralConf::showDesktopNotificationChanged); } void GeneneralConf::initShowTrayIcon() { - QCheckBox *c = new QCheckBox(tr("Show tray icon"), this); + m_showTray = new QCheckBox(tr("Show tray icon"), this); ConfigHandler config; bool checked = !config.getDisabledTrayIcon(); - c->setChecked(checked); - c->setToolTip(tr("Show systemtray icons")); - m_layout->addWidget(c); + m_showTray->setChecked(checked); + m_showTray->setToolTip(tr("Show systemtray icons")); + m_layout->addWidget(m_showTray); - connect(c, &QCheckBox::clicked, this, + connect(m_showTray, &QCheckBox::clicked, this, &GeneneralConf::showTrayIconChanged); } diff --git a/src/config/geneneralconf.h b/src/config/geneneralconf.h index 0e7b8d27..5e3aa96a 100644 --- a/src/config/geneneralconf.h +++ b/src/config/geneneralconf.h @@ -21,12 +21,16 @@ #include class QVBoxLayout; +class QCheckBox; class GeneneralConf : public QGroupBox { Q_OBJECT public: GeneneralConf(QWidget *parent = nullptr); +public slots: + void updateComponents(); + private slots: void showHelpChanged(bool checked); void showDesktopNotificationChanged(bool checked); @@ -34,6 +38,9 @@ private slots: private: QVBoxLayout *m_layout; + QCheckBox *m_sysNotifications; + QCheckBox *m_showTray; + QCheckBox *m_helpMessage; void initShowHelp(); void initShowDesktopNotification(); diff --git a/src/config/uicoloreditor.cpp b/src/config/uicoloreditor.cpp index 3a3e4306..2ac120d7 100644 --- a/src/config/uicoloreditor.cpp +++ b/src/config/uicoloreditor.cpp @@ -28,15 +28,21 @@ UIcolorEditor::UIcolorEditor(QWidget *parent) : QGroupBox(parent) { hLayout = new QHBoxLayout; vLayout = new QVBoxLayout; - ConfigHandler config; - m_uiColor = config.getUIMainColor(); - m_contrastColor = config.getUIContrastColor(); - initButtons(); initColorWheel(); hLayout->addLayout(vLayout); setLayout(hLayout); + updateComponents(); } + +void UIcolorEditor::updateComponents() { + ConfigHandler config; + m_uiColor = config.getUIMainColor(); + m_contrastColor = config.getUIContrastColor(); + m_lastButtonPressed = m_buttonContrast; + changeLastButton(m_buttonMainColor); +} + // updateUIcolor updates the appearance of the buttons void UIcolorEditor::updateUIcolor() { ConfigHandler config; @@ -63,9 +69,7 @@ void UIcolorEditor::initColorWheel() { connect(m_colorWheel, &color_widgets::ColorWheel::colorChanged, this, &UIcolorEditor::updateLocalColor); - m_colorWheel->setColor(m_uiColor); m_colorWheel->setMinimumSize(100, 100); - m_colorWheel->setToolTip(tr("Change the color moving the selectors and see" " the changes in the preview buttons.")); @@ -82,7 +86,6 @@ void UIcolorEditor::initButtons() { frame->setFixedSize(frameSize, frameSize); frame->setFrameStyle(QFrame::StyledPanel); - m_buttonMainColor = new CaptureButton(m_buttonIconType, frame); m_buttonMainColor->move(m_buttonMainColor->x() + extraSize/2, m_buttonMainColor->y() + extraSize/2); QHBoxLayout *h1 = new QHBoxLayout(); @@ -99,22 +102,18 @@ void UIcolorEditor::initButtons() { frame2->setFrameStyle(QFrame::StyledPanel); m_buttonContrast = new CaptureButton(m_buttonIconType, frame2); - m_buttonContrast->setIcon(QIcon()); - m_buttonContrast->setColor(m_contrastColor); m_buttonContrast->move(m_buttonContrast->x() + extraSize/2, m_buttonContrast->y() + extraSize/2); QHBoxLayout *h2 = new QHBoxLayout(); h2->addWidget(frame2); m_labelContrast = new ClickableLabel(tr("Contrast Color"), this); - m_labelContrast->setStyleSheet("QLabel { color : gray; }"); h2->addWidget(m_labelContrast); vLayout->addLayout(h2); m_buttonContrast->setToolTip(tr("Click on this button to set the edition" " mode of the contrast color.")); - m_lastButtonPressed = m_buttonMainColor; connect(m_buttonMainColor, &CaptureButton::pressedButton, this, &UIcolorEditor::changeLastButton); connect(m_buttonContrast, &CaptureButton::pressedButton, diff --git a/src/config/uicoloreditor.h b/src/config/uicoloreditor.h index 70d06346..0399c961 100644 --- a/src/config/uicoloreditor.h +++ b/src/config/uicoloreditor.h @@ -32,6 +32,9 @@ class UIcolorEditor : public QGroupBox { public: explicit UIcolorEditor(QWidget *parent = nullptr); +public slots: + void updateComponents(); + private slots: void updateUIcolor(); void updateLocalColor(const QColor); diff --git a/src/core/controller.cpp b/src/core/controller.cpp index 7ddb9a01..ca189fc7 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -136,3 +136,9 @@ void Controller::disableTrayIcon() { m_trayIcon->deleteLater(); ConfigHandler().setDisabledTrayIcon(true); } + +void Controller::updateConfigComponents() { + if(m_configWindow) { + m_configWindow->updateComponents(); + } +} diff --git a/src/core/controller.h b/src/core/controller.h index 0ac38def..dec8e862 100644 --- a/src/core/controller.h +++ b/src/core/controller.h @@ -46,6 +46,8 @@ public slots: void enableTrayIcon(); void disableTrayIcon(); + void updateConfigComponents(); + private slots: void initDefaults(); diff --git a/src/core/flameshotdbusadapter.cpp b/src/core/flameshotdbusadapter.cpp index 3ebaafce..3768003e 100644 --- a/src/core/flameshotdbusadapter.cpp +++ b/src/core/flameshotdbusadapter.cpp @@ -58,4 +58,5 @@ void FlameshotDBusAdapter::trayIconEnabled(bool enabled) { } else { controller->disableTrayIcon(); } + controller->updateConfigComponents(); } diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h index ee17f6ff..e5125bdf 100644 --- a/src/utils/confighandler.h +++ b/src/utils/confighandler.h @@ -72,8 +72,6 @@ private: QList fromIntToButton(const QList &l); QList fromButtonToInt(const QList &l); - - }; #endif // CONFIGHANDLER_H