diff options
Diffstat (limited to 'src/MainWindow.cpp')
-rw-r--r-- | src/MainWindow.cpp | 124 |
1 files changed, 37 insertions, 87 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index c945da4..899a029 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -28,10 +28,10 @@ #include "IndentHandler.h" #include "SettingsPaths.h" #include "UiGuiSettings.h" +#include "UiGuiSettingsDialog.h" #include "UiGuiVersion.h" #include "ToolBarWidget.h" ///-- #include "AboutDialogGraphicsView.h" -///-- #include "UiGuiSettingsDialog.h" ///-- #include "UiGuiHighlighter.h" #include <tqaction.h> @@ -50,22 +50,10 @@ #include <tqsplitter.h> #include <tqstatusbar.h> #include <tqtextcodec.h> +#include <tqtooltip.h> #include <tqtranslator.h> #include <tqwidget.h> -///-- #include <tqstring.h> -///-- #include <tqscrollbar.h> -///-- #include <tqtextcursor.h> -///-- #include <tqtextstream.h> -///-- #include <tqtextdocument.h> -///-- #include <tqprinter.h> -///-- #include <tqprintdialog.h> -///-- #include <tqcloseevent.h> -///-- #include <tqhelpevent.h> -///-- #include <tqtooltip.h> -///-- #include <tqdate.h> -///-- #include <tqurl.h> -///-- #include <tqtdebug.h> -///-- + #include <tqextscintilla.h> ///-- #include <Qsci/qsciprinter.h> ///-- @@ -89,13 +77,12 @@ */ MainWindow::MainWindow(TQString file2OpenOnStart, TQWidget *parent) : MainWindowBase(parent), m_aboutDialog(nullptr), m_qSciSourceCodeEditor(nullptr), - m_qTranslator(nullptr), m_uiGuiTranslator(nullptr), m_textEditLineColumnInfoLabel(nullptr), + m_uiGuiTranslator(nullptr), m_textEditLineColumnInfoLabel(nullptr), m_oldLinesNumber(0), m_openEncodingActions(), m_saveEncodingActions(), m_encodingActionGroup(nullptr), m_saveEncodedActionGroup(nullptr), m_highlighterActionGroup(nullptr), m_documentModified(false), m_previewToggled(true), - m_indentHandler(nullptr), m_centralSplitter(nullptr) -///- _mainWindowForm(nullptr), _settings(nullptr) -///- m_highlighter(nullptr), _aboutDialogGraphicsView(nullptr), _settingsDialog(nullptr) + m_indentHandler(nullptr), m_centralSplitter(nullptr), m_settingsDialog(nullptr) +///- m_highlighter(nullptr), _aboutDialogGraphicsView(nullptr) ///- m_textEditVScrollBar(nullptr), _toolBarWidget(nullptr) { // Init of some variables. @@ -133,10 +120,9 @@ MainWindow::MainWindow(TQString file2OpenOnStart, TQWidget *parent) : ///-- _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, -///-- SLOT(showDialog())); + // Generate settings dialog box + m_settingsDialog = new UiGuiSettingsDialog(this, m_settings); + connect(actionShowSettings, SIGNAL(activated()), m_settingsDialog, SLOT(showDialog())); if (TQFile::exists(file2OpenOnStart)) { @@ -157,6 +143,7 @@ MainWindow::MainWindow(TQString file2OpenOnStart, TQWidget *parent) : MainWindow::~MainWindow() { + delete m_settingsDialog; delete m_aboutDialog; UiGuiSettings::deleteInstance(); } @@ -254,6 +241,8 @@ void MainWindow::initMainWindow() connect(actionSaveSourceFileAs, SIGNAL(activated()), this, SLOT(saveasSourceFileDialog())); connect(actionExportPDF, SIGNAL(activated()), this, SLOT(exportToPDF())); connect(actionExportHTML, SIGNAL(activated()), this, SLOT(exportToHTML())); + connect(m_settings, SIGNAL(indenterParameterTooltipsEnabled(bool)), + this, SLOT(setIndenterParameterTooltips(bool))); ///-- connect(actionShowLog, SIGNAL(activated()), ///-- debugging::TSLogger::getInstance(), SLOT(show())); @@ -265,9 +254,7 @@ void MainWindow::initMainWindow() this, SLOT(recentlyOpenedFileHighlighted(int))); connect(popupMenuRecentlyOpenedFiles, SIGNAL(activated(int)), this, SLOT(openFileFromRecentlyOpenedList(int))); -///-- //connect( _settings, SIGNAL(recentlyOpenedListSize(int)), this, SLOT(updateRecentlyOpenedList()) -///-- // ); -///-- _settings->registerObjectSlot(this, "updateRecentlyOpenedList()", "recentlyOpenedListSize"); + connect(m_settings, SIGNAL(recentlyOpenedListSize(int)), this, SLOT(updateRecentlyOpenedList())); updateWindowTitle(); } @@ -387,7 +374,7 @@ void MainWindow::initSyntaxHighlighter() /* \brief Initializes the language of UniversalIndentGUI. - If the program language is defined in the _settings, the corresponding language + If the program language is defined in the m_settings, the corresponding language file will be loaded and set for the application. If not set there, the system default language will be set, if a translation file for that language exists. Returns true, if the translation file could be loaded. Otherwise it returns @@ -429,19 +416,10 @@ bool MainWindow::initApplicationLanguage() } // Load the TQt own translation file and set it for the application. - m_qTranslator = new TQTranslator(); - bool translationFileLoaded; - translationFileLoaded = m_qTranslator->load(SettingsPaths::getGlobalFilesPath() + - "/translations/qt_" + languageShort); - if (translationFileLoaded) - { - tqApp->installTranslator(m_qTranslator); - } - // Load the uigui translation file and set it for the application. m_uiGuiTranslator = new TQTranslator(); - translationFileLoaded = m_uiGuiTranslator->load(SettingsPaths::getGlobalFilesPath() + - "/translations/universalindent_" + languageShort); + bool translationFileLoaded = m_uiGuiTranslator->load(SettingsPaths::getGlobalFilesPath() + + "/translations/universalindent_" + languageShort + ".qm"); if (translationFileLoaded) { tqApp->installTranslator(m_uiGuiTranslator); @@ -1102,34 +1080,6 @@ void MainWindow::closeEvent(TQCloseEvent *event) } } -///-- /* -///-- \brief This function is setup to capture tooltip events. -///-- -///-- All widgets that are created by the m_indentHandler object and are responsible -///-- for indenter parameters are connected with this event filter. -///-- So depending on the _settings the tooltips can be enabled and disabled for these widgets. -///-- */ -///-- bool MainWindow::eventFilter(TQObject *obj, TQEvent *event) -///-- { -///-- if (event->type() == TQEvent::ToolTip) -///-- { -///-- if (actionIndenterParameterTooltipsEnabled->isOn()) -///-- { -///-- return TQMainWindow::eventFilter(obj, event); -///-- } -///-- else -///-- { -///-- //TQToolTip::showText( TQPoint(100,100) , "Test1"); -///-- return true; -///-- } -///-- } -///-- else -///-- { -///-- // pass the event on to the parent class -///-- return TQMainWindow::eventFilter(obj, event); -///-- } -///-- } - /* \brief Is called at application exit and asks whether to save the source code file, if it has been changed. @@ -1164,24 +1114,12 @@ void MainWindow::languageChanged(int languageIndex) // Get the mnemonic of the new selected language. TQString languageShort = m_settings->getAvailableTranslations()[languageIndex]; - // Remove the old qt translation. - tqApp->removeTranslator(m_qTranslator); - // Remove the old uigui translation. tqApp->removeTranslator(m_uiGuiTranslator); - // Load the TQt own translation file and set it for the application. - bool translationFileLoaded; - translationFileLoaded = m_qTranslator->load(SettingsPaths::getGlobalFilesPath() + - "/translations/qt_" + languageShort); - if (translationFileLoaded) - { - tqApp->installTranslator(m_qTranslator); - } - // Load the uigui translation file and set it for the application. - translationFileLoaded = m_uiGuiTranslator->load(SettingsPaths::getGlobalFilesPath() + - "/translations/universalindent_" + languageShort); + bool translationFileLoaded = m_uiGuiTranslator->load(SettingsPaths::getGlobalFilesPath() + + "/translations/universalindent_" + languageShort + ".qm"); if (translationFileLoaded) { tqApp->installTranslator(m_uiGuiTranslator); @@ -1337,6 +1275,14 @@ void MainWindow::setWhiteSpaceVisibility(bool visible) } /* + \brief Is called whenever the tooltip visibility is being changed in the settings. + */ +void MainWindow::setIndenterParameterTooltips(bool enabled) +{ + TQToolTip::setGloballyEnabled(enabled); +} + +/* \brief This slot is called whenever the number of lines in the editor changes and adapts the margin for the displayed line numbers. */ @@ -1453,6 +1399,9 @@ void MainWindow::initRecentlyOpenedList() */ void MainWindow::updateRecentlyOpenedList() { + // Make sure to read the currnt max size settings + m_recentlyOpenedListMaxSize = m_settings->getValueByName("RecentlyOpenedListSize").toInt(); + TQString fileName; TQString filePath; @@ -1472,22 +1421,23 @@ void MainWindow::updateRecentlyOpenedList() -1, 0); popupMenuRecentlyOpenedFiles->setWhatsThis(id, m_currentSourceFile); } - // Put the current file at the first position if it not already is and is not empty. + // Put the current file at the first position if it was not in the list else if (currentFileIndex == -1) { m_recentlyOpenedList.prepend(m_currentSourceFile); int id = popupMenuRecentlyOpenedFiles->insertItem(TQFileInfo(m_currentSourceFile).fileName(), -1, 0); popupMenuRecentlyOpenedFiles->setWhatsThis(id, m_currentSourceFile); - // Trim the last element if we have reached the max allowed size - if (m_recentlyOpenedList.size() > m_recentlyOpenedListMaxSize) - { - m_recentlyOpenedList.pop_back(); - popupMenuRecentlyOpenedFiles->removeItemAt(m_recentlyOpenedListMaxSize); - } } } + // Trim excessive elements if the size has shrinked + while (m_recentlyOpenedList.size() > m_recentlyOpenedListMaxSize) + { + m_recentlyOpenedList.pop_back(); + popupMenuRecentlyOpenedFiles->removeItemAt(m_recentlyOpenedListMaxSize); + } + // Enable or disable "actionClearRecentlyOpenedList" actionClearRecentlyOpenedList->setEnabled(!m_recentlyOpenedList.isEmpty()); } |