2017-04-27 18:26:36 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "profile-widget/divepixmapitem.h"
|
|
|
|
#include "profile-widget/animationfunctions.h"
|
2016-03-06 14:52:55 +00:00
|
|
|
#include "qt-models/divepicturemodel.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "core/pref.h"
|
2015-11-06 18:20:18 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/preferences/preferencesdialog.h"
|
2015-11-06 18:20:18 +00:00
|
|
|
#endif
|
2014-06-08 16:11:00 +00:00
|
|
|
|
2014-06-27 21:00:42 +00:00
|
|
|
#include <QDesktopServices>
|
2014-07-30 00:56:45 +00:00
|
|
|
#include <QGraphicsView>
|
2014-06-27 21:00:42 +00:00
|
|
|
#include <QUrl>
|
2017-11-29 11:40:06 +00:00
|
|
|
#include <QGraphicsSceneMouseEvent>
|
2014-06-08 16:11:00 +00:00
|
|
|
|
2018-03-04 00:01:52 +00:00
|
|
|
DivePixmapItem::DivePixmapItem(QGraphicsItem *parent) : QGraphicsPixmapItem(parent)
|
2014-01-14 16:59:24 +00:00
|
|
|
{
|
2014-01-16 04:50:56 +00:00
|
|
|
}
|
2014-06-08 15:43:04 +00:00
|
|
|
|
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::CloseButtonItem(QGraphicsItem *parent): DivePixmapItem(parent)
|
2014-07-30 00:56:45 +00:00
|
|
|
{
|
2017-11-29 09:57:08 +00:00
|
|
|
static QPixmap p = QPixmap(":list-remove-icon");
|
2014-07-30 00:56:45 +00:00
|
|
|
setPixmap(p);
|
|
|
|
setFlag(ItemIgnoresTransformations);
|
|
|
|
}
|
|
|
|
|
2018-05-21 07:42:39 +00:00
|
|
|
void CloseButtonItem::mousePressEvent(QGraphicsSceneMouseEvent *)
|
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
|
|
|
{
|
|
|
|
qgraphicsitem_cast<DivePictureItem*>(parentItem())->removePicture();
|
|
|
|
}
|
|
|
|
|
2014-07-30 00:56:45 +00:00
|
|
|
void CloseButtonItem::hide()
|
|
|
|
{
|
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
|
|
|
DivePixmapItem::hide();
|
2014-07-30 00:56:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CloseButtonItem::show()
|
|
|
|
{
|
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
|
|
|
DivePixmapItem::show();
|
2014-07-30 00:56:45 +00:00
|
|
|
}
|
|
|
|
|
2018-03-04 00:01:52 +00:00
|
|
|
DivePictureItem::DivePictureItem(QGraphicsItem *parent): DivePixmapItem(parent),
|
2015-01-16 20:12:02 +00:00
|
|
|
canvas(new QGraphicsRectItem(this)),
|
2018-03-04 00:01:52 +00:00
|
|
|
shadow(new QGraphicsRectItem(this)),
|
|
|
|
button(new CloseButtonItem(this))
|
2014-06-08 15:43:04 +00:00
|
|
|
{
|
2014-06-27 21:13:33 +00:00
|
|
|
setFlag(ItemIgnoresTransformations);
|
2014-06-09 00:53:28 +00:00
|
|
|
setAcceptHoverEvents(true);
|
2014-06-08 15:43:04 +00:00
|
|
|
setScale(0.2);
|
2015-11-06 18:20:18 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2014-07-11 00:15:20 +00:00
|
|
|
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
|
2015-11-06 18:20:18 +00:00
|
|
|
#endif
|
2014-07-11 00:15:20 +00:00
|
|
|
setVisible(prefs.show_pictures_in_profile);
|
2015-01-16 20:12:02 +00:00
|
|
|
|
|
|
|
canvas->setPen(Qt::NoPen);
|
|
|
|
canvas->setBrush(QColor(Qt::white));
|
|
|
|
canvas->setFlag(ItemStacksBehindParent);
|
|
|
|
canvas->setZValue(-1);
|
|
|
|
|
|
|
|
shadow->setPos(5,5);
|
|
|
|
shadow->setPen(Qt::NoPen);
|
|
|
|
shadow->setBrush(QColor(Qt::lightGray));
|
|
|
|
shadow->setFlag(ItemStacksBehindParent);
|
|
|
|
shadow->setZValue(-2);
|
2018-03-04 00:01:52 +00:00
|
|
|
|
|
|
|
button->setScale(0.2);
|
|
|
|
button->setZValue(7);
|
|
|
|
button->hide();
|
2014-07-11 00:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePictureItem::settingsChanged()
|
|
|
|
{
|
|
|
|
setVisible(prefs.show_pictures_in_profile);
|
2014-06-08 15:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePictureItem::setPixmap(const QPixmap &pix)
|
|
|
|
{
|
|
|
|
DivePixmapItem::setPixmap(pix);
|
2014-06-08 16:11:00 +00:00
|
|
|
QRectF r = boundingRect();
|
2015-01-16 20:12:02 +00:00
|
|
|
canvas->setRect(0 - 10, 0 -10, r.width() + 20, r.height() + 20);
|
|
|
|
shadow->setRect(canvas->rect());
|
2018-03-04 00:01:52 +00:00
|
|
|
button->setPos(boundingRect().width() - button->boundingRect().width() * 0.2,
|
|
|
|
boundingRect().height() - button->boundingRect().height() * 0.2);
|
2014-06-08 15:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePictureItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2016-03-09 18:15:18 +00:00
|
|
|
Q_UNUSED(event);
|
2014-06-08 15:43:04 +00:00
|
|
|
Animations::scaleTo(this, 1.0);
|
2014-06-27 21:03:18 +00:00
|
|
|
setZValue(5);
|
2014-07-30 00:56:45 +00:00
|
|
|
|
2014-07-30 20:20:38 +00:00
|
|
|
button->setOpacity(0);
|
2014-07-30 00:56:45 +00:00
|
|
|
button->show();
|
2014-07-30 20:20:38 +00:00
|
|
|
Animations::show(button);
|
2014-06-08 15:43:04 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 01:13:14 +00:00
|
|
|
void DivePictureItem::setFileUrl(const QString &s)
|
|
|
|
{
|
|
|
|
fileUrl = s;
|
|
|
|
}
|
|
|
|
|
2014-06-08 15:43:04 +00:00
|
|
|
void DivePictureItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2016-03-09 18:15:18 +00:00
|
|
|
Q_UNUSED(event);
|
2014-06-08 15:43:04 +00:00
|
|
|
Animations::scaleTo(this, 0.2);
|
2014-06-27 21:03:18 +00:00
|
|
|
setZValue(0);
|
2018-03-04 00:01:52 +00:00
|
|
|
Animations::hide(button);
|
2014-08-06 21:05:54 +00:00
|
|
|
}
|
|
|
|
|
2014-06-27 21:00:42 +00:00
|
|
|
void DivePictureItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2017-11-29 11:40:06 +00:00
|
|
|
if (event->button() == Qt::LeftButton) {
|
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(fileUrl));
|
|
|
|
}
|
2014-06-27 21:00:42 +00:00
|
|
|
}
|
2014-07-30 00:56:45 +00:00
|
|
|
|
|
|
|
void DivePictureItem::removePicture()
|
|
|
|
{
|
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
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2018-05-18 19:57:18 +00:00
|
|
|
DivePictureModel::instance()->removePictures({ fileUrl });
|
2018-01-10 12:55:29 +00:00
|
|
|
#endif
|
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
|
|
|
}
|