diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2014-06-19 18:45:26 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-06-20 15:43:10 -0700 |
commit | be462ae1a61312fd6b625e00e35c1622bc006f41 (patch) | |
tree | c8f52191c606084ea516b97fef5a4325e87ab663 /qt-ui/starwidget.cpp | |
parent | f3f03e2ee89a55947a10c2a08ebf6dfa49a393b0 (diff) | |
download | subsurface-be462ae1a61312fd6b625e00e35c1622bc006f41.tar.gz |
Change the Star Widget to use QImage instead of QPixmap
Also, clean a few calls, this should make the widget a tiny
bit faster. This patch also moves the grayImage function from
the star widget to the global scope, so I can use it on the
Calendar widget.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/starwidget.cpp')
-rw-r--r-- | qt-ui/starwidget.cpp | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/qt-ui/starwidget.cpp b/qt-ui/starwidget.cpp index ff185a4a0..c682d95e3 100644 --- a/qt-ui/starwidget.cpp +++ b/qt-ui/starwidget.cpp @@ -7,18 +7,19 @@ #include <unistd.h> #include <QStyle> #include <QStyleOption> +#include "simplewidgets.h" -QPixmap *StarWidget::activeStar = 0; -QPixmap *StarWidget::inactiveStar = 0; +QImage StarWidget::activeStar; +QImage StarWidget::inactiveStar; -QPixmap StarWidget::starActive() +const QImage& StarWidget::starActive() { - return (*activeStar); + return activeStar; } -QPixmap StarWidget::starInactive() +const QImage& StarWidget::starInactive() { - return (*inactiveStar); + return inactiveStar; } int StarWidget::currentStars() const @@ -48,12 +49,14 @@ void StarWidget::mouseReleaseEvent(QMouseEvent *event) void StarWidget::paintEvent(QPaintEvent *event) { QPainter p(this); + QPixmap active = QPixmap::fromImage(starActive()); + QPixmap inactive = QPixmap::fromImage(starInactive()); for (int i = 0; i < current; i++) - p.drawPixmap(i * IMG_SIZE + SPACING, 0, starActive()); + p.drawPixmap(i * IMG_SIZE + SPACING, 0, active); for (int i = current; i < TOTALSTARS; i++) - p.drawPixmap(i * IMG_SIZE + SPACING, 0, starInactive()); + p.drawPixmap(i * IMG_SIZE + SPACING, 0, inactive); if (hasFocus()) { QStyleOptionFocusRect option; @@ -74,8 +77,7 @@ StarWidget::StarWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f), current(0), readOnly(false) { - if (!activeStar) { - activeStar = new QPixmap(); + if (activeStar.isNull()) { QSvgRenderer render(QString(":star")); QPixmap renderedStar(IMG_SIZE, IMG_SIZE); @@ -83,18 +85,17 @@ StarWidget::StarWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f), QPainter painter(&renderedStar); render.render(&painter, QRectF(0, 0, IMG_SIZE, IMG_SIZE)); - (*activeStar) = renderedStar; + activeStar = renderedStar.toImage(); } - if (!inactiveStar) { - inactiveStar = new QPixmap(); - (*inactiveStar) = grayImage(activeStar); + if (inactiveStar.isNull()) { + inactiveStar = grayImage(activeStar); } setFocusPolicy(Qt::StrongFocus); } -QPixmap StarWidget::grayImage(QPixmap *coloredImg) +QImage grayImage(const QImage& coloredImg) { - QImage img = coloredImg->toImage(); + QImage img = coloredImg; for (int i = 0; i < img.width(); ++i) { for (int j = 0; j < img.height(); ++j) { QRgb rgb = img.pixel(i, j); @@ -107,7 +108,7 @@ QPixmap StarWidget::grayImage(QPixmap *coloredImg) } } - return QPixmap::fromImage(img); + return img; } QSize StarWidget::sizeHint() const |