Convert Meter and SignalPlotter to QGraphicsWidget based widgets
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=799477
This commit is contained in:
parent
85a1f0e516
commit
77e66bc8fb
@ -59,6 +59,8 @@ set(plasma_LIB_SRCS
|
||||
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
|
||||
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 @@ endif(QT_QTOPENGL_FOUND AND OPENGL_FOUND)
|
||||
|
||||
install(FILES
|
||||
includes/ScriptEngine
|
||||
includes/DataEngineScript
|
||||
includes/RunnerScript
|
||||
includes/DataEngineScript
|
||||
includes/RunnerScript
|
||||
includes/AppletScript
|
||||
DESTINATION ${INCLUDE_INSTALL_DIR}/KDE/Plasma/Scripting)
|
||||
|
||||
|
@ -27,19 +27,19 @@ namespace Plasma {
|
||||
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 @@ public:
|
||||
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 @@ public:
|
||||
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 @@ public:
|
||||
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 @@ void Meter::setSvg(const QString &svg)
|
||||
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 @@ void Meter::setMeterType(MeterType meterType)
|
||||
setSvg("widgets/analog_meter");
|
||||
}
|
||||
}
|
||||
d->setSizePolicyAndPreferredSize();
|
||||
}
|
||||
|
||||
Meter::MeterType Meter::meterType() const
|
||||
@ -256,14 +279,9 @@ Meter::MeterType Meter::meterType() const
|
||||
return d->meterType;
|
||||
}
|
||||
|
||||
QSizeF Meter::sizeHint() const
|
||||
{
|
||||
return d->sizeHint;
|
||||
}
|
||||
|
||||
void Meter::paintWidget(QPainter *p,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget)
|
||||
void Meter::paint(QPainter *p,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
@ -303,7 +321,7 @@ void Meter::paintWidget(QPainter *p,
|
||||
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);
|
||||
|
@ -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 @@ namespace Plasma
|
||||
* @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 @@ public:
|
||||
* @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
|
||||
@ -131,11 +131,6 @@ public:
|
||||
*/
|
||||
MeterType meterType() const;
|
||||
|
||||
/**
|
||||
* Reimplemented from Plasma::Widget
|
||||
*/
|
||||
virtual QSizeF sizeHint() const;
|
||||
|
||||
/**
|
||||
* Set text label for the meter
|
||||
* @param index label index.
|
||||
@ -198,9 +193,9 @@ protected:
|
||||
/**
|
||||
* 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;
|
||||
|
@ -95,8 +95,8 @@ class SignalPlotter::Private
|
||||
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 @@ SignalPlotter::SignalPlotter(Widget *parent)
|
||||
|
||||
d->svgBackground = 0;
|
||||
d->backgroundColor = QColor(0,0,0);
|
||||
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
}
|
||||
|
||||
SignalPlotter::~SignalPlotter()
|
||||
@ -137,11 +139,6 @@ SignalPlotter::~SignalPlotter()
|
||||
delete d;
|
||||
}
|
||||
|
||||
Qt::Orientations SignalPlotter::expandingDirections() const
|
||||
{
|
||||
return Qt::Horizontal | Qt::Vertical;
|
||||
}
|
||||
|
||||
QString SignalPlotter::unit() const
|
||||
{
|
||||
return d->unit;
|
||||
@ -519,11 +516,11 @@ QPixmap SignalPlotter::getSnapshotImage(uint w, uint height)
|
||||
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);
|
||||
|
@ -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 @@ struct PlotColor
|
||||
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 @@ class PLASMA_EXPORT SignalPlotter : public Widget
|
||||
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 @@ protected:
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user