1 /*
2 * Copyright (c) 2004 Christian Loose <christian.loose@kdemail.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include "resolvedialog_p.h"
20 #include "cervisiasettings.h"
21
22 #include <kconfig.h>
23 #include <QPlainTextEdit>
24 #include <kconfiggroup.h>
25 #include <KConfigGroup>
26 #include <QDialogButtonBox>
27 #include <QPushButton>
28 #include <QVBoxLayout>
29
30 using namespace Cervisia;
31
32
ResolveEditorDialog(KConfig & cfg,QWidget * parent)33 ResolveEditorDialog::ResolveEditorDialog(KConfig& cfg, QWidget *parent)
34 : QDialog(parent)
35 , m_partConfig(cfg)
36 {
37 setModal(true);
38
39 QVBoxLayout *mainLayout = new QVBoxLayout;
40 setLayout(mainLayout);
41
42 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
43 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
44 okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
45 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
46 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
47
48 m_edit = new QPlainTextEdit(this);
49 m_edit->setFont(CervisiaSettings::diffFont());
50 m_edit->setFocus();
51
52 mainLayout->addWidget(m_edit);
53 mainLayout->addWidget(buttonBox);
54
55 QFontMetrics const fm(fontMetrics());
56 resize(fm.width('0') * 120, fm.lineSpacing() * 40);
57
58 KConfigGroup cg(&m_partConfig, "ResolveEditorDialog");
59 restoreGeometry(cg.readEntry<QByteArray>("geometry", QByteArray()));
60 }
61
62
~ResolveEditorDialog()63 ResolveEditorDialog::~ResolveEditorDialog()
64 {
65 KConfigGroup cg(&m_partConfig, "ResolveEditorDialog");
66 cg.writeEntry("geometry", saveGeometry());
67 }
68
69
setContent(const QString & text)70 void ResolveEditorDialog::setContent(const QString& text)
71 {
72 m_edit->setPlainText(text);
73 }
74
75
content() const76 QString ResolveEditorDialog::content() const
77 {
78 return m_edit->toPlainText();
79 }
80