diff options
Diffstat (limited to 'src/MainWindow.cpp')
-rw-r--r-- | src/MainWindow.cpp | 272 |
1 files changed, 136 insertions, 136 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 0fbe91b..a3480c7 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -86,12 +86,11 @@ MainWindow::MainWindow(TQString file2OpenOnStart, TQWidget *parent) : MainWindowBase(parent), m_aboutDialog(nullptr), m_qSciSourceCodeEditor(nullptr), m_qTranslator(nullptr), m_uiGuiTranslator(nullptr), m_textEditLineColumnInfoLabel(nullptr), - m_oldLinesNumber(0) -///- _mainWindowForm(nullptr), _settings(nullptr), _saveEncodedActionGroup(nullptr), -///- _highlighter(nullptr), _aboutDialogGraphicsView( -///- nullptr), _settingsDialog(nullptr), _encodingActionGroup(nullptr) -///- _highlighterActionGroup(nullptr), m_textEditVScrollBar(nullptr), _toolBarWidget( -///- nullptr), _indentHandler(nullptr) + m_oldLinesNumber(0), m_encodingsList(), m_encodingActionGroup(nullptr), + m_saveEncodedActionGroup(nullptr), m_highlighterActionGroup(nullptr) +///- _mainWindowForm(nullptr), _settings(nullptr) +///- m_highlighter(nullptr), _aboutDialogGraphicsView(nullptr), _settingsDialog(nullptr) +///- m_textEditVScrollBar(nullptr), _toolBarWidget(nullptr), _indentHandler(nullptr) { // Init of some variables. m_sourceCodeChanged = false; @@ -111,23 +110,23 @@ MainWindow::MainWindow(TQString file2OpenOnStart, TQWidget *parent) : // Create the text edit component using the TQScintilla widget. initTextEditor(); -///-- // Create and init the syntax highlighter. -///-- initSyntaxHighlighter(); -///-- -///-- // Create and init the indenter. -///-- initIndenter(); -///-- -///-- // Create some menus. -///-- createEncodingMenu(); -///-- createHighlighterMenu(); -///-- -///-- + // Create and init the syntax highlighter. + initSyntaxHighlighter(); + + // Create and init the indenter. + initIndenter(); + + // Create some menus. + createEncodingMenu(); + createHighlighterMenu(); + + // Generate about dialog box //m_aboutDialog = new AboutDialog(this, WStyle_Splash); m_aboutDialog = new AboutDialog(this); ///-- _aboutDialogGraphicsView = new AboutDialogGraphicsView(m_aboutDialog, this); connect(actionAboutUniversalIndentGUITQt, SIGNAL(activated()), this, SLOT(showAboutDialog())); -///-- + ///-- // Generate settings dialog box ///-- _settingsDialog = new UiGuiSettingsDialog(this, _settings); ///-- connect(actionShowSettings, SIGNAL(activated()), _settingsDialog, @@ -350,22 +349,25 @@ void MainWindow::initTextEditor() numberOfLinesChanged(); } -///-- /* -///-- \brief Create and init the syntax _highlighter and set it to use the TQScintilla edit component. -///-- */ -///-- void MainWindow::initSyntaxHighlighter() -///-- { -///-- // Create the _highlighter. -///-- _highlighter = new UiGuiHighlighter(m_qSciSourceCodeEditor); -///-- -///-- // Connect the syntax highlighting setting in the menu to the turnHighlightOnOff function. -///-- connect(actionEnableSyntaxHighlighting, SIGNAL(activated(bool)), this, -///-- SLOT(turnHighlightOnOff(bool))); +/* + \brief Create and init the syntax m_highlighter and set it to use the TQScintilla edit component. + */ +void MainWindow::initSyntaxHighlighter() +{ +///-- // Create the highlighter. +///-- m_highlighter = new UiGuiHighlighter(qSciSourceCodeEditor); ///-- -///-- // Register the syntax highlighting setting in the menu to the _settings object. -///-- _settings->registerObjectProperty(actionEnableSyntaxHighlighting, "checked", -///-- "SyntaxHighlightingEnabled"); -///-- } +///-- // Handle if syntax highlighting is enabled +///-- bool syntaxHighlightningEnabled = m_settings->getValueByName("SyntaxHighlightningEnabled").toBool(); +///-- if (syntaxHighlightningEnabled) +///-- { +///-- highlighter->turnHighlightOn(); +///-- } +///-- else +///-- { +///-- highlighter->turnHighlightOff(); +///-- } +} /* \brief Initializes the language of UniversalIndentGUI. @@ -435,11 +437,11 @@ bool MainWindow::initApplicationLanguage() return translationFileLoaded; } -///-- /* -///-- \brief Creates and initializes the indenter. -///-- */ -///-- void MainWindow::initIndenter() -///-- { +/* + \brief Creates and initializes the indenter. + */ +void MainWindow::initIndenter() +{ ///-- // Get Id of last selected indenter. ///-- _currentIndenterID = _settings->getValueByName("selectedIndenter").toInt(); ///-- @@ -461,8 +463,8 @@ bool MainWindow::initApplicationLanguage() ///-- ///-- // Add the indenters context menu to the mainwindows menu. ///-- _mainWindowForm->menuIndenter->addActions(_indentHandler->getIndenterMenuActions()); -///-- } -///-- +} + ///-- /* ///-- \brief Tries to load the by \a filePath defined file and returns its content as TQString. ///-- @@ -490,7 +492,7 @@ bool MainWindow::initApplicationLanguage() ///-- TQFileInfo fileInfo(filePath); ///-- _currentSourceFileExtension = fileInfo.suffix(); ///-- int indexOfHighlighter = _highlighter->setLexerForExtension(_currentSourceFileExtension); -///-- _highlighterActionGroup->actions().at(indexOfHighlighter)->setChecked(true); +///-- m_highlighterActionGroup->actions().at(indexOfHighlighter)->setChecked(true); ///-- } ///-- return fileContent; ///-- } @@ -580,7 +582,7 @@ bool MainWindow::saveasSourceFileDialog(TQAction *chosenEncodingAction) ///-- } ///-- else ///-- { -///-- encoding = _encodingActionGroup->checkedAction()->text(); +///-- encoding = m_encodingActionGroup->checkedAction()->text(); ///-- } ///-- TQTextStream outSrcStrm(&outSrcFile); ///-- outSrcStrm.setCodec(TQTextCodec::codecForName(encoding.toAscii())); @@ -616,7 +618,7 @@ bool MainWindow::saveSourceFile() ///-- outSrcFile.open(TQFile::ReadWrite | TQFile::Text); ///-- ///-- // Get current encoding. -///-- TQString m_currentEncoding = _encodingActionGroup->checkedAction()->text(); +///-- TQString m_currentEncoding = m_encodingActionGroup->checkedAction()->text(); ///-- TQTextStream outSrcStrm(&outSrcFile); ///-- outSrcStrm.setCodec(TQTextCodec::codecForName(m_currentEncoding.toAscii())); ///-- outSrcStrm << _savedSourceContent; @@ -1211,67 +1213,66 @@ void MainWindow::languageChanged(int languageIndex) } } -///-- /* -///-- \brief Creates a menu entries in the file menu for opening and saving a file with different encodings. -///-- */ -///-- void MainWindow::createEncodingMenu() -///-- { -///-- TQAction *encodingAction; -///-- TQString encodingName; -///-- -///-- _encodingsList = TQStringList() << "UTF-8" << "UTF-16" << "UTF-16BE" << "UTF-16LE" << -///-- "Apple Roman" << "Big5" << "Big5-HKSCS" << "EUC-JP" << "EUC-KR" << "GB18030-0" << -///-- "IBM 850" << "IBM 866" << "IBM 874" << "ISO 2022-JP" << "ISO 8859-1" << "ISO 8859-13" << -///-- "Iscii-Bng" << "JIS X 0201" << "JIS X 0208" << "KOI8-R" << "KOI8-U" << "MuleLao-1" << -///-- "ROMAN8" << "Shift-JIS" << "TIS-620" << "TSCII" << "Windows-1250" << "WINSAMI2"; -///-- -///-- _encodingActionGroup = new TQActionGroup(this); -///-- _saveEncodedActionGroup = new TQActionGroup(this); -///-- -///-- // Loop for each available encoding -///-- foreach(encodingName, _encodingsList) -///-- { -///-- // Create actions for the "reopen" menu -///-- encodingAction = new TQAction(encodingName, _encodingActionGroup); -///-- encodingAction->setStatusTip(tr( -///-- "Reopen the currently opened source code file by using the text encoding scheme ") + -///-- encodingName); -///-- encodingAction->setCheckable(true); -///-- if (encodingName == m_currentEncoding) -///-- { -///-- encodingAction->setChecked(true); -///-- } -///-- -///-- // Create actions for the "save as encoded" menu -///-- encodingAction = new TQAction(encodingName, _saveEncodedActionGroup); -///-- encodingAction->setStatusTip(tr( -///-- "Save the currently opened source code file by using the text encoding scheme ") + -///-- encodingName); -///-- } -///-- -///-- _mainWindowForm->popupMenuEncoding->addActions(_encodingActionGroup->actions()); -///-- connect(_encodingActionGroup, SIGNAL(triggered(TQAction*)), this, -///-- SLOT(encodingChanged(TQAction*))); -///-- -///-- _mainWindowForm->popupMenuSaveEncoded->addActions(_saveEncodedActionGroup->actions()); -///-- connect(_saveEncodedActionGroup, SIGNAL(triggered(TQAction*)), this, -///-- SLOT(saveAsOtherEncoding(TQAction*))); -///-- } -///-- -///-- /* -///-- \brief This slot calls the save dialog to save the current source file with another encoding. -///-- -///-- If the saving is successful and not aborted, the currently used encoding, visible in the -///-- "reopen" menu, is also changed to the new encoding. -///-- */ -///-- void MainWindow::saveAsOtherEncoding(TQAction *chosenEncodingAction) -///-- { +/* + \brief Creates menu entries in the file menu for opening and saving a file with different encodings. +*/ +void MainWindow::createEncodingMenu() +{ + m_encodingsList << "UTF-8" << "UTF-16" << "UTF-16BE" << "UTF-16LE" << + "Apple Roman" << "Big5" << "Big5-HKSCS" << "EUC-JP" << "EUC-KR" << "GB18030-0" << + "IBM 850" << "IBM 866" << "IBM 874" << "ISO 2022-JP" << "ISO 8859-1" << "ISO 8859-13" << + "Iscii-Bng" << "JIS X 0201" << "JIS X 0208" << "KOI8-R" << "KOI8-U" << "MuleLao-1" << + "ROMAN8" << "Shift-JIS" << "TIS-620" << "TSCII" << "Windows-1250" << "WINSAMI2"; + + m_encodingActionGroup = new TQActionGroup(this); + m_saveEncodedActionGroup = new TQActionGroup(this); + + // Loop for each available encoding + for(const TQString &encodingName : m_encodingsList) + { + // Create actions for the "reopen" menu + TQAction *encodingAction = new TQAction(m_encodingActionGroup); + encodingAction->setText(encodingName); + encodingAction->setStatusTip(tr( + "Reopen the currently opened source code file by using the text encoding scheme ") + + encodingName); + encodingAction->setToggleAction(true); + if (encodingName == m_currentEncoding) + { + encodingAction->setOn(true); + } + + // Create actions for the "save as encoded" menu + encodingAction = new TQAction(m_saveEncodedActionGroup); + encodingAction->setText(encodingName); + encodingAction->setStatusTip(tr( + "Save the currently opened source code file by using the text encoding scheme ") + + encodingName); + } + + m_encodingActionGroup->addTo(popupMenuEncoding); + connect(m_encodingActionGroup, SIGNAL(selected(TQAction*)), + this, SLOT(encodingChanged(TQAction*))); + + m_saveEncodedActionGroup->addTo(popupMenuSaveEncoded); + connect(m_saveEncodedActionGroup, SIGNAL(selected(TQAction*)), + this, SLOT(saveAsOtherEncoding(TQAction*))); +} + +/* + \brief This slot calls the save dialog to save the current source file with another encoding. + + If the saving is successful and not aborted, the currently used encoding, visible in the + "reopen" menu, is also changed to the new encoding. +*/ +void MainWindow::saveAsOtherEncoding(TQAction *chosenEncodingAction) +{ ///-- bool fileWasSaved = saveasSourceFileDialog(chosenEncodingAction); ///-- ///-- // If the file was save with another encoding, change the selected encoding in the reopen menu. ///-- if (fileWasSaved) ///-- { -///-- foreach(TQAction * action, _encodingActionGroup->actions()) +///-- foreach(TQAction * action, m_encodingActionGroup->actions()) ///-- { ///-- if (action->text() == chosenEncodingAction->text()) ///-- { @@ -1280,13 +1281,13 @@ void MainWindow::languageChanged(int languageIndex) ///-- } ///-- } ///-- } -///-- } -///-- -///-- /* -///-- \brief This slot is called whenever an encoding is selected in the settings menu. -///-- */ -///-- void MainWindow::encodingChanged(TQAction *encodingAction) -///-- { +} + +/* + \brief This slot is called whenever an encoding is selected in the settings menu. +*/ +void MainWindow::encodingChanged(TQAction *encodingAction) +{ ///-- if (maybeSave()) ///-- { ///-- TQFile inSrcFile(_currentSourceFile); @@ -1311,32 +1312,31 @@ void MainWindow::languageChanged(int languageIndex) ///-- m_qSciSourceCodeEditor->setModified(false); ///-- } ///-- } -///-- } -///-- -///-- /* -///-- \brief Creates a menu entry under the settings menu for all available text encodings. -///-- */ -///-- void MainWindow::createHighlighterMenu() -///-- { -///-- TQAction *highlighterAction; -///-- TQString highlighterName; -///-- -///-- _highlighterActionGroup = new TQActionGroup(this); -///-- -///-- // Loop for each known highlighter -///-- foreach(highlighterName, _highlighter->getAvailableHighlighters()) -///-- { -///-- highlighterAction = new TQAction(highlighterName, _highlighterActionGroup); -///-- highlighterAction->setStatusTip(tr("Set the syntax highlighting to ") + highlighterName); -///-- highlighterAction->setCheckable(true); -///-- } -///-- _mainWindowForm->popupMenuHighlighter->addActions(_highlighterActionGroup->actions()); -///-- _mainWindowForm->menuSettings->insertMenu(actionIndenterParameterTooltipsEnabled, -///-- _mainWindowForm->popupMenuHighlighter); -///-- -///-- connect(_highlighterActionGroup, SIGNAL(triggered(TQAction*)), _highlighter, -///-- SLOT(setHighlighterByAction(TQAction*))); -///-- } +} + +/* + \brief Creates a menu entry under the settings menu for all available text encodings. +*/ +void MainWindow::createHighlighterMenu() +{ +///--- m_highlighterActionGroup = new TQActionGroup(this); +///--- +///--- // Loop for each known highlighter +///--- for(const TQString &highlighterName: m_highlighter->getAvailableHighlighters()) +///--- { +///--- TQAction *highlighterAction = new TQAction(m_highlighterActionGroup); +///--- highlighterAction->setText(highlighterName); +///--- highlighterAction->setStatusTip(tr("Set the syntax highlighting to ") + highlighterName); +///--- highlighterAction->setToggleAction(true); +///--- } +///--- +///--- m_highlighterActionGroup ->addTo(popupMenuHighlighter); +///--- connect(m_highlighterActionGroup , SIGNAL(selected(TQAction*)), +///--- m_highlighter, SLOT(setHighlighterByAction(TQAction*))); +///--- +///--- _mainWindowForm->menuSettings->insertMenu(actionIndenterParameterTooltipsEnabled, +///--- _mainWindowForm->popupMenuHighlighter); +} /* \brief Is called whenever the white space visibility is being changed in the menu. @@ -1394,20 +1394,20 @@ void MainWindow::numberOfLinesChanged() ///-- _indentHandler->retranslateUi(); ///-- ///-- // Translate the load encoding menu. -///-- TQList<TQAction*> encodingActionList = _encodingActionGroup->actions(); +///-- TQList<TQAction*> encodingActionList = m_encodingActionGroup->actions(); ///-- for (i = 0; i < encodingActionList.size(); i++) ///-- { ///-- encodingActionList.at(i)->setStatusTip(tr( -///-- "Reopen the currently opened source code file by using the text encoding scheme ") + _encodingsList.at( +///-- "Reopen the currently opened source code file by using the text encoding scheme ") + m_encodingsList.at( ///-- i)); ///-- } ///-- ///-- // Translate the save encoding menu. -///-- encodingActionList = _saveEncodedActionGroup->actions(); +///-- encodingActionList = m_saveEncodedActionGroup->actions(); ///-- for (i = 0; i < encodingActionList.size(); i++) ///-- { ///-- encodingActionList.at(i)->setStatusTip(tr( -///-- "Save the currently opened source code file by using the text encoding scheme ") + _encodingsList.at( +///-- "Save the currently opened source code file by using the text encoding scheme ") + m_encodingsList.at( ///-- i)); ///-- } ///-- |