File indexing completed on 2024-12-22 04:28:12
0001 /* 0002 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "textcustomeditor_export.h" 0010 #include <QTextBrowser> 0011 0012 class QContextMenuEvent; 0013 class QMenu; 0014 namespace TextCustomEditor 0015 { 0016 /** 0017 * @brief The RichTextBrowser class 0018 * @author Laurent Montel <montel@kde.org> 0019 */ 0020 class TEXTCUSTOMEDITOR_EXPORT RichTextBrowser : public QTextBrowser 0021 { 0022 Q_OBJECT 0023 Q_PROPERTY(bool searchSupport READ searchSupport WRITE setSearchSupport) 0024 Q_PROPERTY(bool textToSpeechSupport READ textToSpeechSupport WRITE setTextToSpeechSupport) 0025 Q_PROPERTY(bool webShortcutSupport READ webShortcutSupport WRITE setWebShortcutSupport) 0026 public: 0027 explicit RichTextBrowser(QWidget *parent = nullptr); 0028 ~RichTextBrowser() override; 0029 enum SupportFeature { 0030 None = 0, 0031 Search = 1, 0032 TextToSpeech = 4, 0033 AllowWebShortcut = 16, 0034 }; 0035 Q_DECLARE_FLAGS(SupportFeatures, SupportFeature) 0036 0037 void setSearchSupport(bool b); 0038 [[nodiscard]] bool searchSupport() const; 0039 0040 [[nodiscard]] bool textToSpeechSupport() const; 0041 void setTextToSpeechSupport(bool b); 0042 0043 void setWebShortcutSupport(bool b); 0044 [[nodiscard]] bool webShortcutSupport() const; 0045 0046 void setDefaultFontSize(int val); 0047 [[nodiscard]] int zoomFactor() const; 0048 0049 public Q_SLOTS: 0050 void slotDisplayMessageIndicator(const QString &message); 0051 void slotSpeakText(); 0052 void slotZoomReset(); 0053 0054 protected: 0055 virtual void addExtraMenuEntry(QMenu *menu, QPoint pos); 0056 void contextMenuEvent(QContextMenuEvent *event) override; 0057 bool event(QEvent *ev) override; 0058 void keyPressEvent(QKeyEvent *event) override; 0059 void wheelEvent(QWheelEvent *e) override; 0060 0061 QMenu *mousePopupMenu(QPoint pos); 0062 0063 Q_SIGNALS: 0064 void say(const QString &text); 0065 void findText(); 0066 0067 private: 0068 TEXTCUSTOMEDITOR_NO_EXPORT void slotUndoableClear(); 0069 0070 TEXTCUSTOMEDITOR_NO_EXPORT bool handleShortcut(QKeyEvent *event); 0071 TEXTCUSTOMEDITOR_NO_EXPORT bool overrideShortcut(QKeyEvent *event); 0072 TEXTCUSTOMEDITOR_NO_EXPORT void deleteWordBack(); 0073 TEXTCUSTOMEDITOR_NO_EXPORT void deleteWordForward(); 0074 TEXTCUSTOMEDITOR_NO_EXPORT void moveLineUpDown(bool moveUp); 0075 TEXTCUSTOMEDITOR_NO_EXPORT void moveCursorBeginUpDown(bool moveUp); 0076 TEXTCUSTOMEDITOR_NO_EXPORT void regenerateColorScheme(); 0077 TEXTCUSTOMEDITOR_NO_EXPORT void updateReadOnlyColor(); 0078 class RichTextBrowserPrivate; 0079 std::unique_ptr<RichTextBrowserPrivate> const d; 0080 }; 0081 }