X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fchatscene.cpp;h=6dbe17109f9966be9b11ab4debe174c131b96d1b;hb=c55bd7dc80547563d8c9cc70d54aa3d24ff03166;hp=0671365254a13994d9e665288b8a1ada427543e6;hpb=8efabae6c310d17265eaeb03df43ffe8b555a52e;p=quassel.git diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 06713652..6dbe1710 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -18,6 +18,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include +#include #include #include @@ -43,6 +45,7 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, QObject connect(this, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(rectChanged(const QRectF &))); connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(rowsInserted(const QModelIndex &, int, int))); + connect(model, SIGNAL(modelAboutToBeReset()), this, SLOT(modelReset())); for(int i = 0; i < model->rowCount(); i++) { ChatLine *line = new ChatLine(model->index(i, 0)); _lines.append(line); @@ -74,7 +77,6 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, QObject ChatScene::~ChatScene() { - } void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) { @@ -104,6 +106,15 @@ void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) { } } +void ChatScene::modelReset() { + foreach(ChatLine *line, _lines) { + removeItem(line); + delete line; + } + _lines.clear(); + setSceneRect(QRectF(0, 0, _width, 0)); +} + void ChatScene::setWidth(qreal w) { _width = w; _height = 0; @@ -225,6 +236,12 @@ void ChatScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { void ChatScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if(_isSelecting) { +# ifdef Q_WS_X11 + QApplication::clipboard()->setText(selectionToString(), QClipboard::Selection); +# endif +//# else + QApplication::clipboard()->setText(selectionToString()); +//# endif _isSelecting = false; event->accept(); } else { @@ -232,3 +249,17 @@ void ChatScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { } } +//!\brief Convert current selection to human-readable string. +QString ChatScene::selectionToString() const { + //TODO Make selection format configurable! + if(!_isSelecting) return ""; + QString result; + for(int l = _selectionStart; l <= _selectionEnd; l++) { + if(_selectionMinCol == ChatLineModel::TimestampColumn) + result += _lines[l]->item(ChatLineModel::TimestampColumn)->data(MessageModel::DisplayRole).toString() + " "; + if(_selectionMinCol <= ChatLineModel::SenderColumn) + result += _lines[l]->item(ChatLineModel::SenderColumn)->data(MessageModel::DisplayRole).toString() + " "; + result += _lines[l]->item(ChatLineModel::ContentsColumn)->data(MessageModel::DisplayRole).toString() + "\n"; + } + return result; +}