summaryrefslogtreecommitdiffstats
path: root/profile-widget/divepixmapitem.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-03-04 01:01:52 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-05-13 13:52:35 -0700
commit630862971fc314439dfa6d274474eb18e8f96711 (patch)
tree67eb3d7cbed81b4152a017a39f81d260f9cb02a9 /profile-widget/divepixmapitem.cpp
parente811c7306d210af17a6571e61f23496ce91fa4bc (diff)
downloadsubsurface-630862971fc314439dfa6d274474eb18e8f96711.tar.gz
Dive pictures: remove close-button optimization
One close-button object was used for all dive pictures. This seems like a brittle premature optimization and the pixmap is shared anyway. Make the button a subobject of the dive picture object. Change the object-hierarchy to be based on QGraphicsItem instead of QObject. The QObject here is only used as a kludge to support signals and properties (the latter are necessary for animations). Remove a comment, which does not seem to be relevant after this change. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget/divepixmapitem.cpp')
-rw-r--r--profile-widget/divepixmapitem.cpp42
1 files changed, 13 insertions, 29 deletions
diff --git a/profile-widget/divepixmapitem.cpp b/profile-widget/divepixmapitem.cpp
index 4456d3e53..08525fe34 100644
--- a/profile-widget/divepixmapitem.cpp
+++ b/profile-widget/divepixmapitem.cpp
@@ -12,11 +12,11 @@
#include <QUrl>
#include <QGraphicsSceneMouseEvent>
-DivePixmapItem::DivePixmapItem(QObject *parent) : QObject(parent), QGraphicsPixmapItem()
+DivePixmapItem::DivePixmapItem(QGraphicsItem *parent) : QGraphicsPixmapItem(parent)
{
}
-DiveButtonItem::DiveButtonItem(QObject *parent): DivePixmapItem(parent)
+DiveButtonItem::DiveButtonItem(QGraphicsItem *parent): DivePixmapItem(parent)
{
}
@@ -26,9 +26,7 @@ void DiveButtonItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
emit clicked();
}
-// If we have many many pictures on screen, maybe a shared-pixmap would be better to
-// paint on screen, but for now, this.
-CloseButtonItem::CloseButtonItem(QObject *parent): DiveButtonItem(parent)
+CloseButtonItem::CloseButtonItem(QGraphicsItem *parent): DiveButtonItem(parent)
{
static QPixmap p = QPixmap(":list-remove-icon");
setPixmap(p);
@@ -45,9 +43,10 @@ void CloseButtonItem::show()
DiveButtonItem::show();
}
-DivePictureItem::DivePictureItem(QObject *parent): DivePixmapItem(parent),
+DivePictureItem::DivePictureItem(QGraphicsItem *parent): DivePixmapItem(parent),
canvas(new QGraphicsRectItem(this)),
- shadow(new QGraphicsRectItem(this))
+ shadow(new QGraphicsRectItem(this)),
+ button(new CloseButtonItem(this))
{
setFlag(ItemIgnoresTransformations);
setAcceptHoverEvents(true);
@@ -67,6 +66,10 @@ DivePictureItem::DivePictureItem(QObject *parent): DivePixmapItem(parent),
shadow->setBrush(QColor(Qt::lightGray));
shadow->setFlag(ItemStacksBehindParent);
shadow->setZValue(-2);
+
+ button->setScale(0.2);
+ button->setZValue(7);
+ button->hide();
}
void DivePictureItem::settingsChanged()
@@ -80,28 +83,19 @@ void DivePictureItem::setPixmap(const QPixmap &pix)
QRectF r = boundingRect();
canvas->setRect(0 - 10, 0 -10, r.width() + 20, r.height() + 20);
shadow->setRect(canvas->rect());
+ button->setPos(boundingRect().width() - button->boundingRect().width() * 0.2,
+ boundingRect().height() - button->boundingRect().height() * 0.2);
}
-CloseButtonItem *button = NULL;
void DivePictureItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
Animations::scaleTo(this, 1.0);
setZValue(5);
- if(!button) {
- button = new CloseButtonItem();
- button->setScale(0.2);
- button->setZValue(7);
- scene()->addItem(button);
- }
- button->setParentItem(this);
- button->setPos(boundingRect().width() - button->boundingRect().width() * 0.2,
- boundingRect().height() - button->boundingRect().height() * 0.2);
button->setOpacity(0);
button->show();
Animations::show(button);
- button->disconnect();
connect(button, SIGNAL(clicked()), this, SLOT(removePicture()));
}
@@ -115,17 +109,7 @@ void DivePictureItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Q_UNUSED(event);
Animations::scaleTo(this, 0.2);
setZValue(0);
- if(button){
- button->setParentItem(NULL);
- Animations::hide(button);
- }
-}
-
-DivePictureItem::~DivePictureItem(){
- if(button){
- button->setParentItem(NULL);
- Animations::hide(button);
- }
+ Animations::hide(button);
}
void DivePictureItem::mousePressEvent(QGraphicsSceneMouseEvent *event)