| 
									
										
										
										
											2014-01-14 14:59:24 -02:00
										 |  |  | #include "divepixmapitem.h"
 | 
					
						
							| 
									
										
										
										
											2014-06-08 12:43:04 -03:00
										 |  |  | #include "animationfunctions.h"
 | 
					
						
							| 
									
										
										
										
											2014-06-27 18:00:42 -03:00
										 |  |  | #include <divepicturewidget.h>
 | 
					
						
							| 
									
										
										
										
											2014-07-10 21:15:20 -03:00
										 |  |  | #include <preferences.h>
 | 
					
						
							| 
									
										
										
										
											2014-06-08 13:11:00 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QPen>
 | 
					
						
							|  |  |  | #include <QBrush>
 | 
					
						
							| 
									
										
										
										
											2014-06-08 13:39:32 -03:00
										 |  |  | #include <QGraphicsDropShadowEffect>
 | 
					
						
							| 
									
										
										
										
											2014-06-27 18:00:42 -03:00
										 |  |  | #include <QDesktopServices>
 | 
					
						
							| 
									
										
										
										
											2014-07-29 21:56:45 -03:00
										 |  |  | #include <QGraphicsScene>
 | 
					
						
							|  |  |  | #include <QGraphicsSceneMouseEvent>
 | 
					
						
							|  |  |  | #include <QGraphicsView>
 | 
					
						
							| 
									
										
										
										
											2014-06-27 18:00:42 -03:00
										 |  |  | #include <QUrl>
 | 
					
						
							| 
									
										
										
										
											2014-06-08 13:11:00 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | DivePixmapItem::DivePixmapItem(QObject *parent) : QObject(parent), QGraphicsPixmapItem() | 
					
						
							| 
									
										
										
										
											2014-01-14 14:59:24 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-08 12:43:04 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-29 21:56:45 -03:00
										 |  |  | DiveButtonItem::DiveButtonItem(QObject *parent): DivePixmapItem(parent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DiveButtonItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QGraphicsItem::mousePressEvent(event); | 
					
						
							|  |  |  | 	emit clicked(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // If we have many many pictures on screen, maybe a shared-pixmap would be better to
 | 
					
						
							|  |  |  | // paint on screen, but for now, this.
 | 
					
						
							|  |  |  | CloseButtonItem::CloseButtonItem(QObject *parent): DiveButtonItem(parent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static QPixmap p = QPixmap(":trash"); | 
					
						
							|  |  |  | 	setPixmap(p); | 
					
						
							|  |  |  | 	setFlag(ItemIgnoresTransformations); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CloseButtonItem::hide() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	DiveButtonItem::hide(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CloseButtonItem::show() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	DiveButtonItem::show(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-29 22:13:14 -03:00
										 |  |  | DivePictureItem::DivePictureItem(QObject *parent): DivePixmapItem(parent) | 
					
						
							| 
									
										
										
										
											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
										 |  |  | #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
 | 
					
						
							| 
									
										
										
										
											2014-06-08 12:43:04 -03:00
										 |  |  | 	setAcceptsHoverEvents(true); | 
					
						
							| 
									
										
										
										
											2014-06-08 17:53:28 -07:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 	setAcceptHoverEvents(true); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-06-08 12:43:04 -03:00
										 |  |  | 	setScale(0.2); | 
					
						
							| 
									
										
										
										
											2014-07-10 21:15:20 -03:00
										 |  |  | 	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged())); | 
					
						
							|  |  |  | 	setVisible(prefs.show_pictures_in_profile); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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(); | 
					
						
							|  |  |  | 	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 13:39:32 -03: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 12:43:04 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-29 21:56:45 -03:00
										 |  |  | CloseButtonItem *button = NULL; | 
					
						
							| 
									
										
										
										
											2014-06-08 12:43:04 -03:00
										 |  |  | void DivePictureItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Animations::scaleTo(this, 1.0); | 
					
						
							| 
									
										
										
										
											2014-06-27 18:03:18 -03:00
										 |  |  | 	setZValue(5); | 
					
						
							| 
									
										
										
										
											2014-07-29 21:56:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(!button) { | 
					
						
							|  |  |  | 		button = new CloseButtonItem(); | 
					
						
							|  |  |  | 		button->setScale(0.2); | 
					
						
							|  |  |  | 		button->setZValue(7); | 
					
						
							|  |  |  | 		scene()->addItem(button); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-08-07 16:53:17 -03:00
										 |  |  | 	button->setParentItem(this); | 
					
						
							|  |  |  | 	button->setPos(boundingRect().width() - button->boundingRect().width() * 0.2, | 
					
						
							|  |  |  | 				   boundingRect().height() - button->boundingRect().height() * 0.2); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 	button->disconnect(); | 
					
						
							|  |  |  | 	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) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Animations::scaleTo(this, 0.2); | 
					
						
							| 
									
										
										
										
											2014-06-27 18:03:18 -03:00
										 |  |  | 	setZValue(0); | 
					
						
							| 
									
										
										
										
											2014-08-07 16:53:17 -03:00
										 |  |  | 	if(button){ | 
					
						
							|  |  |  | 		button->setParentItem(NULL); | 
					
						
							|  |  |  | 		Animations::hide(button); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-08 12:43:04 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-27 18:00:42 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-06 18:05:54 -03:00
										 |  |  | DivePictureItem::~DivePictureItem(){ | 
					
						
							| 
									
										
										
										
											2014-08-07 16:53:17 -03:00
										 |  |  | 	if(button){ | 
					
						
							|  |  |  | 		button->setParentItem(NULL); | 
					
						
							| 
									
										
										
										
											2014-08-06 18:05:54 -03:00
										 |  |  | 		Animations::hide(button); | 
					
						
							| 
									
										
										
										
											2014-08-07 16:53:17 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-08-06 18:05:54 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-27 18:00:42 -03:00
										 |  |  | void DivePictureItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-07-29 22:13:14 -03:00
										 |  |  | 	QDesktopServices::openUrl(QUrl::fromLocalFile(fileUrl)); | 
					
						
							| 
									
										
										
										
											2014-06-27 18:00:42 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-07-29 21:56:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void DivePictureItem::removePicture() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-07-29 23:03:32 -03:00
										 |  |  | 	DivePictureModel::instance()->removePicture(fileUrl); | 
					
						
							| 
									
										
										
										
											2014-07-29 21:56:45 -03:00
										 |  |  | } |