Put selection into clipboard - output format config and context menu to follow later
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 31 Jul 2008 23:05:20 +0000 (01:05 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 2 Aug 2008 13:17:11 +0000 (15:17 +0200)
src/qtui/chatscene.cpp
src/qtui/chatscene.h

index 0671365..8207248 100644 (file)
@@ -18,6 +18,8 @@
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
+#include <QApplication>
+#include <QClipboard>
 #include <QGraphicsSceneMouseEvent>
 #include <QPersistentModelIndex>
 
@@ -225,6 +227,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 +240,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;
+}
index 62a65f2..70605cc 100644 (file)
@@ -68,6 +68,7 @@ class ChatScene : public QGraphicsScene {
 
   private:
     void updateSelection(const QPointF &pos);
+    QString selectionToString() const;
 
     QString _idString;
     qreal _width, _height;