mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
d8830ad31c
commit
deafa40d34
2 changed files with 12 additions and 19 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue