1 /* BEGIN_COMMON_COPYRIGHT_HEADER
2 * (c)LGPL2+
3 *
4 * LXQt - a lightweight, Qt based, desktop toolset
5 * https://lxqt.org
6 *
7 * Copyright: 2012 Razor team
8 * Authors:
9 * Christian Surlykke <christian@surlykke.dk>
10 *
11 * This program or library is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20
21 * You should have received a copy of the GNU Lesser General
22 * Public License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301 USA
25 *
26 * END_COMMON_COPYRIGHT_HEADER */
27 #include <LXQt/Settings>
28
29 #include <QDebug>
30 #include <QLabel>
31 #include <QGroupBox>
32 #include <Solid/Battery>
33
34 #include "batterywatchersettings.h"
35 #include "ui_batterywatchersettings.h"
36 #include "powermanagementsettings.h"
37
BatteryWatcherSettings(QWidget * parent)38 BatteryWatcherSettings::BatteryWatcherSettings(QWidget *parent) :
39 QWidget(parent),
40 mSettings(),
41 mUi(new Ui::BatteryWatcherSettings),
42 mChargingIconProducer(),
43 mDischargingIconProducer()
44
45 {
46 mUi->setupUi(this);
47 fillComboBox(mUi->actionComboBox);
48 mUi->chargeLevelSlider->setValue(53);
49 mChargingIconProducer.updateState(Solid::Battery::Charging);
50 mDischargingIconProducer.updateState(Solid::Battery::Discharging);
51
52 connect(mUi->groupBox, &QGroupBox::clicked, this, &BatteryWatcherSettings::saveSettings);
53 connect(mUi->actionComboBox, QOverload<int>::of(&QComboBox::activated), this, &BatteryWatcherSettings::saveSettings);
54 connect(mUi->warningSpinBox, &QSpinBox::editingFinished, this, &BatteryWatcherSettings::saveSettings);
55 connect(mUi->levelSpinBox, &QSpinBox::editingFinished, this, &BatteryWatcherSettings::saveSettings);
56 connect(mUi->showIconCheckBox, &QCheckBox::clicked, this, &BatteryWatcherSettings::saveSettings);
57 connect(mUi->showIconCheckBox, &QCheckBox::clicked, mUi->previewBox, &QGroupBox::setEnabled);
58 connect(mUi->useThemeIconsCheckBox, &QCheckBox::clicked, this, &BatteryWatcherSettings::saveSettings);
59 connect(mUi->useThemeIconsCheckBox, &QCheckBox::clicked, this, &BatteryWatcherSettings::updatePreview);
60 connect(mUi->chargeLevelSlider, &QSlider::valueChanged, this, &BatteryWatcherSettings::updatePreview);
61 connect(&mChargingIconProducer, &IconProducer::iconChanged, this, &BatteryWatcherSettings::onChargeIconChanged);
62 connect(&mDischargingIconProducer, &IconProducer::iconChanged, this, &BatteryWatcherSettings::onDischargeIconChanged);
63 updatePreview();
64 }
65
~BatteryWatcherSettings()66 BatteryWatcherSettings::~BatteryWatcherSettings()
67 {
68 delete mUi;
69 }
70
loadSettings()71 void BatteryWatcherSettings::loadSettings()
72 {
73 mUi->groupBox->setChecked(mSettings.isBatteryWatcherEnabled());
74 setComboBoxToValue(mUi->actionComboBox, mSettings.getPowerLowAction());
75 mUi->warningSpinBox->setValue(mSettings.getPowerLowWarningTime());
76 mUi->levelSpinBox->setValue(mSettings.getPowerLowLevel());
77 mUi->showIconCheckBox->setChecked(mSettings.isShowIcon());
78 mUi->useThemeIconsCheckBox->setChecked(mSettings.isUseThemeIcons());
79 }
80
saveSettings()81 void BatteryWatcherSettings::saveSettings()
82 {
83 mSettings.setBatteryWatcherEnabled(mUi->groupBox->isChecked());
84 mSettings.setPowerLowAction(currentValue(mUi->actionComboBox));
85 mSettings.setPowerLowWarningTime(mUi->warningSpinBox->value());
86 mSettings.setPowerLowLevel(mUi->levelSpinBox->value());
87 mSettings.setShowIcon(mUi->showIconCheckBox->isChecked());
88 mSettings.setUseThemeIcons(mUi->useThemeIconsCheckBox->isChecked());
89 }
90
updatePreview()91 void BatteryWatcherSettings::updatePreview()
92 {
93 mUi->previewBox->setTitle(tr("Preview") + QString::fromLatin1(" (%1)").arg(mSettings.isUseThemeIcons() ? QIcon::themeName() : tr("built in")));
94
95 int chargePercent = mUi->chargeLevelSlider->value();
96 mChargingIconProducer.updateChargePercent(chargePercent);
97 mDischargingIconProducer.updateChargePercent(chargePercent);
98 mUi->chargeLevelLabel->setText(tr("Level: %1%").arg(chargePercent));
99 }
100
onChargeIconChanged()101 void BatteryWatcherSettings::onChargeIconChanged()
102 {
103 mUi->chargingIcon->setPixmap(mChargingIconProducer.mIcon.pixmap(mUi->chargingIcon->size()));
104 mUi->chargingLabel->setText(mChargingIconProducer.mIconName);
105 }
106
onDischargeIconChanged()107 void BatteryWatcherSettings::onDischargeIconChanged()
108 {
109 mUi->dischargingIcon->setPixmap(mDischargingIconProducer.mIcon.pixmap(mUi->dischargingIcon->size()));
110 mUi->dischargingLabel->setText(mDischargingIconProducer.mIconName);
111 }
112