From ca1b10dc28b799edba39547b5cc6f98e3158f8a7 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Thu, 3 Oct 2019 17:57:14 +0800 Subject: [PATCH] navigator view wip --- PineapplePictures.pro | 6 +++-- graphicsview.cpp | 3 +++ graphicsview.h | 4 +++ mainwindow.cpp | 60 +++++++++++++++++++++++++++++++++---------- mainwindow.h | 9 +++++-- navigatorview.cpp | 18 +++++++++++++ navigatorview.h | 16 ++++++++++++ 7 files changed, 98 insertions(+), 18 deletions(-) create mode 100644 navigatorview.cpp create mode 100644 navigatorview.h diff --git a/PineapplePictures.pro b/PineapplePictures.pro index 276d803..63e4040 100644 --- a/PineapplePictures.pro +++ b/PineapplePictures.pro @@ -29,13 +29,15 @@ SOURCES += \ mainwindow.cpp \ graphicsview.cpp \ bottombuttongroup.cpp \ - graphicsscene.cpp + graphicsscene.cpp \ + navigatorview.cpp HEADERS += \ mainwindow.h \ graphicsview.h \ bottombuttongroup.h \ - graphicsscene.h + graphicsscene.h \ + navigatorview.h FORMS += diff --git a/graphicsview.cpp b/graphicsview.cpp index 1626fe7..8bc6594 100644 --- a/graphicsview.cpp +++ b/graphicsview.cpp @@ -23,6 +23,7 @@ GraphicsView::GraphicsView(QWidget *parent) void GraphicsView::showFromUrlList(const QList &urlList) { + emit navigatorViewRequired(false, 0); if (urlList.isEmpty()) { // yeah, it's possible. dragging QQ's original sticker will trigger this, for example. showText("File url list is empty"); @@ -105,12 +106,14 @@ void GraphicsView::zoomView(qreal scaleFactor) { m_scaleFactor *= scaleFactor; reapplyViewTransform(); + emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), m_rotateAngle); } void GraphicsView::resetScale() { m_scaleFactor = 1; reapplyViewTransform(); + emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), m_rotateAngle); } void GraphicsView::rotateView(qreal rotateAngel) diff --git a/graphicsview.h b/graphicsview.h index bee2bed..4fa73ef 100644 --- a/graphicsview.h +++ b/graphicsview.h @@ -7,6 +7,7 @@ class GraphicsScene; class GraphicsView : public QGraphicsView { + Q_OBJECT public: GraphicsView(QWidget *parent = nullptr); @@ -30,6 +31,9 @@ public: void checkAndDoFitInView(); +signals: + void navigatorViewRequired(bool required, qreal angle); + public slots: void toggleCheckerboard(); diff --git a/mainwindow.cpp b/mainwindow.cpp index 281a4c0..3cc8db3 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2,6 +2,7 @@ #include "bottombuttongroup.h" #include "graphicsview.h" +#include "navigatorview.h" #include "graphicsscene.h" #include @@ -44,6 +45,19 @@ MainWindow::MainWindow(QWidget *parent) : m_graphicsView->setScene(scene); this->setCentralWidget(m_graphicsView); + m_gv = new NavigatorView(this); + m_gv->setFixedSize(250, 160); + m_gv->setScene(scene); + m_gv->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio); + + connect(m_graphicsView, &GraphicsView::navigatorViewRequired, + this, [ = ](bool required, qreal angle){ + m_gv->resetTransform(); + m_gv->rotate(angle); + m_gv->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio); + m_gv->setVisible(required); + }); + m_closeButton = new QPushButton(m_graphicsView); m_closeButton->setFlat(true); m_closeButton->setFixedSize(50, 50); @@ -72,14 +86,20 @@ MainWindow::MainWindow(QWidget *parent) : m_graphicsView->resetScale(); m_graphicsView->rotateView(90); m_graphicsView->checkAndDoFitInView(); + m_gv->setVisible(false); }); - m_opacityEffect = new QGraphicsOpacityEffect(m_bottomButtonGroup); - m_bottomButtonGroup->setGraphicsEffect(m_opacityEffect); - m_btnGrpAnimation = new QPropertyAnimation(m_opacityEffect, "opacity"); - m_btnGrpAnimation->setDuration(300); + m_btnGrpEffect = new QGraphicsOpacityEffect(this); + m_bribViewEffect = new QGraphicsOpacityEffect(this); + m_bottomButtonGroup->setGraphicsEffect(m_btnGrpEffect); + m_gv->setGraphicsEffect(m_bribViewEffect); + m_btnGrpOpacityAnimation = new QPropertyAnimation(m_btnGrpEffect, "opacity"); + m_btnGrpOpacityAnimation->setDuration(300); + m_bribViewOpacityAnimation = new QPropertyAnimation(m_bribViewEffect, "opacity"); + m_bribViewOpacityAnimation->setDuration(300); - m_opacityEffect->setOpacity(0); + m_btnGrpEffect->setOpacity(0); + m_bribViewEffect->setOpacity(0); centerWindow(); } @@ -92,6 +112,7 @@ MainWindow::~MainWindow() void MainWindow::showUrls(const QList &urls) { m_graphicsView->showFromUrlList(urls); + m_gv->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio); } void MainWindow::adjustWindowSizeBySceneRect() @@ -125,20 +146,30 @@ void MainWindow::showEvent(QShowEvent *event) void MainWindow::enterEvent(QEvent *event) { - m_btnGrpAnimation->stop(); - m_btnGrpAnimation->setStartValue(m_opacityEffect->opacity()); - m_btnGrpAnimation->setEndValue(1); - m_btnGrpAnimation->start(); + m_btnGrpOpacityAnimation->stop(); + m_btnGrpOpacityAnimation->setStartValue(m_btnGrpEffect->opacity()); + m_btnGrpOpacityAnimation->setEndValue(1); + m_btnGrpOpacityAnimation->start(); + + m_bribViewOpacityAnimation->stop(); + m_bribViewOpacityAnimation->setStartValue(m_bribViewEffect->opacity()); + m_bribViewOpacityAnimation->setEndValue(1); + m_bribViewOpacityAnimation->start(); return QMainWindow::enterEvent(event); } void MainWindow::leaveEvent(QEvent *event) { - m_btnGrpAnimation->stop(); - m_btnGrpAnimation->setStartValue(m_opacityEffect->opacity()); - m_btnGrpAnimation->setEndValue(0); - m_btnGrpAnimation->start(); + m_btnGrpOpacityAnimation->stop(); + m_btnGrpOpacityAnimation->setStartValue(m_btnGrpEffect->opacity()); + m_btnGrpOpacityAnimation->setEndValue(0); + m_btnGrpOpacityAnimation->start(); + + m_bribViewOpacityAnimation->stop(); + m_bribViewOpacityAnimation->setStartValue(m_bribViewEffect->opacity()); + m_bribViewOpacityAnimation->setEndValue(0); + m_bribViewOpacityAnimation->start(); return QMainWindow::leaveEvent(event); } @@ -190,7 +221,7 @@ void MainWindow::resizeEvent(QResizeEvent *event) bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result) { #ifdef _WIN32 - // https://stackoverflow.com/questions/6649936/c-compiling-on-windows-and-linux-ifdef-switch + // https://stackoverflow.com/questions/43505580/qt-windows-resizable-frameless-window // Too lazy to do this now.. just stackoverflow it and did a copy and paste.. Q_UNUSED(eventType); MSG* msg = static_cast(message); @@ -301,4 +332,5 @@ void MainWindow::updateWidgetsPosition() m_closeButton->move(width() - m_closeButton->width(), 0); m_bottomButtonGroup->move((width() - m_bottomButtonGroup->width()) / 2, height() - m_bottomButtonGroup->height()); + m_gv->move(width() - m_gv->width(), height() - m_gv->height()); } diff --git a/mainwindow.h b/mainwindow.h index 7d3c8e9..6e3b7bf 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -8,9 +8,11 @@ QT_BEGIN_NAMESPACE class QGraphicsOpacityEffect; +class QGraphicsView; QT_END_NAMESPACE class GraphicsView; +class NavigatorView; class BottomButtonGroup; class MainWindow : public QMainWindow { @@ -41,13 +43,16 @@ protected slots: private: QPoint m_oldMousePos; - QGraphicsOpacityEffect *m_opacityEffect; - QPropertyAnimation *m_btnGrpAnimation; + QGraphicsOpacityEffect *m_btnGrpEffect; + QGraphicsOpacityEffect *m_bribViewEffect; + QPropertyAnimation *m_btnGrpOpacityAnimation; + QPropertyAnimation *m_bribViewOpacityAnimation; QPropertyAnimation *m_fadeOutAnimation; QPropertyAnimation *m_floatUpAnimation; QParallelAnimationGroup *m_exitAnimationGroup; QPushButton *m_closeButton; GraphicsView *m_graphicsView; + NavigatorView *m_gv; BottomButtonGroup *m_bottomButtonGroup; bool m_clickedOnWindow = false; }; diff --git a/navigatorview.cpp b/navigatorview.cpp new file mode 100644 index 0000000..546d664 --- /dev/null +++ b/navigatorview.cpp @@ -0,0 +1,18 @@ +#include "navigatorview.h" + +#include + +NavigatorView::NavigatorView(QWidget *parent) + : QGraphicsView (parent) +{ + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setStyleSheet("background-color: rgba(0, 0, 0, 220);" + "border-radius: 3px;"); +} + +void NavigatorView::wheelEvent(QWheelEvent *event) +{ + event->ignore(); + return QGraphicsView::wheelEvent(event); +} diff --git a/navigatorview.h b/navigatorview.h new file mode 100644 index 0000000..49b73e2 --- /dev/null +++ b/navigatorview.h @@ -0,0 +1,16 @@ +#ifndef NAVIGATORVIEW_H +#define NAVIGATORVIEW_H + +#include + +class NavigatorView : public QGraphicsView +{ + Q_OBJECT +public: + NavigatorView(QWidget *parent = nullptr); + +private: + void wheelEvent(QWheelEvent *event) override; +}; + +#endif // NAVIGATORVIEW_H