X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatitem.cpp;h=3d2e065ebe33fd817833a3764896e1abac58b6fa;hp=585c958edb5a5f28edb4412ab55710865eacc97b;hb=952ac961af5ad09fa4105de5c938c147b260b3a0;hpb=6e277a228833579b9295d45ca7bd6c6f51aa1152 diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index 585c958e..3d2e065e 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -26,6 +26,8 @@ #include #include #include +#include + #include "chatitem.h" #include "chatlinemodel.h" @@ -263,7 +265,7 @@ void ChatItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { void SenderChatItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); - //painter->setClipRect(boundingRect()); // no idea why QGraphicsItem clipping won't work + painter->setClipRect(boundingRect()); // no idea why QGraphicsItem clipping won't work qreal layoutWidth = layout()->minimumWidth(); qreal offset = 0; if(chatScene()->senderCutoffMode() == ChatScene::CutoffLeft) @@ -276,8 +278,8 @@ void SenderChatItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *op if(layoutWidth > width()) { // Draw a nice gradient for longer items // Qt's text drawing with a gradient brush sucks, so we use an alpha-channeled pixmap instead - QPixmap pixmap(QSize(layout()->boundingRect().width(), layout()->boundingRect().height())); - pixmap.fill(QApplication::palette().brush(QPalette::Base).color()); + QPixmap pixmap(layout()->boundingRect().toRect().size()); + pixmap.fill(Qt::transparent); QPainter pixPainter(&pixmap); layout()->draw(&pixPainter, QPointF(qMax(offset, (qreal)0), 0), QVector() << selectFmt); pixPainter.end(); @@ -357,7 +359,7 @@ void ContentsChatItem::doLayout() { QList ContentsChatItem::findClickables() const { // For matching URLs static QString urlEnd("(?:>|[,.;:\"]*\\s|\\b|$)"); - static QString urlChars("(?:[,.;:]*[\\w\\-~@/?&=+$()!%#])"); + static QString urlChars("(?:[,.;:]*[\\w\\-~@/?&=+$()!%#*|{}\\[\\]])"); static QRegExp regExp[] = { // URL @@ -455,7 +457,7 @@ void ContentsChatItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { case Clickable::Url: if(!str.contains("://")) str = "http://" + str; - QDesktopServices::openUrl(str); + QDesktopServices::openUrl(QUrl::fromEncoded(str.toAscii())); break; case Clickable::Channel: // TODO join or whatever... @@ -508,8 +510,33 @@ void ContentsChatItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { event->accept(); } +void ContentsChatItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { + qint16 idx = posToCursor(event->pos()); + for(int i = 0; i < privateData()->clickables.count(); i++) { + Clickable click = privateData()->clickables.at(i); + if(idx >= click.start && idx < click.start + click.length) { + if(click.type == Clickable::Url) { + QMenu menu; + QAction *copyToClipboard = menu.addAction(QObject::tr("Copy to Clipboard")); + QAction *selected = menu.exec(event->screenPos()); + if(selected == copyToClipboard) { + QString url = data(ChatLineModel::DisplayRole).toString().mid(click.start, click.length); +# ifdef Q_WS_X11 + QApplication::clipboard()->setText(url, QClipboard::Selection); +# endif +//# else + QApplication::clipboard()->setText(url); +//# endif + } + } + } + } +} + void ContentsChatItem::showWebPreview(const Clickable &click) { -#ifdef HAVE_WEBKIT +#ifndef HAVE_WEBKIT + Q_UNUSED(click); +#else QTextLine line = layout()->lineForTextPosition(click.start); qreal x = line.cursorToX(click.start); qreal width = line.cursorToX(click.start + click.length) - x;