fixed gentoo support
[qbat.git] / settings.cpp
blobb1314d2506d2ba9f4723c7a20e5e92ed7b291f38
1 //
2 // C++ Implementation: settings
3 //
4 // Author: Oliver Groß <z.o.gross@gmx.de>, (C) 2008
5 //
6 // Copyright: See COPYING file that comes with this distribution
7 //
8 #include "settings.h"
9 #include <QColorDialog>
11 namespace qbat {
12 CSettings::CSettings(QWidget * parent) : QDialog(parent) {
13 ui.setupUi(this);
14 setWindowIcon(QIcon(UI_ICON_QBAT_SMALL));
16 colorSelectButtons.setExclusive(false);
17 colorSelectButtons.addButton(ui.mainFullColorButton, 1 + UI_COLOR_BRUSH_FULL);
18 colorSelectButtons.addButton(ui.mainChargedColorButton, 1 + UI_COLOR_BRUSH_CHARGED);
19 colorSelectButtons.addButton(ui.mainEmptyColorButton, 1 + UI_COLOR_BRUSH_EMPTY);
20 colorSelectButtons.addButton(ui.textChargingColorButton, 1 + UI_COLOR_PEN_CHARGE);
21 colorSelectButtons.addButton(ui.textDischargingColorButton, 1 + UI_COLOR_PEN_DISCHARGE);
22 colorSelectButtons.addButton(ui.textFullColorButton, 1 + UI_COLOR_PEN_FULL);
23 colorSelectButtons.addButton(ui.poleChargingColorButton, 1 + UI_COLOR_BRUSH_POLE_CHARGE);
24 colorSelectButtons.addButton(ui.poleDischargingColorButton, 1 + UI_COLOR_BRUSH_POLE_DISCHARGE);
25 colorSelectButtons.addButton(ui.poleFullColorButton, 1 + UI_COLOR_BRUSH_POLE_FULL);
26 connect(&colorSelectButtons, SIGNAL(buttonClicked(int)), this, SLOT(editColor(int)));
29 CSettings::~CSettings() {}
31 void CSettings::applySettings() {
32 m_Settings->handleCritical = ui.criticalGroup->isChecked();
33 m_Settings->criticalCapacity = ui.criticalCapacitySpin->value();
35 m_Settings->executeCommand = ui.criticalCommandRadio->isChecked();
36 m_Settings->criticalCommand = ui.criticalCommandEdit->text();
38 m_Settings->confirmCommand = ui.confirmCommandBox->isChecked();
39 m_Settings->confirmWithTimeout = ui.timeoutCheck->isChecked();
40 m_Settings->timeoutValue = ui.timeoutSpin->value();
42 for (int i = 0; i < UI_COUNT_COLORS; i++)
43 m_Settings->colors[i] = colors[i];
45 m_Settings->mergeBatteries = ui.mergeBatteriesCheck->isChecked();
47 m_Settings->showBalloon = ui.showBalloonCheck->isChecked();
48 m_Settings->pollingRate = ui.pollingRateSpin->value();
51 bool CSettings::execute(Settings * settings) {
52 ui.criticalGroup->setChecked(settings->handleCritical);
53 ui.criticalCapacitySpin->setValue(settings->criticalCapacity);
55 if (settings->executeCommand)
56 ui.criticalCommandRadio->setChecked(true);
57 else
58 ui.criticalWarningRadio->setChecked(true);
60 ui.criticalCommandEdit->setText(settings->criticalCommand);
61 ui.confirmCommandBox->setChecked(settings->confirmCommand);
62 ui.timeoutCheck->setChecked(settings->confirmWithTimeout);
63 ui.timeoutSpin->setValue(settings->timeoutValue);
66 QPixmap colorIcon(24, 24);
68 for (int i = 0; i < UI_COUNT_COLORS; i++) {
69 colorIcon.fill(settings->colors[i]);
70 colorSelectButtons.button(i+1)->setIcon(colorIcon);
71 colors[i] = settings->colors[i];
74 ui.mergeBatteriesCheck->setChecked(settings->mergeBatteries);
76 ui.pollingRateSpin->setValue(settings->pollingRate);
77 ui.showBalloonCheck->setChecked(settings->showBalloon);
79 m_Settings = settings;
81 if (exec()) {
82 applySettings();
83 return true;
85 else
86 return false;
89 void CSettings::editColor(int id) {
90 QColor color = QColorDialog::getColor(QColor(colors[id-1]), this);
91 if (color.isValid()) {
92 QPixmap colorIcon(24, 24);
93 colorIcon.fill(color);
95 colorSelectButtons.button(id)->setIcon(QIcon(colorIcon));
96 colors[id-1] = color.rgb();