1 /***************************************************************************
2 * Copyright (C) 2008 by Simon Andreas Eugster (simon.eu@gmail.com) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 ***************************************************************************/
10 #ifndef UNICODEDIALOG_H
11 #define UNICODEDIALOG_H
13 #include "ui_unicodewidget_ui.h"
17 class UnicodeDialog : public KDialog
21 /** \brief The input method for the dialog. Atm only InputHex supported. */
22 enum InputMethod { InputHex, InputDec };
23 explicit UnicodeDialog(InputMethod inputMeth, QWidget *parent = 0);
30 /** \brief Contains the selected unicode character; emitted when Enter is pressed. */
31 void charSelected(const QString&);
34 UnicodeWidget *mUnicodeWidget;
37 class UnicodeWidget : public QWidget, public Ui::UnicodeWidget_UI
42 explicit UnicodeWidget(UnicodeDialog::InputMethod inputMeth, QWidget *parent = 0);
45 /** \brief Returns infos about a unicode number. Extendable/improvable ;) */
46 QString unicodeInfo(const QString &unicode);
48 void showLastUnicode();
51 void wheelEvent(QWheelEvent * event);
54 Ui::UnicodeWidget_UI m_view;
56 enum Direction { Forward, Backward };
58 /** Selected input method */
59 UnicodeDialog::InputMethod inputMethod;
61 /** \brief Validates text and removes all invalid characters (non-hex e.g.) */
62 QString validateText(const QString &text);
63 /** \brief Removes all leading zeros */
64 QString trimmedUnicodeNumber(QString text);
65 /** \brief Checks whether the given string is a control character */
66 bool controlCharacter(const QString& text);
67 /** \brief Checks whether the given uint is a control character */
68 bool controlCharacter(uint value);
70 /** \brief Returns the next available unicode. */
71 QString nextUnicode(const QString &text, Direction direction);
73 /** \brief Paints previous and next characters around current char */
74 void updateOverviewChars(uint unicode);
75 void clearOverviewChars();
78 QString m_lastUnicodeNumber;
80 /** \brief Reads the last used unicode number from the config file. */
82 /** \brief Writes the last used unicode number into the config file. */
86 /** \brief Contains the selected unicode character; emitted when Enter is pressed. */
87 void charSelected(const QString&);
90 void slotReturnPressed();
93 void slotTextChanged(const QString &text);
94 void slotNextUnicode();
95 void slotPrevUnicode();