~ubuntu-branches/ubuntu/hardy/kdebase-workspace/hardy-backports

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-01-06 18:18:37 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080106181837-20dc8x9sru3seyup
Tags: 4:4.0.0-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
Battery::Battery(QObject *parent, const QVariantList &args)
43
43
    : Plasma::Applet(parent, args),
44
44
      m_batteryStyle(0),
45
 
      m_smallPixelSize(48),
 
45
      m_smallPixelSize(22),
46
46
      m_theme(0),
47
47
      m_dialog(0),
48
48
      m_isHovered(0),
51
51
    kDebug() << "Loading applet battery";
52
52
    setAcceptsHoverEvents(true);
53
53
    setHasConfigurationInterface(true);
54
 
    setMinimumContentSize(m_smallPixelSize, m_smallPixelSize);
55
 
    setContentSize(m_smallPixelSize, m_smallPixelSize);
 
54
    // TODO: minimum size causes size on panel to be huge (do not use for now)
 
55
    //setMinimumContentSize(m_smallPixelSize, m_smallPixelSize);
 
56
    setContentSize(64, 64);
56
57
}
57
58
 
58
59
void Battery::init()
61
62
    m_showBatteryString = cg.readEntry("showBatteryString", false);
62
63
    m_showMultipleBatteries = cg.readEntry("showMultipleBatteries", true);
63
64
    m_drawBackground = cg.readEntry("drawBackground", true);
64
 
    setDrawStandardBackground(m_drawBackground);
 
65
 
 
66
    // TODO: set background on panel causes 0 height, so do not use it
 
67
    if (formFactor() != Plasma::Vertical && formFactor() != Plasma::Horizontal) {
 
68
        setDrawStandardBackground(m_drawBackground);
 
69
    }
65
70
 
66
71
    QString svgFile = QString();
67
72
    if (cg.readEntry("style", 0) == 0) {
102
107
    if (constraints & Plasma::FormFactorConstraint) {
103
108
        if (formFactor() == Plasma::Vertical) {
104
109
            kDebug() << "Vertical FormFactor";
 
110
            // TODO: set background(true) on panel causes 0 height, so do not use it
 
111
            setDrawStandardBackground(false);
105
112
        } else if (formFactor() == Plasma::Horizontal) {
106
113
            kDebug() << "Horizontal FormFactor";
 
114
            // TODO: set background(true) on panel causes 0 height, so do not use it
 
115
            setDrawStandardBackground(false);
107
116
        } else if (formFactor() == Plasma::Planar) {
108
117
            kDebug() << "Planar FormFactor";
 
118
            setDrawStandardBackground(m_drawBackground);
109
119
        } else if (formFactor() == Plasma::MediaCenter) {
110
120
            kDebug() << "MediaCenter FormFactor";
 
121
            setDrawStandardBackground(m_drawBackground);
111
122
        } else {
112
123
            kDebug() << "Other FormFactor" << formFactor();
 
124
            setDrawStandardBackground(m_drawBackground);
113
125
        }
114
126
    }
115
127
 
117
129
        kDebug() << "SizeChanged: " << contentSize();
118
130
        m_theme->resize(contentSize().toSize());
119
131
    }
120
 
    updateGeometry();
121
132
}
122
133
 
123
134
QSizeF Battery::contentSizeHint() const
151
162
 
152
163
Qt::Orientations Battery::expandingDirections() const
153
164
{
 
165
    // no use of additional space in any direction
154
166
    return 0;
155
167
}
156
168
 
158
170
{
159
171
    if (source.startsWith(I18N_NOOP("Battery"))) {
160
172
        int battery_percent = data[I18N_NOOP("Percent")].toInt();
161
 
        QString battery_percent_label = data[I18N_NOOP("Percent")].toString();
162
 
        battery_percent_label.append("%");
163
 
        m_batteries_data[source] = qMakePair(battery_percent, battery_percent_label);
164
 
        kDebug() << "Applet::Battery::dataUpdated " << m_batteries_data[source].first;
 
173
        QString battery_state = data[I18N_NOOP("State")].toString();
 
174
        m_batteries_data[source] = qMakePair(battery_percent, battery_state);
 
175
        kDebug() << source << "state:" << battery_state << ":" 
 
176
                 << battery_percent << "%";
165
177
    } else if (source == I18N_NOOP("AC Adapter")) {
166
178
        m_acadapter_plugged = data[I18N_NOOP("Plugged in")].toBool();
167
 
        kDebug() << "Applet::AC Adapter dataUpdated: " << m_acadapter_plugged;
 
179
        kDebug() << source << "plugged:" << m_acadapter_plugged;
168
180
    } else {
169
181
        kDebug() << "Applet::Dunno what to do with " << source;
170
182
    }
206
218
    cg.writeEntry("showMultipleBatteries", m_showMultipleBatteries);
207
219
 
208
220
    m_drawBackground = ui.drawBackgroundCheckBox->checkState() == Qt::Checked;
209
 
    setDrawStandardBackground(m_drawBackground);
210
221
    cg.writeEntry("drawBackground", m_drawBackground);
211
222
 
 
223
    // TODO: set background on panel causes 0 height, so do not use it
 
224
    if (formFactor() != Plasma::Vertical && formFactor() != Plasma::Horizontal) {
 
225
        setDrawStandardBackground(m_drawBackground);
 
226
    }
 
227
 
212
228
    if (ui.styleGroup->selected() != m_batteryStyle) {
213
229
        QString svgFile = QString();
214
230
        if (ui.styleGroup->selected() == OxygenBattery) {
428
444
                // Show the charge percentage with a box
429
445
                // on top of the battery, but only for plasmoids bigger than ....
430
446
                if (width >= 44) {
431
 
                    paintLabel(p, corect, it_battery_data->second);
 
447
                    QString batteryLabel = QVariant(it_battery_data->first).toString();
 
448
                    batteryLabel.append("%");
 
449
                    paintLabel(p, corect, batteryLabel);
432
450
                }
433
451
            }
434
452