Mercurial > hg > forks > UniversalIndentGUI
comparison src/MainWindow.cpp @ 751:ac165b6ae67e
Done some refactoring:
- Moved includes into the cpp files where possible and using class pre-declarations if possible
- Made class member variable names begin with an underscore
- Made by uic created header files be used as class members instead of inherting them
- Renamed some variables to reflect their purpose better
- Added some NULL initializations and added some comments
- Rearranged some include and declaration code parts to be consistent and better readable
- Updated for QScintilla 2.4.5
- Made UiGuiSettings be accessed via a shared pointer only
git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@1028 59b1889a-e5ac-428c-b0c7-476e01d41282
author | thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282> |
---|---|
date | Thu, 14 Oct 2010 19:52:47 +0000 |
parents | 1109652dbb56 |
children | 4ec2ac09969d |
comparison
equal
deleted
inserted
replaced
750:a884b5861e93 | 751:ac165b6ae67e |
---|---|
16 * Free Software Foundation, Inc., * | 16 * Free Software Foundation, Inc., * |
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | 17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 ***************************************************************************/ | 18 ***************************************************************************/ |
19 | 19 |
20 #include "MainWindow.h" | 20 #include "MainWindow.h" |
21 #include "ui_MainWindow.h" | |
21 | 22 |
22 #include "UiGuiVersion.h" | 23 #include "UiGuiVersion.h" |
23 #include "UiGuiLogger.h" | 24 #include "UiGuiLogger.h" |
25 #include "SettingsPaths.h" | |
26 | |
27 #include "ui_ToolBarWidget.h" | |
28 #include "AboutDialog.h" | |
29 #include "AboutDialogGraphicsView.h" | |
30 #include "UiGuiSettings.h" | |
31 #include "UiGuiSettingsDialog.h" | |
32 #include "UiGuiHighlighter.h" | |
33 #include "IndentHandler.h" | |
34 #include "UpdateCheckDialog.h" | |
35 | |
36 #include <QWidget> | |
37 #include <QLabel> | |
38 #include <QString> | |
39 #include <QScrollBar> | |
40 #include <QTextCursor> | |
41 #include <QFileDialog> | |
42 #include <QTextStream> | |
43 #include <QTextDocument> | |
44 #include <QPrinter> | |
45 #include <QPrintDialog> | |
46 #include <QCloseEvent> | |
47 #include <QHelpEvent> | |
48 #include <QToolTip> | |
49 #include <QTranslator> | |
50 #include <QLocale> | |
51 #include <QTextCodec> | |
52 #include <QDate> | |
53 #include <QUrl> | |
54 #include <QMessageBox> | |
55 #include <QtDebug> | |
56 | |
57 #include <Qsci/qsciscintilla.h> | |
58 #include <Qsci/qsciprinter.h> | |
24 | 59 |
25 //! \defgroup grp_MainWindow All concerning main window functionality. | 60 //! \defgroup grp_MainWindow All concerning main window functionality. |
26 | 61 |
27 /*! | 62 /*! |
28 \class MainWindow | 63 \class MainWindow |
35 */ | 70 */ |
36 | 71 |
37 /*! | 72 /*! |
38 \brief Constructs the main window. | 73 \brief Constructs the main window. |
39 */ | 74 */ |
40 MainWindow::MainWindow(QString file2OpenOnStart, QWidget *parent) : QMainWindow(parent), qSciSourceCodeEditor(NULL) { | 75 MainWindow::MainWindow(QString file2OpenOnStart, QWidget *parent) : QMainWindow(parent) |
76 , _mainWindowForm(NULL) | |
77 , _qSciSourceCodeEditor(NULL) | |
78 , _settings(NULL) | |
79 , _highlighter(NULL) | |
80 , _textEditVScrollBar(NULL) | |
81 , _aboutDialog(NULL) | |
82 , _aboutDialogGraphicsView(NULL) | |
83 , _settingsDialog(NULL) | |
84 , _encodingActionGroup(NULL) | |
85 , _saveEncodedActionGroup(NULL) | |
86 , _highlighterActionGroup(NULL) | |
87 , _uiGuiTranslator(NULL) | |
88 , _qTTranslator(NULL) | |
89 , _toolBarWidget(NULL) | |
90 , _indentHandler(NULL) | |
91 , _updateCheckDialog(NULL) | |
92 , _textEditLineColumnInfoLabel(NULL) | |
93 { | |
41 // Init of some variables. | 94 // Init of some variables. |
42 sourceCodeChanged = false; | 95 _sourceCodeChanged = false; |
43 scrollPositionChanged = false; | 96 _scrollPositionChanged = false; |
44 | 97 |
45 // Create the settings object, which loads all UiGui settings from a file. | 98 // Create the _settings object, which loads all UiGui settings from a file. |
46 settings = UiGuiSettings::getInstance(); | 99 _settings = UiGuiSettings::getInstance(); |
47 | 100 |
48 // Initialize the language of the application. | 101 // Initialize the language of the application. |
49 initApplicationLanguage(); | 102 initApplicationLanguage(); |
50 | 103 |
51 // Creates the main window and initializes it. | 104 // Creates the main window and initializes it. |
67 createEncodingMenu(); | 120 createEncodingMenu(); |
68 createHighlighterMenu(); | 121 createHighlighterMenu(); |
69 | 122 |
70 | 123 |
71 // Generate about dialog box | 124 // Generate about dialog box |
72 aboutDialog = new AboutDialog(this, Qt::SplashScreen); | 125 _aboutDialog = new AboutDialog(this, Qt::SplashScreen); |
73 aboutDialogGraphicsView = new AboutDialogGraphicsView(aboutDialog, this); | 126 _aboutDialogGraphicsView = new AboutDialogGraphicsView(_aboutDialog, this); |
74 connect( toolBarWidget->pbAbout, SIGNAL(clicked()), this, SLOT(showAboutDialog()) ); | 127 connect( _toolBarWidget->pbAbout, SIGNAL(clicked()), this, SLOT(showAboutDialog()) ); |
75 connect( actionAbout_UniversalIndentGUI, SIGNAL(triggered()), this, SLOT(showAboutDialog()) ); | 128 connect( _mainWindowForm->actionAbout_UniversalIndentGUI, SIGNAL(triggered()), this, SLOT(showAboutDialog()) ); |
76 | 129 |
77 // Generate settings dialog box | 130 // Generate settings dialog box |
78 settingsDialog = new UiGuiSettingsDialog(this, settings); | 131 _settingsDialog = new UiGuiSettingsDialog(this, _settings); |
79 connect( actionShowSettings, SIGNAL(triggered()), settingsDialog, SLOT(showDialog()) ); | 132 connect( _mainWindowForm->actionShowSettings, SIGNAL(triggered()), _settingsDialog, SLOT(showDialog()) ); |
80 | 133 |
81 // If a file that should be opened on start has been handed over to the constructor exists, load it | 134 // If a file that should be opened on start has been handed over to the constructor exists, load it |
82 if ( QFile::exists(file2OpenOnStart) ) { | 135 if ( QFile::exists(file2OpenOnStart) ) { |
83 openSourceFileDialog(file2OpenOnStart); | 136 openSourceFileDialog(file2OpenOnStart); |
84 } | 137 } |
88 } | 141 } |
89 | 142 |
90 updateSourceView(); | 143 updateSourceView(); |
91 | 144 |
92 // Check if a newer version is available but only if the setting for that is enabled and today not already a check has been done. | 145 // Check if a newer version is available but only if the setting for that is enabled and today not already a check has been done. |
93 if ( settings->getValueByName("CheckForUpdate").toBool() && QDate::currentDate() != settings->getValueByName("LastUpdateCheck").toDate() ) { | 146 if ( _settings->getValueByName("CheckForUpdate").toBool() && QDate::currentDate() != _settings->getValueByName("LastUpdateCheck").toDate() ) { |
94 updateCheckDialog->checkForUpdate(); | 147 _updateCheckDialog->checkForUpdate(); |
95 } | 148 } |
96 | 149 |
97 // Enable accept dropping of files. | 150 // Enable accept dropping of files. |
98 setAcceptDrops(true); | 151 setAcceptDrops(true); |
99 } | 152 } |
100 | 153 |
101 | 154 |
102 /*! | 155 /*! |
103 \brief Initializes the main window by creating the main gui and make some settings. | 156 \brief Initializes the main window by creating the main gui and make some _settings. |
104 */ | 157 */ |
105 void MainWindow::initMainWindow() { | 158 void MainWindow::initMainWindow() { |
106 // Generate gui as it is build in the file "mainwindow.ui" | 159 // Generate gui as it is build in the file "mainwindow.ui" |
107 setupUi(this); | 160 _mainWindowForm = new Ui::MainWindowUi(); |
161 _mainWindowForm->setupUi(this); | |
108 | 162 |
109 // Handle last opened window size | 163 // Handle last opened window size |
110 // ------------------------------ | 164 // ------------------------------ |
111 bool maximized = settings->getValueByName("maximized").toBool(); | 165 bool maximized = _settings->getValueByName("maximized").toBool(); |
112 QPoint pos = settings->getValueByName("position").toPoint(); | 166 QPoint pos = _settings->getValueByName("position").toPoint(); |
113 QSize size = settings->getValueByName("size").toSize(); | 167 QSize size = _settings->getValueByName("size").toSize(); |
114 resize(size); | 168 resize(size); |
115 move(pos); | 169 move(pos); |
116 if ( maximized ) { | 170 if ( maximized ) { |
117 showMaximized(); | 171 showMaximized(); |
118 } | 172 } |
119 #ifndef Q_OS_MAC // On Mac restoring the window state causes the screenshot no longer to work. | 173 #ifndef Q_OS_MAC // On Mac restoring the window state causes the screenshot no longer to work. |
120 restoreState( settings->getValueByName("MainWindowState").toByteArray() ); | 174 restoreState( _settings->getValueByName("MainWindowState").toByteArray() ); |
121 #endif | 175 #endif |
122 | 176 |
123 // Handle if first run of this version | 177 // Handle if first run of this version |
124 // ----------------------------------- | 178 // ----------------------------------- |
125 QString readVersion = settings->getValueByName("version").toString(); | 179 QString readVersion = _settings->getValueByName("version").toString(); |
126 // If version strings are not equal set first run true. | 180 // If version strings are not equal set first run true. |
127 if ( readVersion != PROGRAM_VERSION_STRING ) { | 181 if ( readVersion != PROGRAM_VERSION_STRING ) { |
128 isFirstRunOfThisVersion = true; | 182 _isFirstRunOfThisVersion = true; |
129 } | 183 } |
130 else { | 184 else { |
131 isFirstRunOfThisVersion = false; | 185 _isFirstRunOfThisVersion = false; |
132 } | 186 } |
133 | 187 |
134 // Get last selected file encoding | 188 // Get last selected file encoding |
135 // ------------------------------- | 189 // ------------------------------- |
136 currentEncoding = settings->getValueByName("encoding").toString(); | 190 _currentEncoding = _settings->getValueByName("encoding").toString(); |
137 | 191 |
138 updateCheckDialog = new UpdateCheckDialog(settings, this); | 192 _updateCheckDialog = new UpdateCheckDialog(_settings, this); |
139 | 193 |
140 // Register the load last file setting in the menu to the settings object. | 194 // Register the load last file setting in the menu to the _settings object. |
141 settings->registerObjectProperty(loadLastOpenedFileOnStartupAction, "checked", "loadLastSourceCodeFileOnStartup"); | 195 _settings->registerObjectProperty(_mainWindowForm->loadLastOpenedFileOnStartupAction, "checked", "loadLastSourceCodeFileOnStartup"); |
142 | 196 |
143 // Tell the QScintilla editor if it has to show white space. | 197 // Tell the QScintilla editor if it has to show white space. |
144 connect( whiteSpaceIsVisibleAction, SIGNAL(toggled(bool)), this, SLOT(setWhiteSpaceVisibility(bool)) ); | 198 connect( _mainWindowForm->whiteSpaceIsVisibleAction, SIGNAL(toggled(bool)), this, SLOT(setWhiteSpaceVisibility(bool)) ); |
145 // Register the white space setting in the menu to the settings object. | 199 // Register the white space setting in the menu to the _settings object. |
146 settings->registerObjectProperty(whiteSpaceIsVisibleAction, "checked", "whiteSpaceIsVisible"); | 200 _settings->registerObjectProperty(_mainWindowForm->whiteSpaceIsVisibleAction, "checked", "whiteSpaceIsVisible"); |
147 | 201 |
148 // Connect the remaining menu items. | 202 // Connect the remaining menu items. |
149 connect( actionOpen_Source_File, SIGNAL(triggered()), this, SLOT(openSourceFileDialog()) ); | 203 connect( _mainWindowForm->actionOpen_Source_File, SIGNAL(triggered()), this, SLOT(openSourceFileDialog()) ); |
150 connect( actionSave_Source_File_As, SIGNAL(triggered()), this, SLOT(saveasSourceFileDialog()) ); | 204 connect( _mainWindowForm->actionSave_Source_File_As, SIGNAL(triggered()), this, SLOT(saveasSourceFileDialog()) ); |
151 connect( actionSave_Source_File, SIGNAL(triggered()), this, SLOT(saveSourceFile()) ); | 205 connect( _mainWindowForm->actionSave_Source_File, SIGNAL(triggered()), this, SLOT(saveSourceFile()) ); |
152 connect( actionExportPDF, SIGNAL(triggered()), this, SLOT(exportToPDF()) ); | 206 connect( _mainWindowForm->actionExportPDF, SIGNAL(triggered()), this, SLOT(exportToPDF()) ); |
153 connect( actionExportHTML, SIGNAL(triggered()), this, SLOT(exportToHTML()) ); | 207 connect( _mainWindowForm->actionExportHTML, SIGNAL(triggered()), this, SLOT(exportToHTML()) ); |
154 connect( actionCheck_for_update, SIGNAL(triggered()), updateCheckDialog, SLOT(checkForUpdateAndShowDialog()) ); | 208 connect( _mainWindowForm->actionCheck_for_update, SIGNAL(triggered()), _updateCheckDialog, SLOT(checkForUpdateAndShowDialog()) ); |
155 connect( actionShowLog, SIGNAL(triggered()), UiGuiLogger::getInstance(), SLOT(show()) ); | 209 connect( _mainWindowForm->actionShowLog, SIGNAL(triggered()), UiGuiLogger::getInstance(), SLOT(show()) ); |
156 | 210 |
157 // Init the menu for selecting one of the recently opened files. | 211 // Init the menu for selecting one of the recently opened files. |
158 updateRecentlyOpenedList(); | 212 updateRecentlyOpenedList(); |
159 connect( menuRecently_Opened_Files, SIGNAL(triggered(QAction*)), this, SLOT(openFileFromRecentlyOpenedList(QAction*)) ); | 213 connect( _mainWindowForm->menuRecently_Opened_Files, SIGNAL(triggered(QAction*)), this, SLOT(openFileFromRecentlyOpenedList(QAction*)) ); |
160 //connect( settings, SIGNAL(recentlyOpenedListSize(int)), this, SLOT(updateRecentlyOpenedList()) ); | 214 //connect( _settings, SIGNAL(recentlyOpenedListSize(int)), this, SLOT(updateRecentlyOpenedList()) ); |
161 settings->registerObjectSlot(this, "updateRecentlyOpenedList()", "recentlyOpenedListSize"); | 215 _settings->registerObjectSlot(this, "updateRecentlyOpenedList()", "recentlyOpenedListSize"); |
162 } | 216 } |
163 | 217 |
164 | 218 |
165 /*! | 219 /*! |
166 \brief Creates and inits the tool bar. It is added to the main window. | 220 \brief Creates and inits the tool bar. It is added to the main window. |
167 */ | 221 */ |
168 void MainWindow::initToolBar() { | 222 void MainWindow::initToolBar() { |
169 // Create the tool bar and add it to the main window. | 223 // Create the tool bar and add it to the main window. |
170 toolBarWidget = new Ui::ToolBarWidget(); | 224 _toolBarWidget = new Ui::ToolBarWidget(); |
171 QWidget* helpWidget = new QWidget(); | 225 QWidget* helpWidget = new QWidget(); |
172 toolBarWidget->setupUi(helpWidget); | 226 _toolBarWidget->setupUi(helpWidget); |
173 toolBar->addWidget(helpWidget); | 227 _mainWindowForm->toolBar->addWidget(helpWidget); |
174 toolBar->setAllowedAreas( Qt::TopToolBarArea | Qt::BottomToolBarArea ); | 228 _mainWindowForm->toolBar->setAllowedAreas( Qt::TopToolBarArea | Qt::BottomToolBarArea ); |
175 | 229 |
176 // Connect the tool bar widgets to their functions. | 230 // Connect the tool bar widgets to their functions. |
177 settings->registerObjectProperty(toolBarWidget->enableSyntaxHighlightningCheckBox, "checked", "SyntaxHighlightingEnabled"); | 231 _settings->registerObjectProperty(_toolBarWidget->enableSyntaxHighlightningCheckBox, "checked", "SyntaxHighlightingEnabled"); |
178 toolBarWidget->enableSyntaxHighlightningCheckBox->hide(); | 232 _toolBarWidget->enableSyntaxHighlightningCheckBox->hide(); |
179 connect( toolBarWidget->pbOpen_Source_File, SIGNAL(clicked()), this, SLOT(openSourceFileDialog()) ); | 233 connect( _toolBarWidget->pbOpen_Source_File, SIGNAL(clicked()), this, SLOT(openSourceFileDialog()) ); |
180 connect( toolBarWidget->pbExit, SIGNAL(clicked()), this, SLOT(close())); | 234 connect( _toolBarWidget->pbExit, SIGNAL(clicked()), this, SLOT(close())); |
181 connect( toolBarWidget->cbLivePreview, SIGNAL(toggled(bool)), this, SLOT(previewTurnedOnOff(bool)) ); | 235 connect( _toolBarWidget->cbLivePreview, SIGNAL(toggled(bool)), this, SLOT(previewTurnedOnOff(bool)) ); |
182 connect( toolBarWidget->cbLivePreview, SIGNAL(toggled(bool)), actionLive_Indent_Preview, SLOT(setChecked(bool)) ); | 236 connect( _toolBarWidget->cbLivePreview, SIGNAL(toggled(bool)), _mainWindowForm->actionLive_Indent_Preview, SLOT(setChecked(bool)) ); |
183 connect( actionLive_Indent_Preview, SIGNAL(toggled(bool)), toolBarWidget->cbLivePreview, SLOT(setChecked(bool)) ); | 237 connect( _mainWindowForm->actionLive_Indent_Preview, SIGNAL(toggled(bool)), _toolBarWidget->cbLivePreview, SLOT(setChecked(bool)) ); |
184 } | 238 } |
185 | 239 |
186 | 240 |
187 /*! | 241 /*! |
188 \brief Create and initialize the text editor component. It uses the QScintilla widget. | 242 \brief Create and initialize the text editor component. It uses the QScintilla widget. |
191 // Create the QScintilla widget and add it to the layout. | 245 // Create the QScintilla widget and add it to the layout. |
192 qDebug() << "Trying to load QScintilla library. If anything fails during loading, it might be possible that" | 246 qDebug() << "Trying to load QScintilla library. If anything fails during loading, it might be possible that" |
193 << " the debug and release version of QScintilla are mixed or the library cannot be found at all."; | 247 << " the debug and release version of QScintilla are mixed or the library cannot be found at all."; |
194 // Try and catch doesn't seem to catch the runtime error when starting UiGUI release with QScintilla debug lib and the other way around. | 248 // Try and catch doesn't seem to catch the runtime error when starting UiGUI release with QScintilla debug lib and the other way around. |
195 try { | 249 try { |
196 qSciSourceCodeEditor = new QsciScintilla(this); | 250 _qSciSourceCodeEditor = new QsciScintilla(this); |
197 } | 251 } |
198 catch (...) { | 252 catch (...) { |
199 QMessageBox::critical(this, "Error creating QScintilla text editor component!", | 253 QMessageBox::critical(this, "Error creating QScintilla text editor component!", |
200 "During trying to create the text editor component, that is based on QScintilla, an error occurred. Please make sure that you have installed QScintilla and not mixed release and debug versions." ); | 254 "During trying to create the text editor component, that is based on QScintilla, an error occurred. Please make sure that you have installed QScintilla and not mixed release and debug versions." ); |
201 exit(1); | 255 exit(1); |
202 } | 256 } |
203 hboxLayout1->addWidget(qSciSourceCodeEditor); | 257 _mainWindowForm->hboxLayout1->addWidget(_qSciSourceCodeEditor); |
204 | 258 |
205 // Make some settings for the QScintilla widget. | 259 // Make some _settings for the QScintilla widget. |
206 qSciSourceCodeEditor->setUtf8(true); | 260 _qSciSourceCodeEditor->setUtf8(true); |
207 qSciSourceCodeEditor->setMarginLineNumbers(1, true); | 261 _qSciSourceCodeEditor->setMarginLineNumbers(1, true); |
208 qSciSourceCodeEditor->setMarginWidth(1, QString("10000") ); | 262 _qSciSourceCodeEditor->setMarginWidth(1, QString("10000") ); |
209 qSciSourceCodeEditor->setBraceMatching(qSciSourceCodeEditor->SloppyBraceMatch); | 263 _qSciSourceCodeEditor->setBraceMatching(_qSciSourceCodeEditor->SloppyBraceMatch); |
210 qSciSourceCodeEditor->setMatchedBraceForegroundColor( QColor("red") ); | 264 _qSciSourceCodeEditor->setMatchedBraceForegroundColor( QColor("red") ); |
211 qSciSourceCodeEditor->setFolding(QsciScintilla::BoxedTreeFoldStyle); | 265 _qSciSourceCodeEditor->setFolding(QsciScintilla::BoxedTreeFoldStyle); |
212 qSciSourceCodeEditor->setAutoCompletionSource(QsciScintilla::AcsAll); | 266 _qSciSourceCodeEditor->setAutoCompletionSource(QsciScintilla::AcsAll); |
213 qSciSourceCodeEditor->setAutoCompletionThreshold(3); | 267 _qSciSourceCodeEditor->setAutoCompletionThreshold(3); |
214 | 268 |
215 // Handle if white space is set to be visible | 269 // Handle if white space is set to be visible |
216 bool whiteSpaceIsVisible = settings->getValueByName("whiteSpaceIsVisible").toBool(); | 270 bool whiteSpaceIsVisible = _settings->getValueByName("whiteSpaceIsVisible").toBool(); |
217 setWhiteSpaceVisibility( whiteSpaceIsVisible ); | 271 setWhiteSpaceVisibility( whiteSpaceIsVisible ); |
218 | 272 |
219 // Handle the width of tabs in spaces | 273 // Handle the width of tabs in spaces |
220 int tabWidth = settings->getValueByName("tabWidth").toInt(); | 274 int tabWidth = _settings->getValueByName("tabWidth").toInt(); |
221 qSciSourceCodeEditor->setTabWidth(tabWidth); | 275 _qSciSourceCodeEditor->setTabWidth(tabWidth); |
222 | 276 |
223 // Remember a pointer to the scrollbar of the QScintilla widget used to keep | 277 // Remember a pointer to the scrollbar of the QScintilla widget used to keep |
224 // on the same line as before when turning preview on/off. | 278 // on the same line as before when turning preview on/off. |
225 textEditVScrollBar = qSciSourceCodeEditor->verticalScrollBar(); | 279 _textEditVScrollBar = _qSciSourceCodeEditor->verticalScrollBar(); |
226 | 280 |
227 // Add a column row indicator to the status bar. | 281 // Add a column row indicator to the status bar. |
228 textEditLineColumnInfoLabel = new QLabel( tr("Line %1, Column %2").arg(1).arg(1) ); | 282 _textEditLineColumnInfoLabel = new QLabel( tr("Line %1, Column %2").arg(1).arg(1) ); |
229 statusbar->addPermanentWidget(textEditLineColumnInfoLabel); | 283 _mainWindowForm->statusbar->addPermanentWidget(_textEditLineColumnInfoLabel); |
230 connect( qSciSourceCodeEditor, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(setStatusBarCursorPosInfo(int, int)) ); | 284 connect( _qSciSourceCodeEditor, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(setStatusBarCursorPosInfo(int, int)) ); |
231 | 285 |
232 // Connect the text editor to dependent functions. | 286 // Connect the text editor to dependent functions. |
233 connect( qSciSourceCodeEditor, SIGNAL(textChanged()), this, SLOT(sourceCodeChangedHelperSlot()) ); | 287 connect( _qSciSourceCodeEditor, SIGNAL(textChanged()), this, SLOT(sourceCodeChangedHelperSlot()) ); |
234 connect( qSciSourceCodeEditor, SIGNAL(linesChanged()), this, SLOT(numberOfLinesChanged()) ); | 288 connect( _qSciSourceCodeEditor, SIGNAL(linesChanged()), this, SLOT(numberOfLinesChanged()) ); |
235 //connect( settings, SIGNAL(tabWidth(int)), qSciSourceCodeEditor, SLOT(setTabWidth(int)) ); | 289 //connect( _settings, SIGNAL(tabWidth(int)), _qSciSourceCodeEditor, SLOT(setTabWidth(int)) ); |
236 settings->registerObjectSlot(qSciSourceCodeEditor, "setTabWidth(int)", "tabWidth"); | 290 _settings->registerObjectSlot(_qSciSourceCodeEditor, "setTabWidth(int)", "tabWidth"); |
237 qSciSourceCodeEditor->setTabWidth( settings->getValueByName("tabWidth").toInt() ); | 291 _qSciSourceCodeEditor->setTabWidth( _settings->getValueByName("tabWidth").toInt() ); |
238 } | 292 } |
239 | 293 |
240 | 294 |
241 /*! | 295 /*! |
242 \brief Create and init the syntax highlighter and set it to use the QScintilla edit component. | 296 \brief Create and init the syntax _highlighter and set it to use the QScintilla edit component. |
243 */ | 297 */ |
244 void MainWindow::initSyntaxHighlighter() { | 298 void MainWindow::initSyntaxHighlighter() { |
245 // Create the highlighter. | 299 // Create the _highlighter. |
246 highlighter = new UiGuiHighlighter(qSciSourceCodeEditor); | 300 _highlighter = new UiGuiHighlighter(_qSciSourceCodeEditor); |
247 | 301 |
248 // Connect the syntax highlighting setting in the menu to the turnHighlightOnOff function. | 302 // Connect the syntax highlighting setting in the menu to the turnHighlightOnOff function. |
249 connect( enableSyntaxHighlightingAction, SIGNAL(toggled(bool)), this, SLOT(turnHighlightOnOff(bool)) ); | 303 connect( _mainWindowForm->enableSyntaxHighlightingAction, SIGNAL(toggled(bool)), this, SLOT(turnHighlightOnOff(bool)) ); |
250 | 304 |
251 // Register the syntax highlighting setting in the menu to the settings object. | 305 // Register the syntax highlighting setting in the menu to the _settings object. |
252 settings->registerObjectProperty(enableSyntaxHighlightingAction, "checked", "SyntaxHighlightingEnabled"); | 306 _settings->registerObjectProperty(_mainWindowForm->enableSyntaxHighlightingAction, "checked", "SyntaxHighlightingEnabled"); |
253 } | 307 } |
254 | 308 |
255 | 309 |
256 /*! | 310 /*! |
257 \brief Initializes the language of UniversalIndentGUI. | 311 \brief Initializes the language of UniversalIndentGUI. |
258 | 312 |
259 If the program language is defined in the settings, the corresponding language | 313 If the program language is defined in the _settings, the corresponding language |
260 file will be loaded and set for the application. If not set there, the system | 314 file will be loaded and set for the application. If not set there, the system |
261 default language will be set, if a translation file for that language exists. | 315 default language will be set, if a translation file for that language exists. |
262 Returns true, if the translation file could be loaded. Otherwise it returns | 316 Returns true, if the translation file could be loaded. Otherwise it returns |
263 false and uses the default language, which is English. | 317 false and uses the default language, which is English. |
264 */ | 318 */ |
265 bool MainWindow::initApplicationLanguage() { | 319 bool MainWindow::initApplicationLanguage() { |
266 QString languageShort; | 320 QString languageShort; |
267 | 321 |
268 // Get the language settings from the settings object. | 322 // Get the language _settings from the _settings object. |
269 int languageIndex = settings->getValueByName("language").toInt(); | 323 int languageIndex = _settings->getValueByName("language").toInt(); |
270 | 324 |
271 // If no language was set, indicated by a negative index, use the system language. | 325 // If no language was set, indicated by a negative index, use the system language. |
272 if ( languageIndex < 0 ) { | 326 if ( languageIndex < 0 ) { |
273 languageShort = QLocale::system().name(); | 327 languageShort = QLocale::system().name(); |
274 | 328 |
277 if ( languageShort.left(2) != "zh" && languageShort.left(2) != "ja" ) { | 331 if ( languageShort.left(2) != "zh" && languageShort.left(2) != "ja" ) { |
278 languageShort = languageShort.left(2); | 332 languageShort = languageShort.left(2); |
279 } | 333 } |
280 | 334 |
281 // If no translation file for the systems local language exist, fall back to English. | 335 // If no translation file for the systems local language exist, fall back to English. |
282 if ( settings->getAvailableTranslations().indexOf(languageShort) < 0 ) { | 336 if ( _settings->getAvailableTranslations().indexOf(languageShort) < 0 ) { |
283 languageShort = "en"; | 337 languageShort = "en"; |
284 } | 338 } |
285 | 339 |
286 // Set the language setting to the new language. | 340 // Set the language setting to the new language. |
287 settings->setValueByName("language", settings->getAvailableTranslations().indexOf(languageShort) ); | 341 _settings->setValueByName("language", _settings->getAvailableTranslations().indexOf(languageShort) ); |
288 } | 342 } |
289 // If a language was defined in the settings, get this language mnemonic. | 343 // If a language was defined in the _settings, get this language mnemonic. |
290 else { | 344 else { |
291 languageShort = settings->getAvailableTranslations().at(languageIndex); | 345 languageShort = _settings->getAvailableTranslations().at(languageIndex); |
292 } | 346 } |
293 | 347 |
294 // Load the Qt own translation file and set it for the application. | 348 // Load the Qt own translation file and set it for the application. |
295 qTTranslator = new QTranslator(); | 349 _qTTranslator = new QTranslator(); |
296 bool translationFileLoaded; | 350 bool translationFileLoaded; |
297 translationFileLoaded = qTTranslator->load( SettingsPaths::getGlobalFilesPath() + "/translations/qt_" + languageShort ); | 351 translationFileLoaded = _qTTranslator->load( SettingsPaths::getGlobalFilesPath() + "/translations/qt_" + languageShort ); |
298 if ( translationFileLoaded ) { | 352 if ( translationFileLoaded ) { |
299 qApp->installTranslator(qTTranslator); | 353 qApp->installTranslator(_qTTranslator); |
300 } | 354 } |
301 | 355 |
302 // Load the uigui translation file and set it for the application. | 356 // Load the uigui translation file and set it for the application. |
303 uiGuiTranslator = new QTranslator(); | 357 _uiGuiTranslator = new QTranslator(); |
304 translationFileLoaded = uiGuiTranslator->load( SettingsPaths::getGlobalFilesPath() + "/translations/universalindent_" + languageShort ); | 358 translationFileLoaded = _uiGuiTranslator->load( SettingsPaths::getGlobalFilesPath() + "/translations/universalindent_" + languageShort ); |
305 if ( translationFileLoaded ) { | 359 if ( translationFileLoaded ) { |
306 qApp->installTranslator(uiGuiTranslator); | 360 qApp->installTranslator(_uiGuiTranslator); |
307 } | 361 } |
308 | 362 |
309 //connect( settings, SIGNAL(language(int)), this, SLOT(languageChanged(int)) ); | 363 //connect( _settings, SIGNAL(language(int)), this, SLOT(languageChanged(int)) ); |
310 settings->registerObjectSlot(this, "languageChanged(int)", "language"); | 364 _settings->registerObjectSlot(this, "languageChanged(int)", "language"); |
311 | 365 |
312 return translationFileLoaded; | 366 return translationFileLoaded; |
313 } | 367 } |
314 | 368 |
315 | 369 |
316 /*! | 370 /*! |
317 \brief Creates and initializes the indenter. | 371 \brief Creates and initializes the indenter. |
318 */ | 372 */ |
319 void MainWindow::initIndenter() { | 373 void MainWindow::initIndenter() { |
320 // Get Id of last selected indenter. | 374 // Get Id of last selected indenter. |
321 currentIndenterID = settings->getValueByName("selectedIndenter").toInt(); | 375 _currentIndenterID = _settings->getValueByName("selectedIndenter").toInt(); |
322 | 376 |
323 // Create the indenter widget with the ID and add it to the layout. | 377 // Create the indenter widget with the ID and add it to the layout. |
324 indentHandler = new IndentHandler(currentIndenterID, this, centralwidget); | 378 _indentHandler = new IndentHandler(_currentIndenterID, this, _mainWindowForm->centralwidget); |
325 vboxLayout->addWidget(indentHandler); | 379 _mainWindowForm->vboxLayout->addWidget(_indentHandler); |
326 | 380 |
327 // If settings for the indenter have changed, let the main window know aboud it. | 381 // If _settings for the indenter have changed, let the main window know aboud it. |
328 connect(indentHandler, SIGNAL(indenterSettingsChanged()), this, SLOT(indentSettingsChangedSlot())); | 382 connect(_indentHandler, SIGNAL(indenterSettingsChanged()), this, SLOT(indentSettingsChangedSlot())); |
329 | 383 |
330 // Set this true, so the indenter is called at first program start | 384 // Set this true, so the indenter is called at first program start |
331 indentSettingsChanged = true; | 385 _indentSettingsChanged = true; |
332 previewToggled = true; | 386 _previewToggled = true; |
333 | 387 |
334 // Handle if indenter parameter tool tips are enabled | 388 // Handle if indenter parameter tool tips are enabled |
335 settings->registerObjectProperty(indenterParameterTooltipsEnabledAction, "checked", "indenterParameterTooltipsEnabled"); | 389 _settings->registerObjectProperty(_mainWindowForm->indenterParameterTooltipsEnabledAction, "checked", "indenterParameterTooltipsEnabled"); |
336 | 390 |
337 // Add the indenters context menu to the mainwindows menu. | 391 // Add the indenters context menu to the mainwindows menu. |
338 menuIndenter->addActions( indentHandler->getIndenterMenuActions() ); | 392 _mainWindowForm->menuIndenter->addActions( _indentHandler->getIndenterMenuActions() ); |
339 } | 393 } |
340 | 394 |
341 | 395 |
342 /*! | 396 /*! |
343 \brief Tries to load the by \a filePath defined file and returns its content as QString. | 397 \brief Tries to load the by \a filePath defined file and returns its content as QString. |
352 QMessageBox::warning(NULL, tr("Error opening file"), tr("Cannot read the file ")+"\""+filePath+"\"." ); | 406 QMessageBox::warning(NULL, tr("Error opening file"), tr("Cannot read the file ")+"\""+filePath+"\"." ); |
353 } | 407 } |
354 else { | 408 else { |
355 QTextStream inSrcStrm(&inSrcFile); | 409 QTextStream inSrcStrm(&inSrcFile); |
356 QApplication::setOverrideCursor(Qt::WaitCursor); | 410 QApplication::setOverrideCursor(Qt::WaitCursor); |
357 inSrcStrm.setCodec( QTextCodec::codecForName(currentEncoding.toAscii()) ); | 411 inSrcStrm.setCodec( QTextCodec::codecForName(_currentEncoding.toAscii()) ); |
358 fileContent = inSrcStrm.readAll(); | 412 fileContent = inSrcStrm.readAll(); |
359 QApplication::restoreOverrideCursor(); | 413 QApplication::restoreOverrideCursor(); |
360 inSrcFile.close(); | 414 inSrcFile.close(); |
361 | 415 |
362 QFileInfo fileInfo(filePath); | 416 QFileInfo fileInfo(filePath); |
363 currentSourceFileExtension = fileInfo.suffix(); | 417 _currentSourceFileExtension = fileInfo.suffix(); |
364 int indexOfHighlighter = highlighter->setLexerForExtension( currentSourceFileExtension ); | 418 int indexOfHighlighter = _highlighter->setLexerForExtension( _currentSourceFileExtension ); |
365 highlighterActionGroup->actions().at(indexOfHighlighter)->setChecked(true); | 419 _highlighterActionGroup->actions().at(indexOfHighlighter)->setChecked(true); |
366 } | 420 } |
367 return fileContent; | 421 return fileContent; |
368 } | 422 } |
369 | 423 |
370 | 424 |
378 // is canceled, also stop opening another source file. | 432 // is canceled, also stop opening another source file. |
379 if ( !maybeSave() ) { | 433 if ( !maybeSave() ) { |
380 return; | 434 return; |
381 } | 435 } |
382 QString openedSourceFileContent = ""; | 436 QString openedSourceFileContent = ""; |
383 QString fileExtensions = tr("Supported by indenter")+" ("+indentHandler->getPossibleIndenterFileExtensions()+ | 437 QString fileExtensions = tr("Supported by indenter")+" ("+_indentHandler->getPossibleIndenterFileExtensions()+ |
384 ");;"+tr("All files")+" (*.*)"; | 438 ");;"+tr("All files")+" (*.*)"; |
385 | 439 |
386 //QString openedSourceFileContent = openFileDialog( tr("Choose source code file"), "./", fileExtensions ); | 440 //QString openedSourceFileContent = openFileDialog( tr("Choose source code file"), "./", fileExtensions ); |
387 if ( fileName.isEmpty() ) { | 441 if ( fileName.isEmpty() ) { |
388 fileName = QFileDialog::getOpenFileName( this, tr("Choose source code file"), currentSourceFile, fileExtensions); | 442 fileName = QFileDialog::getOpenFileName( this, tr("Choose source code file"), _currentSourceFile, fileExtensions); |
389 } | 443 } |
390 | 444 |
391 if (fileName != "") { | 445 if (fileName != "") { |
392 currentSourceFile = fileName; | 446 _currentSourceFile = fileName; |
393 QFileInfo fileInfo(fileName); | 447 QFileInfo fileInfo(fileName); |
394 currentSourceFileExtension = fileInfo.suffix(); | 448 _currentSourceFileExtension = fileInfo.suffix(); |
395 | 449 |
396 openedSourceFileContent = loadFile(fileName); | 450 openedSourceFileContent = loadFile(fileName); |
397 sourceFileContent = openedSourceFileContent; | 451 _sourceFileContent = openedSourceFileContent; |
398 if ( toolBarWidget->cbLivePreview->isChecked() ) { | 452 if ( _toolBarWidget->cbLivePreview->isChecked() ) { |
399 callIndenter(); | 453 callIndenter(); |
400 } | 454 } |
401 sourceCodeChanged = true; | 455 _sourceCodeChanged = true; |
402 previewToggled = true; | 456 _previewToggled = true; |
403 updateSourceView(); | 457 updateSourceView(); |
404 updateWindowTitle(); | 458 updateWindowTitle(); |
405 updateRecentlyOpenedList(); | 459 updateRecentlyOpenedList(); |
406 textEditLastScrollPos = 0; | 460 _textEditLastScrollPos = 0; |
407 textEditVScrollBar->setValue( textEditLastScrollPos ); | 461 _textEditVScrollBar->setValue( _textEditLastScrollPos ); |
408 | 462 |
409 savedSourceContent = openedSourceFileContent; | 463 _savedSourceContent = openedSourceFileContent; |
410 qSciSourceCodeEditor->setModified( false ); | 464 _qSciSourceCodeEditor->setModified( false ); |
411 setWindowModified( false ); | 465 setWindowModified( false ); |
412 } | 466 } |
413 } | 467 } |
414 | 468 |
415 | 469 |
418 | 472 |
419 If the file already exists and it should be overwritten, a warning is shown before. | 473 If the file already exists and it should be overwritten, a warning is shown before. |
420 */ | 474 */ |
421 bool MainWindow::saveasSourceFileDialog(QAction *chosenEncodingAction) { | 475 bool MainWindow::saveasSourceFileDialog(QAction *chosenEncodingAction) { |
422 QString encoding; | 476 QString encoding; |
423 QString fileExtensions = tr("Supported by indenter")+" ("+indentHandler->getPossibleIndenterFileExtensions()+ | 477 QString fileExtensions = tr("Supported by indenter")+" ("+_indentHandler->getPossibleIndenterFileExtensions()+ |
424 ");;"+tr("All files")+" (*.*)"; | 478 ");;"+tr("All files")+" (*.*)"; |
425 | 479 |
426 //QString openedSourceFileContent = openFileDialog( tr("Choose source code file"), "./", fileExtensions ); | 480 //QString openedSourceFileContent = openFileDialog( tr("Choose source code file"), "./", fileExtensions ); |
427 QString fileName = QFileDialog::getSaveFileName( this, tr("Save source code file"), currentSourceFile, fileExtensions); | 481 QString fileName = QFileDialog::getSaveFileName( this, tr("Save source code file"), _currentSourceFile, fileExtensions); |
428 | 482 |
429 // Saving has been canceled if the filename is empty | 483 // Saving has been canceled if the filename is empty |
430 if ( fileName.isEmpty() ) { | 484 if ( fileName.isEmpty() ) { |
431 return false; | 485 return false; |
432 } | 486 } |
433 | 487 |
434 savedSourceContent = qSciSourceCodeEditor->text(); | 488 _savedSourceContent = _qSciSourceCodeEditor->text(); |
435 | 489 |
436 currentSourceFile = fileName; | 490 _currentSourceFile = fileName; |
437 QFile::remove(fileName); | 491 QFile::remove(fileName); |
438 QFile outSrcFile(fileName); | 492 QFile outSrcFile(fileName); |
439 outSrcFile.open( QFile::ReadWrite | QFile::Text ); | 493 outSrcFile.open( QFile::ReadWrite | QFile::Text ); |
440 | 494 |
441 // Get current encoding. | 495 // Get current encoding. |
442 if ( chosenEncodingAction != NULL ) { | 496 if ( chosenEncodingAction != NULL ) { |
443 encoding = chosenEncodingAction->text(); | 497 encoding = chosenEncodingAction->text(); |
444 } | 498 } |
445 else { | 499 else { |
446 encoding = encodingActionGroup->checkedAction()->text(); | 500 encoding = _encodingActionGroup->checkedAction()->text(); |
447 } | 501 } |
448 QTextStream outSrcStrm(&outSrcFile); | 502 QTextStream outSrcStrm(&outSrcFile); |
449 outSrcStrm.setCodec( QTextCodec::codecForName(encoding.toAscii()) ); | 503 outSrcStrm.setCodec( QTextCodec::codecForName(encoding.toAscii()) ); |
450 outSrcStrm << savedSourceContent; | 504 outSrcStrm << _savedSourceContent; |
451 outSrcFile.close(); | 505 outSrcFile.close(); |
452 | 506 |
453 QFileInfo fileInfo(fileName); | 507 QFileInfo fileInfo(fileName); |
454 currentSourceFileExtension = fileInfo.suffix(); | 508 _currentSourceFileExtension = fileInfo.suffix(); |
455 | 509 |
456 qSciSourceCodeEditor->setModified( false ); | 510 _qSciSourceCodeEditor->setModified( false ); |
457 setWindowModified( false ); | 511 setWindowModified( false ); |
458 | 512 |
459 updateWindowTitle(); | 513 updateWindowTitle(); |
460 return true; | 514 return true; |
461 } | 515 } |
466 | 520 |
467 If no source file has been opened, because only the static example has been loaded, | 521 If no source file has been opened, because only the static example has been loaded, |
468 the save as file dialog will be shown. | 522 the save as file dialog will be shown. |
469 */ | 523 */ |
470 bool MainWindow::saveSourceFile() { | 524 bool MainWindow::saveSourceFile() { |
471 if ( currentSourceFile.isEmpty() ) { | 525 if ( _currentSourceFile.isEmpty() ) { |
472 return saveasSourceFileDialog(); | 526 return saveasSourceFileDialog(); |
473 } | 527 } |
474 else { | 528 else { |
475 QFile::remove(currentSourceFile); | 529 QFile::remove(_currentSourceFile); |
476 QFile outSrcFile(currentSourceFile); | 530 QFile outSrcFile(_currentSourceFile); |
477 savedSourceContent = qSciSourceCodeEditor->text(); | 531 _savedSourceContent = _qSciSourceCodeEditor->text(); |
478 outSrcFile.open( QFile::ReadWrite | QFile::Text ); | 532 outSrcFile.open( QFile::ReadWrite | QFile::Text ); |
479 | 533 |
480 // Get current encoding. | 534 // Get current encoding. |
481 QString currentEncoding = encodingActionGroup->checkedAction()->text(); | 535 QString _currentEncoding = _encodingActionGroup->checkedAction()->text(); |
482 QTextStream outSrcStrm(&outSrcFile); | 536 QTextStream outSrcStrm(&outSrcFile); |
483 outSrcStrm.setCodec( QTextCodec::codecForName(currentEncoding.toAscii()) ); | 537 outSrcStrm.setCodec( QTextCodec::codecForName(_currentEncoding.toAscii()) ); |
484 outSrcStrm << savedSourceContent; | 538 outSrcStrm << _savedSourceContent; |
485 outSrcFile.close(); | 539 outSrcFile.close(); |
486 | 540 |
487 qSciSourceCodeEditor->setModified( false ); | 541 _qSciSourceCodeEditor->setModified( false ); |
488 setWindowModified( false ); | 542 setWindowModified( false ); |
489 } | 543 } |
490 return true; | 544 return true; |
491 } | 545 } |
492 | 546 |
516 Updates the text edit field, which is showing the loaded, and if preview is enabled formatted, source code. | 570 Updates the text edit field, which is showing the loaded, and if preview is enabled formatted, source code. |
517 Reassigns the line numbers and in case of switch between preview and none preview keeps the text field | 571 Reassigns the line numbers and in case of switch between preview and none preview keeps the text field |
518 at the same line number. | 572 at the same line number. |
519 */ | 573 */ |
520 void MainWindow::updateSourceView() { | 574 void MainWindow::updateSourceView() { |
521 textEditLastScrollPos = textEditVScrollBar->value(); | 575 _textEditLastScrollPos = _textEditVScrollBar->value(); |
522 | 576 |
523 if ( toolBarWidget->cbLivePreview->isChecked() ) { | 577 if ( _toolBarWidget->cbLivePreview->isChecked() ) { |
524 sourceViewContent = sourceFormattedContent; | 578 _sourceViewContent = _sourceFormattedContent; |
525 } | 579 } |
526 else { | 580 else { |
527 sourceViewContent = sourceFileContent; | 581 _sourceViewContent = _sourceFileContent; |
528 } | 582 } |
529 | 583 |
530 if (previewToggled) { | 584 if (_previewToggled) { |
531 disconnect( qSciSourceCodeEditor, SIGNAL(textChanged ()), this, SLOT(sourceCodeChangedHelperSlot()) ); | 585 disconnect( _qSciSourceCodeEditor, SIGNAL(textChanged ()), this, SLOT(sourceCodeChangedHelperSlot()) ); |
532 bool textIsModified = isWindowModified(); | 586 bool textIsModified = isWindowModified(); |
533 qSciSourceCodeEditor->setText(sourceViewContent); | 587 _qSciSourceCodeEditor->setText(_sourceViewContent); |
534 setWindowModified(textIsModified); | 588 setWindowModified(textIsModified); |
535 previewToggled = false; | 589 _previewToggled = false; |
536 connect( qSciSourceCodeEditor, SIGNAL(textChanged ()), this, SLOT(sourceCodeChangedHelperSlot()) ); | 590 connect( _qSciSourceCodeEditor, SIGNAL(textChanged ()), this, SLOT(sourceCodeChangedHelperSlot()) ); |
537 } | 591 } |
538 | 592 |
539 textEditVScrollBar->setValue( textEditLastScrollPos ); | 593 _textEditVScrollBar->setValue( _textEditLastScrollPos ); |
540 } | 594 } |
541 | 595 |
542 | 596 |
543 /*! | 597 /*! |
544 \brief Calls the selected indenter with the currently loaded source code to retrieve the formatted source code. | 598 \brief Calls the selected indenter with the currently loaded source code to retrieve the formatted source code. |
545 | 599 |
546 The original loaded source code file will not be changed. | 600 The original loaded source code file will not be changed. |
547 */ | 601 */ |
548 void MainWindow::callIndenter() { | 602 void MainWindow::callIndenter() { |
549 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); | 603 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
550 sourceFormattedContent = indentHandler->callIndenter(sourceFileContent, currentSourceFileExtension); | 604 _sourceFormattedContent = _indentHandler->callIndenter(_sourceFileContent, _currentSourceFileExtension); |
551 //updateSourceView(); | 605 //updateSourceView(); |
552 QApplication::restoreOverrideCursor(); | 606 QApplication::restoreOverrideCursor(); |
553 } | 607 } |
554 | 608 |
555 | 609 |
556 /*! | 610 /*! |
557 \brief Switches the syntax highlighting corresponding to the value \a turnOn either on or off. | 611 \brief Switches the syntax highlighting corresponding to the value \a turnOn either on or off. |
558 */ | 612 */ |
559 void MainWindow::turnHighlightOnOff(bool turnOn) { | 613 void MainWindow::turnHighlightOnOff(bool turnOn) { |
560 if ( turnOn ) { | 614 if ( turnOn ) { |
561 highlighter->turnHighlightOn(); | 615 _highlighter->turnHighlightOn(); |
562 } | 616 } |
563 else { | 617 else { |
564 highlighter->turnHighlightOff(); | 618 _highlighter->turnHighlightOff(); |
565 } | 619 } |
566 previewToggled = true; | 620 _previewToggled = true; |
567 updateSourceView(); | 621 updateSourceView(); |
568 } | 622 } |
569 | 623 |
570 | 624 |
571 /*! | 625 /*! |
583 void MainWindow::sourceCodeChangedSlot() { | 637 void MainWindow::sourceCodeChangedSlot() { |
584 QChar enteredCharacter; | 638 QChar enteredCharacter; |
585 int cursorPos, cursorPosAbsolut, cursorLine; | 639 int cursorPos, cursorPosAbsolut, cursorLine; |
586 QString text; | 640 QString text; |
587 | 641 |
588 sourceCodeChanged = true; | 642 _sourceCodeChanged = true; |
589 if ( scrollPositionChanged ) { | 643 if ( _scrollPositionChanged ) { |
590 scrollPositionChanged = false; | 644 _scrollPositionChanged = false; |
591 } | 645 } |
592 | 646 |
593 // Get the content text of the text editor. | 647 // Get the content text of the text editor. |
594 sourceFileContent = qSciSourceCodeEditor->text(); | 648 _sourceFileContent = _qSciSourceCodeEditor->text(); |
595 | 649 |
596 // Get the position of the cursor in the unindented text. | 650 // Get the position of the cursor in the unindented text. |
597 if ( sourceFileContent.isEmpty() ) { | 651 if ( _sourceFileContent.isEmpty() ) { |
598 // Add this line feed, because AStyle has problems with a totally emtpy file. | 652 // Add this line feed, because AStyle has problems with a totally emtpy file. |
599 sourceFileContent += "\n"; | 653 _sourceFileContent += "\n"; |
600 cursorPosAbsolut = 0; | 654 cursorPosAbsolut = 0; |
601 cursorPos = 0; | 655 cursorPos = 0; |
602 cursorLine = 0; | 656 cursorLine = 0; |
603 enteredCharacter = sourceFileContent.at(cursorPosAbsolut); | 657 enteredCharacter = _sourceFileContent.at(cursorPosAbsolut); |
604 } | 658 } |
605 else { | 659 else { |
606 qSciSourceCodeEditor->getCursorPosition(&cursorLine, &cursorPos); | 660 _qSciSourceCodeEditor->getCursorPosition(&cursorLine, &cursorPos); |
607 cursorPosAbsolut = qSciSourceCodeEditor->SendScintilla(QsciScintillaBase::SCI_GETCURRENTPOS); | 661 cursorPosAbsolut = _qSciSourceCodeEditor->SendScintilla(QsciScintillaBase::SCI_GETCURRENTPOS); |
608 text = qSciSourceCodeEditor->text(cursorLine); | 662 text = _qSciSourceCodeEditor->text(cursorLine); |
609 if ( cursorPosAbsolut > 0 ) { | 663 if ( cursorPosAbsolut > 0 ) { |
610 cursorPosAbsolut--; | 664 cursorPosAbsolut--; |
611 } | 665 } |
612 if ( cursorPos > 0 ) { | 666 if ( cursorPos > 0 ) { |
613 cursorPos--; | 667 cursorPos--; |
614 } | 668 } |
615 enteredCharacter = sourceFileContent.at(cursorPosAbsolut); | 669 enteredCharacter = _sourceFileContent.at(cursorPosAbsolut); |
616 } | 670 } |
617 | 671 |
618 // Call the indenter to reformat the text. | 672 // Call the indenter to reformat the text. |
619 if ( toolBarWidget->cbLivePreview->isChecked() ) { | 673 if ( _toolBarWidget->cbLivePreview->isChecked() ) { |
620 callIndenter(); | 674 callIndenter(); |
621 previewToggled = true; | 675 _previewToggled = true; |
622 } | 676 } |
623 | 677 |
624 // Update the text editor. | 678 // Update the text editor. |
625 updateSourceView(); | 679 updateSourceView(); |
626 | 680 |
627 if ( toolBarWidget->cbLivePreview->isChecked() && !enteredCharacter.isNull() && enteredCharacter != 10 ) { | 681 if ( _toolBarWidget->cbLivePreview->isChecked() && !enteredCharacter.isNull() && enteredCharacter != 10 ) { |
628 //const char ch = enteredCharacter.toAscii(); | 682 //const char ch = enteredCharacter.toAscii(); |
629 | 683 |
630 int saveCursorLine = cursorLine; | 684 int saveCursorLine = cursorLine; |
631 int saveCursorPos = cursorPos; | 685 int saveCursorPos = cursorPos; |
632 | 686 |
633 bool charFound = false; | 687 bool charFound = false; |
634 | 688 |
635 // Search forward | 689 // Search forward |
636 for ( cursorLine = saveCursorLine; cursorLine-saveCursorLine < 6 && cursorLine < qSciSourceCodeEditor->lines(); cursorLine++ ) { | 690 for ( cursorLine = saveCursorLine; cursorLine-saveCursorLine < 6 && cursorLine < _qSciSourceCodeEditor->lines(); cursorLine++ ) { |
637 text = qSciSourceCodeEditor->text(cursorLine); | 691 text = _qSciSourceCodeEditor->text(cursorLine); |
638 while ( cursorPos < text.count() && enteredCharacter != text.at(cursorPos)) { | 692 while ( cursorPos < text.count() && enteredCharacter != text.at(cursorPos)) { |
639 cursorPos++; | 693 cursorPos++; |
640 } | 694 } |
641 if ( cursorPos >= text.count() ) { | 695 if ( cursorPos >= text.count() ) { |
642 cursorPos = 0; | 696 cursorPos = 0; |
647 } | 701 } |
648 } | 702 } |
649 | 703 |
650 // If foward search did not find the character, search backward | 704 // If foward search did not find the character, search backward |
651 if ( !charFound ) { | 705 if ( !charFound ) { |
652 text = qSciSourceCodeEditor->text(saveCursorLine); | 706 text = _qSciSourceCodeEditor->text(saveCursorLine); |
653 cursorPos = saveCursorPos; | 707 cursorPos = saveCursorPos; |
654 if ( cursorPos >= text.count() ) { | 708 if ( cursorPos >= text.count() ) { |
655 cursorPos = text.count() - 1; | 709 cursorPos = text.count() - 1; |
656 } | 710 } |
657 | 711 |
658 for ( cursorLine = saveCursorLine; saveCursorLine-cursorLine < 6 && cursorLine >= 0; cursorLine-- ) { | 712 for ( cursorLine = saveCursorLine; saveCursorLine-cursorLine < 6 && cursorLine >= 0; cursorLine-- ) { |
659 text = qSciSourceCodeEditor->text(cursorLine); | 713 text = _qSciSourceCodeEditor->text(cursorLine); |
660 while ( cursorPos >= 0 && enteredCharacter != text.at(cursorPos)) { | 714 while ( cursorPos >= 0 && enteredCharacter != text.at(cursorPos)) { |
661 cursorPos--; | 715 cursorPos--; |
662 } | 716 } |
663 if ( cursorPos < 0 ) { | 717 if ( cursorPos < 0 ) { |
664 cursorPos = qSciSourceCodeEditor->lineLength(cursorLine-1) - 1; | 718 cursorPos = _qSciSourceCodeEditor->lineLength(cursorLine-1) - 1; |
665 } | 719 } |
666 else { | 720 else { |
667 charFound = true; | 721 charFound = true; |
668 break; | 722 break; |
669 } | 723 } |
670 } | 724 } |
671 } | 725 } |
672 | 726 |
673 // If the character was found set its new cursor position... | 727 // If the character was found set its new cursor position... |
674 if ( charFound ) { | 728 if ( charFound ) { |
675 qSciSourceCodeEditor->setCursorPosition( cursorLine, cursorPos+1 ); | 729 _qSciSourceCodeEditor->setCursorPosition( cursorLine, cursorPos+1 ); |
676 } | 730 } |
677 // ...if it was not found, set the previous cursor position. | 731 // ...if it was not found, set the previous cursor position. |
678 else { | 732 else { |
679 qSciSourceCodeEditor->setCursorPosition( saveCursorLine, saveCursorPos+1 ); | 733 _qSciSourceCodeEditor->setCursorPosition( saveCursorLine, saveCursorPos+1 ); |
680 } | 734 } |
681 } | 735 } |
682 // set the previous cursor position. | 736 // set the previous cursor position. |
683 else if ( enteredCharacter == 10 ) { | 737 else if ( enteredCharacter == 10 ) { |
684 qSciSourceCodeEditor->setCursorPosition( cursorLine, cursorPos ); | 738 _qSciSourceCodeEditor->setCursorPosition( cursorLine, cursorPos ); |
685 } | 739 } |
686 | 740 |
687 | 741 |
688 if ( toolBarWidget->cbLivePreview->isChecked() ) { | 742 if ( _toolBarWidget->cbLivePreview->isChecked() ) { |
689 sourceCodeChanged = false; | 743 _sourceCodeChanged = false; |
690 } | 744 } |
691 | 745 |
692 if ( savedSourceContent == qSciSourceCodeEditor->text() ) { | 746 if ( _savedSourceContent == _qSciSourceCodeEditor->text() ) { |
693 qSciSourceCodeEditor->setModified( false ); | 747 _qSciSourceCodeEditor->setModified( false ); |
694 setWindowModified( false ); | 748 setWindowModified( false ); |
695 } | 749 } |
696 else { | 750 else { |
697 qSciSourceCodeEditor->setModified( true ); // Has no effect according to QScintilla docs. | 751 _qSciSourceCodeEditor->setModified( true ); // Has no effect according to QScintilla docs. |
698 setWindowModified( true ); | 752 setWindowModified( true ); |
699 } | 753 } |
700 | 754 |
701 // Could set cursor this way and use normal linear search in text instead of columns and rows. | 755 // Could set cursor this way and use normal linear search in text instead of columns and rows. |
702 //qSciSourceCodeEditor->SendScintilla(QsciScintillaBase::SCI_SETCURRENTPOS, 50); | 756 //_qSciSourceCodeEditor->SendScintilla(QsciScintillaBase::SCI_SETCURRENTPOS, 50); |
703 //qSciSourceCodeEditor->SendScintilla(QsciScintillaBase::SCI_SETANCHOR, 50); | 757 //_qSciSourceCodeEditor->SendScintilla(QsciScintillaBase::SCI_SETANCHOR, 50); |
704 } | 758 } |
705 | 759 |
706 | 760 |
707 /*! | 761 /*! |
708 \brief This slot is called whenever one of the indenter settings are changed. | 762 \brief This slot is called whenever one of the indenter _settings are changed. |
709 | 763 |
710 It calls the selected indenter if the preview is turned on. If preview | 764 It calls the selected indenter if the preview is turned on. If preview |
711 is not active a flag is set, that the settings have changed. | 765 is not active a flag is set, that the _settings have changed. |
712 */ | 766 */ |
713 void MainWindow::indentSettingsChangedSlot() { | 767 void MainWindow::indentSettingsChangedSlot() { |
714 indentSettingsChanged = true; | 768 _indentSettingsChanged = true; |
715 | 769 |
716 int cursorLine, cursorPos; | 770 int cursorLine, cursorPos; |
717 qSciSourceCodeEditor->getCursorPosition(&cursorLine, &cursorPos); | 771 _qSciSourceCodeEditor->getCursorPosition(&cursorLine, &cursorPos); |
718 | 772 |
719 if ( toolBarWidget->cbLivePreview->isChecked() ) { | 773 if ( _toolBarWidget->cbLivePreview->isChecked() ) { |
720 callIndenter(); | 774 callIndenter(); |
721 previewToggled = true; | 775 _previewToggled = true; |
722 | 776 |
723 updateSourceView(); | 777 updateSourceView(); |
724 if (sourceCodeChanged) { | 778 if (_sourceCodeChanged) { |
725 /* savedCursor = qSciSourceCodeEditor->textCursor(); | 779 /* savedCursor = _qSciSourceCodeEditor->textCursor(); |
726 if ( cursorPos >= qSciSourceCodeEditor->text().count() ) { | 780 if ( cursorPos >= _qSciSourceCodeEditor->text().count() ) { |
727 cursorPos = qSciSourceCodeEditor->text().count() - 1; | 781 cursorPos = _qSciSourceCodeEditor->text().count() - 1; |
728 } | 782 } |
729 savedCursor.setPosition( cursorPos ); | 783 savedCursor.setPosition( cursorPos ); |
730 qSciSourceCodeEditor->setTextCursor( savedCursor ); | 784 _qSciSourceCodeEditor->setTextCursor( savedCursor ); |
731 */ | 785 */ |
732 sourceCodeChanged = false; | 786 _sourceCodeChanged = false; |
733 } | 787 } |
734 indentSettingsChanged = false; | 788 _indentSettingsChanged = false; |
735 } | 789 } |
736 else { | 790 else { |
737 updateSourceView(); | 791 updateSourceView(); |
738 } | 792 } |
739 | 793 |
740 if ( savedSourceContent == qSciSourceCodeEditor->text() ) { | 794 if ( _savedSourceContent == _qSciSourceCodeEditor->text() ) { |
741 qSciSourceCodeEditor->setModified( false ); | 795 _qSciSourceCodeEditor->setModified( false ); |
742 setWindowModified( false ); | 796 setWindowModified( false ); |
743 } | 797 } |
744 else { | 798 else { |
745 qSciSourceCodeEditor->setModified( true ); // Has no effect according to QScintilla docs. | 799 _qSciSourceCodeEditor->setModified( true ); // Has no effect according to QScintilla docs. |
746 setWindowModified( true ); | 800 setWindowModified( true ); |
747 } | 801 } |
748 } | 802 } |
749 | 803 |
750 | 804 |
753 | 807 |
754 It calls the selected indenter to format the current source code if | 808 It calls the selected indenter to format the current source code if |
755 the code has been changed since the last indenter call. | 809 the code has been changed since the last indenter call. |
756 */ | 810 */ |
757 void MainWindow::previewTurnedOnOff(bool turnOn) { | 811 void MainWindow::previewTurnedOnOff(bool turnOn) { |
758 previewToggled = true; | 812 _previewToggled = true; |
759 | 813 |
760 int cursorLine, cursorPos; | 814 int cursorLine, cursorPos; |
761 qSciSourceCodeEditor->getCursorPosition(&cursorLine, &cursorPos); | 815 _qSciSourceCodeEditor->getCursorPosition(&cursorLine, &cursorPos); |
762 | 816 |
763 if ( turnOn && (indentSettingsChanged || sourceCodeChanged) ) { | 817 if ( turnOn && (_indentSettingsChanged || _sourceCodeChanged) ) { |
764 callIndenter(); | 818 callIndenter(); |
765 } | 819 } |
766 updateSourceView(); | 820 updateSourceView(); |
767 if (sourceCodeChanged) { | 821 if (_sourceCodeChanged) { |
768 /* savedCursor = qSciSourceCodeEditor->textCursor(); | 822 /* savedCursor = _qSciSourceCodeEditor->textCursor(); |
769 if ( cursorPos >= qSciSourceCodeEditor->text().count() ) { | 823 if ( cursorPos >= _qSciSourceCodeEditor->text().count() ) { |
770 cursorPos = qSciSourceCodeEditor->text().count() - 1; | 824 cursorPos = _qSciSourceCodeEditor->text().count() - 1; |
771 } | 825 } |
772 savedCursor.setPosition( cursorPos ); | 826 savedCursor.setPosition( cursorPos ); |
773 qSciSourceCodeEditor->setTextCursor( savedCursor ); | 827 _qSciSourceCodeEditor->setTextCursor( savedCursor ); |
774 */ | 828 */ |
775 sourceCodeChanged = false; | 829 _sourceCodeChanged = false; |
776 } | 830 } |
777 indentSettingsChanged = false; | 831 _indentSettingsChanged = false; |
778 | 832 |
779 if ( savedSourceContent == qSciSourceCodeEditor->text() ) { | 833 if ( _savedSourceContent == _qSciSourceCodeEditor->text() ) { |
780 qSciSourceCodeEditor->setModified( false ); | 834 _qSciSourceCodeEditor->setModified( false ); |
781 setWindowModified( false ); | 835 setWindowModified( false ); |
782 } | 836 } |
783 else { | 837 else { |
784 qSciSourceCodeEditor->setModified( true ); | 838 _qSciSourceCodeEditor->setModified( true ); |
785 setWindowModified( true ); | 839 setWindowModified( true ); |
786 } | 840 } |
787 } | 841 } |
788 | 842 |
789 | 843 |
790 /*! | 844 /*! |
791 \brief This slot updates the main window title to show the currently opened | 845 \brief This slot updates the main window title to show the currently opened |
792 source code filename. | 846 source code filename. |
793 */ | 847 */ |
794 void MainWindow::updateWindowTitle() { | 848 void MainWindow::updateWindowTitle() { |
795 this->setWindowTitle( "UniversalIndentGUI " + QString(PROGRAM_VERSION_STRING) + " [*]" + currentSourceFile ); | 849 this->setWindowTitle( "UniversalIndentGUI " + QString(PROGRAM_VERSION_STRING) + " [*]" + _currentSourceFile ); |
796 } | 850 } |
797 | 851 |
798 | 852 |
799 /*! | 853 /*! |
800 \brief Opens a dialog to save the current source code as a PDF document. | 854 \brief Opens a dialog to save the current source code as a PDF document. |
801 */ | 855 */ |
802 void MainWindow::exportToPDF() { | 856 void MainWindow::exportToPDF() { |
803 QString fileExtensions = tr("PDF Document")+" (*.pdf)"; | 857 QString fileExtensions = tr("PDF Document")+" (*.pdf)"; |
804 | 858 |
805 QString fileName = currentSourceFile; | 859 QString fileName = _currentSourceFile; |
806 QFileInfo fileInfo(fileName); | 860 QFileInfo fileInfo(fileName); |
807 QString fileExtension = fileInfo.suffix(); | 861 QString fileExtension = fileInfo.suffix(); |
808 | 862 |
809 fileName.replace( fileName.length()-fileExtension.length(), fileExtension.length(), "pdf" ); | 863 fileName.replace( fileName.length()-fileExtension.length(), fileExtension.length(), "pdf" ); |
810 fileName = QFileDialog::getSaveFileName( this, tr("Export source code file"), fileName, fileExtensions); | 864 fileName = QFileDialog::getSaveFileName( this, tr("Export source code file"), fileName, fileExtensions); |
811 | 865 |
812 if ( !fileName.isEmpty() ) { | 866 if ( !fileName.isEmpty() ) { |
813 QsciPrinter printer(QPrinter::HighResolution); | 867 QsciPrinter printer(QPrinter::HighResolution); |
814 printer.setOutputFormat(QPrinter::PdfFormat); | 868 printer.setOutputFormat(QPrinter::PdfFormat); |
815 printer.setOutputFileName(fileName); | 869 printer.setOutputFileName(fileName); |
816 printer.printRange(qSciSourceCodeEditor); | 870 printer.printRange(_qSciSourceCodeEditor); |
817 } | 871 } |
818 } | 872 } |
819 | 873 |
820 | 874 |
821 /*! | 875 /*! |
822 \brief Opens a dialog to save the current source code as a HTML document. | 876 \brief Opens a dialog to save the current source code as a HTML document. |
823 */ | 877 */ |
824 void MainWindow::exportToHTML() { | 878 void MainWindow::exportToHTML() { |
825 QString fileExtensions = tr("HTML Document")+" (*.html)"; | 879 QString fileExtensions = tr("HTML Document")+" (*.html)"; |
826 | 880 |
827 QString fileName = currentSourceFile; | 881 QString fileName = _currentSourceFile; |
828 QFileInfo fileInfo(fileName); | 882 QFileInfo fileInfo(fileName); |
829 QString fileExtension = fileInfo.suffix(); | 883 QString fileExtension = fileInfo.suffix(); |
830 | 884 |
831 fileName.replace( fileName.length()-fileExtension.length(), fileExtension.length(), "html" ); | 885 fileName.replace( fileName.length()-fileExtension.length(), fileExtension.length(), "html" ); |
832 fileName = QFileDialog::getSaveFileName( this, tr("Export source code file"), fileName, fileExtensions); | 886 fileName = QFileDialog::getSaveFileName( this, tr("Export source code file"), fileName, fileExtensions); |
833 | 887 |
834 if ( !fileName.isEmpty() ) { | 888 if ( !fileName.isEmpty() ) { |
835 // Create a document from which HTML code can be generated. | 889 // Create a document from which HTML code can be generated. |
836 QTextDocument sourceCodeDocument( qSciSourceCodeEditor->text() ); | 890 QTextDocument sourceCodeDocument( _qSciSourceCodeEditor->text() ); |
837 sourceCodeDocument.setDefaultFont( QFont("Courier", 12, QFont::Normal) ); | 891 sourceCodeDocument.setDefaultFont( QFont("Courier", 12, QFont::Normal) ); |
838 QString sourceCodeAsHTML = sourceCodeDocument.toHtml(); | 892 QString sourceCodeAsHTML = sourceCodeDocument.toHtml(); |
839 // To ensure that empty lines are kept in the HTML code make this replacement. | 893 // To ensure that empty lines are kept in the HTML code make this replacement. |
840 sourceCodeAsHTML.replace("\"></p>", "\"><br /></p>"); | 894 sourceCodeAsHTML.replace("\"></p>", "\"><br /></p>"); |
841 | 895 |
848 } | 902 } |
849 } | 903 } |
850 | 904 |
851 | 905 |
852 /*! | 906 /*! |
853 \brief Loads the last opened file if this option is enabled in the settings. | 907 \brief Loads the last opened file if this option is enabled in the _settings. |
854 | 908 |
855 If the file does not exist, the default example file is tried to be loaded. If even that | 909 If the file does not exist, the default example file is tried to be loaded. If even that |
856 fails a very small code example is shown. | 910 fails a very small code example is shown. |
857 If the setting for opening the last file is disabled, the editor is empty on startup. | 911 If the setting for opening the last file is disabled, the editor is empty on startup. |
858 */ | 912 */ |
859 void MainWindow::loadLastOpenedFile() { | 913 void MainWindow::loadLastOpenedFile() { |
860 // Get setting for last opened source code file. | 914 // Get setting for last opened source code file. |
861 loadLastSourceCodeFileOnStartup = settings->getValueByName("loadLastSourceCodeFileOnStartup").toBool(); | 915 _loadLastSourceCodeFileOnStartup = _settings->getValueByName("loadLastSourceCodeFileOnStartup").toBool(); |
862 | 916 |
863 // Only load last source code file if set to do so | 917 // Only load last source code file if set to do so |
864 if ( loadLastSourceCodeFileOnStartup ) { | 918 if ( _loadLastSourceCodeFileOnStartup ) { |
865 // From the list of last opened files get the first one. | 919 // From the list of last opened files get the first one. |
866 currentSourceFile = settings->getValueByName("lastSourceCodeFile").toString().split("|").first(); | 920 _currentSourceFile = _settings->getValueByName("lastSourceCodeFile").toString().split("|").first(); |
867 | 921 |
868 // If source file exist load it. | 922 // If source file exist load it. |
869 if ( QFile::exists(currentSourceFile) ) { | 923 if ( QFile::exists(_currentSourceFile) ) { |
870 QFileInfo fileInfo(currentSourceFile); | 924 QFileInfo fileInfo(_currentSourceFile); |
871 currentSourceFile = fileInfo.absoluteFilePath(); | 925 _currentSourceFile = fileInfo.absoluteFilePath(); |
872 sourceFileContent = loadFile(currentSourceFile); | 926 _sourceFileContent = loadFile(_currentSourceFile); |
873 } | 927 } |
874 // If the last opened source code file does not exist, try to load the default example.cpp file. | 928 // If the last opened source code file does not exist, try to load the default example.cpp file. |
875 else if ( QFile::exists( SettingsPaths::getIndenterPath() + "/example.cpp" ) ) { | 929 else if ( QFile::exists( SettingsPaths::getIndenterPath() + "/example.cpp" ) ) { |
876 QFileInfo fileInfo( SettingsPaths::getIndenterPath() + "/example.cpp" ); | 930 QFileInfo fileInfo( SettingsPaths::getIndenterPath() + "/example.cpp" ); |
877 currentSourceFile = fileInfo.absoluteFilePath(); | 931 _currentSourceFile = fileInfo.absoluteFilePath(); |
878 sourceFileContent = loadFile(currentSourceFile); | 932 _sourceFileContent = loadFile(_currentSourceFile); |
879 } | 933 } |
880 // If neither the example source code file exists show some small code example. | 934 // If neither the example source code file exists show some small code example. |
881 else { | 935 else { |
882 currentSourceFile = "untitled.cpp"; | 936 _currentSourceFile = "untitled.cpp"; |
883 currentSourceFileExtension = "cpp"; | 937 _currentSourceFileExtension = "cpp"; |
884 sourceFileContent = "if(x==\"y\"){x=z;}"; | 938 _sourceFileContent = "if(x==\"y\"){x=z;}"; |
885 } | 939 } |
886 } | 940 } |
887 // if last opened source file should not be loaded make some default settings. | 941 // if last opened source file should not be loaded make some default _settings. |
888 else { | 942 else { |
889 currentSourceFile = "untitled.cpp"; | 943 _currentSourceFile = "untitled.cpp"; |
890 currentSourceFileExtension = "cpp"; | 944 _currentSourceFileExtension = "cpp"; |
891 sourceFileContent = ""; | 945 _sourceFileContent = ""; |
892 } | 946 } |
893 savedSourceContent = sourceFileContent; | 947 _savedSourceContent = _sourceFileContent; |
894 | 948 |
895 // Update the mainwindow title to show the name of the loaded source code file. | 949 // Update the mainwindow title to show the name of the loaded source code file. |
896 updateWindowTitle(); | 950 updateWindowTitle(); |
897 } | 951 } |
898 | 952 |
899 | 953 |
900 /*! | 954 /*! |
901 \brief Saves the settings for the main application to the file "UniversalIndentGUI.ini". | 955 \brief Saves the _settings for the main application to the file "UniversalIndentGUI.ini". |
902 | 956 |
903 Settings are for example last selected indenter, last loaded config file and so on. | 957 Settings are for example last selected indenter, last loaded config file and so on. |
904 */ | 958 */ |
905 void MainWindow::saveSettings() { | 959 void MainWindow::saveSettings() { |
906 settings->setValueByName( "encoding", currentEncoding ); | 960 _settings->setValueByName( "encoding", _currentEncoding ); |
907 settings->setValueByName( "version", PROGRAM_VERSION_STRING ); | 961 _settings->setValueByName( "version", PROGRAM_VERSION_STRING ); |
908 settings->setValueByName( "maximized", isMaximized() ); | 962 _settings->setValueByName( "maximized", isMaximized() ); |
909 if ( !isMaximized() ) { | 963 if ( !isMaximized() ) { |
910 settings->setValueByName( "position", pos() ); | 964 _settings->setValueByName( "position", pos() ); |
911 settings->setValueByName( "size", size() ); | 965 _settings->setValueByName( "size", size() ); |
912 } | 966 } |
913 settings->setValueByName( "MainWindowState", saveState() ); | 967 _settings->setValueByName( "MainWindowState", saveState() ); |
914 | 968 |
915 // Also save the syntax highlight style for all lexers. | 969 // Also save the syntax highlight style for all lexers. |
916 highlighter->writeCurrentSettings(""); | 970 _highlighter->writeCurrentSettings(""); |
917 } | 971 } |
918 | 972 |
919 | 973 |
920 /*! | 974 /*! |
921 \brief Is always called when the program is quit. Calls the saveSettings function before really quits. | 975 \brief Is always called when the program is quit. Calls the saveSettings function before really quits. |
932 | 986 |
933 | 987 |
934 /*! | 988 /*! |
935 \brief This function is setup to capture tooltip events. | 989 \brief This function is setup to capture tooltip events. |
936 | 990 |
937 All widgets that are created by the indentHandler object and are responsible | 991 All widgets that are created by the _indentHandler object and are responsible |
938 for indenter parameters are connected with this event filter. | 992 for indenter parameters are connected with this event filter. |
939 So depending on the settings the tooltips can be enabled and disabled for these widgets. | 993 So depending on the _settings the tooltips can be enabled and disabled for these widgets. |
940 */ | 994 */ |
941 bool MainWindow::eventFilter(QObject *obj, QEvent *event) { | 995 bool MainWindow::eventFilter(QObject *obj, QEvent *event) { |
942 if ( event->type() == QEvent::ToolTip) { | 996 if ( event->type() == QEvent::ToolTip) { |
943 if ( indenterParameterTooltipsEnabledAction->isChecked() ) { | 997 if ( _mainWindowForm->indenterParameterTooltipsEnabledAction->isChecked() ) { |
944 return QMainWindow::eventFilter(obj, event); | 998 return QMainWindow::eventFilter(obj, event); |
945 } | 999 } |
946 else { | 1000 else { |
947 //QToolTip::showText( QPoint(100,100) , "Test1"); | 1001 //QToolTip::showText( QPoint(100,100) , "Test1"); |
948 return true; | 1002 return true; |
979 /*! | 1033 /*! |
980 \brief This slot is called whenever a language is selected in the menu. It tries to find the | 1034 \brief This slot is called whenever a language is selected in the menu. It tries to find the |
981 corresponding action in the languageInfoList and sets the language. | 1035 corresponding action in the languageInfoList and sets the language. |
982 */ | 1036 */ |
983 void MainWindow::languageChanged(int languageIndex) { | 1037 void MainWindow::languageChanged(int languageIndex) { |
984 if ( languageIndex < settings->getAvailableTranslations().size() ) { | 1038 if ( languageIndex < _settings->getAvailableTranslations().size() ) { |
985 // Get the mnemonic of the new selected language. | 1039 // Get the mnemonic of the new selected language. |
986 QString languageShort = settings->getAvailableTranslations().at(languageIndex); | 1040 QString languageShort = _settings->getAvailableTranslations().at(languageIndex); |
987 | 1041 |
988 // Remove the old qt translation. | 1042 // Remove the old qt translation. |
989 qApp->removeTranslator( qTTranslator ); | 1043 qApp->removeTranslator( _qTTranslator ); |
990 | 1044 |
991 // Remove the old uigui translation. | 1045 // Remove the old uigui translation. |
992 qApp->removeTranslator( uiGuiTranslator ); | 1046 qApp->removeTranslator( _uiGuiTranslator ); |
993 | 1047 |
994 // Load the Qt own translation file and set it for the application. | 1048 // Load the Qt own translation file and set it for the application. |
995 bool translationFileLoaded; | 1049 bool translationFileLoaded; |
996 translationFileLoaded = qTTranslator->load( SettingsPaths::getGlobalFilesPath() + "/translations/qt_" + languageShort ); | 1050 translationFileLoaded = _qTTranslator->load( SettingsPaths::getGlobalFilesPath() + "/translations/qt_" + languageShort ); |
997 if ( translationFileLoaded ) { | 1051 if ( translationFileLoaded ) { |
998 qApp->installTranslator(qTTranslator); | 1052 qApp->installTranslator(_qTTranslator); |
999 } | 1053 } |
1000 | 1054 |
1001 // Load the uigui translation file and set it for the application. | 1055 // Load the uigui translation file and set it for the application. |
1002 translationFileLoaded = uiGuiTranslator->load( SettingsPaths::getGlobalFilesPath() + "/translations/universalindent_" + languageShort ); | 1056 translationFileLoaded = _uiGuiTranslator->load( SettingsPaths::getGlobalFilesPath() + "/translations/universalindent_" + languageShort ); |
1003 if ( translationFileLoaded ) { | 1057 if ( translationFileLoaded ) { |
1004 qApp->installTranslator(uiGuiTranslator); | 1058 qApp->installTranslator(_uiGuiTranslator); |
1005 } | 1059 } |
1006 } | 1060 } |
1007 } | 1061 } |
1008 | 1062 |
1009 | 1063 |
1012 */ | 1066 */ |
1013 void MainWindow::createEncodingMenu() { | 1067 void MainWindow::createEncodingMenu() { |
1014 QAction *encodingAction; | 1068 QAction *encodingAction; |
1015 QString encodingName; | 1069 QString encodingName; |
1016 | 1070 |
1017 encodingsList = QStringList() << "UTF-8" << "UTF-16" << "UTF-16BE" << "UTF-16LE" | 1071 _encodingsList = QStringList() << "UTF-8" << "UTF-16" << "UTF-16BE" << "UTF-16LE" |
1018 << "Apple Roman" << "Big5" << "Big5-HKSCS" << "EUC-JP" << "EUC-KR" << "GB18030-0" | 1072 << "Apple Roman" << "Big5" << "Big5-HKSCS" << "EUC-JP" << "EUC-KR" << "GB18030-0" |
1019 << "IBM 850" << "IBM 866" << "IBM 874" << "ISO 2022-JP" << "ISO 8859-1" << "ISO 8859-13" | 1073 << "IBM 850" << "IBM 866" << "IBM 874" << "ISO 2022-JP" << "ISO 8859-1" << "ISO 8859-13" |
1020 << "Iscii-Bng" << "JIS X 0201" << "JIS X 0208" << "KOI8-R" << "KOI8-U" << "MuleLao-1" | 1074 << "Iscii-Bng" << "JIS X 0201" << "JIS X 0208" << "KOI8-R" << "KOI8-U" << "MuleLao-1" |
1021 << "ROMAN8" << "Shift-JIS" << "TIS-620" << "TSCII" << "Windows-1250" << "WINSAMI2"; | 1075 << "ROMAN8" << "Shift-JIS" << "TIS-620" << "TSCII" << "Windows-1250" << "WINSAMI2"; |
1022 | 1076 |
1023 encodingActionGroup = new QActionGroup(this); | 1077 _encodingActionGroup = new QActionGroup(this); |
1024 saveEncodedActionGroup = new QActionGroup(this); | 1078 _saveEncodedActionGroup = new QActionGroup(this); |
1025 | 1079 |
1026 // Loop for each available encoding | 1080 // Loop for each available encoding |
1027 foreach ( encodingName, encodingsList ) { | 1081 foreach ( encodingName, _encodingsList ) { |
1028 // Create actions for the "reopen" menu | 1082 // Create actions for the "reopen" menu |
1029 encodingAction = new QAction(encodingName, encodingActionGroup); | 1083 encodingAction = new QAction(encodingName, _encodingActionGroup); |
1030 encodingAction->setStatusTip( tr("Reopen the currently opened source code file by using the text encoding scheme ") + encodingName ); | 1084 encodingAction->setStatusTip( tr("Reopen the currently opened source code file by using the text encoding scheme ") + encodingName ); |
1031 encodingAction->setCheckable(true); | 1085 encodingAction->setCheckable(true); |
1032 if ( encodingName == currentEncoding ) { | 1086 if ( encodingName == _currentEncoding ) { |
1033 encodingAction->setChecked(true); | 1087 encodingAction->setChecked(true); |
1034 } | 1088 } |
1035 | 1089 |
1036 // Create actions for the "save as encoded" menu | 1090 // Create actions for the "save as encoded" menu |
1037 encodingAction = new QAction(encodingName, saveEncodedActionGroup); | 1091 encodingAction = new QAction(encodingName, _saveEncodedActionGroup); |
1038 encodingAction->setStatusTip( tr("Save the currently opened source code file by using the text encoding scheme ") + encodingName ); | 1092 encodingAction->setStatusTip( tr("Save the currently opened source code file by using the text encoding scheme ") + encodingName ); |
1039 } | 1093 } |
1040 | 1094 |
1041 encodingMenu->addActions( encodingActionGroup->actions() ); | 1095 _mainWindowForm->encodingMenu->addActions( _encodingActionGroup->actions() ); |
1042 connect( encodingActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(encodingChanged(QAction*)) ); | 1096 connect( _encodingActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(encodingChanged(QAction*)) ); |
1043 | 1097 |
1044 saveEncodedMenu->addActions( saveEncodedActionGroup->actions() ); | 1098 _mainWindowForm->saveEncodedMenu->addActions( _saveEncodedActionGroup->actions() ); |
1045 connect( saveEncodedActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(saveAsOtherEncoding(QAction*)) ); | 1099 connect( _saveEncodedActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(saveAsOtherEncoding(QAction*)) ); |
1046 } | 1100 } |
1047 | 1101 |
1048 | 1102 |
1049 /*! | 1103 /*! |
1050 \brief This slot calls the save dialog to save the current source file with another encoding. | 1104 \brief This slot calls the save dialog to save the current source file with another encoding. |
1055 void MainWindow::saveAsOtherEncoding(QAction *chosenEncodingAction) { | 1109 void MainWindow::saveAsOtherEncoding(QAction *chosenEncodingAction) { |
1056 bool fileWasSaved = saveasSourceFileDialog(chosenEncodingAction); | 1110 bool fileWasSaved = saveasSourceFileDialog(chosenEncodingAction); |
1057 | 1111 |
1058 // If the file was save with another encoding, change the selected encoding in the reopen menu. | 1112 // If the file was save with another encoding, change the selected encoding in the reopen menu. |
1059 if ( fileWasSaved ) { | 1113 if ( fileWasSaved ) { |
1060 foreach ( QAction *action, encodingActionGroup->actions() ) { | 1114 foreach ( QAction *action, _encodingActionGroup->actions() ) { |
1061 if ( action->text() == chosenEncodingAction->text() ) { | 1115 if ( action->text() == chosenEncodingAction->text() ) { |
1062 action->setChecked(true); | 1116 action->setChecked(true); |
1063 return; | 1117 return; |
1064 } | 1118 } |
1065 } | 1119 } |
1070 /*! | 1124 /*! |
1071 \brief This slot is called whenever an encoding is selected in the settings menu. | 1125 \brief This slot is called whenever an encoding is selected in the settings menu. |
1072 */ | 1126 */ |
1073 void MainWindow::encodingChanged(QAction* encodingAction) { | 1127 void MainWindow::encodingChanged(QAction* encodingAction) { |
1074 if ( maybeSave() ) { | 1128 if ( maybeSave() ) { |
1075 QFile inSrcFile(currentSourceFile); | 1129 QFile inSrcFile(_currentSourceFile); |
1076 QString fileContent = ""; | 1130 QString fileContent = ""; |
1077 | 1131 |
1078 if ( !inSrcFile.open(QFile::ReadOnly | QFile::Text) ) { | 1132 if ( !inSrcFile.open(QFile::ReadOnly | QFile::Text) ) { |
1079 QMessageBox::warning(NULL, tr("Error opening file"), tr("Cannot read the file ")+"\""+currentSourceFile+"\"." ); | 1133 QMessageBox::warning(NULL, tr("Error opening file"), tr("Cannot read the file ")+"\""+_currentSourceFile+"\"." ); |
1080 } | 1134 } |
1081 else { | 1135 else { |
1082 QTextStream inSrcStrm(&inSrcFile); | 1136 QTextStream inSrcStrm(&inSrcFile); |
1083 QApplication::setOverrideCursor(Qt::WaitCursor); | 1137 QApplication::setOverrideCursor(Qt::WaitCursor); |
1084 QString encodingName = encodingAction->text(); | 1138 QString encodingName = encodingAction->text(); |
1085 currentEncoding = encodingName; | 1139 _currentEncoding = encodingName; |
1086 inSrcStrm.setCodec( QTextCodec::codecForName(encodingName.toAscii()) ); | 1140 inSrcStrm.setCodec( QTextCodec::codecForName(encodingName.toAscii()) ); |
1087 fileContent = inSrcStrm.readAll(); | 1141 fileContent = inSrcStrm.readAll(); |
1088 QApplication::restoreOverrideCursor(); | 1142 QApplication::restoreOverrideCursor(); |
1089 inSrcFile.close(); | 1143 inSrcFile.close(); |
1090 qSciSourceCodeEditor->setText( fileContent ); | 1144 _qSciSourceCodeEditor->setText( fileContent ); |
1091 qSciSourceCodeEditor->setModified(false); | 1145 _qSciSourceCodeEditor->setModified(false); |
1092 } | 1146 } |
1093 } | 1147 } |
1094 } | 1148 } |
1095 | 1149 |
1096 | 1150 |
1099 */ | 1153 */ |
1100 void MainWindow::createHighlighterMenu() { | 1154 void MainWindow::createHighlighterMenu() { |
1101 QAction *highlighterAction; | 1155 QAction *highlighterAction; |
1102 QString highlighterName; | 1156 QString highlighterName; |
1103 | 1157 |
1104 highlighterActionGroup = new QActionGroup(this); | 1158 _highlighterActionGroup = new QActionGroup(this); |
1105 | 1159 |
1106 // Loop for each known highlighter | 1160 // Loop for each known highlighter |
1107 foreach ( highlighterName, highlighter->getAvailableHighlighters() ) { | 1161 foreach ( highlighterName, _highlighter->getAvailableHighlighters() ) { |
1108 highlighterAction = new QAction(highlighterName, highlighterActionGroup); | 1162 highlighterAction = new QAction(highlighterName, _highlighterActionGroup); |
1109 highlighterAction->setStatusTip( tr("Set the syntax highlightning to ") + highlighterName ); | 1163 highlighterAction->setStatusTip( tr("Set the syntax highlightning to ") + highlighterName ); |
1110 highlighterAction->setCheckable(true); | 1164 highlighterAction->setCheckable(true); |
1111 } | 1165 } |
1112 highlighterMenu->addActions( highlighterActionGroup->actions() ); | 1166 _mainWindowForm->highlighterMenu->addActions( _highlighterActionGroup->actions() ); |
1113 menuSettings->insertMenu(indenterParameterTooltipsEnabledAction, highlighterMenu ); | 1167 _mainWindowForm->menuSettings->insertMenu(_mainWindowForm->indenterParameterTooltipsEnabledAction, _mainWindowForm->highlighterMenu ); |
1114 | 1168 |
1115 connect( highlighterActionGroup, SIGNAL(triggered(QAction*)), highlighter, SLOT(setHighlighterByAction(QAction*)) ); | 1169 connect( _highlighterActionGroup, SIGNAL(triggered(QAction*)), _highlighter, SLOT(setHighlighterByAction(QAction*)) ); |
1116 } | 1170 } |
1117 | 1171 |
1118 | 1172 |
1119 /*! | 1173 /*! |
1120 \brief Is called whenever the white space visibility is being changed in the menu. | 1174 \brief Is called whenever the white space visibility is being changed in the menu. |
1121 */ | 1175 */ |
1122 void MainWindow::setWhiteSpaceVisibility(bool visible) { | 1176 void MainWindow::setWhiteSpaceVisibility(bool visible) { |
1123 if ( qSciSourceCodeEditor != NULL ) { | 1177 if ( _qSciSourceCodeEditor != NULL ) { |
1124 if ( visible ) { | 1178 if ( visible ) { |
1125 qSciSourceCodeEditor->setWhitespaceVisibility(QsciScintilla::WsVisible); | 1179 _qSciSourceCodeEditor->setWhitespaceVisibility(QsciScintilla::WsVisible); |
1126 } | 1180 } |
1127 else { | 1181 else { |
1128 qSciSourceCodeEditor->setWhitespaceVisibility(QsciScintilla::WsInvisible); | 1182 _qSciSourceCodeEditor->setWhitespaceVisibility(QsciScintilla::WsInvisible); |
1129 } | 1183 } |
1130 } | 1184 } |
1131 } | 1185 } |
1132 | 1186 |
1133 /*! | 1187 /*! |
1134 \brief This slot is called whenever the number of lines in the editor changes | 1188 \brief This slot is called whenever the number of lines in the editor changes |
1135 and adapts the margin for the displayed line numbers. | 1189 and adapts the margin for the displayed line numbers. |
1136 */ | 1190 */ |
1137 void MainWindow::numberOfLinesChanged() { | 1191 void MainWindow::numberOfLinesChanged() { |
1138 QString lineNumbers; | 1192 QString lineNumbers; |
1139 lineNumbers.setNum( qSciSourceCodeEditor->lines()*10 ); | 1193 lineNumbers.setNum( _qSciSourceCodeEditor->lines()*10 ); |
1140 qSciSourceCodeEditor->setMarginWidth(1, lineNumbers); | 1194 _qSciSourceCodeEditor->setMarginWidth(1, lineNumbers); |
1141 } | 1195 } |
1142 | 1196 |
1143 | 1197 |
1144 /*! | 1198 /*! |
1145 \brief Catches language change events and retranslates all needed widgets. | 1199 \brief Catches language change events and retranslates all needed widgets. |
1149 | 1203 |
1150 if (event->type() == QEvent::LanguageChange) { | 1204 if (event->type() == QEvent::LanguageChange) { |
1151 QString languageName; | 1205 QString languageName; |
1152 | 1206 |
1153 // Translate the main window. | 1207 // Translate the main window. |
1154 retranslateUi(this); | 1208 _mainWindowForm->retranslateUi(this); |
1155 updateWindowTitle(); | 1209 updateWindowTitle(); |
1156 | 1210 |
1157 // Translate the toolbar. | 1211 // Translate the toolbar. |
1158 toolBarWidget->retranslateUi(toolBar); | 1212 _toolBarWidget->retranslateUi(_mainWindowForm->toolBar); |
1159 | 1213 |
1160 // Translate the indent handler widget. | 1214 // Translate the indent handler widget. |
1161 indentHandler->retranslateUi(); | 1215 _indentHandler->retranslateUi(); |
1162 | 1216 |
1163 // Translate the load encoding menu. | 1217 // Translate the load encoding menu. |
1164 QList<QAction *> encodingActionList = encodingActionGroup->actions(); | 1218 QList<QAction *> encodingActionList = _encodingActionGroup->actions(); |
1165 for ( i = 0; i < encodingActionList.size(); i++ ) { | 1219 for ( i = 0; i < encodingActionList.size(); i++ ) { |
1166 encodingActionList.at(i)->setStatusTip( tr("Reopen the currently opened source code file by using the text encoding scheme ") + encodingsList.at(i) ); | 1220 encodingActionList.at(i)->setStatusTip( tr("Reopen the currently opened source code file by using the text encoding scheme ") + _encodingsList.at(i) ); |
1167 } | 1221 } |
1168 | 1222 |
1169 // Translate the save encoding menu. | 1223 // Translate the save encoding menu. |
1170 encodingActionList = saveEncodedActionGroup->actions(); | 1224 encodingActionList = _saveEncodedActionGroup->actions(); |
1171 for ( i = 0; i < encodingActionList.size(); i++ ) { | 1225 for ( i = 0; i < encodingActionList.size(); i++ ) { |
1172 encodingActionList.at(i)->setStatusTip( tr("Save the currently opened source code file by using the text encoding scheme ") + encodingsList.at(i) ); | 1226 encodingActionList.at(i)->setStatusTip( tr("Save the currently opened source code file by using the text encoding scheme ") + _encodingsList.at(i) ); |
1173 } | 1227 } |
1174 | 1228 |
1175 // Translate the highlighter menu. | 1229 // Translate the _highlighter menu. |
1176 QList<QAction *> actionList = highlighterMenu->actions(); | 1230 QList<QAction *> actionList = _mainWindowForm->highlighterMenu->actions(); |
1177 i = 0; | 1231 i = 0; |
1178 foreach ( QString highlighterName, highlighter->getAvailableHighlighters() ) { | 1232 foreach ( QString highlighterName, _highlighter->getAvailableHighlighters() ) { |
1179 QAction *highlighterAction = actionList.at(i); | 1233 QAction *highlighterAction = actionList.at(i); |
1180 highlighterAction->setStatusTip( tr("Set the syntax highlightning to ") + highlighterName ); | 1234 highlighterAction->setStatusTip( tr("Set the syntax highlightning to ") + highlighterName ); |
1181 i++; | 1235 i++; |
1182 } | 1236 } |
1183 | 1237 |
1184 // Translate the line and column indicators in the statusbar. | 1238 // Translate the line and column indicators in the statusbar. |
1185 int line, column; | 1239 int line, column; |
1186 qSciSourceCodeEditor->getCursorPosition( &line, &column ); | 1240 _qSciSourceCodeEditor->getCursorPosition( &line, &column ); |
1187 setStatusBarCursorPosInfo( line, column ); | 1241 setStatusBarCursorPosInfo( line, column ); |
1188 } | 1242 } |
1189 else { | 1243 else { |
1190 QWidget::changeEvent(event); | 1244 QWidget::changeEvent(event); |
1191 } | 1245 } |
1195 | 1249 |
1196 /*! | 1250 /*! |
1197 \brief Updates the list of recently opened files. | 1251 \brief Updates the list of recently opened files. |
1198 | 1252 |
1199 Therefore the currently open file is set at the lists first position | 1253 Therefore the currently open file is set at the lists first position |
1200 regarding the in the settings set maximum list length. Overheads of the | 1254 regarding the in the _settings set maximum list length. Overheads of the |
1201 list will be cut off. The new list will be updated to the settings and | 1255 list will be cut off. The new list will be updated to the _settings and |
1202 the recently opened menu will be updated too. | 1256 the recently opened menu will be updated too. |
1203 */ | 1257 */ |
1204 void MainWindow::updateRecentlyOpenedList() { | 1258 void MainWindow::updateRecentlyOpenedList() { |
1205 QString fileName; | 1259 QString fileName; |
1206 QString filePath; | 1260 QString filePath; |
1207 QStringList recentlyOpenedList = settings->getValueByName("lastSourceCodeFile").toString().split("|"); | 1261 QStringList recentlyOpenedList = _settings->getValueByName("lastSourceCodeFile").toString().split("|"); |
1208 QList<QAction*> recentlyOpenedActionList = menuRecently_Opened_Files->actions(); | 1262 QList<QAction*> recentlyOpenedActionList = _mainWindowForm->menuRecently_Opened_Files->actions(); |
1209 | 1263 |
1210 // Check if the currently open file is in the list of recently opened. | 1264 // Check if the currently open file is in the list of recently opened. |
1211 int indexOfCurrentFile = recentlyOpenedList.indexOf( currentSourceFile ); | 1265 int indexOfCurrentFile = recentlyOpenedList.indexOf( _currentSourceFile ); |
1212 | 1266 |
1213 // If it is in the list of recently opened files and not at the first position, move it to the first pos. | 1267 // If it is in the list of recently opened files and not at the first position, move it to the first pos. |
1214 if ( indexOfCurrentFile > 0 ) { | 1268 if ( indexOfCurrentFile > 0 ) { |
1215 recentlyOpenedList.move(indexOfCurrentFile, 0); | 1269 recentlyOpenedList.move(indexOfCurrentFile, 0); |
1216 recentlyOpenedActionList.move(indexOfCurrentFile, 0); | 1270 recentlyOpenedActionList.move(indexOfCurrentFile, 0); |
1217 } | 1271 } |
1218 // Put the current file at the first position if it not already is and is not empty. | 1272 // Put the current file at the first position if it not already is and is not empty. |
1219 else if ( indexOfCurrentFile == -1 && !currentSourceFile.isEmpty() ) { | 1273 else if ( indexOfCurrentFile == -1 && !_currentSourceFile.isEmpty() ) { |
1220 recentlyOpenedList.insert(0, currentSourceFile); | 1274 recentlyOpenedList.insert(0, _currentSourceFile); |
1221 QAction *recentlyOpenedAction = new QAction(QFileInfo(currentSourceFile).fileName(), menuRecently_Opened_Files); | 1275 QAction *recentlyOpenedAction = new QAction(QFileInfo(_currentSourceFile).fileName(), _mainWindowForm->menuRecently_Opened_Files); |
1222 recentlyOpenedAction->setStatusTip(currentSourceFile); | 1276 recentlyOpenedAction->setStatusTip(_currentSourceFile); |
1223 recentlyOpenedActionList.insert(0, recentlyOpenedAction ); | 1277 recentlyOpenedActionList.insert(0, recentlyOpenedAction ); |
1224 } | 1278 } |
1225 | 1279 |
1226 // Get the maximum recently opened list size. | 1280 // Get the maximum recently opened list size. |
1227 int recentlyOpenedListMaxSize = settings->getValueByName("recentlyOpenedListSize").toInt(); | 1281 int recentlyOpenedListMaxSize = _settings->getValueByName("recentlyOpenedListSize").toInt(); |
1228 | 1282 |
1229 // Loop for each filepath in the recently opened list, remove non existing files and | 1283 // Loop for each filepath in the recently opened list, remove non existing files and |
1230 // loop only as long as maximum allowed list entries are set. | 1284 // loop only as long as maximum allowed list entries are set. |
1231 for ( int i = 0; i < recentlyOpenedList.size() && i < recentlyOpenedListMaxSize; ) { | 1285 for ( int i = 0; i < recentlyOpenedList.size() && i < recentlyOpenedListMaxSize; ) { |
1232 filePath = recentlyOpenedList.at(i); | 1286 filePath = recentlyOpenedList.at(i); |
1241 } | 1295 } |
1242 } | 1296 } |
1243 // else if its not already in the menu, add it to the menu. | 1297 // else if its not already in the menu, add it to the menu. |
1244 else { | 1298 else { |
1245 if ( i >= recentlyOpenedActionList.size()-2 ) { | 1299 if ( i >= recentlyOpenedActionList.size()-2 ) { |
1246 QAction *recentlyOpenedAction = new QAction(fileInfo.fileName(), menuRecently_Opened_Files); | 1300 QAction *recentlyOpenedAction = new QAction(fileInfo.fileName(), _mainWindowForm->menuRecently_Opened_Files); |
1247 recentlyOpenedAction->setStatusTip(filePath); | 1301 recentlyOpenedAction->setStatusTip(filePath); |
1248 recentlyOpenedActionList.insert( recentlyOpenedActionList.size()-2, recentlyOpenedAction ); | 1302 recentlyOpenedActionList.insert( recentlyOpenedActionList.size()-2, recentlyOpenedAction ); |
1249 } | 1303 } |
1250 i++; | 1304 i++; |
1251 } | 1305 } |
1252 } | 1306 } |
1253 | 1307 |
1254 // Trim the list to its in the settings allowed maximum size. | 1308 // Trim the list to its in the _settings allowed maximum size. |
1255 while ( recentlyOpenedList.size() > recentlyOpenedListMaxSize ) { | 1309 while ( recentlyOpenedList.size() > recentlyOpenedListMaxSize ) { |
1256 recentlyOpenedList.takeLast(); | 1310 recentlyOpenedList.takeLast(); |
1257 QAction* action = recentlyOpenedActionList.takeAt( recentlyOpenedActionList.size()-3 ); | 1311 QAction* action = recentlyOpenedActionList.takeAt( recentlyOpenedActionList.size()-3 ); |
1258 delete action; | 1312 delete action; |
1259 } | 1313 } |
1260 | 1314 |
1261 // Add all actions to the menu. | 1315 // Add all actions to the menu. |
1262 menuRecently_Opened_Files->addActions(recentlyOpenedActionList); | 1316 _mainWindowForm->menuRecently_Opened_Files->addActions(recentlyOpenedActionList); |
1263 | 1317 _mainWindowForm->menuRecently_Opened_Files->addActions(recentlyOpenedActionList); |
1264 // Write the new recently opened list to the settings. | 1318 |
1265 settings->setValueByName( "lastSourceCodeFile", recentlyOpenedList.join("|") ); | 1319 // Write the new recently opened list to the _settings. |
1320 _settings->setValueByName( "lastSourceCodeFile", recentlyOpenedList.join("|") ); | |
1266 | 1321 |
1267 // Enable or disable "actionClear_Recently_Opened_List" if list is [not] emtpy | 1322 // Enable or disable "actionClear_Recently_Opened_List" if list is [not] emtpy |
1268 if ( recentlyOpenedList.isEmpty() ) { | 1323 if ( recentlyOpenedList.isEmpty() ) { |
1269 actionClear_Recently_Opened_List->setEnabled(false); | 1324 _mainWindowForm->actionClear_Recently_Opened_List->setEnabled(false); |
1270 } | 1325 } |
1271 else { | 1326 else { |
1272 actionClear_Recently_Opened_List->setEnabled(true); | 1327 _mainWindowForm->actionClear_Recently_Opened_List->setEnabled(true); |
1273 } | 1328 } |
1274 } | 1329 } |
1275 | 1330 |
1276 | 1331 |
1277 /*! | 1332 /*! |
1278 \brief This slot empties the list of recently opened files. | 1333 \brief This slot empties the list of recently opened files. |
1279 */ | 1334 */ |
1280 void MainWindow::clearRecentlyOpenedList() { | 1335 void MainWindow::clearRecentlyOpenedList() { |
1281 QStringList recentlyOpenedList = settings->getValueByName("lastSourceCodeFile").toString().split("|"); | 1336 QStringList recentlyOpenedList = _settings->getValueByName("lastSourceCodeFile").toString().split("|"); |
1282 QList<QAction*> recentlyOpenedActionList = menuRecently_Opened_Files->actions(); | 1337 QList<QAction*> recentlyOpenedActionList = _mainWindowForm->menuRecently_Opened_Files->actions(); |
1283 | 1338 |
1284 while ( recentlyOpenedList.size() > 0 ) { | 1339 while ( recentlyOpenedList.size() > 0 ) { |
1285 recentlyOpenedList.takeLast(); | 1340 recentlyOpenedList.takeLast(); |
1286 QAction* action = recentlyOpenedActionList.takeAt( recentlyOpenedActionList.size()-3 ); | 1341 QAction* action = recentlyOpenedActionList.takeAt( recentlyOpenedActionList.size()-3 ); |
1287 delete action; | 1342 delete action; |
1288 } | 1343 } |
1289 | 1344 |
1290 // Write the new recently opened list to the settings. | 1345 // Write the new recently opened list to the _settings. |
1291 settings->setValueByName( "lastSourceCodeFile", recentlyOpenedList.join("|") ); | 1346 _settings->setValueByName( "lastSourceCodeFile", recentlyOpenedList.join("|") ); |
1292 | 1347 |
1293 // Disable "actionClear_Recently_Opened_List" | 1348 // Disable "actionClear_Recently_Opened_List" |
1294 actionClear_Recently_Opened_List->setEnabled(false); | 1349 _mainWindowForm->actionClear_Recently_Opened_List->setEnabled(false); |
1295 } | 1350 } |
1296 | 1351 |
1297 | 1352 |
1298 /*! | 1353 /*! |
1299 \brief This slot is called if an entry from the list of recently opened files is | 1354 \brief This slot is called if an entry from the list of recently opened files is |
1300 being selected. | 1355 being selected. |
1301 */ | 1356 */ |
1302 void MainWindow::openFileFromRecentlyOpenedList(QAction* recentlyOpenedAction) { | 1357 void MainWindow::openFileFromRecentlyOpenedList(QAction* recentlyOpenedAction) { |
1303 // If the selected action from the recently opened list menu is the clear action | 1358 // If the selected action from the recently opened list menu is the clear action |
1304 // call the slot to clear the list and then leave. | 1359 // call the slot to clear the list and then leave. |
1305 if ( recentlyOpenedAction == actionClear_Recently_Opened_List ) { | 1360 if ( recentlyOpenedAction == _mainWindowForm->actionClear_Recently_Opened_List ) { |
1306 clearRecentlyOpenedList(); | 1361 clearRecentlyOpenedList(); |
1307 return; | 1362 return; |
1308 } | 1363 } |
1309 | 1364 |
1310 QString fileName = recentlyOpenedAction->text(); | 1365 QString fileName = recentlyOpenedAction->text(); |
1311 int indexOfSelectedFile = menuRecently_Opened_Files->actions().indexOf( recentlyOpenedAction ); | 1366 int indexOfSelectedFile = _mainWindowForm->menuRecently_Opened_Files->actions().indexOf( recentlyOpenedAction ); |
1312 QStringList recentlyOpenedList = settings->getValueByName("lastSourceCodeFile").toString().split("|"); | 1367 QStringList recentlyOpenedList = _settings->getValueByName("lastSourceCodeFile").toString().split("|"); |
1313 QString filePath = recentlyOpenedList.at(indexOfSelectedFile); | 1368 QString filePath = recentlyOpenedList.at(indexOfSelectedFile); |
1314 QFileInfo fileInfo(filePath); | 1369 QFileInfo fileInfo(filePath); |
1315 | 1370 |
1316 // If the file exists, open it. | 1371 // If the file exists, open it. |
1317 if ( fileInfo.exists() ) { | 1372 if ( fileInfo.exists() ) { |
1356 \brief If the dropped in object contains urls/paths to a file, open that file. | 1411 \brief If the dropped in object contains urls/paths to a file, open that file. |
1357 */ | 1412 */ |
1358 void MainWindow::showAboutDialog() { | 1413 void MainWindow::showAboutDialog() { |
1359 //QPixmap originalPixmap = QPixmap::grabWindow(QApplication::desktop()->screen()->winId()); | 1414 //QPixmap originalPixmap = QPixmap::grabWindow(QApplication::desktop()->screen()->winId()); |
1360 //qDebug("in main pixmap width %d, numScreens = %d", originalPixmap.size().width(), QApplication::desktop()->availableGeometry().width()); | 1415 //qDebug("in main pixmap width %d, numScreens = %d", originalPixmap.size().width(), QApplication::desktop()->availableGeometry().width()); |
1361 //aboutDialogGraphicsView->setScreenshotPixmap( originalPixmap ); | 1416 //_aboutDialogGraphicsView->setScreenshotPixmap( originalPixmap ); |
1362 aboutDialogGraphicsView->show(); | 1417 _aboutDialogGraphicsView->show(); |
1363 } | 1418 } |
1364 | 1419 |
1365 | 1420 |
1366 /*! | 1421 /*! |
1367 \brief Sets the label in the status bar to show the \a line and \a column number. | 1422 \brief Sets the label in the status bar to show the \a line and \a column number. |
1368 */ | 1423 */ |
1369 void MainWindow::setStatusBarCursorPosInfo( int line, int column ) { | 1424 void MainWindow::setStatusBarCursorPosInfo( int line, int column ) { |
1370 textEditLineColumnInfoLabel->setText( tr("Line %1, Column %2").arg(line+1).arg(column+1) ); | 1425 _textEditLineColumnInfoLabel->setText( tr("Line %1, Column %2").arg(line+1).arg(column+1) ); |
1371 } | 1426 } |