1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>
Qt Toolkit - xform/xform.cpp example file
</title><style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }
--></style>
</head><body bgcolor="#ffffff">
<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>
<h1 align=center>Transformed Graphics Demo</h1><br clear="all">
This example lets the user rotate, shear and scale text and graphics
arbitrarily.
<hr>
Implementation:
<pre>/****************************************************************************
** $Id: qt/examples/xform/xform.cpp 2.3.1 edited 2001-01-26 $
**
** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
**
** This file is part of an example program for Qt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include <<a name="qapplication.h"></a><a href="qapplication-h.html">qapplication.h</a>>
#include <<a name="qdialog.h"></a><a href="qdialog-h.html">qdialog.h</a>>
#include <<a name="qlabel.h"></a><a href="qlabel-h.html">qlabel.h</a>>
#include <<a name="qlineedit.h"></a><a href="qlineedit-h.html">qlineedit.h</a>>
#include <<a name="qpushbutton.h"></a><a href="qpushbutton-h.html">qpushbutton.h</a>>
#include <<a name="qcheckbox.h"></a><a href="qcheckbox-h.html">qcheckbox.h</a>>
#include <<a name="qradiobutton.h"></a><a href="qradiobutton-h.html">qradiobutton.h</a>>
#include <<a name="qbuttongroup.h"></a><a href="qbuttongroup-h.html">qbuttongroup.h</a>>
#include <<a name="qlcdnumber.h"></a><a href="qlcdnumber-h.html">qlcdnumber.h</a>>
#include <<a name="qslider.h"></a><a href="qslider-h.html">qslider.h</a>>
#include <<a name="qmenubar.h"></a><a href="qmenubar-h.html">qmenubar.h</a>>
#include <<a name="qfontdialog.h"></a><a href="qfontdialog-h.html">qfontdialog.h</a>>
#include <<a name="qlayout.h"></a><a href="qlayout-h.html">qlayout.h</a>>
#include <<a name="qvbox.h"></a><a href="qvbox-h.html">qvbox.h</a>>
#include <<a name="qwidgetstack.h"></a><a href="qwidgetstack-h.html">qwidgetstack.h</a>>
#include <<a name="qpainter.h"></a><a href="qpainter-h.html">qpainter.h</a>>
#include <<a name="qpixmap.h"></a><a href="qpixmap-h.html">qpixmap.h</a>>
#include <<a name="qpicture.h"></a><a href="qpicture-h.html">qpicture.h</a>>
#include <stdlib.h>
class ModeNames {
public:
enum Mode { Text, Image, Picture };
};
class XFormControl : public QVBox, public ModeNames
{
Q_OBJECT
public:
XFormControl( const QFont &initialFont, QWidget *parent=0, const char *name=0 );
~XFormControl() {}
<a name="QWMatrix"></a><a href="qwmatrix.html">QWMatrix</a> matrix();
signals:
void newMatrix( <a href="qwmatrix.html">QWMatrix</a> );
void newText( const QString& );
void newFont( const QFont & );
void newMode( int );
private slots:
void newMtx();
void newTxt(const QString&);
void selectFont();
void fontSelected( const QFont & );
void changeMode(int);
void timerEvent(<a name="QTimerEvent"></a><a href="qtimerevent.html">QTimerEvent</a>*);
private:
Mode mode;
<a name="QSlider"></a><a href="qslider.html">QSlider</a> *rotS; // Rotation angle scroll bar
<a href="qslider.html">QSlider</a> *shearS; // Shear value scroll bar
<a href="qslider.html">QSlider</a> *magS; // Magnification value scroll bar
<a name="QLCDNumber"></a><a href="qlcdnumber.html">QLCDNumber</a> *rotLCD; // Rotation angle LCD display
<a href="qlcdnumber.html">QLCDNumber</a> *shearLCD; // Shear value LCD display
<a href="qlcdnumber.html">QLCDNumber</a> *magLCD; // Magnification value LCD display
<a name="QCheckBox"></a><a href="qcheckbox.html">QCheckBox</a> *mirror; // Checkbox for mirror image on/of
<a name="QWidgetStack"></a><a href="qwidgetstack.html">QWidgetStack</a>* optionals;
<a name="QLineEdit"></a><a href="qlineedit.html">QLineEdit</a> *textEd; // Inp[ut field for xForm text
<a name="QPushButton"></a><a href="qpushbutton.html">QPushButton</a> *fpb; // Select font push button
<a name="QRadioButton"></a><a href="qradiobutton.html">QRadioButton</a> *rb_txt; // Radio button for text
<a href="qradiobutton.html">QRadioButton</a> *rb_img; // Radio button for image
<a href="qradiobutton.html">QRadioButton</a> *rb_pic; // Radio button for picture
<a name="QFont"></a><a href="qfont.html">QFont</a> currentFont;
};
/*
ShowXForm displays a text or a pixmap (<a name="QPixmap"></a><a href="qpixmap.html">QPixmap</a>) using a coordinate
transformation matrix (<a href="qwmatrix.html">QWMatrix</a>)
*/
class ShowXForm : public QWidget, public ModeNames
{
Q_OBJECT
public:
ShowXForm( const QFont &f, QWidget *parent=0, const char *name=0 );
~ShowXForm() {}
void showIt(); // (Re)displays text or pixmap
Mode mode() const { return m; }
public slots:
void setText( const QString& );
void setMatrix( <a href="qwmatrix.html">QWMatrix</a> );
void setFont( const QFont &f );
void setPixmap( <a href="qpixmap.html">QPixmap</a> );
void setPicture( const QPicture& );
void setMode( int );
private:
<a name="QSizePolicy"></a><a href="qsizepolicy.html">QSizePolicy</a> sizePolicy() const;
<a name="QSize"></a><a href="qsize.html">QSize</a> sizeHint() const;
void paintEvent( <a name="QPaintEvent"></a><a href="qpaintevent.html">QPaintEvent</a> * );
void resizeEvent( <a name="QResizeEvent"></a><a href="qresizeevent.html">QResizeEvent</a> * );
<a href="qwmatrix.html">QWMatrix</a> mtx; // coordinate transform matrix
<a name="QString"></a><a href="qstring.html">QString</a> text; // text to be displayed
<a href="qpixmap.html">QPixmap</a> pix; // pixmap to be displayed
<a name="QPicture"></a><a href="qpicture.html">QPicture</a> picture; // text to be displayed
<a name="QRect"></a><a href="qrect.html">QRect</a> eraseRect; // covers last displayed text/pixmap
Mode m;
};
XFormControl::XFormControl( const QFont &initialFont,
<a name="QWidget"></a><a href="qwidget.html">QWidget</a> *parent, const char *name )
: <a name="QVBox"></a><a href="qvbox.html">QVBox</a>( parent, name )
{
setSpacing(6);
setMargin(6);
currentFont = initialFont;
mode = Image;
rotLCD = new <a href="qlcdnumber.html">QLCDNumber</a>( 4, this, "rotateLCD" );
rotS = new <a href="qslider.html">QSlider</a>( QSlider::Horizontal, this,
"rotateSlider" );
shearLCD = new <a href="qlcdnumber.html">QLCDNumber</a>( 5,this, "shearLCD" );
shearS = new <a href="qslider.html">QSlider</a>( QSlider::Horizontal, this,
"shearSlider" );
mirror = new <a href="qcheckbox.html">QCheckBox</a>( this, "mirrorCheckBox" );
rb_txt = new <a href="qradiobutton.html">QRadioButton</a>( this, "text" );
rb_img = new <a href="qradiobutton.html">QRadioButton</a>( this, "image" );
rb_pic = new <a href="qradiobutton.html">QRadioButton</a>( this, "picture" );
optionals = new <a href="qwidgetstack.html">QWidgetStack</a>(this);
<a href="qvbox.html">QVBox</a>* optionals_text = new <a href="qvbox.html">QVBox</a>(optionals);
optionals_text-><a name="setSpacing"></a><a href="qhbox.html#d8c6a6">setSpacing</a>(6);
<a href="qvbox.html">QVBox</a>* optionals_other = new <a href="qvbox.html">QVBox</a>(optionals);
optionals_other-><a href="qhbox.html#d8c6a6">setSpacing</a>(6);
optionals-><a name="addWidget"></a><a href="qwidgetstack.html#30e890">addWidget</a>(optionals_text,0);
optionals-><a href="qwidgetstack.html#30e890">addWidget</a>(optionals_other,1);
fpb = new <a href="qpushbutton.html">QPushButton</a>( optionals_text, "text" );
textEd = new <a href="qlineedit.html">QLineEdit</a>( optionals_text, "text" );
textEd-><a name="setFocus"></a><a href="qwidget.html#666b3c">setFocus</a>();
rotLCD-><a name="display"></a><a href="qlcdnumber.html#0eaac4">display</a>( " 0'" );
rotS-><a name="setRange"></a><a href="qrangecontrol.html#0337f8">setRange</a>( -180, 180 );
rotS-><a name="setValue"></a><a href="qslider.html#c5cce4">setValue</a>( 0 );
connect( rotS, SIGNAL(valueChanged(int)), SLOT(newMtx()) );
shearLCD-><a href="qlcdnumber.html#0eaac4">display</a>( "0.00" );
shearS-><a href="qrangecontrol.html#0337f8">setRange</a>( -25, 25 );
shearS-><a href="qslider.html#c5cce4">setValue</a>( 0 );
connect( shearS, SIGNAL(valueChanged(int)), SLOT(newMtx()) );
mirror-><a name="setText"></a><a href="qbutton.html#58c887">setText</a>( tr("Mirror") );
connect( mirror, SIGNAL(clicked()), SLOT(newMtx()) );
<a name="QButtonGroup"></a><a href="qbuttongroup.html">QButtonGroup</a> *bg = new <a href="qbuttongroup.html">QButtonGroup</a>(this);
bg-><a name="hide"></a><a href="qwidget.html#bc7c6a">hide</a>();
bg-><a name="insert"></a><a href="qbuttongroup.html#067bec">insert</a>(rb_txt,0);
bg-><a href="qbuttongroup.html#067bec">insert</a>(rb_img,1);
bg-><a href="qbuttongroup.html#067bec">insert</a>(rb_pic,2);
rb_txt-><a href="qbutton.html#58c887">setText</a>( tr("Text") );
rb_img-><a href="qbutton.html#58c887">setText</a>( tr("Image") );
rb_img-><a name="setChecked"></a><a href="qradiobutton.html#11e2e3">setChecked</a>(TRUE);
rb_pic-><a href="qbutton.html#58c887">setText</a>( tr("Picture") );
connect( bg, SIGNAL(clicked(int)), SLOT(changeMode(int)) );
fpb-><a href="qbutton.html#58c887">setText</a>( tr("Select font...") );
connect( fpb, SIGNAL(clicked()), SLOT(selectFont()) );
textEd-><a name="setText"></a><a href="qlineedit.html#b85aa3">setText</a>( "Troll" );
connect( textEd, SIGNAL(textChanged(const QString&)),
SLOT(newTxt(const QString&)) );
magLCD = new <a href="qlcdnumber.html">QLCDNumber</a>( 4,optionals_other, "magLCD" );
magLCD-><a href="qlcdnumber.html#0eaac4">display</a>( "100" );
magS = new <a href="qslider.html">QSlider</a>( QSlider::Horizontal, optionals_other,
"magnifySlider" );
magS-><a href="qrangecontrol.html#0337f8">setRange</a>( 0, 800 );
connect( magS, SIGNAL(valueChanged(int)), SLOT(newMtx()) );
magS-><a href="qslider.html#c5cce4">setValue</a>( 0 );
connect( magS, SIGNAL(valueChanged(int)), magLCD, SLOT(display(int)));
optionals_text-><a name="adjustSize"></a><a href="qwidget.html#ab3108">adjustSize</a>();
optionals_other-><a href="qwidget.html#ab3108">adjustSize</a>();
changeMode(Image);
startTimer(20); // start an initial animation
}
void <a name="149"></a>XFormControl::timerEvent(<a href="qtimerevent.html">QTimerEvent</a>*)
{
int v = magS-><a name="value"></a><a href="qslider.html#8f52b8">value</a>();
v = (v+2)+v/10;
if ( v >= 200 ) {
v = 200;
<a name="killTimers"></a><a href="qobject.html#66592d">killTimers</a>();
}
magS-><a href="qslider.html#c5cce4">setValue</a>(v);
}
/*
Called whenever the user has changed one of the matrix parameters
(i.e. rotate, shear or magnification)
*/
void <a name="150"></a>XFormControl::newMtx()
{
emit newMatrix( <a name="matrix"></a><a href="#152">matrix</a>() );
}
void <a name="151"></a>XFormControl::newTxt(const QString& s)
{
emit newText(s);
<a name="changeMode"></a><a href="#155">changeMode</a>(Text);
}
/*
Calculates the matrix appropriate for the current controls,
and updates the displays.
*/
<a href="qwmatrix.html">QWMatrix</a> <a name="152"></a>XFormControl::matrix()
{
<a href="qwmatrix.html">QWMatrix</a> m;
if (mode != Text) {
double magVal = 1.0*magS-><a href="qslider.html#8f52b8">value</a>()/100;
m.<a name="scale"></a><a href="qwmatrix.html#a5e455">scale</a>( magVal, magVal );
}
double shearVal = 1.0*shearS-><a href="qslider.html#8f52b8">value</a>()/25;
m.<a name="shear"></a><a href="qwmatrix.html#8eb34f">shear</a>( shearVal, shearVal );
m.<a name="rotate"></a><a href="qwmatrix.html#84df75">rotate</a>( rotS-><a href="qslider.html#8f52b8">value</a>() );
if ( mirror-><a name="isChecked"></a><a href="qcheckbox.html#30acb4">isChecked</a>() ) {
m.<a href="qwmatrix.html#a5e455">scale</a>( 1, -1 );
m.<a href="qwmatrix.html#84df75">rotate</a>( 180 );
}
<a href="qstring.html">QString</a> tmp;
tmp.<a name="sprintf"></a><a href="qstring.html#2eb9bc">sprintf</a>( "%1.2f", shearVal );
if ( shearVal >= 0 )
tmp.<a name="insert"></a><a href="qstring.html#2a68e1">insert</a>( 0, " " );
shearLCD-><a href="qlcdnumber.html#0eaac4">display</a>( tmp );
int rot = rotS-><a href="qslider.html#8f52b8">value</a>();
if ( rot < 0 )
rot = rot + 360;
tmp.<a href="qstring.html#2eb9bc">sprintf</a>( "%3i'", rot );
rotLCD-><a href="qlcdnumber.html#0eaac4">display</a>( tmp );
return m;
}
void <a name="153"></a>XFormControl::selectFont()
{
bool ok;
<a href="qfont.html">QFont</a> f = QFontDialog::getFont( &ok, currentFont );
if ( ok ) {
currentFont = f;
<a name="fontSelected"></a><a href="#154">fontSelected</a>( f );
}
}
void <a name="154"></a>XFormControl::fontSelected( const QFont &font )
{
emit newFont( font );
<a href=#155>changeMode</a>(Text);
}
/*
Sets the mode - Text, Image, or Picture.
*/
void <a name="155"></a>XFormControl::changeMode(int m)
{
mode = (Mode)m;
emit newMode( m );
<a name="newMtx"></a><a href="#150">newMtx</a>();
if ( mode == Text ) {
optionals-><a name="raiseWidget"></a><a href="qwidgetstack.html#271afe">raiseWidget</a>(0);
rb_txt-><a href="qradiobutton.html#11e2e3">setChecked</a>(TRUE);
} else {
optionals-><a href="qwidgetstack.html#271afe">raiseWidget</a>(1);
if ( mode == Image )
rb_img-><a href="qradiobutton.html#11e2e3">setChecked</a>(TRUE);
else
rb_pic-><a href="qradiobutton.html#11e2e3">setChecked</a>(TRUE);
}
qApp->flushX();
}
ShowXForm::ShowXForm( const QFont &initialFont,
<a href="qwidget.html">QWidget</a> *parent, const char *name )
: <a href="qwidget.html">QWidget</a>( parent, name, WResizeNoErase )
{
<a name="setFont"></a><a href="qwidget.html#dde00b">setFont</a>( initialFont );
<a name="setBackgroundColor"></a><a href="qwidget.html#721b7d">setBackgroundColor</a>( white );
m = Text;
eraseRect = QRect( 0, 0, 0, 0 );
}
<a href="qsizepolicy.html">QSizePolicy</a> <a name="138"></a>ShowXForm::sizePolicy() const
{
return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
}
<a href="qsize.html">QSize</a> <a name="139"></a>ShowXForm::sizeHint() const
{
return QSize(400,400);
}
void <a name="140"></a>ShowXForm::paintEvent( <a href="qpaintevent.html">QPaintEvent</a> * )
{
<a name="showIt"></a><a href="#148">showIt</a>();
}
void <a name="141"></a>ShowXForm::resizeEvent( <a href="qresizeevent.html">QResizeEvent</a> * )
{
eraseRect = QRect( <a name="width"></a><a href="qwidget.html#576663">width</a>()/2, <a name="height"></a><a href="qwidget.html#180786">height</a>()/2, 0, 0 );
<a name="repaint"></a><a href="qwidget.html#977d49">repaint</a>(rect());
}
void <a name="142"></a>ShowXForm::setText( const QString& s )
{
text = s;
<a href=#148>showIt</a>();
}
void <a name="143"></a>ShowXForm::setMatrix( <a href="qwmatrix.html">QWMatrix</a> w )
{
mtx = w;
<a href=#148>showIt</a>();
}
void <a name="144"></a>ShowXForm::setFont( const QFont &f )
{
m = Text;
<a name="setFont"></a><a href="qwidget.html#26de4b">QWidget::setFont</a>( f );
}
void <a name="145"></a>ShowXForm::setPixmap( <a href="qpixmap.html">QPixmap</a> pm )
{
pix = pm;
m = Image;
<a href=#148>showIt</a>();
}
void <a name="146"></a>ShowXForm::setPicture( const QPicture& p )
{
picture = p;
m = Picture;
<a href=#148>showIt</a>();
}
void <a name="147"></a>ShowXForm::setMode( int mode )
{
m = (Mode)mode;
}
void <a name="148"></a>ShowXForm::showIt()
{
<a name="QPainter"></a><a href="qpainter.html">QPainter</a> p;
<a href="qrect.html">QRect</a> r; // rectangle covering new text/pixmap in virtual coordinates
<a href="qwmatrix.html">QWMatrix</a> um; // copy user specified transform
int textYPos = 0; // distance from boundingRect y pos to baseline
int textXPos = 0; // distance from boundingRect x pos to text start
<a href="qrect.html">QRect</a> br;
<a name="QFontMetrics"></a><a href="qfontmetrics.html">QFontMetrics</a> fm( <a name="fontMetrics"></a><a href="qwidget.html#d0d02b">fontMetrics</a>() ); // get widget font metrics
switch ( mode() ) {
case Text:
br = fm.<a name="boundingRect"></a><a href="qfontmetrics.html#0f95c3">boundingRect</a>( text ); // rectangle covering text
r = br;
textYPos = -r.<a name="y"></a><a href="qrect.html#65e614">y</a>();
textXPos = -r.<a name="x"></a><a href="qrect.html#3a3d38">x</a>();
br.<a name="moveTopLeft"></a><a href="qrect.html#39b545">moveTopLeft</a>( <a name="QPoint"></a><a href="qpoint.html">QPoint</a>( -br.<a name="width"></a><a href="qrect.html#44fb71">width</a>()/2, -br.<a name="height"></a><a href="qrect.html#5d9fd1">height</a>()/2 ) );
break;
case Image:
r = pix.<a name="rect"></a><a href="qpixmap.html#1c205e">rect</a>();
break;
case Picture:
// ### need QPicture::boundingRect()
r = QRect(0,0,1000,1000);
break;
}
r.<a href="qrect.html#39b545">moveTopLeft</a>( <a href="qpoint.html">QPoint</a>(-r.<a href="qrect.html#44fb71">width</a>()/2, -r.<a href="qrect.html#5d9fd1">height</a>()/2) );
// compute union of new and old rect
// the resulting rectangle will cover what is already displayed
// and have room for the new text/pixmap
eraseRect = eraseRect.<a name="unite"></a><a href="qrect.html#dd997c">unite</a>( mtx.<a name="map"></a><a href="qwmatrix.html#38577f">map</a>(r) );
eraseRect.<a name="moveBy"></a><a href="qrect.html#35f691">moveBy</a>( -1, -1 ); // add border for matrix round off
eraseRect.<a name="setSize"></a><a href="qrect.html#ba264e">setSize</a>( <a href="qsize.html">QSize</a>( eraseRect.<a href="qrect.html#44fb71">width</a>() + 2,eraseRect.<a href="qrect.html#5d9fd1">height</a>() + 2 ) );
int pw = QMIN(eraseRect.<a href="qrect.html#44fb71">width</a>(),<a href="qwidget.html#576663">width</a>());
int ph = QMIN(eraseRect.<a href="qrect.html#5d9fd1">height</a>(),<a href="qwidget.html#180786">height</a>());
<a href="qpixmap.html">QPixmap</a> pm( pw, ph ); // off-screen drawing pixmap
pm.<a name="fill"></a><a href="qpixmap.html#e584bd">fill</a>( <a name="backgroundColor"></a><a href="qwidget.html#370ea4">backgroundColor</a>() );
p.begin( &pm );
um.<a name="translate"></a><a href="qwmatrix.html#226fc6">translate</a>( pw/2, ph/2 ); // 0,0 is center
um = mtx * um;
p.setWorldMatrix( um );
switch ( mode() ) {
case Text:
p.setFont( <a name="font"></a><a href="qwidget.html#3a7237">font</a>() ); // use widget font
p.drawText( r.<a name="left"></a><a href="qrect.html#d0f453">left</a>() + textXPos, r.<a name="top"></a><a href="qrect.html#a9c6db">top</a>() + textYPos, text );
#if 0
p.setPen( red );
p.drawRect( br );
#endif
break;
case Image:
p.drawPixmap( -pix.<a name="width"></a><a href="qpixmap.html#443c1f">width</a>()/2, -pix.<a name="height"></a><a href="qpixmap.html#1d578d">height</a>()/2, pix );
//QPixmap rotated = pix.<a name="xForm"></a><a href="qpixmap.html#3b77c0">xForm</a>(mtx);
//bitBlt( &pm, pm.<a href="qpixmap.html#443c1f">width</a>()/2 - rotated.width()/2,
//pm.<a href="qpixmap.html#1d578d">height</a>()/2 - rotated.height()/2, &rotated );
break;
case Picture:
// ### need QPicture::boundingRect()
p.scale(0.25,0.25);
p.translate(-230,-180);
p.drawPicture( picture );
}
p.end();
int xpos = width()/2 - pw/2;
int ypos = height()/2 - ph/2;
<a name="bitBlt"></a><a href="qpaintdevice.html#058006">bitBlt</a>( this, xpos, ypos, // copy pixmap to widget
&pm, 0, 0, -1, -1 );
eraseRect = mtx.<a href="qwmatrix.html#38577f">map</a>( r );
}
/*
Grand unifying widget, putting ShowXForm and XFormControl
together.
*/
class XFormCenter : public QHBox, public ModeNames
{
Q_OBJECT
public:
XFormCenter( <a href="qwidget.html">QWidget</a> *parent=0, const char *name=0 );
public slots:
void setFont( const QFont &f ) { sx-><a href="qwidget.html#26de4b">setFont</a>( f ); }
void newMode( int );
private:
ShowXForm *sx;
XFormControl *xc;
};
void <a name="137"></a>XFormCenter::newMode( int m )
{
static bool first_i = TRUE;
static bool first_p = TRUE;
if ( sx->mode() == m )
return;
if ( m == Image && first_i ) {
first_i = FALSE;
<a href="qpixmap.html">QPixmap</a> pm;
if ( pm.<a name="load"></a><a href="qpixmap.html#775e08">load</a>( "image.any" ) )
sx->setPixmap( pm );
return;
}
if ( m == Picture && first_p ) {
first_p = FALSE;
<a href="qpicture.html">QPicture</a> p;
if (p.<a name="load"></a><a href="qpicture.html#acc5b8">load</a>( "picture.any" ))
sx->setPicture( p );
return;
}
sx->setMode(m);
}
XFormCenter::XFormCenter( <a href="qwidget.html">QWidget</a> *parent, const char *name )
: <a name="QHBox"></a><a href="qhbox.html">QHBox</a>( parent, name )
{
<a href="qfont.html">QFont</a> f( "Charter", 36, QFont::Bold );
xc = new XFormControl( f, this );
sx = new ShowXForm( f, this );
<a name="setStretchFactor"></a><a href="qhbox.html#b97571">setStretchFactor</a>(sx,1);
xc-><a name="setFrameStyle"></a><a href="qframe.html#c0d758">setFrameStyle</a>( QFrame::Panel | QFrame::Raised );
xc-><a name="setLineWidth"></a><a href="qframe.html#bffeeb">setLineWidth</a>( 2 );
<a name="connect"></a><a href="qobject.html#c2d209">connect</a>( xc, SIGNAL(newText(const QString&)), sx,
SLOT(setText(const QString&)) );
<a href="qobject.html#c2d209">connect</a>( xc, SIGNAL(newMatrix(<a href="qwmatrix.html">QWMatrix</a>)),
sx, SLOT(setMatrix(<a href="qwmatrix.html">QWMatrix</a>)) );
<a href="qobject.html#c2d209">connect</a>( xc, SIGNAL(newFont(const QFont&)), sx,
SLOT(<a href="qwidget.html#dde00b">setFont</a>(const QFont&)) );
<a href="qobject.html#c2d209">connect</a>( xc, SIGNAL(<a name="newMode"></a><a href="#137">newMode</a>(int)), SLOT(<a href=#137>newMode</a>(int)) );
sx->setText( "Troll" );
<a href=#137>newMode</a>( Image );
sx->setMatrix(xc->matrix());
}
int main( int argc, char **argv )
{
<a name="QApplication"></a><a href="qapplication.html">QApplication</a> a( argc, argv );
XFormCenter *xfc = new XFormCenter;
a.<a name="setMainWidget"></a><a href="qapplication.html#11c921">setMainWidget</a>( xfc );
xfc-><a name="show"></a><a href="qwidget.html#ccc8f7">show</a>();
return a.<a name="exec"></a><a href="qapplication.html#7076af">exec</a>();
}
#include "xform.moc" // include metadata generated by the moc
</pre>
<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright 2000 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.1</div>
</table></div></address></body></html>
|