From f03067d2407b03cc10be1df869b024d8223d46b0 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Sat, 29 May 2010 18:43:14 +0200 Subject: [PATCH] Replace deprecated Q3 widgets in the TTY output window. The window is now a QPlainTextEdit. One advantage of it is that the insertion point (where newly arriving text is inserted) and the user's selection are independent. There is one regression, though: When new lines are inserted at the end, the window should scroll down to keep the last line visible, but it does not anymore. --- kdbg/ttywnd.cpp | 44 +++++++++++++++++++------------------------- kdbg/ttywnd.h | 9 ++++----- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/kdbg/ttywnd.cpp b/kdbg/ttywnd.cpp index 5eb2137..0f05775 100644 --- a/kdbg/ttywnd.cpp +++ b/kdbg/ttywnd.cpp @@ -6,7 +6,8 @@ #include "ttywnd.h" #include -#include +#include +#include #include #include @@ -131,15 +132,15 @@ void STTY::outReceived(int f) TTYWindow::TTYWindow(QWidget* parent) : - Q3TextEdit(parent), + QPlainTextEdit(parent), m_tty(0), - m_hPos(0) + m_pos(document()) { setFont(KGlobalSettings::fixedFont()); setReadOnly(true); - setAutoFormatting(AutoNone); - setTextFormat(Qt::PlainText); - setWordWrap(NoWrap); + setWordWrapMode(QTextOption::NoWrap); + setUndoRedoEnabled(false); + m_pos.setPosition(0); } TTYWindow::~TTYWindow() @@ -172,11 +173,6 @@ void TTYWindow::deactivate() m_tty = 0; } -/** - * Note that it is necessary to track the horizontal position explicitly - * since if the user modifies the selected text in the window, the cursor - * position changes, too. - */ void TTYWindow::slotAppend(char* buffer, int count) { // parse off lines @@ -190,42 +186,40 @@ void TTYWindow::slotAppend(char* buffer, int count) if (len > 0) { QString str = QString::fromLatin1(start, len); // replace text in the last line - int para = paragraphs()-1; // this selection is non-empty only after a '\r' that was not // followed by a '\n' - setSelection(para, m_hPos, para, m_hPos+len, 1); - removeSelectedText(1); - insertAt(str, para, m_hPos); - m_hPos += len; + m_pos.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, len); + m_pos.insertText(str); start += len; len = 0; } if (count > 0 && *start == '\r') { ++start; --count; - m_hPos = 0; + m_pos.movePosition(QTextCursor::StartOfLine); } if (count > 0 && *start == '\n') { ++start; --count; - append(QString()); - m_hPos = 0; + m_pos.movePosition(QTextCursor::End); + m_pos.insertText(QString('\n')); } } } -Q3PopupMenu* TTYWindow::createPopupMenu(const QPoint& pos) +void TTYWindow::contextMenuEvent(QContextMenuEvent *event) { - Q3PopupMenu* menu = Q3TextEdit::createPopupMenu(pos); - menu->insertSeparator(); - menu->insertItem(i18n("&Clear"), this, SLOT(slotClear())); - return menu; + QMenu* menu = createStandardContextMenu(); + menu->addSeparator(); + menu->addAction(i18n("&Clear"),this, SLOT(slotClear())); + menu->exec(event->globalPos()); + delete menu; } void TTYWindow::slotClear() { clear(); - m_hPos = 0; + m_pos.movePosition(QTextCursor::End); } #include "ttywnd.moc" diff --git a/kdbg/ttywnd.h b/kdbg/ttywnd.h index 9c9c973..a12a980 100644 --- a/kdbg/ttywnd.h +++ b/kdbg/ttywnd.h @@ -7,10 +7,9 @@ #ifndef TTYWND_H #define TTYWND_H -#include +#include class QSocketNotifier; -class Q3PopupMenu; /** * This class is cortesy Judin Max . @@ -46,7 +45,7 @@ protected: bool findTTY(); }; -class TTYWindow : public Q3TextEdit +class TTYWindow : public QPlainTextEdit { Q_OBJECT public: @@ -58,8 +57,8 @@ public: protected: STTY* m_tty; - virtual Q3PopupMenu* createPopupMenu(const QPoint& pos); - int m_hPos; //!< tracks horizontal cursor position + QTextCursor m_pos; //!< tracks horizontal cursor position + virtual void contextMenuEvent(QContextMenuEvent*); protected slots: void slotAppend(char* buffer, int count); -- 2.11.4.GIT