remove private class from meter.cpp and support some properties on it.

The properties are useful to be used in animation.

svn path=/trunk/KDE/kdelibs/; revision=1080846
This commit is contained in:
Igor Trindade Oliveira 2010-01-27 02:50:47 +00:00
parent 5eb78f23ea
commit 99cd8006e6
3 changed files with 99 additions and 43 deletions

74
private/meter_p.h Normal file
View File

@ -0,0 +1,74 @@
/*
* Copyright (C) 2007 Petri Damsten <damu@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_METER_PRIVATE_H
#define PLASMA_METER_PRIVATE_H
#include <QObject>
class QRectF;
class QString;
class QPainter;
class QPropertyAnimation;
namespace Plasma {
class Meter;
class FrameSvg;
class MeterPrivate : public QObject
{
Q_OBJECT
Q_PROPERTY(int meterValue READ meterValue WRITE setMeterValue)
public:
MeterPrivate(Meter *m);
void progressChanged(int progress);
void paint(QPainter *p, const QString &elementID);
void text(QPainter *p, int index);
QRectF barRect();
void paintBackground(QPainter *p);
void paintBar(QPainter *p, const QString &prefix);
void paintForeground(QPainter *p);
void setSizePolicyAndPreferredSize();
void setMeterValue(int value);
int meterValue() const;
int minimum;
int maximum;
int value;
int targetValue;
QStringList labels;
QList<Qt::Alignment> alignments;
QList<QColor> colors;
QList<QFont> fonts;
QString svg;
Meter::MeterType meterType;
Plasma::FrameSvg *image;
int minrotate;
int maxrotate;
Meter *meter;
int movementId;
QPropertyAnimation *animation;
};
}
#endif

View File

@ -18,6 +18,7 @@
*/ */
#include "meter.h" #include "meter.h"
#include "private/meter_p.h"
#include <cmath> #include <cmath>
@ -34,11 +35,9 @@
namespace Plasma { namespace Plasma {
class MeterPrivate MeterPrivate::MeterPrivate(Meter *m)
{ : QObject(m),
public: minimum(0),
MeterPrivate(Meter *m)
: minimum(0),
maximum(100), maximum(100),
value(0), value(0),
targetValue(0), targetValue(0),
@ -47,16 +46,16 @@ public:
minrotate(0), minrotate(0),
maxrotate(360), maxrotate(360),
meter(m) meter(m)
{ {
} }
void progressChanged(int progress) void MeterPrivate::progressChanged(int progress)
{ {
value = progress; value = progress;
meter->update(); meter->update();
} }
void paint(QPainter *p, const QString &elementID) void MeterPrivate::paint(QPainter *p, const QString &elementID)
{ {
if (image->hasElement(elementID)) { if (image->hasElement(elementID)) {
QRectF elementRect = image->elementRect(elementID); QRectF elementRect = image->elementRect(elementID);
@ -64,7 +63,7 @@ public:
} }
} }
void text(QPainter *p, int index) void MeterPrivate::text(QPainter *p, int index)
{ {
QString elementID = QString("label%1").arg(index); QString elementID = QString("label%1").arg(index);
QString text = labels[index]; QString text = labels[index];
@ -100,7 +99,7 @@ public:
} }
} }
QRectF barRect() QRectF MeterPrivate::barRect()
{ {
QRectF elementRect; QRectF elementRect;
@ -140,7 +139,7 @@ public:
return elementRect; return elementRect;
} }
void paintBackground(QPainter *p) void MeterPrivate::paintBackground(QPainter *p)
{ {
//be retrocompatible with themes for kde <= 4.1 //be retrocompatible with themes for kde <= 4.1
if (image->hasElement("background-center")) { if (image->hasElement("background-center")) {
@ -163,7 +162,7 @@ public:
} }
} }
void paintBar(QPainter *p, const QString &prefix) void MeterPrivate::paintBar(QPainter *p, const QString &prefix)
{ {
QRectF elementRect = barRect(); QRectF elementRect = barRect();
@ -194,7 +193,7 @@ public:
image->setUsingRenderingCache(true); image->setUsingRenderingCache(true);
} }
void paintForeground(QPainter *p) void MeterPrivate::paintForeground(QPainter *p)
{ {
for (int i = 0; i < labels.count(); ++i) { for (int i = 0; i < labels.count(); ++i) {
text(p, i); text(p, i);
@ -203,7 +202,7 @@ public:
paint(p, "foreground"); paint(p, "foreground");
} }
void setSizePolicyAndPreferredSize() void MeterPrivate::setSizePolicyAndPreferredSize()
{ {
switch (meterType) { switch (meterType) {
case Meter::BarMeterHorizontal: case Meter::BarMeterHorizontal:
@ -247,31 +246,13 @@ public:
} }
} }
int minimum;
int maximum;
int value;
int targetValue;
QStringList labels;
QList<Qt::Alignment> alignments;
QList<QColor> colors;
QList<QFont> fonts;
QString svg;
Meter::MeterType meterType;
Plasma::FrameSvg *image;
int minrotate;
int maxrotate;
Meter *meter;
int movementId;
QPropertyAnimation *animation;
};
Meter::Meter(QGraphicsItem *parent) : Meter::Meter(QGraphicsItem *parent) :
QGraphicsWidget(parent), QGraphicsWidget(parent),
d(new MeterPrivate(this)) d(new MeterPrivate(this))
{ {
d->setSizePolicyAndPreferredSize(); d->setSizePolicyAndPreferredSize();
d->animation = new QPropertyAnimation(this, "meterValue"); d->animation = new QPropertyAnimation(d, "meterValue");
} }
Meter::~Meter() Meter::~Meter()
@ -300,6 +281,11 @@ int Meter::minimum() const
return d->minimum; return d->minimum;
} }
int Meter::value() const
{
return d->value;
}
void Meter::setValue(int value) void Meter::setValue(int value)
{ {
if (value == d->targetValue) { if (value == d->targetValue) {
@ -325,14 +311,14 @@ void Meter::setValue(int value)
} }
} }
int Meter::value() const int MeterPrivate::meterValue() const
{ {
return d->value; return value;
} }
void Meter::setMeterValue(int value) void MeterPrivate::setMeterValue(int value)
{ {
d->progressChanged(value); progressChanged(value);
} }
void Meter::setLabel(int index, const QString &text) void Meter::setLabel(int index, const QString &text)
@ -538,3 +524,4 @@ void Meter::paint(QPainter *p,
} // End of namepace } // End of namepace
#include "meter.moc" #include "meter.moc"
#include "../private/meter_p.moc"

View File

@ -61,8 +61,6 @@ class PLASMA_EXPORT Meter : public QGraphicsWidget
Q_PROPERTY(QString svg READ svg WRITE setSvg) Q_PROPERTY(QString svg READ svg WRITE setSvg)
Q_PROPERTY(MeterType meterType READ meterType WRITE setMeterType) Q_PROPERTY(MeterType meterType READ meterType WRITE setMeterType)
Q_PROPERTY(int meterValue READ value WRITE setMeterValue)
public: public:
/** /**
* Meter types enum * Meter types enum
@ -211,9 +209,6 @@ protected:
const QStyleOptionGraphicsItem *option, const QStyleOptionGraphicsItem *option,
QWidget *widget = 0); QWidget *widget = 0);
private:
void setMeterValue(int value);
private: private:
MeterPrivate *const d; MeterPrivate *const d;
}; };