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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
/*
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>
#include <QDialog>
#include <QSpinBox>
#include <QCheckBox>
class PictureViewerGraphicsScene;
class BoundingRectItem;
class QGraphicsTextItem;
class QGraphicsPixmapItem;
class QWheelEvent;
class QContextMenuEvent;
class QTimer;
class QTextDocument;
class QTextCursor;
class PictureViewer2Item;
class QGraphicsItem;
class SmTreeItem;
class MappingTreeModel;
class PicFilesModel;
class NewPicsDialog;
class QRadioButton;
class QCheckBox;
class QLabel;
class QPushButton;
class QSpinBox;
class MappingEditWidget;
class PictureViewerSlideDlg;
typedef QList<QVariant> PicData;
typedef QList<QList<QVariant> > PicDataList;
class PictureViewer2 : public QGraphicsView {
Q_OBJECT
public:
enum AssocActions { HideAction, MarkAction, DeleteAction, SlideAction };
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 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; }
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 stopSlide();
void startSlide();
void readSettings();
void writeSettings();
void initActions();
void copyCurrent();
void deleteCurrent();
void showNewPicsDialog();
void addToNewPics();
void markCurrent();
void clearMarks();
void showSlide();
void doSlide();
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 nextSlide();
void showFile(const PicData &data);
void constructInfoItem(const PicData &file, QSize picSize, bool converted = false);
void constructMappingItem(const PicData &file);
void docFromTree(SmTreeItem *start, QTextCursor *cur, int indent);
private:
void setGradient(const QPixmap &pic);
void showNext();
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;
PictureViewerSlideDlg *mSlideDlg;
QList<QList<QVariant> > mPicData;
int mTotal;
int mNextSlideCtr;
int mCurPos;
int mConfigInfoPos;
int mConfigMapPos;
int mCursorOffset;
QTimer *mTimer;
bool mSlideTimerRecentRestart;
const static QString mDefaultFile;
PictureViewer2Item *mFnItem;
PictureViewer2Item *mMappingItem;
bool mUseGradient;
QColor mBgColor;
QColor mDefaultTextColor;
QPointF mInfoPos;
QPointF mMappingPos;
QPointF mBoundingPos;
QAction *mHideA;
QAction *mMarkA;
QAction *mDeleteA;
PicFilesModel *mPicFilesModel;
PicData mCurPicData;
NewPicsDialog *mNewPicsDlg;
bool mShowInfoItem;
bool mShowMappingItem;
bool mShowMarkItem;
QString mCurrentDir;
QString mArchiveDir;
};
class PictureViewerSlideDlg : public QDialog {
Q_OBJECT
public:
enum SlideResult { SlideAll, SlideRecent, SlideSelection, NoSlide };
explicit PictureViewerSlideDlg(QWidget *parent = 0, Qt::WindowFlags f = 0);
int result() const { return mSlideResult; }
void setResult(int result);
int days() const { return mRecentDays->value(); }
void setDays(int days) { mRecentDays->setValue(days); }
bool shuffle() const { return mShuffle->isChecked(); }
void setShuffle(bool shuffle) { mShuffle->setChecked(shuffle); }
MappingEditWidget *mappingEditWidget() const { return mMappingEditWidget; }
private slots:
void slideAllToggled(bool checked);
void recentToggled(bool checked);
void slideSelectionToggled(bool checked);
void noSlideToggled(bool checked);
private:
QRadioButton *mSlideAll;
QRadioButton *mRecent;
QRadioButton *mSelection;
QRadioButton *mNoSlide;
QCheckBox *mShuffle;
QLabel *mResultCount;
QSpinBox *mRecentDays;
QPushButton *mOk;
QPushButton *mCancel;
MappingEditWidget *mMappingEditWidget;
int mSlideResult;
};
class PictureViewer2Item : public QGraphicsItem {
public:
explicit PictureViewer2Item(const PicData &data, const int numSelected, int cur, 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 PictureViewerGraphicsScene : public QGraphicsScene {
Q_OBJECT
public:
explicit PictureViewerGraphicsScene(QObject *parent = 0) : QGraphicsScene(parent) {}
void setCursorOffset(int offset) { mCursorOffset = offset; }
signals:
void itemClicked(QGraphicsItem *item);
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *e);
private:
int mCursorOffset;
};
#endif // PICTUREVIEWER2_H
|