aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/starwidget.cpp
diff options
context:
space:
mode:
authorGravatar Giuseppe Bilotta <giuseppe.bilotta@gmail.com>2014-10-15 15:30:52 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-10-18 15:16:15 -0700
commit32ab2b34d39752693697f0f2a33032ceb3f5f3b4 (patch)
treec661c4b6609647f364d09eae609ff5b672fc9f20 /qt-ui/starwidget.cpp
parent72b256de629c7e4ef5c52d7a9ce62ebd68a77991 (diff)
downloadsubsurface-32ab2b34d39752693697f0f2a33032ceb3f5f3b4.tar.gz
Unify icon metrics
Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/starwidget.cpp')
-rw-r--r--qt-ui/starwidget.cpp27
1 files changed, 10 insertions, 17 deletions
diff --git a/qt-ui/starwidget.cpp b/qt-ui/starwidget.cpp
index fe4342b7b..a56ba0b28 100644
--- a/qt-ui/starwidget.cpp
+++ b/qt-ui/starwidget.cpp
@@ -12,7 +12,6 @@
QImage StarWidget::activeStar;
QImage StarWidget::inactiveStar;
-StarMetrics StarWidget::imgMetrics = { -1, -1 };
const QImage& StarWidget::starActive()
{
@@ -24,11 +23,6 @@ const QImage& StarWidget::starInactive()
return inactiveStar;
}
-const StarMetrics& StarWidget::metrics()
-{
- return imgMetrics;
-}
-
int StarWidget::currentStars() const
{
return current;
@@ -40,7 +34,7 @@ void StarWidget::mouseReleaseEvent(QMouseEvent *event)
return;
}
- int starClicked = event->pos().x() / imgMetrics.size + 1;
+ int starClicked = event->pos().x() / defaultIconMetrics().sz_small + 1;
if (starClicked > TOTALSTARS)
starClicked = TOTALSTARS;
@@ -59,11 +53,13 @@ void StarWidget::paintEvent(QPaintEvent *event)
QPixmap active = QPixmap::fromImage(starActive());
QPixmap inactive = QPixmap::fromImage(starInactive());
+ const IconMetrics& metrics = defaultIconMetrics();
+
for (int i = 0; i < current; i++)
- p.drawPixmap(i * imgMetrics.size + imgMetrics.spacing, 0, active);
+ p.drawPixmap(i * metrics.sz_small + metrics.spacing, 0, active);
for (int i = current; i < TOTALSTARS; i++)
- p.drawPixmap(i * imgMetrics.size + imgMetrics.spacing, 0, inactive);
+ p.drawPixmap(i * metrics.sz_small + metrics.spacing, 0, inactive);
if (hasFocus()) {
QStyleOptionFocusRect option;
@@ -84,20 +80,16 @@ StarWidget::StarWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f),
current(0),
readOnly(false)
{
- // set image size and spacing from the default icon size
- if (imgMetrics.size == -1) {
- imgMetrics.size = defaultIconSize();
- imgMetrics.spacing = imgMetrics.size/8;
- }
+ int dim = defaultIconMetrics().sz_small;
if (activeStar.isNull()) {
QSvgRenderer render(QString(":star"));
- QPixmap renderedStar(imgMetrics.size, imgMetrics.size);
+ QPixmap renderedStar(dim, dim);
renderedStar.fill(Qt::transparent);
QPainter painter(&renderedStar);
- render.render(&painter, QRectF(0, 0, imgMetrics.size, imgMetrics.size));
+ render.render(&painter, QRectF(0, 0, dim, dim));
activeStar = renderedStar.toImage();
}
if (inactiveStar.isNull()) {
@@ -126,7 +118,8 @@ QImage grayImage(const QImage& coloredImg)
QSize StarWidget::sizeHint() const
{
- return QSize(imgMetrics.size * TOTALSTARS + imgMetrics.spacing * (TOTALSTARS - 1), imgMetrics.size);
+ const IconMetrics& metrics = defaultIconMetrics();
+ return QSize(metrics.sz_small * TOTALSTARS + metrics.spacing * (TOTALSTARS - 1), metrics.sz_small);
}
void StarWidget::setReadOnly(bool r)