~ubuntu-branches/debian/sid/universalindentgui/sid

« back to all changes in this revision

Viewing changes to src/uiguisettingsdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Pipping
  • Date: 2008-04-02 04:45:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080402044500-abd7znu1tri14n29
Tags: 0.8.1-1
* New upstream release
* debian/rules: Do not delete perltidy as it's no longer shipped
* debian/rules: Cleanup extended

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
*   Copyright (C) 2006-2008 by Thomas Schweitzer                          *
3
 
*   thomas-schweitzer(at)arcor.de                                         *
4
 
*                                                                         *
5
 
*   This program is free software; you can redistribute it and/or modify  *
6
 
*   it under the terms of the GNU General Public License version 2.0 as   *
7
 
*   published by the Free Software Foundation.                            *
8
 
*                                                                         *
9
 
*   This program is distributed in the hope that it will be useful,       *
10
 
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 
*   GNU General Public License for more details.                          *
13
 
*                                                                         *
14
 
*   You should have received a copy of the GNU General Public License     *
15
 
*   along with this program in the file LICENSE.GPL; if not, write to the *
16
 
*   Free Software Foundation, Inc.,                                       *
17
 
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 
***************************************************************************/
19
 
 
20
 
#include "uiguisettingsdialog.h"
21
 
 
22
 
/*!
23
 
        \class UiGuiSettingsDialog
24
 
    \ingroup grp_Settings
25
 
        \brief Displays a dialog window with settings for UniversalIndentGUI
26
 
*/
27
 
 
28
 
/*!
29
 
        \brief The constructor calls the setup function for the ui created by uic. and adds
30
 
*/
31
 
UiGuiSettingsDialog::UiGuiSettingsDialog(QWidget* parent, UiGuiSettings* settings) : QDialog(parent)
32
 
{
33
 
    // Remember pointer to the UiGuiSettings object.
34
 
    this->settings = settings;
35
 
 
36
 
    // Init the user interface created by the UIC.
37
 
        setupUi(this);
38
 
        //TODO: This has to be removed when the properties for the highlighters can be set.
39
 
        groupBoxSyntaxHighlighterProperties->setToolTip( "(Will be implemented soon)" + groupBoxSyntaxHighlighterProperties->toolTip() );
40
 
 
41
 
    // Get all check boxes that are used for settings.
42
 
    checkBoxes = findChildren<QCheckBox*>( QRegExp("uiGui*") );
43
 
 
44
 
    // Get all spin boxes that are used for settings.
45
 
    spinBoxes = findChildren<QSpinBox*>( QRegExp("uiGui*") );
46
 
 
47
 
    // Get all combo boxes that are used for settings.
48
 
    comboBoxes = findChildren<QComboBox*>( QRegExp("uiGui*") );
49
 
 
50
 
    // Connect the accepted signal to own function, to write values back to the UiGuiSettings object.
51
 
    connect(this, SIGNAL(accepted()), this, SLOT(writeWidgetValuesToSettings()) );
52
 
 
53
 
        // Init the language selection combobox.
54
 
        initTranslationSelection();
55
 
}
56
 
 
57
 
/*!
58
 
        \brief By calling this function the combobox for selecting the application language will
59
 
        be initialized. 
60
 
    
61
 
    Also the translation itself will be reinitialized.
62
 
 */
63
 
void UiGuiSettingsDialog::initTranslationSelection() {
64
 
        // First empty the combo box.
65
 
        uiGuiLanguage->clear();
66
 
        
67
 
        // Now add an entry into the box for every language short.
68
 
        foreach (QString languageShort, settings->getAvailableTranslations() ) {
69
 
                // Identify the language mnemonic and set the full name.
70
 
                if ( languageShort == "en" ) {
71
 
                        uiGuiLanguage->addItem( QIcon(QString(":/language/language-"+languageShort+".png")), tr("English") );
72
 
                }
73
 
                else if ( languageShort == "de" ) {
74
 
                        uiGuiLanguage->addItem( QIcon(QString(":/language/language-"+languageShort+".png")), tr("German") );
75
 
                }
76
 
                else if ( languageShort == "zh_TW" ) {
77
 
                        uiGuiLanguage->addItem( QIcon(QString(":/language/language-"+languageShort+".png")), tr("Chinese (Taiwan)") );
78
 
                }
79
 
                else if ( languageShort == "ja_JP" ) {
80
 
                        uiGuiLanguage->addItem( QIcon(QString(":/language/language-"+languageShort+".png")), tr("Japanese") );
81
 
                }
82
 
                else {
83
 
                        uiGuiLanguage->addItem( tr("Unknown language mnemonic ") + languageShort );
84
 
                }
85
 
        }
86
 
}
87
 
 
88
 
 
89
 
/*!
90
 
    \brief Displays the dialog by calling the dialogs exec function. 
91
 
    
92
 
    Before it gets all the values needed from the UiGuiSettings object.
93
 
 */
94
 
int UiGuiSettingsDialog::showDialog() {
95
 
    // Get the values for the check boxes from the settings object.
96
 
    foreach (QCheckBox* checkBox, checkBoxes) {
97
 
        // Get the objects name and remove "uiGui" from its beginning.
98
 
        QString objectName = checkBox->objectName();
99
 
        objectName.remove(0,5);
100
 
 
101
 
        // Get value from settings and assign it to the checkbox.
102
 
        bool value = settings->getValueByName( objectName ).toBool();
103
 
        checkBox->setChecked(value);
104
 
    }
105
 
 
106
 
    // Get the values for the spin boxes from the settings object.
107
 
    foreach (QSpinBox* spinBox, spinBoxes) {
108
 
        // Get the objects name and remove "uiGui" from its beginning.
109
 
        QString objectName = spinBox->objectName();
110
 
        objectName.remove(0,5);
111
 
 
112
 
        // Get value from settings and assign it to the checkbox.
113
 
        int value = settings->getValueByName( objectName ).toInt();
114
 
        spinBox->setValue(value);
115
 
    }
116
 
 
117
 
    // Get the values for the combo boxes from the settings object.
118
 
    foreach (QComboBox* comboBox, comboBoxes) {
119
 
        // Get the objects name and remove "uiGui" from its beginning.
120
 
        QString objectName = comboBox->objectName();
121
 
        objectName.remove(0,5);
122
 
 
123
 
        // Get value from settings and assign it to the checkbox.
124
 
        int value = settings->getValueByName( objectName ).toInt();
125
 
        comboBox->setCurrentIndex(value);
126
 
    }
127
 
 
128
 
    // Execute the dialog.
129
 
    return exec();
130
 
}
131
 
 
132
 
 
133
 
/*!
134
 
    \brief This slot is called when the dialog box is closed by pressing the Ok button.
135
 
 
136
 
    Writes all settings to the UiGuiSettings object.
137
 
 */
138
 
void UiGuiSettingsDialog::writeWidgetValuesToSettings() {
139
 
    // Write the values of the check boxes to the settings object.
140
 
    foreach (QCheckBox* checkBox, checkBoxes) {
141
 
        // Get the objects name and remove "uiGui" from its beginning.
142
 
        QString objectName = checkBox->objectName();
143
 
        objectName.remove(0,5);
144
 
 
145
 
        // Write the check box value to the settings.
146
 
        settings->setValueByName( objectName, checkBox->isChecked() );
147
 
    }
148
 
 
149
 
    // Write the values for the spin boxes to the settings object.
150
 
    foreach (QSpinBox* spinBox, spinBoxes) {
151
 
        // Get the objects name and remove "uiGui" from its beginning.
152
 
        QString objectName = spinBox->objectName();
153
 
        objectName.remove(0,5);
154
 
 
155
 
        // Write the spin box value to the settings.
156
 
        settings->setValueByName( objectName, spinBox->value() );
157
 
    }
158
 
 
159
 
    // Write the values for the spin boxes to the settings object.
160
 
    foreach (QComboBox* comboBox, comboBoxes) {
161
 
        // Get the objects name and remove "uiGui" from its beginning.
162
 
        QString objectName = comboBox->objectName();
163
 
        objectName.remove(0,5);
164
 
 
165
 
        // Write the spin box value to the settings.
166
 
        settings->setValueByName( objectName, comboBox->currentIndex() );
167
 
    }
168
 
}
169
 
 
170
 
 
171
 
/*!
172
 
    \brief Catches language change events and retranslates all needed widgets.
173
 
 */
174
 
void UiGuiSettingsDialog::changeEvent(QEvent *event) {
175
 
    if (event->type() == QEvent::LanguageChange) {
176
 
        retranslateUi(this);
177
 
        // If this is not explicit set here, Qt < 4.3.0 does not translate the buttons.
178
 
        buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok);
179
 
 
180
 
                //TODO: This has to be removed when the properties for the highlighters can be set.
181
 
                groupBoxSyntaxHighlighterProperties->setToolTip( "(Will be implemented soon)" + groupBoxSyntaxHighlighterProperties->toolTip() );
182
 
                uiGuiRecentlyOpenedListSize->setToolTip( "(Will be implemented soon)" + uiGuiRecentlyOpenedListSize->toolTip() );
183
 
 
184
 
        QStringList languageShortList = settings->getAvailableTranslations();
185
 
 
186
 
        // Now retranslate every entry in the language selection box.
187
 
        for (int i = 0; i < languageShortList.size(); i++ ) {
188
 
            QString languageShort = languageShortList.at(i);
189
 
 
190
 
            // Identify the language mnemonic and set the full name.
191
 
            if ( languageShort == "en" ) {
192
 
                uiGuiLanguage->setItemText( i, tr("English") );
193
 
            }
194
 
            else if ( languageShort == "de" ) {
195
 
                uiGuiLanguage->setItemText( i, tr("German") );
196
 
            }
197
 
            else if ( languageShort == "zh_TW" ) {
198
 
                uiGuiLanguage->setItemText( i, tr("Chinese (Taiwan)") );
199
 
            }
200
 
            else if ( languageShort == "ja_JP" ) {
201
 
                uiGuiLanguage->setItemText( i, tr("Japanese") );
202
 
            }
203
 
            else {
204
 
                uiGuiLanguage->setItemText( i, tr("Unknown language mnemonic ") + languageShort );
205
 
            }
206
 
        }
207
 
    } 
208
 
    else {
209
 
        QWidget::changeEvent(event);
210
 
    }
211
 
}
 
1
/***************************************************************************
 
2
*   Copyright (C) 2006-2008 by Thomas Schweitzer                          *
 
3
*   thomas-schweitzer(at)arcor.de                                         *
 
4
*                                                                         *
 
5
*   This program is free software; you can redistribute it and/or modify  *
 
6
*   it under the terms of the GNU General Public License version 2.0 as   *
 
7
*   published by the Free Software Foundation.                            *
 
8
*                                                                         *
 
9
*   This program is distributed in the hope that it will be useful,       *
 
10
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
11
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
12
*   GNU General Public License for more details.                          *
 
13
*                                                                         *
 
14
*   You should have received a copy of the GNU General Public License     *
 
15
*   along with this program in the file LICENSE.GPL; if not, write to the *
 
16
*   Free Software Foundation, Inc.,                                       *
 
17
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
18
***************************************************************************/
 
19
 
 
20
#include "uiguisettingsdialog.h"
 
21
 
 
22
/*!
 
23
        \class UiGuiSettingsDialog
 
24
    \ingroup grp_Settings
 
25
        \brief Displays a dialog window with settings for UniversalIndentGUI
 
26
*/
 
27
 
 
28
/*!
 
29
        \brief The constructor calls the setup function for the ui created by uic. and adds
 
30
*/
 
31
UiGuiSettingsDialog::UiGuiSettingsDialog(QWidget* parent, UiGuiSettings* settings) : QDialog(parent)
 
32
{
 
33
    // Remember pointer to the UiGuiSettings object.
 
34
    this->settings = settings;
 
35
 
 
36
    // Init the user interface created by the UIC.
 
37
        setupUi(this);
 
38
        //TODO: This has to be removed when the properties for the highlighters can be set.
 
39
        groupBoxSyntaxHighlighterProperties->setToolTip( "(Will be implemented soon)" + groupBoxSyntaxHighlighterProperties->toolTip() );
 
40
 
 
41
    // Get all check boxes that are used for settings.
 
42
    checkBoxes = findChildren<QCheckBox*>( QRegExp("uiGui*") );
 
43
 
 
44
    // Get all spin boxes that are used for settings.
 
45
    spinBoxes = findChildren<QSpinBox*>( QRegExp("uiGui*") );
 
46
 
 
47
    // Get all combo boxes that are used for settings.
 
48
    comboBoxes = findChildren<QComboBox*>( QRegExp("uiGui*") );
 
49
 
 
50
    // Connect the accepted signal to own function, to write values back to the UiGuiSettings object.
 
51
    connect(this, SIGNAL(accepted()), this, SLOT(writeWidgetValuesToSettings()) );
 
52
 
 
53
        // Init the language selection combobox.
 
54
        initTranslationSelection();
 
55
}
 
56
 
 
57
/*!
 
58
        \brief By calling this function the combobox for selecting the application language will
 
59
        be initialized. 
 
60
    
 
61
    Also the translation itself will be reinitialized.
 
62
 */
 
63
void UiGuiSettingsDialog::initTranslationSelection() {
 
64
        // First empty the combo box.
 
65
        uiGuiLanguage->clear();
 
66
        
 
67
        // Now add an entry into the box for every language short.
 
68
        foreach (QString languageShort, settings->getAvailableTranslations() ) {
 
69
                // Identify the language mnemonic and set the full name.
 
70
                if ( languageShort == "en" ) {
 
71
                        uiGuiLanguage->addItem( QIcon(QString(":/language/language-"+languageShort+".png")), tr("English") );
 
72
                }
 
73
                else if ( languageShort == "de" ) {
 
74
                        uiGuiLanguage->addItem( QIcon(QString(":/language/language-"+languageShort+".png")), tr("German") );
 
75
                }
 
76
                else if ( languageShort == "zh_TW" ) {
 
77
                        uiGuiLanguage->addItem( QIcon(QString(":/language/language-"+languageShort+".png")), tr("Chinese (Taiwan)") );
 
78
                }
 
79
                else if ( languageShort == "ja_JP" ) {
 
80
                        uiGuiLanguage->addItem( QIcon(QString(":/language/language-"+languageShort+".png")), tr("Japanese") );
 
81
                }
 
82
        else if ( languageShort == "ru" ) {
 
83
            uiGuiLanguage->addItem( QIcon(QString(":/language/language-"+languageShort+".png")), tr("Russian") );
 
84
        }
 
85
        else if ( languageShort == "uk" ) {
 
86
            uiGuiLanguage->addItem( QIcon(QString(":/language/language-"+languageShort+".png")), tr("Ukrainian") );
 
87
        }
 
88
                else {
 
89
                        uiGuiLanguage->addItem( tr("Unknown language mnemonic ") + languageShort );
 
90
                }
 
91
        }
 
92
}
 
93
 
 
94
 
 
95
/*!
 
96
    \brief Displays the dialog by calling the dialogs exec function. 
 
97
    
 
98
    Before it gets all the values needed from the UiGuiSettings object.
 
99
 */
 
100
int UiGuiSettingsDialog::showDialog() {
 
101
    // Get the values for the check boxes from the settings object.
 
102
    foreach (QCheckBox* checkBox, checkBoxes) {
 
103
        // Get the objects name and remove "uiGui" from its beginning.
 
104
        QString objectName = checkBox->objectName();
 
105
        objectName.remove(0,5);
 
106
 
 
107
        // Get value from settings and assign it to the checkbox.
 
108
        bool value = settings->getValueByName( objectName ).toBool();
 
109
        checkBox->setChecked(value);
 
110
    }
 
111
 
 
112
    // Get the values for the spin boxes from the settings object.
 
113
    foreach (QSpinBox* spinBox, spinBoxes) {
 
114
        // Get the objects name and remove "uiGui" from its beginning.
 
115
        QString objectName = spinBox->objectName();
 
116
        objectName.remove(0,5);
 
117
 
 
118
        // Get value from settings and assign it to the checkbox.
 
119
        int value = settings->getValueByName( objectName ).toInt();
 
120
        spinBox->setValue(value);
 
121
    }
 
122
 
 
123
    // Get the values for the combo boxes from the settings object.
 
124
    foreach (QComboBox* comboBox, comboBoxes) {
 
125
        // Get the objects name and remove "uiGui" from its beginning.
 
126
        QString objectName = comboBox->objectName();
 
127
        objectName.remove(0,5);
 
128
 
 
129
        // Get value from settings and assign it to the checkbox.
 
130
        int value = settings->getValueByName( objectName ).toInt();
 
131
        comboBox->setCurrentIndex(value);
 
132
    }
 
133
 
 
134
    // Execute the dialog.
 
135
    return exec();
 
136
}
 
137
 
 
138
 
 
139
/*!
 
140
    \brief This slot is called when the dialog box is closed by pressing the Ok button.
 
141
 
 
142
    Writes all settings to the UiGuiSettings object.
 
143
 */
 
144
void UiGuiSettingsDialog::writeWidgetValuesToSettings() {
 
145
    // Write the values of the check boxes to the settings object.
 
146
    foreach (QCheckBox* checkBox, checkBoxes) {
 
147
        // Get the objects name and remove "uiGui" from its beginning.
 
148
        QString objectName = checkBox->objectName();
 
149
        objectName.remove(0,5);
 
150
 
 
151
        // Write the check box value to the settings.
 
152
        settings->setValueByName( objectName, checkBox->isChecked() );
 
153
    }
 
154
 
 
155
    // Write the values for the spin boxes to the settings object.
 
156
    foreach (QSpinBox* spinBox, spinBoxes) {
 
157
        // Get the objects name and remove "uiGui" from its beginning.
 
158
        QString objectName = spinBox->objectName();
 
159
        objectName.remove(0,5);
 
160
 
 
161
        // Write the spin box value to the settings.
 
162
        settings->setValueByName( objectName, spinBox->value() );
 
163
    }
 
164
 
 
165
    // Write the values for the spin boxes to the settings object.
 
166
    foreach (QComboBox* comboBox, comboBoxes) {
 
167
        // Get the objects name and remove "uiGui" from its beginning.
 
168
        QString objectName = comboBox->objectName();
 
169
        objectName.remove(0,5);
 
170
 
 
171
        // Write the spin box value to the settings.
 
172
        settings->setValueByName( objectName, comboBox->currentIndex() );
 
173
    }
 
174
}
 
175
 
 
176
 
 
177
/*!
 
178
    \brief Catches language change events and retranslates all needed widgets.
 
179
 */
 
180
void UiGuiSettingsDialog::changeEvent(QEvent *event) {
 
181
    if (event->type() == QEvent::LanguageChange) {
 
182
        retranslateUi(this);
 
183
        // If this is not explicit set here, Qt < 4.3.0 does not translate the buttons.
 
184
        buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok);
 
185
 
 
186
                //TODO: This has to be removed when the properties for the highlighters can be set.
 
187
                groupBoxSyntaxHighlighterProperties->setToolTip( "(Will be implemented soon)" + groupBoxSyntaxHighlighterProperties->toolTip() );
 
188
                uiGuiRecentlyOpenedListSize->setToolTip( "(Will be implemented soon)" + uiGuiRecentlyOpenedListSize->toolTip() );
 
189
 
 
190
        QStringList languageShortList = settings->getAvailableTranslations();
 
191
 
 
192
        // Now retranslate every entry in the language selection box.
 
193
        for (int i = 0; i < languageShortList.size(); i++ ) {
 
194
            QString languageShort = languageShortList.at(i);
 
195
 
 
196
            // Identify the language mnemonic and set the full name.
 
197
            if ( languageShort == "en" ) {
 
198
                uiGuiLanguage->setItemText( i, tr("English") );
 
199
            }
 
200
            else if ( languageShort == "de" ) {
 
201
                uiGuiLanguage->setItemText( i, tr("German") );
 
202
            }
 
203
            else if ( languageShort == "zh_TW" ) {
 
204
                uiGuiLanguage->setItemText( i, tr("Chinese (Taiwan)") );
 
205
            }
 
206
            else if ( languageShort == "ja_JP" ) {
 
207
                uiGuiLanguage->setItemText( i, tr("Japanese") );
 
208
            }
 
209
            else if ( languageShort == "ru" ) {
 
210
                uiGuiLanguage->setItemText( i, tr("Russian") );
 
211
            }
 
212
            else if ( languageShort == "uk" ) {
 
213
                uiGuiLanguage->setItemText( i, tr("Ukrainian") );
 
214
            }
 
215
            else {
 
216
                uiGuiLanguage->setItemText( i, tr("Unknown language mnemonic ") + languageShort );
 
217
            }
 
218
        }
 
219
    } 
 
220
    else {
 
221
        QWidget::changeEvent(event);
 
222
    }
 
223
}