1 /*
2 * texteditordialog.cpp
3 * Copyright 2016, Thorbjørn Lindeijer <bjorn@lindeijer.nl>
4 *
5 * This file is part of Tiled.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "texteditordialog.h"
22 #include "ui_texteditordialog.h"
23
24 #include "session.h"
25 #include "utils.h"
26
27 namespace Tiled {
28
29 namespace session {
30 static SessionOption<bool> monospace { "textEdit.monospace", true };
31 } // namespace session
32
TextEditorDialog(QWidget * parent)33 TextEditorDialog::TextEditorDialog(QWidget *parent)
34 : QDialog(parent)
35 , mUi(new Ui::TextEditorDialog)
36 {
37 mUi->setupUi(this);
38 resize(Utils::dpiScaled(size()));
39 #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
40 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
41 #endif
42
43 connect(mUi->monospaceFont, &QAbstractButton::toggled, [this] (bool checked) {
44 mUi->plainTextEdit->setStyleSheet(checked ? QStringLiteral("font-family: monospace;")
45 : QString());
46 session::monospace.set(checked);
47 });
48
49 mUi->monospaceFont->setChecked(session::monospace);
50
51 Utils::restoreGeometry(this);
52 }
53
~TextEditorDialog()54 TextEditorDialog::~TextEditorDialog()
55 {
56 Utils::saveGeometry(this);
57 delete mUi;
58 }
59
setText(const QString & text)60 void TextEditorDialog::setText(const QString &text)
61 {
62 mUi->plainTextEdit->setPlainText(text);
63 }
64
text() const65 QString TextEditorDialog::text() const
66 {
67 return mUi->plainTextEdit->toPlainText();
68 }
69
changeEvent(QEvent * e)70 void TextEditorDialog::changeEvent(QEvent *e)
71 {
72 QDialog::changeEvent(e);
73 switch (e->type()) {
74 case QEvent::LanguageChange:
75 mUi->retranslateUi(this);
76 break;
77 default:
78 break;
79 }
80 }
81
82 } // namespace Tiled
83
84 #include "moc_texteditordialog.cpp"
85