2017-04-27 18:26:36 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-01-14 16:59:24 +00:00
|
|
|
#ifndef DIVEPIXMAPITEM_H
|
|
|
|
#define DIVEPIXMAPITEM_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QGraphicsPixmapItem>
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
class DivePixmapItem : public QObject, public QGraphicsPixmapItem {
|
2014-01-14 16:59:24 +00:00
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(qreal opacity WRITE setOpacity READ opacity)
|
|
|
|
Q_PROPERTY(QPointF pos WRITE setPos READ pos)
|
|
|
|
Q_PROPERTY(qreal x WRITE setX READ x)
|
|
|
|
Q_PROPERTY(qreal y WRITE setY READ y)
|
|
|
|
public:
|
2018-03-04 00:01:52 +00:00
|
|
|
DivePixmapItem(QGraphicsItem *parent = 0);
|
|
|
|
};
|
|
|
|
|
Dive pictures: Fix crash on picture delete
The recent simplification of the close button code introduced a crash:
Deletion of pictures caused an invalid memory access, because the
CloseButtonItem was deleted with the parent DivePicture item.
For some (not fully understood!) reason, a reference to this button
was stored in the depths of Qt.
Empirically, it was found out that removing the first line of the pair
QGraphicsItem::mousePressEvent(event);
emit clicked();
fixed the crash.
It seemed therefore prudent to remove the whole questionable signal/slot
mechanism and directly call the removePicture() function of the parent.
Thus, the intermediate DiveButtonItem class became unnecessary and was
removed, leading to a shallower class hierarchy.
Unfortunately, CloseButtonItem must still be derived from QObject owing
to the Q_PROPERTY machinery, which is in turn needed for animation.
To make this compile on mobile, the conditional compilation of
removePicture() (#ifndef SUBSURFACE_MOBILE) was removed. After all,
if DivePixmapItem is used, there are pictures, so removePicture()
should be functional. Conditional compilation should concern the
whole class, not only this function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-16 20:50:24 +00:00
|
|
|
class CloseButtonItem : public DivePixmapItem {
|
2018-03-04 00:01:52 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
Dive pictures: Fix crash on picture delete
The recent simplification of the close button code introduced a crash:
Deletion of pictures caused an invalid memory access, because the
CloseButtonItem was deleted with the parent DivePicture item.
For some (not fully understood!) reason, a reference to this button
was stored in the depths of Qt.
Empirically, it was found out that removing the first line of the pair
QGraphicsItem::mousePressEvent(event);
emit clicked();
fixed the crash.
It seemed therefore prudent to remove the whole questionable signal/slot
mechanism and directly call the removePicture() function of the parent.
Thus, the intermediate DiveButtonItem class became unnecessary and was
removed, leading to a shallower class hierarchy.
Unfortunately, CloseButtonItem must still be derived from QObject owing
to the Q_PROPERTY machinery, which is in turn needed for animation.
To make this compile on mobile, the conditional compilation of
removePicture() (#ifndef SUBSURFACE_MOBILE) was removed. After all,
if DivePixmapItem is used, there are pictures, so removePicture()
should be functional. Conditional compilation should concern the
whole class, not only this function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-16 20:50:24 +00:00
|
|
|
CloseButtonItem(QGraphicsItem *parent = 0);
|
2018-03-04 00:01:52 +00:00
|
|
|
public slots:
|
|
|
|
void hide();
|
|
|
|
void show();
|
2020-04-13 17:41:30 +00:00
|
|
|
private:
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
2014-01-14 16:59:24 +00:00
|
|
|
};
|
|
|
|
|
2014-06-08 15:43:04 +00:00
|
|
|
class DivePictureItem : public DivePixmapItem {
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(qreal scale WRITE setScale READ scale)
|
|
|
|
public:
|
2018-03-04 00:01:52 +00:00
|
|
|
DivePictureItem(QGraphicsItem *parent = 0);
|
2014-06-08 15:43:04 +00:00
|
|
|
void setPixmap(const QPixmap& pix);
|
2018-07-15 15:56:18 +00:00
|
|
|
void setBaseZValue(double z);
|
2014-07-11 00:15:20 +00:00
|
|
|
public slots:
|
|
|
|
void settingsChanged();
|
2014-07-30 00:56:45 +00:00
|
|
|
void removePicture();
|
2014-07-30 01:13:14 +00:00
|
|
|
void setFileUrl(const QString& s);
|
2020-04-13 17:41:30 +00:00
|
|
|
private:
|
2014-06-08 15:43:04 +00:00
|
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
|
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
2014-06-27 21:00:42 +00:00
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
2014-07-30 01:13:14 +00:00
|
|
|
QString fileUrl;
|
2015-01-16 20:12:02 +00:00
|
|
|
QGraphicsRectItem *canvas;
|
|
|
|
QGraphicsRectItem *shadow;
|
Dive pictures: Fix crash on picture delete
The recent simplification of the close button code introduced a crash:
Deletion of pictures caused an invalid memory access, because the
CloseButtonItem was deleted with the parent DivePicture item.
For some (not fully understood!) reason, a reference to this button
was stored in the depths of Qt.
Empirically, it was found out that removing the first line of the pair
QGraphicsItem::mousePressEvent(event);
emit clicked();
fixed the crash.
It seemed therefore prudent to remove the whole questionable signal/slot
mechanism and directly call the removePicture() function of the parent.
Thus, the intermediate DiveButtonItem class became unnecessary and was
removed, leading to a shallower class hierarchy.
Unfortunately, CloseButtonItem must still be derived from QObject owing
to the Q_PROPERTY machinery, which is in turn needed for animation.
To make this compile on mobile, the conditional compilation of
removePicture() (#ifndef SUBSURFACE_MOBILE) was removed. After all,
if DivePixmapItem is used, there are pictures, so removePicture()
should be functional. Conditional compilation should concern the
whole class, not only this function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-16 20:50:24 +00:00
|
|
|
CloseButtonItem *button;
|
2018-07-15 15:56:18 +00:00
|
|
|
double baseZValue;
|
2014-07-30 00:56:45 +00:00
|
|
|
};
|
|
|
|
|
2014-02-11 18:14:46 +00:00
|
|
|
#endif // DIVEPIXMAPITEM_H
|