############################################################################## #################################### Events ############################### ##############################################################################
| 355 | // #################################### Events ############################### |
| 356 | // ############################################################################## |
| 357 | void DatapickerImageView::keyPressEvent(QKeyEvent* event) { |
| 358 | if (event->matches(QKeySequence::Paste)) { |
| 359 | const QClipboard* clipboard = QApplication::clipboard(); |
| 360 | const QMimeData* mimeData = clipboard->mimeData(); |
| 361 | if (mimeData->hasImage()) { |
| 362 | m_image->setImage(qvariant_cast<QImage>(mimeData->imageData()), QStringLiteral(""), true); |
| 363 | event->accept(); |
| 364 | } else if (mimeData->hasText()) { |
| 365 | // Check if it is a filepath |
| 366 | QString text = mimeData->text(); |
| 367 | if (text.startsWith(QStringLiteral("file://"))) |
| 368 | text.replace(QStringLiteral("file://"), QStringLiteral("")); |
| 369 | QFileInfo fi(text); |
| 370 | if (fi.exists()) { |
| 371 | m_image->setImage(fi.absoluteFilePath(), true); |
| 372 | event->accept(); |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | QGraphicsView::keyPressEvent(event); |
| 377 | } |
| 378 | |
| 379 | void DatapickerImageView::wheelEvent(QWheelEvent* event) { |
| 380 | // https://wiki.qt.io/Smooth_Zoom_In_QGraphicsView |