2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
11 #include "pref_clock.h"
18 #include <QPushButton>
19 #include <QColorDialog>
23 PrefClock::PrefClock() {
24 QVBoxLayout
* main_layout
= new QVBoxLayout(this);
27 QHBoxLayout
* layout
= new QHBoxLayout
;
28 QLabel
* label
= new QLabel("Background color:", this);
29 m_background_button
= new QPushButton("", this);
30 layout
->addWidget(label
);
32 layout
->addWidget(m_background_button
);
33 main_layout
->addLayout(layout
);
34 connect(m_background_button
, SIGNAL(clicked()), this, SLOT(setBackgroundColor()));
37 createSpin(main_layout
, "Caption font size:", m_captionSpin
);
38 createSpin(main_layout
, "Time font size:", m_timeSpin
);
39 createSpin(main_layout
, "Decimals font size:", m_decsSpin
);
40 createSpin(main_layout
, "Player font size:", m_playerSpin
);
42 QHBoxLayout
* button_layout
= new QHBoxLayout
;
43 button_layout
->addStretch();
44 m_ok
= new QPushButton("&OK", this);
45 m_cancel
= new QPushButton("&Cancel", this);
46 button_layout
->addWidget(m_ok
);
47 button_layout
->addWidget(m_cancel
);
48 connect(m_ok
, SIGNAL(clicked()), this, SLOT(accept()));
49 connect(m_cancel
, SIGNAL(clicked()), this, SLOT(reject()));
51 main_layout
->addLayout(button_layout
);
56 void PrefClock::load() {
57 Settings s
= settings
.group("Clock");
58 // std::cout << "caption font size: " << settings["captionFontSize"].value<int>() << std::endl;
59 m_captionSpin
->setValue(s
["captionFontSize"].value
<int>());
60 m_timeSpin
->setValue(s
["timeFontSize"].value
<int>());
61 m_decsSpin
->setValue(s
["decsFontSize"].value
<int>());
62 m_playerSpin
->setValue(s
["playerFontSize"].value
<int>());
65 QPalette palette
= m_background_button
->palette();
66 palette
.setColor(QPalette::Button
, s
["background"].value
<QColor
>());
67 m_background_button
->setPalette(palette
);
71 void PrefClock::createSpin(QBoxLayout
* parent
, const QString
& labelText
, QSpinBox
*& spin
) {
72 QHBoxLayout
* layout
= new QHBoxLayout
;
73 parent
->addLayout(layout
);
74 spin
= new QSpinBox(this);
75 spin
->setRange(6, 40);
76 QLabel
* label
= new QLabel(labelText
, this);
77 layout
->addWidget(label
);
79 layout
->addWidget(spin
);
82 void PrefClock::apply() {
83 Settings s
= settings
.group("Clock");
84 s
["captionFontSize"] = m_captionSpin
->value();
85 s
["timeFontSize"] = m_timeSpin
->value();
86 s
["decsFontSize"] = m_decsSpin
->value();
87 s
["playerFontSize"] = m_playerSpin
->value();
88 s
["background"] = m_background_button
->palette().color(QPalette::Button
);
91 void PrefClock::setBackgroundColor() {
92 QColor color
= QColorDialog::getColor(m_background_button
->palette().color(QPalette::Button
));
93 if (color
.isValid()) {
94 QPalette palette
= m_background_button
->palette();
95 palette
.setColor(QPalette::Button
, color
);
96 m_background_button
->setPalette(palette
);
99 #include "pref_clock.moc"