From: <er...@us...> - 2006-07-16 21:12:14
|
Author: erijo Date: 2006-07-17 06:11:43 +0900 (Mon, 17 Jul 2006) New Revision: 4531 Modified: trunk/qt-gui/src/authuserdlg.cpp trunk/qt-gui/src/chatdlg.h trunk/qt-gui/src/ewidgets.h trunk/qt-gui/src/mainwin.cpp trunk/qt-gui/src/mainwin.h trunk/qt-gui/src/mledit.cpp trunk/qt-gui/src/mledit.h trunk/qt-gui/src/outputwin.cpp trunk/qt-gui/src/usereventdlg.cpp Log: Add spell check to kde-gui. This, at least partly, implements #824. To activate the spell check per default, open a new message dialog, right click in the box where you enter the message, activate "Auto Spell Check" and click "Save Settings" in the main menu. Modified: trunk/qt-gui/src/authuserdlg.cpp =================================================================== --- trunk/qt-gui/src/authuserdlg.cpp 2006-07-15 14:27:46 UTC (rev 4530) +++ trunk/qt-gui/src/authuserdlg.cpp 2006-07-16 21:11:43 UTC (rev 4531) @@ -71,7 +71,7 @@ QString userName; ICQUser *u = gUserManager.FetchUser(m_szId, m_nPPID, LOCK_R); if (u != NULL) { - QTextCodec *codec = UserCodec::codecForICQUser(u); + //QTextCodec *codec = UserCodec::codecForICQUser(u); userName = QString("%1 (%2)").arg(QString::fromUtf8(u->GetAlias())).arg(m_szId); gUserManager.DropUser(u); } else { @@ -152,7 +152,7 @@ QString userName; ICQUser *u = gUserManager.FetchUser(m_nUin, LOCK_R); if (u != NULL) { - QTextCodec *codec = UserCodec::codecForICQUser(u); + //QTextCodec *codec = UserCodec::codecForICQUser(u); userName = QString("%1 (%2)").arg(QString::fromUtf8(u->GetAlias())).arg(m_nUin); gUserManager.DropUser(u); } else { Modified: trunk/qt-gui/src/chatdlg.h =================================================================== --- trunk/qt-gui/src/chatdlg.h 2006-07-15 14:27:46 UTC (rev 4530) +++ trunk/qt-gui/src/chatdlg.h 2006-07-16 21:11:43 UTC (rev 4531) @@ -11,8 +11,6 @@ #include <list> #include <deque> -#include "mledit.h" - class CChatManager; class CChatUser; Modified: trunk/qt-gui/src/ewidgets.h =================================================================== --- trunk/qt-gui/src/ewidgets.h 2006-07-15 14:27:46 UTC (rev 4530) +++ trunk/qt-gui/src/ewidgets.h 2006-07-16 21:11:43 UTC (rev 4531) @@ -11,7 +11,6 @@ #include <qtabwidget.h> #include <qmap.h> -#include "mledit.h" #include "mlview.h" #include "licq_message.h" Modified: trunk/qt-gui/src/mainwin.cpp =================================================================== --- trunk/qt-gui/src/mainwin.cpp 2006-07-15 14:27:46 UTC (rev 4530) +++ trunk/qt-gui/src/mainwin.cpp 2006-07-16 21:11:43 UTC (rev 4531) @@ -110,8 +110,10 @@ #include "xpm/pixCellular.xpm" #include "xpm/pixBirthday.xpm" #include "xpm/pixInvisible.xpm" -#include "xpm/pixKeyEnabled.xpm" -#include "xpm/pixKeyDisabled.xpm" +#ifdef HAVE_LIBGPGME +# include "xpm/pixKeyEnabled.xpm" +# include "xpm/pixKeyDisabled.xpm" +#endif #include "xpm/pixTyping.xpm" #include "xpm/pixICQphoneActive.xpm" #include "xpm/pixICQphoneBusy.xpm" @@ -448,6 +450,7 @@ licqConf.ReadBool("MainWinSticky", m_bMainWinSticky, false); licqConf.ReadBool("MsgWinSticky", m_bMsgWinSticky, false); licqConf.ReadBool("SingleLineChatMode", m_bSingleLineChatMode, false); + licqConf.ReadBool("CheckSpellingEnabled", m_bCheckSpellingEnabled, false); licqConf.ReadStr("ReceiveMessageColor", szTemp, "red"); m_colorRcv = QColor(szTemp); @@ -3655,6 +3658,7 @@ licqConf.WriteBool("MainWinSticky", m_bMainWinSticky); licqConf.WriteBool("MsgWinSticky", m_bMsgWinSticky); licqConf.WriteBool("SingleLineChatMode", m_bSingleLineChatMode); + licqConf.WriteBool("CheckSpellingEnabled", m_bCheckSpellingEnabled); licqConf.WriteNum("ChatMessageStyle", m_nMsgStyle); licqConf.WriteBool("ChatAppendLinebreak", m_bAppendLineBreak); Modified: trunk/qt-gui/src/mainwin.h =================================================================== --- trunk/qt-gui/src/mainwin.h 2006-07-15 14:27:46 UTC (rev 4530) +++ trunk/qt-gui/src/mainwin.h 2006-07-16 21:11:43 UTC (rev 4531) @@ -157,6 +157,7 @@ m_bMainWinSticky, m_bMsgWinSticky, m_bSingleLineChatMode, + m_bCheckSpellingEnabled, m_bShowUserIcons; QString m_MsgAutopopupKey; Modified: trunk/qt-gui/src/mledit.cpp =================================================================== --- trunk/qt-gui/src/mledit.cpp 2006-07-15 14:27:46 UTC (rev 4530) +++ trunk/qt-gui/src/mledit.cpp 2006-07-16 21:11:43 UTC (rev 4531) @@ -1,21 +1,23 @@ // -*- c-basic-offset: 2 -*- /* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + * This file is part of Licq, an instant messaging client for UNIX. + * Copyright (C) 1999-2006 Licq developers + * + * Licq is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Licq is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Licq; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - // written by Graham Roff <gr...@li...> // contributions by Dirk A. Mueller <di...@li...> @@ -24,8 +26,7 @@ #endif #include <qfont.h> -#include <qpainter.h> -#include <qaccel.h> +#include <qpopupmenu.h> #include "mledit.h" @@ -33,18 +34,19 @@ QFont *MLEditWrap::editFont = NULL; MLEditWrap::MLEditWrap (bool wordWrap, QWidget* parent, bool doQuotes, const char *name) - : QMultiLineEdit(parent, name) + : MLEditWrapBase(parent, name), m_fixSetTextNewlines(true) { - m_bDoQuotes = doQuotes; + setTextFormat(Qt::PlainText); + setTabChangesFocus(true); if (wordWrap) { - setWordWrap(WidgetWidth); - setWrapPolicy(AtWhiteSpace); + setWordWrap(QTextEdit::WidgetWidth); + setWrapPolicy(QTextEdit::AtWhiteSpace); } else { - setWordWrap(NoWrap); + setWordWrap(QTextEdit::NoWrap); } if (editFont) @@ -54,43 +56,30 @@ void MLEditWrap::appendNoNewLine(const QString& s) { - if (!atEnd()) GotoEnd(); - QMultiLineEdit::insert(s); + GotoEnd(); + insert(s); } void MLEditWrap::append(const QString& s) { -#if QT_VERSION < 300 - appendNoNewLine(s + "\n"); -#else + MLEditWrapBase::append(s); if (strcmp(qVersion(), "3.0.0") == 0 || strcmp(qVersion(), "3.0.1") == 0 || strcmp(qVersion(), "3.0.2") == 0 || - strcmp(qVersion(), "3.0.3") == 0 || + strcmp(qVersion(), "3.0.3") == 0 || strcmp(qVersion(), "3.0.4") == 0) { - // Workaround -- - // In those versions, QTextEdit::append didn't add a new paragraph. - QTextEdit::append(s); - QTextEdit::append("\n"); + // Workaround -- + // In those versions, QTextEdit::append didn't add a new paragraph. + MLEditWrapBase::append("\n"); } - else - { - QTextEdit::append(s); - } -#endif } void MLEditWrap::GotoEnd() { -#if QT_VERSION >= 300 moveCursor(QTextEdit::MoveEnd, false); -#else - setCursorPosition(numLines() - 1, lineLength(numLines() - 1) - 1); -#endif } - void MLEditWrap::setBackground(const QColor& c) { QPalette pal = palette(); @@ -101,10 +90,6 @@ setPalette(pal); } - -// ----------------------------------------------------------------------------- - - void MLEditWrap::setForeground(const QColor& c) { QPalette pal = palette(); @@ -115,36 +100,20 @@ setPalette(pal); } -bool MLEditWrap::focusNextPrevChild( bool f) +void MLEditWrap::setCheckSpellingEnabled(bool check) { - return QWidget::focusNextPrevChild(f); +#ifdef MLEDIT_USE_KTEXTEDIT + MLEditWrapBase::setCheckSpellingEnabled(check); +#endif } - -// ----------------------------------------------------------------------------- - -void MLEditWrap::paintCell(QPainter* p, int row, int col) +bool MLEditWrap::checkSpellingEnabled() const { - -#if QT_VERSION >= 210 && QT_VERSION < 300 - if (m_bDoQuotes) - { - QString s = stringShown(row); - int i = (s[0] == ' '); - bool italic = (s[i] == '>' && (s[i+1] == ' ' || s[i+1] == '>')); - - if (italic ^ p->font().italic()) - { - QFont f(p->font()); - f.setItalic(italic); - p->setFont(f); - } - } +#ifdef MLEDIT_USE_KTEXTEDIT + return MLEditWrapBase::checkSpellingEnabled(); +#else + return false; #endif - -#if QT_VERSION < 300 - QMultiLineEdit::paintCell(p, row, col); -#endif } void MLEditWrap::keyPressEvent( QKeyEvent *e ) @@ -166,12 +135,12 @@ switch (e->key()) { case Key_W: - cursorWordBackward(true); + moveCursor(QTextEdit::MoveWordBackward, true); del(); break; case Key_U: - home(); - killLine(); + moveCursor(QTextEdit::MoveHome, false); + doKeyboardAction(QTextEdit::ActionKill); break; case Key_L: clear(); @@ -181,29 +150,92 @@ emit signal_CtrlEnterPressed(); break; default: - QMultiLineEdit::keyPressEvent(e); + MLEditWrapBase::keyPressEvent(e); } return; } - QMultiLineEdit::keyPressEvent(e); + MLEditWrapBase::keyPressEvent(e); } -void MLEditWrap::setCellWidth ( int cellW ) +QPopupMenu *MLEditWrap::createPopupMenu(const QPoint &pos) { -#if QT_VERSION == 210 - if ( cellWidth() == cellW ) - return; + QPopupMenu *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; +} - QTableView::setCellWidth(cellW); +void MLEditWrap::slotToggleAllowTab() +{ + setTabChangesFocus(!tabChangesFocus()); +} - if ( autoUpdate() && isVisible() ) - repaint(); -#else -#if QT_VERSION < 300 - QMultiLineEdit::setCellWidth( cellW ); +/** + * @return the number of characters @a c at the end of @a str. + */ +static unsigned int countCharRev(const QString& str, const QChar c) +{ + unsigned int count = 0; + for (unsigned int pos = str.length() - 1; pos >= 0; pos--) + { + if (str.at(pos) != c) + break; + count += 1; + } + return count; +} + +/* + * KTextEdit adds a menu entry for doing spell checking. Unfortunatly KSpell + * (which is what KTextEdit uses to do the spell check) messes with the newlines + * at the end of the text it checks. That's why we need the hack below. It uses + * the fact that setText(const QString&) is non-virtual and only calls the + * virtual setText(const QString&, const QString&) with a null context. + * + * When KTextEdit calls setText(correctedText) after the spell check is done + * it will call QTextEdit::setText (since it's non-virtual). QTextEdit will + * then call setText(correctedText, QString::null) which will end up in the + * setText below (since it's virtual). And with m_fixSetTextNewlines set to + * true we can fix so that there is as many newlines at the end of the corrected + * text as there is in the old. + * + * On the other hand, when any class that uses MLEditWrap calls + * myMLEditWrapInstance->setText(myText) the call will end up at + * MLEditWrap::setText(myText) which will set m_fixSetTextNewlines to false before + * calling QTextEdit::setText(myText). + */ +void MLEditWrap::setText(const QString& text) +{ + m_fixSetTextNewlines = false; + MLEditWrapBase::setText(text); +} + +void MLEditWrap::setText(const QString& txt, const QString& context) +{ + const bool modified = isModified(); // don't let setText reset this flag +#ifdef MLEDIT_USE_KTEXTEDIT + const QString current = text(); + if (m_fixSetTextNewlines && context.isNull()) + { + const unsigned int currentNL = countCharRev(current, '\n'); + const unsigned int txtNL = countCharRev(txt, '\n'); + if (currentNL > txtNL) + MLEditWrapBase::setText(txt + QString().fill('\n', currentNL - txtNL), context); + else if (txtNL > currentNL) + MLEditWrapBase::setText(txt.left(txt.length() - (txtNL - currentNL)), context); + else + MLEditWrapBase::setText(txt, context); + } + else #endif -#endif + MLEditWrapBase::setText(txt, context); + + setModified(modified); + m_fixSetTextNewlines = true; } #include "mledit.moc" Modified: trunk/qt-gui/src/mledit.h =================================================================== --- trunk/qt-gui/src/mledit.h 2006-07-15 14:27:46 UTC (rev 4530) +++ trunk/qt-gui/src/mledit.h 2006-07-16 21:11:43 UTC (rev 4531) @@ -1,9 +1,55 @@ +/* + * This file is part of Licq, an instant messaging client for UNIX. + * Copyright (C) 1999-2006 Licq developers + * + * Licq is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Licq is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Licq; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + #ifndef MLEDIT_H #define MLEDIT_H -#include <qmultilineedit.h> +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -class MLEditWrap : public QMultiLineEdit +#ifdef USE_KDE +# include <kdeversion.h> +# if KDE_IS_VERSION(3, 1, 0) +# define MLEDIT_USE_KTEXTEDIT 1 +# endif +#endif + +// Since moc doesn't understand preprocessor directives we use this wrapper class, +// instead of inheriting directly from (K|Q)TextEdit, to avoid syntax errors. +#ifdef MLEDIT_USE_KTEXTEDIT +# include <ktextedit.h> + class MLEditWrapBase : public KTextEdit + { + public: + MLEditWrapBase(QWidget *parent, const char *name) : KTextEdit(parent, name) {} + }; +#else +# include <qtextedit.h> + class MLEditWrapBase : public QTextEdit + { + public: + MLEditWrapBase(QWidget *parent, const char *name) : QTextEdit(parent, name) {} + }; +#endif + +class MLEditWrap : public MLEditWrapBase { Q_OBJECT public: @@ -14,22 +60,30 @@ void append(const QString& s); void GotoEnd(); - using QMultiLineEdit::newLine; // make newLine() public - void setBackground(const QColor&); void setForeground(const QColor&); + void setCheckSpellingEnabled(bool check); + bool checkSpellingEnabled() const; + static QFont *editFont; protected: - bool m_bDoQuotes; - virtual void paintCell(QPainter *p, int row, int col); - virtual void keyPressEvent( QKeyEvent * ); - virtual void setCellWidth ( int ); - bool focusNextPrevChild( bool n); + virtual void keyPressEvent(QKeyEvent *e); + virtual QPopupMenu *createPopupMenu(const QPoint& pos); +public slots: + void setText(const QString& text); + virtual void setText(const QString& text, const QString& context); + +private slots: + void slotToggleAllowTab(); + signals: void signal_CtrlEnterPressed(); + +private: + bool m_fixSetTextNewlines; }; #endif Modified: trunk/qt-gui/src/outputwin.cpp =================================================================== --- trunk/qt-gui/src/outputwin.cpp 2006-07-15 14:27:46 UTC (rev 4530) +++ trunk/qt-gui/src/outputwin.cpp 2006-07-16 21:11:43 UTC (rev 4531) @@ -100,10 +100,10 @@ outputBox->GotoEnd(); // hardcoded limit, maybe should be user configurable? - if (outputBox->numLines() > 564) { - int todo = outputBox->numLines() - 500; + if (outputBox->paragraphs() > 564) { + int todo = outputBox->paragraphs() - 500; for (int i = 0; i < todo; ++i) - outputBox->removeLine(0); + outputBox->removeParagraph(0); } /* The next call will block, so we need to clear the log so that processing Modified: trunk/qt-gui/src/usereventdlg.cpp =================================================================== --- trunk/qt-gui/src/usereventdlg.cpp 2006-07-15 14:27:46 UTC (rev 4530) +++ trunk/qt-gui/src/usereventdlg.cpp 2006-07-16 21:11:43 UTC (rev 4531) @@ -91,6 +91,7 @@ #include "xpm/chatChangeBg.xpm" #include "xpm/smile.xpm" #include "support.h" +#include "mledit.h" #include <X11/Xlib.h> #include <X11/Xutil.h> @@ -1779,6 +1780,7 @@ } mleSend = new MLEditWrap(true, splView, true); + mleSend->setCheckSpellingEnabled(mainwin->m_bCheckSpellingEnabled); mleSend->installEventFilter(this); // Enables send with enter if (mainwin->m_bMsgChatView) @@ -1815,7 +1817,7 @@ if (isEnter) { if (key->state() & ControlButton) - mleSend->newLine(); + mleSend->insert("\n"); else btnSend->animateClick(); return true; // filter the event out @@ -2121,7 +2123,7 @@ if (e->mleSend && mleSend) { e->mleSend->setText(mleSend->text()); - e->mleSend->setEdited(e->mleSend->length()); + e->mleSend->setModified(e->mleSend->length()); } if (e->mleHistory && mleHistory){ e->mleHistory->setText(mleHistory->text()); @@ -2284,7 +2286,7 @@ if(!mleSend) return; mleSend->setText(txt); mleSend->GotoEnd(); - mleSend->setEdited(false); + mleSend->setModified(false); } @@ -2598,6 +2600,7 @@ // the window, then the new events will stay there slot_ClearNewEvents(); } + mainwin->m_bCheckSpellingEnabled = mleSend->checkSpellingEnabled(); #if QT_VERSION >= 300 if (mainwin->userEventTabDlg && mainwin->userEventTabDlg->tabExists(this)) @@ -2744,7 +2747,7 @@ if (icqEventTag != 0) return; - if(!mleSend->edited() && + if(!mleSend->isModified() && !QueryUser(this, tr("You didn't edit the message.\n" "Do you really want to send it?"), tr("&Yes"), tr("&No"))) return; @@ -3497,7 +3500,7 @@ if (icqEventTag != 0) return; - if(!mleSend->edited() && + if(!mleSend->isModified() && !QueryUser(this, tr("You didn't edit the SMS.\n" "Do you really want to send it?"), tr("&Yes"), tr("&No"))) return; |