| 
									
										
										
										
											2017-04-27 20:26:05 +02:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							| 
									
										
										
										
											2016-04-04 22:02:03 -07:00
										 |  |  | #include "desktop-widgets/divepicturewidget.h"
 | 
					
						
							|  |  |  | #include "qt-models/divepicturemodel.h"
 | 
					
						
							|  |  |  | #include "core/metrics.h"
 | 
					
						
							|  |  |  | #include "core/dive.h"
 | 
					
						
							|  |  |  | #include "core/divelist.h"
 | 
					
						
							| 
									
										
										
										
											2015-03-02 16:18:16 +01:00
										 |  |  | #include <unistd.h>
 | 
					
						
							| 
									
										
										
										
											2014-06-26 14:01:31 -03:00
										 |  |  | #include <QtConcurrentMap>
 | 
					
						
							| 
									
										
										
										
											2015-02-26 14:39:42 +01:00
										 |  |  | #include <QtConcurrentRun>
 | 
					
						
							| 
									
										
										
										
											2015-03-10 10:22:34 -07:00
										 |  |  | #include <QFuture>
 | 
					
						
							| 
									
										
										
										
											2014-06-26 14:01:31 -03:00
										 |  |  | #include <QDir>
 | 
					
						
							| 
									
										
										
										
											2015-02-26 14:39:42 +01:00
										 |  |  | #include <QCryptographicHash>
 | 
					
						
							| 
									
										
										
										
											2015-03-02 16:18:16 +01:00
										 |  |  | #include <QNetworkAccessManager>
 | 
					
						
							|  |  |  | #include <QNetworkReply>
 | 
					
						
							| 
									
										
										
										
											2016-04-04 22:02:03 -07:00
										 |  |  | #include "desktop-widgets/mainwindow.h"
 | 
					
						
							|  |  |  | #include "core/qthelper.h"
 | 
					
						
							| 
									
										
										
										
											2015-03-02 16:18:16 +01:00
										 |  |  | #include <QStandardPaths>
 | 
					
						
							| 
									
										
										
										
											2015-11-03 21:17:50 +01:00
										 |  |  | #include <QtWidgets>
 | 
					
						
							| 
									
										
										
										
											2015-03-02 16:18:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-03 16:48:59 -07:00
										 |  |  | DivePictureWidget::DivePictureWidget(QWidget *parent) : QListView(parent) | 
					
						
							| 
									
										
										
										
											2014-05-30 14:38:27 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-27 16:16:55 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-29 12:40:06 +01:00
										 |  |  | void DivePictureWidget::mouseDoubleClickEvent(QMouseEvent *event) | 
					
						
							| 
									
										
										
										
											2014-06-27 16:16:55 +04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-29 12:40:06 +01:00
										 |  |  | 	if (event->button() == Qt::LeftButton) { | 
					
						
							|  |  |  | 		QString filePath = model()->data(indexAt(event->pos()), Qt::DisplayPropertyRole).toString(); | 
					
						
							|  |  |  | 		emit photoDoubleClicked(localFilePath(filePath)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-30 14:38:27 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-11-03 21:17:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | void DivePictureWidget::mousePressEvent(QMouseEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-29 12:40:06 +01:00
										 |  |  | 	if (event->button() == Qt::LeftButton && event->modifiers() == Qt::NoModifier) { | 
					
						
							| 
									
										
										
										
											2018-07-14 17:40:24 +02:00
										 |  |  | 		QModelIndex index = indexAt(event->pos()); | 
					
						
							|  |  |  | 		QString filename = model()->data(index, Qt::DisplayPropertyRole).toString(); | 
					
						
							|  |  |  | 		int diveId = model()->data(index, Qt::UserRole).toInt(); | 
					
						
							| 
									
										
										
										
											2015-11-03 21:17:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-29 12:40:06 +01:00
										 |  |  | 		if (!filename.isEmpty()) { | 
					
						
							| 
									
										
										
										
											2017-11-29 18:24:13 +01:00
										 |  |  | 			int dim = lrint(defaultIconMetrics().sz_pic * 0.2); | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2017-11-29 12:40:06 +01:00
										 |  |  | 			QPixmap pixmap = model()->data(indexAt(event->pos()), Qt::DecorationRole).value<QPixmap>(); | 
					
						
							| 
									
										
										
										
											2017-11-29 18:24:13 +01:00
										 |  |  | 			pixmap = pixmap.scaled(dim, dim, Qt::KeepAspectRatio); | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2017-11-29 12:40:06 +01:00
										 |  |  | 			QByteArray itemData; | 
					
						
							|  |  |  | 			QDataStream dataStream(&itemData, QIODevice::WriteOnly); | 
					
						
							| 
									
										
										
										
											2018-07-14 17:40:24 +02:00
										 |  |  | 			dataStream << filename << diveId; | 
					
						
							| 
									
										
										
										
											2017-11-29 12:40:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			QMimeData *mimeData = new QMimeData; | 
					
						
							|  |  |  | 			mimeData->setData("application/x-subsurfaceimagedrop", itemData); | 
					
						
							| 
									
										
										
										
											2015-11-03 21:17:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-29 12:40:06 +01:00
										 |  |  | 			QDrag *drag = new QDrag(this); | 
					
						
							|  |  |  | 			drag->setMimeData(mimeData); | 
					
						
							|  |  |  | 			drag->setPixmap(pixmap); | 
					
						
							| 
									
										
										
										
											2015-11-03 21:17:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-29 12:40:06 +01:00
										 |  |  | 			drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-11-29 16:13:57 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-14 17:40:24 +02:00
										 |  |  | 	QListView::mousePressEvent(event); | 
					
						
							| 
									
										
										
										
											2015-11-03 21:17:50 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-12-17 16:17:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | void DivePictureWidget::wheelEvent(QWheelEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (event->modifiers() == Qt::ControlModifier) { | 
					
						
							|  |  |  | 		// Angle delta is given in eighth parts of a degree. A classical mouse
 | 
					
						
							|  |  |  | 		// wheel click is 15 degrees. Each click should correspond to one zoom step.
 | 
					
						
							|  |  |  | 		// Therefore, divide by 15*8=120. To also support touch pads and finer-grained
 | 
					
						
							|  |  |  | 		// mouse wheels, take care to always round away from zero.
 | 
					
						
							|  |  |  | 		int delta = event->angleDelta().y(); | 
					
						
							|  |  |  | 		int carry = delta > 0 ? 119 : -119; | 
					
						
							|  |  |  | 		emit zoomLevelChanged((delta + carry) / 120); | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		QListView::wheelEvent(event); | 
					
						
							|  |  |  | } |