OpenMW
apps/opencs/view/world/datadisplaydelegate.hpp
Go to the documentation of this file.
00001 #ifndef DATADISPLAYDELEGATE_HPP
00002 #define DATADISPLAYDELEGATE_HPP
00003 
00004 #include <QTextOption>
00005 #include "enumdelegate.hpp"
00006 
00007 namespace CSVWorld
00008 {
00009 
00010 
00011     class DataDisplayDelegate : public EnumDelegate
00012     {
00013     public:
00014 
00015         typedef std::vector < std::pair < int, QIcon > > IconList;
00016         typedef std::vector<std::pair<int, QString> > ValueList;
00017 
00018     protected:
00019 
00020         enum DisplayMode
00021         {
00022             Mode_TextOnly,
00023             Mode_IconOnly,
00024             Mode_IconAndText
00025         };
00026 
00027         DisplayMode mDisplayMode;
00028         IconList mIcons;
00029 
00030     private:
00031 
00032         std::vector <std::pair <int, QPixmap> > mPixmaps;
00033         QTextOption mTextAlignment;
00034         QSize mIconSize;
00035         int mIconLeftOffset;
00036         int mTextLeftOffset;
00037 
00038     public:
00039         explicit DataDisplayDelegate (const ValueList & values,
00040                                       const IconList & icons,
00041                                       QUndoStack& undoStack, QObject *parent);
00042 
00043         ~DataDisplayDelegate();
00044 
00045         virtual void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
00046 
00048         void setIconSize (const QSize icon);
00049 
00051         void setIconLeftOffset (int offset);
00052 
00054         void setTextLeftOffset (int offset);
00055 
00056     private:
00057 
00059         void paintIcon (QPainter *painter, const QStyleOptionViewItem &option, int i) const;
00060 
00062         void buildPixmaps();
00063 
00064     };
00065 
00066     class DataDisplayDelegateFactory : public EnumDelegateFactory
00067     {
00068     protected:
00069 
00070         DataDisplayDelegate::IconList mIcons;
00071 
00072     public:
00073 
00074         virtual CommandDelegate *makeDelegate (QUndoStack& undoStack, QObject *parent) const;
00076 
00077     protected:
00078 
00079        void add (int enumValue,const  QString enumName, const QString iconFilename);
00080 
00081     };
00082 
00083 }
00084 
00085 #endif // DATADISPLAYDELEGATE_HPP