Quassel now respects the difference between the clipboard and the X11 selection, and won't
put stuff into the clipboard without a) Ctrl+C or b) the new shiny context menu in ChatView.
This means that just selecting stuff won't overwrite your clipboard on Win and Mac, and on X11
only if your system is configured that way. Oh, and we have a context menu now, and Ctrl+C works ;-)
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+#include <QLayout>
+#include <QKeyEvent>
+#include <QScrollBar>
+
+#include "action.h"
+#include "actioncollection.h"
#include "bufferwidget.h"
#include "chatview.h"
#include "chatviewsearchbar.h"
#include "chatviewsearchcontroller.h"
#include "bufferwidget.h"
#include "chatview.h"
#include "chatviewsearchbar.h"
#include "chatviewsearchcontroller.h"
-
-#include "action.h"
-#include "actioncollection.h"
-#include <QLayout>
-#include <QKeyEvent>
-#include <QScrollBar>
BufferWidget::BufferWidget(QWidget *parent)
: AbstractBufferContainer(parent),
BufferWidget::BufferWidget(QWidget *parent)
: AbstractBufferContainer(parent),
connect(_chatViewSearchController, SIGNAL(newCurrentHighlight(QGraphicsItem *)),
this, SLOT(scrollToHighlight(QGraphicsItem *)));
connect(_chatViewSearchController, SIGNAL(newCurrentHighlight(QGraphicsItem *)),
this, SLOT(scrollToHighlight(QGraphicsItem *)));
ActionCollection *coll = QtUi::actionCollection();
Action *zoomChatview = coll->add<Action>("ZoomChatView");
ActionCollection *coll = QtUi::actionCollection();
Action *zoomChatview = coll->add<Action>("ZoomChatView");
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
+ // Intercept copy key presses
+ if(keyEvent == QKeySequence::Copy) {
+ InputLine *inputLine = qobject_cast<InputLine *>(watched);
+ if(!inputLine)
+ return false;
+ if(inputLine->hasSelectedText())
+ return false;
+ ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
+ if(view)
+ view->scene()->selectionToClipboard();
+ return true;
+ }
+
int direction = 1;
switch(keyEvent->key()) {
case Qt::Key_PageUp:
int direction = 1;
switch(keyEvent->key()) {
case Qt::Key_PageUp:
void ChatItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
if(_selectionMode != NoSelection && !event->buttons() & Qt::LeftButton) {
void ChatItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
if(_selectionMode != NoSelection && !event->buttons() & Qt::LeftButton) {
- QString selection
- = data(MessageModel::DisplayRole).toString().mid(qMin(_selectionStart, _selectionEnd), qAbs(_selectionStart - _selectionEnd));
- chatScene()->putToClipboard(selection);
+ chatScene()->selectionToClipboard(QClipboard::Selection);
event->accept();
} else
event->ignore();
event->accept();
} else
event->ignore();
void ContentsChatItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
qint16 idx = posToCursor(event->pos());
for(int i = 0; i < privateData()->clickables.count(); i++) {
void ContentsChatItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
qint16 idx = posToCursor(event->pos());
for(int i = 0; i < privateData()->clickables.count(); i++) {
void ContentsChatItem::showWebPreview(const Clickable &click) {
#ifndef HAVE_WEBKIT
void ContentsChatItem::showWebPreview(const Clickable &click) {
#ifndef HAVE_WEBKIT
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
- virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
+ //virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
virtual void handleClick(const QPointF &pos, ChatScene::ClickMode clickMode);
virtual void handleClick(const QPointF &pos, ChatScene::ClickMode clickMode);
#include <QClipboard>
#include <QDrag>
#include <QGraphicsSceneMouseEvent>
#include <QClipboard>
#include <QDrag>
#include <QGraphicsSceneMouseEvent>
#include <QPersistentModelIndex>
#include <QWebView>
#include <QPersistentModelIndex>
#include <QWebView>
#include "client.h"
#include "clientbacklogmanager.h"
#include "columnhandleitem.h"
#include "client.h"
#include "clientbacklogmanager.h"
#include "columnhandleitem.h"
#include "messagefilter.h"
#include "qtui.h"
#include "qtuistyle.h"
#include "messagefilter.h"
#include "qtui.h"
#include "qtuistyle.h"
/******** MOUSE HANDLING **************************************************************************/
/******** MOUSE HANDLING **************************************************************************/
+void ChatScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
+ QPointF pos = event->scenePos();
+ QMenu menu;
+
+ if(isPosOverSelection(pos))
+ menu.addAction(SmallIcon("edit-copy"), tr("Copy Selection"),
+ this, SLOT(selectionToClipboard()),
+ QKeySequence::Copy);
+
+ menu.exec(event->screenPos());
+
+}
+
void ChatScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
if(event->buttons() == Qt::LeftButton) {
if(!_clickHandled && (event->scenePos() - _clickPos).toPoint().manhattanLength() >= QApplication::startDragDistance()) {
void ChatScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
if(event->buttons() == Qt::LeftButton) {
if(!_clickHandled && (event->scenePos() - _clickPos).toPoint().manhattanLength() >= QApplication::startDragDistance()) {
} else {
// no click -> drag or selection move
if(isGloballySelecting()) {
} else {
// no click -> drag or selection move
if(isGloballySelecting()) {
- putToClipboard(selection());
+ selectionToClipboard(QClipboard::Selection);
_isSelecting = false;
event->accept();
return;
_isSelecting = false;
event->accept();
return;
chatItem->handleClick(chatItem->mapFromScene(scenePos), _clickMode);
}
_clickHandled = true;
chatItem->handleClick(chatItem->mapFromScene(scenePos), _clickMode);
}
_clickHandled = true;
- } else if(button == Qt::RightButton) {
- // TODO: context menu
-
/******** SELECTIONS ******************************************************************************/
/******** 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;
+
+ switch(mode) {
+ case QClipboard::Clipboard:
+ QApplication::clipboard()->setText(selection());
+ break;
+ case QClipboard::Selection:
+ if(QApplication::clipboard()->supportsSelection())
+ QApplication::clipboard()->setText(selection(), QClipboard::Selection);
+ break;
+ default:
+ break;
+ };
}
//!\brief Convert current selection to human-readable string.
}
//!\brief Convert current selection to human-readable string.
+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++)
void ChatScene::clearGlobalSelection() {
if(hasGlobalSelection()) {
for(int l = qMin(_selectionStart, _selectionEnd); l <= qMax(_selectionStart, _selectionEnd); l++)
#define CHATSCENE_H_
#include <QAbstractItemModel>
#define CHATSCENE_H_
#include <QAbstractItemModel>
#include <QGraphicsItem>
#include <QGraphicsScene>
#include <QSet>
#include <QGraphicsItem>
#include <QGraphicsScene>
#include <QSet>
inline void setSenderCutoffMode(CutoffMode mode) { _cutoffMode = mode; }
QString selection() const;
inline void setSenderCutoffMode(CutoffMode mode) { _cutoffMode = mode; }
QString selection() const;
- inline bool hasGlobalSelection() const { return _selectionStart >= 0; }
- inline bool isGloballySelecting() const { return _isSelecting; }
+ bool hasSelection() const;
+ bool hasGlobalSelection() const;
bool isPosOverSelection(const QPointF &) const;
bool isPosOverSelection(const QPointF &) const;
+ bool isGloballySelecting() const;
void initiateDrag(QWidget *source);
bool isScrollingAllowed() const;
void initiateDrag(QWidget *source);
bool isScrollingAllowed() const;
void startGlobalSelection(ChatItem *item, const QPointF &itemPos);
void clearGlobalSelection();
void clearSelection();
void startGlobalSelection(ChatItem *item, const QPointF &itemPos);
void clearGlobalSelection();
void clearSelection();
-
- void putToClipboard(const QString &);
+ void selectionToClipboard(QClipboard::Mode = QClipboard::Clipboard);
void mouseMoveWhileSelecting(const QPointF &scenePos);
protected:
void mouseMoveWhileSelecting(const QPointF &scenePos);
protected:
+ virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
***************************************************************************/
#include "inputline.h"
***************************************************************************/
#include "inputline.h"
#include "tabcompleter.h"
InputLine::InputLine(QWidget *parent)
#include "tabcompleter.h"
InputLine::InputLine(QWidget *parent)
event->accept();
addToHistory(text(), true);
event->accept();
addToHistory(text(), true);
if(idx > 0) {
idx--;
showHistoryEntry();
}
break;
if(idx > 0) {
idx--;
showHistoryEntry();
}
break;
case Qt::Key_Down:
event->accept();
addToHistory(text(), true);
case Qt::Key_Down:
event->accept();
addToHistory(text(), true);
if(idx < history.count()) {
idx++;
if(idx < history.count() || tempHistory.contains(idx)) // tempHistory might have an entry for idx == history.count() + 1
if(idx < history.count()) {
idx++;
if(idx < history.count() || tempHistory.contains(idx)) // tempHistory might have an entry for idx == history.count() + 1
case Qt::Key_Select: // for Qtopia
emit returnPressed();
case Qt::Key_Select: // for Qtopia
emit returnPressed();
return false;
Q_ASSERT(0 <= idx && idx <= history.count());
return false;
Q_ASSERT(0 <= idx && idx <= history.count());
if(history.isEmpty() || text != history[idx - (int)(idx == history.count())]) {
// if an entry of the history is changed, we remember it and show it again at this
// position until a line was actually sent
if(history.isEmpty() || text != history[idx - (int)(idx == history.count())]) {
// if an entry of the history is changed, we remember it and show it again at this
// position until a line was actually sent
lineSeperators << QString("\r\n")
<< QString('\n')
<< QString('\r');
lineSeperators << QString("\r\n")
<< QString('\n')
<< QString('\r');
QString lineSep;
foreach(QString seperator, lineSeperators) {
if(newText.contains(seperator)) {
QString lineSep;
foreach(QString seperator, lineSeperators) {
if(newText.contains(seperator)) {
if(lineSep.isEmpty())
return;
if(lineSep.isEmpty())
return;
if(newText.contains(lineSep)) {
clear();
QString line = newText.section(lineSep, 0, 0);
if(newText.contains(lineSep)) {
clear();
QString line = newText.section(lineSep, 0, 0);
public:
InputLine(QWidget *parent = 0);
~InputLine();
public:
InputLine(QWidget *parent = 0);
~InputLine();
protected:
// virtual bool event(QEvent *);
virtual void keyPressEvent(QKeyEvent * event);
protected:
// virtual bool event(QEvent *);
virtual void keyPressEvent(QKeyEvent * event);