Implement setWindowIcon() for Windows.
Platform implementation for QWindow::setWindowIcon() was missing from Windows platform plugin. Task-number: QTBUG-27175 Change-Id: I6807d1ded057b7788a9f2fa5b143e212a666029b Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
parent
782cae4104
commit
af13c79b30
@ -61,6 +61,8 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
Q_GUI_EXPORT HICON qt_pixmapToWinHICON(const QPixmap &);
|
||||
|
||||
static QByteArray debugWinStyle(DWORD style)
|
||||
{
|
||||
QByteArray rc = "0x";
|
||||
@ -699,13 +701,15 @@ QWindowsWindow::QWindowsWindow(QWindow *aWindow, const WindowData &data) :
|
||||
m_cursor(QWindowsScreen::screenOf(aWindow)->windowsCursor()->standardWindowCursor()),
|
||||
m_dropTarget(0),
|
||||
m_savedStyle(0),
|
||||
m_format(aWindow->format())
|
||||
m_format(aWindow->format()),
|
||||
#ifdef QT_OPENGL_ES_2
|
||||
, m_eglSurface(0)
|
||||
m_eglSurface(0),
|
||||
#endif
|
||||
#ifdef Q_OS_WINCE
|
||||
, m_previouslyHidden(false)
|
||||
m_previouslyHidden(false),
|
||||
#endif
|
||||
m_iconBig(0),
|
||||
m_iconSmall(0)
|
||||
{
|
||||
if (aWindow->surfaceType() == QWindow::OpenGLSurface)
|
||||
setFlag(OpenGLSurface);
|
||||
@ -730,6 +734,7 @@ QWindowsWindow::QWindowsWindow(QWindow *aWindow, const WindowData &data) :
|
||||
QWindowsWindow::~QWindowsWindow()
|
||||
{
|
||||
destroyWindow();
|
||||
destroyIcon();
|
||||
}
|
||||
|
||||
void QWindowsWindow::destroyWindow()
|
||||
@ -1754,4 +1759,32 @@ QByteArray QWindowsWindow::debugWindowFlags(Qt::WindowFlags wf)
|
||||
return rc;
|
||||
}
|
||||
|
||||
static HICON createHIcon(const QIcon &icon, int xSize, int ySize)
|
||||
{
|
||||
if (!icon.isNull()) {
|
||||
const QPixmap pm = icon.pixmap(icon.actualSize(QSize(xSize, ySize)));
|
||||
if (!pm.isNull())
|
||||
return qt_pixmapToWinHICON(pm);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void QWindowsWindow::setWindowIcon(const QIcon &icon)
|
||||
{
|
||||
if (m_data.hwnd) {
|
||||
destroyIcon();
|
||||
|
||||
m_iconSmall = createHIcon(icon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
|
||||
m_iconBig = createHIcon(icon, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
|
||||
|
||||
if (m_iconBig) {
|
||||
SendMessage(m_data.hwnd, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)m_iconSmall);
|
||||
SendMessage(m_data.hwnd, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)m_iconBig);
|
||||
} else {
|
||||
SendMessage(m_data.hwnd, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)m_iconSmall);
|
||||
SendMessage(m_data.hwnd, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)m_iconSmall);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -238,6 +238,7 @@ public:
|
||||
|
||||
void setEnabled(bool enabled);
|
||||
bool isEnabled() const;
|
||||
void setWindowIcon(const QIcon &icon);
|
||||
|
||||
#ifndef Q_OS_WINCE
|
||||
void alertWindow(int durationMs = 0);
|
||||
@ -259,6 +260,7 @@ private:
|
||||
void unregisterDropSite();
|
||||
void handleGeometryChange();
|
||||
void handleWindowStateChange(Qt::WindowState state);
|
||||
inline void destroyIcon();
|
||||
|
||||
mutable WindowData m_data;
|
||||
mutable unsigned m_flags;
|
||||
@ -277,6 +279,8 @@ private:
|
||||
#ifdef Q_OS_WINCE
|
||||
bool m_previouslyHidden;
|
||||
#endif
|
||||
HICON m_iconSmall;
|
||||
HICON m_iconBig;
|
||||
};
|
||||
|
||||
// Conveniences for window frames.
|
||||
@ -346,6 +350,18 @@ void QWindowsWindow::setUserDataOf(HWND hwnd, void *ud)
|
||||
SetWindowLongPtr(hwnd, GWLP_USERDATA, LONG_PTR(ud));
|
||||
}
|
||||
|
||||
inline void QWindowsWindow::destroyIcon()
|
||||
{
|
||||
if (m_iconBig) {
|
||||
DestroyIcon(m_iconBig);
|
||||
m_iconBig = 0;
|
||||
}
|
||||
if (m_iconSmall) {
|
||||
DestroyIcon(m_iconSmall);
|
||||
m_iconSmall = 0;
|
||||
}
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWINDOWSWINDOW_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user