1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

change color for precise selection on focus-in/out

This commit is contained in:
krepa098 2015-02-03 10:33:46 +01:00
parent 8d7a32f4ec
commit 5c01f1585b
8 changed files with 41 additions and 5 deletions

View File

@ -109,6 +109,12 @@ void ChatLine::selectionCleared()
c->selectionCleared(); c->selectionCleared();
} }
void ChatLine::selectionFocusChanged(bool focusIn)
{
for(ChatLineContent* c : content)
c->selectionFocusChanged(focusIn);
}
int ChatLine::getColumnCount() int ChatLine::getColumnCount()
{ {
return content.size(); return content.size();

View File

@ -71,6 +71,7 @@ public:
void addToScene(QGraphicsScene* scene); void addToScene(QGraphicsScene* scene);
void setVisible(bool visible); void setVisible(bool visible);
void selectionCleared(); void selectionCleared();
void selectionFocusChanged(bool focusIn);
int getColumnCount(); int getColumnCount();
int getRow() const; int getRow() const;

View File

@ -57,6 +57,11 @@ void ChatLineContent::selectionDoubleClick(QPointF)
} }
void ChatLineContent::selectionFocusChanged(bool)
{
}
bool ChatLineContent::isOverSelection(QPointF) const bool ChatLineContent::isOverSelection(QPointF) const
{ {
return false; return false;

View File

@ -39,6 +39,7 @@ public:
virtual void selectionStarted(QPointF scenePos); virtual void selectionStarted(QPointF scenePos);
virtual void selectionCleared(); virtual void selectionCleared();
virtual void selectionDoubleClick(QPointF scenePos); virtual void selectionDoubleClick(QPointF scenePos);
virtual void selectionFocusChanged(bool focusIn);
virtual bool isOverSelection(QPointF scenePos) const; virtual bool isOverSelection(QPointF scenePos) const;
virtual QString getSelectedText() const; virtual QString getSelectedText() const;

View File

@ -747,11 +747,25 @@ void ChatLog::showEvent(QShowEvent*)
void ChatLog::focusInEvent(QFocusEvent* ev) void ChatLog::focusInEvent(QFocusEvent* ev)
{ {
QGraphicsView::focusInEvent(ev); QGraphicsView::focusInEvent(ev);
if(selectionMode != None)
{
selGraphItem->setBrush(QBrush(selectionRectColor)); selGraphItem->setBrush(QBrush(selectionRectColor));
for(int i=selFirstRow; i<=selLastRow; ++i)
lines[i]->selectionFocusChanged(true);
}
} }
void ChatLog::focusOutEvent(QFocusEvent* ev) void ChatLog::focusOutEvent(QFocusEvent* ev)
{ {
QGraphicsView::focusOutEvent(ev); QGraphicsView::focusOutEvent(ev);
if(selectionMode != None)
{
selGraphItem->setBrush(QBrush(selectionRectColor.lighter(120))); selGraphItem->setBrush(QBrush(selectionRectColor.lighter(120)));
for(int i=selFirstRow; i<=selLastRow; ++i)
lines[i]->selectionFocusChanged(false);
}
} }

View File

@ -120,7 +120,7 @@ private:
int selClickedCol = -1; int selClickedCol = -1;
int selFirstRow = -1; int selFirstRow = -1;
int selLastRow = -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; SelectionMode selectionMode = None;
QPointF clickPos; QPointF clickPos;
QGraphicsRectItem* selGraphItem = nullptr; QGraphicsRectItem* selGraphItem = nullptr;

View File

@ -126,6 +126,12 @@ void Text::selectionDoubleClick(QPointF scenePos)
update(); update();
} }
void Text::selectionFocusChanged(bool focusIn)
{
selectionHasFocus = focusIn;
update();
}
bool Text::isOverSelection(QPointF scenePos) const bool Text::isOverSelection(QPointF scenePos) const
{ {
int cur = cursorFromPos(scenePos); int cur = cursorFromPos(scenePos);
@ -160,8 +166,9 @@ void Text::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWid
sel.cursor.setPosition(getSelectionEnd(), QTextCursor::KeepAnchor); sel.cursor.setPosition(getSelectionEnd(), QTextCursor::KeepAnchor);
} }
sel.format.setBackground(QApplication::palette().color(QPalette::Highlight)); const QColor selectionColor = QColor::fromRgbF(0.23, 0.68, 0.91);
sel.format.setForeground(QApplication::palette().color(QPalette::HighlightedText)); sel.format.setBackground(selectionColor.lighter(selectionHasFocus ? 100 : 160));
sel.format.setForeground(selectionHasFocus ? Qt::white : Qt::black);
ctx.selections.append(sel); ctx.selections.append(sel);
// draw text // draw text

View File

@ -39,6 +39,7 @@ public:
virtual void selectionStarted(QPointF scenePos) override; virtual void selectionStarted(QPointF scenePos) override;
virtual void selectionCleared() override; virtual void selectionCleared() override;
virtual void selectionDoubleClick(QPointF scenePos) override; virtual void selectionDoubleClick(QPointF scenePos) override;
virtual void selectionFocusChanged(bool focusIn) override;
virtual bool isOverSelection(QPointF scenePos) const override; virtual bool isOverSelection(QPointF scenePos) const override;
virtual QString getSelectedText() const override; virtual QString getSelectedText() const override;
@ -75,6 +76,7 @@ private:
bool keepInMemory = false; bool keepInMemory = false;
bool elide = false; bool elide = false;
bool dirty = false; bool dirty = false;
bool selectionHasFocus = true;
int selectionEnd = -1; int selectionEnd = -1;
int selectionAnchor = -1; int selectionAnchor = -1;
qreal ascent = 0.0; qreal ascent = 0.0;