Changeset 4550

Show
Ignore:
Timestamp:
08/04/06 05:46:03 (2 years ago)
Author:
erijo
Message:

Implement the second part of #646 "When copying from a licq window,
the underlying text should be copied, not skipped just because licq
interprets it as an emoticon". Closes #646.

Also fixes an issue reported by Arne Schmitz where
text[space]:)[space]text would be replaced with text[space]:)text.
It looks like Qt removes a space after every img-tag. So the solution
is to add an extra space for Qt to remove.

Location:
trunk/qt-gui/src
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/qt-gui/src/emoticon.cpp

    r4545 r4550  
    3030#include <qdir.h> 
    3131#include <qdom.h> 
     32#include <qregexp.h> 
    3233#include <qstylesheet.h> 
    3334 
     
    457458          } 
    458459 
    459           const QString img = QString::fromLatin1("<img src=\"%1\" title=\"%2\" />").arg(emo.file).arg(emo.escapedSmiley); 
     460          const QString img = QString::fromLatin1("<img alt=\"%1\" src=\"%2\" > ").arg(emo.escapedSmiley).arg(emo.file); 
    460461//           qDebug(" Replacing '%s' with '%s'", message.mid(pos, emo.escapedSmiley.length()).latin1(), img.latin1()); 
    461462          message.replace(pos, emo.escapedSmiley.length(), img); 
     
    472473} 
    473474 
     475/** 
     476 * "unparse" the message, removing all <img> tags and replacing them with the smiley. 
     477 */ 
     478void CEmoticons::unparseMessage(QString &message) 
     479{ 
     480  const QRegExp imageAlt("<img alt=([^>]*) src=[^>]* >"); 
     481  message.replace(imageAlt, "\\1"); 
     482} 
     483 
    474484#include "emoticon.moc" 
  • trunk/qt-gui/src/emoticon.h

    r4545 r4550  
    8080    void parseMessage(QString &message, ParseMode mode) const; 
    8181 
     82    /// Replace all emoticons with their smiley 
     83    static void unparseMessage(QString &message); 
     84 
    8285  signals: 
    8386    void themeChanged(); 
    8487 
    8588  private: 
     89    CEmoticons(const CEmoticons&); 
     90    CEmoticons& operator=(const CEmoticons&); 
     91 
    8692    static CEmoticons *m_self; 
    8793 
  • trunk/qt-gui/src/mlview.cpp

    r4545 r4550  
    2828#include <qapplication.h> 
    2929#include <qclipboard.h> 
     30#include <qdragobject.h> 
     31#include <qmime.h> 
    3032#include <qpopupmenu.h> 
    3133#include <qregexp.h> 
     
    3537 
    3638MLView::MLView (QWidget* parent, const char *name) 
    37   : QTextBrowser(parent, name), m_handleLinks(true) 
     39  : QTextBrowser(parent, name), m_handleLinks(true), m_clipboardMode(-1) 
    3840{ 
    3941  setWordWrap(WidgetWidth); 
     
    179181    // and the selection clipboard (paste with middle mouse button). 
    180182    QClipboard *cb = QApplication::clipboard(); 
    181     cb->setText(m_url); 
     183    cb->setText(m_url, QClipboard::Clipboard); 
    182184    if (cb->supportsSelection()) 
     185      cb->setText(m_url, QClipboard::Selection); 
     186  } 
     187} 
     188 
     189/** @see MLView::copy() */ 
     190void MLView::slotClipboardSelectionChanged() 
     191{ 
     192  m_clipboardMode = QClipboard::Selection; 
     193} 
     194 
     195/** @see MLView::copy() */ 
     196void MLView::slotClipboardDataChanged() 
     197{ 
     198  m_clipboardMode = QClipboard::Clipboard; 
     199} 
     200 
     201/** 
     202 * After we have copied the text, we update the copy so that all emoticons are 
     203 * replaced with their respective smiley. 
     204 */ 
     205void MLView::copy() 
     206{ 
     207  m_clipboardMode = -1; 
     208 
     209  // We connect these so that we know which clipboard changed (selection or data) 
     210  connect(QApplication::clipboard(), SIGNAL(selectionChanged()), this, SLOT(slotClipboardSelectionChanged())); 
     211  connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(slotClipboardDataChanged())); 
     212 
     213  QTextBrowser::copy(); 
     214 
     215  disconnect(QApplication::clipboard(), SIGNAL(selectionChanged()), this, SLOT(slotClipboardSelectionChanged())); 
     216  disconnect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(slotClipboardDataChanged())); 
     217 
     218  // m_clipboardMode is set in one of slotClipboard{Selection,Data}Changed() 
     219  if (m_clipboardMode != -1) 
     220  { 
     221    // QTextEdit copies the text both as rich text and as regular text. 
     222    // We parse the rich text and then update the regular text. 
     223    QMimeSource *m = QApplication::clipboard()->data(static_cast<QClipboard::Mode>(m_clipboardMode)); 
     224    if (m->provides("application/x-qrichtext") && QTextDrag::canDecode(m)) 
    183225    { 
    184       bool enabled = cb->selectionModeEnabled(); 
    185       cb->setSelectionMode(!enabled); 
    186       cb->setText(m_url); 
    187       cb->setSelectionMode(enabled); 
     226      if (QTextDrag *drag = dynamic_cast<QTextDrag*>(m)) 
     227      { 
     228        QString text = QString::fromUtf8(m->encodedData("application/x-qrichtext").data()); 
     229 
     230        CEmoticons::unparseMessage(text); 
     231 
     232        const QRegExp newline("<br( /)?>"); 
     233        text.replace(newline, "\n"); 
     234 
     235        const QRegExp htmlTags("</?[^>]+>"); 
     236        text.remove(htmlTags); 
     237 
     238        text.replace("&lt;", "<"); 
     239        text.replace("&gt;", ">"); 
     240        text.replace("&amp;", "&"); 
     241 
     242        drag->setText(text); 
     243      } 
    188244    } 
    189245  } 
  • trunk/qt-gui/src/mlview.h

    r4537 r4550  
    4848public slots: 
    4949  virtual void setSource(const QString& name); 
     50  virtual void copy(); 
     51 
     52private slots: 
    5053  void slotCopyUrl(); 
     54  void slotClipboardSelectionChanged(); 
     55  void slotClipboardDataChanged(); 
    5156 
    5257private: 
    5358  bool m_handleLinks; 
    5459  QString m_url; 
     60  int m_clipboardMode; 
    5561 
    5662signals: