Add ability for QIcons to be marked as template images.

This allows end users to create QSystemTrayIcons that are properly
displayed as monochrome images on OS X, which is especially important
on Yosemite and above when Dark Mode is turned on.

[ChangeLog][QtGui][QIcon] Add ability for QIcons to be marked
as template images. This allows end users to create QSystemTrayIcons
that are properly displayed as monochrome images on OS X, which is
especially important on Yosemite and above when Dark Mode is turned on.


Task-number: QTBUG-42109
Change-Id: I095fb71355ffa572d0abb4769341f68b89b877c4
Reviewed-by: Jake Petroules <jake.petroules@petroules.com>
This commit is contained in:
James Turner 2015-06-24 10:17:04 +01:00
parent bd4ff0b552
commit 130c2baa93
4 changed files with 32 additions and 1 deletions

View File

@ -129,7 +129,8 @@ static qreal qt_effective_device_pixel_ratio(QWindow *window = 0)
QIconPrivate::QIconPrivate()
: engine(0), ref(1),
serialNum(serialNumCounter.fetchAndAddRelaxed(1)),
detach_no(0)
detach_no(0),
is_mask(false)
{
}
@ -1196,6 +1197,31 @@ bool QIcon::hasThemeIcon(const QString &name)
return icon.name() == name;
}
/*!
\since 5.6
Indicate that this icon is a mask image, and hence can potentially
be modified based on where it's displayed.
\sa isMask()
*/
void QIcon::setIsMask(bool isMask)
{
d->is_mask = isMask;
}
/*!
\since 5.6
Returns \c true if this icon has been marked as a mask image.
Certain platforms render mask icons differently (for example,
menu icons on OS X).
\sa setIsMask()
*/
bool QIcon::isMask() const
{
return d->is_mask;
}
/*****************************************************************************
QIcon stream functions

View File

@ -102,6 +102,9 @@ public:
QList<QSize> availableSizes(Mode mode = Normal, State state = Off) const;
void setIsMask(bool isMask);
bool isMask() const;
static QIcon fromTheme(const QString &name, const QIcon &fallback = QIcon());
static bool hasThemeIcon(const QString &name);

View File

@ -71,6 +71,7 @@ public:
QAtomicInt ref;
int serialNum;
int detach_no;
bool is_mask;
};

View File

@ -252,6 +252,7 @@ void QCocoaSystemTrayIcon::updateIcon(const QIcon &icon)
}
NSImage *nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(fullHeightPixmap));
[nsimage setTemplate:icon.isMask()];
[(NSImageView*)[[m_sys->item item] view] setImage: nsimage];
[nsimage release];
}