Friendiqa/source-linux/common/documenthandler.h

115 lines
4.0 KiB
C++

// This file is part of Friendiqa
// https://github.com/lubuwest/Friendiqa
// Copyright (C) 2020 Marco R. <thomasschmidt45@gmx.net>
//
// This program 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.
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations including
// the two.
//
// You must obey the GNU General Public License in all respects for all
// of the code used other than OpenSSL. If you modify file(s) with this
// exception, you may extend this exception to your version of the
// file(s), but you are not obligated to do so. If you do not wish to do
// so, delete this exception statement from your version. If you delete
// this exception statement from all source files in the program, then
// also delete it here.
//
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef DOCUMENTHANDLER_H
#define DOCUMENTHANDLER_H
//#include <QFont>
#include <QObject>
#include <QTextCursor>
#include <QTextDocument>
#include <QQuickTextDocument>
//QT_BEGIN_NAMESPACE
//class QTextDocument;
//class QQuickTextDocument;
//QT_END_NAMESPACE
class DocumentHandler : public QObject{
Q_OBJECT
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(QFont font READ font WRITE setFont NOTIFY fontChanged)
Q_PROPERTY(bool bold READ bold WRITE setBold NOTIFY boldChanged)
Q_PROPERTY(bool italic READ italic WRITE setItalic NOTIFY italicChanged)
Q_PROPERTY(bool liststyle READ liststyle WRITE setListstyle NOTIFY liststyleChanged)
Q_PROPERTY(bool codeblock READ codeblock WRITE setCodeblock NOTIFY codeblockChanged)
Q_PROPERTY(bool modified READ modified WRITE setModified NOTIFY modifiedChanged)
public:
explicit DocumentHandler(QObject *parent = nullptr);
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);
QFont font() const;
void setFont(const QFont & font);
bool bold() const;
void setBold(bool bold);
bool italic() const;
void setItalic(bool italic);
bool liststyle() const;
void setListstyle(bool liststyle);
bool modified() const;
void setModified(bool m);
bool codeblock() const;
void setCodeblock(bool codeblock);
signals:
void documentChanged();
void cursorPositionChanged();
void selectionStartChanged();
void selectionEndChanged();
void fontChanged();
void boldChanged();
void italicChanged();
void liststyleChanged();
void codeblockChanged();
void error(const QString &message);
void modifiedChanged();
private:
QTextCursor textCursor() const;
QTextDocument *textDocument() const;
void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
QQuickTextDocument *m_document;
int m_cursorPosition;
int m_selectionStart;
int m_selectionEnd;
};
#endif // DOCUMENTHANDLER_H