aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2019-06-21 15:50:46 -0700
committerAlexis La Goutte <alexis.lagoutte@gmail.com>2019-06-23 06:14:16 +0000
commit737b7eb6c6e0c0b06d512ed093d3de94ef698f35 (patch)
treeeab8bc846c374e2f5eb47a4ef37cc3c6366e2250
parenta9ed94356d1b0cb149351e063014d3bdb94c0cd7 (diff)
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>
-rw-r--r--ui/qt/main_window.cpp2
-rw-r--r--ui/qt/utils/stock_icon.cpp1
-rw-r--r--ui/qt/welcome_page.cpp203
-rw-r--r--ui/qt/welcome_page.h3
-rw-r--r--ui/qt/widgets/filter_expression_toolbar.cpp2
-rw-r--r--ui/qt/widgets/stock_icon_tool_button.cpp2
6 files changed, 121 insertions, 92 deletions
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp
index fabde28ecf..6f5593b20d 100644
--- a/ui/qt/main_window.cpp
+++ b/ui/qt/main_window.cpp
@@ -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:
diff --git a/ui/qt/utils/stock_icon.cpp b/ui/qt/utils/stock_icon.cpp
index b54b36dac8..6e3437937d 100644
--- a/ui/qt/utils/stock_icon.cpp
+++ b/ui/qt/utils/stock_icon.cpp
@@ -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:
diff --git a/ui/qt/welcome_page.cpp b/ui/qt/welcome_page.cpp
index 4826f82ef7..5c76f2832f 100644
--- a/ui/qt/welcome_page.cpp
+++ b/ui/qt/welcome_page.cpp
@@ -59,101 +59,14 @@ WelcomePage::WelcomePage(QWidget *parent) :
welcome_ui_->captureFilterComboBox->setEnabled(false);
- 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
+ updateStyleSheets();
- // 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);
diff --git a/ui/qt/welcome_page.h b/ui/qt/welcome_page.h
index dce4a64e7e..73aa7f2218 100644
--- a/ui/qt/welcome_page.h
+++ b/ui/qt/welcome_page.h
@@ -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_;
diff --git a/ui/qt/widgets/filter_expression_toolbar.cpp b/ui/qt/widgets/filter_expression_toolbar.cpp
index cc56e46c87..89cf3b648f 100644
--- a/ui/qt/widgets/filter_expression_toolbar.cpp
+++ b/ui/qt/widgets/filter_expression_toolbar.cpp
@@ -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:
diff --git a/ui/qt/widgets/stock_icon_tool_button.cpp b/ui/qt/widgets/stock_icon_tool_button.cpp
index 3db550ce78..548f851a6c 100644
--- a/ui/qt/widgets/stock_icon_tool_button.cpp
+++ b/ui/qt/widgets/stock_icon_tool_button.cpp
@@ -95,7 +95,7 @@ bool StockIconToolButton::event(QEvent *event)
}
break;
}
- case QEvent::PaletteChange:
+ case QEvent::ApplicationPaletteChange:
setStockIcon();
break;
default: