1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version
2 of the License, or (at your option) any later version.
*/
#ifndef PICTUREVIEWER2_H
#define PICTUREVIEWER2_H
#include <QGraphicsView>
#include <QList>
#include <QVariant>
#include <QGraphicsItem>
#include <QStaticText>
class PictureViewerGraphicsScene;
class BoundingRectItem;
class QGraphicsPixmapItem;
class QWheelEvent;
class QContextMenuEvent;
class QTimer;
class QTextDocument;
class QTextCursor;
class PictureViewer2Item;
class QGraphicsItem;
class SmTreeItem;
class MappingTreeModel;
class PicFilesModel;
class NewPicsDialog;
typedef QList<QVariant> PicData;
typedef QList<QList<QVariant> > PicDataList;
class PictureViewer2 : public QGraphicsView {
Q_OBJECT
public:
enum AssocActions { ToggleSlideAction, SlideSelectedAction, SlideAllAction, HideAction, MarkAction, DeleteAction, SkipForwardAction, SkipBackwardAction };
explicit PictureViewer2(QWidget *parent = 0);
void addFiles(const PicDataList &files, bool clear = true);
void addFiles(const QString &dir, bool clear = true);
void addFiles(const QStringList &files, bool clear = true);
void addFile(const QString &fullPath, int fileId = -1);
void setFile(const PicData &file);
void setFile(QString fullPath = mDefaultFile);
void setPixmap(const QPixmap &pm);
void setShowInfoItem(bool show) { mShowInfoItem = show; }
void setShowMappingItem(bool show) { mShowMappingItem = show; }
void setShowMarkItem(bool show) { mShowMarkItem = show; }
void setCurrentDir(const QString &curDir) { mCurrentDir = curDir; }
void setSlideSelected();
const PicDataList marked() { return mMarkedFiles; }
PicData picData(const QString &fullPath, int fileId = -1);
public slots:
void next();
void previous();
void skip(int amount);
void selectPic(const QString &path);
void toggleSlide(bool slide);
void slide(bool);
void slideThrouhghAll(bool);
void readSettings();
void writeSettings();
void shuffle();
void initActions();
void copyCurrent();
void deleteCurrent();
void showNewPicsDialog();
void addToNewPics();
void markCurrent();
void clearMarks();
protected:
virtual void wheelEvent(QWheelEvent *event);
virtual void contextMenuEvent(QContextMenuEvent *e);
virtual void keyPressEvent(QKeyEvent *e);
virtual void showEvent(QShowEvent *e);
virtual void hideEvent(QHideEvent *e);
virtual void resizeEvent(QResizeEvent *event);
private slots:
void showFile(const PicData &data);
void constructInfoItem(const PicData &file, QSize picSize);
void constructMappingItem(const PicData &file);
void docFromTree(SmTreeItem *start, QTextCursor *cur, int indent);
void nextFromAll();
private:
void setupDialog();
void setGradient(const QPixmap &pic);
void setNextBatch();
QTextDocument *treeToString(const SmTreeItem *root) const;
void treeToStringRecursive(const SmTreeItem *parent, QTextCursor *cursor, int indent) const;
QPointF getPos(QGraphicsItem *item, int pos, const QPointF &movPos);
QString constructWindowTitle() const;
PicDataList mFiles;
PicDataList mMarkedFiles;
PictureViewerGraphicsScene *mScene;
QGraphicsPixmapItem *mCur;
int mCurPos;
int mConfigInfoPos;
int mConfigMapPos;
QTimer *mSlideTimer;
QTimer *mSlideTimerAll;
QTimer *mCurTimer;
bool mSlideTimerAllRestart;
const static QString mDefaultFile;
PictureViewer2Item *mFnItem;
PictureViewer2Item *mMappingItem;
BoundingRectItem *mBoundingRectItem;
bool mUseGradient;
QColor mBgColor;
QPointF mInfoPos;
QPointF mMappingPos;
QPointF mBoundingPos;
QAction *mSlideA;
QAction *mToggleSlideA;
QAction *mSlideAllA;
QAction *mHideA;
QAction *mMarkA;
QAction *mDeleteA;
QAction *mSkipForwardA;
QAction *mSkipBackwardA;
MappingTreeModel *mMappingTreeModel;
PicFilesModel *mPicFilesModel;
PicData mCurPicData;
NewPicsDialog *mNewPicsDlg;
bool mShowInfoItem;
bool mShowMappingItem;
bool mShowMarkItem;
QString mCurrentDir;
};
class PictureViewer2Item : public QGraphicsItem {
public:
explicit PictureViewer2Item(const PicData &data, const int numSelected, const QSize &picSize = QSize(), QGraphicsItem *parent = 0);
explicit PictureViewer2Item(QTextDocument *doc, QGraphicsItem *parent = 0);
~PictureViewer2Item();
QRectF boundingRect() const;
void appendText(const QString &text);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
private:
QStringList mTextList;
QTextDocument *mDoc;
};
class BoundingRectItem : public QGraphicsItem {
public:
explicit BoundingRectItem(const QSize &size, QGraphicsItem *parent = 0) : QGraphicsItem(parent), mSize(size) {}
QRectF boundingRect() const;
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
private:
QSize mSize;
};
class PictureViewerGraphicsScene : public QGraphicsScene {
public:
explicit PictureViewerGraphicsScene(QObject *parent = 0) : QGraphicsScene(parent) {}
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *e);
};
#endif // PICTUREVIEWER2_H
|