lib Library API Documentation

kotoolbutton.h

00001 /* This file is part of the KDE project 00002 Copyright (C) 2002 Werner Trobin <trobin@kde.org> 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., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #ifndef _kotoolbutton_h_ 00021 #define _kotoolbutton_h_ 00022 00023 #include <ktoolbarbutton.h> 00024 #include <qmap.h> 00025 #include <qpoint.h> 00026 00027 class QPopupMenu; 00028 00029 class KoColorPanel : public QWidget 00030 { 00031 Q_OBJECT 00032 public: 00033 KoColorPanel( QWidget* parent = 0, const char* name = 0 ); 00034 virtual ~KoColorPanel(); 00035 00036 virtual QSize sizeHint() const; 00037 virtual QSize minimumSizeHint() const; 00038 00039 enum MenuStyle { Plain, CustomColors }; 00040 static QPopupMenu* createColorPopup( MenuStyle style, const QColor& defaultColor, 00041 const QObject* receiver, const char* slot, 00042 QWidget* parent, const char* name ); 00043 00044 public slots: 00045 void clear(); 00046 void insertColor( const QColor& color ); 00047 void insertColor( const QColor& color, const QString& toolTip ); 00048 void insertDefaultColors(); 00049 00050 signals: 00051 void colorSelected( const QColor& color ); 00052 00053 protected: 00054 virtual void mousePressEvent( QMouseEvent* e ); 00055 virtual void mouseReleaseEvent( QMouseEvent* e ); 00056 virtual void mouseMoveEvent( QMouseEvent* e ); 00057 virtual void paintEvent( QPaintEvent* e ); 00058 virtual void keyPressEvent( QKeyEvent* e ); 00059 virtual void focusInEvent( QFocusEvent* e ); 00060 virtual void dragEnterEvent( QDragEnterEvent* e ); 00061 virtual void dropEvent( QDropEvent* e ); 00062 00063 private: 00064 // The position of the 16x16 tiles in "tile steps" 00065 struct Position { 00066 Position() : x( -1 ), y( -1 ) {} 00067 Position( short x_, short y_ ) : x( x_ ), y( y_ ) {} 00068 00069 short x; 00070 short y; 00071 }; 00072 friend bool operator<( const KoColorPanel::Position& lhs, const KoColorPanel::Position& rhs ); 00073 00074 void finalizeInsertion( const Position& pos ); 00075 bool insertColor( const QColor& color, bool checking ); 00076 bool insertColor( const QColor& color, const QString& toolTip, bool checking ); 00077 bool isAvailable( const QColor& color ); 00078 00079 Position mapToPosition( const QPoint& point ) const; 00080 QColor mapToColor( const QPoint& point ) const; 00081 QColor mapToColor( const Position& position ) const; 00082 QRect mapFromPosition( const Position& position ) const; 00083 Position validPosition( const Position& position ); 00084 00085 int lines() const; 00086 void paintArea( const QRect& rect, int& startRow, int& endRow, int& startCol, int& endCol ) const; 00087 void updateFocusPosition( const Position& newPosition ); 00088 void paint( const Position& position ); 00089 void init(); 00090 00091 Position m_nextPosition, m_focusPosition; 00092 QMap<Position, QColor> m_colorMap; 00093 QPoint m_pressedPos; 00094 bool m_defaultsAdded; 00095 }; 00096 00097 // Needed for the use of KoColorPanel::Position in QMap 00098 bool operator<( const KoColorPanel::Position& lhs, const KoColorPanel::Position& rhs ); 00099 00100 00101 // A tiny class needed to emit the correct signal when the default 00102 // color item in the color-panel popup is activated. Additionally 00103 // it's used to provide the color select dialog and manages the recent 00104 // colors... hacky 00105 class KoColorPopupProxy : public QObject 00106 { 00107 Q_OBJECT 00108 public: 00109 KoColorPopupProxy( const QColor& defaultColor, KoColorPanel* recentColors, QObject* parent, const char* name ); 00110 virtual ~KoColorPopupProxy() {} 00111 00112 void setRecentColorPanel( KoColorPanel* recentColors ); 00113 00114 public slots: 00115 void slotDefaultColor(); 00116 void slotMoreColors(); 00117 00118 signals: 00119 void colorSelected( const QColor& color ); 00120 00121 private: 00122 QColor m_defaultColor; 00123 KoColorPanel* m_recentColors; 00124 }; 00125 00126 00127 // Parts of the code are from KToolBarButton 00128 class KoToolButton : public KToolBarButton 00129 { 00130 Q_OBJECT 00131 public: 00143 KoToolButton( const QString& icon, int id, QWidget* parent, 00144 const char* name = 0L, const QString& txt = QString::null, 00145 KInstance* _instance = KGlobal::instance() ); 00146 00158 KoToolButton( const QPixmap& pixmap, int id, QWidget* parent, 00159 const char* name = 0L, const QString& txt = QString::null ); 00160 00161 virtual ~KoToolButton(); 00162 00163 virtual QSize sizeHint() const; 00164 virtual QSize minimumSizeHint() const; 00165 virtual QSize minimumSize() const; 00166 00167 public slots: 00168 void colorSelected( const QColor& color ); 00169 00170 protected: 00171 virtual void drawButton(QPainter *p); 00172 virtual bool eventFilter( QObject* o, QEvent* e ); 00173 00174 private: 00175 void init(); 00176 void buttonShift( int& dx, int& dy ); 00177 bool hitArrow( const QPoint& pos ); 00178 00179 QPopupMenu* m_popup; 00180 bool m_arrowPressed; 00181 }; 00182 00183 #endif // _kotoolbutton_h_
KDE Logo
This file is part of the documentation for lib Library Version 1.3.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Sep 28 04:04:02 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003