File: tableactionhelper.h

package info (click to toggle)
marknote 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,724 kB
  • sloc: cpp: 3,006; xml: 295; makefile: 5; sh: 1
file content (90 lines) | stat: -rw-r--r-- 2,798 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
  SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org>
  SPDX-FileCopyrightText: 2024 Carl Schwan <carl@carlschwan.eu>

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

*/

#pragma once

#include <QAction>
#include <QObject>
#include <QQuickTextDocument>
#include <QTextDocument>
#include <QtQml>

class TableActionHelper : public QObject
{
    Q_OBJECT
    QML_ELEMENT

    Q_PROPERTY(QQuickTextDocument *document READ document WRITE setDocument NOTIFY documentChanged)
    Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
    Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged)
    Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged)

    Q_PROPERTY(QAction *actionInsertRowBelow MEMBER actionInsertRowBelow CONSTANT)
    Q_PROPERTY(QAction *actionInsertRowAbove MEMBER actionInsertRowAbove CONSTANT)

    Q_PROPERTY(QAction *actionInsertColumnBefore MEMBER actionInsertColumnBefore CONSTANT)
    Q_PROPERTY(QAction *actionInsertColumnAfter MEMBER actionInsertColumnAfter CONSTANT)

    Q_PROPERTY(QAction *actionRemoveRow MEMBER actionRemoveRow CONSTANT)
    Q_PROPERTY(QAction *actionRemoveColumn MEMBER actionRemoveColumn CONSTANT)

    Q_PROPERTY(QAction *actionRemoveCellContents MEMBER actionRemoveCellContents CONSTANT)

public:
    explicit TableActionHelper(QObject *parent = nullptr);
    ~TableActionHelper() override;

    QQuickTextDocument *document() const;
    void setDocument(QQuickTextDocument *document);

    int cursorPosition() const;
    void setCursorPosition(int position);

    int selectionStart() const;
    void setSelectionStart(int position);

    int selectionEnd() const;
    void setSelectionEnd(int position);

Q_SIGNALS:
    void cursorPositionChanged();
    void documentChanged();
    void selectionStartChanged();
    void selectionEndChanged();

private:
    QTextCursor textCursor() const;
    QTextDocument *textDocument() const;

    void _k_slotInsertRowBelow();
    void _k_slotInsertRowAbove();
    void _k_slotInsertColumnBefore();
    void _k_slotInsertColumnAfter();

    void _k_slotRemoveRow();
    void _k_slotRemoveColumn();
    void _k_slotRemoveCellContents();

    void _k_updateActions(bool forceUpdate = false);

    QAction *actionInsertRowBelow = nullptr;
    QAction *actionInsertRowAbove = nullptr;

    QAction *actionInsertColumnBefore = nullptr;
    QAction *actionInsertColumnAfter = nullptr;

    QAction *actionRemoveRow = nullptr;
    QAction *actionRemoveColumn = nullptr;

    QAction *actionRemoveCellContents = nullptr;

    QQuickTextDocument *m_document = nullptr;
    int m_cursorPosition = 0;
    int m_selectionStart = 0;
    int m_selectionEnd = 0;
};