diff --git a/app/folderviewcontextmanageritem.cpp b/app/folderviewcontextmanageritem.cpp --- a/app/folderviewcontextmanageritem.cpp +++ b/app/folderviewcontextmanageritem.cpp @@ -28,7 +28,7 @@ #include #include #include - +#include // KDE #include @@ -208,6 +208,8 @@ // widget). mView->header()->setStretchLastSection(false); mView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); +//myChange + QScroller::grabGesture(mView->viewport(), QScroller::TouchGesture); setWidget(mView); QObject::connect(mView, &QTreeView::activated, this, &FolderViewContextManagerItem::slotActivated); diff --git a/app/startmainpage.cpp b/app/startmainpage.cpp --- a/app/startmainpage.cpp +++ b/app/startmainpage.cpp @@ -33,7 +33,7 @@ #include #include - +#include // KDE #include #include @@ -167,6 +167,7 @@ d->mBookmarksView->setModel(d->mBookmarksModel); d->mBookmarksView->setAutoResizeItemsEnabled(false); + QScroller::grabGesture(d->mBookmarksView->viewport(), QScroller::TouchGesture); connect(d->mBookmarksView, &KFilePlacesView::urlChanged, this, &StartMainPage::urlSelected); diff --git a/lib/documentview/abstractdocumentviewadapter.h b/lib/documentview/abstractdocumentviewadapter.h --- a/lib/documentview/abstractdocumentviewadapter.h +++ b/lib/documentview/abstractdocumentviewadapter.h @@ -144,7 +144,7 @@ { mWidget = widget; } - + Q_SIGNALS: /** * @addgroup zooming functions diff --git a/lib/documentview/documentview.h b/lib/documentview/documentview.h --- a/lib/documentview/documentview.h +++ b/lib/documentview/documentview.h @@ -33,6 +33,8 @@ class QPropertyAnimation; class QUrl; +class QGestureEvent; + namespace Gwenview { @@ -207,6 +209,8 @@ bool sceneEventFilter(QGraphicsItem*, QEvent*) Q_DECL_OVERRIDE; void dragEnterEvent(QGraphicsSceneDragDropEvent* event) override; void dropEvent(QGraphicsSceneDragDropEvent* event) override; + bool event(QEvent*) Q_DECL_OVERRIDE; + bool gestureEvent( QGestureEvent*); private Q_SLOTS: void finishOpenUrl(); diff --git a/lib/documentview/documentview.cpp b/lib/documentview/documentview.cpp --- a/lib/documentview/documentview.cpp +++ b/lib/documentview/documentview.cpp @@ -41,11 +41,13 @@ #include #include #include - +#include +#include +#include +#include // KDE #include #include - // Local #include #include @@ -67,6 +69,7 @@ #include #include #include +#include namespace Gwenview { @@ -101,7 +104,6 @@ QGraphicsOpacityEffect* mOpacityEffect; LoadingIndicator* mLoadingIndicator; - QScopedPointer mAdapter; QList mZoomSnapValues; Document::Ptr mDocument; @@ -113,7 +115,10 @@ QPointF mDragStartPosition; QPointer mDragThumbnailProvider; QPointer mDrag; - + qint64 timestamp; + qreal rotationsDelta=15; + qreal lastRotation; + void setCurrentAdapter(AbstractDocumentViewAdapter* adapter) { Q_ASSERT(adapter); @@ -433,6 +438,14 @@ d->controlWheelAccumulatedDelta = 0; d->mDragStartPosition = QPointF(0, 0); d->mDrag = nullptr; + grabGesture(Qt::PinchGesture); +/* + grabGesture(Qt::TapAndHoldGesture); + grabGesture(Qt::PanGesture); + grabGesture(Qt::SwipeGesture); + grabGesture(Qt::TapGesture); +*/ + setAcceptTouchEvents (true); // We use an opacity effect instead of using the opacity property directly, because the latter operates at // the painter level, which means if you draw multiple layers in paint(), all layers get the specified @@ -670,6 +683,102 @@ return d->mAdapter->zoom(); } +bool DocumentView::event(QEvent* event) +{ + + if (event->type() == QEvent::TouchBegin) + { + QTouchEvent* touchevent=static_cast(event); + event->accept(); + d->timestamp=QDateTime::currentMSecsSinceEpoch(); + return true; + } + if (event->type() == QEvent::TouchUpdate) + { + QTouchEvent* touchevent=static_cast(event); + } + if (event->type() == QEvent::TouchEnd) + { + QTouchEvent* touchevent=static_cast(event); + QPointF diff= touchevent->touchPoints().at(0).startPos()-touchevent->touchPoints().at(0).pos(); + qint64 now=QDateTime::currentMSecsSinceEpoch(); + qint64 time=now-d->timestamp; + if (touchevent->touchPoints().size()==1 && diff.manhattanLength() > 200 && time<500) + { + //TODO im moment würde eine vertikale swipe gesture in horizontal umgesestz + //sicherstellen das abs wert von x größer oder mehrfaches von y ist, das ist dann besser + if (diff.x() <0 ) //nach recht vorheriges Bild + { + d->mAdapter->previousImageRequested(); + } + if (diff.x() >0 ) //nach links nächstes Bild + { + d->mAdapter->nextImageRequested(); + } + } + + } + + + if ( event->type() == QEvent::Gesture ) { + + return gestureEvent(static_cast( event )); + } + return QGraphicsWidget::event( event ); +} + +bool DocumentView::gestureEvent( QGestureEvent * event ) +{ + QPinchGesture *pinch = static_cast(event->gesture(Qt::PinchGesture)); + + if (pinch) + { + event->accept(); + if (pinch->state()==Qt::GestureStarted) + { + d->lastRotation=0; + } + if (pinch->state()==Qt::GestureUpdated) + { + if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged) + { + if (d->mAdapter->canZoom()) + { + qreal currentZoom = d->mAdapter->zoom(); + qreal zoom=currentZoom*pinch->scaleFactor(); + qreal diff = currentZoom > zoom ? currentZoom - zoom : zoom - currentZoom; + if (diff>0.001) { + d->setZoom(zoom,mapToScene (pinch->lastCenterPoint())); + //TODO center for zoom action not very nice, only works if image greater than window + } + } + } + + if (pinch->changeFlags() & QPinchGesture::RotationAngleChanged) + { + if (pinch->rotationAngle()-d->lastRotation > d->rotationsDelta) + { + TransformImageOperation* op = new TransformImageOperation(ROT_90); + op->applyToDocument(d->mDocument); + d->lastRotation=pinch->rotationAngle(); + } + else if (-(pinch->rotationAngle()-d->lastRotation) > d->rotationsDelta) + { + TransformImageOperation* op = new TransformImageOperation(ROT_270); + op->applyToDocument(d->mDocument); + d->lastRotation=pinch->rotationAngle(); + } + } + } + if (pinch->state()==Qt::GestureFinished) + { + d->lastRotation=0; + } + return true; + } + return false; +} + void DocumentView::resizeEvent(QGraphicsSceneResizeEvent *event) { d->resizeAdapterWidget(); diff --git a/lib/documentview/documentviewcontainer.h b/lib/documentview/documentviewcontainer.h --- a/lib/documentview/documentviewcontainer.h +++ b/lib/documentview/documentviewcontainer.h @@ -31,12 +31,10 @@ // Qt #include #include - namespace Gwenview { class DocumentView; - struct DocumentViewContainerPrivate; /** * A container for DocumentViews which will arrange them to make best use of @@ -88,7 +86,6 @@ protected: void showEvent(QShowEvent*) Q_DECL_OVERRIDE; void resizeEvent(QResizeEvent*) Q_DECL_OVERRIDE; - private: friend class ViewItem; DocumentViewContainerPrivate* const d; diff --git a/lib/documentview/documentviewcontainer.cpp b/lib/documentview/documentviewcontainer.cpp --- a/lib/documentview/documentviewcontainer.cpp +++ b/lib/documentview/documentviewcontainer.cpp @@ -36,6 +36,9 @@ #include #include #include +#include +#include +#include namespace Gwenview { @@ -52,7 +55,6 @@ DocumentViewSet mAddedViews; DocumentViewSet mRemovedViews; QTimer* mLayoutUpdateTimer; - void scheduleLayoutUpdate() { mLayoutUpdateTimer->start(); diff --git a/lib/thumbnailview/thumbnailview.cpp b/lib/thumbnailview/thumbnailview.cpp --- a/lib/thumbnailview/thumbnailview.cpp +++ b/lib/thumbnailview/thumbnailview.cpp @@ -36,7 +36,7 @@ #include #include #include - +#include // KDE #include #include @@ -309,6 +309,8 @@ setVerticalScrollMode(ScrollPerPixel); setHorizontalScrollMode(ScrollPerPixel); + QScroller::grabGesture(this->viewport(), QScroller::TouchGesture); + d->mScheduledThumbnailGenerationTimer.setSingleShot(true); d->mScheduledThumbnailGenerationTimer.setInterval(500); connect(&d->mScheduledThumbnailGenerationTimer, &QTimer::timeout, this, &ThumbnailView::generateThumbnailsForItems);