source: trunk/examples/cursor/cursor.cpp

Last change on this file was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 5.0 KB
Line 
1/****************************************************************************
2** $Id: cursor.cpp 2 2005-11-16 15:49:26Z dmik $
3**
4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
5**
6** This file is part of an example program for Qt. This example
7** program may be used, distributed and modified without limitation.
8**
9*****************************************************************************/
10
11#include <qlabel.h>
12#include <qbitmap.h>
13#include <qapplication.h>
14#include <qlayout.h>
15#include <qcursor.h>
16
17// cb_bits and cm_bits were generated by X bitmap program.
18
19#define cb_width 32
20#define cb_height 32
21
22static unsigned char cb_bits[] = { // cursor bitmap
23 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x0f, 0x00,
24 0x00, 0x06, 0x30, 0x00, 0x80, 0x01, 0xc0, 0x00, 0x40, 0x00, 0x00, 0x01,
25 0x20, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x04, 0x08, 0x3e, 0x3e, 0x08,
26 0x08, 0x03, 0xe0, 0x08, 0xc4, 0x00, 0x00, 0x11, 0x04, 0x1e, 0x78, 0x10,
27 0x02, 0x0c, 0x30, 0x20, 0x02, 0x40, 0x00, 0x20, 0x02, 0x40, 0x00, 0x20,
28 0x02, 0x40, 0x00, 0x20, 0x02, 0x20, 0x04, 0x20, 0x02, 0x20, 0x04, 0x20,
29 0x02, 0x10, 0x08, 0x20, 0x02, 0x08, 0x08, 0x20, 0x02, 0xf0, 0x07, 0x20,
30 0x04, 0x00, 0x00, 0x10, 0x04, 0x00, 0x00, 0x10, 0x08, 0x00, 0xc0, 0x08,
31 0x08, 0x3c, 0x30, 0x08, 0x10, 0xe6, 0x19, 0x04, 0x20, 0x00, 0x0f, 0x02,
32 0x40, 0x00, 0x00, 0x01, 0x80, 0x01, 0xc0, 0x00, 0x00, 0x06, 0x30, 0x00,
33 0x00, 0xf8, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00};
34
35#define cm_width 32
36#define cm_height 32
37
38static unsigned char cm_bits[] = { // cursor bitmap mask
39 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0xfe, 0x3f, 0x00,
40 0x80, 0x07, 0xf0, 0x00, 0xc0, 0x01, 0xc0, 0x01, 0x60, 0x00, 0x00, 0x03,
41 0x30, 0x00, 0x00, 0x06, 0x18, 0x00, 0x00, 0x0c, 0x0c, 0x3e, 0x3e, 0x18,
42 0x0e, 0x03, 0xe0, 0x18, 0xc6, 0x00, 0x00, 0x31, 0x07, 0x1e, 0x78, 0x30,
43 0x03, 0x0c, 0x30, 0x60, 0x03, 0x40, 0x00, 0x60, 0x03, 0x40, 0x00, 0x60,
44 0x03, 0x40, 0x00, 0x60, 0x03, 0x20, 0x04, 0x60, 0x03, 0x20, 0x04, 0x60,
45 0x03, 0x10, 0x08, 0x60, 0x03, 0x08, 0x08, 0x60, 0x03, 0xf0, 0x07, 0x60,
46 0x06, 0x00, 0x00, 0x30, 0x06, 0x00, 0x00, 0x30, 0x0c, 0x00, 0xc0, 0x18,
47 0x0c, 0x3c, 0x30, 0x18, 0x18, 0xe6, 0x19, 0x0c, 0x30, 0x00, 0x0f, 0x06,
48 0x60, 0x00, 0x00, 0x03, 0xc0, 0x01, 0xc0, 0x01, 0x80, 0x07, 0xf0, 0x00,
49 0x00, 0xfe, 0x3f, 0x00, 0x00, 0xf8, 0x0f, 0x00};
50
51
52//
53// The CursorView contains many labels with different cursors.
54//
55
56class CursorView : public QWidget // cursor view
57{
58public:
59 CursorView();
60};
61
62//
63// Constructs a cursor view.
64//
65
66CursorView::CursorView() // construct view
67{
68 struct List {
69 CursorShape shape;
70 const char* name; // cursor name
71 };
72 static List list[] = {
73 { ArrowCursor, "arrowCursor" },
74 { UpArrowCursor, "upArrowCursor" },
75 { CrossCursor, "crossCursor" },
76 { WaitCursor, "waitCursor" },
77 { IbeamCursor, "ibeamCursor" },
78 { SizeVerCursor, "sizeVerCursor" },
79 { SizeHorCursor, "sizeHorCursor" },
80 { SizeBDiagCursor, "sizeBDiagCursor" },
81 { SizeFDiagCursor, "sizeFDiagCursor" },
82 { SizeAllCursor, "sizeAllCursor" },
83 { BlankCursor, "blankCursor" },
84 { SplitVCursor, "splitVCursor" },
85 { SplitHCursor, "splitHCursor" },
86 { PointingHandCursor, "pointingHandCursor" },
87 { ForbiddenCursor, "forbiddenCursor" },
88 { WhatsThisCursor, "whatsThisCursor" },
89 { BusyCursor, "busyCursor" }
90 };
91
92 setCaption( "CursorView" ); // set window caption
93
94 QGridLayout* grid = new QGridLayout( this, 5, 4, 20 );
95 QLabel *label;
96
97 int i=0;
98 for ( int y=0; y<4; y++ ) { // create the small labels
99 for ( int x=0; x<4; x++ ) {
100 label = new QLabel( this );
101 label->setCursor( QCursor( list[i].shape ) );
102 label->setText( list[i].name );
103 label->setAlignment( AlignCenter );
104 label->setMargin( 10 );
105 label->setFrameStyle( QFrame::Box | QFrame::Raised );
106 grid->addWidget( label, x, y );
107 i++;
108 }
109 }
110
111
112 label = new QLabel( this );
113 label->setCursor( QCursor( list[i].shape ) );
114 label->setText( list[i].name );
115 label->setAlignment( AlignCenter );
116 label->setMargin( 10 );
117 label->setFrameStyle( QFrame::Box | QFrame::Raised );
118 grid->addWidget( label, 4, 0 );
119
120
121
122 QBitmap cb( cb_width, cb_height, cb_bits, TRUE );
123 QBitmap cm( cm_width, cm_height, cm_bits, TRUE );
124 QCursor custom( cb, cm ); // create bitmap cursor
125
126 label = new QLabel( this ); // create the big label
127 label->setCursor( custom );
128 label->setText( "Custom bitmap cursor" );
129 label->setAlignment( AlignCenter );
130 label->setMargin( 10 );
131 label->setFrameStyle( QFrame::Box | QFrame::Sunken );
132 grid->addMultiCellWidget( label, 4, 4, 1, 3 );
133
134}
135
136
137//
138// Create and display a CursorView.
139//
140
141int main( int argc, char **argv )
142{
143 QApplication a( argc, argv ); // application object
144 CursorView v; // cursor view
145 a.setMainWidget( &v );
146 v.setCaption("Qt Example - Cursors");
147 v.show();
148 return a.exec();
149}
Note: See TracBrowser for help on using the repository browser.