Scribus
Open source desktop publishing at your fingertips
previewimage.h
1 /*****************************************************************
2 * Copyright (C) 2009 Pierre Marchand
3 
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 *
17 ******************************************************************/
18 
19 #ifndef PREVIEWIMAGE_H
20 #define PREVIEWIMAGE_H
21 
22 #include <QAbstractListModel>
23 #include <QDateTime>
24 #include <QImage>
25 #include <QFileInfo>
26 #include <QMimeData>
27 #include <QModelIndex>
28 #include <QPixmap>
29 #include <QString>
30 #include <QStringList>
31 #include <QVariant>
32 
33 #include "scribusdoc.h"
34 
35 class imageCollection;
36 class PageItem;
37 class PictureBrowser;
38 
39 
40 
41 //holds information about an image
43 {
44  public:
46 
47  int width, height;
48  int type;
49  int colorspace;
50  int xdpi, ydpi;
51  int layers;
52  bool embedded;
53  QString profileName;
54  bool valid;
55 };
56 
57 
58 //class for a single previewimage, contains all information related to the image
60 {
61  public:
62  //constructor, sets filepath for an image
63  previewImage ( QString imageFile );
64  ~previewImage();
65 
66  //creates the previewicon in desired size in pixels
67  //parameters:
68  //const QImage &image: image to create icon from
69  //int size: the desired iconsize
70  bool createPreviewIcon ( const QImage &image, int size );
71 
72  //creates a new imageframe on a page and inserts the image
73  bool insertIntoDocument ( ScribusDoc *doc, InsertAFrameData &iafData );
74  //inserts the image into a given imageframe
75  bool insertIntoImageFrame ( ScribusDoc *doc, PageItem *imageFrame );
76 
77  //filter attribute. if filter settings match, its set to true and no longer considered for display/sorting
78  bool filtered;
79  //contains fileinformation
80  QFileInfo fileInformation;
81  //keeps imageinformation
82  ImageInformation *imgInfo;
83  //current size of previewIcon
84  int currentSize;
85  //tells wether previewIcon is loading in thread
86  bool previewImageLoading;
87  //tells if previewIcon was created previously or needs to be loaded
88  bool previewIconCreated;
89  //contains previewicon which is to be shown
90  QPixmap previewIcon;
91  //tags
92  QStringList tags;
93 };
94 
95 
96 //class for managing a set of previewImage objects
98 {
99  public:
100  //constructor, adds imageFiles to this set
101  previewImages ( const QStringList& imageFiles );
102 
103  //creates previewimage objects from a QStringList
104  void createPreviewImagesList ( const QStringList& imageFiles );
105  //creates previewimage objects from imageCollection
106  void createPreviewImagesList ( const imageCollection *collection );
107  //deletes all entries
108  void clearPreviewImagesList();
109 
110  //little helper function to reduce code
111  bool toRemove ( bool a, bool b );
112  //filters by filename, invert specifies wether to include or to remove file fileName
113  void filterFileName ( const QString &fileName, bool invert );
114  //filters by filesize, smallerThan specifies wether to include or to remove files smaller than fileSize
115  void filterFileSize ( qint64 fileSize, bool smallerThan );
116  //filters by filetype, invert specifies wether to include or to remove files with fileExtension
117  void filterFileType ( const QStringList &types, bool invert );
118  //filters by date last modified, smallerThan specifies wether to include or to remove files younger than modified
119  void filterFileModified ( const QDateTime &modified, bool smallerThan );
120  //filters by imageresolution, smallerThan specifies wether to include or to remove images with lower resolution
121  void filterResolution ( qint64 resolution, bool smallerThan );
122  //filters by tag, invert specifies wether to include or to remove item with tag
123  void filterTag ( const QStringList &tags, bool invert );
124  //clears all previously applied filters
125  void clearFilters();
126 
127  //sorts previewImagesList after sort criteria
128  //0: sort by filename
129  //1: sort by fileextension
130  //2: sort by date last modified
131  //3: sort by filesize
132  void sortPreviewImages ( const int sort );
133 
134  //all our precious previewimages are indexed here
135  QList<previewImage *> previewImagesList;
136 };
137 
138 
139 //a model which holds the previewimages and is connected to QListView
140 class PreviewImagesModel : public QAbstractListModel
141 {
142  Q_OBJECT
143 
144  public:
145  PreviewImagesModel ( QObject *parent = 0 );
146  //saves pointer to calling PictureBrowser instance, for later access
148 
149  //creates the default icon which is displayed when image is not loaded yet
150  //parameters:
151  //int size: size of the icon to be created
152  void createDefaultIcon ( int size );
153  //sets the modelitemslist to previewImagesList, ignores filtered images
154  void setModelItemsList ( const QList<previewImage *> &previewImagesList );
155  //removes all items
156  void clearModelItemsList();
157 
158  //returns previewicons and, depending on previewmode, additional text
159  QVariant data ( const QModelIndex &index, int role = Qt::DisplayRole ) const;
160  //returns flags for items
161  Qt::ItemFlags flags ( const QModelIndex &index ) const;
162  //returns the number of previewimages
163  int rowCount ( const QModelIndex &parent ) const;
164 
165  QMimeData *mimeData ( const QModelIndexList &indexes ) const;
166  QStringList mimeTypes() const;
167 
168  //all our precious previewimages are indexed here
169  QList<previewImage *> modelItemsList;
170  //a unique id telling the thread wether to cancel current loading operations because files have changed
171  int pId;
172 
173  private slots:
174  //called when imageloadingthread has finished
175  //parameters:
176  //previewImage* loadedImage: pointer to identify the loaded image
177  //const QImage image: the actual image
178  //int tpId: the id the thread has been called from
179  void processLoadedImage ( int row, const QImage image, ImageInformation* imgInfo, int tpId );
180  void processImageLoadError ( int row, int tpId, int errorcode );
181 
182  private:
183  //pointer to the picturebrowser class
184  PictureBrowser *pictureBrowser;
185  //default icon
186  QPixmap defaultIcon;
187  //icon size of defaultIcon
188  int defaultIconSize;
189 
190 };
191 
192 #endif // PREVIEWIMAGE_H
Definition: previewimage.h:42
Definition: previewimage.h:97
Definition: previewimage.h:140
Definition: usertaskstructs.h:15
the Document Class
Definition: scribusdoc.h:90
Definition: collection.h:29
Definition: previewimage.h:59
Definition: pageitem.h:92
Definition: picturebrowser.h:97