Support multiline text

Use rich text editor widget as dialog for multiline text input

Change-Id: I13147e776867032fe1145d6a8a37fcd6976399e4
Task-number: QDS-2229
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Lukasz Ornatek
2020-07-20 12:09:18 +02:00
committed by Łukasz Ornatek
parent ce926844d0
commit a7c14b5493
5 changed files with 217 additions and 5 deletions

View File

@@ -26,6 +26,8 @@
import QtQuick 2.1
import HelperWidgets 2.0
import QtQuick.Layouts 1.0
import StudioControls 1.0 as StudioControls
import StudioTheme 1.0 as StudioTheme
Section {
anchors.left: parent.left
@@ -46,11 +48,31 @@ Section {
Label {
text: qsTr("Text")
}
RowLayout {
LineEdit {
backendValue: backendValues.text
Layout.fillWidth: true
}
StudioControls.AbstractButton {
id: richTextEditorButton
buttonIcon: StudioTheme.Constants.textAlignTop
onClicked: {
richTextDialogLoader.show()
}
}
RichTextEditor{
onRejected: {
hideWidget()
}
onAccepted: {
hideWidget()
}
}
}
Label {
visible: showVerticalAlignment
text: qsTr("Wrap mode")
@@ -219,4 +241,38 @@ Section {
Layout.fillWidth: true
}
}
Loader {
id: richTextDialogLoader
visible: false
active: visible
function show() {
richTextDialogLoader.visible = true
}
sourceComponent: Item {
id: richTextEditorParent
Component.onCompleted: {
richTextEditor.showWidget()
richTextEditor.richText = backendValues.text.value
}
RichTextEditor {
id: richTextEditor
onRejected: {
hideWidget()
richTextDialogLoader.visible = false
}
onAccepted: {
backendValues.text.value = richTextEditor.richText
hideWidget()
richTextDialogLoader.visible = false
}
}
}
}
}

View File

@@ -40,6 +40,7 @@
#include "aligndistribute.h"
#include "propertyeditorcontextobject.h"
#include "tooltip.h"
#include "richtexteditor/richtexteditorproxy.h"
namespace QmlDesigner {
@@ -69,6 +70,7 @@ void Quick2PropertyEditorView::registerQmlTypes()
AlignDistribute::registerDeclarativeType();
Tooltip::registerDeclarativeType();
EasingCurveEditor::registerDeclarativeType();
RichTextEditorProxy::registerDeclarativeType();
}
}

View File

@@ -1,7 +1,9 @@
HEADERS += $$PWD/richtexteditor.h
HEADERS += $$PWD/richtexteditor.h \
$$PWD/richtexteditorproxy.h
HEADERS += $$PWD/hyperlinkdialog.h
SOURCES += $$PWD/richtexteditor.cpp
SOURCES += $$PWD/richtexteditor.cpp \
$$PWD/richtexteditorproxy.cpp
SOURCES += $$PWD/hyperlinkdialog.cpp
FORMS += $$PWD/richtexteditor.ui

View File

@@ -0,0 +1,87 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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 General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "richtexteditorproxy.h"
#include <QDialog>
#include <QDialogButtonBox>
#include "richtexteditor.h"
namespace QmlDesigner {
RichTextEditorProxy::RichTextEditorProxy(QObject *parent)
: QObject(parent)
, m_dialog(new QDialog{})
, m_widget(new RichTextEditor{})
{
QGridLayout *layout = new QGridLayout{};
layout->addWidget(m_widget);
QDialogButtonBox *standardButtons = new QDialogButtonBox{QDialogButtonBox::Ok
| QDialogButtonBox::Cancel};
connect(standardButtons, &QDialogButtonBox::accepted, m_dialog, &QDialog::accept);
connect(standardButtons, &QDialogButtonBox::rejected, m_dialog, &QDialog::reject);
layout->addWidget(standardButtons);
m_dialog->setLayout(layout);
connect(m_dialog, &QDialog::accepted, [this]() { emit accepted(); });
connect(m_dialog, &QDialog::rejected, [this]() { emit rejected(); });
}
RichTextEditorProxy::~RichTextEditorProxy()
{
delete m_dialog;
}
void RichTextEditorProxy::registerDeclarativeType()
{
qmlRegisterType<RichTextEditorProxy>("HelperWidgets", 2, 0, "RichTextEditor");
}
void RichTextEditorProxy::showWidget()
{
m_dialog->show();
}
void RichTextEditorProxy::hideWidget()
{
m_dialog->hide();
}
QString RichTextEditorProxy::richText() const
{
return m_widget->richText();
}
void RichTextEditorProxy::setRichText(const QString &text)
{
m_widget->setRichText(text);
}
} // namespace QmlDesigner

View File

@@ -0,0 +1,65 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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 General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <QObject>
#include <QQuickItem>
QT_BEGIN_NAMESPACE
class QDialog;
QT_END_NAMESPACE
namespace QmlDesigner {
class RichTextEditor;
class RichTextEditorProxy : public QObject
{
Q_OBJECT
Q_PROPERTY(QString richText READ richText WRITE setRichText)
public:
explicit RichTextEditorProxy(QObject *parent = nullptr);
~RichTextEditorProxy();
static void registerDeclarativeType();
Q_INVOKABLE void showWidget();
Q_INVOKABLE void hideWidget();
QString richText() const;
void setRichText(const QString &text);
signals:
void accepted();
void rejected();
private:
QDialog *m_dialog;
RichTextEditor *m_widget;
};
} // namespace QmlDesigner