mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-17 21:26:16 +00:00
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>
This commit is contained in:
parent
e811c7306d
commit
630862971f
4 changed files with 37 additions and 53 deletions
|
@ -12,7 +12,7 @@
|
||||||
extern struct ev_select *ev_namelist;
|
extern struct ev_select *ev_namelist;
|
||||||
extern int evn_used;
|
extern int evn_used;
|
||||||
|
|
||||||
DiveEventItem::DiveEventItem(QObject *parent) : DivePixmapItem(parent),
|
DiveEventItem::DiveEventItem(QGraphicsItem *parent) : DivePixmapItem(parent),
|
||||||
vAxis(NULL),
|
vAxis(NULL),
|
||||||
hAxis(NULL),
|
hAxis(NULL),
|
||||||
dataModel(NULL),
|
dataModel(NULL),
|
||||||
|
|
|
@ -11,7 +11,7 @@ struct event;
|
||||||
class DiveEventItem : public DivePixmapItem {
|
class DiveEventItem : public DivePixmapItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DiveEventItem(QObject *parent = 0);
|
DiveEventItem(QGraphicsItem *parent = 0);
|
||||||
virtual ~DiveEventItem();
|
virtual ~DiveEventItem();
|
||||||
void setEvent(struct event *ev, struct gasmix *lastgasmix);
|
void setEvent(struct event *ev, struct gasmix *lastgasmix);
|
||||||
struct event *getEvent();
|
struct event *getEvent();
|
||||||
|
|
|
@ -12,11 +12,11 @@
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#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();
|
emit clicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have many many pictures on screen, maybe a shared-pixmap would be better to
|
CloseButtonItem::CloseButtonItem(QGraphicsItem *parent): DiveButtonItem(parent)
|
||||||
// paint on screen, but for now, this.
|
|
||||||
CloseButtonItem::CloseButtonItem(QObject *parent): DiveButtonItem(parent)
|
|
||||||
{
|
{
|
||||||
static QPixmap p = QPixmap(":list-remove-icon");
|
static QPixmap p = QPixmap(":list-remove-icon");
|
||||||
setPixmap(p);
|
setPixmap(p);
|
||||||
|
@ -45,9 +43,10 @@ void CloseButtonItem::show()
|
||||||
DiveButtonItem::show();
|
DiveButtonItem::show();
|
||||||
}
|
}
|
||||||
|
|
||||||
DivePictureItem::DivePictureItem(QObject *parent): DivePixmapItem(parent),
|
DivePictureItem::DivePictureItem(QGraphicsItem *parent): DivePixmapItem(parent),
|
||||||
canvas(new QGraphicsRectItem(this)),
|
canvas(new QGraphicsRectItem(this)),
|
||||||
shadow(new QGraphicsRectItem(this))
|
shadow(new QGraphicsRectItem(this)),
|
||||||
|
button(new CloseButtonItem(this))
|
||||||
{
|
{
|
||||||
setFlag(ItemIgnoresTransformations);
|
setFlag(ItemIgnoresTransformations);
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
|
@ -67,6 +66,10 @@ DivePictureItem::DivePictureItem(QObject *parent): DivePixmapItem(parent),
|
||||||
shadow->setBrush(QColor(Qt::lightGray));
|
shadow->setBrush(QColor(Qt::lightGray));
|
||||||
shadow->setFlag(ItemStacksBehindParent);
|
shadow->setFlag(ItemStacksBehindParent);
|
||||||
shadow->setZValue(-2);
|
shadow->setZValue(-2);
|
||||||
|
|
||||||
|
button->setScale(0.2);
|
||||||
|
button->setZValue(7);
|
||||||
|
button->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DivePictureItem::settingsChanged()
|
void DivePictureItem::settingsChanged()
|
||||||
|
@ -80,28 +83,19 @@ void DivePictureItem::setPixmap(const QPixmap &pix)
|
||||||
QRectF r = boundingRect();
|
QRectF r = boundingRect();
|
||||||
canvas->setRect(0 - 10, 0 -10, r.width() + 20, r.height() + 20);
|
canvas->setRect(0 - 10, 0 -10, r.width() + 20, r.height() + 20);
|
||||||
shadow->setRect(canvas->rect());
|
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)
|
void DivePictureItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
Animations::scaleTo(this, 1.0);
|
Animations::scaleTo(this, 1.0);
|
||||||
setZValue(5);
|
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->setOpacity(0);
|
||||||
button->show();
|
button->show();
|
||||||
Animations::show(button);
|
Animations::show(button);
|
||||||
button->disconnect();
|
|
||||||
connect(button, SIGNAL(clicked()), this, SLOT(removePicture()));
|
connect(button, SIGNAL(clicked()), this, SLOT(removePicture()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,17 +109,7 @@ void DivePictureItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
Animations::scaleTo(this, 0.2);
|
Animations::scaleTo(this, 0.2);
|
||||||
setZValue(0);
|
setZValue(0);
|
||||||
if(button){
|
|
||||||
button->setParentItem(NULL);
|
|
||||||
Animations::hide(button);
|
Animations::hide(button);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DivePictureItem::~DivePictureItem(){
|
|
||||||
if(button){
|
|
||||||
button->setParentItem(NULL);
|
|
||||||
Animations::hide(button);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DivePictureItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void DivePictureItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
|
|
@ -12,15 +12,33 @@ class DivePixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||||
Q_PROPERTY(qreal x WRITE setX READ x)
|
Q_PROPERTY(qreal x WRITE setX READ x)
|
||||||
Q_PROPERTY(qreal y WRITE setY READ y)
|
Q_PROPERTY(qreal y WRITE setY READ y)
|
||||||
public:
|
public:
|
||||||
DivePixmapItem(QObject *parent = 0);
|
DivePixmapItem(QGraphicsItem *parent = 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
class DiveButtonItem : public DivePixmapItem {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
DiveButtonItem(QGraphicsItem *parent = 0);
|
||||||
|
protected:
|
||||||
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
signals:
|
||||||
|
void clicked();
|
||||||
|
};
|
||||||
|
|
||||||
|
class CloseButtonItem : public DiveButtonItem {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
CloseButtonItem(QGraphicsItem *parent = 0);
|
||||||
|
public slots:
|
||||||
|
void hide();
|
||||||
|
void show();
|
||||||
};
|
};
|
||||||
|
|
||||||
class DivePictureItem : public DivePixmapItem {
|
class DivePictureItem : public DivePixmapItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(qreal scale WRITE setScale READ scale)
|
Q_PROPERTY(qreal scale WRITE setScale READ scale)
|
||||||
public:
|
public:
|
||||||
DivePictureItem(QObject *parent = 0);
|
DivePictureItem(QGraphicsItem *parent = 0);
|
||||||
virtual ~DivePictureItem();
|
|
||||||
void setPixmap(const QPixmap& pix);
|
void setPixmap(const QPixmap& pix);
|
||||||
public slots:
|
public slots:
|
||||||
void settingsChanged();
|
void settingsChanged();
|
||||||
|
@ -36,25 +54,7 @@ private:
|
||||||
QString fileUrl;
|
QString fileUrl;
|
||||||
QGraphicsRectItem *canvas;
|
QGraphicsRectItem *canvas;
|
||||||
QGraphicsRectItem *shadow;
|
QGraphicsRectItem *shadow;
|
||||||
};
|
DiveButtonItem *button;
|
||||||
|
|
||||||
class DiveButtonItem : public DivePixmapItem {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
DiveButtonItem(QObject *parent = 0);
|
|
||||||
protected:
|
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
|
||||||
signals:
|
|
||||||
void clicked();
|
|
||||||
};
|
|
||||||
|
|
||||||
class CloseButtonItem : public DiveButtonItem {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
CloseButtonItem(QObject *parent = 0);
|
|
||||||
public slots:
|
|
||||||
void hide();
|
|
||||||
void show();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DIVEPIXMAPITEM_H
|
#endif // DIVEPIXMAPITEM_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue