Back to index

kdeartwork  4.3.2
icewm.h
Go to the documentation of this file.
00001 /*
00002   $Id: icewm.h 474856 2005-10-27 12:44:04Z mlaurent $
00003 
00004   Gallium-IceWM themeable KWin client
00005 
00006   Copyright 2001
00007        Karol Szwed <gallium@kde.org>
00008        http://gallium.n3.net/
00009 
00010   This program is free software; you can redistribute it and/or
00011   modify it under the terms of the GNU General Public
00012   License as published by the Free Software Foundation; either
00013   version 2 of the License, or (at your option) any later version.
00014 
00015   This program is distributed in the hope that it will be useful,
00016   but WITHOUT ANY WARRANTY; without even the implied warranty of
00017   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018   General Public License for more details.
00019 
00020   You should have received a copy of the GNU General Public License
00021   along with this program; see the file COPYING.  If not, write to
00022   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00023   Boston, MA 02110-1301, USA.
00024 
00025   -----------------------------------------------------------------------------
00026   This client loads most icewm 1.0.X pixmap themes, without taking into account
00027   specific font settings for clients, or coloured mouse cursors. Titlebar
00028   fonts can be changed via the kde control center. Bi-colour mouse cursors
00029   may be added in future if requested by users, as well as theme font support.
00030   Any styles using inbuilt icewm titlebar drawing without using pixmaps (e.g.
00031   Warp4, win95 etc.) are not fully supported, and may cause drawing errors,
00032   as these themes use in-built icewm drawing mechanisms.
00033 
00034   When a pixmap theme is not present (or a corrupt one is present) then very
00035   plain title decorations are painted instead, so that users don't see
00036   non-painted window areas where possible ;)
00037 
00038   At a later date, frame shaping may be added if really requested, and an
00039   update to support the latest icewm 1.1.X theme format may be made.
00040 */
00041 
00042 #ifndef __KDEGALLIUM_ICEWM_H
00043 #define __KDEGALLIUM_ICEWM_H
00044 
00045 #include <q3button.h>
00046 #include <qlayout.h>
00047 //Added by qt3to4:
00048 #include <QPixmap>
00049 #include <QPaintEvent>
00050 #include <QGridLayout>
00051 #include <QEvent>
00052 #include <QBoxLayout>
00053 #include <QLabel>
00054 #include <QShowEvent>
00055 #include <QResizeEvent>
00056 #include <QMouseEvent>
00057 #include <kpixmap.h>
00058 #include <kdecoration.h>
00059 #include <kdecorationfactory.h>
00060 #include <kcommondecoration.h>
00061 #include <q3button.h>
00062 class QLabel;
00063 class QSpacerItem;
00064 class QBoxLayout;
00065 class QGridLayout;
00066 
00067 namespace IceWM {
00068 
00069 class IceWMClient;
00070 
00071 // Pixmap group
00072 enum { InActive=0, Active };
00073 // Pixmap stretching mode
00074 enum { Qt::Vertical=0, Qt::Horizontal=1 };
00075 
00076 
00077 // Handles the resetClients() signal from the Options class,
00078 // and manages the dynamic pixmaps, configuration and theme changing
00079 class ThemeHandler: public KDecorationFactory
00080 {
00081        public:
00082               ThemeHandler();
00083               ~ThemeHandler();
00084 
00085               virtual KDecoration* createDecoration( KDecorationBridge* );
00086               virtual bool reset( unsigned long changed );
00087               virtual bool supports( Ability ability );
00088 
00089        private:
00090               bool initialized;
00091               QString themeName;
00092 
00093               void readConfig();
00094               QColor decodeColor( QString& s );
00095               bool isFrameValid();
00096               void initTheme();
00097               void freePixmaps();
00098               void freePixmapGroup( QPixmap* p[] );
00099               void setPixmap( QPixmap* p[], QString s1, QString s2, bool
00100                                           stretch=false, bool stretchHoriz=true );
00101               void setPixmapButton( QPixmap* p[], QString s1, QString s2);
00102               QPixmap* stretchPixmap( QPixmap* src, bool stretchHoriz=true,
00103                                                         int stretchSize=-1);
00104               QPixmap* duplicateValidPixmap( bool act, int size = -1 );
00105               void convertButtons( QString& s );
00106               QString reverseString( QString s );
00107 };
00108 
00109 
00110 class IceWMButton : public Q3Button
00111 {
00112        public:
00113               IceWMButton( IceWMClient *parent=0, const char *name=0,
00114                                     QPixmap* (*p)[2]=0L, bool isToggle=false,
00115                                     const QString& tip=NULL, const int realizeBtns = Qt::LeftButton );
00116               void setTipText(const QString &tip);
00117               void  usePixmap( QPixmap* (*p)[2] );
00118               QSize sizeHint() const;
00119               void  turnOn( bool isOn );
00120               ButtonState   last_button;
00121 
00122        protected:
00123               void mousePressEvent( QMouseEvent* e );
00124               void mouseReleaseEvent( QMouseEvent* e );
00125 
00126               void drawButton( QPainter *p );
00127               void drawButtonLabel( QPainter * ) {;}
00128 
00129        private:
00130               int m_realizeButtons;
00131               IceWMClient* client;
00132               QPixmap* (*pix)[2]; // Points to active/inactive pixmap array
00133 };
00134 
00135 
00136 class IceWMClient : public KDecoration
00137 {
00138     Q_OBJECT
00139        public:
00140            IceWMClient( KDecorationBridge* bridge, KDecorationFactory* factory );
00141            ~IceWMClient();
00142 
00143               virtual void init();
00144               virtual void resize(const QSize&);
00145               virtual bool eventFilter( QObject* o, QEvent* e );
00146 
00147        protected:
00148            void resizeEvent( QResizeEvent* );
00149            void paintEvent( QPaintEvent* );
00150            void showEvent( QShowEvent* );
00151            void mouseDoubleClickEvent( QMouseEvent * );
00152            virtual void captionChange();
00153            virtual void maximizeChange();
00154            virtual void shadeChange();
00155            virtual void activeChange();
00156        //     void shadeChange(bool);     /* KWin Client class doesn't provide this yet */
00157            Position mousePosition( const QPoint& ) const;
00158               void renderMenuIcons();
00159               void iconChange();
00160               virtual void desktopChange( );
00161               virtual void borders(int&, int&, int&, int&) const;
00162               virtual QSize minimumSize() const;
00163 
00164        protected slots:
00165            void slotMaximize();
00166            void menuButtonPressed();
00167            void menuButtonReleased();
00168            void toggleShade();
00169 
00170        private:
00171            // These are all the icewm button types :)
00172            enum Buttons{ BtnSysMenu=0, BtnClose, BtnMaximize, BtnMinimize,
00173                                      BtnHide, BtnRollup, BtnDepth, BtnCount };
00174 
00175               QString shortenCaption( const QString* s );
00176               void calcHiddenButtons();
00177            int  titleTextWidth( const QString& s );
00178               void addClientButtons( const QString& s );
00179               QSpacerItem* addPixmapSpacer( QPixmap* p[],
00180                      QSizePolicy::SizeType = QSizePolicy::Maximum, int hsize = -1 );
00181 
00182            IceWMButton* button[ IceWMClient::BtnCount ];
00183            QPixmap*     menuButtonWithIconPix[2];
00184            QSpacerItem* titleSpacerJ;
00185            QSpacerItem* titleSpacerL;
00186            QSpacerItem* titleSpacerS;
00187            QSpacerItem* titleSpacerP;
00188            QSpacerItem* titlebar;
00189            QSpacerItem* titleSpacerM;
00190            QSpacerItem* titleSpacerB;
00191        QSpacerItem* titleSpacerR;
00192            QSpacerItem* titleSpacerQ;
00193            QBoxLayout*  hb;
00194            QGridLayout* grid;
00195            bool m_closing;
00196 };
00197 
00198 }
00199 
00200 #endif
00201 
00202 // vim: ts=4