summaryrefslogtreecommitdiffstats
path: root/src/MainWindow.cpp
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2023-09-05 18:04:18 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2023-09-05 18:04:18 +0900
commit455025d23a917ed4fd8e61bf2ede45432119d4b4 (patch)
treeff5cba64bb23755b8d8d1b40c5c259bb66605b05 /src/MainWindow.cpp
parentdd4c8a461d88cbbba745f4de76eed75a9a8e4cfe (diff)
downloaduniversal-indent-gui-tqt-455025d23a917ed4fd8e61bf2ede45432119d4b4.tar.gz
universal-indent-gui-tqt-455025d23a917ed4fd8e61bf2ede45432119d4b4.zip
Add UiGuiHighlighter code
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'src/MainWindow.cpp')
-rw-r--r--src/MainWindow.cpp122
1 files changed, 64 insertions, 58 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index 899a029..851037b 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -32,7 +32,7 @@
#include "UiGuiVersion.h"
#include "ToolBarWidget.h"
///-- #include "AboutDialogGraphicsView.h"
-///-- #include "UiGuiHighlighter.h"
+#include "UiGuiHighlighter.h"
#include <tqaction.h>
#include <tqapplication.h>
@@ -79,10 +79,11 @@ MainWindow::MainWindow(TQString file2OpenOnStart, TQWidget *parent) :
MainWindowBase(parent), m_aboutDialog(nullptr), m_qSciSourceCodeEditor(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), m_settingsDialog(nullptr)
-///- m_highlighter(nullptr), _aboutDialogGraphicsView(nullptr)
+ m_encodingActionGroup(nullptr), m_saveEncodedActionGroup(nullptr),
+ m_highlighterActionGroup(nullptr), m_documentModified(false), m_previewToggled(true),
+ m_indentHandler(nullptr), m_centralSplitter(nullptr), m_settingsDialog(nullptr),
+ m_highlighter(nullptr), m_highlightingActions()
+///_aboutDialogGraphicsView(nullptr)
///- m_textEditVScrollBar(nullptr), _toolBarWidget(nullptr)
{
// Init of some variables.
@@ -113,7 +114,6 @@ MainWindow::MainWindow(TQString file2OpenOnStart, TQWidget *parent) :
createEncodingMenu();
createHighlighterMenu();
-
// Generate about dialog box
//m_aboutDialog = new AboutDialog(this, WStyle_Splash);
m_aboutDialog = new AboutDialog(this);
@@ -135,7 +135,7 @@ MainWindow::MainWindow(TQString file2OpenOnStart, TQWidget *parent) :
loadLastOpenedFile();
}
- updateSourceView();
+ updateSyntaxHighlighting();
///-- // Enable accept dropping of files.
///-- setAcceptDrops(true);
@@ -271,7 +271,7 @@ void MainWindow::initToolBar()
m_toolBarWidget = new ToolBarWidget(toolBar);
// Connect the tool bar widgets to their functions.
-///-- _settings->registerObjectProperty(_toolBarWidget->cbEnableSyntaxHL, "checked",
+///-- m_settings->registerObjectProperty(_toolBarWidget->cbEnableSyntaxHL, "checked",
///-- "SyntaxHighlightingEnabled");
m_toolBarWidget->cbEnableSyntaxHL->hide();
@@ -312,7 +312,7 @@ void MainWindow::initTextEditor()
exit(1);
}
- // Make some _settings for the TQScintilla widget.
+ // Make some settings for the TQScintilla widget.
m_qSciSourceCodeEditor->setUtf8(true);
m_qSciSourceCodeEditor->setMarginLineNumbers(1, true);
m_qSciSourceCodeEditor->setMarginWidth(1, TQString("10000"));
@@ -351,24 +351,22 @@ void MainWindow::initTextEditor()
numberOfLinesChanged();
}
+void MainWindow::updateSyntaxHighlighting()
+{
+ turnHighlightOnOff(actionEnableSyntaxHighlighting->isOn());
+}
+
/*
- \brief Create and init the syntax m_highlighter and set it to use the TQScintilla edit component.
+ \brief Create and init the syntax highlighter and set it to use the TQScintilla edit component.
*/
void MainWindow::initSyntaxHighlighter()
{
-///-- // Create the highlighter.
-///-- m_highlighter = new UiGuiHighlighter(qSciSourceCodeEditor);
-///--
-///-- // Handle if syntax highlighting is enabled
-///-- bool syntaxHighlightningEnabled = m_settings->getValueByName("SyntaxHighlightningEnabled").toBool();
-///-- if (syntaxHighlightningEnabled)
-///-- {
-///-- highlighter->turnHighlightOn();
-///-- }
-///-- else
-///-- {
-///-- highlighter->turnHighlightOff();
-///-- }
+ // Create the highlighter.
+ m_highlighter = new UiGuiHighlighter(m_qSciSourceCodeEditor);
+
+ // Handle if syntax highlighting is enabled
+ bool syntaxHighlightningEnabled = m_settings->getValueByName("SyntaxHighlightningEnabled").toBool();
+ turnHighlightOnOff(syntaxHighlightningEnabled);
}
/*
@@ -442,7 +440,7 @@ void MainWindow::initIndenter()
m_indentHandler = new IndentHandler(m_currentIndenterID, this, m_centralSplitter);
m_centralSplitter->moveToFirst(m_indentHandler);
- // If _settings for the indenter have changed, let the main window know aboud it.
+ // If settings for the indenter have changed, let the main window know aboud it.
connect(m_indentHandler, SIGNAL(indenterSettingsChanged()), this,
SLOT(indentSettingsChangedSlot()));
@@ -451,7 +449,7 @@ void MainWindow::initIndenter()
m_previewToggled = true;
///-- // Handle if indenter parameter tool tips are enabled
-///-- _settings->registerObjectProperty(actionIndenterParameterTooltipsEnabled,
+///-- m_settings->registerObjectProperty(actionIndenterParameterTooltipsEnabled,
///-- "checked", "indenterParameterTooltipsEnabled");
}
@@ -481,8 +479,18 @@ TQString MainWindow::loadFile(const TQString &filePath)
TQFileInfo fileInfo(filePath);
m_currentSourceFileExtension = fileInfo.extension(false);
-///-- int indexOfHighlighter = _highlighter->setLexerForExtension(m_currentSourceFileExtension);
-///-- m_highlighterActionGroup->actions().at(indexOfHighlighter)->setChecked(true);
+ int indexOfHighlighter = m_highlighter->setLexer(m_currentSourceFileExtension);
+ // Mark the selected highlighter in the corresponding menu
+ int idx = 0;
+ for (TQAction *action : m_highlightingActions)
+ {
+ if (idx == indexOfHighlighter)
+ {
+ action->setOn(true);
+ break;
+ }
+ ++idx;
+ }
}
return fileContent;
}
@@ -670,16 +678,16 @@ void MainWindow::callIndenter()
*/
void MainWindow::turnHighlightOnOff(bool turnOn)
{
-///-- if (turnOn)
-///-- {
-///-- _highlighter->turnHighlightOn();
-///-- }
-///-- else
-///-- {
-///-- _highlighter->turnHighlightOff();
-///-- }
-///-- m_previewToggled = true;
-///-- updateSourceView();
+ if (turnOn)
+ {
+ m_highlighter->turnHighlightOn();
+ }
+ else
+ {
+ m_highlighter->turnHighlightOff();
+ }
+ m_previewToggled = true;
+ updateSourceView();
}
/*
@@ -1059,9 +1067,9 @@ void MainWindow::saveSettings()
m_settings->setValueByName("LastOpenedFiles", m_recentlyOpenedList.join("|"));
///-- m_settings->setValueByName("MainWindowState", saveState());
-///--
-///-- // Also save the syntax highlight style for all lexers.
-///-- _highlighter->writeCurrentSettings("");
+
+ // Also save the syntax highlight style for all lexers.
+ m_highlighter->writeCurrentSettings();
}
/*
@@ -1142,7 +1150,7 @@ void MainWindow::createEncodingMenu()
m_saveEncodedActionGroup = new TQActionGroup(this);
// Loop for each available encoding
- for(const TQString &encodingName : encodingsList)
+ for (const TQString &encodingName : encodingsList)
{
// Create actions for the "reopen" menu
TQAction *encodingAction = new TQAction(m_encodingActionGroup);
@@ -1237,23 +1245,21 @@ void MainWindow::encodingChanged(TQAction *encodingAction)
*/
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);
+ 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_highlightingActions.append(highlighterAction);
+ }
+
+ m_highlighterActionGroup->addTo(popupMenuHighlighter);
+ connect(m_highlighterActionGroup , SIGNAL(selected(TQAction*)),
+ m_highlighter, SLOT(setHighlighterByAction(TQAction*)));
}
/*