Home HomeGriffin Kate Matthew Swift 03 Neonowy dwórEnoch Suzanne Rodzina Griffinów 02 Zaproszenie do grzechuGriffin Kate Matthew Swift 02 Nocny BurmistrzBarton Beverly Griffin Powell 05 Cichy zabójcaWEB Griffin [Badge Of Honor 02] Special OperationsGriffin W.E.B. Braterstwo broni 07 Nowy GatunekWEB Griffin [BoW 03] The MajorsW.E.B Griffin Więzy honoru 2 Krew i honorW.E.B Griffin Ostatni bohaterowie 4 Walka agentówW.E.B Griffin Ostatni bohaterowie 1 Dwa fronty

[ Pobierz całość w formacie PDF ]
.setMainWidget(cursormouse);34 return(app.exec());35 }3637 CursorMouse::CursorMouse(QWidget *parent,const char *name)38 : QWidget(parent,name)39 {40 QHBoxLayout *horlayout = new QHBoxLayout(this);4142 QListBox *list = new QListBox(this);43 for(int i=0; iinsertItem(curs[i].name);45 horlayout->addWidget(list);46 connect(list,SIGNAL(highlighted(int)),47 this,SLOT(changeCursor(int)));4849 QVBoxLayout *verlayout = new QVBoxLayout(30);5051 selectButton = new QPushButton( Select ,this);52 selectButton->setMinimumSize(selectButton->sizeHint());53 verlayout->addWidget(selectButton);54 connect(selectButton,SIGNAL(clicked()),55 this,SLOT(selectCursor()));5657 exitButton = new QPushButton( Exit ,this);58 exitButton->setMinimumSize(exitButton->sizeHint());59 verlayout->addWidget(exitButton);60 connect(exitButton,SIGNAL(clicked()),61 this,SLOT(shutdown()));6263 horlayout->addLayout(verlayout);6465 resize(250,200);66 horlayout->activate();67 }68 void CursorMouse::changeCursor(int index)69 {70 cursorID = curs[index].number;71 setCursor(QCursor(cursorID));72 }73 void CursorMouse::selectCursor()74 { 4682-1 ch08.f.qc 11/13/00 14:11 Page 187Chapter 8 &' The Mouse and the Keyboard18775 selectButton->setCursor(QCursor(cursorID));76 }77 void CursorMouse::shutdown()78 {79 kapp->exit(0);80 }The array on lines 7 through 26 holds the names and ID numbers of the predefinedcursors.The names are used as the selection text in a list box, and the ID values areused as arguments on the constructor of QCursor.The CursorMouseclass, defined beginning on line 37, is the top-level widget of theapplication.It uses a horizontal box to hold a QListBoxon the left, and a verticalbox with two buttons on the right, as shown previously in Figure 8-3.The list box is created on line 43.The loop on lines 43 and 44 populate the list boxwith the cursor names.The call to connect()on line 46 connects the list box sig-nal named highlighted()to the local slot named changeCursor().The changeCursor()slot will be executed whenever a list box member is highlighted.It isn tused here, but there is also a selected()signal from the list box that requires adouble-click on a list box member.Both of these list box signals supply the indexnumber of the list box item.The selectButtonis created on line 51, and it has its clicked()signal connectedto the local slot selectCursor().The exitButtonis created on line 57, with itsclicked()signal connected to the local slot shutdown().The slot method changeCursor()on line 68 is passed the index of each newlyselected list box item.The text of the list box was loaded from the array names, sothe index from the list box is also an index into the array.Line 70 extracts the cur-sor ID from the array and makes it the current cursor ID number by storing it incursorID.The call to setCursor()on line 71 sets the cursor to the one suppliedas the argument.The QCursorconstructor accepts the cursor ID of one of the pre-defined cursors, as selected from the list box.The slot method selectCursor()on line 73 sets the cursor of the selectButtonto whatever is the currently selected cursor.If no cursor is ever set for this button,it will use the same one as its parent window (that is, the cursor defined on line 71).Once the call to setCursor()on line 75 has been made, the selectButtonwill useits own cursor.All of this means that three cursors are being used in this one application.Thedefault cursor (the one named ArrowCursor) will continue to be used for the titlebar of the main window.Whichever cursor is currently highlighted in the list boxwill be used for everything else inside the main window.The only exception is thatthe Select button will have its own cursor  it will be the one that was highlightedwhen the button was selected. 4682-1 ch08.f.qc 11/13/00 14:11 Page 188Part II &' Step by Step188There are a couple of special cursors in the list.The cursor named BlankCursorhas no graphic  the cursor simply disappears.It is a valid cursor in that you canstill move it around and try to find things to click on, but you can t see it.The otherspecial cursor is the one named BitmapCursor.For this to work, you must supply acursor of your own making, which is the subject of the next section.Designing Your Own CursorA cursor is a rectangle of pixels.Each pixel can be black, white, or transparent.For example, the KDE default arrow cursor is a black arrow with a white outline.Allthe other pixels are transparent [ Pobierz całość w formacie PDF ]