-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsm3_color.cpp
285 lines (210 loc) · 10.1 KB
/
sm3_color.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
//! \file sm_font.cpp
#include "sysmon3.h"
#include "sm3_font.h"
SM_Color::SM_Color( SM_Settings* setngs )
{
settingsPtr = setngs;
QString family = settingsPtr->value( "fontFamily" );
int fontSize = settingsPtr->value( "fontSize" ).toInt();
QFont oldfont = QFont( family, fontSize );
widgetsPtr = new SM_Widgets( oldfont );
// Get current font; second parameter is default
bool checked = settingsPtr->value( "fontBold" ) == "true";
int weight = checked ? QFont::Bold : QFont::Normal;
// Frame layout
setWindowTitle( "Color Selection Dialog" );
setAttribute( Qt::WA_DeleteOnClose );
QBoxLayout* topbox = new QVBoxLayout( this );
topbox->setSpacing( 2 );
// Label color
QGridLayout* labelLayout = new QGridLayout();
pb_label_color = widgetsPtr->sm_pushbutton( tr( "Change\nLabel Color" ) );
labelLayout->addWidget( pb_label_color, 0, 0 );
connect( pb_label_color, SIGNAL( clicked() ), SLOT( label_color() ) );
pb_label_background = widgetsPtr->sm_pushbutton( tr( "Change\nLabel Background" ) );
labelLayout->addWidget( pb_label_background, 0 , 1 );
connect( pb_label_background, SIGNAL( clicked() ), SLOT( label_background() ) );
sample_label = widgetsPtr->sm_label( "Sample Label" );
sample_label->setFont( QFont( family, fontSize, weight ) );
labelLayout->addWidget( sample_label, 0, 2 );
// Data color
pb_data_color = widgetsPtr->sm_pushbutton( tr( "Change\nData Color" ) );
labelLayout->addWidget( pb_data_color, 1, 0 );
connect( pb_data_color, SIGNAL( clicked() ), SLOT( data_color() ) );
pb_data_background = widgetsPtr->sm_pushbutton( tr( "Change\nData Background" ) );
labelLayout->addWidget( pb_data_background, 1, 1 );
connect( pb_data_background, SIGNAL( clicked() ), SLOT( data_background() ) );
sample_data = widgetsPtr->sm_label( "Sample Data" );
sample_data->setFont( QFont( family, fontSize, weight ) );
labelLayout->addWidget( sample_data, 1, 2 );
// ProgressBar color
pb_progress_color = widgetsPtr->sm_pushbutton( tr( "Change\nProgress Color" ) );
labelLayout->addWidget( pb_progress_color, 2, 0 );
connect( pb_progress_color, SIGNAL( clicked() ), SLOT( progress_color() ) );
pb_progress_background = widgetsPtr->sm_pushbutton( tr( "Change\nProgress Background" ) );
labelLayout->addWidget( pb_progress_background, 2, 1 );
connect( pb_progress_background, SIGNAL( clicked() ), SLOT( progress_background() ) );
sample_progress = new QProgressBar();
sample_progress->setRange( 0, 100 );
sample_progress->setValue( 75 );
sample_progress->setFont( QFont( family, fontSize, weight ) );
labelLayout->addWidget( sample_progress, 2, 2 );
topbox->addLayout( labelLayout );
// Default
pb_default = widgetsPtr->sm_pushbutton( tr( "Set Default Colors" ) );
connect( pb_default, SIGNAL( clicked() ), SLOT( setDefault() ) );
topbox->addWidget( pb_default );
// Buttons
pb_apply = widgetsPtr->sm_pushbutton( tr( "Apply" ) );
connect( pb_apply, SIGNAL( clicked() ), SLOT( apply() ) );
//pb_help = sm_pushbutton( tr( "Help" ) );
//connect( pb_help, SIGNAL( clicked() ), SLOT( help() ) );
pb_exit = widgetsPtr->sm_pushbutton( tr( "Exit" ) );
connect( pb_exit, SIGNAL( clicked() ), SLOT( close() ) );
QBoxLayout* buttons = new QHBoxLayout();
buttons->addWidget( pb_apply );
//buttons->addWidget( pb_help );
buttons->addWidget( pb_exit );
topbox->addLayout( buttons );
redraw(); // Set colors for examples
}
void SM_Color::setDefault( void )
{
QPalette p = sample_label->palette();
// Get defaults from SM_Settings
QColor labelColor = QColor( settingsPtr->getDefault( "labelColor" ) );
QColor labelBg = QColor( settingsPtr->getDefault( "labelBg" ) );
QColor dataColor = QColor( settingsPtr->getDefault( "dataColor" ) );
QColor dataBg = QColor( settingsPtr->getDefault( "dataBg" ) );
QColor progressColor = QColor( settingsPtr->getDefault( "progressColor" ) );
QColor progressBg = QColor( settingsPtr->getDefault( "progressBg" ) );
// The Active group is used for the window that has keyboard focus.
p.setColor( QPalette::Active, QPalette::Window, dataBg );
p.setColor( QPalette::Active, QPalette::WindowText, dataColor );
p.setColor( QPalette::Active, QPalette::Highlight, progressColor );
p.setColor( QPalette::Active, QPalette::Base, progressBg );
//The Inactive group is used for other windows.
p.setColor( QPalette::Inactive, QPalette::Window, dataBg );
p.setColor( QPalette::Inactive, QPalette::WindowText, dataColor );
p.setColor( QPalette::Inactive, QPalette::Highlight, progressColor );
p.setColor( QPalette::Inactive, QPalette::Base, progressBg );
sample_data ->setPalette( p );
sample_progress->setPalette( p );
p.setColor( QPalette::Active, QPalette::Window, labelBg );
p.setColor( QPalette::Active, QPalette::WindowText, labelColor );
p.setColor( QPalette::Inactive, QPalette::Window, labelBg );
p.setColor( QPalette::Inactive, QPalette::WindowText, labelColor );
sample_label ->setPalette( p );
}
void SM_Color::label_color( void )
{
QPalette p = sample_label->palette();
QColor oldColor = p.color( QPalette::Active, QPalette::WindowText);
QColor newColor = QColorDialog::getColor(oldColor, this );
if ( ! newColor.isValid() ) return;
p.setColor( QPalette::Active, QPalette::WindowText, newColor );
p.setColor( QPalette::Inactive, QPalette::WindowText, newColor );
sample_label->setPalette( p );
}
void SM_Color::label_background( void )
{
QPalette p = sample_label->palette();
// Background is QPalette::Window
QColor oldColor = p.color( QPalette::Active, QPalette::Window);
QColor newColor = QColorDialog::getColor(oldColor, this );
if ( ! newColor.isValid() ) return;
p.setColor( QPalette::Active, QPalette::Window, newColor );
p.setColor( QPalette::Inactive, QPalette::Window, newColor );
sample_label->setPalette( p );
}
void SM_Color::data_color( void )
{
QPalette p = sample_data->palette();
QColor oldColor = p.color( QPalette::Active, QPalette::WindowText);
QColor newColor = QColorDialog::getColor(oldColor, this );
if ( ! newColor.isValid() ) return;
p.setColor( QPalette::Active, QPalette::WindowText, newColor );
p.setColor( QPalette::Inactive, QPalette::WindowText, newColor );
sample_data->setPalette( p );
}
void SM_Color::data_background( void )
{
QPalette p = sample_data->palette();
QColor oldColor = p.color( QPalette::Active, QPalette::Window);
QColor newColor = QColorDialog::getColor(oldColor, this );
if ( ! newColor.isValid() ) return;
p.setColor( QPalette::Active, QPalette::Window, newColor );
p.setColor( QPalette::Inactive, QPalette::Window, newColor );
sample_data->setPalette( p );
}
void SM_Color::progress_color( void )
{
QPalette p = sample_progress->palette();
QColor oldColor = p.color( QPalette::Active, QPalette::WindowText);
QColor newColor = QColorDialog::getColor(oldColor, this );
if ( ! newColor.isValid() ) return;
p.setColor( QPalette::Active, QPalette::Highlight, newColor );
p.setColor( QPalette::Inactive, QPalette::Highlight, newColor );
sample_progress->setPalette( p );
}
void SM_Color::progress_background( void )
{
QPalette p = sample_progress->palette();
QColor oldColor = p.color( QPalette::Active, QPalette::Window);
QColor newColor = QColorDialog::getColor(oldColor, this );
if ( ! newColor.isValid() ) return;
p.setColor( QPalette::Active, QPalette::Base, newColor );
p.setColor( QPalette::Inactive, QPalette::Base, newColor );
sample_progress->setPalette( p );
}
void SM_Color::update( int index )
{
index++; // So the comiler does not complain about unused parameter
redraw();
}
void SM_Color::apply()
{
QPalette p = sample_label->palette();
QColor text = p.color( QPalette::Active, QPalette::WindowText );
QColor background = p.color( QPalette::Active, QPalette::Window );
// Set color values in settingsPtr
settingsPtr->setValue( "labelColor", text .name() );
settingsPtr->setValue( "labelBg" , background.name() );
p = sample_data->palette();
text = p.color( QPalette::Active, QPalette::WindowText );
background = p.color( QPalette::Active, QPalette::Window );
settingsPtr->setValue( "dataColor", text.name() );
settingsPtr->setValue( "dataBg" , background.name() );
p = sample_progress->palette();
text = p.color( QPalette::Active, QPalette::Highlight );
background = p.color( QPalette::Active, QPalette::Base );
settingsPtr->setValue( "progressColor", text.name() );
settingsPtr->setValue( "progressBg" , background.name() );
settingsPtr->sync();
emit updateColors();
}
//void SM_Font::help()
//{
// US_Help* help = new US_Help();
// help->show_help( "manual/usfont.html" );
//}
void SM_Color::redraw( void )
{
QString lblFg = settingsPtr->value( "labelColor" );
QString lblBg = settingsPtr->value( "labelBg" );
QString dataFg = settingsPtr->value( "dataColor" );
QString dataBg = settingsPtr->value( "dataBg" );
QString progressFg = settingsPtr->value( "progressColor" );
QString progressBg = settingsPtr->value( "progressBg" );
QPalette p;
p.setColor( QPalette::Active, QPalette::WindowText, QColor( lblFg ) );
p.setColor( QPalette::Active, QPalette::Window, QColor( lblBg ) );
sample_label->setPalette( p );
p.setColor( QPalette::Active, QPalette::WindowText, QColor( dataFg ) );
p.setColor( QPalette::Active, QPalette::Window, QColor( dataBg ) );
sample_data->setPalette( p );
p.setColor( QPalette::Active, QPalette::Highlight, QColor( progressFg ) );
p.setColor( QPalette::Active, QPalette::Base, QColor( progressBg ) );
sample_progress->setPalette( p );
this->repaint();
}