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
96
97
98
99
100
101
102
103
104
105
106
|
/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Designer of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:COMM$
**
** 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.
**
** $QT_END_LICENSE$
**
**
**
**
**
**
**
**
****************************************************************************/
#include "plaintexteditor_p.h"
#include <QtDesigner/abstractsettings.h>
#include <QtDesigner/abstractformeditor.h>
#include <QtWidgets/qplaintextedit.h>
#include <QtWidgets/qdialogbuttonbox.h>
#include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qpushbutton.h>
QT_BEGIN_NAMESPACE
static const char *PlainTextDialogC = "PlainTextDialog";
static const char *Geometry = "Geometry";
namespace qdesigner_internal {
PlainTextEditorDialog::PlainTextEditorDialog(QDesignerFormEditorInterface *core, QWidget *parent) :
QDialog(parent),
m_editor(new QPlainTextEdit),
m_core(core)
{
setWindowTitle(tr("Edit text"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
QVBoxLayout *vlayout = new QVBoxLayout(this);
vlayout->addWidget(m_editor);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);
QPushButton *ok_button = buttonBox->button(QDialogButtonBox::Ok);
ok_button->setDefault(true);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
vlayout->addWidget(buttonBox);
QDesignerSettingsInterface *settings = core->settingsManager();
settings->beginGroup(QLatin1String(PlainTextDialogC));
if (settings->contains(QLatin1String(Geometry)))
restoreGeometry(settings->value(QLatin1String(Geometry)).toByteArray());
settings->endGroup();
}
PlainTextEditorDialog::~PlainTextEditorDialog()
{
QDesignerSettingsInterface *settings = m_core->settingsManager();
settings->beginGroup(QLatin1String(PlainTextDialogC));
settings->setValue(QLatin1String(Geometry), saveGeometry());
settings->endGroup();
}
int PlainTextEditorDialog::showDialog()
{
m_editor->setFocus();
return exec();
}
void PlainTextEditorDialog::setDefaultFont(const QFont &font)
{
m_editor->setFont(font);
}
void PlainTextEditorDialog::setText(const QString &text)
{
m_editor->setPlainText(text);
}
QString PlainTextEditorDialog::text() const
{
return m_editor->toPlainText();
}
} // namespace qdesigner_internal
QT_END_NAMESPACE
|