subtraction of already painted area: be fool and
[kdelibs.git] / kdeui / kcharselect.h
blobe54c36b041fd18a230140b18f919d97d507a96bb
1 /* This file is part of the KDE libraries
3 Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 #ifndef kcharselect_h
22 #define kcharselect_h
24 #include <qgridview.h>
25 #include <qvbox.h>
26 #include <qcombobox.h>
27 #include <qspinbox.h>
28 #include <qstring.h>
29 #include <qpoint.h>
30 #include <qstringlist.h>
32 #include <kdelibs_export.h>
34 class QFont;
35 class QFontDatabase;
36 class QMouseEvent;
37 class QSpinBox;
38 class KCharSelectTablePrivate;
39 class KCharSelectPrivate;
41 /**
42 * @short Character selection table
44 * A table widget which displays the characters of a font. Internally
45 * used by KCharSelect. See the KCharSelect documentation for further
46 * details.
48 * @author Reginald Stadlbauer <reggie@kde.org>
51 class KDEUI_EXPORT KCharSelectTable : public QGridView
53 Q_OBJECT
55 public:
56 KCharSelectTable( QWidget *parent, const char *name, const QString &_font,
57 const QChar &_chr, int _tableNum );
59 virtual QSize sizeHint() const;
60 virtual void resizeEvent( QResizeEvent * );
62 virtual void setFont( const QString &_font );
63 virtual void setChar( const QChar &_chr );
64 virtual void setTableNum( int _tableNum );
66 virtual QChar chr() { return vChr; }
68 protected:
69 virtual void paintCell( class QPainter *p, int row, int col );
71 virtual void mousePressEvent( QMouseEvent *e ) { mouseMoveEvent( e ); }
72 virtual void mouseDoubleClickEvent ( QMouseEvent *e ){ mouseMoveEvent( e ); emit doubleClicked();}
73 virtual void mouseReleaseEvent( QMouseEvent *e ) { mouseMoveEvent( e ); emit activated( chr() ); emit activated(); }
74 virtual void mouseMoveEvent( QMouseEvent *e );
76 virtual void keyPressEvent( QKeyEvent *e );
78 void gotoLeft();
79 void gotoRight();
80 void gotoUp();
81 void gotoDown();
83 QString vFont;
84 QChar vChr;
85 int vTableNum;
86 QPoint vPos;
87 QChar focusItem;
88 QPoint focusPos;
89 int temp;
91 signals:
92 void highlighted( const QChar &c );
93 void highlighted();
94 void activated( const QChar &c );
95 void activated();
96 void focusItemChanged();
97 void focusItemChanged( const QChar &c );
98 void tableUp();
99 void tableDown();
100 void doubleClicked();
102 private:
103 virtual void setFont(const QFont &f) { QGridView::setFont(f); }
104 void setToolTips();
105 protected:
106 virtual void virtual_hook( int id, void* data );
107 private:
108 KCharSelectTablePrivate* const d;
112 * @short Character selection widget
114 * This widget allows the user to select a character of a
115 * specified font in a table
117 * \image html kcharselect.png "Character Selection Widget"
119 * You can specify the font whose characters should be displayed via
120 * setFont() or in the constructor. Using enableFontCombo() you can allow the
121 * user to choose the font from a combob-box. As only 256 characters
122 * are displayed at once in the table, using the spinbox on the top
123 * the user can choose starting from which character the table
124 * displays them. This spinbox also can be enabled or disabled using
125 * enableTableSpinBox().
127 * KCharSelect supports keyboard and mouse navigation. Click+Move
128 * always selects the character below the mouse cursor. Using the
129 * arrow keys moves the focus mark around and pressing RETURN
130 * or SPACE selects the cell which contains the focus mark.
132 * To get the current selected character, use the chr()
133 * method. You can set the character which should be displayed with
134 * setChar() and the table number which should be displayed with
135 * setTableNum().
137 * @author Reginald Stadlbauer <reggie@kde.org>
140 class KDEUI_EXPORT KCharSelect : public QVBox
142 Q_OBJECT
143 Q_PROPERTY( QString fontFamily READ font WRITE setFont )
144 Q_PROPERTY( int tableNum READ tableNum WRITE setTableNum )
145 Q_PROPERTY( bool fontComboEnabled READ isFontComboEnabled WRITE enableFontCombo )
146 Q_PROPERTY( bool tableSpinBoxEnabled READ isTableSpinBoxEnabled WRITE enableTableSpinBox )
148 public:
150 * Constructor. @p font specifies which font should be displayed, @p
151 * chr which character should be selected and @p tableNum specifies
152 * the number of the table which should be displayed.
154 KCharSelect( QWidget *parent, const char *name,
155 const QString &font = QString::null, const QChar &chr = ' ', int tableNum = 0 );
156 ~KCharSelect();
158 * Reimplemented.
160 virtual QSize sizeHint() const;
163 * Sets the font which is displayed to @p font
165 virtual void setFont( const QString &font );
168 * Sets the currently selected character to @p chr.
170 virtual void setChar( const QChar &chr );
173 * Sets the currently displayed table to @p tableNum.
175 virtual void setTableNum( int tableNum );
178 * Returns the currently selected character.
180 virtual QChar chr() const { return charTable->chr(); }
183 * Returns the currently displayed font.
185 virtual QString font() const { return fontCombo->currentText(); }
188 * Returns the currently displayed table
190 virtual int tableNum() const { return tableSpinBox->value(); }
193 * If @p e is set to true, the combobox which allows the user to
194 * select the font which should be displayed is enabled, else
195 * disabled.
197 virtual void enableFontCombo( bool e ) { fontCombo->setEnabled( e ); }
201 * If @p e is set to true, the spinbox which allows the user to
202 * specify which characters of the font should be displayed, is
203 * enabled, else disabled.
205 virtual void enableTableSpinBox( bool e ) { tableSpinBox->setEnabled( e ); }
208 * Returns wether the font combobox on the top is enabled or
209 * disabled.
211 * @see enableFontCombo()
213 virtual bool isFontComboEnabled() const { return fontCombo->isEnabled(); }
216 * Returns wether the table spinbox on the top is enabled or
217 * disabled.
219 * @see enableTableSpinBox()
221 virtual bool isTableSpinBoxEnabled() const { return tableSpinBox->isEnabled(); }
223 protected:
224 virtual void fillFontCombo();
225 static void cleanupFontDatabase();
227 QComboBox *fontCombo;
228 QSpinBox *tableSpinBox;
229 KCharSelectTable *charTable;
230 QStringList fontList;
231 static QFontDatabase * fontDataBase;
233 protected slots:
234 void fontSelected( const QString &_font );
235 void tableChanged( int _value );
236 void charHighlighted( const QChar &c ) { emit highlighted( c ); }
237 void charHighlighted() { emit highlighted(); }
238 void charActivated( const QChar &c ) { emit activated( c ); }
239 void charActivated() { emit activated(); }
240 void charFocusItemChanged() { emit focusItemChanged(); }
241 void charFocusItemChanged( const QChar &c ) { emit focusItemChanged( c ); }
242 void charTableUp() { if ( tableNum() < 255 ) setTableNum( tableNum() + 1 ); }
243 void charTableDown() { if ( tableNum() > 0 ) setTableNum( tableNum() - 1 ); }
244 void slotDoubleClicked() { emit doubleClicked(); }
245 void slotUnicodeEntered();
246 void slotUpdateUnicode( const QChar &c );
247 signals:
248 void highlighted( const QChar &c );
249 void highlighted();
250 void activated( const QChar &c );
251 void activated();
252 void fontChanged( const QString &_font );
253 void focusItemChanged();
254 void focusItemChanged( const QChar &c );
255 void doubleClicked();
257 private:
258 virtual void setFont(const QFont &f) { QVBox::setFont(f); }
259 protected:
260 virtual void virtual_hook( int id, void* data );
261 private:
262 class KCharSelectPrivate;
263 KCharSelectPrivate* const d;
266 #endif