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

#include <qwscursor_qws.h>

Public Functions

QPoint hotSpot () const
 
QImageimage ()
 
 QWSCursor ()
 
 QWSCursor (const uchar *data, const uchar *mask, int width, int height, int hotX, int hotY)
 
void set (const uchar *data, const uchar *mask, int width, int height, int hotX, int hotY)
 

Static Public Functions

static QWSCursorsystemCursor (int id)
 

Private Functions

void createDropShadow (int dropx, int dropy)
 

Static Private Functions

static void createSystemCursor (int id)
 

Properties

QImage cursor
 
QPoint hot
 

Detailed Description

Definition at line 54 of file qwscursor_qws.h.

Constructors and Destructors

◆ QWSCursor() [1/2]

QWSCursor::QWSCursor ( )
inline

Definition at line 57 of file qwscursor_qws.h.

57 {}

◆ QWSCursor() [2/2]

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

Definition at line 58 of file qwscursor_qws.h.

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

Functions

◆ createDropShadow()

void QWSCursor::createDropShadow ( int  dropx,
int  dropy 
)
private

Definition at line 587 of file qwscursor_qws.cpp.

588 {
589  //####
590 #if 1 || defined(QT_NO_QWS_CURSOR) || defined(QT_NO_QWS_ALHPA_CURSOR)
591  Q_UNUSED(dropx);
592  Q_UNUSED(dropy);
593 #else
594  if (cursor.width() + dropx > 64 || cursor.height() + dropy > 64)
595  return;
596 
597  if (!cursor.hasAlphaBuffer()) {
598  cursor.setAlphaBuffer(true);
599 
600  const int nblur=4;
601  const int darkness=140;
602 
603  QImage drop(cursor.width()+dropx+nblur, cursor.height()+dropy+nblur, 8, 18);
604  drop.setColor(0, 0xff000000); // bg (black)
605  drop.setColor(1, 0xffffffff); // fg (white)
606  for (int i=0; i<16; i++) {
607  drop.setColor(2+i, (darkness*i/16)<<24);
608  }
609  drop.fill(2); // all trans
610  QImage drop2 = drop.copy();
611 
612  int cp;
613 
614  // made solid shadow
615  for (int row = 0; row < cursor.height(); row++) {
616  for (int col = 0; col < cursor.width(); col++) {
617  cp = cursor.pixelIndex(col, row);
618  if (cp != 2)
619  drop.setPixel(col+dropx, row+dropy, 17);
620  }
621  }
622 
623  // blur shadow
624  for (int blur=0; blur<nblur; blur++) {
625  QImage& to((blur&1)?drop:drop2);
626  QImage& from((blur&1)?drop2:drop);
627  for (int row = 1; row < drop.height()-1; row++) {
628  for (int col = 1; col < drop.width()-1; col++) {
629  int t=0;
630  for (int dx=-1; dx<=1; dx++) {
631  for (int dy=-1; dy<=1; dy++) {
632  t += from.pixelIndex(col+dx,row+dy)-2;
633  }
634  }
635  to.setPixel(col,row,2+t/9);
636  }
637  }
638  }
639 
640  // copy cursor
641  for (int row = 0; row < cursor.height(); row++) {
642  for (int col = 0; col < cursor.width(); col++) {
643  cp = cursor.pixelIndex(col, row);
644  if (cp != 2)
645  drop.setPixel(col, row, cp);
646  }
647  }
648 
649  cursor = drop;
650  }
651 #endif
652 }
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
Definition: qimage.cpp:1410
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
QImage cursor
Definition: qwscursor_qws.h:76
int pixelIndex(int x, int y) const
Returns the pixel index at (x, y).
Definition: qimage.cpp:4194
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
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
#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

◆ createSystemCursor()

void QWSCursor::createSystemCursor ( int  id)
staticprivate

Definition at line 384 of file qwscursor_qws.cpp.

385 {
386 #ifdef QT_NO_QWS_CURSOR
387  Q_UNUSED(id);
388 #else
389  if (!systemCursorTableInit) {
390  for (int i = 0; i <= Qt::LastCursor; i++)
391  systemCursorTable[i] = 0;
393  systemCursorTableInit = true;
394  }
395  switch (id) {
396  // 16x16 cursors
397  case Qt::ArrowCursor:
399  new QWSCursor(cur_arrow_bits, mcur_arrow_bits, 16, 16, 0, 0);
400  break;
401 
402  case Qt::UpArrowCursor:
404  new QWSCursor(cur_up_arrow_bits, mcur_up_arrow_bits, 16, 16, 7, 0);
405  break;
406 
407  case Qt::CrossCursor:
409  new QWSCursor(cur_cross_bits, mcur_cross_bits, 16, 16, 7, 7);
410  break;
411 
412  case Qt::IBeamCursor:
414  new QWSCursor(cur_ibeam_bits, mcur_ibeam_bits, 16, 16, 7, 7);
415  break;
416 
417  case Qt::SizeVerCursor:
419  new QWSCursor(cur_ver_bits, mcur_ver_bits, 16, 16, 7, 7);
420  break;
421 
422  case Qt::SizeHorCursor:
424  new QWSCursor(cur_hor_bits, mcur_hor_bits, 16, 16, 7, 7);
425  break;
426 
427  case Qt::SizeBDiagCursor:
429  new QWSCursor(cur_bdiag_bits, mcur_bdiag_bits, 16, 16, 7, 7);
430  break;
431 
432  case Qt::SizeFDiagCursor:
434  new QWSCursor(cur_fdiag_bits, mcur_fdiag_bits, 16, 16, 7, 7);
435  break;
436 
437  case Qt::BlankCursor:
439  new QWSCursor(0, 0, 0, 0, 0, 0);
440  break;
441 
442  // 20x20 cursors
443  case Qt::ForbiddenCursor:
445  new QWSCursor(forbidden_bits, forbiddenm_bits, 20, 20, 10, 10);
446  break;
447 
448  // 32x32 cursors
449  case Qt::WaitCursor:
451  new QWSCursor(wait_data_bits, wait_mask_bits, 32, 32, 15, 15);
452  break;
453 
454  case Qt::SplitVCursor:
456  new QWSCursor(vsplit_bits, vsplitm_bits, 32, 32, 15, 15);
457  break;
458 
459  case Qt::SplitHCursor:
461  new QWSCursor(hsplit_bits, hsplitm_bits, 32, 32, 15, 15);
462  break;
463 
464  case Qt::SizeAllCursor:
466  new QWSCursor(size_all_data_bits, size_all_mask_bits, 32, 32, 15, 15);
467  break;
468 
471  new QWSCursor(phand_bits, phandm_bits, 32, 32, 0, 0);
472  break;
473 
474  case Qt::WhatsThisCursor:
476  new QWSCursor(whatsthis_bits, whatsthism_bits, 32, 32, 0, 0);
477  break;
478  case Qt::BusyCursor:
480  new QWSCursor(busy_bits, busym_bits, 32, 32, 0, 0);
481  break;
482 
483  case Qt::OpenHandCursor:
485  new QWSCursor(openhand_bits, openhandm_bits, 16, 16, 8, 8);
486  break;
489  new QWSCursor(closedhand_bits, closedhandm_bits, 16, 16, 8, 8);
490  break;
491  default:
492  qWarning("Unknown system cursor %d", id);
493  }
494 #endif
495 }
static void cleanupSystemCursorTable()
static const uchar hsplit_bits[]
static const uchar size_all_mask_bits[]
static const uchar closedhandm_bits[]
static QWSCursor * systemCursorTable[Qt::LastCursor+1]
static const unsigned char cur_cross_bits[]
static const uchar phand_bits[]
static const uchar vsplit_bits[]
void qAddPostRoutine(QtCleanUpFunction p)
static const uchar openhandm_bits[]
static const uchar cur_bdiag_bits[]
static const uchar openhand_bits[]
static const uchar mcur_ibeam_bits[]
static const uchar cur_hor_bits[]
static const uchar mcur_ver_bits[]
static const uchar closedhand_bits[]
static const uchar whatsthis_bits[]
static const uchar phandm_bits[]
static const uchar mcur_hor_bits[]
static const uchar busy_bits[]
static const uchar hsplitm_bits[]
static const uchar mcur_arrow_bits[]
static const uchar busym_bits[]
static const uchar cur_arrow_bits[]
static const uchar whatsthism_bits[]
static const unsigned char mcur_cross_bits[]
Q_CORE_EXPORT void qWarning(const char *,...)
static const uchar forbidden_bits[]
static const unsigned char cur_up_arrow_bits[]
static const uchar vsplitm_bits[]
static const uchar size_all_data_bits[]
static const uchar wait_data_bits[]
static const uchar wait_mask_bits[]
static const uchar cur_ibeam_bits[]
static const unsigned char mcur_up_arrow_bits[]
static const uchar mcur_bdiag_bits[]
static const uchar cur_ver_bits[]
#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
static const uchar mcur_fdiag_bits[]
static const uchar forbiddenm_bits[]
static bool systemCursorTableInit
static const uchar cur_fdiag_bits[]

◆ hotSpot()

QPoint QWSCursor::hotSpot ( ) const
inline

Definition at line 65 of file qwscursor_qws.h.

Referenced by QWSServerPrivate::setCursor().

65 { return hot; }
QPoint hot
Definition: qwscursor_qws.h:75

◆ image()

QImage& QWSCursor::image ( )
inline

Definition at line 66 of file qwscursor_qws.h.

Referenced by QWSServerPrivate::setCursor().

66 { return cursor; }
QImage cursor
Definition: qwscursor_qws.h:76

◆ set()

void QWSCursor::set ( const uchar data,
const uchar mask,
int  width,
int  height,
int  hotX,
int  hotY 
)

Definition at line 518 of file qwscursor_qws.cpp.

520 {
521 #ifdef QT_NO_QWS_CURSOR
522  Q_UNUSED(data);
523  Q_UNUSED(mask);
524  Q_UNUSED(width);
525  Q_UNUSED(height);
526  Q_UNUSED(hx);
527  Q_UNUSED(hy);
528 #else
529  hot.setX(hx);
530  hot.setY(hy);
531 
532  cursor = QImage(width,height, QImage::Format_Indexed8);
533 
534  if (!width || !height || !data || !mask || cursor.isNull())
535  return;
536 
538  cursor.setColor(0, 0xff000000);
539  cursor.setColor(1, 0xffffffff);
540  cursor.setColor(2, 0x00000000);
541 
542  int bytesPerLine = (width + 7) / 8;
543  int p = 0;
544  int d, m;
545 
546  int x = -1, w = 0;
547 
548  uchar *cursor_data = cursor.bits();
549  int bpl = cursor.bytesPerLine();
550  for (int i = 0; i < height; i++)
551  {
552  for (int j = 0; j < bytesPerLine; j++, data++, mask++)
553  {
554  for (int b = 0; b < 8 && j*8+b < width; b++)
555  {
556  d = *data & (1 << b);
557  m = *mask & (1 << b);
558  if (d && m) p = 0;
559  else if (!d && m) p = 1;
560  else p = 2;
561  cursor_data[j*8+b] = p;
562 
563  // calc region
564  if (x < 0 && m)
565  x = j*8+b;
566  else if (x >= 0 && !m) {
567  x = -1;
568  w = 0;
569  }
570  if (m)
571  w++;
572  }
573  }
574  if (x >= 0) {
575  x = -1;
576  w = 0;
577  }
578  cursor_data += bpl;
579  }
580 
582  createDropShadow(5, 2);
583 #endif
584 }
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
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
bool supportsAlphaCursor() const
Definition: qscreen_qws.h:146
QPoint hot
Definition: qwscursor_qws.h:75
QImage cursor
Definition: qwscursor_qws.h:76
unsigned char uchar
Definition: qglobal.h:994
void setColorCount(int)
Resizes the color table to contain colorCount entries.
Definition: qimage.cpp:2275
void createDropShadow(int dropx, int dropy)
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
Q_GUI_EXPORT QScreenCursor * qt_screencursor
Definition: qscreen_qws.cpp:67
void setX(int x)
Sets the x coordinate of this point to the given x coordinate.
Definition: qpoint.h:134
#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

◆ systemCursor()

QWSCursor * QWSCursor::systemCursor ( int  id)
static

Definition at line 497 of file qwscursor_qws.cpp.

Referenced by QWSServerPrivate::initializeCursor(), QWSServerPrivate::invokeSelectCursor(), QWSServerPrivate::sendMouseEventUnfiltered(), QWSServerPrivate::setCursor(), and QWSServer::setCursorVisible().

498 {
499  QWSCursor *cursor = 0;
500 #ifdef QT_NO_QWS_CURSOR
501  Q_UNUSED(id);
502 #else
503  if (id >= 0 && id <= Qt::LastCursor) {
504  if (!systemCursorTable[id])
505  createSystemCursor(id);
506  cursor = systemCursorTable[id];
507  }
508 
509  if (cursor == 0) {
511  createSystemCursor(Qt::ArrowCursor);
513  }
514 #endif
515  return cursor;
516 }
static void createSystemCursor(int id)
static QWSCursor * systemCursorTable[Qt::LastCursor+1]
QImage cursor
Definition: qwscursor_qws.h:76
#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

Properties

◆ cursor

QImage QWSCursor::cursor
private

Definition at line 76 of file qwscursor_qws.h.

◆ hot

QPoint QWSCursor::hot
private

Definition at line 75 of file qwscursor_qws.h.


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