]> git.sesse.net Git - kdenlive/blob - src/unicodedialog.h
1c7a83a0464d32f5dcd03ea300cfae2fed6c6621
[kdenlive] / src / unicodedialog.h
1 /***************************************************************************
2  *   Copyright (C) 2008 by Simon Andreas Eugster (simon.eu@gmail.com)      *
3  *                                                                         *
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  ***************************************************************************/
9
10 #ifndef UNICODEDIALOG_H
11 #define UNICODEDIALOG_H
12
13 #include "ui_unicodewidget_ui.h"
14 #include <KDialog>
15 class UnicodeWidget;
16 class UnicodeDialog : public KDialog
17 {
18     Q_OBJECT
19 public:
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);
23     ~UnicodeDialog();
24
25 private Q_SLOTS:
26     void slotAccept();
27
28 Q_SIGNALS:
29     /** \brief Contains the selected unicode character; emitted when Enter is pressed. */
30     void charSelected(const QString&);
31
32 private:
33     UnicodeWidget *mUnicodeWidget;
34 };
35
36 class UnicodeWidget : public QWidget, public Ui::UnicodeWidget_UI
37 {
38     Q_OBJECT
39 public:
40
41     explicit UnicodeWidget(UnicodeDialog::InputMethod inputMeth, QWidget *parent = 0);
42     ~UnicodeWidget();
43
44     /** \brief Returns infos about a unicode number. Extendable/improvable ;) */
45     QString unicodeInfo(const QString &unicode);
46
47     void showLastUnicode();
48
49 protected:
50     void wheelEvent(QWheelEvent * event);
51
52 private:
53     Ui::UnicodeWidget_UI m_view;
54
55     enum Direction { Forward, Backward };
56
57     /** Selected input method */
58     UnicodeDialog::InputMethod inputMethod;
59
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);
68
69     /** \brief Returns the next available unicode. */
70     QString nextUnicode(const QString &text, Direction direction);
71
72     /** \brief Paints previous and next characters around current char */
73     void updateOverviewChars(uint unicode);
74     void clearOverviewChars();
75
76     int m_lastCursorPos;
77     QString m_lastUnicodeNumber;
78
79     /** \brief Reads the last used unicode number from the config file. */
80     void readChoices();
81     /** \brief Writes the last used unicode number into the config file. */
82     void writeChoices();
83
84 signals:
85     /** \brief Contains the selected unicode character; emitted when Enter is pressed. */
86     void charSelected(const QString&);
87
88 public slots:
89     void slotReturnPressed();
90
91 private slots:
92     void slotTextChanged(const QString &text);
93     void slotNextUnicode();
94     void slotPrevUnicode();
95 };
96
97
98
99 #endif