navigator view wip
This commit is contained in:
parent
0ff1e80132
commit
ca1b10dc28
|
@ -29,13 +29,15 @@ SOURCES += \
|
||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
graphicsview.cpp \
|
graphicsview.cpp \
|
||||||
bottombuttongroup.cpp \
|
bottombuttongroup.cpp \
|
||||||
graphicsscene.cpp
|
graphicsscene.cpp \
|
||||||
|
navigatorview.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
mainwindow.h \
|
mainwindow.h \
|
||||||
graphicsview.h \
|
graphicsview.h \
|
||||||
bottombuttongroup.h \
|
bottombuttongroup.h \
|
||||||
graphicsscene.h
|
graphicsscene.h \
|
||||||
|
navigatorview.h
|
||||||
|
|
||||||
FORMS +=
|
FORMS +=
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ GraphicsView::GraphicsView(QWidget *parent)
|
||||||
|
|
||||||
void GraphicsView::showFromUrlList(const QList<QUrl> &urlList)
|
void GraphicsView::showFromUrlList(const QList<QUrl> &urlList)
|
||||||
{
|
{
|
||||||
|
emit navigatorViewRequired(false, 0);
|
||||||
if (urlList.isEmpty()) {
|
if (urlList.isEmpty()) {
|
||||||
// yeah, it's possible. dragging QQ's original sticker will trigger this, for example.
|
// yeah, it's possible. dragging QQ's original sticker will trigger this, for example.
|
||||||
showText("File url list is empty");
|
showText("File url list is empty");
|
||||||
|
@ -105,12 +106,14 @@ void GraphicsView::zoomView(qreal scaleFactor)
|
||||||
{
|
{
|
||||||
m_scaleFactor *= scaleFactor;
|
m_scaleFactor *= scaleFactor;
|
||||||
reapplyViewTransform();
|
reapplyViewTransform();
|
||||||
|
emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), m_rotateAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsView::resetScale()
|
void GraphicsView::resetScale()
|
||||||
{
|
{
|
||||||
m_scaleFactor = 1;
|
m_scaleFactor = 1;
|
||||||
reapplyViewTransform();
|
reapplyViewTransform();
|
||||||
|
emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), m_rotateAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsView::rotateView(qreal rotateAngel)
|
void GraphicsView::rotateView(qreal rotateAngel)
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
class GraphicsScene;
|
class GraphicsScene;
|
||||||
class GraphicsView : public QGraphicsView
|
class GraphicsView : public QGraphicsView
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
GraphicsView(QWidget *parent = nullptr);
|
GraphicsView(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
@ -30,6 +31,9 @@ public:
|
||||||
|
|
||||||
void checkAndDoFitInView();
|
void checkAndDoFitInView();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void navigatorViewRequired(bool required, qreal angle);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void toggleCheckerboard();
|
void toggleCheckerboard();
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "bottombuttongroup.h"
|
#include "bottombuttongroup.h"
|
||||||
#include "graphicsview.h"
|
#include "graphicsview.h"
|
||||||
|
#include "navigatorview.h"
|
||||||
#include "graphicsscene.h"
|
#include "graphicsscene.h"
|
||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
@ -44,6 +45,19 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
m_graphicsView->setScene(scene);
|
m_graphicsView->setScene(scene);
|
||||||
this->setCentralWidget(m_graphicsView);
|
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 = new QPushButton(m_graphicsView);
|
||||||
m_closeButton->setFlat(true);
|
m_closeButton->setFlat(true);
|
||||||
m_closeButton->setFixedSize(50, 50);
|
m_closeButton->setFixedSize(50, 50);
|
||||||
|
@ -72,14 +86,20 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
m_graphicsView->resetScale();
|
m_graphicsView->resetScale();
|
||||||
m_graphicsView->rotateView(90);
|
m_graphicsView->rotateView(90);
|
||||||
m_graphicsView->checkAndDoFitInView();
|
m_graphicsView->checkAndDoFitInView();
|
||||||
|
m_gv->setVisible(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
m_opacityEffect = new QGraphicsOpacityEffect(m_bottomButtonGroup);
|
m_btnGrpEffect = new QGraphicsOpacityEffect(this);
|
||||||
m_bottomButtonGroup->setGraphicsEffect(m_opacityEffect);
|
m_bribViewEffect = new QGraphicsOpacityEffect(this);
|
||||||
m_btnGrpAnimation = new QPropertyAnimation(m_opacityEffect, "opacity");
|
m_bottomButtonGroup->setGraphicsEffect(m_btnGrpEffect);
|
||||||
m_btnGrpAnimation->setDuration(300);
|
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();
|
centerWindow();
|
||||||
}
|
}
|
||||||
|
@ -92,6 +112,7 @@ MainWindow::~MainWindow()
|
||||||
void MainWindow::showUrls(const QList<QUrl> &urls)
|
void MainWindow::showUrls(const QList<QUrl> &urls)
|
||||||
{
|
{
|
||||||
m_graphicsView->showFromUrlList(urls);
|
m_graphicsView->showFromUrlList(urls);
|
||||||
|
m_gv->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::adjustWindowSizeBySceneRect()
|
void MainWindow::adjustWindowSizeBySceneRect()
|
||||||
|
@ -125,20 +146,30 @@ void MainWindow::showEvent(QShowEvent *event)
|
||||||
|
|
||||||
void MainWindow::enterEvent(QEvent *event)
|
void MainWindow::enterEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
m_btnGrpAnimation->stop();
|
m_btnGrpOpacityAnimation->stop();
|
||||||
m_btnGrpAnimation->setStartValue(m_opacityEffect->opacity());
|
m_btnGrpOpacityAnimation->setStartValue(m_btnGrpEffect->opacity());
|
||||||
m_btnGrpAnimation->setEndValue(1);
|
m_btnGrpOpacityAnimation->setEndValue(1);
|
||||||
m_btnGrpAnimation->start();
|
m_btnGrpOpacityAnimation->start();
|
||||||
|
|
||||||
|
m_bribViewOpacityAnimation->stop();
|
||||||
|
m_bribViewOpacityAnimation->setStartValue(m_bribViewEffect->opacity());
|
||||||
|
m_bribViewOpacityAnimation->setEndValue(1);
|
||||||
|
m_bribViewOpacityAnimation->start();
|
||||||
|
|
||||||
return QMainWindow::enterEvent(event);
|
return QMainWindow::enterEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::leaveEvent(QEvent *event)
|
void MainWindow::leaveEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
m_btnGrpAnimation->stop();
|
m_btnGrpOpacityAnimation->stop();
|
||||||
m_btnGrpAnimation->setStartValue(m_opacityEffect->opacity());
|
m_btnGrpOpacityAnimation->setStartValue(m_btnGrpEffect->opacity());
|
||||||
m_btnGrpAnimation->setEndValue(0);
|
m_btnGrpOpacityAnimation->setEndValue(0);
|
||||||
m_btnGrpAnimation->start();
|
m_btnGrpOpacityAnimation->start();
|
||||||
|
|
||||||
|
m_bribViewOpacityAnimation->stop();
|
||||||
|
m_bribViewOpacityAnimation->setStartValue(m_bribViewEffect->opacity());
|
||||||
|
m_bribViewOpacityAnimation->setEndValue(0);
|
||||||
|
m_bribViewOpacityAnimation->start();
|
||||||
|
|
||||||
return QMainWindow::leaveEvent(event);
|
return QMainWindow::leaveEvent(event);
|
||||||
}
|
}
|
||||||
|
@ -190,7 +221,7 @@ void MainWindow::resizeEvent(QResizeEvent *event)
|
||||||
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#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..
|
// Too lazy to do this now.. just stackoverflow it and did a copy and paste..
|
||||||
Q_UNUSED(eventType);
|
Q_UNUSED(eventType);
|
||||||
MSG* msg = static_cast<MSG*>(message);
|
MSG* msg = static_cast<MSG*>(message);
|
||||||
|
@ -301,4 +332,5 @@ void MainWindow::updateWidgetsPosition()
|
||||||
m_closeButton->move(width() - m_closeButton->width(), 0);
|
m_closeButton->move(width() - m_closeButton->width(), 0);
|
||||||
m_bottomButtonGroup->move((width() - m_bottomButtonGroup->width()) / 2,
|
m_bottomButtonGroup->move((width() - m_bottomButtonGroup->width()) / 2,
|
||||||
height() - m_bottomButtonGroup->height());
|
height() - m_bottomButtonGroup->height());
|
||||||
|
m_gv->move(width() - m_gv->width(), height() - m_gv->height());
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,11 @@
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QGraphicsOpacityEffect;
|
class QGraphicsOpacityEffect;
|
||||||
|
class QGraphicsView;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
class GraphicsView;
|
class GraphicsView;
|
||||||
|
class NavigatorView;
|
||||||
class BottomButtonGroup;
|
class BottomButtonGroup;
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
|
@ -41,13 +43,16 @@ protected slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPoint m_oldMousePos;
|
QPoint m_oldMousePos;
|
||||||
QGraphicsOpacityEffect *m_opacityEffect;
|
QGraphicsOpacityEffect *m_btnGrpEffect;
|
||||||
QPropertyAnimation *m_btnGrpAnimation;
|
QGraphicsOpacityEffect *m_bribViewEffect;
|
||||||
|
QPropertyAnimation *m_btnGrpOpacityAnimation;
|
||||||
|
QPropertyAnimation *m_bribViewOpacityAnimation;
|
||||||
QPropertyAnimation *m_fadeOutAnimation;
|
QPropertyAnimation *m_fadeOutAnimation;
|
||||||
QPropertyAnimation *m_floatUpAnimation;
|
QPropertyAnimation *m_floatUpAnimation;
|
||||||
QParallelAnimationGroup *m_exitAnimationGroup;
|
QParallelAnimationGroup *m_exitAnimationGroup;
|
||||||
QPushButton *m_closeButton;
|
QPushButton *m_closeButton;
|
||||||
GraphicsView *m_graphicsView;
|
GraphicsView *m_graphicsView;
|
||||||
|
NavigatorView *m_gv;
|
||||||
BottomButtonGroup *m_bottomButtonGroup;
|
BottomButtonGroup *m_bottomButtonGroup;
|
||||||
bool m_clickedOnWindow = false;
|
bool m_clickedOnWindow = false;
|
||||||
};
|
};
|
||||||
|
|
18
navigatorview.cpp
Normal file
18
navigatorview.cpp
Normal 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
16
navigatorview.h
Normal 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
|
Loading…
Reference in New Issue
Block a user