Qt 4.8
Functions
qcursor_win.cpp File Reference
#include <private/qcursor_p.h>
#include <qbitmap.h>
#include <qcursor.h>
#include <qimage.h>
#include <qt_windows.h>
#include <private/qapplication_p.h>

Go to the source code of this file.

Functions

static HCURSOR create32BitCursor (const QPixmap &pixmap, int hx, int hy)
 
HBITMAP qt_createIconMask (const QBitmap &bitmap)
 

Function Documentation

◆ create32BitCursor()

static HCURSOR create32BitCursor ( const QPixmap pixmap,
int  hx,
int  hy 
)
static

Definition at line 128 of file qcursor_win.cpp.

129 {
130  HCURSOR cur = 0;
131 #if !defined(Q_WS_WINCE)
132  QBitmap mask = pixmap.mask();
133  if (mask.isNull()) {
134  mask = QBitmap(pixmap.size());
135  mask.fill(Qt::color1);
136  }
137 
138  HBITMAP ic = pixmap.toWinHBITMAP(QPixmap::Alpha);
139  HBITMAP im = qt_createIconMask(mask);
140 
141  ICONINFO ii;
142  ii.fIcon = 0;
143  ii.xHotspot = hx;
144  ii.yHotspot = hy;
145  ii.hbmMask = im;
146  ii.hbmColor = ic;
147 
148  cur = CreateIconIndirect(&ii);
149 
150  DeleteObject(ic);
151  DeleteObject(im);
152 #elif defined(GWES_ICONCURS)
153  QImage bbits, mbits;
154  bool invb, invm;
155  bbits = pixmap.toImage().convertToFormat(QImage::Format_Mono);
156  mbits = pixmap.toImage().convertToFormat(QImage::Format_Mono);
157  invb = bbits.colorCount() > 1 && qGray(bbits.color(0)) < qGray(bbits.color(1));
158  invm = mbits.colorCount() > 1 && qGray(mbits.color(0)) < qGray(mbits.color(1));
159 
160  int sysW = GetSystemMetrics(SM_CXCURSOR);
161  int sysH = GetSystemMetrics(SM_CYCURSOR);
162  int sysN = qMax(1, sysW / 8);
163  int n = qMax(1, bbits.width() / 8);
164  int h = bbits.height();
165 
166  uchar* xBits = new uchar[sysH * sysN];
167  uchar* xMask = new uchar[sysH * sysN];
168  int x = 0;
169  for (int i = 0; i < sysH; ++i) {
170  if (i >= h) {
171  memset(&xBits[x] , 255, sysN);
172  memset(&xMask[x] , 0, sysN);
173  x += sysN;
174  } else {
175  int fillWidth = n > sysN ? sysN : n;
176  uchar *bits = bbits.scanLine(i);
177  uchar *mask = mbits.scanLine(i);
178  for (int j = 0; j < fillWidth; ++j) {
179  uchar b = bits[j];
180  uchar m = mask[j];
181  if (invb)
182  b ^= 0xFF;
183  if (invm)
184  m ^= 0xFF;
185  xBits[x] = ~m;
186  xMask[x] = b ^ m;
187  ++x;
188  }
189  for (int j = fillWidth; j < sysN; ++j ) {
190  xBits[x] = 255;
191  xMask[x] = 0;
192  ++x;
193  }
194  }
195  }
196 
197  cur = CreateCursor(qWinAppInst(), hx, hy, sysW, sysH,
198  xBits, xMask);
199 #else
200  Q_UNUSED(pixmap);
201  Q_UNUSED(hx);
202  Q_UNUSED(hy);
203 #endif
204  return cur;
205 }
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
HICON HCURSOR
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
unsigned char uchar
Definition: qglobal.h:994
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int qGray(int r, int g, int b)
Definition: qrgb.h:75
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
HBITMAP toWinHBITMAP(HBitmapFormat format=NoAlpha) const
It is the caller&#39;s responsibility to free the HBITMAP data after use.
QBitmap mask() const
Extracts a bitmap mask from the pixmap&#39;s alpha channel.
Definition: qpixmap.cpp:2077
int colorCount() const
Returns the size of the color table for the image.
Definition: qimage.cpp:1656
#define SM_CYCURSOR
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
Q_CORE_EXPORT HINSTANCE qWinAppInst()
HBITMAP qt_createIconMask(const QBitmap &bitmap)
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
#define SM_CXCURSOR
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QRgb color(int i) const
Returns the color in the color table at index i.
Definition: qimage.cpp:1829
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ qt_createIconMask()

HBITMAP qt_createIconMask ( const QBitmap bitmap)

Definition at line 242 of file qpixmap_win.cpp.

Referenced by create32BitCursor(), QCursor::QCursor(), and QPixmap::toWinHICON().

243 {
245  int w = bm.width();
246  int h = bm.height();
247  int bpl = ((w+15)/16)*2; // bpl, 16 bit alignment
248  uchar *bits = new uchar[bpl*h];
249  bm.invertPixels();
250  for (int y=0; y<h; y++)
251  memcpy(bits+y*bpl, bm.scanLine(y), bpl);
252  HBITMAP hbm = CreateBitmap(w, h, 1, 1, bits);
253  delete [] bits;
254  return hbm;
255 }
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
unsigned char uchar
Definition: qglobal.h:994
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
void invertPixels(InvertMode=InvertRgb)
Inverts all pixel values in the image.
Definition: qimage.cpp:2179
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886