Changeset 4550
- Timestamp:
- 08/04/06 05:46:03 (2 years ago)
- Location:
- trunk/qt-gui/src
- Files:
-
- 4 modified
-
emoticon.cpp (modified) (3 diffs)
-
emoticon.h (modified) (1 diff)
-
mlview.cpp (modified) (3 diffs)
-
mlview.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/qt-gui/src/emoticon.cpp
r4545 r4550 30 30 #include <qdir.h> 31 31 #include <qdom.h> 32 #include <qregexp.h> 32 33 #include <qstylesheet.h> 33 34 … … 457 458 } 458 459 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); 460 461 // qDebug(" Replacing '%s' with '%s'", message.mid(pos, emo.escapedSmiley.length()).latin1(), img.latin1()); 461 462 message.replace(pos, emo.escapedSmiley.length(), img); … … 472 473 } 473 474 475 /** 476 * "unparse" the message, removing all <img> tags and replacing them with the smiley. 477 */ 478 void CEmoticons::unparseMessage(QString &message) 479 { 480 const QRegExp imageAlt("<img alt=([^>]*) src=[^>]* >"); 481 message.replace(imageAlt, "\\1"); 482 } 483 474 484 #include "emoticon.moc" -
trunk/qt-gui/src/emoticon.h
r4545 r4550 80 80 void parseMessage(QString &message, ParseMode mode) const; 81 81 82 /// Replace all emoticons with their smiley 83 static void unparseMessage(QString &message); 84 82 85 signals: 83 86 void themeChanged(); 84 87 85 88 private: 89 CEmoticons(const CEmoticons&); 90 CEmoticons& operator=(const CEmoticons&); 91 86 92 static CEmoticons *m_self; 87 93 -
trunk/qt-gui/src/mlview.cpp
r4545 r4550 28 28 #include <qapplication.h> 29 29 #include <qclipboard.h> 30 #include <qdragobject.h> 31 #include <qmime.h> 30 32 #include <qpopupmenu.h> 31 33 #include <qregexp.h> … … 35 37 36 38 MLView::MLView (QWidget* parent, const char *name) 37 : QTextBrowser(parent, name), m_handleLinks(true) 39 : QTextBrowser(parent, name), m_handleLinks(true), m_clipboardMode(-1) 38 40 { 39 41 setWordWrap(WidgetWidth); … … 179 181 // and the selection clipboard (paste with middle mouse button). 180 182 QClipboard *cb = QApplication::clipboard(); 181 cb->setText(m_url );183 cb->setText(m_url, QClipboard::Clipboard); 182 184 if (cb->supportsSelection()) 185 cb->setText(m_url, QClipboard::Selection); 186 } 187 } 188 189 /** @see MLView::copy() */ 190 void MLView::slotClipboardSelectionChanged() 191 { 192 m_clipboardMode = QClipboard::Selection; 193 } 194 195 /** @see MLView::copy() */ 196 void 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 */ 205 void 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)) 183 225 { 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("<", "<"); 239 text.replace(">", ">"); 240 text.replace("&", "&"); 241 242 drag->setText(text); 243 } 188 244 } 189 245 } -
trunk/qt-gui/src/mlview.h
r4537 r4550 48 48 public slots: 49 49 virtual void setSource(const QString& name); 50 virtual void copy(); 51 52 private slots: 50 53 void slotCopyUrl(); 54 void slotClipboardSelectionChanged(); 55 void slotClipboardDataChanged(); 51 56 52 57 private: 53 58 bool m_handleLinks; 54 59 QString m_url; 60 int m_clipboardMode; 55 61 56 62 signals:
