-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsettings_dialog.cpp
109 lines (82 loc) · 2.97 KB
/
settings_dialog.cpp
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// ---------------------------------------------------------------------
//
// Copyright (C) 2017 by Martin Steigemann and Wolfgang Bangerth
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------
#include "settings_dialog.h"
#include <QErrorMessage>
#include <QFontDialog>
#include <QPushButton>
#include <QFormLayout>
namespace dealii
{
namespace ParameterGui
{
SettingsDialog::SettingsDialog(QSettings *gui_settings,
QWidget *parent)
: QDialog(parent, 0)
{
setWindowTitle("Settings");
settings = gui_settings;
loadSettings();
QFormLayout * grid = new QFormLayout(this);
// add a choose font button
change_font = new QPushButton(this);
change_font->setText(QErrorMessage::tr("Change font"));
connect(change_font, SIGNAL(clicked()), this, SLOT(selectFont()));
grid->addRow("Change Font",change_font);
// add a checkbox
hide_default = new QCheckBox(this);
hide_default->setChecked(hide_default_values);
connect(hide_default, SIGNAL(stateChanged(int)), this, SLOT(changeHideDefault(int)));
grid->addRow("Hide default values",hide_default);
// add an OK button
ok = new QPushButton(this);
ok->setText(QErrorMessage::tr("&OK"));
connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
// add a Cancel button
cancel = new QPushButton(this);
cancel->setText(QErrorMessage::tr("&Cancel"));
connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
grid->addRow(ok,cancel);
connect(this, SIGNAL(accepted()), this, SLOT(writeSettings()));
}
void SettingsDialog::selectFont()
{
bool ok;
QFont new_font = QFontDialog::getFont(
&ok, selected_font, this);
if (ok) {
selected_font = new_font;
}
}
void SettingsDialog::changeHideDefault(int state)
{
hide_default_values = state;
}
void SettingsDialog::loadSettings()
{
settings->beginGroup("Settings");
hide_default_values = settings->value("hideDefault", false).toBool();
QString stored_font_string = settings->value("Font", QFont().toString()).toString();
selected_font.fromString(stored_font_string);
settings->endGroup();
}
void SettingsDialog::writeSettings()
{
settings->beginGroup("Settings");
settings->setValue("hideDefault", hide_default_values);
settings->setValue("Font", selected_font.toString());
settings->endGroup();
}
}
}