-ChatItem::WrapColumnFinder::WrapColumnFinder(ChatItem *_item) : item(_item) {
- wrapList = item->data(ChatLineModel::WrapListRole).value<ChatLineModel::WrapList>();
- wordidx = 0;
- layout = 0;
- lastwrapcol = 0;
- lastwrappos = 0;
- w = 0;
-}
-
-ChatItem::WrapColumnFinder::~WrapColumnFinder() {
- delete layout;
-}
-
-qint16 ChatItem::WrapColumnFinder::nextWrapColumn() {
- while(wordidx < wrapList.count()) {
- w += wrapList.at(wordidx).width;
- if(w >= item->width()) {
- if(lastwrapcol >= wrapList.at(wordidx).start) {
- // first word, and it doesn't fit
- if(!line.isValid()) {
- layout = item->createLayout(QTextOption::NoWrap);
- layout->beginLayout();
- line = layout->createLine();
- line.setLineWidth(item->width());
- layout->endLayout();
- }
- int idx = line.xToCursor(lastwrappos + item->width(), QTextLine::CursorOnCharacter);
- qreal x = line.cursorToX(idx, QTextLine::Trailing);
- w = w - wrapList.at(wordidx).width - (x - lastwrappos);
- lastwrappos = x;
- lastwrapcol = idx;
- return idx;
+void ContentsChatItem::handleClick(const QPointF &pos, ChatScene::ClickMode clickMode) {
+ if(clickMode == ChatScene::SingleClick) {
+ qint16 idx = posToCursor(pos);
+ Clickable foo = privateData()->clickables.atCursorPos(idx);
+ if(foo.isValid()) {
+ NetworkId networkId = Client::networkModel()->networkId(data(MessageModel::BufferIdRole).value<BufferId>());
+ QString text = data(ChatLineModel::DisplayRole).toString();
+ foo.activate(networkId, text);
+ }
+ } else if(clickMode == ChatScene::DoubleClick) {
+ chatScene()->setSelectingItem(this);
+ setSelectionMode(PartialSelection);
+ Clickable click = clickableAt(pos);
+ if(click.isValid()) {
+ setSelectionStart(click.start());
+ setSelectionEnd(click.start() + click.length());
+ } else {
+ // find word boundary
+ QString str = data(ChatLineModel::DisplayRole).toString();
+ qint16 cursor = posToCursor(pos);
+ qint16 start = str.lastIndexOf(QRegExp("\\W"), cursor) + 1;
+ qint16 end = qMin(str.indexOf(QRegExp("\\W"), cursor), str.length());
+ if(end < 0) end = str.length();
+ setSelectionStart(start);
+ setSelectionEnd(end);
+ }
+ chatLine()->update();
+ } else if(clickMode == ChatScene::TripleClick) {
+ setSelection(PartialSelection, 0, data(ChatLineModel::DisplayRole).toString().length());
+ }
+ ChatItem::handleClick(pos, clickMode);
+}
+
+void ContentsChatItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
+ // mouse move events always mean we're not hovering anymore...
+ endHoverMode();
+ ChatItem::mouseMoveEvent(event);
+}
+
+void ContentsChatItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
+ endHoverMode();
+ event->accept();
+}
+
+void ContentsChatItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
+ bool onClickable = false;
+ Clickable click = clickableAt(event->pos());
+ if(click.isValid()) {
+ if(click.type() == Clickable::Url) {
+ onClickable = true;
+ showWebPreview(click);
+ } else if(click.type() == Clickable::Channel) {
+ QString name = data(ChatLineModel::DisplayRole).toString().mid(click.start(), click.length());
+ // don't make clickable if it's our own name
+ BufferId myId = data(MessageModel::BufferIdRole).value<BufferId>();
+ if(Client::networkModel()->bufferName(myId) != name)
+ onClickable = true;
+ }
+ if(onClickable) {
+ chatLine()->setCursor(Qt::PointingHandCursor);
+ privateData()->currentClickable = click;
+ chatLine()->update();
+ return;
+ }
+ }
+ if(!onClickable) endHoverMode();
+ event->accept();
+}
+
+void ContentsChatItem::addActionsToMenu(QMenu *menu, const QPointF &pos) {
+ if(privateData()->currentClickable.isValid()) {
+ Clickable click = privateData()->currentClickable;
+ switch(click.type()) {
+ case Clickable::Url:
+ privateData()->activeClickable = click;
+ menu->addAction(SmallIcon("edit-copy"), tr("Copy Link Address"),
+ &_actionProxy, SLOT(copyLinkToClipboard()))->setData(QVariant::fromValue<void *>(this));
+ break;
+ case Clickable::Channel: {
+ // Hide existing menu actions, they confuse us when right-clicking on a clickable
+ foreach(QAction *action, menu->actions())
+ action->setVisible(false);
+ QString name = data(ChatLineModel::DisplayRole).toString().mid(click.start(), click.length());
+ GraphicalUi::contextMenuActionProvider()->addActions(menu, chatScene()->filter(), data(MessageModel::BufferIdRole).value<BufferId>(), name);
+ break;