summaryrefslogtreecommitdiffstats
path: root/pictureviewer2.h
blob: 2e879d113c7b157e2a35090a15a4069d24b1e301 (plain)
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
/*
  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 QGraphicsScene;
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 { SlideAction, HideAction, MarkAction };
        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; }
        const PicDataList marked() { return mMarkedFiles; }
        PicData picData(const QString &fullPath);
        virtual QSize sizeHint() const;

    public slots:
        void next();
        void previous();
        void selectPic(const QString &path);
        void slide(bool);
        void readSettings();
        void writeSettings();
        void shuffle();
        void initActions();
        void copyCurrent();
        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);

    private slots:
        void showFile(const PicData &data);
        void constructInfoItem(const PicData &file, QSize picSize);
        void constructMappingItem(const PicData &file);

    private:
        void setupDialog();
        void setGradient(const QPixmap &pic);
        QTextDocument *treeToString(const SmTreeItem *root) const;
        void treeToStringRecursive(const SmTreeItem *parent, QTextCursor *cursor, int indent) const;
        QPointF getPos(PictureViewer2Item *item, int pos, const QPointF &movPos);
        QString constructWindowTitle() const;
        PicDataList mFiles;
        PicDataList mMarkedFiles;
        QGraphicsScene *mScene;
        QSize mSize;
        QGraphicsPixmapItem *mCur;
        int mCurPos;
        int mConfigInfoPos;
        int mConfigMapPos;
        QTimer *mSlideTimer;
        const static QString mDefaultFile;
        PictureViewer2Item *mFnItem;
        PictureViewer2Item *mMappingItem;
        bool mUseGradient;
        QColor mBgColor;
        QPointF mInfoPos;
        QPointF mMappingPos;
        QAction *mSlideA;
        QAction *mHideA;
        QAction *mMarkA;
        MappingTreeModel *mMappingTreeModel;
        PicFilesModel *mPicFilesModel;
        PicData mCurPicData;
        NewPicsDialog *mNewPicsDlg;
        bool mShowInfoItem;
        bool mShowMappingItem;
        bool mShowMarkItem;
};

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

#endif // PICTUREVIEWER2_H