Initialize TQScintilla's editor. TabWidth settings is now saved and restored across executions

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
master
Michele Calgaro 2 years ago
parent 64dc8cad72
commit 658a06d1ee
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -54,3 +54,9 @@ check_cxx_source_compiles(
if( NOT HAVE_SSTREAM AND NOT HAVE_STRSTREAM )
message(FATAL_ERROR "\nsstream or strstream support is required, but not found on your system." )
endif( )
# check for tqscintilla
pkg_search_module( TQSCINTILLA tqscintilla )
if( NOT TQSCINTILLA_FOUND )
tde_message_fatal( "tqscintilla is required, but was not found on your system" )
endif( )

@ -44,6 +44,6 @@ set( ${target}_SRCS
tde_add_executable( ${target} AUTOMOC
SOURCES ${${target}_SRCS}
LINK ${TQT_LIBRARIES}
LINK ${TQT_LIBRARIES} ${TQSCINTILLA_LIBRARIES}
DESTINATION ${BIN_INSTALL_DIR}
)

@ -22,6 +22,8 @@
///-- #include "debugging/TSLogger.h"
#include "stdlib.h"
#include "AboutDialog.h"
#include "SettingsPaths.h"
#include "UiGuiSettings.h"
@ -35,13 +37,15 @@
#include <tqaction.h>
#include <tqapplication.h>
#include <tqcheckbox.h>
#include <tqlabel.h>
#include <tqlocale.h>
#include <tqmessagebox.h>
#include <tqpixmap.h>
#include <tqpopupmenu.h>
#include <tqpushbutton.h>
#include <tqstatusbar.h>
#include <tqtranslator.h>
///-- #include <tqwidget.h>
///-- #include <tqlabel.h>
///-- #include <tqstring.h>
///-- #include <tqscrollbar.h>
///-- #include <tqtextcursor.h>
@ -56,7 +60,6 @@
///-- #include <tqtextcodec.h>
///-- #include <tqdate.h>
///-- #include <tqurl.h>
///-- #include <tqmessagebox.h>
///-- #include <tqtdebug.h>
///--
#include <tqextscintilla.h>
@ -82,17 +85,18 @@
*/
MainWindow::MainWindow(TQString file2OpenOnStart, TQWidget *parent) :
MainWindowBase(parent), m_aboutDialog(nullptr), m_qSciSourceCodeEditor(nullptr),
m_qTranslator(nullptr), m_uiGuiTranslator(nullptr)
m_qTranslator(nullptr), m_uiGuiTranslator(nullptr), m_textEditLineColumnInfoLabel(nullptr),
m_oldLinesNumber(0)
///- _mainWindowForm(nullptr), _settings(nullptr), _saveEncodedActionGroup(nullptr),
///- _highlighter(nullptr), _textEditVScrollBar(nullptr), _aboutDialogGraphicsView(
///- _highlighter(nullptr), _aboutDialogGraphicsView(
///- nullptr), _settingsDialog(nullptr), _encodingActionGroup(nullptr)
///- _highlighterActionGroup(nullptr), _toolBarWidget(
///- nullptr), _indentHandler(nullptr), _textEditLineColumnInfoLabel(nullptr)
///- _highlighterActionGroup(nullptr), m_textEditVScrollBar(nullptr), _toolBarWidget(
///- nullptr), _indentHandler(nullptr)
{
// Init of some variables.
m_sourceCodeChanged = false;
m_sourceCodeChanged = false;
// Create the _settings object, which loads all UiGui settings from a file.
// Create the settings object, which loads all UiGui settings from a file.
m_settings = UiGuiSettings::getInstance();
// Initialize the language of the application.
@ -104,9 +108,9 @@ MainWindow::MainWindow(TQString file2OpenOnStart, TQWidget *parent) :
// Create toolbar and insert it into the main window.
initToolBar();
///-- // Create the text edit component using the TQScintilla widget.
///-- initTextEditor();
///--
// Create the text edit component using the TQScintilla widget.
initTextEditor();
///-- // Create and init the syntax highlighter.
///-- initSyntaxHighlighter();
///--
@ -184,7 +188,7 @@ void MainWindow::initMainWindow()
actionShowLog->setIconSet(TQPixmap(ICONS_PATH + "document-properties.png"));
actionAboutUniversalIndentGUITQt->setIconSet(TQPixmap(ICONS_PATH + "info.png"));
// Menu ids
_actionClearRecentlyOpenedListId = popupMenuRecentlyOpenedFiles->idAt(
m_actionClearRecentlyOpenedListId = popupMenuRecentlyOpenedFiles->idAt(
popupMenuRecentlyOpenedFiles->count() - 1);
// Handle last opened window size
@ -282,66 +286,70 @@ void MainWindow::initToolBar()
///-- bool)), m_toolBarWidget->cbLivePreview, SLOT(setChecked(bool)));
}
///-- /*
///-- \brief Create and initialize the text editor component. It uses the TQScintilla widget.
///-- */
///-- void MainWindow::initTextEditor()
///-- {
///-- // Create the TQScintilla widget and add it to the layout.
///-- tqDebug() <<
///-- "Trying to load TQScintilla library. If anything fails during loading, it might be possible that"
///-- <<
///-- " the debug and release version of TQScintilla are mixed or the library cannot be found at all.";
///-- // Try and catch doesn't seem to catch the runtime error when starting UiGUI release with
///-- // TQScintilla debug lib and the other way around.
///-- try
///-- {
///-- m_qSciSourceCodeEditor = new QsciScintilla(this);
///-- }
///-- catch (...)
///-- {
///-- TQMessageBox::critical(this, "Error creating TQScintilla text editor component!",
///-- "During trying to create the text editor component, that is based on TQScintilla, an error occurred. Please make sure that you have installed TQScintilla and not mixed release and debug versions.");
///-- exit(1);
///-- }
///-- _mainWindowForm->hboxLayout1->addWidget(m_qSciSourceCodeEditor);
///--
///-- // Make some _settings for the TQScintilla widget.
///-- m_qSciSourceCodeEditor->setUtf8(true);
///-- m_qSciSourceCodeEditor->setMarginLineNumbers(1, true);
///-- m_qSciSourceCodeEditor->setMarginWidth(1, TQString("10000"));
///-- m_qSciSourceCodeEditor->setBraceMatching(m_qSciSourceCodeEditor->SloppyBraceMatch);
///-- m_qSciSourceCodeEditor->setMatchedBraceForegroundColor(TQColor("red"));
///-- m_qSciSourceCodeEditor->setFolding(QsciScintilla::BoxedTreeFoldStyle);
///-- m_qSciSourceCodeEditor->setAutoCompletionSource(QsciScintilla::AcsAll);
///-- m_qSciSourceCodeEditor->setAutoCompletionThreshold(3);
///--
///-- // Handle if white space is set to be visible
///-- bool whiteSpaceIsVisible = _settings->getValueByName("whiteSpaceIsVisible").toBool();
///-- setWhiteSpaceVisibility(whiteSpaceIsVisible);
///--
///-- // Handle the width of tabs in spaces
///-- int tabWidth = _settings->getValueByName("tabWidth").toInt();
///-- m_qSciSourceCodeEditor->setTabWidth(tabWidth);
///--
///-- // Remember a pointer to the scrollbar of the TQScintilla widget used to keep
///-- // on the same line as before when turning preview on/off.
///-- _textEditVScrollBar = m_qSciSourceCodeEditor->verticalScrollBar();
///--
///-- // Add a column row indicator to the status bar.
///-- _textEditLineColumnInfoLabel = new TQLabel(tr("Line %1, Column %2").arg(1).arg(1));
///-- _mainWindowForm->statusbar->addPermanentWidget(_textEditLineColumnInfoLabel);
///-- connect(m_qSciSourceCodeEditor, SIGNAL(cursorPositionChanged(int,int)), this,
///-- SLOT(setStatusBarCursorPosInfo(int, int)));
///--
///-- // Connect the text editor to dependent functions.
///-- connect(m_qSciSourceCodeEditor, SIGNAL(textChanged()), this, SLOT(sourceCodeChangedHelperSlot()));
///-- connect(m_qSciSourceCodeEditor, SIGNAL(linesChanged()), this, SLOT(numberOfLinesChanged()));
///-- //connect( _settings, SIGNAL(tabWidth(int)), m_qSciSourceCodeEditor, SLOT(setTabWidth(int)) );
///-- _settings->registerObjectSlot(m_qSciSourceCodeEditor, "setTabWidth(int)", "tabWidth");
///-- m_qSciSourceCodeEditor->setTabWidth(_settings->getValueByName("tabWidth").toInt());
///-- }
///--
/*
\brief Create and initialize the text editor component. It uses the TQScintilla widget.
*/
void MainWindow::initTextEditor()
{
// Create the TQScintilla widget and add it to the layout.
//tqDebug("Trying to load TQScintilla library. If anything fails during loading, it might be "
// "possible that the debug and release version of TQScintilla are mixed or the library "
// "cannot be found at all.");
// Try and catch doesn't seem to catch the runtime error when starting UiGUI release with
// TQScintilla debug lib and the other way around.
try
{
m_qSciSourceCodeEditor = new TQextScintilla(this);
}
catch (...)
{
TQMessageBox::critical(this, "Error creating TQScintilla text editor component!",
"While trying to create the text editor component (based on TQScintilla), an error "
"occurred. Please make sure that TQScintilla is installed and that release and debug "
"versions are not mixed.");
exit(1);
}
setCentralWidget(m_qSciSourceCodeEditor);
// Make some _settings for the TQScintilla widget.
m_qSciSourceCodeEditor->setUtf8(true);
m_qSciSourceCodeEditor->setMarginLineNumbers(1, true);
m_qSciSourceCodeEditor->setMarginWidth(1, TQString("10000"));
m_qSciSourceCodeEditor->setBraceMatching(m_qSciSourceCodeEditor->SloppyBraceMatch);
m_qSciSourceCodeEditor->setMatchedBraceForegroundColor(TQColor("red"));
m_qSciSourceCodeEditor->setFolding(TQextScintilla::BoxedTreeFoldStyle);
m_qSciSourceCodeEditor->setAutoCompletionSource(TQextScintilla::AcsAll);
m_qSciSourceCodeEditor->setAutoCompletionThreshold(3);
// Handle if white space is set to be visible
bool whiteSpaceIsVisible = m_settings->getValueByName("WhiteSpaceIsVisible").toBool();
setWhiteSpaceVisibility(whiteSpaceIsVisible);
// Handle the width of tabs in spaces
int tabWidth = m_settings->getValueByName("TabWidth").toInt();
m_qSciSourceCodeEditor->setTabWidth(tabWidth);
connect(m_settings, SIGNAL(tabWidth(int)), m_qSciSourceCodeEditor, SLOT(setTabWidth(int)));
// TODO not available in TQScintilla 1.71
// Remember a pointer to the scrollbar of the TQScintilla widget used to keep
// on the same line as before when turning preview on/off.
//m_textEditVScrollBar = m_qSciSourceCodeEditor->verticalScrollBar();
// Add a column row indicator to the status bar.
m_textEditLineColumnInfoLabel = new TQLabel(tr("Line %1, Column %2").arg(1).arg(1), this);
statusBar()->addWidget(m_textEditLineColumnInfoLabel, 0, true);
connect(m_qSciSourceCodeEditor, SIGNAL(cursorPositionChanged(int,int)),
this, SLOT(setStatusBarCursorPosInfo(int, int)));
// Connect the text editor to dependent functions.
connect(m_qSciSourceCodeEditor, SIGNAL(textChanged()), this, SLOT(sourceCodeChangedHelperSlot()));
// TODO signal 'linesChanged' is not available in TQScintilla 1.71.
// Use textChanged for now and check for line number changes in the slot
//connect(m_qSciSourceCodeEditor, SIGNAL(linesChanged()), this, SLOT(numberOfLinesChanged()));
connect(m_qSciSourceCodeEditor, SIGNAL(textChanged()), this, SLOT(numberOfLinesChanged()));
numberOfLinesChanged();
}
///-- /*
///-- \brief Create and init the syntax _highlighter and set it to use the TQScintilla edit component.
///-- */
@ -529,7 +537,7 @@ void MainWindow::openSourceFileDialog(TQString fileName)
///-- updateWindowTitle();
///-- updateRecentlyOpenedList();
///-- _textEditLastScrollPos = 0;
///-- _textEditVScrollBar->setValue(_textEditLastScrollPos);
///-- m_textEditVScrollBar->setValue(_textEditLastScrollPos);
///--
///-- _savedSourceContent = openedSourceFileContent;
///-- m_qSciSourceCodeEditor->setModified(false);
@ -650,7 +658,7 @@ bool MainWindow::saveSourceFile()
///-- */
///-- void MainWindow::updateSourceView()
///-- {
///-- _textEditLastScrollPos = _textEditVScrollBar->value();
///-- _textEditLastScrollPos = m_textEditVScrollBar->value();
///--
///-- if (m_toolBarWidget->cbLivePreview->isChecked())
///-- {
@ -673,7 +681,7 @@ bool MainWindow::saveSourceFile()
///-- SLOT(sourceCodeChangedHelperSlot()));
///-- }
///--
///-- _textEditVScrollBar->setValue(_textEditLastScrollPos);
///-- m_textEditVScrollBar->setValue(_textEditLastScrollPos);
///-- }
///--
///-- /*
@ -707,20 +715,20 @@ void MainWindow::turnHighlightOnOff(bool turnOn)
///-- updateSourceView();
}
///-- /*
///-- \brief Added this slot to avoid multiple calls because of changed text.
///-- */
///-- void MainWindow::sourceCodeChangedHelperSlot()
///-- {
///-- TQTimer::singleShot(0, this, SLOT(sourceCodeChangedSlot()));
///-- }
///--
///-- /*
///-- \brief Is emitted whenever the text inside the source view window changes. Calls the indenter
///-- to format the changed source code.
///-- */
///-- void MainWindow::sourceCodeChangedSlot()
///-- {
/*
\brief Added this slot to avoid multiple calls because of changed text.
*/
void MainWindow::sourceCodeChangedHelperSlot()
{
TQTimer::singleShot(0, this, SLOT(sourceCodeChangedSlot()));
}
/*
\brief Is emitted whenever the text inside the source view window changes. Calls the indenter
to format the changed source code.
*/
void MainWindow::sourceCodeChangedSlot()
{
///-- TQChar enteredCharacter;
///-- int cursorPos, cursorPosAbsolut, cursorLine;
///-- TQString text;
@ -863,8 +871,8 @@ void MainWindow::turnHighlightOnOff(bool turnOn)
///-- // Could set cursor this way and use normal linear search in text instead of columns and rows.
///-- //m_qSciSourceCodeEditor->SendScintilla(QsciScintillaBase::SCI_SETCURRENTPOS, 50);
///-- //m_qSciSourceCodeEditor->SendScintilla(QsciScintillaBase::SCI_SETANCHOR, 50);
///-- }
///--
}
///-- /*
///-- \brief This slot is called whenever one of the indenter _settings are changed.
///--
@ -1348,17 +1356,22 @@ void MainWindow::setWhiteSpaceVisibility(bool visible)
}
}
///-- /*
///-- \brief This slot is called whenever the number of lines in the editor changes
///-- and adapts the margin for the displayed line numbers.
///-- */
///-- void MainWindow::numberOfLinesChanged()
///-- {
///-- TQString lineNumbers;
///-- lineNumbers.setNum(m_qSciSourceCodeEditor->lines() * 10);
///-- m_qSciSourceCodeEditor->setMarginWidth(1, lineNumbers);
///-- }
///--
/*
\brief This slot is called whenever the number of lines in the editor changes
and adapts the margin for the displayed line numbers.
*/
void MainWindow::numberOfLinesChanged()
{
int lines = m_qSciSourceCodeEditor->lines();
if (lines != m_oldLinesNumber)
{
m_oldLinesNumber = lines;
TQString lineNumbers;
lineNumbers.setNum(lines * 10);
m_qSciSourceCodeEditor->setMarginWidth(1, lineNumbers);
}
}
///-- /*
///-- \brief Catches language change events and retranslates all needed widgets.
///-- */
@ -1547,7 +1560,7 @@ void MainWindow::openFileFromRecentlyOpenedList(int recentlyOpenedActionId)
{
// If the selected action from the recently opened list menu is the clear action
// call the slot to clear the list and then leave.
if (recentlyOpenedActionId == _actionClearRecentlyOpenedListId)
if (recentlyOpenedActionId == m_actionClearRecentlyOpenedListId)
{
clearRecentlyOpenedList();
return;
@ -1618,12 +1631,12 @@ void MainWindow::showAboutDialog()
m_aboutDialog->show();
}
///-- /*
///-- \brief Sets the label in the status bar to show the \a line and \a column number.
///-- */
///-- void MainWindow::setStatusBarCursorPosInfo(int line, int column)
///-- {
///-- _textEditLineColumnInfoLabel->setText(tr("Line %1, Column %2").arg(line + 1).arg(column + 1));
///-- }
/*
\brief Sets the label in the status bar to show the \a line and \a column number.
*/
void MainWindow::setStatusBarCursorPosInfo(int line, int column)
{
m_textEditLineColumnInfoLabel->setText(tr("Line %1, Column %2").arg(line + 1).arg(column + 1));
}
#include "MainWindow.moc"

@ -32,10 +32,10 @@ class AboutDialog;
class UiGuiSettings;
class ToolBarWidget;
///
/// class TQLabel;
/// class TQScrollBar;
/// class TQActionGroup;
class TQextScintilla;
class TQLabel;
class TQScrollBar;
class TQTranslator;
@ -61,20 +61,20 @@ class MainWindow : public MainWindowBase
///-- void updateSourceView();
void turnHighlightOnOff(bool turnOn);
void setWhiteSpaceVisibility(bool visible);
///-- void sourceCodeChangedHelperSlot();
///-- void sourceCodeChangedSlot();
void sourceCodeChangedHelperSlot();
void sourceCodeChangedSlot();
///-- void indentSettingsChangedSlot();
void previewTurnedOnOff(bool turnOn);
void exportToPDF();
void exportToHTML();
void languageChanged(int languageIndex);
///-- void encodingChanged(TQAction *encodingAction);
///-- void numberOfLinesChanged();
void numberOfLinesChanged();
void updateRecentlyOpenedList();
void openFileFromRecentlyOpenedList(int recentlyOpenedActionId);
void clearRecentlyOpenedList();
void showAboutDialog();
///-- void setStatusBarCursorPosInfo(int line, int column);
void setStatusBarCursorPosInfo(int line, int column);
///--
private:
///-- TQString loadFile(TQString filePath);
@ -88,7 +88,7 @@ class MainWindow : public MainWindowBase
bool initApplicationLanguage();
void initMainWindow();
void initToolBar();
///-- void initTextEditor();
void initTextEditor();
///-- void initSyntaxHighlighter();
///-- void initIndenter();
///-- void changeEvent(TQEvent *event);
@ -103,13 +103,14 @@ class MainWindow : public MainWindowBase
///-- TQString _sourceFormattedContent;
///-- TQString _sourceViewContent;
///-- UiGuiHighlighter *_highlighter;
///-- TQScrollBar *_textEditVScrollBar;
///-- TQScrollBar *m_textEditVScrollBar;
AboutDialog *m_aboutDialog;
///-- AboutDialogGraphicsView *_aboutDialogGraphicsView;
///-- UiGuiSettingsDialog *_settingsDialog;
int _actionClearRecentlyOpenedListId;
int m_actionClearRecentlyOpenedListId;
///-- int _textEditLastScrollPos;
///-- int _currentIndenterID;
int m_oldLinesNumber;
///-- bool _loadLastSourceCodeFileOnStartup;
///-- TQString _currentSourceFile;
///-- TQString _currentSourceFileExtension;
@ -120,14 +121,14 @@ class MainWindow : public MainWindowBase
TQTranslator *m_uiGuiTranslator;
TQTranslator *m_qTranslator;
///--
bool m_sourceCodeChanged;
bool m_sourceCodeChanged;
///-- bool _indentSettingsChanged;
///-- bool _previewToggled;
///-- TQStringList _encodingsList;
///--
ToolBarWidget *m_toolBarWidget;
///-- IndentHandler *_indentHandler;
///-- TQLabel *_textEditLineColumnInfoLabel;
TQLabel *m_textEditLineColumnInfoLabel;
};
#endif // MAINWINDOW_H

@ -341,7 +341,6 @@ void UiGuiSettings::handleValueChangeFromExtern(bool value)
// Set the value of the setting to the objects value.
setValueByName(settingName, value);
tqWarning("MIKE set="+settingName);
}
}
}
@ -361,6 +360,10 @@ void UiGuiSettings::emitSignalForSetting(TQString settingName)
{
emit whiteSpaceIsVisible(m_settings[settingName].toBool());
}
else if (settingName == "TabWidth")
{
emit tabWidth(m_settings[settingName].toInt());
}
else if (settingName == "Language")
{
emit language(m_settings[settingName].toInt());

@ -93,7 +93,7 @@ class UiGuiSettings : public TQObject
void syntaxHighlightingEnabled(bool value);
void whiteSpaceIsVisible(bool value);
// [++] void indenterParameterTooltipsEnabled(bool value);
// [++] void tabWidth(int value);
void tabWidth(int value);
void language(int value);
// [++] void lastUpdateCheck(TQDate value);
// [++] void mainWindowState(TQByteArray value);

@ -79,13 +79,13 @@
/*
\class UiGuiHighlighter
\ingroup grp_EditorComponent
\brief UiGuiHighlighter used for selecting the syntax highlighter/lexer for the QsciScintilla component.
\brief UiGuiHighlighter used for selecting the syntax highlighter/lexer for the TQextScintilla component.
*/
/*
\brief The constructor initializes some regular expressions and keywords to identify cpp tokens
*/
UiGuiHighlighter::UiGuiHighlighter(QsciScintilla *parent) :
UiGuiHighlighter::UiGuiHighlighter(TQextScintilla *parent) :
TQObject(parent)
{
_qsciEditorParent = parent;

@ -28,7 +28,7 @@
class TQAction;
class TQSettings;
class QsciScintilla;
class TQextScintilla;
class QsciLexer;
@ -37,7 +37,7 @@ class UiGuiHighlighter : public TQObject
Q_OBJECT
public:
UiGuiHighlighter(QsciScintilla *parent);
UiGuiHighlighter(TQextScintilla *parent);
void turnHighlightOff();
void turnHighlightOn();
@ -64,7 +64,7 @@ class UiGuiHighlighter : public TQObject
private:
bool _highlightingIsOn;
QsciScintilla *_qsciEditorParent;
TQextScintilla *_qsciEditorParent;
TQMap<int, TQFont> _fontForStyles;
TQMap<int, TQColor> _colorForStyles;
QsciLexer *_lexer;

Loading…
Cancel
Save