diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2014-10-15 15:30:52 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-10-18 15:16:15 -0700 |
commit | 32ab2b34d39752693697f0f2a33032ceb3f5f3b4 (patch) | |
tree | c661c4b6609647f364d09eae609ff5b672fc9f20 /qt-ui/profile | |
parent | 72b256de629c7e4ef5c52d7a9ce62ebd68a77991 (diff) | |
download | subsurface-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/profile')
-rw-r--r-- | qt-ui/profile/divetooltipitem.cpp | 31 | ||||
-rw-r--r-- | qt-ui/profile/divetooltipitem.h | 9 |
2 files changed, 14 insertions, 26 deletions
diff --git a/qt-ui/profile/divetooltipitem.cpp b/qt-ui/profile/divetooltipitem.cpp index fe69b56dd..ad69560a6 100644 --- a/qt-ui/profile/divetooltipitem.cpp +++ b/qt-ui/profile/divetooltipitem.cpp @@ -19,17 +19,17 @@ #include "display.h" #endif -ToolTipItem::IconMetrics ToolTipItem::iconMetrics = { -1, -1, -1, -1 }; - void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QPixmap *pixmap) { + const IconMetrics& iconMetrics = defaultIconMetrics(); + QGraphicsPixmapItem *iconItem = 0, *pixmapItem = 0; double yValue = title->boundingRect().height() + iconMetrics.spacing; Q_FOREACH (ToolTip t, toolTips) { yValue += t.second->boundingRect().height(); } if (!icon.isNull()) { - iconItem = new QGraphicsPixmapItem(icon.pixmap(iconMetrics.small, iconMetrics.small), this); + iconItem = new QGraphicsPixmapItem(icon.pixmap(iconMetrics.sz_small, iconMetrics.sz_small), this); iconItem->setPos(iconMetrics.spacing, yValue); } else { if (pixmap && !pixmap->isNull()) { @@ -39,7 +39,7 @@ void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QP } QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem(toolTip, this); - textItem->setPos(iconMetrics.spacing + iconMetrics.small + iconMetrics.spacing, yValue); + textItem->setPos(iconMetrics.spacing + iconMetrics.sz_small + iconMetrics.spacing, yValue); textItem->setBrush(QBrush(Qt::white)); textItem->setFlag(ItemIgnoresTransformations); toolTips.push_back(qMakePair(iconItem, textItem)); @@ -89,10 +89,12 @@ void ToolTipItem::setRect(const QRectF &r) void ToolTipItem::collapse() { + int dim = defaultIconMetrics().sz_small; + QPropertyAnimation *animation = new QPropertyAnimation(this, "rect"); animation->setDuration(100); animation->setStartValue(nextRectangle); - animation->setEndValue(QRect(0, 0, iconMetrics.small, iconMetrics.small)); + animation->setEndValue(QRect(0, 0, dim, dim)); animation->start(QAbstractAnimation::DeleteWhenStopped); clear(); @@ -104,6 +106,8 @@ void ToolTipItem::expand() if (!title) return; + const IconMetrics& iconMetrics = defaultIconMetrics(); + double width = 0, height = title->boundingRect().height() + iconMetrics.spacing; Q_FOREACH (ToolTip t, toolTips) { if (t.second->boundingRect().width() > width) @@ -111,13 +115,13 @@ void ToolTipItem::expand() height += t.second->boundingRect().height(); } /* Left padding, Icon Size, space, right padding */ - width += iconMetrics.spacing + iconMetrics.small + iconMetrics.spacing + iconMetrics.spacing; + width += iconMetrics.spacing + iconMetrics.sz_small + iconMetrics.spacing + iconMetrics.spacing; if (width < title->boundingRect().width() + iconMetrics.spacing * 2) width = title->boundingRect().width() + iconMetrics.spacing * 2; - if (height < iconMetrics.small) - height = iconMetrics.small; + if (height < iconMetrics.sz_small) + height = iconMetrics.sz_small; nextRectangle.setWidth(width); nextRectangle.setHeight(height); @@ -139,14 +143,6 @@ ToolTipItem::ToolTipItem(QGraphicsItem *parent) : QGraphicsPathItem(parent), timeAxis(0), lastTime(-1) { - // set icon sizes and spacing from the default icon size - if (iconMetrics.small == -1) { - iconMetrics.small = defaultIconSize(); - iconMetrics.medium = iconMetrics.small + iconMetrics.small/2; - iconMetrics.big = iconMetrics.small*2; - iconMetrics.spacing = iconMetrics.small/4; - } - memset(&pInfo, 0, sizeof(pInfo)); setFlags(ItemIgnoresTransformations | ItemIsMovable | ItemClipsChildrenToShape); @@ -161,10 +157,11 @@ ToolTipItem::~ToolTipItem() void ToolTipItem::updateTitlePosition() { + const IconMetrics& iconMetrics = defaultIconMetrics(); if (rectangle.width() < title->boundingRect().width() + iconMetrics.spacing * 4) { QRectF newRect = rectangle; newRect.setWidth(title->boundingRect().width() + iconMetrics.spacing * 4); - newRect.setHeight((newRect.height() && isExpanded()) ? newRect.height() : iconMetrics.small); + newRect.setHeight((newRect.height() && isExpanded()) ? newRect.height() : iconMetrics.sz_small); setRect(newRect); } diff --git a/qt-ui/profile/divetooltipitem.h b/qt-ui/profile/divetooltipitem.h index bdb7627e7..51e8eccd1 100644 --- a/qt-ui/profile/divetooltipitem.h +++ b/qt-ui/profile/divetooltipitem.h @@ -28,13 +28,6 @@ public: EXPANDED }; - struct IconMetrics { - int small; - int medium; - int big; - int spacing; - }; - explicit ToolTipItem(QGraphicsItem *parent = 0); virtual ~ToolTipItem(); @@ -68,8 +61,6 @@ private: int lastTime; QList<QGraphicsItem*> oldSelection; - - static IconMetrics iconMetrics; }; #endif // DIVETOOLTIPITEM_H |