mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Refresh chat view colors on theme changed. (#6581)
Took 35 minutes Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
bf5891a910
commit
d410078673
2 changed files with 52 additions and 15 deletions
|
|
@ -28,21 +28,9 @@ ChatView::ChatView(TabSupervisor *_tabSupervisor, AbstractGame *_game, bool _sho
|
|||
userListProxy(_tabSupervisor->getUserListManager()), evenNumber(true), showTimestamps(_showTimestamps),
|
||||
hoveredItemType(HoveredNothing)
|
||||
{
|
||||
if (palette().windowText().color().lightness() > 200) {
|
||||
document()->setDefaultStyleSheet(R"(
|
||||
a { text-decoration: none; color: rgb(71,158,252); }
|
||||
.blue { color: rgb(71,158,252); }
|
||||
)");
|
||||
serverMessageColor = QColor(0xFF, 0x73, 0x83);
|
||||
otherUserColor = otherUserColor.lighter(150);
|
||||
linkColor = QColor(71, 158, 252);
|
||||
} else {
|
||||
document()->setDefaultStyleSheet(R"(
|
||||
a { text-decoration: none; color: blue; }
|
||||
.blue { color: blue }
|
||||
)");
|
||||
linkColor = palette().link().color();
|
||||
}
|
||||
adjustColorsToPalette();
|
||||
|
||||
connect(&SettingsCache::instance(), &SettingsCache::themeChanged, this, &ChatView::adjustColorsToPalette);
|
||||
|
||||
userContextMenu = new UserContextMenu(tabSupervisor, this, game);
|
||||
connect(userContextMenu, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool)));
|
||||
|
|
@ -63,6 +51,53 @@ ChatView::ChatView(TabSupervisor *_tabSupervisor, AbstractGame *_game, bool _sho
|
|||
connect(this, &ChatView::anchorClicked, this, &ChatView::openLink);
|
||||
}
|
||||
|
||||
void ChatView::adjustColorsToPalette()
|
||||
{
|
||||
if (palette().windowText().color().lightness() > 200) {
|
||||
document()->setDefaultStyleSheet(R"(
|
||||
a { text-decoration: none; color: rgb(71,158,252); }
|
||||
.blue { color: rgb(71,158,252); }
|
||||
)");
|
||||
serverMessageColor = QColor(0xFF, 0x73, 0x83);
|
||||
otherUserColor = otherUserColor.lighter(150);
|
||||
linkColor = QColor(71, 158, 252);
|
||||
} else {
|
||||
document()->setDefaultStyleSheet(R"(
|
||||
a { text-decoration: none; color: blue; }
|
||||
.blue { color: blue }
|
||||
)");
|
||||
linkColor = palette().link().color();
|
||||
}
|
||||
|
||||
QTimer::singleShot(0, this, &ChatView::refreshBlockColors);
|
||||
}
|
||||
|
||||
void ChatView::refreshBlockColors()
|
||||
{
|
||||
QTextDocument *doc = document();
|
||||
QTextCursor cursor(doc);
|
||||
|
||||
bool even = true; // start fresh
|
||||
|
||||
for (QTextBlock block = doc->begin(); block.isValid(); block = block.next()) {
|
||||
QTextBlockFormat fmt = block.blockFormat();
|
||||
|
||||
if (even)
|
||||
fmt.setBackground(palette().window());
|
||||
else
|
||||
fmt.setBackground(palette().base());
|
||||
|
||||
fmt.setForeground(palette().text());
|
||||
|
||||
cursor.setPosition(block.position());
|
||||
cursor.setBlockFormat(fmt);
|
||||
|
||||
even = !even;
|
||||
}
|
||||
|
||||
evenNumber = even; // keep future rows consistent
|
||||
}
|
||||
|
||||
void ChatView::retranslateUi()
|
||||
{
|
||||
userContextMenu->retranslateUi();
|
||||
|
|
|
|||
|
|
@ -85,6 +85,8 @@ private:
|
|||
private slots:
|
||||
void openLink(const QUrl &link);
|
||||
void actMessageClicked();
|
||||
void adjustColorsToPalette();
|
||||
void refreshBlockColors();
|
||||
|
||||
public:
|
||||
ChatView(TabSupervisor *_tabSupervisor, AbstractGame *_game, bool _showTimestamps, QWidget *parent = nullptr);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue