Skip to content

Commit 9488072

Browse files
committed
custom color selection reset added
1 parent 10abb7e commit 9488072

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/utils/Settings.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ QString get_string(const char* name) {
3838
return value;
3939
}
4040

41+
QString get_default_string(const char* name) {
42+
QString value;
43+
if(settingsDefault->contains(QString::fromUtf8(name))){
44+
value = settingsDefault->value(QString::fromUtf8(name)).toString();
45+
}
46+
return value;
47+
}
4148
bool get_bool(const char* name) {
4249
bool value;
4350
if(settings->contains(QString::fromUtf8(name))){

src/utils/Settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define _SETTINGS_H
44
void settings_init();
55
QString get_string(const char* name);
6+
QString get_default_string(const char* name);
67
void set_string(const char* name, const QString value);
78
int get_int(const char* name);
89
void set_int(const char* name, int value);

src/widgets/Button.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,17 @@ QPushButton* create_color_button(QColor fcolor, bool read_only, const char* name
6060
QObject::connect(button, &QPushButton::released, [=]() mutable {
6161
size_t diff = get_epoch() - time;
6262
if(diff > 500000 && ! read_only){
63-
QColor newColor = QColorDialog::getColor(drawing->penColor, NULL, _("Select Color"));
64-
if(newColor.isValid()) {
65-
if(strlen(name) > 0){
66-
set_string(name, newColor.name());
67-
}
68-
color = newColor;
69-
button->setStyleSheet(QString(
70-
"background-color: "+color.name()+";"
71-
"border-radius: 12px;"
72-
));
73-
} else {
74-
color = QColor(get_string(name));
63+
color = QColorDialog::getColor(drawing->penColor, NULL, _("Select Color"));
64+
if(!color.isValid()) {
65+
color = QColor(get_default_string(name));
7566
}
67+
if(strlen(name) > 0){
68+
set_string(name, color.name());
69+
}
70+
button->setStyleSheet(QString(
71+
"background-color: "+color.name()+";"
72+
"border-radius: 12px;"
73+
));
7674
}
7775
drawing->penColor = color;
7876
set_string("color", drawing->penColor.name());

0 commit comments

Comments
 (0)