[kde-doc-english] branches/KDE/4.5/kdebase/workspace/plasma/generic/applets/battery
Rafał Miłecki
zajec5 at gmail.com
Sun Aug 1 01:50:43 CEST 2010
SVN commit 1157716 by rmilecki:
Backport 1157714: Control any amount of brightness devices
Ship it! by Sebastian Kügler:
http://reviewboard.kde.org/r/4796/
GUI:
BUG: 199520
FIXED-IN: 4.5.0
M +46 -23 battery.cpp
M +8 -3 battery.h
--- branches/KDE/4.5/kdebase/workspace/plasma/generic/applets/battery/battery.cpp #1157715:1157716
@@ -81,9 +81,9 @@
m_batteryInfoLabel(0),
m_acLabelLabel(0),
m_acInfoLabel(0),
+ m_brightnessSliders(0),
m_profileLabel(0),
m_profileCombo(0),
- m_brightnessSlider(0),
m_minutes(0),
m_hours(0),
m_theme(0),
@@ -408,15 +408,24 @@
void Battery::brightnessChanged(const int brightness)
{
if (!m_ignoreBrightnessChange) {
- Solid::Control::PowerManager::setBrightness(brightness);
+ for (int i = 0; i < m_brightnessSliders->size(); ++i) {
+ const struct BrightnessSet *bs = &m_brightnessSliders->at(i);
+ if (bs->slider == sender()) {
+ Solid::Control::PowerManager::setBrightness(brightness, bs->device);
+ return;
}
}
+ kDebug() << "Received signal from not stored slider";
+ }
+}
-void Battery::updateSlider(const float brightness)
+void Battery::updateSliders()
{
- if (m_brightnessSlider->value() != (int)brightness) {
+ for (int i = 0; i < m_brightnessSliders->size(); ++i) {
+ const struct BrightnessSet *bs = &m_brightnessSliders->at(i);
+ float value = Solid::Control::PowerManager::brightness(bs->device);
m_ignoreBrightnessChange = true;
- m_brightnessSlider->setValue((int) brightness);
+ bs->slider->setValue(value);
m_ignoreBrightnessChange = false;
}
}
@@ -505,25 +514,39 @@
m_extenderApplet->updateConstraints(Plasma::StartupCompletedConstraint);
m_controlsLayout->addItem(m_extenderApplet, 1, 2, 2, 1);
- m_brightnessLabel = createBuddyLabel(m_controls);
+
+
+ m_brightnessSliders = new QList<BrightnessSet>;
+ Solid::Control::PowerManager::BrightnessControlsList controls = Solid::Control::PowerManager::brightnessControlsAvailable();
+ foreach (const QString &device, controls.keys()) {
+ struct BrightnessSet brightnessSet;
+
+ /* Device name */
+ brightnessSet.device = device;
+
+ /* Label */
+ brightnessSet.label = new Plasma::Label(m_controls);
+ brightnessSet.label = createBuddyLabel(m_controls);
#if KDE_IS_VERSION(4, 5, 60)
- m_brightnessLabel->setText(i18n("Screen Brightness:"));
+ brightnessSet.label->setText(i18n("Screen Brightness:"));
#else
- m_brightnessLabel->setText(i18n("Screen Brightness") + ':');
+ brightnessSet.label->setText(i18n("Screen Brightness") + ':');
#endif
+ m_controlsLayout->addItem(brightnessSet.label, row, 0);
- m_controlsLayout->addItem(m_brightnessLabel, row, 0);
-
- m_brightnessSlider = new Plasma::Slider(m_controls);
- m_brightnessSlider->setRange(0, 100);
- updateSlider(Solid::Control::PowerManager::brightness());
- m_brightnessSlider->nativeWidget()->setTickInterval(10);
- m_brightnessSlider->setOrientation(Qt::Horizontal);
- connect(m_brightnessSlider, SIGNAL(valueChanged(int)),
+ /* Slider */
+ brightnessSet.slider = new Plasma::Slider(m_controls);
+ brightnessSet.slider->setRange(0, 100);
+ brightnessSet.slider->nativeWidget()->setTickInterval(10);
+ brightnessSet.slider->setOrientation(Qt::Horizontal);
+ connect(brightnessSet.slider, SIGNAL(valueChanged(int)),
this, SLOT(brightnessChanged(int)));
+ m_controlsLayout->addItem(brightnessSet.slider, row, 1, 1, 2);
- m_controlsLayout->addItem(m_brightnessSlider, row, 1, 1, 2);
+ m_brightnessSliders->append(brightnessSet);
row++;
+ }
+ updateSliders();
m_profileLabel = createBuddyLabel(m_controls);
m_profileLabel->setText(i18n("Power Profile:"));
@@ -606,7 +629,9 @@
{
if (m_batteryLabelLabel) {
QFont infoFont = KGlobalSettings::generalFont();
- m_brightnessLabel->setFont(infoFont);
+ for (int i = 0; i < m_brightnessSliders->size(); ++i) {
+ m_brightnessSliders->at(i).label->setFont(infoFont);
+ }
m_profileLabel->setFont(infoFont);
QFont boldFont = infoFont;
@@ -719,10 +744,8 @@
}
}
- if (m_brightnessSlider) {
- updateSlider(Solid::Control::PowerManager::brightness());
+ updateSliders();
}
-}
void Battery::openConfig()
{
@@ -1069,8 +1092,8 @@
int posY = rect.y() + 4 * rect.height() / 5;
m_brightnessOSD->setGeometry(posX, posY, size.width(), size.height());
- if (m_extenderVisible && m_brightnessSlider) {
- updateSlider(brightness);
+ if (m_extenderVisible) {
+ updateSliders();
}
}
}
--- branches/KDE/4.5/kdebase/workspace/plasma/generic/applets/battery/battery.h #1157715:1157716
@@ -39,6 +39,12 @@
class Slider;
}
+struct BrightnessSet {
+ QString device;
+ Plasma::Label *label;
+ Plasma::Slider *slider;
+};
+
class BrightnessOSDWidget;
class Battery : public Plasma::PopupApplet
@@ -87,7 +93,7 @@
void sourceAdded(const QString &source);
void sourceRemoved(const QString &source);
void brightnessChanged(const int brightness);
- void updateSlider(const float brightness);
+ void updateSliders();
void openConfig();
void setProfile(const QString &profile);
void suspend();
@@ -135,10 +141,9 @@
//QGraphicsGridLayout *m_brightnessLayout;
Plasma::Label *m_statusLabel;
//Plasma::Label *m_batteryLabel;
- Plasma::Label *m_brightnessLabel;
+ QList<struct BrightnessSet> *m_brightnessSliders;
Plasma::Label *m_profileLabel;
Plasma::ComboBox *m_profileCombo;
- Plasma::Slider *m_brightnessSlider;
int m_inhibitCookie;
/* Show multiple batteries with individual icons and charge info? */
More information about the kde-doc-english
mailing list