1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Designer of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include "plaintexteditor_p.h"
30
31#include <QtDesigner/abstractsettings.h>
32#include <QtDesigner/abstractformeditor.h>
33
34#include <QtWidgets/qplaintextedit.h>
35#include <QtWidgets/qdialogbuttonbox.h>
36#include <QtWidgets/qboxlayout.h>
37#include <QtWidgets/qpushbutton.h>
38
39QT_BEGIN_NAMESPACE
40
41static const char *PlainTextDialogC = "PlainTextDialog";
42static const char *Geometry = "Geometry";
43
44
45namespace qdesigner_internal {
46
47PlainTextEditorDialog::PlainTextEditorDialog(QDesignerFormEditorInterface *core, QWidget *parent) :
48 QDialog(parent),
49 m_editor(new QPlainTextEdit),
50 m_core(core)
51{
52 setWindowTitle(tr(s: "Edit text"));
53 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
54
55 QVBoxLayout *vlayout = new QVBoxLayout(this);
56 vlayout->addWidget(m_editor);
57
58 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);
59 QPushButton *ok_button = buttonBox->button(which: QDialogButtonBox::Ok);
60 ok_button->setDefault(true);
61 connect(sender: buttonBox, signal: &QDialogButtonBox::accepted, receiver: this, slot: &QDialog::accept);
62 connect(sender: buttonBox, signal: &QDialogButtonBox::rejected, receiver: this, slot: &QDialog::reject);
63 vlayout->addWidget(buttonBox);
64
65 QDesignerSettingsInterface *settings = core->settingsManager();
66 settings->beginGroup(prefix: QLatin1String(PlainTextDialogC));
67
68 if (settings->contains(key: QLatin1String(Geometry)))
69 restoreGeometry(geometry: settings->value(key: QLatin1String(Geometry)).toByteArray());
70
71 settings->endGroup();
72}
73
74PlainTextEditorDialog::~PlainTextEditorDialog()
75{
76 QDesignerSettingsInterface *settings = m_core->settingsManager();
77 settings->beginGroup(prefix: QLatin1String(PlainTextDialogC));
78
79 settings->setValue(key: QLatin1String(Geometry), value: saveGeometry());
80 settings->endGroup();
81}
82
83int PlainTextEditorDialog::showDialog()
84{
85 m_editor->setFocus();
86 return exec();
87}
88
89void PlainTextEditorDialog::setDefaultFont(const QFont &font)
90{
91 m_editor->setFont(font);
92}
93
94void PlainTextEditorDialog::setText(const QString &text)
95{
96 m_editor->setPlainText(text);
97}
98
99QString PlainTextEditorDialog::text() const
100{
101 return m_editor->toPlainText();
102}
103
104} // namespace qdesigner_internal
105
106QT_END_NAMESPACE
107

source code of qttools/src/designer/src/lib/shared/plaintexteditor.cpp