aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2019-06-13 10:25:19 -0700
committerAnders Broman <a.broman58@gmail.com>2019-06-13 18:02:50 +0000
commitb94047c606a53f405ea24ca5bf5161a74da7d4b9 (patch)
tree0c1b8091e8533adccb1d92331434f472cef725ba /ui
parentf41e1d22f0d9b9deb7f7f8dc9e3f81f45faae11a (diff)
Qt: Add support for template icons.
Add support for ".template" icons, which are masked against the current WindowText color. Convert the edit-find icons to templates. Reload our icon(s) when we receive a QEvent::PaletteChange in MainWindow and in StockIconToolButton. Clean our SVGs. To do: - Convert other black or mostly black icons to templates. - Handle QEvent::PaletteChange in more places. Ping-Bug: 15511 Change-Id: I1ce78d92e769861dc38d86a3def5116fb869e2bf Reviewed-on: https://code.wireshark.org/review/33571 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/main_window.cpp13
-rw-r--r--ui/qt/main_window.h1
-rw-r--r--ui/qt/utils/stock_icon.cpp35
-rw-r--r--ui/qt/widgets/stock_icon_tool_button.cpp15
-rw-r--r--ui/qt/widgets/stock_icon_tool_button.h3
5 files changed, 61 insertions, 6 deletions
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp
index 9ff8d0965e..6a532dec09 100644
--- a/ui/qt/main_window.cpp
+++ b/ui/qt/main_window.cpp
@@ -877,6 +877,19 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
return QMainWindow::eventFilter(obj, event);
}
+bool MainWindow::event(QEvent *event)
+{
+ switch (event->type()) {
+ case QEvent::PaletteChange:
+ initMainToolbarIcons();
+ break;
+ default:
+ break;
+
+ }
+ return QMainWindow::event(event);
+}
+
void MainWindow::keyPressEvent(QKeyEvent *event) {
// Explicitly focus on the display filter combo.
diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h
index 26559a645f..cba3ced572 100644
--- a/ui/qt/main_window.h
+++ b/ui/qt/main_window.h
@@ -133,6 +133,7 @@ public:
protected:
virtual bool eventFilter(QObject *obj, QEvent *event);
+ virtual bool event(QEvent *event);
virtual void keyPressEvent(QKeyEvent *event);
virtual void closeEvent(QCloseEvent *event);
virtual void dragEnterEvent(QDragEnterEvent *event);
diff --git a/ui/qt/utils/stock_icon.cpp b/ui/qt/utils/stock_icon.cpp
index 014a625fbd..c623326943 100644
--- a/ui/qt/utils/stock_icon.cpp
+++ b/ui/qt/utils/stock_icon.cpp
@@ -29,7 +29,8 @@
// http://msdn.microsoft.com/en-us/library/ms246582.aspx
// To do:
-// - 32x32, 48x48, 64x64, and unscaled (.svg) icons
+// - 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:
// WIRESHARK_STOCK_CAPTURE_FILTER x-capture-filter
@@ -75,7 +76,39 @@ StockIcon::StockIcon(const QString icon_name) :
// Is this one of our locally sourced, cage-free, organic icons?
QStringList types = QStringList() << "14x14" << "16x16" << "24x14" << "24x24";
+ QList<QPalette::ColorGroup> color_groups = QList<QPalette::ColorGroup>()
+ << QPalette::Disabled
+ << QPalette::Active
+ << QPalette::Inactive
+ << QPalette::Normal;
foreach (QString type, types) {
+ // First, check for a template (mask) icon
+ // Templates should be monochrome as described at
+ // https://developer.apple.com/design/human-interface-guidelines/macos/icons-and-images/custom-icons/
+ // Transparency is supported.
+ QString icon_path_template = path_pfx_ + QString("%1/%2.template.png").arg(type).arg(icon_name);
+ if (QFile::exists(icon_path_template)) {
+ QIcon mask_icon = QIcon();
+ mask_icon.addFile(icon_path_template);
+
+ foreach(QSize sz, mask_icon.availableSizes()) {
+ QPixmap mask_pm = mask_icon.pixmap(sz);
+ foreach (QPalette::ColorGroup cg, color_groups) {
+ QImage mode_img(sz, QImage::Format_ARGB32);
+ mode_img.setDevicePixelRatio(mask_pm.devicePixelRatioF());
+ QPainter painter(&mode_img);
+ QBrush br(wsApp->palette().color(cg, QPalette::WindowText));
+ painter.fillRect(0, 0, sz.width(), sz.height(), br);
+ painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
+ painter.drawPixmap(0, 0, mask_pm);
+ addPixmap(QPixmap::fromImage(mode_img));
+ }
+ }
+
+ continue;
+ }
+
+ // Regular full-color icons
QString icon_path = path_pfx_ + QString("%1/%2.png").arg(type).arg(icon_name);
if (QFile::exists(icon_path)) {
addFile(icon_path);
diff --git a/ui/qt/widgets/stock_icon_tool_button.cpp b/ui/qt/widgets/stock_icon_tool_button.cpp
index 11a373a57e..3db550ce78 100644
--- a/ui/qt/widgets/stock_icon_tool_button.cpp
+++ b/ui/qt/widgets/stock_icon_tool_button.cpp
@@ -28,9 +28,7 @@ StockIconToolButton::StockIconToolButton(QWidget * parent, QString stock_icon_na
QToolButton(parent),
leave_timer_(0)
{
- if (!stock_icon_name.isEmpty()) {
- setStockIcon(stock_icon_name);
- }
+ setStockIcon(stock_icon_name);
}
void StockIconToolButton::setIconMode(QIcon::Mode mode)
@@ -47,7 +45,13 @@ void StockIconToolButton::setIconMode(QIcon::Mode mode)
void StockIconToolButton::setStockIcon(QString icon_name)
{
- base_icon_ = StockIcon(icon_name);
+ if (!icon_name.isEmpty()) {
+ icon_name_ = icon_name;
+ }
+ if (icon_name_.isEmpty()) {
+ return;
+ }
+ base_icon_ = StockIcon(icon_name_);
setIconMode();
}
@@ -91,6 +95,9 @@ bool StockIconToolButton::event(QEvent *event)
}
break;
}
+ case QEvent::PaletteChange:
+ setStockIcon();
+ break;
default:
break;
}
diff --git a/ui/qt/widgets/stock_icon_tool_button.h b/ui/qt/widgets/stock_icon_tool_button.h
index 793e7fd2ea..7fc0e2f0b8 100644
--- a/ui/qt/widgets/stock_icon_tool_button.h
+++ b/ui/qt/widgets/stock_icon_tool_button.h
@@ -19,13 +19,14 @@ public:
explicit StockIconToolButton(QWidget * parent = 0, QString stock_icon_name = QString());
void setIconMode(QIcon::Mode mode = QIcon::Normal);
- void setStockIcon(QString icon_name);
+ void setStockIcon(QString icon_name = QString());
protected:
virtual bool event(QEvent *event);
private:
QIcon base_icon_;
+ QString icon_name_;
int leave_timer_;
static const int leave_interval_ = 500; // ms
};