forked from osmocom/wireshark
Qt: Handle ApplicationPaletteChange events in the welcome page.
Update our various welcome page style sheets when we receive an ApplicationPaletteChange event. It looks like ApplicationPaletteChange is the proper way to detect a system-wide theme change, since we can infinitely recurse if we hold things wrong inside a regular PaletteChange event (I'm guessing setting CSS background and foreground colors were the culprits in this case). Switch from PaletteChange to ApplicationPaletteChange everywhere. Ping-Bug: 15511 Change-Id: I6e7aa627d9ca1d1d3872ab31620ea5c579061191 Reviewed-on: https://code.wireshark.org/review/33703 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
This commit is contained in:
parent
a9ed94356d
commit
737b7eb6c6
|
@ -880,7 +880,7 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
|
|||
bool MainWindow::event(QEvent *event)
|
||||
{
|
||||
switch (event->type()) {
|
||||
case QEvent::PaletteChange:
|
||||
case QEvent::ApplicationPaletteChange:
|
||||
initMainToolbarIcons();
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
// http://msdn.microsoft.com/en-us/library/ms246582.aspx
|
||||
|
||||
// To do:
|
||||
// - Respond to dark mode changes via QEvent::PaletteChange.
|
||||
// - 32x32, 48x48, 64x64, and unscaled (.svg) icons.
|
||||
// - Indent find & go actions when those panes are open.
|
||||
// - Replace or remove:
|
||||
|
|
|
@ -59,101 +59,14 @@ WelcomePage::WelcomePage(QWidget *parent) :
|
|||
|
||||
welcome_ui_->captureFilterComboBox->setEnabled(false);
|
||||
|
||||
QColor hover_color = ColorUtils::alphaBlend(palette().window(), palette().highlight(), 0.5);
|
||||
updateStyleSheets();
|
||||
|
||||
QString welcome_ss = QString(
|
||||
"WelcomePage {"
|
||||
" padding: 1em;"
|
||||
" }"
|
||||
"WelcomePage, QAbstractItemView {"
|
||||
" background-color: palette(base);"
|
||||
" color: palette(text);"
|
||||
" }"
|
||||
"QAbstractItemView {"
|
||||
" border: 0;"
|
||||
"}"
|
||||
);
|
||||
#if !defined(Q_OS_WIN)
|
||||
welcome_ss += QString(
|
||||
"QAbstractItemView:item:hover {"
|
||||
" background-color: %1;"
|
||||
" color: palette(text);"
|
||||
"}"
|
||||
)
|
||||
.arg(hover_color.name());
|
||||
#endif
|
||||
setStyleSheet(welcome_ss);
|
||||
|
||||
QString banner_ss = QString(
|
||||
"QLabel {"
|
||||
" border-radius: 0.33em;"
|
||||
" color: %1;"
|
||||
" background-color: %2;"
|
||||
" padding: 0.33em;"
|
||||
"}"
|
||||
)
|
||||
.arg(QColor(tango_aluminium_6).name()) // Text color
|
||||
.arg(QColor(tango_sky_blue_2).name()); // Background color
|
||||
welcome_ui_->mainWelcomeBanner->setStyleSheet(banner_ss);
|
||||
|
||||
QString title_button_ss = QString(
|
||||
"QLabel {"
|
||||
" color: %1;"
|
||||
"}"
|
||||
"QLabel::hover {"
|
||||
" color: %2;"
|
||||
"}"
|
||||
)
|
||||
.arg(QColor(tango_aluminium_4).name()) // Text color
|
||||
.arg(QColor(tango_sky_blue_4).name()); // Hover color
|
||||
|
||||
// XXX Is there a better term than "flavor"? Provider? Admonition (a la DocBook)?
|
||||
// Release_source?
|
||||
// Typical use cases are automated builds from wireshark.org and private,
|
||||
// not-for-redistribution packages.
|
||||
if (flavor_.isEmpty()) {
|
||||
welcome_ui_->flavorBanner->hide();
|
||||
} else {
|
||||
// If needed there are a couple of ways we can make this customizable.
|
||||
// - Add one or more classes, e.g. "note" or "warning" similar to
|
||||
// SyntaxLineEdit, which we can then expose vi #defines.
|
||||
// - Just expose direct color values via #defines.
|
||||
QString flavor_ss = QString(
|
||||
"QLabel {"
|
||||
" border-radius: 0.25em;"
|
||||
" color: %1;"
|
||||
" background-color: %2;"
|
||||
" padding: 0.25em;"
|
||||
"}"
|
||||
)
|
||||
.arg("white") // Text color
|
||||
.arg("#2c4bc4"); // Background color. Matches capture start button.
|
||||
// .arg(QColor(tango_butter_5).name()); // "Warning" background
|
||||
|
||||
welcome_ui_->flavorBanner->setText(flavor_);
|
||||
welcome_ui_->flavorBanner->setStyleSheet(flavor_ss);
|
||||
}
|
||||
welcome_ui_->captureLabel->setStyleSheet(title_button_ss);
|
||||
welcome_ui_->recentLabel->setStyleSheet(title_button_ss);
|
||||
welcome_ui_->helpLabel->setStyleSheet(title_button_ss);
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
recent_files_->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||
#endif
|
||||
|
||||
welcome_ui_->openFrame->hide();
|
||||
recent_files_->setStyleSheet(
|
||||
"QListWidget::item {"
|
||||
" padding-top: 0.2em;"
|
||||
" padding-bottom: 0.2em;"
|
||||
"}"
|
||||
"QListWidget::item::first {"
|
||||
" padding-top: 0;"
|
||||
"}"
|
||||
"QListWidget::item::last {"
|
||||
" padding-bottom: 0;"
|
||||
"}"
|
||||
);
|
||||
recent_files_->setTextElideMode(Qt::ElideLeft);
|
||||
|
||||
recent_ctx_menu_ = new QMenu(this);
|
||||
|
@ -317,6 +230,19 @@ void WelcomePage::interfaceSelected()
|
|||
emit interfacesChanged();
|
||||
}
|
||||
|
||||
bool WelcomePage::event(QEvent *event)
|
||||
{
|
||||
switch (event->type()) {
|
||||
case QEvent::ApplicationPaletteChange:
|
||||
updateStyleSheets();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
return QFrame::event(event);
|
||||
}
|
||||
|
||||
void WelcomePage::on_interfaceFrame_showExtcapOptions(QString device_name)
|
||||
{
|
||||
emit showExtcapOptions(device_name);
|
||||
|
@ -498,6 +424,107 @@ void WelcomePage::on_helpLabel_clicked()
|
|||
QDesktopServices::openUrl(QUrl(topic_online_url(ONLINEPAGE_DOCS)));
|
||||
}
|
||||
|
||||
void WelcomePage::updateStyleSheets()
|
||||
{
|
||||
QColor hover_color = ColorUtils::alphaBlend(palette().window(), palette().highlight(), 0.5);
|
||||
|
||||
QString welcome_ss = QString(
|
||||
"WelcomePage {"
|
||||
" padding: 1em;"
|
||||
" }"
|
||||
"WelcomePage, QAbstractItemView {"
|
||||
" background-color: palette(base);"
|
||||
" color: palette(text);"
|
||||
" }"
|
||||
"QAbstractItemView {"
|
||||
" border: 0;"
|
||||
"}"
|
||||
);
|
||||
#if !defined(Q_OS_WIN)
|
||||
welcome_ss += QString(
|
||||
"QAbstractItemView:item:hover {"
|
||||
" background-color: %1;"
|
||||
" color: palette(text);"
|
||||
"}"
|
||||
)
|
||||
.arg(hover_color.name());
|
||||
#endif
|
||||
setStyleSheet(welcome_ss);
|
||||
|
||||
QString banner_ss = QString(
|
||||
"QLabel {"
|
||||
" border-radius: 0.33em;"
|
||||
" color: %1;"
|
||||
" background-color: %2;"
|
||||
" padding: 0.33em;"
|
||||
"}"
|
||||
)
|
||||
.arg(QColor(tango_aluminium_6).name()) // Text color
|
||||
.arg(QColor(tango_sky_blue_2).name()); // Background color
|
||||
welcome_ui_->mainWelcomeBanner->setStyleSheet(banner_ss);
|
||||
|
||||
QString title_button_ss = QString(
|
||||
"QLabel {"
|
||||
" color: %1;"
|
||||
"}"
|
||||
"QLabel::hover {"
|
||||
" color: %2;"
|
||||
"}"
|
||||
)
|
||||
.arg(QColor(tango_aluminium_4).name()) // Text color
|
||||
.arg(QColor(tango_sky_blue_4).name()); // Hover color
|
||||
|
||||
// XXX Is there a better term than "flavor"? Provider? Admonition (a la DocBook)?
|
||||
// Release_source?
|
||||
// Typical use cases are automated builds from wireshark.org and private,
|
||||
// not-for-redistribution packages.
|
||||
if (flavor_.isEmpty()) {
|
||||
welcome_ui_->flavorBanner->hide();
|
||||
} else {
|
||||
// If needed there are a couple of ways we can make this customizable.
|
||||
// - Add one or more classes, e.g. "note" or "warning" similar to
|
||||
// SyntaxLineEdit, which we can then expose vi #defines.
|
||||
// - Just expose direct color values via #defines.
|
||||
QString flavor_ss = QString(
|
||||
"QLabel {"
|
||||
" border-radius: 0.25em;"
|
||||
" color: %1;"
|
||||
" background-color: %2;"
|
||||
" padding: 0.25em;"
|
||||
"}"
|
||||
)
|
||||
.arg("white") // Text color
|
||||
.arg("#2c4bc4"); // Background color. Matches capture start button.
|
||||
// .arg(QColor(tango_butter_5).name()); // "Warning" background
|
||||
|
||||
welcome_ui_->flavorBanner->setText(flavor_);
|
||||
welcome_ui_->flavorBanner->setStyleSheet(flavor_ss);
|
||||
}
|
||||
welcome_ui_->captureLabel->setStyleSheet(title_button_ss);
|
||||
welcome_ui_->recentLabel->setStyleSheet(title_button_ss);
|
||||
welcome_ui_->helpLabel->setStyleSheet(title_button_ss);
|
||||
|
||||
recent_files_->setStyleSheet(
|
||||
"QListWidget::item {"
|
||||
" padding-top: 0.2em;"
|
||||
" padding-bottom: 0.2em;"
|
||||
"}"
|
||||
"QListWidget::item::first {"
|
||||
" padding-top: 0;"
|
||||
"}"
|
||||
"QListWidget::item::last {"
|
||||
" padding-bottom: 0;"
|
||||
"}"
|
||||
);
|
||||
|
||||
// The helpLinks markup includes its own <style>...</style> section.
|
||||
// Replacing it with a stylesheet and reapplying it like we do above
|
||||
// doesn't work, but this does.
|
||||
QString hl_text = welcome_ui_->helpLinks->text();
|
||||
welcome_ui_->helpLinks->clear();
|
||||
welcome_ui_->helpLinks->setText(hl_text);
|
||||
}
|
||||
|
||||
void WelcomePage::on_recentLabel_clicked()
|
||||
{
|
||||
wsApp->doTriggerMenuItem(WiresharkApplication::FileOpenDialog);
|
||||
|
|
|
@ -37,6 +37,7 @@ public slots:
|
|||
void interfaceSelected();
|
||||
|
||||
protected:
|
||||
virtual bool event(QEvent *event);
|
||||
virtual void resizeEvent(QResizeEvent *event);
|
||||
virtual void changeEvent(QEvent* event);
|
||||
|
||||
|
@ -46,6 +47,8 @@ protected slots:
|
|||
void on_helpLabel_clicked();
|
||||
|
||||
private:
|
||||
void updateStyleSheets();
|
||||
|
||||
Ui::WelcomePage *welcome_ui_;
|
||||
QString flavor_;
|
||||
QString show_in_str_;
|
||||
|
|
|
@ -52,7 +52,7 @@ FilterExpressionToolBar::FilterExpressionToolBar(QWidget * parent) :
|
|||
bool FilterExpressionToolBar::event(QEvent *event)
|
||||
{
|
||||
switch (event->type()) {
|
||||
case QEvent::PaletteChange:
|
||||
case QEvent::ApplicationPaletteChange:
|
||||
updateStyleSheet();
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -95,7 +95,7 @@ bool StockIconToolButton::event(QEvent *event)
|
|||
}
|
||||
break;
|
||||
}
|
||||
case QEvent::PaletteChange:
|
||||
case QEvent::ApplicationPaletteChange:
|
||||
setStockIcon();
|
||||
break;
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue