mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
selection rect: change color on focus-in/out, action cleanup
This commit is contained in:
parent
39b2771b8d
commit
8d7a32f4ec
|
@ -56,15 +56,15 @@ ChatLog::ChatLog(QWidget* parent)
|
||||||
setBackgroundBrush(QBrush(Qt::white, Qt::SolidPattern));
|
setBackgroundBrush(QBrush(Qt::white, Qt::SolidPattern));
|
||||||
|
|
||||||
// The selection rect for multi-line selection
|
// The selection rect for multi-line selection
|
||||||
const QColor selGraphColor = QColor(166,225,255);
|
selGraphItem = scene->addRect(0,0,0,0,selectionRectColor.darker(120),selectionRectColor);
|
||||||
selGraphItem = scene->addRect(0,0,0,0,selGraphColor.darker(120),selGraphColor);
|
|
||||||
selGraphItem->setZValue(-1.0); // behind all other items
|
selGraphItem->setZValue(-1.0); // behind all other items
|
||||||
|
|
||||||
// copy action (ie. Ctrl+C)
|
// copy action (ie. Ctrl+C)
|
||||||
QAction* copyAction = new QAction(this);
|
copyAction = new QAction(this);
|
||||||
copyAction->setIcon(QIcon::fromTheme("edit-copy"));
|
copyAction->setIcon(QIcon::fromTheme("edit-copy"));
|
||||||
copyAction->setText(tr("Copy"));
|
copyAction->setText(tr("Copy"));
|
||||||
copyAction->setShortcut(QKeySequence::Copy);
|
copyAction->setShortcut(QKeySequence::Copy);
|
||||||
|
copyAction->setEnabled(false);
|
||||||
connect(copyAction, &QAction::triggered, this, [this](bool) { copySelectedText(); });
|
connect(copyAction, &QAction::triggered, this, [this](bool) { copySelectedText(); });
|
||||||
addAction(copyAction);
|
addAction(copyAction);
|
||||||
|
|
||||||
|
@ -106,6 +106,7 @@ void ChatLog::clearSelection()
|
||||||
selClickedRow = -1;
|
selClickedRow = -1;
|
||||||
|
|
||||||
selectionMode = None;
|
selectionMode = None;
|
||||||
|
copyAction->setEnabled(false);
|
||||||
|
|
||||||
updateMultiSelectionRect();
|
updateMultiSelectionRect();
|
||||||
}
|
}
|
||||||
|
@ -213,6 +214,7 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev)
|
||||||
content->selectionStarted(sceneClickPos);
|
content->selectionStarted(sceneClickPos);
|
||||||
|
|
||||||
selectionMode = Precise;
|
selectionMode = Precise;
|
||||||
|
copyAction->setEnabled(true);
|
||||||
|
|
||||||
// ungrab mouse grabber
|
// ungrab mouse grabber
|
||||||
if(scene->mouseGrabberItem())
|
if(scene->mouseGrabberItem())
|
||||||
|
@ -225,6 +227,7 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev)
|
||||||
selLastRow = selClickedRow;
|
selLastRow = selClickedRow;
|
||||||
|
|
||||||
selectionMode = Multi;
|
selectionMode = Multi;
|
||||||
|
copyAction->setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,6 +566,7 @@ void ChatLog::selectAll()
|
||||||
selFirstRow = 0;
|
selFirstRow = 0;
|
||||||
selLastRow = lines.size()-1;
|
selLastRow = lines.size()-1;
|
||||||
|
|
||||||
|
copyAction->setEnabled(true);
|
||||||
updateMultiSelectionRect();
|
updateMultiSelectionRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -733,9 +737,21 @@ void ChatLog::onWorkerTimeout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatLog::showEvent(QShowEvent *)
|
void ChatLog::showEvent(QShowEvent*)
|
||||||
{
|
{
|
||||||
// Empty.
|
// Empty.
|
||||||
// The default implementation calls centerOn - for some reason - causing
|
// The default implementation calls centerOn - for some reason - causing
|
||||||
// the scrollbar to move.
|
// 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)));
|
||||||
|
}
|
||||||
|
|
|
@ -79,8 +79,10 @@ protected:
|
||||||
virtual void mouseReleaseEvent(QMouseEvent* ev);
|
virtual void mouseReleaseEvent(QMouseEvent* ev);
|
||||||
virtual void mouseMoveEvent(QMouseEvent* ev);
|
virtual void mouseMoveEvent(QMouseEvent* ev);
|
||||||
virtual void scrollContentsBy(int dx, int dy);
|
virtual void scrollContentsBy(int dx, int dy);
|
||||||
virtual void resizeEvent(QResizeEvent *ev);
|
virtual void resizeEvent(QResizeEvent* ev);
|
||||||
virtual void showEvent(QShowEvent *);
|
virtual void showEvent(QShowEvent*);
|
||||||
|
virtual void focusInEvent(QFocusEvent* ev);
|
||||||
|
virtual void focusOutEvent(QFocusEvent* ev);
|
||||||
|
|
||||||
void updateMultiSelectionRect();
|
void updateMultiSelectionRect();
|
||||||
void updateTypingNotification();
|
void updateTypingNotification();
|
||||||
|
@ -105,6 +107,7 @@ private:
|
||||||
Down,
|
Down,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QAction* copyAction = nullptr;
|
||||||
QGraphicsScene* scene = nullptr;
|
QGraphicsScene* scene = nullptr;
|
||||||
QGraphicsScene* busyScene = nullptr;
|
QGraphicsScene* busyScene = nullptr;
|
||||||
QVector<ChatLine::Ptr> lines;
|
QVector<ChatLine::Ptr> lines;
|
||||||
|
@ -117,6 +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);
|
||||||
SelectionMode selectionMode = None;
|
SelectionMode selectionMode = None;
|
||||||
QPointF clickPos;
|
QPointF clickPos;
|
||||||
QGraphicsRectItem* selGraphItem = nullptr;
|
QGraphicsRectItem* selGraphItem = nullptr;
|
||||||
|
|
|
@ -200,9 +200,6 @@ void GenericChatForm::onChatContextMenuRequested(QPoint pos)
|
||||||
QWidget* sender = (QWidget*)QObject::sender();
|
QWidget* sender = (QWidget*)QObject::sender();
|
||||||
pos = sender->mapToGlobal(pos);
|
pos = sender->mapToGlobal(pos);
|
||||||
|
|
||||||
//copy action
|
|
||||||
menu.actions().first()->setEnabled(chatWidget->hasTextToBeCopied());
|
|
||||||
|
|
||||||
menu.exec(pos);
|
menu.exec(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user