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