File: configdialog.cpp

package info (click to toggle)
ktikz 0.11~git20161122-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 5,248 kB
  • ctags: 1,225
  • sloc: cpp: 10,302; xml: 701; sh: 150; makefile: 29
file content (94 lines) | stat: -rw-r--r-- 3,842 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/***************************************************************************
 *   Copyright (C) 2007, 2008, 2009, 2011, 2014                            *
 *     by Glad Deschrijver <glad.deschrijver@gmail.com>                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, see <http://www.gnu.org/licenses/>.  *
 ***************************************************************************/

#include "configdialog.h"

#include <QtGui/QKeyEvent>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QtWidgets/QWhatsThis>
#else
#include <QtGui/QWhatsThis>
#endif

#include "configappearancewidget.h"
#include "configeditorwidget.h"
#include "configgeneralwidget.h"
#include "configpreviewwidget.h"
#include "ktikzapplication.h"
#include "../common/utils/icon.h"

ConfigDialog::ConfigDialog(QWidget *parent) : PageDialog(parent)
{
	setCaption(tr("Configure %1").arg(KtikzApplication::applicationName()));
	setHelp(QLatin1String("chap-configuration"));

	m_configGeneralWidget = new ConfigGeneralWidget(this);
	m_configEditorWidget = new ConfigEditorWidget(this);
	m_configAppearanceWidget = new ConfigAppearanceWidget(this);
	m_configPreviewWidget = new ConfigPreviewWidget(this);
	addPage(m_configGeneralWidget, tr("&General"), QLatin1String("preferences-desktop-theme"));
	addPage(m_configEditorWidget, tr("&Editor"), QLatin1String("accessories-text-editor"));
	addPage(m_configAppearanceWidget, tr("&Highlighting"), QLatin1String("preferences-desktop-color"));
	addPage(m_configPreviewWidget, tr("&Preview"), QLatin1String("preferences-desktop-theme"));
}

void ConfigDialog::readSettings()
{
	m_configGeneralWidget->readSettings(QString());
	m_configEditorWidget->readSettings(QLatin1String("Editor"));
	m_configAppearanceWidget->readSettings(QLatin1String("Highlighting"));
	m_configPreviewWidget->readSettings(QLatin1String("Preview"));
}

void ConfigDialog::writeSettings()
{
	m_configGeneralWidget->writeSettings(QString());
	m_configEditorWidget->writeSettings(QLatin1String("Editor"));
	m_configAppearanceWidget->writeSettings(QLatin1String("Highlighting"));
	m_configPreviewWidget->writeSettings(QLatin1String("Preview"));
}

void ConfigDialog::setTranslatedHighlightTypeNames(const QStringList &typeNames)
{
	Q_FOREACH (const QString &typeName, typeNames)
		m_configAppearanceWidget->addItem(typeName);
}

void ConfigDialog::setHighlightTypeNames(const QStringList &typeNames)
{
	m_configAppearanceWidget->setTypeNames(typeNames);
}

void ConfigDialog::setDefaultHighlightFormats(const QMap<QString, QTextCharFormat> &defaultFormatList)
{
	m_configAppearanceWidget->setDefaultTextCharFormats(defaultFormatList);
}

void ConfigDialog::accept()
{
	writeSettings();
	Q_EMIT settingsChanged();
	QDialog::accept();
}

void ConfigDialog::keyPressEvent(QKeyEvent *event)
{
	if (event->key() == Qt::Key_F1 && event->modifiers() == Qt::ShiftModifier)
		QWhatsThis::enterWhatsThisMode();
	QDialog::keyPressEvent(event);
}