Fix no newlines warnings. Patch by Peter Oberndorfer
[kdevelopdvcssupport.git] / plugins / sourceformatter / editstyledialog.cpp
blob15fd44718a8d0bfb96c156bce76ec6d8161f9a3c
1 /* This file is part of KDevelop
2 * Copyright (C) 2008 Cédric Pasteur <cedric.pasteur@free.fr>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
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 GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "editstyledialog.h"
22 #include <QVBoxLayout>
23 #include <KMessageBox>
24 #include <ktexteditor/document.h>
25 #include <ktexteditor/view.h>
26 #include <ktexteditor/editor.h>
27 #include <ktexteditor/editorchooser.h>
28 #include <ktexteditor/configinterface.h>
30 #include <util/interfaces/isourceformatter.h>
32 EditStyleDialog::EditStyleDialog(ISourceFormatter *formatter, const KMimeType::Ptr &mime,
33 const QString &content, QWidget *parent)
34 : KDialog(parent), m_sourceFormatter(formatter), m_mimeType(mime)
36 m_content = new QWidget();
37 m_ui.setupUi(m_content);
38 setMainWidget(m_content);
40 m_settingsWidget = m_sourceFormatter->editStyleWidget(mime);
41 if (m_settingsWidget && !content.isEmpty())
42 m_settingsWidget->load(QString(), content);
43 init();
46 EditStyleDialog::~EditStyleDialog()
50 void EditStyleDialog::init()
52 // add plugin settings widget
53 if(m_settingsWidget) {
54 QVBoxLayout *layout = new QVBoxLayout(m_ui.settingsWidgetParent);
55 layout->addWidget(m_settingsWidget);
56 m_ui.settingsWidgetParent->setLayout(layout);
57 connect(m_settingsWidget, SIGNAL(previewTextChanged(const QString&)),
58 this, SLOT(updatePreviewText(const QString&)));
61 // add texteditor preview
62 KTextEditor::Editor *editor = KTextEditor::EditorChooser::editor();
63 if (!editor)
64 KMessageBox::error(this, i18n("A KDE text-editor component could not be found.\n"
65 "Please check your KDE installation."));
67 m_document = editor->createDocument(this);
68 m_document->setReadWrite(false);
69 QString mode = m_sourceFormatter->highlightModeForMime(m_mimeType);
70 m_document->setHighlightingMode(mode);
72 m_view = qobject_cast<KTextEditor::View*>(
73 m_document->createView(m_ui.textEditor));
74 QVBoxLayout *layout2 = new QVBoxLayout(m_ui.textEditor);
75 layout2->addWidget(m_view);
76 m_ui.textEditor->setLayout(layout2);
77 m_view->show();
79 KTextEditor::ConfigInterface *iface =
80 qobject_cast<KTextEditor::ConfigInterface*>(m_view);
81 if (iface) {
82 iface->setConfigValue("dynamic-word-wrap", false);
83 iface->setConfigValue("icon-bar", false);
86 if (m_sourceFormatter)
87 updatePreviewText(m_sourceFormatter->previewText(m_mimeType));
90 void EditStyleDialog::updatePreviewText(const QString &text)
92 m_document->setReadWrite(true);
93 if (m_sourceFormatter)
94 m_document->setText(text);
95 m_document->setReadWrite(false);
98 QString EditStyleDialog::content()
100 if(m_settingsWidget)
101 return m_settingsWidget->save();
102 return QString();
105 #include "editstyledialog.moc"
106 // kate: indent-mode cstyle; space-indent off; tab-width 4;