aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-01-16 16:01:54 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-01-17 08:03:18 +1300
commitdeafa40d34f2a4c86a51aed6eb57c542356387db (patch)
treeac44d9d674b6c3c9fe758002b2a0102755ea13d4
parentd8830ad31c9e84b215df15f30e79dc13ee59c39c (diff)
downloadsubsurface-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>
-rw-r--r--qt-ui/profile/divetooltipitem.cpp25
-rw-r--r--qt-ui/profile/divetooltipitem.h6
2 files changed, 12 insertions, 19 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);
}
diff --git a/qt-ui/profile/divetooltipitem.h b/qt-ui/profile/divetooltipitem.h
index ca5bc8905..7ac9d8652 100644
--- a/qt-ui/profile/divetooltipitem.h
+++ b/qt-ui/profile/divetooltipitem.h
@@ -1,7 +1,7 @@
#ifndef DIVETOOLTIPITEM_H
#define DIVETOOLTIPITEM_H
-#include <QGraphicsPathItem>
+#include <QGraphicsRectItem>
#include <QVector>
#include <QPair>
#include <QRectF>
@@ -17,10 +17,10 @@ struct graphics_context;
/* To use a tooltip, simply ->setToolTip on the QGraphicsItem that you want
* or, if it's a "global" tooltip, set it on the mouseMoveEvent of the ProfileGraphicsView.
*/
-class ToolTipItem : public QObject, public QGraphicsPathItem {
+class ToolTipItem : public QObject, public QGraphicsRectItem {
Q_OBJECT
void updateTitlePosition();
- Q_PROPERTY(QRectF rect READ boundingRect WRITE setRect)
+ Q_PROPERTY(QRectF rect READ rect WRITE setRect)
public:
enum Status {