| 1 |
/* |
| 2 |
* Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd. |
| 3 |
* |
| 4 |
* Author: ZhangYong <[email protected]> |
| 5 |
* |
| 6 |
* Maintainer: ZhangYong <[email protected]> |
| 7 |
* |
| 8 |
* This program is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* This program is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
#ifndef SVGVIEW_H |
| 22 |
#define SVGVIEW_H |
| 23 |
#include "controller/viewerthememanager.h" |
| 24 |
#include "imageengine/imageenginethread.h" |
| 25 |
|
| 26 |
#include <QGraphicsView> |
| 27 |
#include <QFutureWatcher> |
| 28 |
#include <QThread> |
| 29 |
#include <QFileSystemWatcher> |
| 30 |
#include <QTimer> |
| 31 |
#include <QGraphicsBlurEffect> |
| 32 |
#include <QPointer> |
| 33 |
#include <QMap> |
| 34 |
#include <QFileSystemWatcher> |
| 35 |
|
| 36 |
QT_BEGIN_NAMESPACE |
| 37 |
class QWheelEvent; |
| 38 |
class QPaintEvent; |
| 39 |
class QFile; |
| 40 |
class GraphicsMovieItem; |
| 41 |
class GraphicsPixmapItem; |
| 42 |
class QGraphicsSvgItem; |
| 43 |
class QThreadPool; |
| 44 |
class QGestureEvent; |
| 45 |
class QPinchGesture; |
| 46 |
class QSwipeGesture; |
| 47 |
QT_END_NAMESPACE |
| 48 |
|
| 49 |
#include "dtkwidget_global.h" |
| 50 |
DWIDGET_BEGIN_NAMESPACE |
| 51 |
DWIDGET_END_NAMESPACE |
| 52 |
|
| 53 |
class CFileWatcher; |
| 54 |
class ImageView : public QGraphicsView |
| 55 |
{ |
| 56 |
Q_OBJECT |
| 57 |
|
| 58 |
public: |
| 59 |
enum RendererType { Native, OpenGL }; |
| 60 |
|
| 61 |
explicit ImageView(QWidget *parent = nullptr); |
| 62 |
~ImageView() override; |
| 63 |
void clear(); |
| 64 |
void fitWindow(); |
| 65 |
void fitImage(); |
| 66 |
void rotateClockWise(); |
| 67 |
void rotateCounterclockwise(); |
| 68 |
void centerOn(qreal x, qreal y); |
| 69 |
void setImage(const QString &path, const QImage &image = QImage()); |
| 70 |
// void setRenderer(RendererType type = Native); |
| 71 |
void setScaleValue(qreal v); |
| 72 |
|
| 73 |
void autoFit(); |
| 74 |
|
| 75 |
const QImage image(); |
| 76 |
qreal imageRelativeScale() const; |
| 77 |
qreal windowRelativeScale() const; |
| 78 |
// const QRectF imageRect() const; |
| 79 |
const QString path() const; |
| 80 |
|
| 81 |
QPoint mapToImage(const QPoint &p) const; |
| 82 |
QRect mapToImage(const QRect &r) const; |
| 83 |
QRect visibleImageRect() const; |
| 84 |
bool isWholeImageVisible() const; |
| 85 |
|
| 86 |
bool isFitImage() const; |
| 87 |
bool isFitWindow() const; |
| 88 |
|
| 89 |
signals: |
| 90 |
void clicked(); |
| 91 |
void doubleClicked(); |
| 92 |
void imageChanged(const QString &path); |
| 93 |
void mouseHoverMoved(); |
| 94 |
void scaled(qreal perc); |
| 95 |
void transformChanged(); |
| 96 |
void showScaleLabel(); |
| 97 |
void hideNavigation(); |
| 98 |
void nextRequested(); |
| 99 |
void previousRequested(); |
| 100 |
void disCheckAdaptImageBtn(); |
| 101 |
void disCheckAdaptScreenBtn(); |
| 102 |
void checkAdaptImageBtn(); |
| 103 |
void checkAdaptScreenBtn(); |
| 104 |
void sigFileDelete(); |
| 105 |
|
| 106 |
|
| 107 |
public slots: |
| 108 |
// void setHighQualityAntialiasing(bool highQualityAntialiasing); |
| 109 |
void onImgFileChanged(const QString &ddfFile); |
| 110 |
void onLoadTimerTimeout(); |
| 111 |
void onThemeTypeChanged(); |
| 112 |
void onIsChangedTimerTimeout(); |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
protected: |
| 117 |
void mouseDoubleClickEvent(QMouseEvent *e) override; |
| 118 |
void mouseReleaseEvent(QMouseEvent *e) override; |
| 119 |
void mousePressEvent(QMouseEvent *e) override; |
| 120 |
void mouseMoveEvent(QMouseEvent *e) override; |
| 121 |
void leaveEvent(QEvent *e) override; |
| 122 |
// void resizeEvent(QResizeEvent *event) override; |
| 123 |
void wheelEvent(QWheelEvent *event) override; |
| 124 |
void paintEvent(QPaintEvent *event) override; |
| 125 |
void dragEnterEvent(QDragEnterEvent *e) override; |
| 126 |
void drawBackground(QPainter *painter, const QRectF &rect) override; |
| 127 |
bool event(QEvent *event) override; |
| 128 |
|
| 129 |
private slots: |
| 130 |
void onCacheFinish(); |
| 131 |
void onThemeChanged(ViewerThemeManager::AppTheme theme); |
| 132 |
void scaleAtPoint(QPoint pos, qreal factor); |
| 133 |
void handleGestureEvent(QGestureEvent *gesture); |
| 134 |
void pinchTriggered(QPinchGesture *gesture); |
| 135 |
// void swipeTriggered(QSwipeGesture *gesture); |
| 136 |
// void updateImages(const QStringList &path); |
| 137 |
private: |
| 138 |
bool m_isFitImage = false; |
| 139 |
bool m_isFitWindow = false; |
| 140 |
QColor m_backgroundColor; |
| 141 |
RendererType m_renderer; |
| 142 |
QFutureWatcher<QVariantList> m_watcher; |
| 143 |
QString m_path; |
| 144 |
QString m_loadingIconPath; |
| 145 |
QThreadPool *m_pool; |
| 146 |
GraphicsMovieItem *m_movieItem = nullptr; |
| 147 |
GraphicsPixmapItem *m_pixmapItem = nullptr; |
| 148 |
QPointer<QGraphicsBlurEffect> m_blurEffect; |
| 149 |
// CFileWatcher *m_imgFileWatcher; |
| 150 |
QFileSystemWatcher *m_imgFileWatcher; |
| 151 |
QTimer *m_isChangedTimer; |
| 152 |
|
| 153 |
bool m_isFirstPinch = false; |
| 154 |
QPointF m_centerPoint; |
| 155 |
QTimer *m_loadTimer = nullptr; |
| 156 |
QString m_loadPath;//需要加载的图片路径 |
| 157 |
int m_startpointx = 0;//触摸操作放下时的x坐标 |
| 158 |
int m_maxTouchPoints = 0;//触摸动作时手指数 |
| 159 |
|
| 160 |
//平板需求,记录打开图片时初始缩放比例 |
| 161 |
bool m_firstset = false; |
| 162 |
double m_value = 0.0; |
| 163 |
double m_max_scale_factor = 2.0; |
| 164 |
double m_min_scale_factor = 0.0; |
| 165 |
|
| 166 |
//单指点击标识位 |
| 167 |
bool m_press = false; |
| 168 |
}; |
| 169 |
|
| 170 |
//class CFileWatcher: public QThread |
| 171 |
//{ |
| 172 |
// Q_OBJECT |
| 173 |
//public: |
| 174 |
// enum EFileChangedType {EFileModified, EFileMoved, EFileCount}; |
| 175 |
|
| 176 |
// explicit CFileWatcher(QObject *parent = nullptr); |
| 177 |
// ~CFileWatcher(); |
| 178 |
|
| 179 |
// bool isVaild(); |
| 180 |
|
| 181 |
// void addWather(const QString &path); |
| 182 |
//// void removePath(const QString &path); |
| 183 |
|
| 184 |
// void clear(); |
| 185 |
|
| 186 |
//signals: |
| 187 |
// void fileChanged(const QString &path, int tp); |
| 188 |
|
| 189 |
//protected: |
| 190 |
// void run(); |
| 191 |
|
| 192 |
//private: |
| 193 |
// void doRun(); |
| 194 |
|
| 195 |
// int _handleId = -1; |
| 196 |
// bool _running = false; |
| 197 |
|
| 198 |
|
| 199 |
// QMap<QString, int> watchedFiles; |
| 200 |
// QMap<int, QString> watchedFilesId; |
| 201 |
|
| 202 |
// QMutex _mutex; |
| 203 |
//}; |
| 204 |
#endif // SVGVIEW_H |