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:
parent
8d7a32f4ec
commit
5c01f1585b
|
@ -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();
|
||||
|
|
|
@ -71,6 +71,7 @@ public:
|
|||
void addToScene(QGraphicsScene* scene);
|
||||
void setVisible(bool visible);
|
||||
void selectionCleared();
|
||||
void selectionFocusChanged(bool focusIn);
|
||||
|
||||
int getColumnCount();
|
||||
int getRow() const;
|
||||
|
|
|
@ -57,6 +57,11 @@ void ChatLineContent::selectionDoubleClick(QPointF)
|
|||
|
||||
}
|
||||
|
||||
void ChatLineContent::selectionFocusChanged(bool)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool ChatLineContent::isOverSelection(QPointF) const
|
||||
{
|
||||
return false;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -747,11 +747,25 @@ void ChatLog::showEvent(QShowEvent*)
|
|||
void ChatLog::focusInEvent(QFocusEvent* ev)
|
||||
{
|
||||
QGraphicsView::focusInEvent(ev);
|
||||
|
||||
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);
|
||||
|
||||
if(selectionMode != None)
|
||||
{
|
||||
selGraphItem->setBrush(QBrush(selectionRectColor.lighter(120)));
|
||||
|
||||
for(int i=selFirstRow; i<=selLastRow; ++i)
|
||||
lines[i]->selectionFocusChanged(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user