From 5c01f1585bb10cffb8ca6032efb41097028eb15f Mon Sep 17 00:00:00 2001 From: krepa098 Date: Tue, 3 Feb 2015 10:33:46 +0100 Subject: [PATCH] change color for precise selection on focus-in/out --- src/chatlog/chatline.cpp | 6 ++++++ src/chatlog/chatline.h | 1 + src/chatlog/chatlinecontent.cpp | 5 +++++ src/chatlog/chatlinecontent.h | 1 + src/chatlog/chatlog.cpp | 18 ++++++++++++++++-- src/chatlog/chatlog.h | 2 +- src/chatlog/content/text.cpp | 11 +++++++++-- src/chatlog/content/text.h | 2 ++ 8 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/chatlog/chatline.cpp b/src/chatlog/chatline.cpp index e7f506a81..4dff5f75e 100644 --- a/src/chatlog/chatline.cpp +++ b/src/chatlog/chatline.cpp @@ -109,6 +109,12 @@ void ChatLine::selectionCleared() c->selectionCleared(); } +void ChatLine::selectionFocusChanged(bool focusIn) +{ + for(ChatLineContent* c : content) + c->selectionFocusChanged(focusIn); +} + int ChatLine::getColumnCount() { return content.size(); diff --git a/src/chatlog/chatline.h b/src/chatlog/chatline.h index 842fb4b61..0f7405cff 100644 --- a/src/chatlog/chatline.h +++ b/src/chatlog/chatline.h @@ -71,6 +71,7 @@ public: void addToScene(QGraphicsScene* scene); void setVisible(bool visible); void selectionCleared(); + void selectionFocusChanged(bool focusIn); int getColumnCount(); int getRow() const; diff --git a/src/chatlog/chatlinecontent.cpp b/src/chatlog/chatlinecontent.cpp index 9b163d4fd..ad1ce2de0 100644 --- a/src/chatlog/chatlinecontent.cpp +++ b/src/chatlog/chatlinecontent.cpp @@ -57,6 +57,11 @@ void ChatLineContent::selectionDoubleClick(QPointF) } +void ChatLineContent::selectionFocusChanged(bool) +{ + +} + bool ChatLineContent::isOverSelection(QPointF) const { return false; diff --git a/src/chatlog/chatlinecontent.h b/src/chatlog/chatlinecontent.h index 674182185..49e21b611 100644 --- a/src/chatlog/chatlinecontent.h +++ b/src/chatlog/chatlinecontent.h @@ -39,6 +39,7 @@ public: virtual void selectionStarted(QPointF scenePos); virtual void selectionCleared(); virtual void selectionDoubleClick(QPointF scenePos); + virtual void selectionFocusChanged(bool focusIn); virtual bool isOverSelection(QPointF scenePos) const; virtual QString getSelectedText() const; diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 3f1e96a50..1cdc4fea3 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -747,11 +747,25 @@ void ChatLog::showEvent(QShowEvent*) void ChatLog::focusInEvent(QFocusEvent* ev) { QGraphicsView::focusInEvent(ev); - selGraphItem->setBrush(QBrush(selectionRectColor)); + + if(selectionMode != None) + { + selGraphItem->setBrush(QBrush(selectionRectColor)); + + for(int i=selFirstRow; i<=selLastRow; ++i) + lines[i]->selectionFocusChanged(true); + } } void ChatLog::focusOutEvent(QFocusEvent* ev) { QGraphicsView::focusOutEvent(ev); - selGraphItem->setBrush(QBrush(selectionRectColor.lighter(120))); + + if(selectionMode != None) + { + selGraphItem->setBrush(QBrush(selectionRectColor.lighter(120))); + + for(int i=selFirstRow; i<=selLastRow; ++i) + lines[i]->selectionFocusChanged(false); + } } diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index 837049903..ffc1bf876 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -120,7 +120,7 @@ private: int selClickedCol = -1; int selFirstRow = -1; int selLastRow = -1; - QColor selectionRectColor = QColor(166,225,255); + QColor selectionRectColor = QColor::fromRgbF(0.23, 0.68, 0.91).lighter(150); SelectionMode selectionMode = None; QPointF clickPos; QGraphicsRectItem* selGraphItem = nullptr; diff --git a/src/chatlog/content/text.cpp b/src/chatlog/content/text.cpp index ce58cf9f7..6119f6100 100644 --- a/src/chatlog/content/text.cpp +++ b/src/chatlog/content/text.cpp @@ -126,6 +126,12 @@ void Text::selectionDoubleClick(QPointF scenePos) update(); } +void Text::selectionFocusChanged(bool focusIn) +{ + selectionHasFocus = focusIn; + update(); +} + bool Text::isOverSelection(QPointF scenePos) const { int cur = cursorFromPos(scenePos); @@ -160,8 +166,9 @@ void Text::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWid sel.cursor.setPosition(getSelectionEnd(), QTextCursor::KeepAnchor); } - sel.format.setBackground(QApplication::palette().color(QPalette::Highlight)); - sel.format.setForeground(QApplication::palette().color(QPalette::HighlightedText)); + const QColor selectionColor = QColor::fromRgbF(0.23, 0.68, 0.91); + sel.format.setBackground(selectionColor.lighter(selectionHasFocus ? 100 : 160)); + sel.format.setForeground(selectionHasFocus ? Qt::white : Qt::black); ctx.selections.append(sel); // draw text diff --git a/src/chatlog/content/text.h b/src/chatlog/content/text.h index beaa1cecf..1f15107ac 100644 --- a/src/chatlog/content/text.h +++ b/src/chatlog/content/text.h @@ -39,6 +39,7 @@ public: virtual void selectionStarted(QPointF scenePos) override; virtual void selectionCleared() override; virtual void selectionDoubleClick(QPointF scenePos) override; + virtual void selectionFocusChanged(bool focusIn) override; virtual bool isOverSelection(QPointF scenePos) const override; virtual QString getSelectedText() const override; @@ -75,6 +76,7 @@ private: bool keepInMemory = false; bool elide = false; bool dirty = false; + bool selectionHasFocus = true; int selectionEnd = -1; int selectionAnchor = -1; qreal ascent = 0.0;