[Licq-devel] to flynd: mledit rewritten
"Eugene Paskevich" <[email protected]>
| Newsgroups | gmane.network.licq.devel |
|---|---|
| Organization | Raptor's NestSite |
| Message-ID | <[email protected]> |
Hi,
Please be aware, that the patch in attachment must be considered as
experimental.
Here is short summary of positive changes:
1) Ctrl-U has been fixed to kill the line under cursor, not the first line.
(same has to be fixed in qt3 plugin either, didn't check);
2) Suggested my preferred Ctrl-U behaviour under Ctrl-N shortcut;
3) Made cursor width to be 2 pixels instead of 1 in overwrite mode;
analogous summary for negative changes (drawbacks):
1) there is no more setText() with context parameter in qt4, removed;
2) CLogWidget length limit of 500 lines was temporarily removed.
There is a handy method in QTextDocument (setMaximumBlockCount),
but I couldn't implement it;
--
Eugene Paskevich | *==)----------- | Plug me into
[email protected] | -----------(==* | The Matrix
licq_qt4_mledit.diff
(application/octet-stream, 8.2 KB)
Index: mledit.cpp =================================================================== --- mledit.cpp (revision 5032) +++ mledit.cpp (working copy) @@ -21,59 +21,46 @@ // written by Graham Roff <[email protected]> // contributions by Dirk A. Mueller <[email protected]> -#include "config.h" +#include <QMenu> -#include <QFont> -#include <Q3PopupMenu> -//Added by qt3to4: -#include <QKeyEvent> - #include "mledit.h" - QFont *MLEditWrap::editFont = NULL; bool MLEditWrap::useDoubleReturn = false; MLEditWrap::MLEditWrap (bool wordWrap, QWidget* parent, bool /* doQuotes */, const char *name) - : MLEditWrapBase(parent, name), + : MLEditWrapBase(parent), m_fixSetTextNewlines(true), m_lastKeyWasReturn(false) { - setTextFormat(Qt::PlainText); + setObjectName(name); setTabChangesFocus(true); - if (wordWrap) - { - setWordWrap(Q3TextEdit::WidgetWidth); - setWrapPolicy(Q3TextEdit::AtWhiteSpace); - } - else - { - setWordWrap(Q3TextEdit::NoWrap); - } + if (!wordWrap) + setLineWrapMode(NoWrap); if (editFont) - QWidget::setFont(*editFont, true); + setCurrentFont(*editFont); } void MLEditWrap::appendNoNewLine(const QString& s) { GotoEnd(); - insert(s); + insertPlainText(s); } void MLEditWrap::GotoEnd() { - moveCursor(Q3TextEdit::MoveEnd, false); + moveCursor(QTextCursor::End); } void MLEditWrap::setBackground(const QColor& c) { QPalette pal = palette(); - pal.setColor(QPalette::Active, QColorGroup::Base, c); - pal.setColor(QPalette::Inactive, QColorGroup::Base, c); + pal.setColor(QPalette::Active, QPalette::Base, c); + pal.setColor(QPalette::Inactive, QPalette::Base, c); setPalette(pal); } @@ -82,8 +69,8 @@ { QPalette pal = palette(); - pal.setColor(QPalette::Active, QColorGroup::Text, c); - pal.setColor(QPalette::Inactive, QColorGroup::Text, c); + pal.setColor(QPalette::Active, QPalette::Text, c); + pal.setColor(QPalette::Inactive, QPalette::Text, c); setPalette(pal); } @@ -108,9 +95,11 @@ void MLEditWrap::keyPressEvent( QKeyEvent *e ) { - const bool isShift = e->state() & Qt::ShiftButton; - const bool isControl = e->state() & Qt::ControlButton; + const bool isShift = e->modifiers() & Qt::ShiftModifier; + const bool isControl = e->modifiers() & Qt::ControlModifier; + QTextCursor cr = textCursor(); + // Get flag from last time and reset it before any possible returns bool lastKeyWasReturn = m_lastKeyWasReturn; m_lastKeyWasReturn = false; @@ -124,25 +113,32 @@ if (isControl && e->key() == Qt::Key_Insert) return copy(); + if (isControl) { switch (e->key()) { case Qt::Key_W: - moveCursor(Q3TextEdit::MoveWordBackward, true); - del(); + cr.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor); + cr.removeSelectedText(); break; case Qt::Key_U: - moveCursor(Q3TextEdit::MoveHome, false); - doKeyboardAction(Q3TextEdit::ActionKill); + cr.select(QTextCursor::LineUnderCursor); + cr.removeSelectedText(); break; case Qt::Key_L: clear(); break; + case Qt::Key_N: // Temporarily inserted here to depict how I think Ctrl-U should behave + cr.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor); + if (!cr.hasSelection()) + cr.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor); + cr.removeSelectedText(); + break; case Qt::Key_Return: case Qt::Key_Enter: if (useDoubleReturn) - insert("\n"); + insertPlainText(QString("\n")); else emit signal_CtrlEnterPressed(); break; @@ -152,7 +148,7 @@ return; } - if ((e->state() & Qt::KeyButtonMask) == 0) + if ((e->modifiers() & Qt::KeyboardModifierMask) == 0) { switch (e->key()) { @@ -161,8 +157,8 @@ if (lastKeyWasReturn && useDoubleReturn) { // Return pressed twice, remove the previous line break and emit signal - moveCursor(MoveBackward, true); - del(); + cr.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor); + cr.removeSelectedText(); emit signal_CtrlEnterPressed(); return; } @@ -172,21 +168,37 @@ m_lastKeyWasReturn = true; } break; + case Qt::Key_Insert: + if (overwriteMode()) { + setOverwriteMode(false); + setCursorWidth(1); + } + else + { + setOverwriteMode(true); + setCursorWidth(2); + } + break; } } MLEditWrapBase::keyPressEvent(e); } -Q3PopupMenu *MLEditWrap::createPopupMenu(const QPoint &pos) +void MLEditWrap::contextMenuEvent(QContextMenuEvent *e) { - Q3PopupMenu *menu = MLEditWrapBase::createPopupMenu(pos); -#ifndef MLEDIT_USE_KTEXTEDIT - menu->insertSeparator(); - int id = menu->insertItem(tr("Allow Tabulations"), this, SLOT(slotToggleAllowTab())); - menu->setItemChecked(id, !tabChangesFocus()); -#endif - return menu; + QMenu *menu=createStandardContextMenu(); + + QAction *tabul = new QAction(tr("Allow Tabulations"), menu); + tabul->setCheckable(true); + tabul->setChecked(!tabChangesFocus()); + connect(tabul, SIGNAL(triggered()), this, SLOT(slotToggleAllowTab())); + + menu->addSeparator(); // is it really needed? + menu->addAction(tabul); + + menu->exec(e->globalPos()); + delete menu; } void MLEditWrap::slotToggleAllowTab() @@ -236,6 +248,7 @@ MLEditWrapBase::setText(text); } +#if 0 void MLEditWrap::setText(const QString& txt, const QString& context) { const bool modified = isModified(); // don't let setText reset this flag @@ -259,5 +272,6 @@ setModified(modified); m_fixSetTextNewlines = true; } +#endif #include "mledit.moc" Index: outputwin.cpp =================================================================== --- outputwin.cpp (revision 5032) +++ outputwin.cpp (working copy) @@ -105,12 +105,14 @@ outputBox->appendNoNewLine(str); outputBox->GotoEnd(); +#if 0 // hardcoded limit, maybe should be user configurable? if (outputBox->paragraphs() > 564) { int todo = outputBox->paragraphs() - 500; for (int i = 0; i < todo; ++i) outputBox->removeParagraph(0); } +#endif /* The next call will block, so we need to clear the log so that processing can continue */ Index: mledit.h =================================================================== --- mledit.h (revision 5032) +++ mledit.h (working copy) @@ -1,6 +1,3 @@ -//Added by qt3to4: -#include <Q3PopupMenu> -#include <QKeyEvent> /* * This file is part of Licq, an instant messaging client for UNIX. * Copyright (C) 1999-2006 Licq developers @@ -42,11 +39,11 @@ MLEditWrapBase(QWidget *parent, const char *name) : KTextEdit(parent, name) {} }; #else -# include <Q3TextEdit> - class MLEditWrapBase : public Q3TextEdit +# include <QTextEdit> + class MLEditWrapBase : public QTextEdit { public: - MLEditWrapBase(QWidget *parent, const char *name) : Q3TextEdit(parent, name) {} + MLEditWrapBase(QWidget *parent) : QTextEdit(parent) {} }; #endif @@ -71,11 +68,11 @@ protected: virtual void keyPressEvent(QKeyEvent *e); - virtual Q3PopupMenu *createPopupMenu(const QPoint& pos); + virtual void contextMenuEvent(QContextMenuEvent *e); public slots: void setText(const QString& text); - virtual void setText(const QString& text, const QString& context); + //virtual void setText(const QString& text, const QString& context); private slots: void slotToggleAllowTab(); Index: usereventdlg.cpp =================================================================== --- usereventdlg.cpp (revision 5032) +++ usereventdlg.cpp (working copy) @@ -2135,7 +2135,7 @@ if (e->mleSend && mleSend) { e->mleSend->setText(mleSend->text()); - e->mleSend->setModified(e->mleSend->length()); + e->mleSend->setModified(mleSend->isModified()); } if (e->mleHistory && mleHistory){ e->mleHistory->setText(mleHistory->text()); @@ -2878,7 +2878,7 @@ mleSend->setFocus(); // Makes the cursor blink so that the user sees that the text edit has focus. - mleSend->moveCursor(Q3TextEdit::MoveHome, false); + mleSend->moveCursor(QTextCursor::Start); massMessageToggled( false ); }