X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fchatitem.h;h=b0afbfa1ba4327ff2515fb1fc805a86f81b6b642;hb=aa7841638c6537034102da959cad8c36853bf280;hp=3cb9c3d754dd2c4b440b7c6b8a85ebf4e3138ed5;hpb=eacb532f13295a30fa4366a6ff29d1168db84280;p=quassel.git diff --git a/src/qtui/chatitem.h b/src/qtui/chatitem.h index 3cb9c3d7..b0afbfa1 100644 --- a/src/qtui/chatitem.h +++ b/src/qtui/chatitem.h @@ -21,6 +21,7 @@ #ifndef CHATITEM_H_ #define CHATITEM_H_ +#include #include #include @@ -67,6 +68,7 @@ public: QList findWords(const QString &searchWord, Qt::CaseSensitivity caseSensitive); + virtual void addActionsToMenu(QMenu *menu, const QPointF &itemPos); virtual void handleClick(const QPointF &pos, ChatScene::ClickMode); protected: @@ -129,7 +131,7 @@ private: struct ChatItemPrivate { QTextLayout *layout; ChatItemPrivate(QTextLayout *l) : layout(l) {} - ~ChatItemPrivate() { + virtual ~ChatItemPrivate() { delete layout; } }; @@ -174,6 +176,8 @@ struct ContentsChatItemPrivate; //! A ChatItem for the contents column class ContentsChatItem : public ChatItem { + Q_DECLARE_TR_FUNCTIONS(ContentsChatItem); + public: ContentsChatItem(const qreal &width, const QPointF &pos, QGraphicsItem *parent); @@ -187,10 +191,11 @@ protected: virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); - virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); - virtual void handleClick(const QPointF &pos, ChatScene::ClickMode clickMode); + virtual void addActionsToMenu(QMenu *menu, const QPointF &itemPos); + virtual void copyLinkToClipboard(); + virtual QVector additionalFormats() const; virtual void doLayout(); @@ -198,6 +203,7 @@ protected: private: struct Clickable; + class ActionProxy; class WrapColumnFinder; inline ContentsChatItemPrivate *privateData() const; @@ -212,6 +218,9 @@ private: friend struct ContentsChatItemPrivate; QFontMetricsF *_fontMetrics; + + // we need a receiver for Action signals + static ActionProxy _actionProxy; }; struct ContentsChatItem::Clickable { @@ -236,6 +245,7 @@ struct ContentsChatItemPrivate : ChatItemPrivate { ContentsChatItem *contentsItem; QList clickables; ContentsChatItem::Clickable currentClickable; + ContentsChatItem::Clickable activeClickable; ContentsChatItemPrivate(QTextLayout *l, const QList &c, ContentsChatItem *parent) : ChatItemPrivate(l), contentsItem(parent), clickables(c) {} @@ -264,6 +274,28 @@ private: qreal choppedTrailing; }; +//! Acts as a proxy for Action signals targetted at a ContentsChatItem +/** Since a ChatItem is not a QObject, hence cannot receive signals, we use a static ActionProxy + * as a receiver instead. This avoids having to handle ChatItem actions (e.g. context menu entries) + * outside the ChatItem. + */ +class ContentsChatItem::ActionProxy : public QObject { + Q_OBJECT + +public slots: + inline void copyLinkToClipboard() { item()->copyLinkToClipboard(); } + +private: + /// Returns the ContentsChatItem that should receive the action event. + /** For efficiency reasons, values are not checked for validity. You gotta make sure that you set the data() member + * in the Action correctly. + * @return The ChatItem from which the sending Action originated + */ + inline ContentsChatItem *item() const { + return static_cast(qobject_cast(sender())->data().value()); + } +}; + /*************************************************************************************************/ // Avoid circular include deps