File indexing completed on 2024-04-14 04:47:24

0001 /*
0002     SPDX-FileCopyrightText: 2008 Simon Andreas Eugster <simon.eu@gmail.com>
0003 
0004 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include "ui_unicodewidget_ui.h"
0010 #include <QDialog>
0011 
0012 class UnicodeWidget;
0013 class UnicodeDialog : public QDialog
0014 {
0015     Q_OBJECT
0016 public:
0017     /** \brief The input method for the dialog. Atm only InputHex supported. */
0018     enum InputMethod { InputHex, InputDec };
0019     explicit UnicodeDialog(InputMethod inputMeth, QWidget *parent = nullptr);
0020     ~UnicodeDialog() override;
0021 
0022 private Q_SLOTS:
0023     void slotAccept();
0024 
0025 Q_SIGNALS:
0026     /** \brief Contains the selected unicode character; emitted when Enter is pressed. */
0027     void charSelected(const QString &);
0028 
0029 private:
0030     UnicodeWidget *m_unicodeWidget;
0031 };
0032 
0033 class UnicodeWidget : public QWidget, public Ui::UnicodeWidget_UI
0034 {
0035     Q_OBJECT
0036 public:
0037     explicit UnicodeWidget(UnicodeDialog::InputMethod inputMeth, QWidget *parent = nullptr);
0038     ~UnicodeWidget() override;
0039 
0040     /** \brief Returns infos about a unicode number. Extendable/improvable ;) */
0041     QString unicodeInfo(const QString &unicode);
0042 
0043     void showLastUnicode();
0044 
0045 protected:
0046     void wheelEvent(QWheelEvent *event) override;
0047 
0048 private:
0049     enum Direction { Forward, Backward };
0050 
0051     /** Selected input method */
0052     UnicodeDialog::InputMethod m_inputMethod;
0053 
0054     /** \brief Removes all leading zeros */
0055     QString trimmedUnicodeNumber(QString text);
0056     /** \brief Checks whether the given string is a control character */
0057     bool controlCharacter(const QString &text);
0058     /** \brief Checks whether the given uint is a control character */
0059     bool controlCharacter(uint value);
0060 
0061     /** \brief Returns the next available unicode. */
0062     QString nextUnicode(const QString &text, Direction direction);
0063 
0064     /** \brief Paints previous and next characters around current char */
0065     void updateOverviewChars(uint unicode);
0066     void clearOverviewChars();
0067 
0068     QString m_lastUnicodeNumber;
0069 
0070     /** \brief Reads the last used unicode number from the config file. */
0071     void readChoices();
0072     /** \brief Writes the last used unicode number into the config file. */
0073     void writeChoices();
0074 
0075 Q_SIGNALS:
0076     /** \brief Contains the selected unicode character; emitted when Enter is pressed. */
0077     void charSelected(const QString &);
0078 
0079 public Q_SLOTS:
0080     void slotReturnPressed();
0081 
0082 private Q_SLOTS:
0083     void slotTextChanged(const QString &text);
0084     void slotNextUnicode();
0085     void slotPrevUnicode();
0086 };