File: richtextquicktextformat.h

package info (click to toggle)
ktextaddons 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,360 kB
  • sloc: cpp: 54,647; ansic: 6,591; xml: 2,630; sh: 11; makefile: 7
file content (63 lines) | stat: -rw-r--r-- 1,772 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
   SPDX-FileCopyrightText: 2025 Laurent Montel <montel@kde.org>

   SPDX-License-Identifier: LGPL-2.0-or-later
*/

#pragma once

#include "textaddonswidgets_export.h"
#include <QFrame>
class QTimer;
class QHBoxLayout;
class QTextEdit;
namespace TextAddonsWidgets
{
/**
 * @brief The RichTextQuickTextFormat class
 * @author Laurent Montel <montel@kde.org>
 */
class TEXTADDONSWIDGETS_EXPORT RichTextQuickTextFormat : public QFrame
{
    Q_OBJECT
public:
    enum class QuickTextFormatType : uint8_t {
        Unknown = 0,
        Bold = 1,
        Italic = 2,
        StrikeThrough = 4,
        CodeBlock = 8,
        BlockQuote = 16,
        InsertLink = 32,
        UnderLine = 64,
    };
    Q_ENUM(QuickTextFormatType)
    Q_FLAGS(QuickTextFormatType QuickTextFormatTypes)
    Q_DECLARE_FLAGS(QuickTextFormatTypes, QuickTextFormatType)

    explicit RichTextQuickTextFormat(QTextEdit *editor, QWidget *parent = nullptr);
    ~RichTextQuickTextFormat() override;

    [[nodiscard]] QuickTextFormatTypes formatTypes() const;
    void setFormatTypes(const QuickTextFormatTypes &newFormatTypes);

    [[nodiscard]] bool enabled() const;
    void setEnabled(bool newEnabled);

Q_SIGNALS:
    void quickTextFormatRequested(TextAddonsWidgets::RichTextQuickTextFormat::QuickTextFormatType type);

protected:
    [[nodiscard]] bool eventFilter(QObject *watched, QEvent *event) override;

private:
    TEXTADDONSWIDGETS_NO_EXPORT void updatePosition();
    TEXTADDONSWIDGETS_NO_EXPORT void initializeTextFormat();
    TEXTADDONSWIDGETS_NO_EXPORT void updateActions();
    QuickTextFormatTypes mFormatTypes = QuickTextFormatType::Unknown;
    QTextEdit *const mEditor;
    QTimer *const mUpdatePositionTimer;
    QHBoxLayout *const mMainLayout;
    bool mEnabled = true;
};
}