]> Shamusworld >> Repos - architektonas/blob - src/forms/dlgoptionsgeneral.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / forms / dlgoptionsgeneral.cpp
1 // dlgoptionsgeneral.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  05/18/2010  Added this text. :-)
15 //
16
17 #include "dlgoptionsgeneral.h"
18
19 #include "enums.h"
20 #include "debug.h"
21 #include "settings.h"
22 #include "system.h"
23 #include "units.h"
24
25 DlgOptionsGeneral::DlgOptionsGeneral(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
26         QDialog(parent, flags)
27 {
28         ui.setupUi(this);
29
30 #ifdef QC_PREDEFINED_LOCALE
31         bgLanguage->hide();
32         Widget9Layout->addMultiCellWidget(bgGraphicView, 0, 2, 0, 0); //use empty space as well
33 #endif
34         // Fill combobox with languages:
35         QStringList languageList = SYSTEM->getLanguageList();
36         languageList.prepend("en");
37
38         for(QStringList::Iterator it=languageList.begin(); it!=languageList.end(); it++)
39         {
40                 DEBUG->print("DlgOptionsGeneral::init: adding %s to combobox", (*it).toLatin1().data());
41
42                 QString l = SYSTEM->symbolToLanguage(*it);
43
44                 if (l.isEmpty() == false)
45                 {
46                         DEBUG->print("DlgOptionsGeneral::init: %s", l.toLatin1().data());
47                         ui.cbLanguage->addItem(l);
48                         ui.cbLanguageCmd->addItem(l);
49                 }
50         }
51
52         settings.beginGroup("Appearance");
53
54         // set current language:
55         QString def_lang = "en";
56 #ifdef QC_PREDEFINED_LOCALE
57         def_lang = QC_PREDEFINED_LOCALE;
58 #endif
59         QString lang = settings.value("Language", def_lang).toString();
60 //      ui.cbLanguage->setCurrentText(SYSTEM->symbolToLanguage(lang));
61         ui.cbLanguage->setItemText(ui.cbLanguage->currentIndex(), SYSTEM->symbolToLanguage(lang));
62
63         QString langCmd = settings.value("LanguageCmd", def_lang).toString();
64 //      ui.cbLanguageCmd->setCurrentText(SYSTEM->symbolToLanguage(langCmd));
65         ui.cbLanguageCmd->setItemText(ui.cbLanguageCmd->currentIndex(), SYSTEM->symbolToLanguage(langCmd));
66
67         // graphic view:
68         // crosshairs:
69         bool showCrosshairs = settings.value("ShowCrosshairs", true).toBool();
70         ui.cbShowCrosshairs->setChecked(showCrosshairs);
71
72         // scale grid:
73         bool scaleGrid = settings.value("ScaleGrid", true).toBool();
74         ui.cbScaleGrid->setChecked(scaleGrid);
75         QString minGridSpacing = settings.value("MinGridSpacing", "10").toString();
76 //      ui.cbMinGridSpacing->setCurrentText(minGridSpacing);
77         ui.cbMinGridSpacing->setItemText(ui.cbMinGridSpacing->currentIndex(), minGridSpacing);
78
79         // preview:
80         QString maxPreview = settings.value("MaxPreview", "100").toString();
81 //      ui.cbMaxPreview->setCurrentText(maxPreview);
82         ui.cbMaxPreview->setItemText(ui.cbMaxPreview->currentIndex(), maxPreview);
83
84         // colors:
85         QString backgroundColor = settings.value("BackgroundColor", "Black").toString();
86 //      ui.cbBackgroundColor->setCurrentText(backgroundColor);
87         ui.cbBackgroundColor->setItemText(ui.cbBackgroundColor->currentIndex(), backgroundColor);
88         QString gridColor = settings.value("GridColor", "Gray").toString();
89 //      ui.cbGridColor->setCurrentText(gridColor);
90         ui.cbGridColor->setItemText(ui.cbGridColor->currentIndex(), gridColor);
91         QString metaGridColor = settings.value("MetaGridColor", "#404040").toString();
92 //      ui.cbMetaGridColor->setCurrentText(metaGridColor);
93         ui.cbMetaGridColor->setItemText(ui.cbMetaGridColor->currentIndex(), metaGridColor);
94         QString selectedColor = settings.value("SelectedColor", "#a54747").toString();
95 //      ui.cbSelectedColor->setCurrentText(selectedColor);
96         ui.cbSelectedColor->setItemText(ui.cbSelectedColor->currentIndex(), selectedColor);
97         QString highlightedColor = settings.value("HighlightedColor", "#739373").toString();
98 //      ui.cbHighlightedColor->setCurrentText(highlightedColor);
99         ui.cbHighlightedColor->setItemText(ui.cbHighlightedColor->currentIndex(), highlightedColor);
100
101         // font size:
102         QString sizeStatus = settings.value("StatusBarFontSize", "9").toString();
103 //      ui.cbSizeStatus->setCurrentText(sizeStatus);
104         ui.cbSizeStatus->setItemText(ui.cbSizeStatus->currentIndex(), sizeStatus);
105
106         settings.endGroup();
107
108         settings.beginGroup("Paths");
109         ui.lePathTranslations->setText(settings.value("Translations", "").toString());
110         ui.lePathHatch->setText(settings.value("Patterns", "").toString());
111         ui.lePathFonts->setText(settings.value("Fonts", "").toString());
112         ui.lePathScripts->setText(settings.value("Scripts", "").toString());
113         ui.lePathLibrary->setText(settings.value("Library", "").toString());
114         settings.endGroup();
115
116         ui.cbUnit->setInsertPolicy(QComboBox::InsertAlphabetically);
117
118         // units:
119         for(int i=RS2::None; i<RS2::LastUnit; i++)
120         {
121                 if (i != (int)RS2::None)
122                         ui.cbUnit->addItem(Units::unitToString((RS2::Unit)i));
123         }
124
125 //should be [DONE]
126 //#warning "Need to port to Qt4... !!! FIX !!!"
127 //#if 0
128 //      cbUnit->listBox()->sort();
129 //#endif
130         ui.cbUnit->setInsertPolicy(QComboBox::InsertAtBottom);
131         ui.cbUnit->addItem(Units::unitToString(RS2::None), 0);
132
133         QString def_unit = "Millimeter";
134 #ifdef QC_PREDEFINED_UNIT
135         def_unit = QC_PREDEFINED_UNIT;
136 #endif
137         settings.beginGroup("Defaults");
138 //      ui.cbUnit->setCurrentText(QObject::tr(RS_SETTINGS->readEntry("/Unit", def_unit)));
139 //      ui.cbUnit->setItemText(ui.cbUnit->currentIndex(), QObject::tr(RS_SETTINGS->readEntry("/Unit", def_unit)));
140         ui.cbUnit->setItemText(ui.cbUnit->currentIndex(), (settings.value("Unit", def_unit).toString()));
141         settings.endGroup();
142
143         restartNeeded = false;
144 }
145
146 DlgOptionsGeneral::~DlgOptionsGeneral()
147 {
148 }
149
150 void DlgOptionsGeneral::setRestartNeeded()
151 {
152         restartNeeded = true;
153 }
154
155 void DlgOptionsGeneral::ok()
156 {
157         //SYSTEM->loadTranslation(cbLanguage->currentText());
158         settings.beginGroup("Appearance");
159         settings.setValue("Language", SYSTEM->languageToSymbol(ui.cbLanguage->currentText()));
160         settings.setValue("LanguageCmd", SYSTEM->languageToSymbol(ui.cbLanguageCmd->currentText()));
161         settings.setValue("ShowCrosshairs", ui.cbShowCrosshairs->isChecked());
162         settings.setValue("ScaleGrid", ui.cbScaleGrid->isChecked());
163         settings.setValue("MinGridSpacing", ui.cbMinGridSpacing->currentText());
164         settings.setValue("MaxPreview", ui.cbMaxPreview->currentText());
165         settings.setValue("BackgroundColor", ui.cbBackgroundColor->currentText());
166         settings.setValue("GridColor", ui.cbGridColor->currentText());
167         settings.setValue("MetaGridColor", ui.cbMetaGridColor->currentText());
168         settings.setValue("SelectedColor", ui.cbSelectedColor->currentText());
169         settings.setValue("HighlightedColor", ui.cbHighlightedColor->currentText());
170         settings.setValue("StatusBarFontSize", ui.cbSizeStatus->currentText());
171         settings.endGroup();
172
173         settings.beginGroup("Paths");
174         settings.setValue("Translations", ui.lePathTranslations->text());
175         settings.setValue("Patterns", ui.lePathHatch->text());
176         settings.setValue("Fonts", ui.lePathFonts->text());
177         settings.setValue("Scripts", ui.lePathScripts->text());
178         settings.setValue("Library", ui.lePathLibrary->text());
179         settings.endGroup();
180
181         settings.beginGroup("Defaults");
182         settings.setValue("Unit", Units::unitToString(Units::stringToUnit(ui.cbUnit->currentText()), false/*untr.*/));
183         settings.endGroup();
184
185         if (restartNeeded == true)
186         {
187                 QMessageBox::warning( this, tr("Preferences"),
188                         tr("Please restart the application to apply all changes."), QMessageBox::Ok, Qt::NoButton);
189         }
190
191         accept();
192         //return true;
193 }