kwin Library API Documentation

buttons.h

00001 /*
00002     This is the new kwindecoration kcontrol module
00003 
00004     Copyright (c) 2004, Sandro Giessl <sandro@giessl.com>
00005     Copyright (c) 2001
00006         Karol Szwed <gallium@kde.org>
00007         http://gallium.n3.net/
00008 
00009     Supports new kwin configuration plugins, and titlebar button position
00010     modification via dnd interface.
00011 
00012     Based on original "kwintheme" (Window Borders) 
00013     Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
00014 
00015     This program is free software; you can redistribute it and/or modify
00016     it under the terms of the GNU General Public License as published by
00017     the Free Software Foundation; either version 2 of the License, or
00018     (at your option) any later version.
00019   
00020     This program is distributed in the hope that it will be useful,
00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023     GNU General Public License for more details.
00024   
00025     You should have received a copy of the GNU General Public License
00026     along with this program; if not, write to the Free Software
00027     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00028 
00029 */
00030 
00031 #ifndef __BUTTONS_H_
00032 #define __BUTTONS_H_
00033 
00034 #include <qbitmap.h>
00035 #include <qevent.h>
00036 #include <qdragobject.h>
00037 #include <qlistbox.h>
00038 
00039 #include <klistview.h>
00040 
00041 class KDecorationFactory;
00042 
00046 class Button
00047 {
00048     public:
00049         Button();
00050         Button(const QString& name, const QBitmap& icon, QChar type, bool duplicate, bool supported);
00051         virtual ~Button();
00052 
00053         QString name;
00054         QBitmap icon;
00055         QChar type;
00056         bool duplicate;
00057         bool supported;
00058 };
00059 
00060 class ButtonDrag : public QStoredDrag
00061 {
00062     public:
00063         ButtonDrag( Button btn, QWidget* parent, const char* name=0 );
00064         ~ButtonDrag() {};
00065 
00066         static bool canDecode( QDropEvent* e );
00067         static bool decode( QDropEvent* e, Button& btn );
00068 };
00069 
00073 class ButtonDropSiteItem
00074 {
00075     public:
00076         ButtonDropSiteItem(const Button& btn);
00077         ~ButtonDropSiteItem();
00078     
00079         Button button();
00080 
00081         QRect rect;
00082         int width();
00083         int height();
00084 
00085         void draw(QPainter *p, const QColorGroup& cg, QRect rect);
00086 
00087     private:
00088         Button m_button;
00089 };
00090 
00094 class ButtonSourceItem : public QListViewItem
00095 {
00096     public:
00097         ButtonSourceItem(QListView * parent, const Button& btn);
00098         virtual ~ButtonSourceItem();
00099 
00100         void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align);
00101 
00102         void setButton(const Button& btn);
00103         Button button() const;
00104     private:
00105         Button m_button;
00106         bool m_dirty;
00107 };
00108 
00112 class ButtonSource : public KListView
00113 {
00114     Q_OBJECT
00115 
00116     public:
00117         ButtonSource(QWidget *parent = 0, const char* name = 0);
00118         virtual ~ButtonSource();
00119 
00120         QSize sizeHint() const;
00121 
00122         void hideAllButtons();
00123         void showAllButtons();
00124 
00125     public slots:
00126         void hideButton(QChar btn);
00127         void showButton(QChar btn);
00128 
00129     protected:
00130         bool acceptDrag(QDropEvent* e) const;
00131         virtual QDragObject *dragObject();
00132 };
00133 
00134 typedef QValueList<ButtonDropSiteItem*> ButtonList;
00135 
00139 class ButtonDropSite: public QFrame
00140 {
00141     Q_OBJECT
00142 
00143     public:
00144         ButtonDropSite( QWidget* parent=0, const char* name=0 );
00145         ~ButtonDropSite();
00146 
00147         // Allow external classes access our buttons - ensure buttons are
00148         // not duplicated however.
00149         ButtonList buttonsLeft;
00150         ButtonList buttonsRight;
00151         void clearLeft();
00152         void clearRight();
00153 
00154     signals:
00155         void buttonAdded(QChar btn);
00156         void buttonRemoved(QChar btn);
00157         void changed();
00158 
00159     public slots:
00160         bool removeSelectedButton(); 
00161         void recalcItemGeometry(); 
00162 
00163     protected:
00164         void resizeEvent(QResizeEvent*);
00165         void dragEnterEvent( QDragEnterEvent* e );
00166         void dragMoveEvent( QDragMoveEvent* e );
00167         void dragLeaveEvent( QDragLeaveEvent* e );
00168         void dropEvent( QDropEvent* e );
00169         void mousePressEvent( QMouseEvent* e ); 
00170 
00171         void drawContents( QPainter* p );
00172         ButtonDropSiteItem *buttonAt(QPoint p);
00173         bool removeButton(ButtonDropSiteItem *item);
00174         int calcButtonListWidth(const ButtonList& buttons); 
00175         void drawButtonList(QPainter *p, const ButtonList& buttons, int offset);
00176 
00177         QRect leftDropArea();
00178         QRect rightDropArea();
00179 
00180     private:
00184         bool getItemIterator(ButtonDropSiteItem *item, ButtonList* &list, ButtonList::iterator &iterator);
00185 
00186         void cleanDropVisualizer();
00187         QRect m_oldDropVisualizer;
00188 
00189         ButtonDropSiteItem *m_selected;
00190 };
00191 
00192 class ButtonPositionWidget : public QWidget
00193 {
00194     Q_OBJECT
00195 
00196     public:
00197         ButtonPositionWidget(QWidget *parent = 0, const char* name = 0);
00198         ~ButtonPositionWidget();
00199 
00203         void setDecorationFactory(KDecorationFactory *factory);
00204 
00205         QString buttonsLeft() const;
00206         QString buttonsRight() const;
00207         void setButtonsLeft(const QString &buttons);
00208         void setButtonsRight(const QString &buttons);
00209 
00210     signals:
00211         void changed();
00212 
00213     private:
00214         void clearButtonList(const ButtonList& btns);
00215         Button getButton(QChar type, bool& success);
00216 
00217         ButtonDropSite* m_dropSite;
00218         ButtonSource *m_buttonSource;
00219 
00220         KDecorationFactory *m_factory;
00221         QString m_supportedButtons;
00222 };
00223 
00224 
00225 #endif
00226 // vim: ts=4
00227 // kate: space-indent off; tab-width 4;
KDE Logo
This file is part of the documentation for kwin Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Nov 4 00:45:25 2005 by doxygen 1.4.0 written by Dimitri van Heesch, © 1997-2003