forked from lirios/text
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocumenthandler.h
More file actions
95 lines (78 loc) · 2.81 KB
/
documenthandler.h
File metadata and controls
95 lines (78 loc) · 2.81 KB
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
91
92
93
94
95
/*
* Copyright © 2016-2017 Andrew Penkrat
*
* This file is part of Liri Text.
*
* Liri Text is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Liri Text is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Liri Text. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DOCUMENTHANDLER_H
#define DOCUMENTHANDLER_H
#include <QObject>
#include <QQuickTextDocument>
#include <QTextCodec>
#include <QFile>
#ifndef QT_NO_FILESYSTEMWATCHER
#include <QFileSystemWatcher>
#endif
#include "lirisyntaxhighlighter.h"
class DocumentHandler : public QObject
{
Q_OBJECT
Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)
Q_PROPERTY(QUrl fileUrl READ fileUrl WRITE setFileUrl NOTIFY fileUrlChanged)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(
QString documentTitle READ documentTitle WRITE setDocumentTitle NOTIFY documentTitleChanged)
Q_PROPERTY(bool modified READ modified NOTIFY modifiedChanged)
public:
DocumentHandler(QObject *parent = nullptr);
~DocumentHandler();
inline QQuickItem *target() { return m_target; }
void setTarget(QQuickItem *target);
inline QUrl fileUrl() { return m_fileUrl; }
Q_INVOKABLE bool setFileUrl(const QUrl &fileUrl);
inline QString text() { return m_text; }
void setText(const QString &text);
inline QString documentTitle() { return m_documentTitle; }
void setDocumentTitle(const QString &title);
inline bool modified() { return m_document->isModified(); }
Q_INVOKABLE QString textFragment(int position, int blockCount);
signals:
void targetChanged();
void fileUrlChanged();
void textChanged();
void documentTitleChanged();
void fileChangedOnDisk();
void modifiedChanged();
void error(const QString &description);
public slots:
bool saveAs(const QUrl &filename);
bool reloadText();
private slots:
void fileChanged(const QString &file);
private:
QQuickItem *m_target;
QTextDocument *m_document;
#ifndef QT_NO_FILESYSTEMWATCHER
// QFileSystemWatcher is not supported on all platforms like WinRT:
// https://codereview.qt-project.org/#/c/64825/
QFileSystemWatcher *m_watcher;
#endif
LiriSyntaxHighlighter *m_highlighter;
QSharedPointer<LanguageDefaultStyles> m_defStyles;
QUrl m_fileUrl;
QString m_text;
QString m_documentTitle;
};
#endif // DOCUMENTHANDLER_H