diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2015-01-16 16:01:54 -0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-01-17 08:03:18 +1300 |
commit | deafa40d34f2a4c86a51aed6eb57c542356387db (patch) | |
tree | ac44d9d674b6c3c9fe758002b2a0102755ea13d4 /qt-ui/profile/divetooltipitem.cpp | |
parent | d8830ad31c9e84b215df15f30e79dc13ee59c39c (diff) | |
download | subsurface-deafa40d34f2a4c86a51aed6eb57c542356387db.tar.gz |
Inherit from QGraphicsRectItem instead of QGraphicsShapeItem
a rectangle is *much* faster to paint than a simple ShapeItem,
so this is a safer choice. We still need to create the paint
method so we can use the correct roundness for the rectangle.
Currently it's white with a 1px solid line - terrible. :)
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/profile/divetooltipitem.cpp')
-rw-r--r-- | qt-ui/profile/divetooltipitem.cpp | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/qt-ui/profile/divetooltipitem.cpp b/qt-ui/profile/divetooltipitem.cpp index 790c222fd..c351a30f0 100644 --- a/qt-ui/profile/divetooltipitem.cpp +++ b/qt-ui/profile/divetooltipitem.cpp @@ -57,20 +57,13 @@ void ToolTipItem::clear() void ToolTipItem::setRect(const QRectF &r) { - if( r == rectangle ) { + if( r == rect() ) { return; } - rectangle = r; - - // Creates a 2pixels border - QPainterPath border; - border.addRoundedRect(-4, -4, rectangle.width() + 8, rectangle.height() + 10, 3, 3); - border.addRoundedRect(-1, -1, rectangle.width() + 3, rectangle.height() + 4, 3, 3); - setPath(border); - + QGraphicsRectItem::setRect(r); QPainterPath bg; - bg.addRoundedRect(-1, -1, rectangle.width() + 3, rectangle.height() + 4, 3, 3); + bg.addRoundedRect(-1, -1, rect().width() + 3, rect().height() + 4, 3, 3); background->setPath(bg); updateTitlePosition(); @@ -122,10 +115,10 @@ void ToolTipItem::expand() nextRectangle.setWidth(width); nextRectangle.setHeight(height); - if (nextRectangle != rectangle) { + if (nextRectangle != rect()) { QPropertyAnimation *animation = new QPropertyAnimation(this, "rect", this); animation->setDuration(100); - animation->setStartValue(rectangle); + animation->setStartValue(rect()); animation->setEndValue(nextRectangle); animation->start(QAbstractAnimation::DeleteWhenStopped); } @@ -133,7 +126,7 @@ void ToolTipItem::expand() status = EXPANDED; } -ToolTipItem::ToolTipItem(QGraphicsItem *parent) : QGraphicsPathItem(parent), +ToolTipItem::ToolTipItem(QGraphicsItem *parent) : QGraphicsRectItem(parent), background(0), separator(new QGraphicsLineItem(this)), title(new QGraphicsSimpleTextItem(tr("Information"), this)), @@ -181,8 +174,8 @@ ToolTipItem::~ToolTipItem() void ToolTipItem::updateTitlePosition() { const IconMetrics& iconMetrics = defaultIconMetrics(); - if (rectangle.width() < title->boundingRect().width() + iconMetrics.spacing * 4) { - QRectF newRect = rectangle; + if (rect().width() < title->boundingRect().width() + iconMetrics.spacing * 4) { + QRectF newRect = rect(); newRect.setWidth(title->boundingRect().width() + iconMetrics.spacing * 4); newRect.setHeight((newRect.height() && isExpanded()) ? newRect.height() : iconMetrics.sz_small); setRect(newRect); @@ -206,7 +199,7 @@ bool ToolTipItem::isExpanded() const void ToolTipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { persistPos(); - QGraphicsPathItem::mouseReleaseEvent(event); + QGraphicsRectItem::mouseReleaseEvent(event); Q_FOREACH (QGraphicsItem *item, oldSelection) { item->setSelected(true); } |