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