mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
f54268e527
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>
50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#ifndef DIVEPIXMAPITEM_H
|
|
#define DIVEPIXMAPITEM_H
|
|
|
|
#include <QObject>
|
|
#include <QGraphicsPixmapItem>
|
|
|
|
class DivePixmapItem : public QObject, public QGraphicsPixmapItem {
|
|
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:
|
|
DivePixmapItem(QGraphicsItem *parent = 0);
|
|
};
|
|
|
|
class CloseButtonItem : public DivePixmapItem {
|
|
Q_OBJECT
|
|
public:
|
|
CloseButtonItem(QGraphicsItem *parent = 0);
|
|
protected:
|
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
|
public slots:
|
|
void hide();
|
|
void show();
|
|
};
|
|
|
|
class DivePictureItem : public DivePixmapItem {
|
|
Q_OBJECT
|
|
Q_PROPERTY(qreal scale WRITE setScale READ scale)
|
|
public:
|
|
DivePictureItem(QGraphicsItem *parent = 0);
|
|
void setPixmap(const QPixmap& pix);
|
|
public slots:
|
|
void settingsChanged();
|
|
void removePicture();
|
|
void setFileUrl(const QString& s);
|
|
protected:
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
|
private:
|
|
QString fileUrl;
|
|
QGraphicsRectItem *canvas;
|
|
QGraphicsRectItem *shadow;
|
|
CloseButtonItem *button;
|
|
};
|
|
|
|
#endif // DIVEPIXMAPITEM_H
|