Clipboard will no longer be randomly overwritten with an empty string
authorManuel Nickschas <sputnick@quassel-irc.org>
Fri, 15 Aug 2008 12:56:14 +0000 (14:56 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Fri, 15 Aug 2008 12:56:14 +0000 (14:56 +0200)
src/qtui/chatitem.cpp
src/qtui/chatscene.cpp
src/qtui/chatscene.h

index 036a6e6..051151c 100644 (file)
@@ -208,7 +208,7 @@ void ChatItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
     if(_selectionMode == NoSelection) {
       chatScene()->setSelectingItem(this);  // removes earlier selection if exists
       _selectionStart = _selectionEnd = posToCursor(event->pos());
     if(_selectionMode == NoSelection) {
       chatScene()->setSelectingItem(this);  // removes earlier selection if exists
       _selectionStart = _selectionEnd = posToCursor(event->pos());
-      _selectionMode = PartialSelection;
+      //_selectionMode = PartialSelection;
     } else {
       chatScene()->setSelectingItem(0);
       _selectionMode = NoSelection;
     } else {
       chatScene()->setSelectingItem(0);
       _selectionMode = NoSelection;
@@ -226,6 +226,8 @@ void ChatItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
       qint16 end = posToCursor(event->pos());
       if(end != _selectionEnd) {
         _selectionEnd = end;
       qint16 end = posToCursor(event->pos());
       if(end != _selectionEnd) {
         _selectionEnd = end;
+        if(_selectionStart != _selectionEnd) _selectionMode = PartialSelection;
+        else _selectionMode = NoSelection;
         update();
       }
     } else {
         update();
       }
     } else {
@@ -243,7 +245,7 @@ void ChatItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
     _selectionEnd = posToCursor(event->pos());
     QString selection
         = data(MessageModel::DisplayRole).toString().mid(qMin(_selectionStart, _selectionEnd), qAbs(_selectionStart - _selectionEnd));
     _selectionEnd = posToCursor(event->pos());
     QString selection
         = data(MessageModel::DisplayRole).toString().mid(qMin(_selectionStart, _selectionEnd), qAbs(_selectionStart - _selectionEnd));
-    QApplication::clipboard()->setText(selection, QClipboard::Clipboard);  // TODO configure where selections should go
+    chatScene()->putToClipboard(selection);
     event->accept();
   } else {
     event->ignore();
     event->accept();
   } else {
     event->ignore();
index e04784c..cb06e74 100644 (file)
@@ -266,12 +266,7 @@ void ChatScene::mousePressEvent(QGraphicsSceneMouseEvent *event) {
 
 void ChatScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
   if(_isSelecting && !event->buttons() & Qt::LeftButton) {
 
 void ChatScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
   if(_isSelecting && !event->buttons() & Qt::LeftButton) {
-#   ifdef Q_WS_X11
-      QApplication::clipboard()->setText(selectionToString(), QClipboard::Selection);
-#   endif
-//# else
-      QApplication::clipboard()->setText(selectionToString());
-//# endif
+    putToClipboard(selectionToString());
     _isSelecting = false;
     event->accept();
   } else {
     _isSelecting = false;
     event->accept();
   } else {
@@ -279,6 +274,16 @@ void ChatScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
   }
 }
 
   }
 }
 
+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
+}
+
 //!\brief Convert current selection to human-readable string.
 QString ChatScene::selectionToString() const {
   //TODO Make selection format configurable!
 //!\brief Convert current selection to human-readable string.
 QString ChatScene::selectionToString() const {
   //TODO Make selection format configurable!
index 1dae1e2..c0231f7 100644 (file)
@@ -58,6 +58,7 @@ class ChatScene : public QGraphicsScene {
     void setSelectingItem(ChatItem *item);
     ChatItem *selectingItem() const { return _selectingItem; }
     void startGlobalSelection(ChatItem *item, const QPointF &itemPos);
     void setSelectingItem(ChatItem *item);
     ChatItem *selectingItem() const { return _selectingItem; }
     void startGlobalSelection(ChatItem *item, const QPointF &itemPos);
+    void putToClipboard(const QString &);
 
     void setIsFetchingBacklog(bool);
     inline void setBufferForBacklogFetching(BufferId buffer);
 
     void setIsFetchingBacklog(bool);
     inline void setBufferForBacklogFetching(BufferId buffer);