2014-01-14 16:59:24 +00:00
|
|
|
#include "divepixmapitem.h"
|
2014-06-08 15:43:04 +00:00
|
|
|
#include "animationfunctions.h"
|
2014-06-27 21:00:42 +00:00
|
|
|
#include <divepicturewidget.h>
|
2014-06-08 16:11:00 +00:00
|
|
|
|
|
|
|
#include <QPen>
|
|
|
|
#include <QBrush>
|
2014-06-08 16:39:32 +00:00
|
|
|
#include <QGraphicsDropShadowEffect>
|
2014-06-27 21:00:42 +00:00
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QUrl>
|
2014-06-08 16:11:00 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
DivePixmapItem::DivePixmapItem(QObject *parent) : QObject(parent), QGraphicsPixmapItem()
|
2014-01-14 16:59:24 +00:00
|
|
|
{
|
2014-01-16 04:50:56 +00:00
|
|
|
}
|
2014-06-08 15:43:04 +00:00
|
|
|
|
2014-06-27 21:00:42 +00:00
|
|
|
DivePictureItem::DivePictureItem(int row, QObject *parent): DivePixmapItem(parent)
|
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
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
2014-06-08 15:43:04 +00:00
|
|
|
setAcceptsHoverEvents(true);
|
2014-06-09 00:53:28 +00:00
|
|
|
#else
|
|
|
|
setAcceptHoverEvents(true);
|
|
|
|
#endif
|
2014-06-27 21:00:42 +00:00
|
|
|
rowOnModel = row;
|
2014-06-08 15:43:04 +00:00
|
|
|
setScale(0.2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivePictureItem::setPixmap(const QPixmap &pix)
|
|
|
|
{
|
|
|
|
DivePixmapItem::setPixmap(pix);
|
2014-06-08 16:11:00 +00:00
|
|
|
QRectF r = boundingRect();
|
|
|
|
QGraphicsRectItem *rect = new QGraphicsRectItem(0 - 10, 0 -10, r.width() + 20, r.height() + 20, this);
|
|
|
|
rect->setPen(Qt::NoPen);
|
|
|
|
rect->setBrush(QColor(Qt::white));
|
|
|
|
rect->setFlag(ItemStacksBehindParent);
|
2014-06-08 16:39:32 +00:00
|
|
|
rect->setZValue(-1);
|
|
|
|
|
|
|
|
QGraphicsRectItem *shadow = new QGraphicsRectItem(rect->boundingRect(), this);
|
|
|
|
shadow->setPos(5,5);
|
|
|
|
shadow->setPen(Qt::NoPen);
|
|
|
|
shadow->setBrush(QColor(Qt::lightGray));
|
|
|
|
shadow->setFlag(ItemStacksBehindParent);
|
|
|
|
shadow->setZValue(-2);
|
2014-06-08 15:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePictureItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
Animations::scaleTo(this, 1.0);
|
2014-06-27 21:03:18 +00:00
|
|
|
setZValue(5);
|
2014-06-08 15:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePictureItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
Animations::scaleTo(this, 0.2);
|
2014-06-27 21:03:18 +00:00
|
|
|
setZValue(0);
|
2014-06-08 15:43:04 +00:00
|
|
|
}
|
2014-06-27 21:00:42 +00:00
|
|
|
|
|
|
|
void DivePictureItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
QString filePath = DivePictureModel::instance()->index(rowOnModel,0).data(Qt::ToolTipRole).toString();
|
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
|
|
|
|
}
|