2 Copyright (C) 2015-2016 Montel Laurent <montel@kde.org>
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 "editorpage.h"
21 #include "editorwidget.h"
22 #include "previewwidget.h"
23 #include "themeeditorwidget.h"
24 #include "themetemplatewidget.h"
25 #include "contactprintthemepreview.h"
26 #include "contactprintthemeeditorutil.h"
27 #include "kpimtextedit/plaintexteditor.h"
28 #include "KSplitterCollapserButton"
30 #include <KLocalizedString>
32 #include <KConfigGroup>
35 #include <QVBoxLayout>
36 #include <KSharedConfig>
38 EditorPage::EditorPage(GrantleeThemeEditor::EditorPage::PageType type
, const QString
&projectDirectory
, QWidget
*parent
)
39 : GrantleeThemeEditor::EditorPage(type
, parent
),
43 QVBoxLayout
*lay
= new QVBoxLayout
;
46 mMainSplitter
= new QSplitter
;
47 if (mType
== MainPage
) {
48 mWidgetSplitter
= new QSplitter
;
49 mWidgetSplitter
->setOrientation(Qt::Vertical
);
50 mWidgetSplitter
->setChildrenCollapsible(false);
51 lay
->addWidget(mWidgetSplitter
);
53 mWidgetSplitter
->addWidget(mMainSplitter
);
55 mPreview
= new ContactPrintThemePreview(projectDirectory
);
56 mWidgetSplitter
->addWidget(mPreview
);
57 connect(mPreview
, &ContactPrintThemePreview::needUpdateViewer
, this, &EditorPage::needUpdateViewer
);
59 lay
->addWidget(mMainSplitter
);
62 mEditor
= new ThemeEditorWidget
;
64 if (mType
== MainPage
) {
65 ContactPrintThemeEditorutil contactUtil
;
66 KConfigGroup
group(KSharedConfig::openConfig(), QStringLiteral("Global"));
67 mEditor
->setPlainText(group
.readEntry("defaultTemplate", contactUtil
.defaultTemplate()));
69 mMainSplitter
->addWidget(mEditor
);
70 mThemeTemplate
= new ThemeTemplateWidget(i18n("Theme Templates:"));
71 connect(mThemeTemplate
, &ThemeTemplateWidget::insertTemplate
, mEditor
->editor(), &QPlainTextEdit::insertPlainText
);
72 mMainSplitter
->addWidget(mThemeTemplate
);
73 mMainSplitter
->setCollapsible(0, false);
74 new KSplitterCollapserButton(mThemeTemplate
, mMainSplitter
);
76 connect(mEditor
->editor(), &QPlainTextEdit::textChanged
, this, &GrantleeThemeEditor::EditorPage::changed
);
78 if (mType
== MainPage
) {
79 KConfigGroup
group(KSharedConfig::openConfig(), "EditorPage");
82 mMainSplitter
->setSizes(group
.readEntry("mainSplitter", size
));
83 mWidgetSplitter
->setSizes(group
.readEntry("widgetSplitter", size
));
88 EditorPage::~EditorPage()
90 if (mType
== MainPage
) {
91 KConfigGroup
group(KSharedConfig::openConfig(), "EditorPage");
92 group
.writeEntry("mainSplitter", mMainSplitter
->sizes());
93 group
.writeEntry("widgetSplitter", mWidgetSplitter
->sizes());
97 ContactPrintThemePreview
*EditorPage::preview() const