aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quickcontrols2/texteditor
diff options
context:
space:
mode:
authorMitch Curtis <[email protected]>2021-08-12 14:39:51 +0200
committerMitch Curtis <[email protected]>2021-08-16 12:52:59 +0200
commit809339d1484cf556512534367b8170bc26baf072 (patch)
tree12871313b658f36d058b5ef25af1e247e9c46ce9 /examples/quickcontrols2/texteditor
parentb01b4f00eae8022c6a97d90f54dac395144ae095 (diff)
Remove qtquickcontrols2 sources and explain where they wentHEADdev
Now that qtquickcontrols2 has been merged into qtdeclarative, we should make it obvious that this repo should no longer be used, by preventing it from being built. Task-number: QTBUG-95173 Pick-to: 6.2 Change-Id: I95bd6a214f3d75a865ab163ee0a1f9ffbeb7a051 Reviewed-by: Alexandru Croitor <[email protected]> Reviewed-by: Volker Hilsheimer <[email protected]>
Diffstat (limited to 'examples/quickcontrols2/texteditor')
-rw-r--r--examples/quickcontrols2/texteditor/+touch/texteditor.html19
-rw-r--r--examples/quickcontrols2/texteditor/.prev_CMakeLists.txt73
-rw-r--r--examples/quickcontrols2/texteditor/CMakeLists.txt73
-rw-r--r--examples/quickcontrols2/texteditor/creatorKateHighlighter.pngbin106622 -> 0 bytes
-rw-r--r--examples/quickcontrols2/texteditor/doc/images/qtquickcontrols2-texteditor-desktop.jpgbin76304 -> 0 bytes
-rw-r--r--examples/quickcontrols2/texteditor/doc/images/qtquickcontrols2-texteditor-touch.jpgbin31203 -> 0 bytes
-rw-r--r--examples/quickcontrols2/texteditor/doc/src/qtquickcontrols2-texteditor.qdoc124
-rw-r--r--examples/quickcontrols2/texteditor/documenthandler.cpp403
-rw-r--r--examples/quickcontrols2/texteditor/documenthandler.h176
-rw-r--r--examples/quickcontrols2/texteditor/einstein.pngbin19989 -> 0 bytes
-rw-r--r--examples/quickcontrols2/texteditor/example.md173
-rw-r--r--examples/quickcontrols2/texteditor/fonts/fontello.ttfbin10152 -> 0 bytes
-rw-r--r--examples/quickcontrols2/texteditor/images/qt-logo.pngbin4039 -> 0 bytes
-rw-r--r--examples/quickcontrols2/texteditor/qml/+touch/texteditor.qml267
-rw-r--r--examples/quickcontrols2/texteditor/qml/texteditor.qml473
-rw-r--r--examples/quickcontrols2/texteditor/qtquickcontrols2.conf11
-rw-r--r--examples/quickcontrols2/texteditor/red.pngbin130 -> 0 bytes
-rw-r--r--examples/quickcontrols2/texteditor/texteditor.cpp97
-rw-r--r--examples/quickcontrols2/texteditor/texteditor.html43
-rw-r--r--examples/quickcontrols2/texteditor/texteditor.pro22
-rw-r--r--examples/quickcontrols2/texteditor/texteditor.qrc11
21 files changed, 0 insertions, 1965 deletions
diff --git a/examples/quickcontrols2/texteditor/+touch/texteditor.html b/examples/quickcontrols2/texteditor/+touch/texteditor.html
deleted file mode 100644
index b5f03f25..00000000
--- a/examples/quickcontrols2/texteditor/+touch/texteditor.html
+++ /dev/null
@@ -1,19 +0,0 @@
-<html>
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <meta name="qrichtext" content="1">
- <title>Text Editor Example</title>
-</head>
-<body>
-<body>
- <p align="center">
- <img src="/service/qrc:/images/qt-logo.png" />
- </p>
- <h2 align="center">
- Qt Quick Controls 2
- </h2>
- <p align="center">
- This example demonstrates a modern rich text editor.
- </p>
-</body>
-</html>
diff --git a/examples/quickcontrols2/texteditor/.prev_CMakeLists.txt b/examples/quickcontrols2/texteditor/.prev_CMakeLists.txt
deleted file mode 100644
index a3075353..00000000
--- a/examples/quickcontrols2/texteditor/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,73 +0,0 @@
-# Generated from texteditor.pro.
-
-cmake_minimum_required(VERSION 3.14)
-project(texteditor LANGUAGES CXX)
-
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
-set(CMAKE_AUTOUIC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quickcontrols2/texteditor")
-
-find_package(Qt6 COMPONENTS Core)
-find_package(Qt6 COMPONENTS Gui)
-find_package(Qt6 COMPONENTS Quick)
-find_package(Qt6 COMPONENTS QuickControls2)
-
-qt_add_executable(texteditor
- documenthandler.cpp documenthandler.h
- texteditor.cpp
-)
-set_target_properties(texteditor PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-target_link_libraries(texteditor PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Quick
- Qt::QuickControls2
-)
-
-
-# Resources:
-set(texteditor_resource_files
- "+touch/texteditor.html"
- "fonts/fontello.ttf"
- "images/qt-logo.png"
- "qml/+touch/texteditor.qml"
- "qml/texteditor.qml"
- "qtquickcontrols2.conf"
- "texteditor.html"
-)
-
-qt6_add_resources(texteditor "texteditor"
- PREFIX
- "/"
- FILES
- ${texteditor_resource_files}
-)
-
-if(TARGET Qt::Widgets)
- target_link_libraries(texteditor PUBLIC
- Qt::Widgets
- )
-endif()
-
-if(CMAKE_CROSSCOMPILING)
- target_compile_definitions(texteditor PUBLIC
- QT_EXTRA_FILE_SELECTOR=\\\"touch\\\"
- )
-endif()
-
-install(TARGETS texteditor
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/quickcontrols2/texteditor/CMakeLists.txt b/examples/quickcontrols2/texteditor/CMakeLists.txt
deleted file mode 100644
index 8c1f7cfb..00000000
--- a/examples/quickcontrols2/texteditor/CMakeLists.txt
+++ /dev/null
@@ -1,73 +0,0 @@
-# Generated from texteditor.pro.
-
-cmake_minimum_required(VERSION 3.14)
-project(texteditor LANGUAGES CXX)
-
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
-set(CMAKE_AUTOUIC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quickcontrols2/texteditor")
-
-find_package(Qt6 COMPONENTS Core)
-find_package(Qt6 COMPONENTS Gui)
-find_package(Qt6 COMPONENTS Quick)
-find_package(Qt6 COMPONENTS QuickControls2)
-
-qt_add_executable(texteditor
- documenthandler.cpp documenthandler.h
- texteditor.cpp
-)
-set_target_properties(texteditor PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-target_link_libraries(texteditor PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Quick
- Qt::QuickControls2
-)
-
-
-# Resources:
-set(texteditor_resource_files
- "+touch/texteditor.html"
- "fonts/fontello.ttf"
- "images/qt-logo.png"
- "qml/+touch/texteditor.qml"
- "qml/texteditor.qml"
- "qtquickcontrols2.conf"
- "texteditor.html"
-)
-
-qt6_add_resources(texteditor "texteditor"
- PREFIX
- "/"
- FILES
- ${texteditor_resource_files}
-)
-
-if(TARGET Qt::Widgets)
- target_link_libraries(texteditor PUBLIC
- Qt::Widgets
- )
-endif()
-
-if(CMAKE_CROSSCOMPILING)
- target_compile_definitions(texteditor PUBLIC
- QT_EXTRA_FILE_SELECTOR="touch" # special case
- )
-endif()
-
-install(TARGETS texteditor
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/quickcontrols2/texteditor/creatorKateHighlighter.png b/examples/quickcontrols2/texteditor/creatorKateHighlighter.png
deleted file mode 100644
index 7dd81950..00000000
--- a/examples/quickcontrols2/texteditor/creatorKateHighlighter.png
+++ /dev/null
Binary files differ
diff --git a/examples/quickcontrols2/texteditor/doc/images/qtquickcontrols2-texteditor-desktop.jpg b/examples/quickcontrols2/texteditor/doc/images/qtquickcontrols2-texteditor-desktop.jpg
deleted file mode 100644
index 259e0e8b..00000000
--- a/examples/quickcontrols2/texteditor/doc/images/qtquickcontrols2-texteditor-desktop.jpg
+++ /dev/null
Binary files differ
diff --git a/examples/quickcontrols2/texteditor/doc/images/qtquickcontrols2-texteditor-touch.jpg b/examples/quickcontrols2/texteditor/doc/images/qtquickcontrols2-texteditor-touch.jpg
deleted file mode 100644
index 6a924cdf..00000000
--- a/examples/quickcontrols2/texteditor/doc/images/qtquickcontrols2-texteditor-touch.jpg
+++ /dev/null
Binary files differ
diff --git a/examples/quickcontrols2/texteditor/doc/src/qtquickcontrols2-texteditor.qdoc b/examples/quickcontrols2/texteditor/doc/src/qtquickcontrols2-texteditor.qdoc
deleted file mode 100644
index 28cf3f3b..00000000
--- a/examples/quickcontrols2/texteditor/doc/src/qtquickcontrols2-texteditor.qdoc
+++ /dev/null
@@ -1,124 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-/*!
- \example texteditor
- \keyword Qt Quick Controls - Text Editor
- \title Qt Quick Controls - Text Editor
- \keyword Qt Quick Controls 2 - Text Editor
- \ingroup qtquickcontrols2-examples
- \brief A QML app using Qt Quick Controls and a C++ class to
- provide a fully-functional rich-text editor application.
-
- The \e {Text Editor Example} presents a sample HTML file using the TextArea
- control, preserving the HTML formatting. The application comes with two user
- interfaces; one for traditional desktop platforms with a mouse pointer, and
- another simpler, touch-oriented version.
-
- \section1 Desktop User Interface
-
- \image qtquickcontrols2-texteditor-desktop.jpg
-
- The desktop version is a complete text editor with capabilities for formatting
- text, and opening and saving HTML and plain text files. It demonstrates the
- native-looking dialogs and menus using the \l{Qt Labs Platform} module. These
- types are mostly suitable for desktop platforms with support for multiple
- top-level windows, a mouse pointer, and moderate screen size.
-
- The desktop UI uses FileDialog for opening and saving files:
-
- \quotefromfile texteditor/qml/texteditor.qml
- \skipto FileDialog
- \printuntil /\bsaveAs\b/
- \printline }
-
- It uses FontDialog and ColorDialog for choosing fonts and colors:
-
- \skipto FontDialog
- \printuntil /.*colorDialog$/
- \printuntil /^\s{4}\}$/
-
- It also uses \l[QML QtLabsPlatform]{Menu} and
- \l[QML QtLabsPlatform]{MenuItem} that provide a context menu to format text
- within:
-
- \skipto /\bMenu\b/
- \printuntil /^\s{4}\}$/
-
- \note There is also a standard menubar with more options than the
- context menu.
-
- \section1 Touch User Interface
-
- \image qtquickcontrols2-texteditor-touch.jpg
-
- The touch user interface is a simplified version of the text editor. It is
- suitable for touch devices with limited screen size. The example uses
- \l{Using File Selectors with Qt Quick Controls}{file selectors} to load
- the appropriate user interface automatically.
-
- Unlike the desktop version, which uses top-level dialogs, the touch version
- uses the QML \l Dialog type, which is not a top-level window. This type of
- dialog is fully supported on mobile and embedded platforms that do not support
- multiple top-level windows.
-
- \quotefromfile texteditor/qml/+touch/texteditor.qml
- \skipto /\bDialog\b/
- \printuntil /^\s{4}\}$/
-
- \section1 C++ Backend
-
- Both user interfaces use the same C++ backend, which supports opening, formatting,
- and editing a document. The C++ class, \c DocumentHandler, extends QObject and is
- registered as a QML type under the namespace \c {io.qt.examples.texteditor 1.0}.
-
- The following snippets show how the type is registered under a namespace and later
- imported and instantiated by \e main.qml. For more information about registering C++
- classes as QML types, see \l {Defining QML Types from C++}.
-
- QML type registration:
-
- \code
- #include <QtQml/qqml.h>
- ...
- qmlRegisterType<DocumentHandler>("io.qt.examples.texteditor", 1, 0, "DocumentHandler");
- ...
- \endcode
-
- QML namespace import:
-
- \code
- import io.qt.examples.texteditor 1.0
- \endcode
-
- QML instance:
-
- \quotefromfile texteditor/qml/texteditor.qml
- \skipto DocumentHandler
- \printuntil /^\s{4}\}$/
-
- \include examples-run.qdocinc
-*/
diff --git a/examples/quickcontrols2/texteditor/documenthandler.cpp b/examples/quickcontrols2/texteditor/documenthandler.cpp
deleted file mode 100644
index e82fbb8c..00000000
--- a/examples/quickcontrols2/texteditor/documenthandler.cpp
+++ /dev/null
@@ -1,403 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "documenthandler.h"
-
-#include <QFile>
-#include <QFileInfo>
-#include <QFileSelector>
-#include <QMimeDatabase>
-#include <QQmlFile>
-#include <QQmlFileSelector>
-#include <QQuickTextDocument>
-#include <QTextCharFormat>
-#include <QStringDecoder>
-#include <QTextDocument>
-#include <QDebug>
-
-DocumentHandler::DocumentHandler(QObject *parent)
- : QObject(parent)
- , m_document(nullptr)
- , m_cursorPosition(-1)
- , m_selectionStart(0)
- , m_selectionEnd(0)
-{
-}
-
-QQuickTextDocument *DocumentHandler::document() const
-{
- return m_document;
-}
-
-void DocumentHandler::setDocument(QQuickTextDocument *document)
-{
- if (document == m_document)
- return;
-
- if (m_document)
- m_document->textDocument()->disconnect(this);
- m_document = document;
- if (m_document)
- connect(m_document->textDocument(), &QTextDocument::modificationChanged, this, &DocumentHandler::modifiedChanged);
- emit documentChanged();
-}
-
-int DocumentHandler::cursorPosition() const
-{
- return m_cursorPosition;
-}
-
-void DocumentHandler::setCursorPosition(int position)
-{
- if (position == m_cursorPosition)
- return;
-
- m_cursorPosition = position;
- reset();
- emit cursorPositionChanged();
-}
-
-int DocumentHandler::selectionStart() const
-{
- return m_selectionStart;
-}
-
-void DocumentHandler::setSelectionStart(int position)
-{
- if (position == m_selectionStart)
- return;
-
- m_selectionStart = position;
- emit selectionStartChanged();
-}
-
-int DocumentHandler::selectionEnd() const
-{
- return m_selectionEnd;
-}
-
-void DocumentHandler::setSelectionEnd(int position)
-{
- if (position == m_selectionEnd)
- return;
-
- m_selectionEnd = position;
- emit selectionEndChanged();
-}
-
-QString DocumentHandler::fontFamily() const
-{
- QTextCursor cursor = textCursor();
- if (cursor.isNull())
- return QString();
- QTextCharFormat format = cursor.charFormat();
- return format.font().family();
-}
-
-void DocumentHandler::setFontFamily(const QString &family)
-{
- QTextCharFormat format;
- format.setFontFamily(family);
- mergeFormatOnWordOrSelection(format);
- emit fontFamilyChanged();
-}
-
-QColor DocumentHandler::textColor() const
-{
- QTextCursor cursor = textCursor();
- if (cursor.isNull())
- return QColor(Qt::black);
- QTextCharFormat format = cursor.charFormat();
- return format.foreground().color();
-}
-
-void DocumentHandler::setTextColor(const QColor &color)
-{
- QTextCharFormat format;
- format.setForeground(QBrush(color));
- mergeFormatOnWordOrSelection(format);
- emit textColorChanged();
-}
-
-Qt::Alignment DocumentHandler::alignment() const
-{
- QTextCursor cursor = textCursor();
- if (cursor.isNull())
- return Qt::AlignLeft;
- return textCursor().blockFormat().alignment();
-}
-
-void DocumentHandler::setAlignment(Qt::Alignment alignment)
-{
- QTextBlockFormat format;
- format.setAlignment(alignment);
- QTextCursor cursor = textCursor();
- cursor.mergeBlockFormat(format);
- emit alignmentChanged();
-}
-
-bool DocumentHandler::bold() const
-{
- QTextCursor cursor = textCursor();
- if (cursor.isNull())
- return false;
- return textCursor().charFormat().fontWeight() == QFont::Bold;
-}
-
-void DocumentHandler::setBold(bool bold)
-{
- QTextCharFormat format;
- format.setFontWeight(bold ? QFont::Bold : QFont::Normal);
- mergeFormatOnWordOrSelection(format);
- emit boldChanged();
-}
-
-bool DocumentHandler::italic() const
-{
- QTextCursor cursor = textCursor();
- if (cursor.isNull())
- return false;
- return textCursor().charFormat().fontItalic();
-}
-
-void DocumentHandler::setItalic(bool italic)
-{
- QTextCharFormat format;
- format.setFontItalic(italic);
- mergeFormatOnWordOrSelection(format);
- emit italicChanged();
-}
-
-bool DocumentHandler::underline() const
-{
- QTextCursor cursor = textCursor();
- if (cursor.isNull())
- return false;
- return textCursor().charFormat().fontUnderline();
-}
-
-void DocumentHandler::setUnderline(bool underline)
-{
- QTextCharFormat format;
- format.setFontUnderline(underline);
- mergeFormatOnWordOrSelection(format);
- emit underlineChanged();
-}
-
-int DocumentHandler::fontSize() const
-{
- QTextCursor cursor = textCursor();
- if (cursor.isNull())
- return 0;
- QTextCharFormat format = cursor.charFormat();
- return format.font().pointSize();
-}
-
-void DocumentHandler::setFontSize(int size)
-{
- if (size <= 0)
- return;
-
- QTextCursor cursor = textCursor();
- if (cursor.isNull())
- return;
-
- if (!cursor.hasSelection())
- cursor.select(QTextCursor::WordUnderCursor);
-
- if (cursor.charFormat().property(QTextFormat::FontPointSize).toInt() == size)
- return;
-
- QTextCharFormat format;
- format.setFontPointSize(size);
- mergeFormatOnWordOrSelection(format);
- emit fontSizeChanged();
-}
-
-QString DocumentHandler::fileName() const
-{
- const QString filePath = QQmlFile::urlToLocalFileOrQrc(m_fileUrl);
- const QString fileName = QFileInfo(filePath).fileName();
- if (fileName.isEmpty())
- return QStringLiteral("untitled.txt");
- return fileName;
-}
-
-QString DocumentHandler::fileType() const
-{
- return QFileInfo(fileName()).suffix();
-}
-
-QUrl DocumentHandler::fileUrl() const
-{
- return m_fileUrl;
-}
-
-void DocumentHandler::load(const QUrl &fileUrl)
-{
- if (fileUrl == m_fileUrl)
- return;
-
- QQmlEngine *engine = qmlEngine(this);
- if (!engine) {
- qWarning() << "load() called before DocumentHandler has QQmlEngine";
- return;
- }
-
- const QUrl path = QQmlFileSelector::get(engine)->selector()->select(fileUrl);
- const QString fileName = QQmlFile::urlToLocalFileOrQrc(path);
- if (QFile::exists(fileName)) {
- QMimeType mime = QMimeDatabase().mimeTypeForFile(fileName);
- QFile file(fileName);
- if (file.open(QFile::ReadOnly)) {
- QByteArray data = file.readAll();
- if (QTextDocument *doc = textDocument()) {
- doc->setBaseUrl(path.adjusted(QUrl::RemoveFilename));
- doc->setModified(false);
- if (mime.inherits("text/markdown")) {
- emit loaded(QString::fromUtf8(data), Qt::MarkdownText);
- } else {
- auto encoding = QStringConverter::encodingForHtml(data);
- if (encoding) {
- QStringDecoder decoder(*encoding);
- emit loaded(decoder(data), Qt::AutoText);
- } else {
- // fall back to utf8
- emit loaded(QString::fromUtf8(data), Qt::AutoText);
- }
- }
- }
-
- reset();
- }
- }
-
- m_fileUrl = fileUrl;
- emit fileUrlChanged();
-}
-
-void DocumentHandler::saveAs(const QUrl &fileUrl)
-{
- QTextDocument *doc = textDocument();
- if (!doc)
- return;
-
- const QString filePath = fileUrl.toLocalFile();
- const bool isHtml = QFileInfo(filePath).suffix().contains(QLatin1String("htm"));
- QFile file(filePath);
- if (!file.open(QFile::WriteOnly | QFile::Truncate | (isHtml ? QFile::NotOpen : QFile::Text))) {
- emit error(tr("Cannot save: ") + file.errorString());
- return;
- }
- file.write((isHtml ? doc->toHtml() : doc->toPlainText()).toUtf8());
- file.close();
-
- if (fileUrl == m_fileUrl)
- return;
-
- m_fileUrl = fileUrl;
- emit fileUrlChanged();
-}
-
-void DocumentHandler::reset()
-{
- emit fontFamilyChanged();
- emit alignmentChanged();
- emit boldChanged();
- emit italicChanged();
- emit underlineChanged();
- emit fontSizeChanged();
- emit textColorChanged();
-}
-
-QTextCursor DocumentHandler::textCursor() const
-{
- QTextDocument *doc = textDocument();
- if (!doc)
- return QTextCursor();
-
- QTextCursor cursor = QTextCursor(doc);
- if (m_selectionStart != m_selectionEnd) {
- cursor.setPosition(m_selectionStart);
- cursor.setPosition(m_selectionEnd, QTextCursor::KeepAnchor);
- } else {
- cursor.setPosition(m_cursorPosition);
- }
- return cursor;
-}
-
-QTextDocument *DocumentHandler::textDocument() const
-{
- if (!m_document)
- return nullptr;
-
- return m_document->textDocument();
-}
-
-void DocumentHandler::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
-{
- QTextCursor cursor = textCursor();
- if (!cursor.hasSelection())
- cursor.select(QTextCursor::WordUnderCursor);
- cursor.mergeCharFormat(format);
-}
-
-bool DocumentHandler::modified() const
-{
- return m_document && m_document->textDocument()->isModified();
-}
-
-void DocumentHandler::setModified(bool m)
-{
- if (m_document)
- m_document->textDocument()->setModified(m);
-}
-
-#include "moc_documenthandler.cpp"
diff --git a/examples/quickcontrols2/texteditor/documenthandler.h b/examples/quickcontrols2/texteditor/documenthandler.h
deleted file mode 100644
index 3863eb49..00000000
--- a/examples/quickcontrols2/texteditor/documenthandler.h
+++ /dev/null
@@ -1,176 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DOCUMENTHANDLER_H
-#define DOCUMENTHANDLER_H
-
-#include <QFont>
-#include <QObject>
-#include <QTextCursor>
-#include <QUrl>
-
-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(QColor textColor READ textColor WRITE setTextColor NOTIFY textColorChanged)
- Q_PROPERTY(QString fontFamily READ fontFamily WRITE setFontFamily NOTIFY fontFamilyChanged)
- Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
-
- Q_PROPERTY(bool bold READ bold WRITE setBold NOTIFY boldChanged)
- Q_PROPERTY(bool italic READ italic WRITE setItalic NOTIFY italicChanged)
- Q_PROPERTY(bool underline READ underline WRITE setUnderline NOTIFY underlineChanged)
-
- Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
-
- Q_PROPERTY(QString fileName READ fileName NOTIFY fileUrlChanged)
- Q_PROPERTY(QString fileType READ fileType NOTIFY fileUrlChanged)
- Q_PROPERTY(QUrl fileUrl READ fileUrl NOTIFY fileUrlChanged)
-
- 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);
-
- QString fontFamily() const;
- void setFontFamily(const QString &family);
-
- QColor textColor() const;
- void setTextColor(const QColor &color);
-
- Qt::Alignment alignment() const;
- void setAlignment(Qt::Alignment alignment);
-
- bool bold() const;
- void setBold(bool bold);
-
- bool italic() const;
- void setItalic(bool italic);
-
- bool underline() const;
- void setUnderline(bool underline);
-
- int fontSize() const;
- void setFontSize(int size);
-
- QString fileName() const;
- QString fileType() const;
- QUrl fileUrl() const;
-
- bool modified() const;
- void setModified(bool m);
-
-public Q_SLOTS:
- void load(const QUrl &fileUrl);
- void saveAs(const QUrl &fileUrl);
-
-Q_SIGNALS:
- void documentChanged();
- void cursorPositionChanged();
- void selectionStartChanged();
- void selectionEndChanged();
-
- void fontFamilyChanged();
- void textColorChanged();
- void alignmentChanged();
-
- void boldChanged();
- void italicChanged();
- void underlineChanged();
-
- void fontSizeChanged();
-
- void textChanged();
- void fileUrlChanged();
-
- void loaded(const QString &text, int format);
- void error(const QString &message);
-
- void modifiedChanged();
-
-private:
- void reset();
- QTextCursor textCursor() const;
- QTextDocument *textDocument() const;
- void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
-
- QQuickTextDocument *m_document;
-
- int m_cursorPosition;
- int m_selectionStart;
- int m_selectionEnd;
-
- QFont m_font;
- QUrl m_fileUrl;
-};
-
-#endif // DOCUMENTHANDLER_H
diff --git a/examples/quickcontrols2/texteditor/einstein.png b/examples/quickcontrols2/texteditor/einstein.png
deleted file mode 100644
index 3611284d..00000000
--- a/examples/quickcontrols2/texteditor/einstein.png
+++ /dev/null
Binary files differ
diff --git a/examples/quickcontrols2/texteditor/example.md b/examples/quickcontrols2/texteditor/example.md
deleted file mode 100644
index 169ff433..00000000
--- a/examples/quickcontrols2/texteditor/example.md
+++ /dev/null
@@ -1,173 +0,0 @@
-# Markdown in Qt Quick
-
-The Text, TextEdit and TextArea items support rich text formatted in HTML.
-Since Qt 5.14, they now support two dialects of Markdown as well:
-[The CommonMark Specification](https://spec.commonmark.org/0.29/) is the
-conservative formal specification, while
-[GitHub Flavored Markdown](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown)
-adds extra features such as task lists and tables.
-
-If you are viewing this document in the Qt Quick Controls Text Editor example,
-you can edit this document to explore Qt's rich text editing features.
-We have included some comments in each of the following sections to
-encourage you to experiment.
-
-## Font and Paragraph Styles
-
-Markdown supports **bold**, *italic*, ~~strikethrough~~ and `monospace` font
-styles.
-
-> A block quote is indented according to the convention for email quoting.
-
- A block of code;
- can be indented;
- with 4 spaces or a tab;
-
-or
-
-```
-Block {
- id: code
- CanBe {
- wrappedBy: "triple backticks"
- }
-}
-```
-
-Block quotes can be nested, and block quotes can include indented code blocks.
-
-In [The CommonMark Specification](https://spec.commonmark.org/0.29/)
-John MacFarlane writes:
-
-> What distinguishes Markdown from many other lightweight markup syntaxes,
-> which are often easier to write, is its readability. As Gruber writes:
-
-> > The overriding design goal for Markdown's formatting syntax is to make it
-> > as readable as possible. The idea is that a Markdown-formatted document should
-> > be publishable as-is, as plain text, without looking like it's been marked up
-> > with tags or formatting instructions. (
-> > [http://daringfireball.net/projects/markdown/](http://daringfireball.net/projects/markdown/))
-
-> The point can be illustrated by comparing a sample of AsciiDoc with an
-> equivalent sample of Markdown. Here is a sample of AsciiDoc from the AsciiDoc
-> manual:
-
-> 1. List item one.
-> +
-> List item one continued with a second paragraph followed by an
-> Indented block.
-> +
-> .................
-> $ ls *.sh
-> $ mv *.sh ~/tmp
-> .................
-> +
-> List item continued with a third paragraph.
->
-> 2. List item two continued with an open block.
-> ...
->
-
-## Hyperlinks
-
-Hyperlinks can be written with the link text first, and the URL immediately
-following: [Qt Assistant](http://doc.qt.io/qt-5/qtassistant-index.html)
-
-A plain url is automatically recognized: https://doc.qt.io/qt-5/qml-qtquick-text.html
-
-There are also "reference links" where the link text is first labeled
-and then the URL for the label is given elsewhere:
-[The Qt Creator Manual][creatormanual]
-
-## Images
-
-Inline images like this one ![red square](red.png) flow with the surrounding text.
-
-The code for including an image is just a link that starts with a bang.
-An image in its own paragraph is given its own space:
-
-![Albert Einstein image](einstein.png)
-
-## Lists
-
-Different kinds of lists can be included. Standard bullet lists can be nested,
-using different symbols for each level of the list. List items can have nested
-items such as block quotes, code blocks and images. Check boxes can be included
-to form a task list.
-
-- Disc symbols are typically used for top-level list items.
- * Circle symbols can be used to distinguish between items in lower-level
- lists.
- + Square symbols provide a reasonable alternative to discs and circles.
- * Lists can be continued...
- * further down
-- List items can include images: ![red square](red.png)
-- and even nested quotes, like this:
-
- The [Qt Documentation](https://doc.qt.io/qt-5/qml-qtquick-textedit.html#details)
- points out that
- > The TextEdit item displays a block of editable, formatted text.
- >
- > It can display both plain and rich text. For example:
- >
- > TextEdit {
- > width: 240
- > text: "<b>Hello</b> <i>World!</i>"
- > font.family: "Helvetica"
- > font.pointSize: 20
- > color: "blue"
- > focus: true
- > }
-- List items with check boxes allow task lists to be incorporated:
- * [ ] This task is not yet done
- * [x] We aced this one!
-
-Ordered lists can be used for tables of contents, for example. Each number
-should end with a period or a parenthesis:
-
-1. Markdown in Qt Quick
- 1) Font and Paragraph Styles
- 5) Hyperlinks
- 3) Images ![red square](red.png)
- 2) Lists
- 4) Tables
-2. Related work
-
-The list will automatically be renumbered during rendering.
-
-## Tables
-
-One of the GitHub extensions is support for tables:
-
-| |Development Tools |Programming Techniques |Graphical User Interfaces|
-|-------------|------------------------------------|---------------------------|-------------------------|
-|9:00 - 11:00 |Introduction to Qt |||
-|11:00 - 13:00|Using Qt Creator |QML and its runtime |Layouts in Qt |
-|13:00 - 15:00|Qt Quick Designer Tutorial |Extreme Programming |Writing Custom Styles |
-|15:00 - 17:00|Qt Linguist and Internationalization| | |
-
-# Related Work
-
-Some Qt Widgets also support Markdown.
-[QTextEdit](https://doc.qt.io/qt-5/qtextedit.html) has similar WYSIWYG
-editing features as TextEdit and TextArea: you can edit the rendered text
-directly. You can use
-[QTextDocument::toMarkdown](https://doc-snapshots.qt.io/qt5-dev/qtextdocument.html#toMarkdown)
-to rewrite the Markdown format, and save it back to a file.
-
-If you have the [KDE Kate Editor](https://kate-editor.org/) installed on your
-system, you probably also have the `markdown.xml` syntax highlighting
-definition file; that can be reused to add Markdown syntax highlighting to
-Qt Creator.
-
-![creator markdown highlighting from Kate](creatorKateHighlighter.png)
-
-Qt owes thanks to the authors of the [MD4C parser](https://github.com/mity/md4c)
-for making markdown import possible. The QTextMarkdownWriter class does not
-have such dependencies, and also has not yet been tested as extensively, so we
-do not yet guarantee that we are able to rewrite every Markdown document that
-you are able to read and display with Text or TextEdit. But you are free to
-write [bugs](https://bugreports.qt.io) about any troublesome cases that you
-encounter.
-
-[creatormanual]: https://doc.qt.io/qtcreator/ "Qt Creator Manual"
diff --git a/examples/quickcontrols2/texteditor/fonts/fontello.ttf b/examples/quickcontrols2/texteditor/fonts/fontello.ttf
deleted file mode 100644
index db957652..00000000
--- a/examples/quickcontrols2/texteditor/fonts/fontello.ttf
+++ /dev/null
Binary files differ
diff --git a/examples/quickcontrols2/texteditor/images/qt-logo.png b/examples/quickcontrols2/texteditor/images/qt-logo.png
deleted file mode 100644
index 2ebc01aa..00000000
--- a/examples/quickcontrols2/texteditor/images/qt-logo.png
+++ /dev/null
Binary files differ
diff --git a/examples/quickcontrols2/texteditor/qml/+touch/texteditor.qml b/examples/quickcontrols2/texteditor/qml/+touch/texteditor.qml
deleted file mode 100644
index 7d7554f4..00000000
--- a/examples/quickcontrols2/texteditor/qml/+touch/texteditor.qml
+++ /dev/null
@@ -1,267 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-import QtQuick
-import QtQuick.Controls
-import QtQuick.Layouts
-import QtQuick.Window
-
-import io.qt.examples.texteditor
-
-// TODO:
-// - make designer-friendly
-
-ApplicationWindow {
- id: window
- visible: true
- title: document.fileName + " - Text Editor Example"
-
- header: ToolBar {
- leftPadding: 5
-
- RowLayout {
- anchors.fill: parent
- spacing: 0
-
- ToolButton {
- id: doneEditingButton
- font.family: "fontello"
- text: "\uE80A" // icon-ok
- opacity: !textArea.readOnly ? 1 : 0
- onClicked: textArea.readOnly = true
- }
-
- Label {
- text: qsTr("Text Editor Example")
- font.bold: true
- font.pixelSize: 20
- elide: Label.ElideRight
- Layout.fillWidth: true
- }
-
- ToolButton {
- font.family: "fontello"
- text: "\uF142" // icon-ellipsis-vert
- onClicked: menu.open()
-
- Menu {
- id: menu
-
- MenuItem {
- text: qsTr("About")
- onTriggered: aboutDialog.open()
- }
- }
- }
- }
- }
-
- DocumentHandler {
- id: document
- document: textArea.textDocument
- cursorPosition: textArea.cursorPosition
- selectionStart: textArea.selectionStart
- selectionEnd: textArea.selectionEnd
- // textColor: TODO
- Component.onCompleted: document.load("qrc:/texteditor.html")
- onLoaded: {
- textArea.text = text
- }
- onError: {
- errorDialog.text = message
- errorDialog.visible = true
- }
- }
-
- Flickable {
- id: flickable
- flickableDirection: Flickable.VerticalFlick
- anchors.fill: parent
-
- TextArea.flickable: TextArea {
- id: textArea
- textFormat: Qt.RichText
- wrapMode: TextArea.Wrap
- readOnly: true
- persistentSelection: true
- // Different styles have different padding and background
- // decorations, but since this editor is almost taking up the
- // entire window, we don't need them.
- leftPadding: 6
- rightPadding: 6
- topPadding: 0
- bottomPadding: 0
- background: null
-
- onLinkActivated: Qt.openUrlExternally(link)
- }
-
- ScrollBar.vertical: ScrollBar {}
- }
-
- footer: ToolBar {
- visible: !textArea.readOnly && textArea.activeFocus
-
- Material.primary: "#E0E0E0"
- Material.elevation: 0
-
- Flickable {
- anchors.fill: parent
- contentWidth: toolRow.implicitWidth
- flickableDirection: Qt.Horizontal
- boundsBehavior: Flickable.StopAtBounds
-
- Row {
- id: toolRow
-
- ToolButton {
- id: boldButton
- text: "\uE800" // icon-bold
- font.family: "fontello"
- // Don't want to close the virtual keyboard when this is clicked.
- focusPolicy: Qt.NoFocus
- checkable: true
- checked: document.bold
- onClicked: document.bold = !document.bold
- }
- ToolButton {
- id: italicButton
- text: "\uE801" // icon-italic
- font.family: "fontello"
- focusPolicy: Qt.NoFocus
- checkable: true
- checked: document.italic
- onClicked: document.italic = !document.italic
- }
- ToolButton {
- id: underlineButton
- text: "\uF0CD" // icon-underline
- font.family: "fontello"
- focusPolicy: Qt.NoFocus
- checkable: true
- checked: document.underline
- onClicked: document.underline = !document.underline
- }
-
- ToolSeparator {}
-
- ToolButton {
- id: alignLeftButton
- text: "\uE803" // icon-align-left
- font.family: "fontello"
- focusPolicy: Qt.NoFocus
- checkable: true
- checked: document.alignment == Qt.AlignLeft
- onClicked: document.alignment = Qt.AlignLeft
- }
- ToolButton {
- id: alignCenterButton
- text: "\uE804" // icon-align-center
- font.family: "fontello"
- focusPolicy: Qt.NoFocus
- checkable: true
- checked: document.alignment == Qt.AlignHCenter
- onClicked: document.alignment = Qt.AlignHCenter
- }
- ToolButton {
- id: alignRightButton
- text: "\uE805" // icon-align-right
- font.family: "fontello"
- focusPolicy: Qt.NoFocus
- checkable: true
- checked: document.alignment == Qt.AlignRight
- onClicked: document.alignment = Qt.AlignRight
- }
- ToolButton {
- id: alignJustifyButton
- text: "\uE806" // icon-align-justify
- font.family: "fontello"
- focusPolicy: Qt.NoFocus
- checkable: true
- checked: document.alignment == Qt.AlignJustify
- onClicked: document.alignment = Qt.AlignJustify
- }
- }
- }
- }
-
- RoundButton {
- id: editButton
- font.family: "fontello"
- text: "\uE809" // icon-pencil
- width: 48
- height: width
- // Don't want to use anchors for the y position, because it will anchor
- // to the footer, leaving a large vertical gap.
- y: parent.height - height - 12
- anchors.right: parent.right
- anchors.margins: 12
- visible: textArea.readOnly
- highlighted: true
-
- onClicked: {
- textArea.readOnly = false
- // Force focus on the text area so the cursor and footer show up.
- textArea.forceActiveFocus()
- }
- }
-
- Dialog {
- id: aboutDialog
- standardButtons: Dialog.Ok
- modal: true
- x: parent.width / 2 - width / 2
- y: parent.height / 2 - height / 2
-
- contentItem: Label {
- text: qsTr("Qt Quick Controls - Text Editor Example")
- }
- }
-}
diff --git a/examples/quickcontrols2/texteditor/qml/texteditor.qml b/examples/quickcontrols2/texteditor/qml/texteditor.qml
deleted file mode 100644
index 0c0f75e1..00000000
--- a/examples/quickcontrols2/texteditor/qml/texteditor.qml
+++ /dev/null
@@ -1,473 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-import QtQuick
-import QtQuick.Controls
-import QtQuick.Window
-import Qt.labs.platform
-
-import io.qt.examples.texteditor
-
-// TODO:
-// - make designer-friendly
-
-ApplicationWindow {
- id: window
- width: 1024
- height: 600
- visible: true
- title: document.fileName + " - Text Editor Example"
-
- Component.onCompleted: {
- x = Screen.width / 2 - width / 2
- y = Screen.height / 2 - height / 2
- }
-
- Shortcut {
- sequence: StandardKey.Open
- onActivated: openDialog.open()
- }
- Shortcut {
- sequence: StandardKey.SaveAs
- onActivated: saveDialog.open()
- }
- Shortcut {
- sequence: StandardKey.Quit
- onActivated: close()
- }
- Shortcut {
- sequence: StandardKey.Copy
- onActivated: textArea.copy()
- }
- Shortcut {
- sequence: StandardKey.Cut
- onActivated: textArea.cut()
- }
- Shortcut {
- sequence: StandardKey.Paste
- onActivated: textArea.paste()
- }
- Shortcut {
- sequence: StandardKey.Bold
- onActivated: document.bold = !document.bold
- }
- Shortcut {
- sequence: StandardKey.Italic
- onActivated: document.italic = !document.italic
- }
- Shortcut {
- sequence: StandardKey.Underline
- onActivated: document.underline = !document.underline
- }
-
- MenuBar {
- Menu {
- title: qsTr("&File")
-
- MenuItem {
- text: qsTr("&Open")
- onTriggered: openDialog.open()
- }
- MenuItem {
- text: qsTr("&Save As...")
- onTriggered: saveDialog.open()
- }
- MenuItem {
- text: qsTr("&Quit")
- onTriggered: close()
- }
- }
-
- Menu {
- title: qsTr("&Edit")
-
- MenuItem {
- text: qsTr("&Copy")
- enabled: textArea.selectedText
- onTriggered: textArea.copy()
- }
- MenuItem {
- text: qsTr("Cu&t")
- enabled: textArea.selectedText
- onTriggered: textArea.cut()
- }
- MenuItem {
- text: qsTr("&Paste")
- enabled: textArea.canPaste
- onTriggered: textArea.paste()
- }
- }
-
- Menu {
- title: qsTr("F&ormat")
-
- MenuItem {
- text: qsTr("&Bold")
- checkable: true
- checked: document.bold
- onTriggered: document.bold = !document.bold
- }
- MenuItem {
- text: qsTr("&Italic")
- checkable: true
- checked: document.italic
- onTriggered: document.italic = !document.italic
- }
- MenuItem {
- text: qsTr("&Underline")
- checkable: true
- checked: document.underline
- onTriggered: document.underline = !document.underline
- }
- }
- }
-
- FileDialog {
- id: openDialog
- fileMode: FileDialog.OpenFile
- selectedNameFilter.index: 1
- nameFilters: ["Text files (*.txt)", "HTML files (*.html *.htm)", "Markdown files (*.md *.markdown)"]
- folder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
- onAccepted: document.load(file)
- }
-
- FileDialog {
- id: saveDialog
- fileMode: FileDialog.SaveFile
- defaultSuffix: document.fileType
- nameFilters: openDialog.nameFilters
- selectedNameFilter.index: document.fileType === "txt" ? 0 : 1
- folder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
- onAccepted: document.saveAs(file)
- }
-
- FontDialog {
- id: fontDialog
- onAccepted: {
- document.fontFamily = font.family;
- document.fontSize = font.pointSize;
- }
- }
-
- ColorDialog {
- id: colorDialog
- currentColor: "black"
- }
-
- MessageDialog {
- id: errorDialog
- }
-
- MessageDialog {
- id : quitDialog
- title: qsTr("Quit?")
- text: qsTr("The file has been modified. Quit anyway?")
- buttons: (MessageDialog.Yes | MessageDialog.No)
- onYesClicked: Qt.quit()
- }
-
- header: ToolBar {
- leftPadding: 8
-
- Flow {
- id: flow
- width: parent.width
-
- Row {
- id: fileRow
- ToolButton {
- id: openButton
- text: "\uF115" // icon-folder-open-empty
- font.family: "fontello"
- onClicked: openDialog.open()
- }
- ToolSeparator {
- contentItem.visible: fileRow.y === editRow.y
- }
- }
-
- Row {
- id: editRow
- ToolButton {
- id: copyButton
- text: "\uF0C5" // icon-docs
- font.family: "fontello"
- focusPolicy: Qt.TabFocus
- enabled: textArea.selectedText
- onClicked: textArea.copy()
- }
- ToolButton {
- id: cutButton
- text: "\uE802" // icon-scissors
- font.family: "fontello"
- focusPolicy: Qt.TabFocus
- enabled: textArea.selectedText
- onClicked: textArea.cut()
- }
- ToolButton {
- id: pasteButton
- text: "\uF0EA" // icon-paste
- font.family: "fontello"
- focusPolicy: Qt.TabFocus
- enabled: textArea.canPaste
- onClicked: textArea.paste()
- }
- ToolSeparator {
- contentItem.visible: editRow.y === formatRow.y
- }
- }
-
- Row {
- id: formatRow
- ToolButton {
- id: boldButton
- text: "\uE800" // icon-bold
- font.family: "fontello"
- focusPolicy: Qt.TabFocus
- checkable: true
- checked: document.bold
- onClicked: document.bold = !document.bold
- }
- ToolButton {
- id: italicButton
- text: "\uE801" // icon-italic
- font.family: "fontello"
- focusPolicy: Qt.TabFocus
- checkable: true
- checked: document.italic
- onClicked: document.italic = !document.italic
- }
- ToolButton {
- id: underlineButton
- text: "\uF0CD" // icon-underline
- font.family: "fontello"
- focusPolicy: Qt.TabFocus
- checkable: true
- checked: document.underline
- onClicked: document.underline = !document.underline
- }
- ToolButton {
- id: fontFamilyToolButton
- text: qsTr("\uE808") // icon-font
- font.family: "fontello"
- font.bold: document.bold
- font.italic: document.italic
- font.underline: document.underline
- onClicked: {
- fontDialog.currentFont.family = document.fontFamily;
- fontDialog.currentFont.pointSize = document.fontSize;
- fontDialog.open();
- }
- }
- ToolButton {
- id: textColorButton
- text: "\uF1FC" // icon-brush
- font.family: "fontello"
- focusPolicy: Qt.TabFocus
- onClicked: colorDialog.open()
-
- Rectangle {
- width: aFontMetrics.width + 3
- height: 2
- color: document.textColor
- parent: textColorButton.contentItem
- anchors.horizontalCenter: parent.horizontalCenter
- anchors.baseline: parent.baseline
- anchors.baselineOffset: 6
-
- TextMetrics {
- id: aFontMetrics
- font: textColorButton.font
- text: textColorButton.text
- }
- }
- }
- ToolSeparator {
- contentItem.visible: formatRow.y === alignRow.y
- }
- }
-
- Row {
- id: alignRow
- ToolButton {
- id: alignLeftButton
- text: "\uE803" // icon-align-left
- font.family: "fontello"
- focusPolicy: Qt.TabFocus
- checkable: true
- checked: document.alignment == Qt.AlignLeft
- onClicked: document.alignment = Qt.AlignLeft
- }
- ToolButton {
- id: alignCenterButton
- text: "\uE804" // icon-align-center
- font.family: "fontello"
- focusPolicy: Qt.TabFocus
- checkable: true
- checked: document.alignment == Qt.AlignHCenter
- onClicked: document.alignment = Qt.AlignHCenter
- }
- ToolButton {
- id: alignRightButton
- text: "\uE805" // icon-align-right
- font.family: "fontello"
- focusPolicy: Qt.TabFocus
- checkable: true
- checked: document.alignment == Qt.AlignRight
- onClicked: document.alignment = Qt.AlignRight
- }
- ToolButton {
- id: alignJustifyButton
- text: "\uE806" // icon-align-justify
- font.family: "fontello"
- focusPolicy: Qt.TabFocus
- checkable: true
- checked: document.alignment == Qt.AlignJustify
- onClicked: document.alignment = Qt.AlignJustify
- }
- }
- }
- }
-
- DocumentHandler {
- id: document
- document: textArea.textDocument
- cursorPosition: textArea.cursorPosition
- selectionStart: textArea.selectionStart
- selectionEnd: textArea.selectionEnd
- textColor: colorDialog.color
- Component.onCompleted: {
- if (Qt.application.arguments.length === 2)
- document.load("file:" + Qt.application.arguments[1]);
- else
- document.load("qrc:/texteditor.html")
- }
- onLoaded: {
- textArea.textFormat = format
- textArea.text = text
- }
- onError: {
- errorDialog.text = message
- errorDialog.visible = true
- }
- }
-
- Flickable {
- id: flickable
- flickableDirection: Flickable.VerticalFlick
- anchors.fill: parent
-
- TextArea.flickable: TextArea {
- id: textArea
- textFormat: Qt.RichText
- wrapMode: TextArea.Wrap
- focus: true
- selectByMouse: true
- persistentSelection: true
- // Different styles have different padding and background
- // decorations, but since this editor is almost taking up the
- // entire window, we don't need them.
- leftPadding: 6
- rightPadding: 6
- topPadding: 0
- bottomPadding: 0
- background: null
-
- MouseArea {
- acceptedButtons: Qt.RightButton
- anchors.fill: parent
- onClicked: contextMenu.open()
- }
-
- onLinkActivated: Qt.openUrlExternally(link)
- }
-
- ScrollBar.vertical: ScrollBar {}
- }
-
- Menu {
- id: contextMenu
-
- MenuItem {
- text: qsTr("Copy")
- enabled: textArea.selectedText
- onTriggered: textArea.copy()
- }
- MenuItem {
- text: qsTr("Cut")
- enabled: textArea.selectedText
- onTriggered: textArea.cut()
- }
- MenuItem {
- text: qsTr("Paste")
- enabled: textArea.canPaste
- onTriggered: textArea.paste()
- }
-
- MenuSeparator {}
-
- MenuItem {
- text: qsTr("Font...")
- onTriggered: fontDialog.open()
- }
-
- MenuItem {
- text: qsTr("Color...")
- onTriggered: colorDialog.open()
- }
- }
-
- onClosing: {
- if (document.modified) {
- quitDialog.open()
- close.accepted = false
- }
- }
-}
diff --git a/examples/quickcontrols2/texteditor/qtquickcontrols2.conf b/examples/quickcontrols2/texteditor/qtquickcontrols2.conf
deleted file mode 100644
index ecac617f..00000000
--- a/examples/quickcontrols2/texteditor/qtquickcontrols2.conf
+++ /dev/null
@@ -1,11 +0,0 @@
-[Controls]
-Style=Material
-
-[Material]
-Primary=White
-Foreground=#444444
-Accent=Blue
-Theme=System
-
-[Universal]
-Theme=System
diff --git a/examples/quickcontrols2/texteditor/red.png b/examples/quickcontrols2/texteditor/red.png
deleted file mode 100644
index 9038fef7..00000000
--- a/examples/quickcontrols2/texteditor/red.png
+++ /dev/null
Binary files differ
diff --git a/examples/quickcontrols2/texteditor/texteditor.cpp b/examples/quickcontrols2/texteditor/texteditor.cpp
deleted file mode 100644
index 9b882dc8..00000000
--- a/examples/quickcontrols2/texteditor/texteditor.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifdef QT_WIDGETS_LIB
-#include <QApplication>
-#else
-#include <QGuiApplication>
-#endif
-#include <QFontDatabase>
-#include <QDebug>
-#include <QQmlApplicationEngine>
-#include <QQmlContext>
-#include <QQmlFileSelector>
-#include <QQuickStyle>
-
-#include "documenthandler.h"
-
-int main(int argc, char *argv[])
-{
- QGuiApplication::setApplicationName("Text Editor");
- QGuiApplication::setOrganizationName("QtProject");
-
-#ifdef QT_WIDGETS_LIB
- QApplication app(argc, argv);
-#else
- QGuiApplication app(argc, argv);
-#endif
-
- if (QFontDatabase::addApplicationFont(":/fonts/fontello.ttf") == -1)
- qWarning() << "Failed to load fontello.ttf";
-
- qmlRegisterType<DocumentHandler>("io.qt.examples.texteditor", 1, 0, "DocumentHandler");
-
- QStringList selectors;
-#ifdef QT_EXTRA_FILE_SELECTOR
- selectors += QT_EXTRA_FILE_SELECTOR;
-#else
- if (app.arguments().contains("-touch"))
- selectors += "touch";
-#endif
-
- QQmlApplicationEngine engine;
- QQmlFileSelector::get(&engine)->setExtraSelectors(selectors);
-
- engine.load(QUrl("qrc:/qml/texteditor.qml"));
- if (engine.rootObjects().isEmpty())
- return -1;
-
- return app.exec();
-}
diff --git a/examples/quickcontrols2/texteditor/texteditor.html b/examples/quickcontrols2/texteditor/texteditor.html
deleted file mode 100644
index 41705f85..00000000
--- a/examples/quickcontrols2/texteditor/texteditor.html
+++ /dev/null
@@ -1,43 +0,0 @@
-<html>
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <meta name="qrichtext" content="1">
- <title>Text Editor Example</title>
- <style type="text/css">
- p,
- body, <!-- specifiying font-size for body seems to be necessary to avoid bullet points being incorrectly positioned -->
- li {
- white-space: pre-wrap;
- font-size:11pt;
- }
- </style>
-</head>
-<body>
- <p align="center">
- <img src="/service/qrc:/images/qt-logo.png" />
- </p>
- <h2 align="center">
- Qt Quick Controls 2
- </h2>
- <p align="center">
- This example demonstrates a modern rich text editor. The UI uses Qt Labs Platforms to provide native menus and dialogs.
- </p>
- <br />
- <br />
- <br />
-
- <p>
- Below you'll find a list of the native controls used in this application.
- </p>
-
- <ul>
- <li><a href="https://doc.qt.io/qt-5/qml-qt-labs-platform-menu.html">Menu</a> - provides a QML API for native platform menu popups.</li>
- <li><a href="https://doc.qt.io/qt-5/qml-qt-labs-platform-menubar.html">MenuBar</a> - provides a QML API for native platform menubars.</li>
- <li><a href="https://doc.qt.io/qt-5/qml-qt-labs-platform-menuitem.html">MenuItem</a> - provides a QML API for native platform menu items.</li>
- <li><a href="https://doc.qt.io/qt-5/qml-qt-labs-platform-filedialog.html">FileDialog</a> - provides a QML API for native platform file dialogs.</li>
- <li><a href="https://doc.qt.io/qt-5/qml-qt-labs-platform-fontdialog.html">FontDialog</a> - provides a QML API for native platform font dialogs.</li>
- <li><a href="https://doc.qt.io/qt-5/qml-qt-labs-platform-colordialog.html">ColorDialog</a> - provides a QML API for native platform color dialogs.</li>
- <li><a href="https://doc.qt.io/qt-5/qml-qt-labs-platform-messagedialog.html">MessageDialog</a> - provides a QML API for native platform message dialogs.</li>
- </ul>
-</body>
-</html>
diff --git a/examples/quickcontrols2/texteditor/texteditor.pro b/examples/quickcontrols2/texteditor/texteditor.pro
deleted file mode 100644
index deb24576..00000000
--- a/examples/quickcontrols2/texteditor/texteditor.pro
+++ /dev/null
@@ -1,22 +0,0 @@
-TEMPLATE = app
-TARGET = texteditor
-QT += quick quickcontrols2
-qtHaveModule(widgets): QT += widgets
-
-cross_compile: DEFINES += QT_EXTRA_FILE_SELECTOR=\\\"touch\\\"
-
-HEADERS += \
- documenthandler.h
-
-SOURCES += \
- texteditor.cpp \
- documenthandler.cpp
-
-OTHER_FILES += \
- qml/*.qml
-
-RESOURCES += \
- texteditor.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/texteditor
-INSTALLS += target
diff --git a/examples/quickcontrols2/texteditor/texteditor.qrc b/examples/quickcontrols2/texteditor/texteditor.qrc
deleted file mode 100644
index 8f2da843..00000000
--- a/examples/quickcontrols2/texteditor/texteditor.qrc
+++ /dev/null
@@ -1,11 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>qtquickcontrols2.conf</file>
- <file>images/qt-logo.png</file>
- <file>fonts/fontello.ttf</file>
- <file>qml/texteditor.qml</file>
- <file>texteditor.html</file>
- <file>qml/+touch/texteditor.qml</file>
- <file>+touch/texteditor.html</file>
- </qresource>
-</RCC>