Reimplement default configuration
Now it uses real default values without having to set all the
initial values.
I a value is not found it will use the default one.
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
#include "src/capture/tools/toolfactory.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include <QListWidgetItem>
|
||||
#include <QSettings>
|
||||
#include <algorithm>
|
||||
|
||||
ButtonListView::ButtonListView(QWidget *parent) : QListWidget(parent) {
|
||||
@@ -67,15 +66,13 @@ void ButtonListView::initButtonList() {
|
||||
|
||||
void ButtonListView::updateActiveButtons(QListWidgetItem *item) {
|
||||
CaptureButton::ButtonType bType = m_buttonTypeByName[item->text()];
|
||||
int buttonIndex = static_cast<int>(bType);
|
||||
|
||||
if (item->checkState() == Qt::Checked) {
|
||||
m_listButtons.append(buttonIndex);
|
||||
m_listButtons.append(bType);
|
||||
std::sort(m_listButtons.begin(), m_listButtons.end());
|
||||
} else {
|
||||
m_listButtons.removeOne(buttonIndex);
|
||||
m_listButtons.removeOne(bType);
|
||||
}
|
||||
QSettings().setValue("buttons", QVariant::fromValue(m_listButtons));
|
||||
ConfigHandler().setButtons(m_listButtons);
|
||||
}
|
||||
|
||||
void ButtonListView::reverseItemCheck(QListWidgetItem *item){
|
||||
@@ -96,11 +93,12 @@ void ButtonListView::selectAll() {
|
||||
}
|
||||
|
||||
void ButtonListView::updateComponents() {
|
||||
m_listButtons = QSettings().value("buttons").value<QList<int> >();
|
||||
m_listButtons = ConfigHandler().getButtons();
|
||||
auto listTypes = CaptureButton::getIterableButtonTypes();
|
||||
for(int i = 0; i < this->count(); ++i) {
|
||||
QListWidgetItem* item = this->item(i);
|
||||
if (m_listButtons.contains(listTypes.at(i))) {
|
||||
auto elem = static_cast<CaptureButton::ButtonType>(listTypes.at(i));
|
||||
if (m_listButtons.contains(elem)) {
|
||||
item->setCheckState(Qt::Checked);
|
||||
} else {
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
|
||||
@@ -36,7 +36,7 @@ protected:
|
||||
void initButtonList();
|
||||
|
||||
private:
|
||||
QList<int> m_listButtons;
|
||||
QList<CaptureButton::ButtonType> m_listButtons;
|
||||
QMap<QString, CaptureButton::ButtonType> m_buttonTypeByName;
|
||||
|
||||
void updateActiveButtons(QListWidgetItem *);
|
||||
|
||||
@@ -38,8 +38,6 @@ Controller::Controller() : m_captureWindow(nullptr)
|
||||
{
|
||||
qApp->setQuitOnLastWindowClosed(false);
|
||||
|
||||
initDefaults();
|
||||
|
||||
// init tray icon
|
||||
#if defined(Q_OS_LINUX)
|
||||
if (!ConfigHandler().disabledTrayIconValue()) {
|
||||
@@ -63,16 +61,6 @@ Controller *Controller::getInstance() {
|
||||
return &c;
|
||||
}
|
||||
|
||||
// initDefaults inits the global config in the first execution of the program
|
||||
void Controller::initDefaults() {
|
||||
ConfigHandler config;
|
||||
//config.setNotInitiated();
|
||||
if (!config.initiatedIsSet()) {
|
||||
config.setDefaults();
|
||||
config.setInitiated();
|
||||
}
|
||||
}
|
||||
|
||||
// creation of a new capture in GUI mode
|
||||
void Controller::createVisualCapture(const uint id, const QString &forcedSavePath) {
|
||||
if (!m_captureWindow) {
|
||||
|
||||
@@ -56,7 +56,6 @@ public slots:
|
||||
void updateConfigComponents();
|
||||
|
||||
private slots:
|
||||
void initDefaults();
|
||||
|
||||
private:
|
||||
Controller();
|
||||
|
||||
@@ -26,12 +26,18 @@ ConfigHandler::ConfigHandler(){
|
||||
}
|
||||
|
||||
QList<CaptureButton::ButtonType> ConfigHandler::getButtons() {
|
||||
QList<int> buttons = m_settings.value("buttons").value<QList<int> >();
|
||||
bool modified = normalizeButtons(buttons);
|
||||
if (modified) {
|
||||
m_settings.setValue("buttons", QVariant::fromValue(buttons));
|
||||
QList<CaptureButton::ButtonType> buttons;
|
||||
if (m_settings.contains("buttons")) {
|
||||
QList<int> buttonsInt = m_settings.value("buttons").value<QList<int> >();
|
||||
bool modified = normalizeButtons(buttonsInt);
|
||||
if (modified) {
|
||||
m_settings.setValue("buttons", QVariant::fromValue(buttonsInt));
|
||||
}
|
||||
buttons = fromIntToButton(buttonsInt);
|
||||
} else {
|
||||
buttons = CaptureButton::getIterableButtonTypes().toList();
|
||||
}
|
||||
return fromIntToButton(buttons);
|
||||
return buttons;
|
||||
}
|
||||
|
||||
void ConfigHandler::setButtons(const QList<CaptureButton::ButtonType> &buttons) {
|
||||
@@ -49,7 +55,11 @@ void ConfigHandler::setSavePath(const QString &savePath) {
|
||||
}
|
||||
|
||||
QColor ConfigHandler::uiMainColorValue() {
|
||||
return m_settings.value("uiColor").value<QColor>();
|
||||
QColor res = QColor(116, 0, 150);
|
||||
if (m_settings.contains("uiColor")) {
|
||||
res = m_settings.value("uiColor").value<QColor>();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void ConfigHandler::setUIMainColor(const QColor &c) {
|
||||
@@ -57,7 +67,11 @@ void ConfigHandler::setUIMainColor(const QColor &c) {
|
||||
}
|
||||
|
||||
QColor ConfigHandler::uiContrastColorValue() {
|
||||
return m_settings.value("contastUiColor").value<QColor>();
|
||||
QColor res = QColor(86, 0, 120);
|
||||
if (m_settings.contains("contastUiColor")) {
|
||||
res = m_settings.value("contastUiColor").value<QColor>();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void ConfigHandler::setUIContrastColor(const QColor &c) {
|
||||
@@ -65,7 +79,11 @@ void ConfigHandler::setUIContrastColor(const QColor &c) {
|
||||
}
|
||||
|
||||
QColor ConfigHandler::drawColorValue() {
|
||||
return m_settings.value("drawColor").value<QColor>();
|
||||
QColor res(Qt::red);
|
||||
if (m_settings.contains("drawColor")) {
|
||||
res = m_settings.value("drawColor").value<QColor>();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void ConfigHandler::setDrawColor(const QColor &c) {
|
||||
@@ -73,7 +91,11 @@ void ConfigHandler::setDrawColor(const QColor &c) {
|
||||
}
|
||||
|
||||
bool ConfigHandler::showHelpValue() {
|
||||
return m_settings.value("showHelp").toBool();
|
||||
bool res = true;
|
||||
if (m_settings.contains("showHelp")) {
|
||||
res = m_settings.value("showHelp").toBool();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void ConfigHandler::setShowHelp(const bool showHelp) {
|
||||
@@ -81,7 +103,11 @@ void ConfigHandler::setShowHelp(const bool showHelp) {
|
||||
}
|
||||
|
||||
bool ConfigHandler::desktopNotificationValue() {
|
||||
return m_settings.value("showDesktopNotification").toBool();
|
||||
bool res = true;
|
||||
if (m_settings.contains("showDesktopNotification")) {
|
||||
res = m_settings.value("showDesktopNotification").toBool();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void ConfigHandler::setDesktopNotification(const bool showDesktopNotification) {
|
||||
@@ -97,7 +123,11 @@ void ConfigHandler::setFilenamePattern(const QString &pattern) {
|
||||
}
|
||||
|
||||
bool ConfigHandler::disabledTrayIconValue() {
|
||||
return m_settings.value("disabledTrayIcon").toBool();
|
||||
bool res = false;
|
||||
if (m_settings.contains("disabledTrayIcon")) {
|
||||
res = m_settings.value("disabledTrayIcon").toBool();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void ConfigHandler::setDisabledTrayIcon(const bool disabledTrayIcon) {
|
||||
@@ -105,7 +135,11 @@ void ConfigHandler::setDisabledTrayIcon(const bool disabledTrayIcon) {
|
||||
}
|
||||
|
||||
int ConfigHandler::drawThicknessValue() {
|
||||
return m_settings.value("drawThickness").toInt();
|
||||
int res = 0;
|
||||
if (m_settings.contains("drawThickness")) {
|
||||
res = m_settings.value("drawThickness").toInt();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void ConfigHandler::setdrawThickness(const int thickness) {
|
||||
@@ -171,25 +205,13 @@ void ConfigHandler::setContrastOpacity(const int transparency) {
|
||||
m_settings.setValue("contrastOpacity", transparency);
|
||||
}
|
||||
|
||||
bool ConfigHandler::initiatedIsSet() {
|
||||
return m_settings.value("initiated").toBool();
|
||||
}
|
||||
|
||||
void ConfigHandler::setInitiated() {
|
||||
m_settings.setValue("initiated", true);
|
||||
}
|
||||
|
||||
void ConfigHandler::setNotInitiated() {
|
||||
m_settings.setValue("initiated", false);
|
||||
}
|
||||
|
||||
void ConfigHandler::setDefaults() {
|
||||
setShowHelp(true);
|
||||
setDesktopNotification(true);
|
||||
setDrawColor(QColor(Qt::red));
|
||||
setUIMainColor(QColor(116, 0, 150));
|
||||
setUIContrastColor(QColor(86, 0, 120));
|
||||
setdrawThickness(0);
|
||||
setdrawThickness(0);
|
||||
setContrastOpacity(190);
|
||||
setDisabledTrayIcon(false);
|
||||
setAllTheButtons();
|
||||
|
||||
@@ -66,12 +66,7 @@ public:
|
||||
int contrastOpacityValue();
|
||||
void setContrastOpacity(const int);
|
||||
|
||||
|
||||
bool initiatedIsSet();
|
||||
void setInitiated();
|
||||
void setNotInitiated();
|
||||
void setDefaults();
|
||||
|
||||
void setAllTheButtons();
|
||||
|
||||
QString configFilePath() const;
|
||||
|
||||
Reference in New Issue
Block a user