Autoupdate config menu after config changes
This commit is contained in:
@@ -27,8 +27,6 @@ ButtonListView::ButtonListView(QWidget *parent) : QListWidget(parent) {
|
||||
setFlow(QListWidget::TopToBottom);
|
||||
initButtonList();
|
||||
updateComponents();
|
||||
connect(this, &QListWidget::itemChanged, this,
|
||||
&ButtonListView::updateActiveButtons);
|
||||
connect(this, &QListWidget::itemClicked, this,
|
||||
&ButtonListView::reverseItemCheck);
|
||||
}
|
||||
@@ -44,7 +42,6 @@ void ButtonListView::initButtonList() {
|
||||
m_buttonTypeByName.insert(tool->getName(), t);
|
||||
|
||||
// init the menu option
|
||||
|
||||
QListWidgetItem *m_buttonItem = new QListWidgetItem(this);
|
||||
|
||||
// when the background is lighter than gray, it uses the white icons
|
||||
@@ -78,6 +75,7 @@ void ButtonListView::updateActiveButtons(QListWidgetItem *item) {
|
||||
} else {
|
||||
m_listButtons.removeOne(buttonIndex);
|
||||
}
|
||||
qDebug("updateActiveButtons");
|
||||
QSettings().setValue("buttons", QVariant::fromValue(m_listButtons));
|
||||
}
|
||||
|
||||
@@ -87,6 +85,7 @@ void ButtonListView::reverseItemCheck(QListWidgetItem *item){
|
||||
} else {
|
||||
item->setCheckState(Qt::Checked);
|
||||
}
|
||||
updateActiveButtons(item);
|
||||
}
|
||||
|
||||
void ButtonListView::selectAll() {
|
||||
|
||||
@@ -30,7 +30,6 @@ public slots:
|
||||
void updateComponents();
|
||||
|
||||
private slots:
|
||||
void updateActiveButtons(QListWidgetItem *);
|
||||
void reverseItemCheck(QListWidgetItem *);
|
||||
|
||||
protected:
|
||||
@@ -40,6 +39,7 @@ private:
|
||||
QList<int> m_listButtons;
|
||||
QMap<QString, CaptureButton::ButtonType> m_buttonTypeByName;
|
||||
|
||||
void updateActiveButtons(QListWidgetItem *);
|
||||
};
|
||||
|
||||
#endif // BUTTONLISTVIEW_H
|
||||
|
||||
@@ -22,10 +22,13 @@
|
||||
#include "src/config/geneneralconf.h"
|
||||
#include "src/config/filenameeditor.h"
|
||||
#include "src/config/strftimechooserwidget.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include <QIcon>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QKeyEvent>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QDebug>
|
||||
|
||||
// ConfigWindow contains the menus where you can configure the application
|
||||
|
||||
@@ -35,6 +38,19 @@ ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) {
|
||||
setWindowIcon(QIcon(":img/flameshot.png"));
|
||||
setWindowTitle(tr("Configuration"));
|
||||
|
||||
auto changedSlot = [this](QString s){
|
||||
Q_UNUSED(s);
|
||||
this->m_configWatcher->removePath(s);
|
||||
this->m_configWatcher->addPath(s);
|
||||
if(!this->hasFocus()) {
|
||||
Q_EMIT updateComponents();
|
||||
}
|
||||
};
|
||||
m_configWatcher = new QFileSystemWatcher(this);
|
||||
m_configWatcher->addPath(ConfigHandler().getConfigFilePath());
|
||||
connect(m_configWatcher, &QFileSystemWatcher::fileChanged,
|
||||
this, changedSlot);
|
||||
|
||||
QColor background = this->palette().background().color();
|
||||
bool isWhite = CaptureButton::iconIsWhiteByColor(background);
|
||||
QString modifier = isWhite ? ":img/configWhite/" : ":img/configBlack/";
|
||||
|
||||
@@ -24,6 +24,7 @@ class ButtonListView;
|
||||
class UIcolorEditor;
|
||||
class FileNameEditor;
|
||||
class GeneneralConf;
|
||||
class QFileSystemWatcher;
|
||||
|
||||
class ConfigWindow : public QTabWidget {
|
||||
Q_OBJECT
|
||||
@@ -45,6 +46,8 @@ private:
|
||||
FileNameEditor *m_filenameEditor;
|
||||
GeneneralConf *m_generalConfig;
|
||||
|
||||
QFileSystemWatcher *m_configWatcher;
|
||||
|
||||
};
|
||||
|
||||
#endif // CONFIGURATION_H
|
||||
|
||||
@@ -32,8 +32,6 @@
|
||||
|
||||
Controller::Controller() : m_captureWindow(nullptr)
|
||||
{
|
||||
// required for the button serialization
|
||||
qRegisterMetaTypeStreamOperators<QList<int> >("QList<int>");
|
||||
qApp->setQuitOnLastWindowClosed(false);
|
||||
|
||||
// init tray icon
|
||||
@@ -133,7 +131,9 @@ void Controller::enableTrayIcon() {
|
||||
}
|
||||
|
||||
void Controller::disableTrayIcon() {
|
||||
m_trayIcon->deleteLater();
|
||||
if (m_trayIcon) {
|
||||
m_trayIcon->deleteLater();
|
||||
}
|
||||
ConfigHandler().setDisabledTrayIcon(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,5 +58,4 @@ void FlameshotDBusAdapter::trayIconEnabled(bool enabled) {
|
||||
} else {
|
||||
controller->disableTrayIcon();
|
||||
}
|
||||
controller->updateConfigComponents();
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include <QDir>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// required for the button serialization
|
||||
qRegisterMetaTypeStreamOperators<QList<int> >("QList<int>");
|
||||
qApp->setApplicationVersion(static_cast<QString>(APP_VERSION));
|
||||
|
||||
QTranslator translator;
|
||||
|
||||
@@ -34,6 +34,7 @@ QList<CaptureButton::ButtonType> ConfigHandler::getButtons() {
|
||||
void ConfigHandler::setButtons(const QList<CaptureButton::ButtonType> &buttons) {
|
||||
QList<int> l = fromButtonToInt(buttons);
|
||||
normalizeButtons(l);
|
||||
qDebug("setButtons");
|
||||
m_settings->setValue("buttons", QVariant::fromValue(l));
|
||||
}
|
||||
|
||||
@@ -131,6 +132,10 @@ void ConfigHandler::setAllTheButtons() {
|
||||
m_settings->setValue("buttons", QVariant::fromValue(buttons));
|
||||
}
|
||||
|
||||
QString ConfigHandler::getConfigFilePath() const {
|
||||
return m_settings->fileName();
|
||||
}
|
||||
|
||||
bool ConfigHandler::normalizeButtons(QList<int> &buttons) {
|
||||
auto listTypes = CaptureButton::getIterableButtonTypes();
|
||||
QList<int> listTypesInt;
|
||||
|
||||
@@ -64,6 +64,8 @@ public:
|
||||
|
||||
void setAllTheButtons();
|
||||
|
||||
QString getConfigFilePath() const;
|
||||
|
||||
private:
|
||||
QSettings *m_settings;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user