-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editorprefdialog.cpp
142 lines (117 loc) · 4.43 KB
/
editorprefdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// This source code is part of QAbc, a minimal ABC music notation editor.
// QAbc is Copyright © 2021 Benoît Rouits <[email protected]>.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "editorprefdialog.h"
#include <QVBoxLayout>
#include <QPushButton>
#include <QColorDialog>
#include "config.h"
#include "settings.h"
EditorPrefDialog::EditorPrefDialog(QWidget *parent) : QDialog(parent)
{
Settings settings;
setWindowTitle(tr("Editor settings"));
setMinimumSize(400, 320);
mainLayout = new QVBoxLayout;
int fontRange = settings.value(EDITOR_FONT_RANGE).toInt();
fontRangeLabel = new QLabel(tr("Font enlargement"));
fontRangeSpinBox = new QSpinBox;
fontRangeSpinBox->setRange(-5,+5);
fontRangeSpinBox->setValue(fontRange);
fontRangeLabel->setBuddy(fontRangeSpinBox);
QHBoxLayout* fshbox = new QHBoxLayout;
fshbox->addWidget(fontRangeLabel);
fshbox->addWidget(fontRangeSpinBox);
mainLayout->addLayout(fshbox);
bool highlight = settings.value(EDITOR_HIGHLIGHT).toBool();
highlightLabel = new QLabel(tr("Highlight current line"));
highlightCheck = new QCheckBox;
highlightCheck->setChecked(highlight);
highlightLabel->setBuddy(highlightCheck);
QHBoxLayout* hlhbox = new QHBoxLayout;
hlhbox->addWidget(highlightLabel);
hlhbox->addWidget(highlightCheck);
mainLayout->addLayout(hlhbox);
/* WARNING: labels, keys, buttons in the same order */
colorLabels << tr("Header color") \
<< tr("Comment color") \
<< tr("Extra instruction color") \
<< tr("Measure bar color") \
<< tr("Decoration color") \
<< tr("Guitar chord color") \
<< tr("Lyric color");
colorKeys << EDITOR_HEADER_COLOR \
<< EDITOR_COMMENT_COLOR \
<< EDITOR_EXTRAINSTR_COLOR \
<< EDITOR_BAR_COLOR \
<< EDITOR_DECORATION_COLOR \
<< EDITOR_GCHORD_COLOR \
<< EDITOR_LYRIC_COLOR;
for (int i = 0; i < colorKeys.length(); i++) {
QColor color = settings.value(colorKeys.at(i)).toString();
QHBoxLayout* hbox = new QHBoxLayout;
QLabel* label = new QLabel(colorLabels.at(i));
QPushButton* butt = new QPushButton;
QPalette pal = butt->palette();
pal.setColor(QPalette::Button, color);
pal.setColor(QPalette::ButtonText, color);
label->setBuddy(butt);
butt->setText(QVariant(color).toString());
butt->setStyleSheet("color: " + QVariant(color).toString() + ";");
butt->setPalette(pal);
butt->setAutoFillBackground(true);
butt->update();
colorButtons.append(butt);
connect(butt, &QPushButton::clicked, this, &EditorPrefDialog::onColorButtonClicked);
hbox->addWidget(label);
hbox->addWidget(butt);
mainLayout->addLayout(hbox);
}
buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
mainLayout->addWidget(buttons);
setLayout(mainLayout);
}
EditorPrefDialog::~EditorPrefDialog()
{
delete mainLayout;
}
QColor EditorPrefDialog::getColor(QString key)
{
int i = colorKeys.indexOf(key);
QPushButton* butt = colorButtons.at(i);
QPalette pal = butt->palette();
QColor color = pal.color(QPalette::Button);
return color;
}
bool EditorPrefDialog::getHighlight()
{
return highlightCheck->isChecked();
}
int EditorPrefDialog::getFontRange()
{
return fontRangeSpinBox->value();
}
void EditorPrefDialog::onColorButtonClicked()
{
QPushButton* butt = static_cast<QPushButton*>(sender());
QPalette pal = butt->palette();
QColor color = pal.color(QPalette::Button);
QColor choose = QColorDialog::getColor(color, this);
if (!choose.isValid())
return;
pal.setColor(QPalette::Button, choose);
pal.setColor(QPalette::ButtonText, choose);
butt->setAutoFillBackground(true);
butt->setStyleSheet("color: " + QVariant(choose).toString() + ";");
butt->setPalette(pal);
butt->setText(QVariant(choose).toString());
butt->update();
}