File indexing completed on 2025-04-27 03:58:40

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2022-08-01
0007  * Description : Text edit widgets with spellcheck support and edition limitations.
0008  *
0009  * SPDX-FileCopyrightText: 2021-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_DTEXT_EDIT_P_H
0016 #define DIGIKAM_DTEXT_EDIT_P_H
0017 
0018 #include "dtextedit.h"
0019 #include "digikam_config.h"
0020 
0021 // Qt includes
0022 
0023 #include <QMargins>
0024 #include <QColor>
0025 #include <QTextDocument>
0026 #include <QFontMetrics>
0027 #include <QFontDatabase>
0028 #include <QMimeData>
0029 #include <QLabel>
0030 #include <QIcon>
0031 #include <QStyle>
0032 #include <QPainter>
0033 #include <QApplication>
0034 #include <QScrollBar>
0035 #include <QUrl>
0036 #include <QToolTip>
0037 
0038 // KDE includes
0039 
0040 #ifdef HAVE_SONNET
0041 #   include <sonnet/spellcheckdecorator.h>
0042 #   include <sonnet/highlighter.h>
0043 
0044 using namespace Sonnet;
0045 
0046 #endif
0047 
0048 #include <klocalizedstring.h>
0049 
0050 // Local includes
0051 
0052 #include "digikam_debug.h"
0053 #include "localizesettings.h"
0054 #include "localizecontainer.h"
0055 
0056 namespace Digikam
0057 {
0058 
0059 class Q_DECL_HIDDEN DTextEditClearButton : public QLabel
0060 {
0061     Q_OBJECT
0062 
0063 public:
0064 
0065     explicit DTextEditClearButton(QWidget* const parent);
0066 
0067 Q_SIGNALS:
0068 
0069     void clicked();
0070 
0071 protected:
0072 
0073     void mousePressEvent(QMouseEvent* e) override;
0074 };
0075 
0076 // -------------------------------------------------------------------------------
0077 
0078 class Q_DECL_HIDDEN DTextEdit::Private
0079 {
0080 public:
0081 
0082     explicit Private();
0083 
0084     /**
0085      * Init the text widget with the spell-checker engine (optional).
0086      */
0087     void init(DTextEdit* const parent);
0088 
0089 public:
0090 
0091 #ifdef HAVE_SONNET
0092 
0093     Sonnet::SpellCheckDecorator* spellChecker = nullptr;
0094 
0095 #endif
0096 
0097     QString                      ignoredMask;               ///< Mask of ignored characters in text editor.
0098     QString                      acceptedMask;              ///< Mask of accepted characters in text editor.
0099 
0100     unsigned int                 lines          = 3;
0101 
0102     DTextEditClearButton*        clrBtn         = nullptr;
0103 
0104     LocalizeContainer            container;                 ///< Spell checking settings container.
0105 
0106     int                          maxLength      = 0;
0107 
0108     bool                         clearBtnEnable = true;
0109 };
0110 
0111 // ------------------------------------------------------------------------------------------------
0112 
0113 class Q_DECL_HIDDEN DPlainTextEdit::Private
0114 {
0115 public:
0116 
0117     explicit Private();
0118 
0119     /**
0120      * Init the text widget with the spell-checker engine (optional).
0121      */
0122     void init(DPlainTextEdit* const parent);
0123 
0124 public:
0125 
0126 #ifdef HAVE_SONNET
0127 
0128     Sonnet::SpellCheckDecorator* spellChecker = nullptr;
0129 
0130 #endif
0131 
0132     QString                      ignoredMask;               ///< Mask of ignored characters in text editor.
0133     QString                      acceptedMask;              ///< Mask of accepted characters in text editor.
0134 
0135     unsigned int                 lines          = 3;
0136 
0137     DTextEditClearButton*        clrBtn         = nullptr;
0138 
0139     LocalizeContainer            container;                 ///< Spell checking settings container.
0140 
0141     int                          maxLength      = 0;
0142 
0143     bool                         clearBtnEnable = true;
0144 };
0145 
0146 } // namespace Digikam
0147 
0148 #endif // DIGIKAM_LINE_EDIT_SPELL_CHECKER_P_H