[Licq-devel] Re: to flynd: mledit rewritten
"Eugene Paskevich" <[email protected]>
| Newsgroups | gmane.network.licq.devel |
|---|---|
| Organization | Raptor's NestSite |
| Message-ID | <[email protected]> |
On Fri, 20 Jul 2007 14:54:52 +0300, Eugene Paskevich <[email protected]> wrote: > 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; Well, here is the final (hope so) version of the patch where the second drawback is solved and one more signal introduced to make awaymsgdlg work correctly. -- Eugene Paskevich | *==)----------- | Plug me into [email protected] | -----------(==* | The Matrix
licq_qt4_mledit.diff
(application/octet-stream, 9.6 KB)
Index: mledit.h
===================================================================
--- mledit.h (revision 5035)
+++ 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,17 +68,19 @@
protected:
virtual void keyPressEvent(QKeyEvent *e);
- virtual Q3PopupMenu *createPopupMenu(const QPoint& pos);
+ virtual void mousePressEvent(QMouseEvent *e);
+ 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();
signals:
void signal_CtrlEnterPressed();
+ void signal_Clicked();
private:
bool m_fixSetTextNewlines;
Index: mledit.cpp
===================================================================
--- mledit.cpp (revision 5035)
+++ 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;
@@ -129,20 +118,30 @@
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::BlockUnderCursor);
+ if (!cr.hasSelection())
+ cr.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);
+ if (!cr.hasSelection())
+ cr.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
+ cr.removeSelectedText();
break;
case Qt::Key_L:
clear();
break;
+ case Qt::Key_N: // Just the opposite of Ctrl+K
+ cr.movePosition(QTextCursor::StartOfBlock, 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 +151,7 @@
return;
}
- if ((e->state() & Qt::KeyButtonMask) == 0)
+ if ((e->modifiers() & Qt::KeyboardModifierMask) == 0)
{
switch (e->key())
{
@@ -161,8 +160,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,23 +171,46 @@
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::mousePressEvent(QMouseEvent *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;
+ emit signal_Clicked();
+ MLEditWrapBase::mousePressEvent(e);
}
+void MLEditWrap::contextMenuEvent(QContextMenuEvent *e)
+{
+ QMenu *menu=createStandardContextMenu();
+
+ if (!isReadOnly())
+ {
+ QAction *tabul = new QAction(tr("Allow Tabulations"), menu);
+ tabul->setCheckable(true);
+ tabul->setChecked(!tabChangesFocus());
+ connect(tabul, SIGNAL(triggered()), this, SLOT(slotToggleAllowTab()));
+ menu->addAction(tabul);
+ }
+
+ menu->exec(e->globalPos());
+ delete menu;
+}
+
void MLEditWrap::slotToggleAllowTab()
{
setTabChangesFocus(!tabChangesFocus());
@@ -236,6 +258,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 +282,6 @@
setModified(modified);
m_fixSetTextNewlines = true;
}
+#endif
#include "mledit.moc"
Index: outputwin.cpp
===================================================================
--- outputwin.cpp (revision 5035)
+++ outputwin.cpp (working copy)
@@ -56,6 +56,12 @@
outputBox->setMinimumHeight(outputBox->frameWidth()*2
+ 16*outputBox->fontMetrics().lineSpacing());
outputBox->setMinimumWidth(outputBox->minimumHeight()*2);
+
+ QTextDocument *doc = outputBox->document();
+ // hardcoded limit, maybe should be user configurable?
+ doc->setMaximumBlockCount(500);
+ outputBox->setDocument(doc);
+
top_lay->addWidget(outputBox);
QHBoxLayout* lay = new QHBoxLayout();
@@ -105,13 +111,6 @@
outputBox->appendNoNewLine(str);
outputBox->GotoEnd();
- // 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);
- }
-
/* The next call will block, so we need to clear the log so that processing
can continue */
unsigned short nNextLogType = NextLogType();
Index: usereventdlg.cpp
===================================================================
--- usereventdlg.cpp (revision 5035)
+++ 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 );
}
Index: awaymsgdlg.cpp
===================================================================
--- awaymsgdlg.cpp (revision 5035)
+++ awaymsgdlg.cpp (working copy)
@@ -117,7 +117,7 @@
m_autocloseCounter = -1;
installEventFilter(this);
mleAwayMsg->installEventFilter(this);
- connect(mleAwayMsg, SIGNAL(clicked(int, int)), SLOT(slot_autocloseStop()));
+ connect(mleAwayMsg, SIGNAL(signal_Clicked()), SLOT(slot_autocloseStop()));
connect(mnuSelect, SIGNAL(aboutToShow()), SLOT(slot_autocloseStop()));
connect(btnHints, SIGNAL(clicked()), SLOT(slot_autocloseStop()));
}