| | 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)) |
| 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 | qDebug("'%s'", text.latin1()); |
| | 230 | |
| | 231 | const QRegExp imageAlt("<img alt=([^>]*) src=[^>]* >"); |
| | 232 | text.replace(imageAlt, "\\1"); |
| | 233 | |
| | 234 | const QRegExp newline("<br( /)?>"); |
| | 235 | text.replace(newline, "\n"); |
| | 236 | |
| | 237 | const QRegExp htmlTags("</?[^>]+>"); |
| | 238 | text.remove(htmlTags); |
| | 239 | |
| | 240 | text.replace("<", "<"); |
| | 241 | text.replace(">", ">"); |
| | 242 | text.replace("&", "&"); |
| | 243 | |
| | 244 | drag->setText(text); |
| | 245 | } |