Qt 4.8
Public Functions | Static Private Functions | Properties | List of all members
QPlatformCursorImage Class Reference

The QPlatformCursorImage class provides a set of graphics intended to be used as cursors. More...

#include <qplatformcursor_qpa.h>

Public Functions

QPoint hotspot ()
 Return the cursor's hotspot. More...
 
QImageimage ()
 Return the cursor graphic as a pointer to a QImage. More...
 
 QPlatformCursorImage (const uchar *data, const uchar *mask, int width, int height, int hotX, int hotY)
 Sets the cursor image to the graphic represented by the combination of data and mask, with dimensions given by width and height and a hotspot at the point specified by (hotX, hotY). More...
 
void set (const uchar *data, const uchar *mask, int width, int height, int hotX, int hotY)
 Sets the cursor image to the graphic represented by the combination of data and mask, with dimensions given by width and height and a hotspot at the point specified by (hx, hy). More...
 
void set (const QImage &image, int hx, int hy)
 Sets the cursor image to the given image, with the hotspot at the point specified by (hx, hy). More...
 
void set (Qt::CursorShape)
 Calling this method sets the cursor image to the specified shape. More...
 

Static Private Functions

static void createSystemCursor (int id)
 

Properties

QImage cursorImage
 
QPoint hot
 

Detailed Description

The QPlatformCursorImage class provides a set of graphics intended to be used as cursors.

Since
4.8
See also
QPlatformCursor

Definition at line 59 of file qplatformcursor_qpa.h.

Constructors and Destructors

◆ QPlatformCursorImage()

QPlatformCursorImage::QPlatformCursorImage ( const uchar data,
const uchar mask,
int  width,
int  height,
int  hotX,
int  hotY 
)
inline

Sets the cursor image to the graphic represented by the combination of data and mask, with dimensions given by width and height and a hotspot at the point specified by (hotX, hotY).

See also
set()

Definition at line 61 of file qplatformcursor_qpa.h.

62  { set(data, mask, width, height, hotX, hotY); }
static const char * data(const QByteArray &arr)

Functions

◆ createSystemCursor()

void QPlatformCursorImage::createSystemCursor ( int  id)
staticprivate

Definition at line 423 of file qplatformcursor_qpa.cpp.

424 {
425  if (!systemCursorTableInit) {
426  for (int i = 0; i <= Qt::LastCursor; i++)
427  systemCursorTable[i] = 0;
428  systemCursorTableInit = true;
429  }
430  switch (id) {
431  // 16x16 cursors
432  case Qt::ArrowCursor:
435  break;
436 
437  case Qt::UpArrowCursor:
440  break;
441 
442  case Qt::CrossCursor:
445  break;
446 
447  case Qt::IBeamCursor:
450  break;
451 
452  case Qt::SizeVerCursor:
454  new QPlatformCursorImage(cur_ver_bits, mcur_ver_bits, 16, 16, 7, 7);
455  break;
456 
457  case Qt::SizeHorCursor:
459  new QPlatformCursorImage(cur_hor_bits, mcur_hor_bits, 16, 16, 7, 7);
460  break;
461 
462  case Qt::SizeBDiagCursor:
465  break;
466 
467  case Qt::SizeFDiagCursor:
470  break;
471 
472  case Qt::BlankCursor:
474  new QPlatformCursorImage(0, 0, 0, 0, 0, 0);
475  break;
476 
477  // 20x20 cursors
478  case Qt::ForbiddenCursor:
481  break;
482 
483  // 32x32 cursors
484  case Qt::WaitCursor:
486  new QPlatformCursorImage(wait_data_bits, wait_mask_bits, 32, 32, 15, 15);
487  break;
488 
489  case Qt::SplitVCursor:
491  new QPlatformCursorImage(vsplit_bits, vsplitm_bits, 32, 32, 15, 15);
492  break;
493 
494  case Qt::SplitHCursor:
496  new QPlatformCursorImage(hsplit_bits, hsplitm_bits, 32, 32, 15, 15);
497  break;
498 
499  case Qt::SizeAllCursor:
502  break;
503 
506  new QPlatformCursorImage(phand_bits, phandm_bits, 32, 32, 0, 0);
507  break;
508 
509  case Qt::WhatsThisCursor:
512  break;
513  case Qt::BusyCursor:
515  new QPlatformCursorImage(busy_bits, busym_bits, 32, 32, 0, 0);
516  break;
517 
518  case Qt::OpenHandCursor:
521  break;
525  break;
526  default:
527  qWarning("Unknown system cursor %d", id);
528  }
529 }
static const uchar wait_mask_bits[]
static const uchar closedhandm_bits[]
static const unsigned char mcur_cross_bits[]
static const uchar vsplit_bits[]
static const uchar openhand_bits[]
static const uchar cur_hor_bits[]
static const uchar mcur_ibeam_bits[]
static const uchar mcur_fdiag_bits[]
static const uchar forbiddenm_bits[]
static const uchar mcur_ver_bits[]
static const uchar size_all_data_bits[]
static const uchar cur_bdiag_bits[]
static bool systemCursorTableInit
static const uchar whatsthis_bits[]
static const uchar mcur_bdiag_bits[]
static const uchar phandm_bits[]
static const uchar hsplitm_bits[]
static const unsigned char cur_up_arrow_bits[]
static const uchar hsplit_bits[]
static const uchar cur_fdiag_bits[]
static const uchar whatsthism_bits[]
Q_CORE_EXPORT void qWarning(const char *,...)
static const uchar cur_ibeam_bits[]
static const uchar cur_ver_bits[]
static const uchar openhandm_bits[]
static QPlatformCursorImage * systemCursorTable[Qt::LastCursor+1]
static const uchar forbidden_bits[]
QPlatformCursorImage(const uchar *data, const uchar *mask, int width, int height, int hotX, int hotY)
Sets the cursor image to the graphic represented by the combination of data and mask, with dimensions given by width and height and a hotspot at the point specified by (hotX, hotY).
static const uchar wait_data_bits[]
static const uchar cur_arrow_bits[]
static const uchar mcur_hor_bits[]
static const unsigned char mcur_up_arrow_bits[]
static const uchar busym_bits[]
static const uchar closedhand_bits[]
static const uchar vsplitm_bits[]
static const uchar size_all_mask_bits[]
static const unsigned char cur_cross_bits[]
static const uchar mcur_arrow_bits[]
static const uchar busy_bits[]
static const uchar phand_bits[]

◆ hotspot()

QPoint QPlatformCursorImage::hotspot ( )
inline

Return the cursor's hotspot.

Definition at line 64 of file qplatformcursor_qpa.h.

Referenced by QDirectFBCursor::changeCursor(), QPlatformSoftwareCursor::getCurrentRect(), and QVNCCursor::sendClientCursor().

64 { return hot; }

◆ image()

QImage * QPlatformCursorImage::image ( )
inline

◆ set() [1/3]

void QPlatformCursorImage::set ( const uchar data,
const uchar mask,
int  width,
int  height,
int  hx,
int  hy 
)

Sets the cursor image to the graphic represented by the combination of data and mask, with dimensions given by width and height and a hotspot at the point specified by (hx, hy).

The image data specified by data must be supplied in the format described by QImage::Format_Indexed8.

The corresponding mask data specified by mask must be supplied in a character array containing packed 1 bit per pixel format data, with any padding bits at the end of the array. Bits of value 0 represent transparent pixels in the image data.

Definition at line 590 of file qplatformcursor_qpa.cpp.

Referenced by QDirectFBCursor::changeCursor(), and QPlatformSoftwareCursor::setCursor().

592 {
593  hot.setX(hx);
594  hot.setY(hy);
595 
596  cursorImage = QImage(width,height, QImage::Format_Indexed8);
597 
598  if (!width || !height || !data || !mask || cursorImage.isNull())
599  return;
600 
602  cursorImage.setColor(0, 0xff000000);
603  cursorImage.setColor(1, 0xffffffff);
604  cursorImage.setColor(2, 0x00000000);
605 
606  int bytesPerLine = (width + 7) / 8;
607  int p = 0;
608  int d, m;
609 
610  int x = -1, w = 0;
611 
612  uchar *cursor_data = cursorImage.bits();
613  int bpl = cursorImage.bytesPerLine();
614  for (int i = 0; i < height; i++)
615  {
616  for (int j = 0; j < bytesPerLine; j++, data++, mask++)
617  {
618  for (int b = 0; b < 8 && j*8+b < width; b++)
619  {
620  d = *data & (1 << b);
621  m = *mask & (1 << b);
622  if (d && m) p = 0;
623  else if (!d && m) p = 1;
624  else p = 2;
625  cursor_data[j*8+b] = p;
626 
627  // calc region
628  if (x < 0 && m)
629  x = j*8+b;
630  else if (x >= 0 && !m) {
631  x = -1;
632  w = 0;
633  }
634  if (m)
635  w++;
636  }
637  }
638  if (x >= 0) {
639  x = -1;
640  w = 0;
641  }
642  cursor_data += bpl;
643  }
644 
645 }
double d
Definition: qnumeric_p.h:62
void setColor(int i, QRgb c)
Sets the color at the given index in the color table, to the given to colorValue. ...
Definition: qimage.cpp:1850
QT_DEPRECATED void setNumColors(int)
Resizes the color table to contain numColors entries.
Definition: qimage.cpp:2252
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
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
static const char * data(const QByteArray &arr)
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
void setY(int y)
Sets the y coordinate of this point to the given y coordinate.
Definition: qpoint.h:137
void setX(int x)
Sets the x coordinate of this point to the given x coordinate.
Definition: qpoint.h:134

◆ set() [2/3]

void QPlatformCursorImage::set ( const QImage image,
int  hx,
int  hy 
)

Sets the cursor image to the given image, with the hotspot at the point specified by (hx, hy).

Definition at line 568 of file qplatformcursor_qpa.cpp.

569 {
570  hot.setX(hx);
571  hot.setY(hy);
572  cursorImage = image;
573 }
QImage * image()
Return the cursor graphic as a pointer to a QImage.
void setY(int y)
Sets the y coordinate of this point to the given y coordinate.
Definition: qpoint.h:137
void setX(int x)
Sets the x coordinate of this point to the given x coordinate.
Definition: qpoint.h:134

◆ set() [3/3]

void QPlatformCursorImage::set ( Qt::CursorShape  id)

Calling this method sets the cursor image to the specified shape.

id is one of the defined Qt::CursorShape values.

If id is invalid, Qt::BitmapCursor, or unknown by the implementation, Qt::ArrowCursor is used instead.

Definition at line 545 of file qplatformcursor_qpa.cpp.

546 {
547  QPlatformCursorImage *cursor = 0;
548  if (id >= 0 && id <= Qt::LastCursor) {
549  if (!systemCursorTable[id])
550  createSystemCursor(id);
551  cursor = systemCursorTable[id];
552  }
553 
554  if (cursor == 0) {
556  createSystemCursor(Qt::ArrowCursor);
558  }
559  cursorImage = cursor->cursorImage;
560  hot = cursor->hot;
561 }
static void createSystemCursor(int id)
static QPlatformCursorImage * systemCursorTable[Qt::LastCursor+1]
The QPlatformCursorImage class provides a set of graphics intended to be used as cursors.

Properties

◆ cursorImage

QImage QPlatformCursorImage::cursorImage
private

Definition at line 70 of file qplatformcursor_qpa.h.

Referenced by set().

◆ hot

QPoint QPlatformCursorImage::hot
private

Definition at line 71 of file qplatformcursor_qpa.h.

Referenced by set().


The documentation for this class was generated from the following files: