summaryrefslogtreecommitdiff
path: root/cad/plugins/NanoVision-1/src/PreferencesDialog.cpp
blob: 543b3853e49657b17bc9cb4c505b9e6e6456c244 (plain)
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
109
110
111
112
113
114
115
116
// Copyright 2008 Nanorex, Inc.  See LICENSE file for details.

#include "PreferencesDialog.h"


/* CONSTRUCTORS */
PreferencesDialog::PreferencesDialog(QWidget *parent)
		: QDialog(parent), Ui_PreferencesDialog() {
		
	setupUi(this);
	
	UserSettings* settings = UserSettings::Instance();
	
	// General/Miscellaneous
	int state = Qt::Checked;
	if (!settings->value("Miscellaneous/SaveWindowSizeOnExit").toBool())
		state = Qt::Unchecked;
	saveWindowSizeCheckBox->setCheckState((Qt::CheckState)state);
	
	// General/Logging
	state = Qt::Checked;
	if (!settings->value("Logging/EnableFileLogging").toBool())
		state = Qt::Unchecked;
	logToFileCheckBoxChanged(state);
	fileLogDetailComboBox->setCurrentIndex
		(settings->value("Logging/FileLoggingLevel").toInt());
	fileLogFilenameLineEdit->setText
		(settings->value("Logging/FileLoggingFilename").toString());
	state = Qt::Checked;
	if (!settings->value("Logging/EnableConsoleLogging").toBool())
		state = Qt::Unchecked;
	logToConsoleCheckBoxChanged(state);
	consoleLogDetailComboBox->setCurrentIndex
		(settings->value("Logging/ConsoleLoggingLevel").toInt());
	
	connect(logToFileCheckBox, SIGNAL(stateChanged(int)),
			this, SLOT(logToFileCheckBoxChanged(int)));
	connect(logToConsoleCheckBox, SIGNAL(stateChanged(int)),
			this, SLOT(logToConsoleCheckBoxChanged(int)));
	connect(fileLogBrowseButton, SIGNAL(clicked(bool)),
			this, SLOT(fileLogBrowseButtonClicked(bool)));
}


/* DESTRUCTOR */
PreferencesDialog::~PreferencesDialog() {
}


/* FUNCTION: accept */
void PreferencesDialog::accept() {
	UserSettings* settings = UserSettings::Instance();

	// General/Miscellaneous
	settings->setValue("Miscellaneous/SaveWindowSizeOnExit",
					   saveWindowSizeCheckBox->checkState() == Qt::Checked);

	// General/Logging
	settings->setValue("Logging/EnableFileLogging",
					   logToFileCheckBox->checkState() == Qt::Checked);
	settings->setValue("Logging/FileLoggingLevel",
					   fileLogDetailComboBox->currentIndex());
	settings->setValue("Logging/FileLoggingFilename",
					   fileLogFilenameLineEdit->text());
	settings->setValue("Logging/EnableConsoleLogging",
					   logToFileCheckBox->checkState() == Qt::Checked);
	settings->setValue("Logging/ConsoleLoggingLevel",
					   fileLogDetailComboBox->currentIndex());

	settings->sync();
	QDialog::accept();
}


/* FUNCTION: logToFileCheckBoxChanged */
void PreferencesDialog::logToFileCheckBoxChanged(int state) {
	if (state == Qt::Checked) {
		logToFileCheckBox->setCheckState(Qt::Checked);
		fileLogDetailLabel->setEnabled(true);
		fileLogDetailComboBox->setEnabled(true);
		fileLogFilenameLineEdit->setEnabled(true);
		fileLogBrowseButton->setEnabled(true);
		
	} else {
		logToFileCheckBox->setCheckState(Qt::Unchecked);
		fileLogDetailLabel->setEnabled(false);
		fileLogDetailComboBox->setEnabled(false);
		fileLogFilenameLineEdit->setEnabled(false);
		fileLogBrowseButton->setEnabled(false);
	}
}


/* FUNCTION: logToConsoleCheckBoxChanged */
void PreferencesDialog::logToConsoleCheckBoxChanged(int state) {
	if (state == Qt::Checked) {
		logToConsoleCheckBox->setCheckState(Qt::Checked);
		consoleLogDetailLabel->setEnabled(true);
		consoleLogDetailComboBox->setEnabled(true);
		
	} else {
		logToConsoleCheckBox->setCheckState(Qt::Unchecked);
		consoleLogDetailLabel->setEnabled(false);
		consoleLogDetailComboBox->setEnabled(false);
	}
}


/* FUNCTION: fileLogBrowseButtonClicked */
void PreferencesDialog::fileLogBrowseButtonClicked(bool checked) {
	QString filename =
		QFileDialog::getSaveFileName(this, tr("Choose a file to log to"),
									 fileLogFilenameLineEdit->text());
	fileLogFilenameLineEdit->setText(filename);
}