Add update values slot for config widget

This commit is contained in:
lupoDharkael
2017-07-31 01:00:14 +02:00
parent 37acf9383c
commit 162bd5f543
14 changed files with 121 additions and 50 deletions

View File

@@ -19,7 +19,6 @@
#include "src/capture/tools/toolfactory.h"
#include "src/utils/confighandler.h"
#include <QListWidgetItem>
#include <QListWidgetItem>
#include <QSettings>
#include <algorithm>
@@ -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<QList<int> >();
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<int>(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<QList<int> >();
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);
}
}
}

View File

@@ -27,6 +27,7 @@ public:
public slots:
void selectAll();
void updateComponents();
private slots:
void updateActiveButtons(QListWidgetItem *);
@@ -38,6 +39,7 @@ protected:
private:
QList<int> m_listButtons;
QMap<QString, CaptureButton::ButtonType> m_buttonTypeByName;
};
#endif // BUTTONLISTVIEW_H

View File

@@ -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) {

View File

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

View File

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

View File

@@ -48,6 +48,7 @@ private:
public slots:
void addToNameEditor(QString s);
void updateComponents();
private slots:
void savePattern();

View File

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

View File

@@ -21,12 +21,16 @@
#include <QGroupBox>
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();

View File

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

View File

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

View File

@@ -136,3 +136,9 @@ void Controller::disableTrayIcon() {
m_trayIcon->deleteLater();
ConfigHandler().setDisabledTrayIcon(true);
}
void Controller::updateConfigComponents() {
if(m_configWindow) {
m_configWindow->updateComponents();
}
}

View File

@@ -46,6 +46,8 @@ public slots:
void enableTrayIcon();
void disableTrayIcon();
void updateConfigComponents();
private slots:
void initDefaults();

View File

@@ -58,4 +58,5 @@ void FlameshotDBusAdapter::trayIconEnabled(bool enabled) {
} else {
controller->disableTrayIcon();
}
controller->updateConfigComponents();
}

View File

@@ -72,8 +72,6 @@ private:
QList<CaptureButton::ButtonType> fromIntToButton(const QList<int> &l);
QList<int> fromButtonToInt(const QList<CaptureButton::ButtonType> &l);
};
#endif // CONFIGHANDLER_H