00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _kotoolbutton_h_
00021 #define _kotoolbutton_h_
00022
00023
00024 #include <QMap>
00025 #include <QPoint>
00026 #include <kinstance.h>
00027
00028 #include <QPixmap>
00029 #include <QFocusEvent>
00030 #include <QPaintEvent>
00031 #include <QKeyEvent>
00032 #include <QEvent>
00033 #include <QDropEvent>
00034 #include <Q3PopupMenu>
00035 #include <QDragEnterEvent>
00036 #include <QMouseEvent>
00037
00038 class Q3PopupMenu;
00039
00040 class KoColorPanel : public QWidget
00041 {
00042 Q_OBJECT
00043 public:
00044 KoColorPanel( QWidget* parent = 0, const char* name = 0 );
00045 virtual ~KoColorPanel();
00046
00047 virtual QSize sizeHint() const;
00048 virtual QSize minimumSizeHint() const;
00049
00050 enum MenuStyle { Plain, CustomColors };
00051 static Q3PopupMenu* createColorPopup( MenuStyle style, const QColor& defaultColor,
00052 const QObject* receiver, const char* slot,
00053 QWidget* parent, const char* name );
00054
00055 public slots:
00056 void clear();
00057 void insertColor( const QColor& color );
00058 void insertColor( const QColor& color, const QString& toolTip );
00059 void insertDefaultColors();
00060
00061 signals:
00062 void colorSelected( const QColor& color );
00063
00064 protected:
00065 virtual void mousePressEvent( QMouseEvent* e );
00066 virtual void mouseReleaseEvent( QMouseEvent* e );
00067 virtual void mouseMoveEvent( QMouseEvent* e );
00068 virtual void paintEvent( QPaintEvent* e );
00069 virtual void keyPressEvent( QKeyEvent* e );
00070 virtual void focusInEvent( QFocusEvent* e );
00071 virtual void dragEnterEvent( QDragEnterEvent* e );
00072 virtual void dropEvent( QDropEvent* e );
00073
00074 private:
00075
00076 struct Position {
00077 Position() : x( -1 ), y( -1 ) {}
00078 Position( short x_, short y_ ) : x( x_ ), y( y_ ) {}
00079
00080 short x;
00081 short y;
00082 };
00083 friend bool operator<( const KoColorPanel::Position& lhs, const KoColorPanel::Position& rhs );
00084
00085 void finalizeInsertion( const Position& pos );
00086 bool insertColor( const QColor& color, bool checking );
00087 bool insertColor( const QColor& color, const QString& toolTip, bool checking );
00088 bool isAvailable( const QColor& color );
00089
00090 Position mapToPosition( const QPoint& point ) const;
00091 QColor mapToColor( const QPoint& point ) const;
00092 QColor mapToColor( const Position& position ) const;
00093 QRect mapFromPosition( const Position& position ) const;
00094 Position validPosition( const Position& position );
00095
00096 int lines() const;
00097 void paintArea( const QRect& rect, int& startRow, int& endRow, int& startCol, int& endCol ) const;
00098 void updateFocusPosition( const Position& newPosition );
00099 void paint( const Position& position );
00100 void init();
00101
00102 Position m_nextPosition, m_focusPosition;
00103 QMap<Position, QColor> m_colorMap;
00104 QPoint m_pressedPos;
00105 bool m_defaultsAdded;
00106 };
00107
00108
00109 bool operator<( const KoColorPanel::Position& lhs, const KoColorPanel::Position& rhs );
00110
00111
00112
00113
00114
00115
00116 class KoColorPopupProxy : public QObject
00117 {
00118 Q_OBJECT
00119 public:
00120 KoColorPopupProxy( const QColor& defaultColor, KoColorPanel* recentColors, QObject* parent, const char* name );
00121 virtual ~KoColorPopupProxy() {}
00122
00123 void setRecentColorPanel( KoColorPanel* recentColors );
00124
00125 public slots:
00126 void slotDefaultColor();
00127 void slotMoreColors();
00128
00129 signals:
00130 void colorSelected( const QColor& color );
00131
00132 private:
00133 QColor m_defaultColor;
00134 KoColorPanel* m_recentColors;
00135 };
00136
00137
00138
00139 class KoToolButton : public KToolBarButton
00140 {
00141 Q_OBJECT
00142 public:
00154 KoToolButton( const QString& icon, int id, QWidget* parent,
00155 const char* name = 0L, const QString& txt = QString::null,
00156 KInstance* _instance = KGlobal::instance() );
00157
00169 KoToolButton( const QPixmap& pixmap, int id, QWidget* parent,
00170 const char* name = 0L, const QString& txt = QString::null );
00171
00172 virtual ~KoToolButton();
00173
00174 virtual QSize sizeHint() const;
00175 virtual QSize minimumSizeHint() const;
00176 virtual QSize minimumSize() const;
00177
00178 public slots:
00179 void colorSelected( const QColor& color );
00180
00181 protected:
00182 virtual void drawButton(QPainter *p);
00183 virtual bool eventFilter( QObject* o, QEvent* e );
00184
00185 private:
00186 void init();
00187 void buttonShift( int& dx, int& dy );
00188 bool hitArrow( const QPoint& pos );
00189
00190 Q3PopupMenu* m_popup;
00191 bool m_arrowPressed;
00192 };
00193
00194 #endif // _kotoolbutton_h_