F:/KPlato/koffice/libs/kofficeui/KoTooluButton.h

Aller à la documentation de ce fichier.
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., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef _kotoolbutton_h_
00021 #define _kotoolbutton_h_
00022 
00023 
00024 #include <QMap>
00025 #include <QPoint>
00026 #include <kinstance.h>
00027 //Added by qt3to4:
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     // The position of the 16x16 tiles in "tile steps"
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 // Needed for the use of KoColorPanel::Position in QMap
00109 bool operator<( const KoColorPanel::Position& lhs, const KoColorPanel::Position& rhs );
00110 
00111 
00112 // A tiny class needed to emit the correct signal when the default
00113 // color item in the color-panel popup is activated. Additionally
00114 // it's used to provide the color select dialog and manages the recent
00115 // colors... hacky
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 // Parts of the code are from KToolBarButton
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_

Généré le Wed Nov 22 23:41:05 2006 pour KPlato par  doxygen 1.5.1-p1