[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/workspace/libs/plasma
From: Petri Damstén <petri.damsten () kdemail ! net>
Date: 2008-04-21 16:26:19
Message-ID: 1208795179.317323.11623.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 799477 by pdamsten:
Convert Meter and SignalPlotter to QGraphicsWidget based widgets
M +6 -2 CMakeLists.txt
M +38 -20 widgets/meter.cpp
M +6 -11 widgets/meter.h
M +6 -9 widgets/signalplotter.cpp
M +5 -6 widgets/signalplotter.h
--- trunk/KDE/kdebase/workspace/libs/plasma/CMakeLists.txt #799476:799477
@@ -59,6 +59,8 @@
scripting/scriptengine.cpp
widgets/icon.cpp
widgets/webcontent.cpp
+ widgets/meter.cpp
+ widgets/signalplotter.cpp
)
kde4_add_ui_files (
@@ -133,6 +135,8 @@
install(FILES
widgets/icon.h
widgets/webcontent.h
+ widgets/meter.h
+ widgets/signalplotter.h
DESTINATION ${INCLUDE_INSTALL_DIR}/plasma/widgets)
#For future
@@ -183,8 +187,8 @@
install(FILES
includes/ScriptEngine
- includes/DataEngineScript
- includes/RunnerScript
+ includes/DataEngineScript
+ includes/RunnerScript
includes/AppletScript
DESTINATION ${INCLUDE_INSTALL_DIR}/KDE/Plasma/Scripting)
--- trunk/KDE/kdebase/workspace/libs/plasma/widgets/meter.cpp #799476:799477
@@ -27,19 +27,19 @@
class Meter::Private
{
public:
- Private() :
+ Private(Meter* m) :
minimum(0),
maximum(100),
value(0),
meterType(AnalogMeter),
image(0),
- sizeHint(QSizeF(0.0, 0.0)),
minrotate(0),
- maxrotate(360) {};
+ maxrotate(360),
+ meter(m) {};
void paint(QPainter *p, const QString& elementID)
{
- if (image->elementExists(elementID)) {
+ if (image->hasElement(elementID)) {
QRectF elementRect = image->elementRect(elementID);
image->paint(p, elementRect.topLeft(), elementID);
}
@@ -50,7 +50,7 @@
QString elementID = QString("label%1").arg(index);
QString text = labels[index];
- if (image->elementExists(elementID)) {
+ if (image->hasElement(elementID)) {
QRectF elementRect = image->elementRect(elementID);
Qt::Alignment align = Qt::AlignCenter;
@@ -96,6 +96,27 @@
paint(p, "foreground");
}
+ void setSizePolicyAndPreferredSize()
+ {
+ switch (meterType) {
+ case BarMeterHorizontal:
+ meter->setSizePolicy(QSizePolicy::Expanding, \
QSizePolicy::Preferred); + break;
+ case BarMeterVertical:
+ meter->setSizePolicy(QSizePolicy::Preferred, \
QSizePolicy::Expanding); + break;
+ case AnalogMeter:
+ default:
+ meter->setSizePolicy(QSizePolicy::Preferred, \
QSizePolicy::Preferred); + break;
+ }
+ if (image) {
+ meter->setPreferredSize(image->size());
+ } else {
+ meter->setPreferredSize(QSizeF(30, 30));
+ }
+ }
+
int minimum;
int maximum;
int value;
@@ -106,15 +127,16 @@
QString svg;
MeterType meterType;
Plasma::Svg *image;
- QSizeF sizeHint;
int minrotate;
int maxrotate;
+ Meter* meter;
};
-Meter::Meter(QGraphicsItem *parent, QObject *parentObject) :
- Plasma::Widget(parent, parentObject),
- d(new Private)
+Meter::Meter(QGraphicsItem *parent) :
+ QGraphicsWidget(parent),
+ d(new Private(this))
{
+ d->setSizePolicyAndPreferredSize();
}
Meter::~Meter()
@@ -224,8 +246,8 @@
d->image = new Plasma::Svg(svg, this);
// To create renderer and get default size
d->image->resize();
- d->sizeHint = d->image->size();
- if (d->image->elementExists("rotateminmax")) {
+ d->setSizePolicyAndPreferredSize();
+ if (d->image->hasElement("rotateminmax")) {
QRectF r = d->image->elementRect("rotateminmax");
d->minrotate = (int)r.height();
d->maxrotate = (int)r.width();
@@ -249,6 +271,7 @@
setSvg("widgets/analog_meter");
}
}
+ d->setSizePolicyAndPreferredSize();
}
Meter::MeterType Meter::meterType() const
@@ -256,15 +279,10 @@
return d->meterType;
}
-QSizeF Meter::sizeHint() const
+void Meter::paint(QPainter *p,
+ const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
{
- return d->sizeHint;
-}
-
-void Meter::paintWidget(QPainter *p,
- const QStyleOptionGraphicsItem *option,
- QWidget *widget)
-{
Q_UNUSED(option)
Q_UNUSED(widget)
QRectF rect(QPointF(0, 0), size());
@@ -303,7 +321,7 @@
case AnalogMeter:
d->paintBackground(p);
- if (d->image->elementExists("rotatecenter")) {
+ if (d->image->hasElement("rotatecenter")) {
QRectF r = d->image->elementRect("rotatecenter");
rotateCenter = QPointF(r.left() + r.width() / 2,
r.top() + r.height() / 2);
--- trunk/KDE/kdebase/workspace/libs/plasma/widgets/meter.h #799476:799477
@@ -22,7 +22,7 @@
#include <plasma/plasma_export.h>
#include <plasma/dataengine.h>
-#include <plasma/widgets/widget.h>
+#include <QGraphicsWidget>
namespace Plasma
{
@@ -45,7 +45,7 @@
* @author Petri Damstén
*/
-class PLASMA_EXPORT Meter : public Plasma::Widget
+class PLASMA_EXPORT Meter : public QGraphicsWidget
{
Q_OBJECT
Q_ENUMS(MeterType)
@@ -73,7 +73,7 @@
* @param parent the QGraphicsItem this meter is parented to.
* @param parent the QObject this meter is parented to.
*/
- explicit Meter(QGraphicsItem *parent = 0, QObject *parentObject = 0);
+ explicit Meter(QGraphicsItem *parent = 0);
/**
* Destructor
@@ -132,11 +132,6 @@
MeterType meterType() const;
/**
- * Reimplemented from Plasma::Widget
- */
- virtual QSizeF sizeHint() const;
-
- /**
* Set text label for the meter
* @param index label index.
* @param text text for the label.
@@ -198,9 +193,9 @@
/**
* Reimplemented from Plasma::Widget
*/
- virtual void paintWidget(QPainter *p,
- const QStyleOptionGraphicsItem *option,
- QWidget *widget = 0);
+ virtual void paint(QPainter *p,
+ const QStyleOptionGraphicsItem *option,
+ QWidget *widget = 0);
private:
class Private;
--- trunk/KDE/kdebase/workspace/libs/plasma/widgets/signalplotter.cpp #799476:799477
@@ -95,8 +95,8 @@
QList<QList<double> > plotData;
};
-SignalPlotter::SignalPlotter(Widget *parent)
- : Widget(parent),
+SignalPlotter::SignalPlotter(QGraphicsItem *parent)
+ : QGraphicsWidget(parent),
d(new Private)
{
d->precision = 0;
@@ -130,6 +130,8 @@
d->svgBackground = 0;
d->backgroundColor = QColor(0,0,0);
+
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}
SignalPlotter::~SignalPlotter()
@@ -137,11 +139,6 @@
delete d;
}
-Qt::Orientations SignalPlotter::expandingDirections() const
-{
- return Qt::Horizontal | Qt::Vertical;
-}
-
QString SignalPlotter::unit() const
{
return d->unit;
@@ -519,11 +516,11 @@
void SignalPlotter::setGeometry(const QRectF &geometry)
{
// First update our size, then update the data buffers accordingly.
- Widget::setGeometry(geometry);
+ QGraphicsWidget::setGeometry(geometry);
updateDataBuffers();
}
-void SignalPlotter::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem \
*option, QWidget *widget) +void SignalPlotter::paint(QPainter *painter, const \
QStyleOptionGraphicsItem *option, QWidget *widget) {
Q_UNUSED(option);
Q_UNUSED(widget);
--- trunk/KDE/kdebase/workspace/libs/plasma/widgets/signalplotter.h #799476:799477
@@ -22,8 +22,9 @@
#ifndef SIGNALPLOTTER_H
#define SIGNALPLOTTER_H
-#include <plasma/widgets/widget.h>
#include <QtGui/QFont>
+#include <QGraphicsWidget>
+#include <plasma/plasma_export.h>
namespace Plasma
{
@@ -34,7 +35,7 @@
QColor darkColor;
};
-class PLASMA_EXPORT SignalPlotter : public Widget
+class PLASMA_EXPORT SignalPlotter : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY( QString title READ title WRITE setTitle )
@@ -59,11 +60,9 @@
Q_PROPERTY( bool stackPlots READ stackPlots WRITE setStackPlots )
public:
- SignalPlotter(Widget *parent = 0);
+ SignalPlotter(QGraphicsItem *parent = 0);
~SignalPlotter();
- Qt::Orientations expandingDirections() const;
-
/**
* Add a new line to the graph plotter, with the specified color.
* Note that the order you add the plots must be the same order that
@@ -420,7 +419,7 @@
void updateDataBuffers();
void calculateNiceRange();
- void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, \
QWidget *widget); + void paint(QPainter *painter, const QStyleOptionGraphicsItem \
*option, QWidget *widget);
void drawWidget(QPainter *p, uint w, uint height, int horizontalScale);
void drawBackground(QPainter *p, int w, int h);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic