2 Copyright (c) 2013-2015 Montel Laurent <montel@kde.org>
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License, version 2, as
6 published by the Free Software Foundation.
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #include "editorpage.h"
19 #include "editorwidget.h"
20 #include "previewwidget.h"
21 #include "themeeditorwidget.h"
22 #include "themetemplatewidget.h"
23 #include "kpimtextedit/plaintexteditor.h"
24 #include "KSplitterCollapserButton"
26 #include <KLocalizedString>
28 #include <KConfigGroup>
31 #include <QVBoxLayout>
32 #include <KSharedConfig>
34 EditorPage::EditorPage(GrantleeThemeEditor::EditorPage::PageType type
, const QString
&projectDirectory
, QWidget
*parent
)
35 : GrantleeThemeEditor::EditorPage(type
, parent
),
38 QVBoxLayout
*lay
= new QVBoxLayout
;
40 mMainSplitter
= new QSplitter
;
41 if (mType
== MainPage
) {
42 mWidgetSplitter
= new QSplitter
;
43 mWidgetSplitter
->setOrientation(Qt::Vertical
);
44 mWidgetSplitter
->setChildrenCollapsible(false);
45 lay
->addWidget(mWidgetSplitter
);
47 mWidgetSplitter
->addWidget(mMainSplitter
);
49 mPreview
= new PreviewWidget(projectDirectory
);
50 mWidgetSplitter
->addWidget(mPreview
);
51 connect(mPreview
, &PreviewWidget::needUpdateViewer
, this, &EditorPage::needUpdateViewer
);
53 lay
->addWidget(mMainSplitter
);
56 mEditor
= new ThemeEditorWidget
;
58 if (mType
== MainPage
) {
59 KConfigGroup
group(KSharedConfig::openConfig(), QStringLiteral("Global"));
60 mEditor
->setPlainText(group
.readEntry("defaultTemplate", QString()));
62 mMainSplitter
->addWidget(mEditor
);
63 mThemeTemplate
= new ThemeTemplateWidget(i18n("Theme Templates:"));
64 connect(mThemeTemplate
, &ThemeTemplateWidget::insertTemplate
, mEditor
->editor(), &QPlainTextEdit::insertPlainText
);
65 mMainSplitter
->addWidget(mThemeTemplate
);
66 mMainSplitter
->setCollapsible(0, false);
67 new KSplitterCollapserButton(mThemeTemplate
, mMainSplitter
);
69 connect(mEditor
->editor(), &QPlainTextEdit::textChanged
, this, &GrantleeThemeEditor::EditorPage::changed
);
71 if (mType
== MainPage
) {
72 KConfigGroup
group(KSharedConfig::openConfig(), "EditorPage");
75 mMainSplitter
->setSizes(group
.readEntry("mainSplitter", size
));
76 mWidgetSplitter
->setSizes(group
.readEntry("widgetSplitter", size
));
81 EditorPage::~EditorPage()
83 if (mType
== MainPage
) {
84 KConfigGroup
group(KSharedConfig::openConfig(), "EditorPage");
85 group
.writeEntry("mainSplitter", mMainSplitter
->sizes());
86 group
.writeEntry("widgetSplitter", mWidgetSplitter
->sizes());
90 GrantleeThemeEditor::PreviewWidget
*EditorPage::preview() const