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
#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
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
00098
bool operator<( const KoColorPanel::Position& lhs, const KoColorPanel::Position& rhs );
00099
00100
00101
00102
00103
00104
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
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