diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 14c10dd..4c71ba2 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -75,7 +75,7 @@ MainWindow::MainWindow(TQString file2OpenOnStart, TQWidget *parent) : m_highlighterActionGroup(nullptr), m_documentModified(false), m_previewToggled(true), m_indentHandler(nullptr), m_centralSplitter(nullptr), m_settingsDialog(nullptr), m_highlighter(nullptr), m_highlightingActions(), m_toolBarWidget(nullptr) -///_aboutDialogGraphicsView(nullptr), m_textEditVScrollBar(nullptr) +///-- m_textEditVScrollBar(nullptr) { // Init of some variables. m_sourceCodeChanged = false; @@ -689,148 +689,146 @@ void MainWindow::sourceCodeChangedHelperSlot() */ void MainWindow::sourceCodeChangedSlot() { -///-- TQChar enteredCharacter; -///-- int cursorPos, cursorPosAbsolut, cursorLine; -///-- TQString text; -///-- -///-- m_sourceCodeChanged = true; -///-- -///-- // Get the content text of the text editor. -///-- m_sourceFileContent = m_qSciSourceCodeEditor->text(); -///-- -///-- // Get the position of the cursor in the unindented text. -///-- if (m_sourceFileContent.isEmpty()) -///-- { -///-- // Add this line feed, because AStyle has problems with a totally emtpy file. -///-- m_sourceFileContent += "\n"; -///-- cursorPosAbsolut = 0; -///-- cursorPos = 0; -///-- cursorLine = 0; -///-- enteredCharacter = m_sourceFileContent.at(cursorPosAbsolut); -///-- } -///-- else -///-- { -///-- m_qSciSourceCodeEditor->getCursorPosition(&cursorLine, &cursorPos); -///-- cursorPosAbsolut = m_qSciSourceCodeEditor->SendScintilla(QsciScintillaBase::SCI_GETCURRENTPOS); -///-- text = m_qSciSourceCodeEditor->text(cursorLine); -///-- if (cursorPosAbsolut > 0) -///-- { -///-- cursorPosAbsolut--; -///-- } -///-- if (cursorPos > 0) -///-- { -///-- cursorPos--; -///-- } -///-- enteredCharacter = m_sourceFileContent.at(cursorPosAbsolut); -///-- } -///-- -///-- // Call the indenter to reformat the text. -///-- if (m_toolBarWidget->cbLivePreview->isChecked()) -///-- { -///-- callIndenter(); -///-- m_previewToggled = true; -///-- } -///-- -///-- // Update the text editor. -///-- updateSourceView(); -///-- -///-- if (m_toolBarWidget->cbLivePreview->isChecked() && !enteredCharacter.isNull() && -///-- enteredCharacter != 10) -///-- { -///-- //const char ch = enteredCharacter.toAscii(); -///-- -///-- int saveCursorLine = cursorLine; -///-- int saveCursorPos = cursorPos; -///-- -///-- bool charFound = false; -///-- -///-- // Search forward -///-- for (cursorLine = saveCursorLine; -///-- cursorLine - saveCursorLine < 6 && cursorLine < m_qSciSourceCodeEditor->lines(); -///-- cursorLine++) -///-- { -///-- text = m_qSciSourceCodeEditor->text(cursorLine); -///-- while (cursorPos < text.count() && enteredCharacter != text.at(cursorPos)) -///-- { -///-- cursorPos++; -///-- } -///-- if (cursorPos >= text.count()) -///-- { -///-- cursorPos = 0; -///-- } -///-- else -///-- { -///-- charFound = true; -///-- break; -///-- } -///-- } -///-- -///-- // If foward search did not find the character, search backward -///-- if (!charFound) -///-- { -///-- text = m_qSciSourceCodeEditor->text(saveCursorLine); -///-- cursorPos = saveCursorPos; -///-- if (cursorPos >= text.count()) -///-- { -///-- cursorPos = text.count() - 1; -///-- } -///-- -///-- for (cursorLine = saveCursorLine; saveCursorLine - cursorLine < 6 && cursorLine >= 0; -///-- cursorLine--) -///-- { -///-- text = m_qSciSourceCodeEditor->text(cursorLine); -///-- while (cursorPos >= 0 && enteredCharacter != text.at(cursorPos)) -///-- { -///-- cursorPos--; -///-- } -///-- if (cursorPos < 0) -///-- { -///-- cursorPos = m_qSciSourceCodeEditor->lineLength(cursorLine - 1) - 1; -///-- } -///-- else -///-- { -///-- charFound = true; -///-- break; -///-- } -///-- } -///-- } -///-- -///-- // If the character was found set its new cursor position... -///-- if (charFound) -///-- { -///-- m_qSciSourceCodeEditor->setCursorPosition(cursorLine, cursorPos + 1); -///-- } -///-- // ...if it was not found, set the previous cursor position. -///-- else -///-- { -///-- m_qSciSourceCodeEditor->setCursorPosition(saveCursorLine, saveCursorPos + 1); -///-- } -///-- } -///-- // set the previous cursor position. -///-- else if (enteredCharacter == 10) -///-- { -///-- m_qSciSourceCodeEditor->setCursorPosition(cursorLine, cursorPos); -///-- } -///-- -///-- if (m_toolBarWidget->cbLivePreview->isChecked()) -///-- { -///-- m_sourceCodeChanged = false; -///-- } -///-- -///-- if (m_savedSourceContent == m_qSciSourceCodeEditor->text()) -///-- { -///-- m_qSciSourceCodeEditor->setModified(false); -///-- m_documentModified = false; -///-- } -///-- else -///-- { -///-- m_qSciSourceCodeEditor->setModified(true); // Has no effect according to TQScintilla docs. -///-- m_documentModified = true; -///-- } -///-- -///-- // 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); + TQChar enteredCharacter; + int cursorPos, cursorPosAbsolut, cursorLine; + TQString text; + + m_sourceCodeChanged = true; + + // Get the content text of the text editor. + m_sourceFileContent = m_qSciSourceCodeEditor->text(); + + // Get the position of the cursor in the unindented text. + if (m_sourceFileContent.isEmpty()) + { + // Add this line feed, because AStyle has problems with a totally empty file. + m_sourceFileContent += "\n"; + cursorPosAbsolut = 0; + cursorPos = 0; + cursorLine = 0; + enteredCharacter = m_sourceFileContent.at(cursorPosAbsolut); + } + else + { + m_qSciSourceCodeEditor->getCursorPosition(&cursorLine, &cursorPos); + cursorPosAbsolut = m_qSciSourceCodeEditor->SendScintilla(TQextScintillaBase::SCI_GETCURRENTPOS); + text = m_qSciSourceCodeEditor->text(cursorLine); + if (cursorPosAbsolut > 0) + { + cursorPosAbsolut--; + } + if (cursorPos > 0) + { + cursorPos--; + } + // TODO: TQScintilla 1.7 returns the position as byte number within a C string. + // In case of UTF-8 characters, the index could increase by more than one per + // character. Therefore change the text to a C string and access the local + // 8 bit representation to get the character that was entered. + enteredCharacter = m_qSciSourceCodeEditor->text().local8Bit().at(cursorPosAbsolut); + } + + // Call the indenter to reformat the text. + if (m_toolBarWidget->cbLivePreview->isChecked()) + { + callIndenter(); + m_previewToggled = true; + } + + // Update the text editor. + updateSourceView(); + + if (m_toolBarWidget->cbLivePreview->isChecked() && !enteredCharacter.isNull() && + enteredCharacter != TQChar(10)) + { + int saveCursorLine = cursorLine; + int saveCursorPos = cursorPos; + + bool charFound = false; + + // Search forward + for (cursorLine = saveCursorLine; + cursorLine - saveCursorLine < 6 && cursorLine < m_qSciSourceCodeEditor->lines(); + cursorLine++) + { + text = m_qSciSourceCodeEditor->text(cursorLine); + while (cursorPos < text.length() && enteredCharacter != text.at(cursorPos)) + { + cursorPos++; + } + if (cursorPos >= text.length()) + { + cursorPos = 0; + } + else + { + charFound = true; + break; + } + } + + // If forward search did not find the character, search backward + if (!charFound) + { + text = m_qSciSourceCodeEditor->text(saveCursorLine); + cursorPos = saveCursorPos; + if (cursorPos >= text.length()) + { + cursorPos = text.length() - 1; + } + + for (cursorLine = saveCursorLine; saveCursorLine - cursorLine < 6 && cursorLine >= 0; + cursorLine--) + { + text = m_qSciSourceCodeEditor->text(cursorLine); + while (cursorPos >= 0 && enteredCharacter != text.at(cursorPos)) + { + cursorPos--; + } + if (cursorPos < 0) + { + cursorPos = m_qSciSourceCodeEditor->lineLength(cursorLine - 1) - 1; + } + else + { + charFound = true; + break; + } + } + } + + // If the character was found set its new cursor position... + if (charFound) + { + m_qSciSourceCodeEditor->setCursorPosition(cursorLine, cursorPos + 1); + } + // ...if it was not found, set the previous cursor position. + else + { + m_qSciSourceCodeEditor->setCursorPosition(saveCursorLine, saveCursorPos + 1); + } + } + // set the previous cursor position. + else if (enteredCharacter == TQChar(10)) + { + m_qSciSourceCodeEditor->setCursorPosition(cursorLine, cursorPos); + } + + if (m_toolBarWidget->cbLivePreview->isChecked()) + { + m_sourceCodeChanged = false; + } + + if (m_savedSourceContent == m_qSciSourceCodeEditor->text()) + { + m_qSciSourceCodeEditor->setModified(false); + m_documentModified = false; + } + else + { + m_qSciSourceCodeEditor->setModified(true); // Has no effect according to TQScintilla docs. + m_documentModified = true; + } } /* @@ -926,6 +924,10 @@ void MainWindow::updateWindowTitle() */ void MainWindow::exportToPDF() { + // Not supported in TQt3 + TQMessageBox::warning(this, tr("Not supported"), + tr("Export to PDF is currently not supported.")); + ///-- TQString fileExtensions = tr("PDF Document") + " (*.pdf)"; ///-- ///-- TQString fileName = m_currentSourceFile; @@ -950,6 +952,10 @@ void MainWindow::exportToPDF() */ void MainWindow::exportToHTML() { + // Not supported in TQt3 + TQMessageBox::warning(this, tr("Not supported"), + tr("Export to HTML is currently not supported.")); + ///-- TQString fileExtensions = tr("HTML Document") + " (*.html)"; ///-- ///-- TQString fileName = m_currentSourceFile; diff --git a/src/MainWindowBase.ui b/src/MainWindowBase.ui index 087352e..229d41a 100755 --- a/src/MainWindowBase.ui +++ b/src/MainWindowBase.ui @@ -41,11 +41,6 @@ - - - - -