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"
16 class UnicodeDialog : public KDialog
20 /** \brief The input method for the dialog. Atm only InputHex supported. */
21 enum InputMethod { InputHex, InputDec };
22 explicit UnicodeDialog(InputMethod inputMeth, QWidget *parent = 0);
29 /** \brief Contains the selected unicode character; emitted when Enter is pressed. */
30 void charSelected(const QString&);
33 UnicodeWidget *mUnicodeWidget;
36 class UnicodeWidget : public QWidget, public Ui::UnicodeWidget_UI
41 explicit UnicodeWidget(UnicodeDialog::InputMethod inputMeth, QWidget *parent = 0);
44 /** \brief Returns infos about a unicode number. Extendable/improvable ;) */
45 QString unicodeInfo(const QString &unicode);
47 void showLastUnicode();
50 void wheelEvent(QWheelEvent * event);
53 Ui::UnicodeWidget_UI m_view;
55 enum Direction { Forward, Backward };
57 /** Selected input method */
58 UnicodeDialog::InputMethod inputMethod;
60 /** \brief Validates text and removes all invalid characters (non-hex e.g.) */
61 QString validateText(const QString &text);
62 /** \brief Removes all leading zeros */
63 QString trimmedUnicodeNumber(QString text);
64 /** \brief Checks whether the given string is a control character */
65 bool controlCharacter(const QString& text);
66 /** \brief Checks whether the given uint is a control character */
67 bool controlCharacter(uint value);
69 /** \brief Returns the next available unicode. */
70 QString nextUnicode(const QString &text, Direction direction);
72 /** \brief Paints previous and next characters around current char */
73 void updateOverviewChars(uint unicode);
74 void clearOverviewChars();
77 QString m_lastUnicodeNumber;
79 /** \brief Reads the last used unicode number from the config file. */
81 /** \brief Writes the last used unicode number into the config file. */
85 /** \brief Contains the selected unicode character; emitted when Enter is pressed. */
86 void charSelected(const QString&);
89 void slotReturnPressed();
92 void slotTextChanged(const QString &text);
93 void slotNextUnicode();
94 void slotPrevUnicode();