krita

layerlist.h

00001 /*
00002   Copyright (c) 2005 Gábor Lehel <illissius@gmail.com>
00003 
00004   This library is free software; you can redistribute it and/or
00005   modify it under the terms of the GNU Library General Public
00006   License as published by the Free Software Foundation; either
00007   version 2 of the License, or (at your option) any later version.
00008 
00009   This library is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012   Library General Public License for more details.
00013 
00014   You should have received a copy of the GNU Library General Public License
00015   along with this library; see the file COPYING.LIB.  If not, write to
00016   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017   Boston, MA 02110-1301, USA.
00018 */
00019 
00020 
00021 #ifndef LAYERLIST_H
00022 #define LAYERLIST_H
00023 
00024 #include <qiconset.h>
00025 #include <klistview.h>
00026 
00027 class QMouseEvent;
00028 class QString;
00029 class KPopupMenu;
00030 class LayerItem;
00031 class LayerFolder;
00032 template<class T> class QPtrList;
00033 
00034 class LayerList: public KListView
00035 {
00036     Q_OBJECT
00037 
00038 public:
00039     LayerList( QWidget *parent = 0, const char *name = 0 );
00040     virtual ~LayerList();
00041 
00042     void addProperty( const QString &name, const QString &displayName, const QIconSet &icon = QIconSet(),
00043                       bool defaultValue = false, bool validForFolders = true );
00044     void addProperty( const QString &name, const QString &displayName, QPixmap enabled, QPixmap disabled,
00045                       bool defaultValue = false, bool validForFolders = true );
00046 
00047     bool foldersCanBeActive() const;
00048     bool previewsShown() const;
00049     int itemHeight() const;
00050     int numRows() const;
00051 
00052     LayerItem *layer( int id ) const;
00053     LayerItem *folder( int id ) const; //returns 0 if not a folder
00054 
00055     LayerItem *activeLayer() const;
00056     int activeLayerID() const;
00057 
00058     QValueList<LayerItem*> selectedLayers() const;
00059     QValueList<int> selectedLayerIDs() const;
00060 
00061     void makeFolder( int id );
00062     bool isFolder( int id ) const;
00063     QString displayName( int id ) const;
00064     bool property( int id, const QString &name ) const;
00065 
00066     struct MenuItems
00067     {
00068         enum { NewLayer = 0, NewFolder, RemoveLayer, LayerProperties, COUNT };
00069     };
00070     KPopupMenu *contextMenu() const;
00071 
00072 public slots:
00073     void setFoldersCanBeActive( bool can );
00074     void setPreviewsShown( bool show );
00075     void setItemHeight( int height );
00076     void setNumRows( int rows ); //how many rows of property icons can fit
00077 
00078     void setActiveLayer( LayerItem *layer );
00079     void setActiveLayer( int id );
00080 
00081     void setLayerDisplayName( LayerItem *layer, const QString &displayName );
00082     void setLayerDisplayName( int id, const QString &displayName );
00083 
00084     void setLayerProperty( LayerItem *layer, const QString &name, bool on );
00085     void setLayerProperty( int id, const QString &name, bool on );
00086 
00087     void toggleLayerProperty( LayerItem *layer, const QString &name );
00088     void toggleLayerProperty( int id, const QString &name );
00089 
00090     void setLayerPreviewImage( LayerItem *layer, QImage *image );
00091     void setLayerPreviewImage( int id, QImage *image );
00092 
00093     void layerPreviewChanged( LayerItem *layer );
00094     void layerPreviewChanged( int id );
00095 
00096     LayerItem *addLayer( const QString &displayName, LayerItem *after = 0, int id = -1 );
00097     LayerItem *addLayer( const QString &displayName, int afterID, int id = -1 );
00098 
00099     LayerItem *addLayerToParent( const QString &displayName, LayerItem *parent, LayerItem *after = 0, int id = -1 );
00100     LayerItem *addLayerToParent( const QString &displayName, int parentID, int afterID = -1, int id = -1 );
00101 
00102     void moveLayer( LayerItem *layer, LayerItem *parent, LayerItem *after );
00103     void moveLayer( int id, int parentID, int afterID );
00104 
00105     void removeLayer( LayerItem *layer );
00106     void removeLayer( int id );
00107 
00108 signals:
00109     void activated( LayerItem *layer );
00110     void activated( int id );
00111 
00112     void displayNameChanged( LayerItem *layer, const QString &displayName );
00113     void displayNameChanged( int id, const QString &displayName );
00114 
00115     void propertyChanged( LayerItem *layer, const QString &name, bool on );
00116     void propertyChanged( int id, const QString &name, bool on );
00117 
00118     void layerMoved( LayerItem *layer, LayerItem *parent, LayerItem *after );
00119     void layerMoved( int id, int parentID, int afterID );
00120 
00121     void requestNewLayer( LayerItem *parent, LayerItem *after );
00122     void requestNewLayer( int parentID, int afterID );
00123 
00124     void requestNewFolder( LayerItem *parent, LayerItem *after );
00125     void requestNewFolder( int parentID, int afterID );
00126 
00127     void requestRemoveLayer( LayerItem *layer );
00128     void requestRemoveLayer( int id );
00129 
00130     void requestRemoveLayers( QValueList<LayerItem*> layers );
00131     void requestRemoveLayers( QValueList<int> ids );
00132 
00133     void requestLayerProperties( LayerItem *layer );
00134     void requestLayerProperties( int id );
00135 
00136 public: //convenience
00137     LayerItem *firstChild() const;
00138     LayerItem *lastChild() const;
00139 
00140 protected slots:
00141     virtual void constructMenu( LayerItem *layer );
00142     virtual void menuActivated( int id, LayerItem *layer );
00143 
00144 private:
00145     typedef KListView super;
00146     friend class LayerItem;
00147     friend class LayerToolTIp;
00148 
00149     class Private;
00150     Private* const d;
00151 
00152 private slots:
00153     void slotItemRenamed( QListViewItem *item, const QString &text, int col );
00154     void slotItemMoved( QPtrList<QListViewItem>&, QPtrList<QListViewItem>&, QPtrList<QListViewItem>& );
00155     void showContextMenu();
00156     void hideTip();
00157     void maybeTip();
00158 
00159 public: //reimplemented for internal reasons
00160     virtual void setCurrentItem( QListViewItem *i );
00161 
00162 protected:
00163     virtual void contentsMousePressEvent( QMouseEvent *e );
00164     virtual void contentsMouseDoubleClickEvent ( QMouseEvent *e );
00165     virtual void findDrop( const QPoint &pos, QListViewItem *&parent, QListViewItem *&after );
00166 };
00167 
00168 class LayerItem: public KListViewItem
00169 {
00170 public:
00171     LayerItem( const QString &displayName, LayerList *parent, LayerItem *after = 0, int id = -1 );
00172     LayerItem( const QString &displayName, LayerItem *parent, LayerItem *after = 0, int id = -1 );
00173     virtual ~LayerItem();
00174 
00175     void makeFolder();
00176     bool isFolder() const;
00177 
00178     // Returns true if this item is the given item or the tree rooted at
00179     // this item contains the given item.
00180     bool contains(const LayerItem *item);
00181 
00182     int id() const;
00183 
00184     QString displayName() const;
00185     void setDisplayName( const QString &displayName );
00186 
00187     bool isActive() const;
00188     void setActive();
00189 
00190     bool property( const QString &name ) const;
00191     void setProperty( const QString &name, bool on );
00192     void toggleProperty( const QString &name );
00193 
00194     void setPreviewImage( QImage *image );
00195     void previewChanged();
00196 
00197     LayerItem *addLayer( const QString &displayName, LayerItem *after = 0, int id = -1 );
00198 
00199     LayerItem *prevSibling() const;
00200 
00201 public: //convenience
00202     LayerItem *nextSibling() const;
00203     LayerList *listView() const;
00204     LayerItem *firstChild() const;
00205     LayerItem *parent() const;
00206     void update() const; //like QWidget::update()
00207 
00208 protected:
00209     virtual QRect rect() const;
00210 
00211     int    mapXFromListView( int x ) const;
00212     int    mapYFromListView( int y ) const;
00213     QPoint mapFromListView( const QPoint &point ) const;
00214     QRect  mapFromListView( const QRect &rect ) const;
00215 
00216     int    mapXToListView( int x ) const;
00217     int    mapYToListView( int y ) const;
00218     QPoint mapToListView( const QPoint &point ) const;
00219     QRect  mapToListView( const QRect &rect ) const;
00220 
00221     virtual QRect textRect() const;
00222     virtual QRect iconsRect() const;
00223     virtual QRect previewRect() const;
00224 
00225     virtual void drawText( QPainter *p, const QColorGroup &cg, const QRect &r );
00226     virtual void drawIcons( QPainter *p, const QColorGroup &cg, const QRect &r );
00227     virtual void drawPreview( QPainter *p, const QColorGroup &cg, const QRect &r );
00228 
00229     bool multiline() const;
00230     bool showPreview() const;
00231     virtual QFont font() const;
00232     QFontMetrics fontMetrics() const;
00233 
00234     virtual bool mousePressEvent( QMouseEvent *e );
00235 
00236     virtual QString tooltip() const;
00237 
00238     virtual QImage *previewImage() const;
00239     virtual QImage tooltipPreview() const;
00240 
00241 private:
00242     typedef KListViewItem super;
00243     friend class LayerList;
00244     friend class LayerToolTip;
00245 
00246     class Private;
00247     Private* const d;
00248 
00249     void init();
00250 
00251 public: //reimplemented for internal reasons
00252     virtual int width( const QFontMetrics &fm, const QListView *lv, int c ) const;
00253     virtual void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align );
00254     virtual void setup();
00255     virtual void setSelected( bool selected );
00256 };
00257 
00258 class LayerFolder: public LayerItem
00259 {
00260 public:
00261     LayerFolder( const QString &displayName, LayerList *parent, LayerItem *after = 0, int id = -1 )
00262         : LayerItem( displayName, parent, after, id ) { makeFolder(); }
00263     LayerFolder( const QString &displayName, LayerItem *parent, LayerItem *after = 0, int id = -1 )
00264         : LayerItem( displayName, parent, after, id ) { makeFolder(); }
00265 };
00266 
00267 
00268 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys