-
Notifications
You must be signed in to change notification settings - Fork 0
/
globalpreferences.cpp
executable file
·126 lines (110 loc) · 3.82 KB
/
globalpreferences.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "globalpreferences.h"
#include "ui_globalpreferences.h"
#include <qvariant.h>
#include <qmessagebox.h>
#include <qimage.h>
#include <qdir.h>
#include <qfile.h>
#include <QImageWriter>
#include <QTextStream>
#include <QFileDialog>
#include "config.h"
/**
* Constructs a GlobalPreferences as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
GlobalPreferences::GlobalPreferences(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
: QDialog(parent, fl)
{
this->setWindowTitle(name);
this->setModal(modal);
setupUi(this);
init();
}
/*
* Destroys the object and frees any allocated resources
*/
GlobalPreferences::~GlobalPreferences()
{
destroy();
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void GlobalPreferences::languageChange()
{
retranslateUi(this);
}
void GlobalPreferences::init()
{
QString str;
for (int i=0; i< QImageWriter::supportedImageFormats().count(); i++){
str = QImageWriter::supportedImageFormats().at(i);
imageFormatComboBox->addItem(str);
}
connect( imageFormatComboBox, SIGNAL(activated(int)), this, SLOT(changeImageFormat(int)) );
}
void GlobalPreferences::destroy()
{
}
void GlobalPreferences::changeImageFormat(int i)
{
imageFormatComboBox->setCurrentIndex(i);
}
/**
@fn slotOk
@brief Writes all global preferences seen on the dialog to a file when
the OK button is clicked.
The method slotOk writes the user's settings a file when the OK button
on the dialog is clicked.
*/
void GlobalPreferences::slotOk()
{
//make dir if it doesn't exist
QDir cuview;
if(!cuview.exists(QDir::homePath()+"/.cuviewer"))
cuview.mkdir(QDir::homePath()+"/.cuviewer");
//write everything to $home/.cuview/cuviewrc
QFile *file = new QFile(QDir::home().path()+"/.cuviewer/cuviewrc-"+VERSION);
// file->remove();
file->setFileName(QDir::home().path()+"/.cuviewer/cuviewrc-"+VERSION);
if(file->open(QIODevice::ReadWrite)){
QTextStream ts(file);
ts << QString("General preferences for cuviewer\n");
ts << QString("restore_ws %1\n").arg((int)restoreWSCheck->isChecked());
ts << QString("show_sscreen %1\n").arg((int)showSplashScreenCheck->isChecked());
if(docPathLineEdit->text().isEmpty()){
docPathLineEdit->setText(DOCUMENTATION);
}
ts << QString("doc_path %1\n").arg(docPathLineEdit->text());
ts << QString("update_display %1\n").arg(updateDisplayButtonGroup->id(updateDisplayButtonGroup->checkedButton()));
ts << QString("box_model %1\n").arg((int)boxModelCheck->isChecked());
ts << QString("box_model_always %1\n").arg((int)drawBoxAlwaysCheck->isChecked());
ts << QString("drawaxis %1\n").arg((int)drawAxisCheck->isChecked());
ts << QString("drawaxisorigin %1\n").arg((int)drawAxisOriginCheck->isChecked());
ts << QString("mouse_buttons %1\n").arg(mouseButtonsSpinBox->text());
QString fmt = imageFormatComboBox->currentText();
ts << QString("image_format %1\n").arg(fmt.isEmpty() ? QString("?"):fmt);
ts << QString("direct_rendering %1\n").arg((int)directRenderingCheck->isChecked());
ts << QString("bin_palettes %1\n").arg(binPalettesSpinBox->text());
ts << QString("startUpRefresh %1\n").arg((int)startUpRefreshCheck->isChecked());
ts << QString("execute_scriptfile %1\n").arg((int)openScriptFileCheck->isChecked());
ts << QString("scriptfile %1\n").arg(scriptFileNameLineEdit->text());
file->close();
}
else
qDebug("Can't save prefs to file");
delete file;
accept();
}
void GlobalPreferences::changeDocPath(){
QString dirPath(QFileDialog::getExistingDirectory());
if (!dirPath.isEmpty()){
docPathLineEdit->setText(dirPath);
}
}