From 8d7a32f4ec014ebe2d723519a540ce0db6fc498f Mon Sep 17 00:00:00 2001 From: krepa098 Date: Mon, 2 Feb 2015 18:11:29 +0100 Subject: [PATCH] selection rect: change color on focus-in/out, action cleanup --- src/chatlog/chatlog.cpp | 24 ++++++++++++++++++++---- src/chatlog/chatlog.h | 8 ++++++-- src/widget/form/genericchatform.cpp | 3 --- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 0c636c4ee..3f1e96a50 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -56,15 +56,15 @@ ChatLog::ChatLog(QWidget* parent) setBackgroundBrush(QBrush(Qt::white, Qt::SolidPattern)); // The selection rect for multi-line selection - const QColor selGraphColor = QColor(166,225,255); - selGraphItem = scene->addRect(0,0,0,0,selGraphColor.darker(120),selGraphColor); + selGraphItem = scene->addRect(0,0,0,0,selectionRectColor.darker(120),selectionRectColor); selGraphItem->setZValue(-1.0); // behind all other items // copy action (ie. Ctrl+C) - QAction* copyAction = new QAction(this); + copyAction = new QAction(this); copyAction->setIcon(QIcon::fromTheme("edit-copy")); copyAction->setText(tr("Copy")); copyAction->setShortcut(QKeySequence::Copy); + copyAction->setEnabled(false); connect(copyAction, &QAction::triggered, this, [this](bool) { copySelectedText(); }); addAction(copyAction); @@ -106,6 +106,7 @@ void ChatLog::clearSelection() selClickedRow = -1; selectionMode = None; + copyAction->setEnabled(false); updateMultiSelectionRect(); } @@ -213,6 +214,7 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev) content->selectionStarted(sceneClickPos); selectionMode = Precise; + copyAction->setEnabled(true); // ungrab mouse grabber if(scene->mouseGrabberItem()) @@ -225,6 +227,7 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev) selLastRow = selClickedRow; selectionMode = Multi; + copyAction->setEnabled(true); } } @@ -563,6 +566,7 @@ void ChatLog::selectAll() selFirstRow = 0; selLastRow = lines.size()-1; + copyAction->setEnabled(true); updateMultiSelectionRect(); } @@ -733,9 +737,21 @@ void ChatLog::onWorkerTimeout() } } -void ChatLog::showEvent(QShowEvent *) +void ChatLog::showEvent(QShowEvent*) { // Empty. // The default implementation calls centerOn - for some reason - causing // the scrollbar to move. } + +void ChatLog::focusInEvent(QFocusEvent* ev) +{ + QGraphicsView::focusInEvent(ev); + selGraphItem->setBrush(QBrush(selectionRectColor)); +} + +void ChatLog::focusOutEvent(QFocusEvent* ev) +{ + QGraphicsView::focusOutEvent(ev); + selGraphItem->setBrush(QBrush(selectionRectColor.lighter(120))); +} diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index 611900fbc..837049903 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -79,8 +79,10 @@ protected: virtual void mouseReleaseEvent(QMouseEvent* ev); virtual void mouseMoveEvent(QMouseEvent* ev); virtual void scrollContentsBy(int dx, int dy); - virtual void resizeEvent(QResizeEvent *ev); - virtual void showEvent(QShowEvent *); + virtual void resizeEvent(QResizeEvent* ev); + virtual void showEvent(QShowEvent*); + virtual void focusInEvent(QFocusEvent* ev); + virtual void focusOutEvent(QFocusEvent* ev); void updateMultiSelectionRect(); void updateTypingNotification(); @@ -105,6 +107,7 @@ private: Down, }; + QAction* copyAction = nullptr; QGraphicsScene* scene = nullptr; QGraphicsScene* busyScene = nullptr; QVector lines; @@ -117,6 +120,7 @@ private: int selClickedCol = -1; int selFirstRow = -1; int selLastRow = -1; + QColor selectionRectColor = QColor(166,225,255); SelectionMode selectionMode = None; QPointF clickPos; QGraphicsRectItem* selGraphItem = nullptr; diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 77aba3d7e..de415fccd 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -200,9 +200,6 @@ void GenericChatForm::onChatContextMenuRequested(QPoint pos) QWidget* sender = (QWidget*)QObject::sender(); pos = sender->mapToGlobal(pos); - //copy action - menu.actions().first()->setEnabled(chatWidget->hasTextToBeCopied()); - menu.exec(pos); }