Hydra 0.20
hydra.src/desktop/ThumbsView.h
00001 
00002 /*
00003  * Copyright (c) 2010 Aleksander B. Demko
00004  * This source code is distributed under the MIT license.
00005  * See the accompanying file LICENSE.MIT.txt for details.
00006  */
00007 
00008 #ifndef __INCLUDED_HYDRADESKTOP_THUMBSVIEW_H__
00009 #define __INCLUDED_HYDRADESKTOP_THUMBSVIEW_H__
00010 
00011 #include <QAbstractListModel>
00012 #include <QListView>
00013 #include <QListWidget>
00014 
00015 #include <hydra/Thumb.h>
00016 #include <desktop/View.h>
00017 #include <desktop/ThumbCache.h>
00018 
00019 namespace desktop
00020 {
00021   class ThumbsDelegate; // internal
00022   class ThumbsView;
00023 }
00024 
00025 // helper class for ThumbsView
00026 class desktop::ThumbsDelegate : public QAbstractItemDelegate
00027 {
00028   public:
00029     static const int PIC_W = hydra::Thumb::DEFAULT_THUMB_W/2;
00030     static const int PIC_H = hydra::Thumb::DEFAULT_THUMB_H/2;
00031     static const int OFFSET_W = 10;
00032     static const int OFFSET_H = 10;
00033     static const int FULL_W = PIC_W+OFFSET_W*2;
00034     static const int FULL_H = PIC_H+OFFSET_H*2+OFFSET_H*6;
00035 
00036   public:
00037     ThumbsDelegate(FileList *_filelist, ThreadedThumbCache *_thumbcache);
00038 
00039     virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
00040     virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
00041 
00042     void clear(void);
00043 
00044     // called when an image is rotated, etc
00045     void onImageChange(FileList *fl, int fileIndex);
00046   private:
00047     FileList *dm_filelist;
00048     ThreadedThumbCache *dm_thumbcache;
00049 
00050     typedef std::map<QString, desktop::cache_ptr<QPixmap> > imagecache_t;
00051     // key is HASH, not filename
00052     mutable imagecache_t dm_images;
00053 };
00054 
00055 /**
00056  * A thumbnail veiwer.
00057  *
00058  * @author Aleksander Demko
00059  */ 
00060 class desktop::ThumbsView : public desktop::View
00061 {
00062     Q_OBJECT
00063 
00064   public:
00065     /**
00066      * Constructor.
00067      *
00068      * @param wrap_list if true, there will be wrapping (false = thumbstrip like mode)
00069      * @param popout_on_activate if nonnull, this MainWindow will be used to popout
00070      * a new view on activation
00071      * @author Aleksander Demko
00072      */ 
00073     ThumbsView(MainWindow *mainwin, FileList *_filelist, ThreadedThumbCache *_thumbcache, bool wrap_list,
00074         bool popout_on_activate = false);
00075 
00076     // called when an image is rotated, etc
00077     virtual void onImageChange(FileList *fl, int fileIndex);
00078 
00079   protected:
00080     virtual void contextMenuEvent(QContextMenuEvent * event);
00081 
00082   private slots:
00083     void onActivated(const QModelIndex &i);
00084 
00085   private:
00086     void initGui(bool wrap_list);
00087 
00088   private:
00089     ThreadedThumbCache *dm_thumbcache;
00090 
00091     QListView *dm_list;
00092 
00093     ThumbsDelegate dm_delegate;
00094 
00095     bool dm_popout_on_active;
00096 };
00097 
00098 #endif
00099 
 All Classes Namespaces Functions Variables