summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qpixmap_win.cpp
diff options
context:
space:
mode:
authorminiak <milan.burda@gmail.com>2009-09-22 08:33:27 (GMT)
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2009-09-22 08:33:27 (GMT)
commitac7fca3606d1a7dd5985b6fc284c40c0f2682fe5 (patch)
tree986d53bf15469aa9207e301b8a1c7c401218dc36 /src/gui/image/qpixmap_win.cpp
parentc0f1055fe809e6f4c90ea7ba3c369b2c01aaae07 (diff)
downloadQt-ac7fca3606d1a7dd5985b6fc284c40c0f2682fe5.zip
Qt-ac7fca3606d1a7dd5985b6fc284c40c0f2682fe5.tar.gz
Qt-ac7fca3606d1a7dd5985b6fc284c40c0f2682fe5.tar.bz2
* QPixmap: Add toWinHICON() & fromWinHICON() method
Duplicate QPixmap <-> HICON conversion code removed from qwidget_win.cpp & qsystemtrayicon_win.cpp. Task-number: 218533 Merge-request: 1570 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
Diffstat (limited to 'src/gui/image/qpixmap_win.cpp')
-rw-r--r--src/gui/image/qpixmap_win.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/gui/image/qpixmap_win.cpp b/src/gui/image/qpixmap_win.cpp
index 9042840..7f0c8e3 100644
--- a/src/gui/image/qpixmap_win.cpp
+++ b/src/gui/image/qpixmap_win.cpp
@@ -236,6 +236,49 @@ QPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format)
return fromImage(result);
}
+HBITMAP qt_createIconMask(const QBitmap &bitmap)
+{
+ QImage bm = bitmap.toImage().convertToFormat(QImage::Format_Mono);
+ int w = bm.width();
+ int h = bm.height();
+ int bpl = ((w+15)/16)*2; // bpl, 16 bit alignment
+ uchar *bits = new uchar[bpl*h];
+ bm.invertPixels();
+ for (int y=0; y<h; y++)
+ memcpy(bits+y*bpl, bm.scanLine(y), bpl);
+ HBITMAP hbm = CreateBitmap(w, h, 1, 1, bits);
+ delete [] bits;
+ return hbm;
+}
+
+HICON QPixmap::toWinHICON() const
+{
+ QBitmap maskBitmap = mask();
+ if (maskBitmap.isNull()) {
+ maskBitmap= QBitmap(size());
+ maskBitmap.fill(Qt::color1);
+ }
+
+ ICONINFO ii;
+ ii.fIcon = true;
+ ii.hbmMask = qt_createIconMask(maskBitmap);
+ ii.hbmColor = toWinHBITMAP(QPixmap::Alpha);
+ ii.xHotspot = 0;
+ ii.yHotspot = 0;
+
+ HICON hIcon = CreateIconIndirect(&ii);
+
+ DeleteObject(ii.hbmColor);
+ DeleteObject(ii.hbmMask);
+
+ return hIcon;
+}
+
+QPixmap QPixmap::fromWinHICON(HICON icon)
+{
+ return convertHIconToPixmap(icon);
+}
+
#ifdef Q_WS_WIN
#ifndef Q_WS_WINCE