~ubuntu-branches/ubuntu/precise/kde-workspace/precise-security

« back to all changes in this revision

Viewing changes to plasma/generic/applets/battery/battery.cpp

Tags: upstream-4.7.2
Import upstream version 4.7.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
#include "battery.h"
23
23
 
24
 
#include "brightnessosdwidget.h"
25
 
 
26
24
#include <QApplication>
27
25
#include <QDBusConnection>
28
26
#include <QDBusInterface>
94
92
      m_labelAnimation(0),
95
93
      m_acAlpha(0),
96
94
      m_acAnimation(0),
97
 
      m_ignoreBrightnessChange(false),
98
 
      m_brightnessOSD(0)
 
95
      m_ignoreBrightnessChange(false)
99
96
{
100
97
    //kDebug() << "Loading applet battery";
101
98
    setAcceptsHoverEvents(true);
127
124
 
128
125
Battery::~Battery()
129
126
{
130
 
    delete m_brightnessOSD;
131
127
}
132
128
 
133
129
void Battery::init()
167
163
        initPopupWidget();
168
164
        // let's show a brightness OSD
169
165
        QDBusConnection::sessionBus().connect("org.kde.Solid.PowerManagement", "/org/kde/Solid/PowerManagement", "org.kde.Solid.PowerManagement",
170
 
                                              "brightnessChanged", this, SLOT(showBrightnessOSD(int)));
 
166
                                              "brightnessChanged", this, SLOT(updateSlider(float)));
171
167
    }
172
168
 
173
169
    if (m_acAdapterPlugged) {
1106
1102
    return m_acAlpha;
1107
1103
}
1108
1104
 
1109
 
void Battery::showBrightnessOSD(int brightness)
1110
 
{
1111
 
    // code adapted from KMix
1112
 
    if (!m_brightnessOSD) {
1113
 
        m_brightnessOSD = new BrightnessOSDWidget();
1114
 
    }
1115
 
 
1116
 
    m_brightnessOSD->setCurrentBrightness(brightness);
1117
 
    m_brightnessOSD->show();
1118
 
    m_brightnessOSD->activateOSD(); //Enable the hide timer
1119
 
 
1120
 
    //Center the OSD
1121
 
    QRect rect = KApplication::kApplication()->desktop()->screenGeometry(QCursor::pos());
1122
 
    QSize size = m_brightnessOSD->sizeHint();
1123
 
    int posX = rect.x() + (rect.width() - size.width()) / 2;
1124
 
    int posY = rect.y() + 4 * rect.height() / 5;
1125
 
    m_brightnessOSD->setGeometry(posX, posY, size.width(), size.height());
1126
 
 
1127
 
    if (m_extenderVisible && m_brightnessSlider) {
1128
 
        updateSlider(brightness);
1129
 
    }
1130
 
}
1131
 
 
1132
1105
#include "battery.moc"