kcommondecoration.h

00001 /*
00002   This file is part of the KDE project.
00003 
00004   Copyright (C) 2005 Sandro Giessl <sandro@giessl.com>
00005 
00006   Permission is hereby granted, free of charge, to any person obtaining a
00007   copy of this software and associated documentation files (the "Software"),
00008   to deal in the Software without restriction, including without limitation
00009   the rights to use, copy, modify, merge, publish, distribute, sublicense,
00010   and/or sell copies of the Software, and to permit persons to whom the
00011   Software is furnished to do so, subject to the following conditions:
00012 
00013   The above copyright notice and this permission notice shall be included in
00014   all copies or substantial portions of the Software.
00015 
00016   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00019   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00021   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00022   DEALINGS IN THE SOFTWARE.
00023  */
00024 
00025 #ifndef KCOMMONDECORATION_H
00026 #define KCOMMONDECORATION_H
00027 
00028 #include <qbutton.h>
00029 #include <qvaluevector.h>
00030 
00031 #include "kdecoration.h"
00032 
00033 class KDecorationBridge;
00034 class KDecorationFactory;
00035 
00036 enum ButtonType {
00037     HelpButton=0,
00038     MaxButton,
00039     MinButton,
00040     CloseButton,
00041     MenuButton,
00042     OnAllDesktopsButton,
00043     AboveButton,
00044     BelowButton,
00045     ShadeButton,
00046     NumButtons
00047 };
00048 
00049 class KCommonDecorationButton;
00050 
00051 class KCommonDecorationButtonPrivate;
00052 class KCommonDecorationPrivate;
00053 
00059 class KWIN_EXPORT KCommonDecoration : public KDecoration
00060 {
00061     Q_OBJECT
00062 
00063     public:
00064         KCommonDecoration(KDecorationBridge* bridge, KDecorationFactory* factory);
00065         virtual ~KCommonDecoration();
00066 
00100         enum LayoutMetric
00101         {
00102             LM_BorderLeft,
00103             LM_BorderRight,
00104             LM_BorderBottom,
00105             LM_TitleHeight,
00106             LM_TitleBorderLeft,
00107             LM_TitleBorderRight,
00108             LM_TitleEdgeLeft,
00109             LM_TitleEdgeRight,
00110             LM_TitleEdgeTop,
00111             LM_TitleEdgeBottom,
00112             LM_ButtonWidth,
00113             LM_ButtonHeight,
00114             LM_ButtonSpacing,
00115             LM_ExplicitButtonSpacer,
00116             LM_ButtonMarginTop
00117         };
00118 
00119         enum DecorationBehaviour
00120         {
00121             DB_MenuClose, 
00122             DB_WindowMask, 
00123             DB_ButtonHide  
00124         };
00125 
00126         enum WindowCorner
00127         {
00128             WC_TopLeft,
00129             WC_TopRight,
00130             WC_BottomLeft,
00131             WC_BottomRight
00132         };
00133 
00137         virtual QString visibleName() const = 0;
00143         virtual QString defaultButtonsLeft() const = 0;
00149         virtual QString defaultButtonsRight() const = 0;
00150 
00155         virtual bool decorationBehaviour(DecorationBehaviour behaviour) const;
00156 
00164         virtual int layoutMetric(LayoutMetric lm, bool respectWindowState = true, const KCommonDecorationButton *button = 0) const;
00165 
00170         virtual KCommonDecorationButton *createButton(ButtonType type) = 0;
00171 
00175         virtual QRegion cornerShape(WindowCorner corner);
00176 
00184         virtual void updateWindowShape();
00185 
00189         virtual void paintEvent(QPaintEvent *e) = 0;
00190 
00195         virtual void updateCaption();
00196 
00197         int buttonsLeftWidth() const;
00198         int buttonsRightWidth() const;
00199 
00203         void updateLayout() const;
00207         void updateButtons() const;
00211         void resetButtons() const;
00212 
00217         bool isToolWindow() const;
00222          QRect titleRect() const;
00223 
00224     public:
00228         virtual void init();
00232         virtual void reset( unsigned long changed );
00233         virtual void borders( int& left, int& right, int& top, int& bottom ) const;
00234         virtual void show();
00235         virtual void resize(const QSize& s);
00236         virtual QSize minimumSize() const;
00237         virtual void maximizeChange();
00238         virtual void desktopChange();
00239         virtual void shadeChange();
00240         virtual void iconChange();
00241         virtual void activeChange();
00242         virtual void captionChange();
00243     public slots:
00244         void keepAboveChange(bool above);
00245         void keepBelowChange(bool below);
00246         void slotMaximize();
00247         void slotShade();
00248         void slotKeepAbove();
00249         void slotKeepBelow();
00250         void menuButtonPressed();
00251         void menuButtonReleased();
00252     public:
00253         virtual Position mousePosition(const QPoint &point) const;
00254 
00255         virtual bool eventFilter( QObject* o, QEvent* e );
00256         virtual void resizeEvent(QResizeEvent *e);
00257         virtual void mouseDoubleClickEvent(QMouseEvent *e);
00258         virtual void wheelEvent(QWheelEvent *e);
00259 
00260     private:
00261         void resetLayout();
00262 
00263         void moveWidget(int x, int y, QWidget *widget) const;
00264         void resizeWidget(int w, int h, QWidget *widget) const;
00265 
00266         typedef QValueVector <KCommonDecorationButton*> ButtonContainer; 
00267         int buttonContainerWidth(const ButtonContainer &btnContainer, bool countHidden = false) const;
00268         void addButtons(ButtonContainer &btnContainer, const QString& buttons, bool isLeft);
00269 
00270         KCommonDecorationButton *m_button[NumButtons];
00271 
00272         ButtonContainer m_buttonsLeft;
00273         ButtonContainer m_buttonsRight;
00274 
00275         QWidget *m_previewWidget;
00276 
00277         // button hiding for small windows
00278         void calcHiddenButtons();
00279         int btnHideMinWidth;
00280         int btnHideLastWidth;
00281 
00282         bool closing; // for menu doubleclick closing...
00283 
00284         KCommonDecorationPrivate *d;
00285 };
00286 
00290 class KWIN_EXPORT KCommonDecorationButton : public QButton
00291 {
00292     friend class KCommonDecoration;
00293 
00294     public:
00295         KCommonDecorationButton(ButtonType type, KCommonDecoration *parent, const char *name);
00296         virtual ~KCommonDecorationButton();
00297 
00301         enum
00302         {
00303             ManualReset     = 1 << 0, 
00304             SizeChange      = 1 << 1, 
00305             ToggleChange    = 1 << 2, 
00306             StateChange     = 1 << 3, 
00307             IconChange      = 1 << 4, 
00308             DecorationReset = 1 << 5  
00309         };
00313         virtual void reset(unsigned long changed) = 0;
00317         KCommonDecoration *decoration() const;
00322         ButtonType type() const;
00323 
00327         bool isLeft() const;
00328 
00332         void setRealizeButtons(int btns);
00336         void setSize(const QSize &s);
00340         void setTipText(const QString &tip);
00344         ButtonState lastMousePress() const { return m_lastMouse; }
00345 
00346         QSize sizeHint() const;
00347 
00348     protected:
00349         void setToggleButton(bool toggle);
00350         void setOn(bool on);
00351         void setLeft(bool left);
00352         void mousePressEvent(QMouseEvent *e);
00353         void mouseReleaseEvent(QMouseEvent *e);
00354 
00355     private:
00356         KCommonDecoration *m_decoration;
00357         ButtonType m_type;
00358         int m_realizeButtons;
00359         QSize m_size;
00360         ButtonState m_lastMouse;
00361 
00362         bool m_isLeft;
00363 
00364         KCommonDecorationButtonPrivate *d;
00365 };
00366 
00367 #endif // KCOMMONDECORATION_H
KDE Home | KDE Accessibility Home | Description of Access Keys