Changeset View
Changeset View
Standalone View
Standalone View
lib/thumbnailview/thumbnailview.cpp
Show All 30 Lines | |||||
31 | #include <QQueue> | 31 | #include <QQueue> | ||
32 | #include <QScrollBar> | 32 | #include <QScrollBar> | ||
33 | #include <QTimeLine> | 33 | #include <QTimeLine> | ||
34 | #include <QTimer> | 34 | #include <QTimer> | ||
35 | #include <QDrag> | 35 | #include <QDrag> | ||
36 | #include <QMimeData> | 36 | #include <QMimeData> | ||
37 | #include <QDebug> | 37 | #include <QDebug> | ||
38 | #include <QDateTime> | 38 | #include <QDateTime> | ||
39 | #include <QGestureEvent> | ||||
40 | #include <QScroller> | ||||
39 | 41 | | |||
ngraham: Unnecessary whitespace change | |||||
40 | // KDE | 42 | // KDE | ||
41 | #include <KDirModel> | 43 | #include <KDirModel> | ||
42 | #include <KIconLoader> | 44 | #include <KIconLoader> | ||
43 | #include <KPixmapSequence> | 45 | #include <KPixmapSequence> | ||
44 | #include <KUrlMimeData> | 46 | #include <KUrlMimeData> | ||
45 | 47 | | |||
46 | // Local | 48 | // Local | ||
47 | #include "abstractdocumentinfoprovider.h" | 49 | #include "abstractdocumentinfoprovider.h" | ||
48 | #include "abstractthumbnailviewhelper.h" | 50 | #include "abstractthumbnailviewhelper.h" | ||
49 | #include "archiveutils.h" | 51 | #include "archiveutils.h" | ||
50 | #include "dragpixmapgenerator.h" | 52 | #include "dragpixmapgenerator.h" | ||
51 | #include "mimetypeutils.h" | 53 | #include "mimetypeutils.h" | ||
52 | #include "urlutils.h" | 54 | #include "urlutils.h" | ||
53 | #include <lib/gvdebug.h> | 55 | #include <lib/gvdebug.h> | ||
54 | #include <lib/thumbnailprovider/thumbnailprovider.h> | 56 | #include <lib/thumbnailprovider/thumbnailprovider.h> | ||
57 | #include <lib/scrollerutils.h> | ||||
58 | #include <lib/touch/touch.h> | ||||
55 | 59 | | |||
56 | namespace Gwenview | 60 | namespace Gwenview | ||
57 | { | 61 | { | ||
58 | 62 | | |||
59 | #undef ENABLE_LOG | 63 | #undef ENABLE_LOG | ||
60 | #undef LOG | 64 | #undef LOG | ||
61 | //#define ENABLE_LOG | 65 | //#define ENABLE_LOG | ||
62 | #ifdef ENABLE_LOG | 66 | #ifdef ENABLE_LOG | ||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | 172 | { | |||
182 | QPointer<ThumbnailProvider> mThumbnailProvider; | 186 | QPointer<ThumbnailProvider> mThumbnailProvider; | ||
183 | 187 | | |||
184 | PersistentModelIndexSet mBusyIndexSet; | 188 | PersistentModelIndexSet mBusyIndexSet; | ||
185 | KPixmapSequence mBusySequence; | 189 | KPixmapSequence mBusySequence; | ||
186 | QTimeLine* mBusyAnimationTimeLine; | 190 | QTimeLine* mBusyAnimationTimeLine; | ||
187 | 191 | | |||
188 | bool mCreateThumbnailsForRemoteUrls; | 192 | bool mCreateThumbnailsForRemoteUrls; | ||
189 | 193 | | |||
194 | QScroller* mScroller; | ||||
195 | Touch* mTouch; | ||||
196 | | ||||
190 | void setupBusyAnimation() | 197 | void setupBusyAnimation() | ||
191 | { | 198 | { | ||
192 | mBusySequence = KIconLoader::global()->loadPixmapSequence(QStringLiteral("process-working"), 22); | 199 | mBusySequence = KIconLoader::global()->loadPixmapSequence(QStringLiteral("process-working"), 22); | ||
193 | mBusyAnimationTimeLine = new QTimeLine(100 * mBusySequence.frameCount(), q); | 200 | mBusyAnimationTimeLine = new QTimeLine(100 * mBusySequence.frameCount(), q); | ||
194 | mBusyAnimationTimeLine->setCurveShape(QTimeLine::LinearCurve); | 201 | mBusyAnimationTimeLine->setCurveShape(QTimeLine::LinearCurve); | ||
195 | mBusyAnimationTimeLine->setEndFrame(mBusySequence.frameCount() - 1); | 202 | mBusyAnimationTimeLine->setEndFrame(mBusySequence.frameCount() - 1); | ||
196 | mBusyAnimationTimeLine->setLoopCount(0); | 203 | mBusyAnimationTimeLine->setLoopCount(0); | ||
197 | QObject::connect(mBusyAnimationTimeLine, &QTimeLine::frameChanged, q, &ThumbnailView::updateBusyIndexes); | 204 | QObject::connect(mBusyAnimationTimeLine, &QTimeLine::frameChanged, q, &ThumbnailView::updateBusyIndexes); | ||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Line(s) | 289 | { | |||
312 | 319 | | |||
313 | d->mSmoothThumbnailTimer.setSingleShot(true); | 320 | d->mSmoothThumbnailTimer.setSingleShot(true); | ||
314 | connect(&d->mSmoothThumbnailTimer, &QTimer::timeout, this, &ThumbnailView::smoothNextThumbnail); | 321 | connect(&d->mSmoothThumbnailTimer, &QTimer::timeout, this, &ThumbnailView::smoothNextThumbnail); | ||
315 | 322 | | |||
316 | setContextMenuPolicy(Qt::CustomContextMenu); | 323 | setContextMenuPolicy(Qt::CustomContextMenu); | ||
317 | connect(this, &ThumbnailView::customContextMenuRequested, this, &ThumbnailView::showContextMenu); | 324 | connect(this, &ThumbnailView::customContextMenuRequested, this, &ThumbnailView::showContextMenu); | ||
318 | 325 | | |||
319 | connect(this, &ThumbnailView::activated, this, &ThumbnailView::emitIndexActivatedIfNoModifiers); | 326 | connect(this, &ThumbnailView::activated, this, &ThumbnailView::emitIndexActivatedIfNoModifiers); | ||
327 | | ||||
328 | d->mScroller = ScrollerUtils::setQScroller(this->viewport()); | ||||
329 | d->mTouch = new Touch(viewport()); | ||||
330 | connect(d->mTouch, &Touch::twoFingerTapTriggered, this, &ThumbnailView::showContextMenu); | ||||
331 | connect(d->mTouch, &Touch::pinchZoomTriggered, this, &ThumbnailView::zoomGesture); | ||||
332 | connect(d->mTouch, &Touch::pinchGestureStarted, this, &ThumbnailView::setZoomParameter); | ||||
333 | connect(d->mTouch, &Touch::tapTriggered, this, &ThumbnailView::tapGesture); | ||||
334 | connect(d->mTouch, &Touch::tapHoldAndMovingTriggered, this, &ThumbnailView::startDragFromTouch); | ||||
320 | } | 335 | } | ||
321 | 336 | | |||
322 | ThumbnailView::~ThumbnailView() | 337 | ThumbnailView::~ThumbnailView() | ||
323 | { | 338 | { | ||
339 | delete d->mTouch; | ||||
324 | delete d; | 340 | delete d; | ||
325 | } | 341 | } | ||
326 | 342 | | |||
327 | ThumbnailView::ThumbnailScaleMode ThumbnailView::thumbnailScaleMode() const | 343 | ThumbnailView::ThumbnailScaleMode ThumbnailView::thumbnailScaleMode() const | ||
328 | { | 344 | { | ||
329 | return d->mScaleMode; | 345 | return d->mScaleMode; | ||
330 | } | 346 | } | ||
331 | 347 | | |||
▲ Show 20 Lines • Show All 356 Lines • ▼ Show 20 Line(s) | 695 | { | |||
688 | } | 704 | } | ||
689 | 705 | | |||
690 | QDrag* drag = new QDrag(this); | 706 | QDrag* drag = new QDrag(this); | ||
691 | drag->setMimeData(MimeTypeUtils::selectionMimeData(selectedFiles, MimeTypeUtils::DropTarget)); | 707 | drag->setMimeData(MimeTypeUtils::selectionMimeData(selectedFiles, MimeTypeUtils::DropTarget)); | ||
692 | d->initDragPixmap(drag, indexes); | 708 | d->initDragPixmap(drag, indexes); | ||
693 | drag->exec(Qt::MoveAction | Qt::CopyAction | Qt::LinkAction, Qt::CopyAction); | 709 | drag->exec(Qt::MoveAction | Qt::CopyAction | Qt::LinkAction, Qt::CopyAction); | ||
694 | } | 710 | } | ||
695 | 711 | | |||
712 | void ThumbnailView::setZoomParameter() | ||||
This also seems to duplicate code, but again, is there any mechanism in Qt for handling this instead of having to code so much manual handling of the touch events? rkflx: This also seems to duplicate code, but again, is there any mechanism in Qt for handling this… | |||||
713 | { | ||||
714 | const qreal sensitivityModifier = 0.25; | ||||
715 | d->mTouch->setZoomParameter(sensitivityModifier, d->mThumbnailSize.width()); | ||||
716 | } | ||||
717 | | ||||
718 | void ThumbnailView::zoomGesture(qreal newZoom, const QPoint&) | ||||
719 | { | ||||
720 | if (newZoom >= 0.0) { | ||||
721 | int width = qBound (int(MinThumbnailSize), static_cast<int>(newZoom), int(MaxThumbnailSize)); | ||||
722 | setThumbnailWidth(width); | ||||
723 | } | ||||
724 | } | ||||
725 | | ||||
726 | void ThumbnailView::tapGesture(const QPoint& pos) | ||||
727 | { | ||||
728 | const QRect rect = QRect(pos, QSize(1, 1)); | ||||
729 | setSelection(rect, QItemSelectionModel::ClearAndSelect); | ||||
730 | emit activated(indexAt(pos)); | ||||
731 | } | ||||
732 | | ||||
733 | void ThumbnailView::startDragFromTouch(const QPoint& pos) | ||||
734 | { | ||||
735 | QModelIndex index = indexAt(pos); | ||||
736 | if (index.isValid()) { | ||||
737 | setCurrentIndex(index); | ||||
738 | d->mScroller->stop(); | ||||
739 | startDrag(Qt::CopyAction); | ||||
740 | } | ||||
741 | } | ||||
742 | | ||||
696 | void ThumbnailView::dragEnterEvent(QDragEnterEvent* event) | 743 | void ThumbnailView::dragEnterEvent(QDragEnterEvent* event) | ||
697 | { | 744 | { | ||
698 | QAbstractItemView::dragEnterEvent(event); | 745 | QAbstractItemView::dragEnterEvent(event); | ||
699 | if (event->mimeData()->hasUrls()) { | 746 | if (event->mimeData()->hasUrls()) { | ||
700 | event->acceptProposedAction(); | 747 | event->acceptProposedAction(); | ||
701 | } | 748 | } | ||
702 | } | 749 | } | ||
703 | 750 | | |||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Line(s) | |||||
786 | { | 833 | { | ||
787 | QModelIndexList list = selectedIndexes(); | 834 | QModelIndexList list = selectedIndexes(); | ||
788 | if (list.count() >= 1) { | 835 | if (list.count() >= 1) { | ||
789 | scrollTo(list.first(), PositionAtCenter); | 836 | scrollTo(list.first(), PositionAtCenter); | ||
790 | } | 837 | } | ||
791 | } | 838 | } | ||
792 | 839 | | |||
793 | void ThumbnailView::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) | 840 | void ThumbnailView::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) | ||
794 | { | 841 | { | ||
rkflx: So essentially this is a `bool`? Also, what is it needed for? | |||||
I know it is a little bit crude, the aim was, to lower the sensitivity of the zoom. I wanted to use only every second gesture event to zoom the size of the thumbnail. Because the thumbnail size is an integer, I cannot modify the size in 0.5 steps. steffenh: I know it is a little bit crude, the aim was, to lower the sensitivity of the zoom. I wanted to… | |||||
795 | QListView::selectionChanged(selected, deselected); | 842 | QListView::selectionChanged(selected, deselected); | ||
796 | emit selectionChangedSignal(selected, deselected); | 843 | emit selectionChangedSignal(selected, deselected); | ||
rkflx: Use `qBound`. | |||||
797 | } | 844 | } | ||
798 | 845 | | |||
799 | void ThumbnailView::scrollContentsBy(int dx, int dy) | 846 | void ThumbnailView::scrollContentsBy(int dx, int dy) | ||
800 | { | 847 | { | ||
801 | QListView::scrollContentsBy(dx, dy); | 848 | QListView::scrollContentsBy(dx, dy); | ||
802 | d->scheduleThumbnailGeneration(); | 849 | d->scheduleThumbnailGeneration(); | ||
803 | } | 850 | } | ||
804 | 851 | | |||
▲ Show 20 Lines • Show All 180 Lines • Show Last 20 Lines |
Unnecessary whitespace change