new theming capabilities into the bar meter widget
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=876149
This commit is contained in:
parent
08b16a80dc
commit
9dfd938d17
@ -18,7 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "meter.h"
|
#include "meter.h"
|
||||||
#include "plasma/svg.h"
|
#include "plasma/panelsvg.h"
|
||||||
|
#include <cmath>
|
||||||
#include <kdebug.h>
|
#include <kdebug.h>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
@ -41,7 +42,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (image->hasElement(elementID)) {
|
if (image->hasElement(elementID)) {
|
||||||
QRectF elementRect = image->elementRect(elementID);
|
QRectF elementRect = image->elementRect(elementID);
|
||||||
image->paint(p, elementRect.topLeft(), elementID);
|
image->paint(p, elementRect, elementID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,18 +82,71 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRectF barRect()
|
||||||
|
{
|
||||||
|
if (labels.count() > 0) {
|
||||||
|
return image->elementRect("background");
|
||||||
|
} else {
|
||||||
|
return QRectF(QPoint(0,0), meter->size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void paintBackground(QPainter *p)
|
void paintBackground(QPainter *p)
|
||||||
{
|
{
|
||||||
paint(p, "background");
|
//be retrocompatible with themes for kde <= 4.1
|
||||||
p->save();
|
if (image->hasElement("background-center")) {
|
||||||
|
QRectF elementRect = barRect();
|
||||||
|
QSize imageSize = image->size();
|
||||||
|
image->resize();
|
||||||
|
|
||||||
|
image->setElementPrefix("background");
|
||||||
|
image->resizePanel(elementRect.size());
|
||||||
|
image->paintPanel(p, elementRect.topLeft());
|
||||||
|
image->resize(imageSize);
|
||||||
|
|
||||||
|
paintBar(p, "bar-inactive");
|
||||||
|
} else {
|
||||||
|
paint(p, "background");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void paintBar(QPainter *p, const QString &prefix)
|
||||||
|
{
|
||||||
|
QRectF elementRect = barRect();
|
||||||
|
QSize imageSize = image->size();
|
||||||
|
image->resize();
|
||||||
|
QSize tileSize = image->elementSize("bar-active-center");
|
||||||
|
|
||||||
|
if (elementRect.width() > elementRect.height()) {
|
||||||
|
qreal ratio = tileSize.height() / tileSize.width();
|
||||||
|
int numTiles = elementRect.width()/(elementRect.height()/ratio);
|
||||||
|
tileSize = QSize(elementRect.width()/numTiles, elementRect.height());
|
||||||
|
|
||||||
|
QPoint center = elementRect.center().toPoint();
|
||||||
|
elementRect.setWidth(tileSize.width()*numTiles);
|
||||||
|
elementRect.moveCenter(center);
|
||||||
|
} else {
|
||||||
|
qreal ratio = tileSize.width() / tileSize.height();
|
||||||
|
int numTiles = elementRect.height()/(elementRect.width()/ratio);
|
||||||
|
tileSize = QSize(elementRect.width(), elementRect.height()/numTiles);
|
||||||
|
|
||||||
|
QPoint center = elementRect.center().toPoint();
|
||||||
|
elementRect.setHeight(tileSize.height()*numTiles);
|
||||||
|
elementRect.moveCenter(center);
|
||||||
|
}
|
||||||
|
|
||||||
|
image->setElementPrefix(prefix);
|
||||||
|
image->resizePanel(tileSize);
|
||||||
|
p->drawTiledPixmap(elementRect, image->panelPixmap());
|
||||||
|
image->resize(imageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void paintForeground(QPainter *p)
|
void paintForeground(QPainter *p)
|
||||||
{
|
{
|
||||||
p->restore();
|
|
||||||
for (int i = 0; i < labels.count(); ++i) {
|
for (int i = 0; i < labels.count(); ++i) {
|
||||||
text(p, i);
|
text(p, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
paint(p, "foreground");
|
paint(p, "foreground");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +180,7 @@ public:
|
|||||||
QList<QFont> fonts;
|
QList<QFont> fonts;
|
||||||
QString svg;
|
QString svg;
|
||||||
Meter::MeterType meterType;
|
Meter::MeterType meterType;
|
||||||
Plasma::Svg *image;
|
Plasma::PanelSvg *image;
|
||||||
int minrotate;
|
int minrotate;
|
||||||
int maxrotate;
|
int maxrotate;
|
||||||
Meter *meter;
|
Meter *meter;
|
||||||
@ -246,7 +300,7 @@ void Meter::setSvg(const QString &svg)
|
|||||||
{
|
{
|
||||||
d->svg = svg;
|
d->svg = svg;
|
||||||
delete d->image;
|
delete d->image;
|
||||||
d->image = new Plasma::Svg(this);
|
d->image = new Plasma::PanelSvg(this);
|
||||||
d->image->setImagePath(svg);
|
d->image->setImagePath(svg);
|
||||||
// To create renderer and get default size
|
// To create renderer and get default size
|
||||||
d->image->resize();
|
d->image->resize();
|
||||||
@ -309,7 +363,8 @@ void Meter::paint(QPainter *p,
|
|||||||
case BarMeterVertical:
|
case BarMeterVertical:
|
||||||
d->paintBackground(p);
|
d->paintBackground(p);
|
||||||
|
|
||||||
clipRect = d->image->elementRect("bar");
|
p->save();
|
||||||
|
clipRect = d->barRect();
|
||||||
if (clipRect.width() > clipRect.height()) {
|
if (clipRect.width() > clipRect.height()) {
|
||||||
clipRect.setWidth(clipRect.width() * percentage);
|
clipRect.setWidth(clipRect.width() * percentage);
|
||||||
} else {
|
} else {
|
||||||
@ -318,13 +373,20 @@ void Meter::paint(QPainter *p,
|
|||||||
clipRect.moveBottom(bottom);
|
clipRect.moveBottom(bottom);
|
||||||
}
|
}
|
||||||
p->setClipRect(clipRect);
|
p->setClipRect(clipRect);
|
||||||
d->paint(p, "bar");
|
//be retrocompatible
|
||||||
|
if (d->image->hasElement("bar-active-center")) {
|
||||||
|
d->paintBar(p, "bar-active");
|
||||||
|
} else {
|
||||||
|
d->paint(p, "bar");
|
||||||
|
}
|
||||||
|
p->restore();
|
||||||
|
|
||||||
d->paintForeground(p);
|
d->paintForeground(p);
|
||||||
break;
|
break;
|
||||||
case AnalogMeter:
|
case AnalogMeter:
|
||||||
d->paintBackground(p);
|
d->paintBackground(p);
|
||||||
|
|
||||||
|
p->save();
|
||||||
if (d->image->hasElement("rotatecenter")) {
|
if (d->image->hasElement("rotatecenter")) {
|
||||||
QRectF r = d->image->elementRect("rotatecenter");
|
QRectF r = d->image->elementRect("rotatecenter");
|
||||||
rotateCenter = QPointF(r.left() + r.width() / 2,
|
rotateCenter = QPointF(r.left() + r.width() / 2,
|
||||||
@ -338,6 +400,7 @@ void Meter::paint(QPainter *p,
|
|||||||
p->rotate(angle);
|
p->rotate(angle);
|
||||||
p->translate(-1 * rotateCenter);
|
p->translate(-1 * rotateCenter);
|
||||||
d->paint(p, "pointer");
|
d->paint(p, "pointer");
|
||||||
|
p->restore();
|
||||||
|
|
||||||
d->paintForeground(p);
|
d->paintForeground(p);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user