navigator view wip

This commit is contained in:
Gary Wang 2019-10-03 17:57:14 +08:00
parent 0ff1e80132
commit ca1b10dc28
7 changed files with 98 additions and 18 deletions

View File

@ -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 +=

View File

@ -23,6 +23,7 @@ GraphicsView::GraphicsView(QWidget *parent)
void GraphicsView::showFromUrlList(const QList<QUrl> &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)

View File

@ -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();

View File

@ -2,6 +2,7 @@
#include "bottombuttongroup.h"
#include "graphicsview.h"
#include "navigatorview.h"
#include "graphicsscene.h"
#include <QMouseEvent>
@ -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<QUrl> &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<MSG*>(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());
}

View File

@ -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;
};

18
navigatorview.cpp Normal file
View File

@ -0,0 +1,18 @@
#include "navigatorview.h"
#include <QMouseEvent>
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);
}

16
navigatorview.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef NAVIGATORVIEW_H
#define NAVIGATORVIEW_H
#include <QGraphicsView>
class NavigatorView : public QGraphicsView
{
Q_OBJECT
public:
NavigatorView(QWidget *parent = nullptr);
private:
void wheelEvent(QWheelEvent *event) override;
};
#endif // NAVIGATORVIEW_H