lib

tkcoloractions.h

00001 /*
00002  * Kivio - Visual Modelling and Flowcharting
00003  * Copyright (C) 2000 theKompany.com
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef TKCOLORACTION_H
00022 #define TKCOLORACTION_H
00023 
00024 #include "tkaction.h"
00025 #include <koffice_export.h>
00026 #include <kpopupmenu.h>
00027 #include <qdict.h>
00028 
00029 class QGridLayout;
00030 class TKColorPanel;
00031 class TKSelectColorActionPrivate;
00032 
00033 class TKColorPopupMenu : public KPopupMenu
00034 { Q_OBJECT
00035 public:
00036   TKColorPopupMenu( QWidget* parent = 0, const char* name = 0 );
00037   ~TKColorPopupMenu();
00038 
00039 public slots:
00040   void updateItemSize();
00041 };
00042 /****************************************************************************************/
00043 class KOFFICEUI_EXPORT TKSelectColorAction : public TKAction
00044 { Q_OBJECT
00045 public:
00046   enum Type {
00047     TextColor,
00048     LineColor,
00049     FillColor,
00050     Color
00051   };
00052 
00053   TKSelectColorAction( const QString& text, Type type, QObject* parent, const char* name, bool menuDefaultColor=false);
00054   TKSelectColorAction( const QString& text, Type type,
00055                        QObject* receiver, const char* slot,
00056                        QObject* parent, const char* name,bool menuDefaultColor=false );
00057 
00058   virtual ~TKSelectColorAction();
00059 
00060   QColor color() const { return m_pCurrentColor; }
00061 
00062   KPopupMenu* popupMenu() const { return m_pMenu; }
00063   void setDefaultColor(const QColor &_col);
00064 
00065 
00066 public slots:
00067   void setCurrentColor( const QColor& );
00068   void setActiveColor( const QColor& );
00069   virtual void activate();
00070 
00071 signals:
00072   void colorSelected( const QColor& );
00073 
00074 protected slots:
00075   void selectColorDialog();
00076   void panelColorSelected( const QColor& );
00077   void panelReject();
00078   virtual void slotActivated();
00079   void defaultColor();
00080 
00081 protected:
00082   void init();
00083   virtual void initToolBarButton(TKToolBarButton*);
00084   void updatePixmap();
00085   void updatePixmap(TKToolBarButton*);
00086 
00087 protected:
00088   TKColorPopupMenu* m_pMenu;
00089   TKColorPanel* m_pStandardColor;
00090   TKColorPanel* m_pRecentColor;
00091   int m_type;
00092 
00093   QColor m_pCurrentColor;
00094 
00095 private:
00096   TKSelectColorActionPrivate *d;
00097 };
00098 /****************************************************************************************/
00099 class TKColorPanelButton : public QFrame
00100 { Q_OBJECT
00101 public:
00102   TKColorPanelButton( const QColor&, QWidget* parent, const char* name = 0 );
00103   ~TKColorPanelButton();
00104 
00105   void setActive( bool );
00106 
00107   QColor panelColor() const { return m_Color; }
00108 
00109 signals:
00110   void selected( const QColor& );
00111 
00112 protected:
00113   virtual void paintEvent( QPaintEvent* );
00114   virtual void enterEvent( QEvent* );
00115   virtual void leaveEvent( QEvent* );
00116   virtual void mouseReleaseEvent( QMouseEvent* );
00117 
00118   QColor m_Color;
00119   bool m_bActive;
00120 
00121 private:
00122   class TKColorPanelButtonPrivate;
00123   TKColorPanelButtonPrivate *d;
00124 };
00125 /****************************************************************************************/
00126 class TKColorPanel : public QWidget
00127 { Q_OBJECT
00128 
00129 public:
00130   TKColorPanel( QWidget* parent = 0L, const char* name = 0 );
00131   ~TKColorPanel();
00132 
00133   void setActiveColor( const QColor& );
00134   void setNumCols( int col );
00135   void clear();
00136 
00137 public slots:
00138   void insertColor( const QColor& );
00139   void insertColor( const QColor&, const QString& );
00140   void selected( const QColor& );
00141 
00142 signals:
00143   void colorSelected( const QColor& );
00144   void reject();
00145   void sizeChanged();
00146 
00147 protected:
00148   void addToGrid( TKColorPanelButton* );
00149   void resetGrid();
00150 
00151   virtual void mouseReleaseEvent( QMouseEvent* );
00152   virtual void showEvent( QShowEvent *e );
00153 
00154   QGridLayout* m_pLayout;
00155   int m_iWidth;
00156   int m_iX;
00157   int m_iY;
00158 
00159   QColor m_activeColor;
00160   QDict<TKColorPanelButton> m_pColorDict;
00161 
00162 private:
00163   void fillPanel();
00164 
00165   class TKColorPanelPrivate;
00166   TKColorPanelPrivate *d;
00167 };
00168 
00169 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys