X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatscene.cpp;h=f85e34445f41f032037c0b4236ee14aaea9b2090;hp=313d80eb3c2806266e8ecb3fcccd17e2cb102c28;hb=aa2d0a85c3e04a99d46c05512165c20414a669ec;hpb=f64ded9b73ed4eb09d3e2c14cddc0ead1e269185 diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 313d80eb..f85e3444 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -29,9 +30,11 @@ #include "chatline.h" #include "chatlinemodelitem.h" #include "chatscene.h" +#include "chatview.h" #include "client.h" #include "clientbacklogmanager.h" #include "columnhandleitem.h" +#include "iconloader.h" #include "messagefilter.h" #include "qtui.h" #include "qtuistyle.h" @@ -549,7 +552,7 @@ bool ChatScene::isPosOverSelection(const QPointF &pos) const { if(hasGlobalSelection()) { int row = chatItem->row(); if(row >= qMin(_selectionStart, _selectionEnd) && row <= qMax(_selectionStart, _selectionEnd)) - return true; + return columnByScenePos(pos) >= _selectionMinCol; } else { return chatItem->isPosOverSelection(chatItem->mapFromScene(pos)); } @@ -567,6 +570,28 @@ bool ChatScene::isScrollingAllowed() const { /******** MOUSE HANDLING **************************************************************************/ +void ChatScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { + QPointF pos = event->scenePos(); + QMenu menu; + + // zoom actions and similar + chatView()->addActionsToMenu(&menu, pos); + menu.addSeparator(); + + if(isPosOverSelection(pos)) + menu.addAction(SmallIcon("edit-copy"), tr("Copy Selection"), + this, SLOT(selectionToClipboard()), + QKeySequence::Copy); + + // item-specific options (select link etc) + ChatItem *item = chatItemAt(pos); + if(item) + item->addActionsToMenu(&menu, item->mapFromScene(pos)); + + menu.exec(event->screenPos()); + +} + void ChatScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if(event->buttons() == Qt::LeftButton) { if(!_clickHandled && (event->scenePos() - _clickPos).toPoint().manhattanLength() >= QApplication::startDragDistance()) { @@ -623,14 +648,15 @@ void ChatScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if(!event->buttons() & Qt::LeftButton) { _leftButtonPressed = false; if(_clickMode != NoClick) { - clearSelection(); + if(_clickMode == SingleClick) + clearSelection(); event->accept(); if(!_clickTimer.isActive()) handleClick(Qt::LeftButton, _clickPos); } else { // no click -> drag or selection move if(isGloballySelecting()) { - putToClipboard(selection()); + selectionToClipboard(QClipboard::Selection); _isSelecting = false; event->accept(); return; @@ -655,9 +681,6 @@ void ChatScene::handleClick(Qt::MouseButton button, const QPointF &scenePos) { chatItem->handleClick(chatItem->mapFromScene(scenePos), _clickMode); } _clickHandled = true; - } else if(button == Qt::RightButton) { - // TODO: context menu - } } @@ -672,14 +695,25 @@ void ChatScene::initiateDrag(QWidget *source) { /******** SELECTIONS ******************************************************************************/ -void ChatScene::putToClipboard(const QString &selection) { - // TODO Configure clipboards -# ifdef Q_WS_X11 - QApplication::clipboard()->setText(selection, QClipboard::Selection); -# endif -//# else - QApplication::clipboard()->setText(selection); -//# endif +void ChatScene::selectionToClipboard(QClipboard::Mode mode) { + if(!hasSelection()) + return; + + stringToClipboard(selection(), mode); +} + +void ChatScene::stringToClipboard(const QString &str, QClipboard::Mode mode) { + switch(mode) { + case QClipboard::Clipboard: + QApplication::clipboard()->setText(str); + break; + case QClipboard::Selection: + if(QApplication::clipboard()->supportsSelection()) + QApplication::clipboard()->setText(str, QClipboard::Selection); + break; + default: + break; + }; } //!\brief Convert current selection to human-readable string. @@ -706,6 +740,18 @@ QString ChatScene::selection() const { return QString(); } +bool ChatScene::hasSelection() const { + return hasGlobalSelection() || (selectingItem() && selectingItem()->hasSelection()); +} + +bool ChatScene::hasGlobalSelection() const { + return _selectionStart >= 0; +} + +bool ChatScene::isGloballySelecting() const { + return _isSelecting; +} + void ChatScene::clearGlobalSelection() { if(hasGlobalSelection()) { for(int l = qMin(_selectionStart, _selectionEnd); l <= qMax(_selectionStart, _selectionEnd); l++) @@ -730,7 +776,7 @@ void ChatScene::requestBacklog() { return; } -ChatLineModel::ColumnType ChatScene::columnByScenePos(qreal x) { +ChatLineModel::ColumnType ChatScene::columnByScenePos(qreal x) const { if(x < _firstColHandle->x()) return ChatLineModel::TimestampColumn; if(x < _secondColHandle->x()) @@ -739,7 +785,7 @@ ChatLineModel::ColumnType ChatScene::columnByScenePos(qreal x) { return ChatLineModel::ContentsColumn; } -int ChatScene::rowByScenePos(qreal y) { +int ChatScene::rowByScenePos(qreal y) const { // This is somewhat hacky... we look at the contents item that is at the given y position, since // it has the full height. From this item, we can then determine the row index and hence the ChatLine. // ChatItems cover their ChatLine, so we won't get to the latter directly.