Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 112b0974ad288f6cd55bf971ee6026a9 > files > 2327

libqt3-devel-3.0.2-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /tmp/qt-3.0-reggie-28534/qt-x11-free-3.0.2/examples/xform/xform.doc:4 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Transformed Graphics Demo</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: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Transformed Graphics Demo</h1>

   
<p> 
This example lets the user rotate, shear and scale text and graphics
arbitrarily.
<p> <hr>
<p> Implementation:
<p> <pre>/****************************************************************************
** $Id:  qt/xform.cpp   3.0.2   edited Oct 12 12:18 $
**
** 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 &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;

#include &lt;<a href="qdialog-h.html">qdialog.h</a>&gt;
#include &lt;<a href="qlabel-h.html">qlabel.h</a>&gt;
#include &lt;<a href="qlineedit-h.html">qlineedit.h</a>&gt;
#include &lt;<a href="qpushbutton-h.html">qpushbutton.h</a>&gt;
#include &lt;<a href="qcheckbox-h.html">qcheckbox.h</a>&gt;
#include &lt;<a href="qradiobutton-h.html">qradiobutton.h</a>&gt;
#include &lt;<a href="qbuttongroup-h.html">qbuttongroup.h</a>&gt;
#include &lt;<a href="qlcdnumber-h.html">qlcdnumber.h</a>&gt;
#include &lt;<a href="qslider-h.html">qslider.h</a>&gt;
#include &lt;<a href="qmenubar-h.html">qmenubar.h</a>&gt;
#include &lt;<a href="qfontdialog-h.html">qfontdialog.h</a>&gt;
#include &lt;<a href="qlayout-h.html">qlayout.h</a>&gt;
#include &lt;<a href="qvbox-h.html">qvbox.h</a>&gt;
#include &lt;<a href="qwidgetstack-h.html">qwidgetstack.h</a>&gt;

#include &lt;<a href="qpainter-h.html">qpainter.h</a>&gt;
#include &lt;<a href="qpixmap-h.html">qpixmap.h</a>&gt;
#include &lt;<a href="qpicture-h.html">qpicture.h</a>&gt;

#include &lt;stdlib.h&gt;


class ModeNames {
public:
    enum Mode { Text, Image, Picture };
};


class XFormControl : public <a href="qvbox.html">QVBox</a>, public ModeNames
{
    <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
public:
    XFormControl( const <a href="qfont.html">QFont</a> &amp;initialFont, QWidget *parent=0, const char *name=0 );
   ~XFormControl() {}

    <a href="qwmatrix.html">QWMatrix</a> matrix();

signals:
    void newMatrix( <a href="qwmatrix.html">QWMatrix</a> );
    void newText( const <a href="qstring.html">QString</a>&amp; );
    void newFont( const <a href="qfont.html">QFont</a> &amp; );
    void newMode( int );
private slots:
    void newMtx();
    void newTxt(const <a href="qstring.html">QString</a>&amp;);
    void selectFont();
    void fontSelected( const <a href="qfont.html">QFont</a> &amp; );
    void changeMode(int);
    void timerEvent(QTimerEvent*);
private:
    Mode mode;
    <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 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 href="qcheckbox.html">QCheckBox</a>    *mirror;              // Checkbox for mirror image on/of
    <a href="qwidgetstack.html">QWidgetStack</a>* optionals;
    <a href="qlineedit.html">QLineEdit</a>    *textEd;              // Inp[ut field for xForm text
    <a href="qpushbutton.html">QPushButton</a>  *fpb;                 // Select font push button
    <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 href="qfont.html">QFont</a> currentFont;
};

/*
  ShowXForm displays a text or a pixmap (QPixmap) using a coordinate
  transformation matrix (QWMatrix)
*/

class ShowXForm : public <a href="qwidget.html">QWidget</a>, public ModeNames
{
    Q_OBJECT
public:
    ShowXForm( const <a href="qfont.html">QFont</a> &amp;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 <a href="qstring.html">QString</a>&amp; );
    void setMatrix( <a href="qwmatrix.html">QWMatrix</a> );
    void setFont( const <a href="qfont.html">QFont</a> &amp;f );
    void setPixmap( <a href="qpixmap.html">QPixmap</a> );
    void setPicture( const <a href="qpicture.html">QPicture</a>&amp; );
    void setMode( int );
private:
    <a href="qsizepolicy.html">QSizePolicy</a> sizePolicy() const;
    <a href="qsize.html">QSize</a> sizeHint() const;
    void paintEvent( <a href="qpaintevent.html">QPaintEvent</a> * );
    void resizeEvent( <a href="qresizeevent.html">QResizeEvent</a> * );
    <a href="qwmatrix.html">QWMatrix</a>  mtx;                      // coordinate transform matrix
    <a href="qstring.html">QString</a>   text;                     // text to be displayed
    <a href="qpixmap.html">QPixmap</a>   pix;                      // pixmap to be displayed
    <a href="qpicture.html">QPicture</a>  picture;                  // text to be displayed
    <a href="qrect.html">QRect</a>     eraseRect;                // covers last displayed text/pixmap
    Mode      m;
};

<a name="f162"></a>XFormControl::XFormControl( const <a href="qfont.html">QFont</a> &amp;initialFont,
                            <a href="qwidget.html">QWidget</a> *parent, const char *name )
        : <a href="qvbox.html">QVBox</a>( parent, name )
{
    <a href="qhbox.html#setSpacing">setSpacing</a>(6);
    <a href="qframe.html#setMargin">setMargin</a>(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);
<a name="x82"></a>    optionals_text-&gt;<a href="qhbox.html#setSpacing">setSpacing</a>(6);
    <a href="qvbox.html">QVBox</a>* optionals_other = new <a href="qvbox.html">QVBox</a>(optionals);
    optionals_other-&gt;<a href="qhbox.html#setSpacing">setSpacing</a>(6);
<a name="x132"></a>    optionals-&gt;<a href="qwidgetstack.html#addWidget">addWidget</a>(optionals_text,0);
    optionals-&gt;<a href="qwidgetstack.html#addWidget">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" );
<a name="x127"></a>    textEd-&gt;<a href="qwidget.html#setFocus">setFocus</a>();

<a name="x83"></a>    rotLCD-&gt;<a href="qlcdnumber.html#display">display</a>( "  0'" );

<a name="x106"></a>    rotS-&gt;<a href="qrangecontrol.html#setRange">setRange</a>( -180, 180 );
<a name="x117"></a>    rotS-&gt;<a href="qslider.html#setValue">setValue</a>( 0 );
<a name="x119"></a>    <a href="qobject.html#connect">connect</a>( rotS, SIGNAL(<a href="qslider.html#valueChanged">valueChanged</a>(int)), SLOT(newMtx()) );

    shearLCD-&gt;<a href="qlcdnumber.html#display">display</a>( "0.00" );

    shearS-&gt;<a href="qrangecontrol.html#setRange">setRange</a>( -25, 25 );
    shearS-&gt;<a href="qslider.html#setValue">setValue</a>( 0 );
    <a href="qobject.html#connect">connect</a>( shearS, SIGNAL(<a href="qslider.html#valueChanged">valueChanged</a>(int)), SLOT(newMtx()) );

<a name="x74"></a>    mirror-&gt;<a href="qbutton.html#setText">setText</a>( <a href="qobject.html#tr">tr</a>("Mirror") );
    <a href="qobject.html#connect">connect</a>( mirror, SIGNAL(<a href="qbutton.html#clicked">clicked</a>()), SLOT(newMtx()) );

    <a href="qbuttongroup.html">QButtonGroup</a> *bg = new <a href="qbuttongroup.html">QButtonGroup</a>(this);
<a name="x123"></a>    bg-&gt;<a href="qwidget.html#hide">hide</a>();
<a name="x76"></a>    bg-&gt;<a href="qbuttongroup.html#insert">insert</a>(rb_txt,0);
    bg-&gt;<a href="qbuttongroup.html#insert">insert</a>(rb_img,1);
    bg-&gt;<a href="qbuttongroup.html#insert">insert</a>(rb_pic,2);
    rb_txt-&gt;<a href="qbutton.html#setText">setText</a>( <a href="qobject.html#tr">tr</a>("Text") );
    rb_img-&gt;<a href="qbutton.html#setText">setText</a>( <a href="qobject.html#tr">tr</a>("Image") );
<a name="x105"></a>    rb_img-&gt;<a href="qradiobutton.html#setChecked">setChecked</a>(TRUE);
    rb_pic-&gt;<a href="qbutton.html#setText">setText</a>( <a href="qobject.html#tr">tr</a>("Picture") );
<a name="x75"></a>    <a href="qobject.html#connect">connect</a>( bg, SIGNAL(<a href="qbuttongroup.html#clicked">clicked</a>(int)), SLOT(changeMode(int)) );

    fpb-&gt;<a href="qbutton.html#setText">setText</a>( <a href="qobject.html#tr">tr</a>("Select font...") );
    <a href="qobject.html#connect">connect</a>( fpb, SIGNAL(<a href="qbutton.html#clicked">clicked</a>()), SLOT(selectFont()) );

<a name="x84"></a>    textEd-&gt;<a href="qlineedit.html#setText">setText</a>( "Troll" );
<a name="x85"></a>    <a href="qobject.html#connect">connect</a>( textEd, SIGNAL(<a href="qlineedit.html#textChanged">textChanged</a>(const <a href="qstring.html">QString</a>&amp;)),
                     SLOT(newTxt(const <a href="qstring.html">QString</a>&amp;)) );

    magLCD = new <a href="qlcdnumber.html">QLCDNumber</a>( 4,optionals_other, "magLCD" );
    magLCD-&gt;<a href="qlcdnumber.html#display">display</a>( "100" );
    magS = new <a href="qslider.html">QSlider</a>( QSlider::Horizontal, optionals_other,
                           "magnifySlider" );
    magS-&gt;<a href="qrangecontrol.html#setRange">setRange</a>( 0, 800 );
    <a href="qobject.html#connect">connect</a>( magS, SIGNAL(<a href="qslider.html#valueChanged">valueChanged</a>(int)), SLOT(newMtx()) );
    magS-&gt;<a href="qslider.html#setValue">setValue</a>( 0 );
    <a href="qobject.html#connect">connect</a>( magS, SIGNAL(<a href="qslider.html#valueChanged">valueChanged</a>(int)), magLCD, SLOT(<a href="qlcdnumber.html#display">display</a>(int)));

<a name="x122"></a>    optionals_text-&gt;<a href="qwidget.html#adjustSize">adjustSize</a>();
    optionals_other-&gt;<a href="qwidget.html#adjustSize">adjustSize</a>();
    changeMode(Image);

    <a href="qobject.html#startTimer">startTimer</a>(20); // start an initial animation
}

<a name="x86"></a>void XFormControl::<a href="qobject.html#timerEvent">timerEvent</a>(QTimerEvent*)
{
<a name="x118"></a>    int v = magS-&gt;<a href="qslider.html#value">value</a>();
    v = (v+2)+v/10;
    if ( v &gt;= 200 ) {
        v = 200;
        <a href="qobject.html#killTimers">killTimers</a>();
    }
    magS-&gt;<a href="qslider.html#setValue">setValue</a>(v);
}



/*
    Called whenever the user has changed one of the matrix parameters
    (i.e. rotate, shear or magnification)
*/
void <a name="f163"></a>XFormControl::newMtx()
{
    emit newMatrix( matrix() );
}

void <a name="f164"></a>XFormControl::newTxt(const <a href="qstring.html">QString</a>&amp; s)
{
    emit newText(s);
    changeMode(Text);
}

/*
    Calculates the matrix appropriate for the current controls,
    and updates the displays.
*/
QWMatrix <a name="f165"></a>XFormControl::matrix()
{
    <a href="qwmatrix.html">QWMatrix</a> m;
    if (mode != Text) {
        double magVal = 1.0*magS-&gt;<a href="qslider.html#value">value</a>()/100;
<a name="x136"></a>        m.<a href="qwmatrix.html#scale">scale</a>( magVal, magVal );
    }
    double shearVal = 1.0*shearS-&gt;<a href="qslider.html#value">value</a>()/25;
<a name="x137"></a>    m.<a href="qwmatrix.html#shear">shear</a>( shearVal, shearVal );
<a name="x135"></a>    m.<a href="qwmatrix.html#rotate">rotate</a>( rotS-&gt;<a href="qslider.html#value">value</a>() );
<a name="x77"></a>    if ( mirror-&gt;<a href="qcheckbox.html#isChecked">isChecked</a>() ) {
        m.<a href="qwmatrix.html#scale">scale</a>( 1, -1 );
        m.<a href="qwmatrix.html#rotate">rotate</a>( 180 );
    }

    <a href="qstring.html">QString</a> tmp;
<a name="x121"></a>    tmp.<a href="qstring.html#sprintf">sprintf</a>( "%1.2f", shearVal  );
    if ( shearVal &gt;= 0 )
<a name="x120"></a>        tmp.<a href="qstring.html#insert">insert</a>( 0, " " );
    shearLCD-&gt;<a href="qlcdnumber.html#display">display</a>( tmp );

    int rot = rotS-&gt;<a href="qslider.html#value">value</a>();
    if ( rot &lt; 0 )
        rot = rot + 360;
    tmp.<a href="qstring.html#sprintf">sprintf</a>( "%3i'", rot );
    rotLCD-&gt;<a href="qlcdnumber.html#display">display</a>( tmp );
    return m;
}


void <a name="f166"></a>XFormControl::selectFont()
{
    bool ok;
<a name="x78"></a>    <a href="qfont.html">QFont</a> f = QFontDialog::<a href="qfontdialog.html#getFont">getFont</a>( &amp;ok, currentFont );
    if ( ok ) {
        currentFont = f;
        fontSelected( f );
    }
}

void <a name="f167"></a>XFormControl::fontSelected( const <a href="qfont.html">QFont</a> &amp;font )
{
    emit newFont( font );
    changeMode(Text);
}

/*
    Sets the mode - Text, Image, or Picture.
*/

void <a name="f168"></a>XFormControl::changeMode(int m)
{
    mode = (Mode)m;

    emit newMode( m );
    newMtx();
    if ( mode == Text ) {
<a name="x133"></a>        optionals-&gt;<a href="qwidgetstack.html#raiseWidget">raiseWidget</a>(0);
        rb_txt-&gt;<a href="qradiobutton.html#setChecked">setChecked</a>(TRUE);
    } else {
        optionals-&gt;<a href="qwidgetstack.html#raiseWidget">raiseWidget</a>(1);
        if ( mode == Image )
            rb_img-&gt;<a href="qradiobutton.html#setChecked">setChecked</a>(TRUE);
        else
            rb_pic-&gt;<a href="qradiobutton.html#setChecked">setChecked</a>(TRUE);
    }
<a name="x71"></a>    qApp-&gt;<a href="qapplication.html#flushX">flushX</a>();
}

<a name="f153"></a>ShowXForm::ShowXForm( const <a href="qfont.html">QFont</a> &amp;initialFont,
                      <a href="qwidget.html">QWidget</a> *parent, const char *name )
        : <a href="qwidget.html">QWidget</a>( parent, name, WResizeNoErase )
{
    <a href="qwidget.html#setFont">setFont</a>( initialFont );
    <a href="qwidget.html#setBackgroundColor">setBackgroundColor</a>( white );
    m = Text;
    eraseRect = QRect( 0, 0, 0, 0 );
}

<a name="x131"></a>QSizePolicy ShowXForm::<a href="qwidget.html#sizePolicy">sizePolicy</a>() const
{
    return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
}

QSize ShowXForm::<a href="qwidget.html#sizeHint">sizeHint</a>() const
{
    return QSize(400,400);
}

void ShowXForm::<a href="qwidget.html#paintEvent">paintEvent</a>( <a href="qpaintevent.html">QPaintEvent</a> * )
{
    showIt();
}

void ShowXForm::<a href="qwidget.html#resizeEvent">resizeEvent</a>( <a href="qresizeevent.html">QResizeEvent</a> * )
{
    eraseRect = QRect( <a href="qwidget.html#width">width</a>()/2, height()/2, 0, 0 );
    <a href="qwidget.html#repaint">repaint</a>(<a href="qwidget.html#rect">rect</a>());
}

void <a name="f154"></a>ShowXForm::setText( const <a href="qstring.html">QString</a>&amp; s )
{
    text = s;
    showIt();
}

void <a name="f155"></a>ShowXForm::setMatrix( <a href="qwmatrix.html">QWMatrix</a> w )
{
    mtx = w;
    showIt();
}

<a name="x128"></a>void ShowXForm::<a href="qwidget.html#setFont">setFont</a>( const <a href="qfont.html">QFont</a> &amp;f )
{
    m = Text;
    QWidget::<a href="qwidget.html#setFont">setFont</a>( f );
}

void <a name="f156"></a>ShowXForm::setPixmap( <a href="qpixmap.html">QPixmap</a> pm )
{
    pix  = pm;
    m    = Image;
    showIt();
}

void <a name="f157"></a>ShowXForm::setPicture( const <a href="qpicture.html">QPicture</a>&amp; p )
{
    picture = p;
    m = Picture;
    showIt();
}

void <a name="f158"></a>ShowXForm::setMode( int mode )
{
    m = (Mode)mode;
}

void <a name="f159"></a>ShowXForm::showIt()
{
    <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 href="qfontmetrics.html">QFontMetrics</a> fm( <a href="qwidget.html#fontMetrics">fontMetrics</a>() );   // get widget font metrics
    switch ( mode() ) {
      case Text:
<a name="x79"></a>        br = fm.<a href="qfontmetrics.html#boundingRect">boundingRect</a>( text );   // rectangle covering text
        r  = br;
        textYPos = -r.<a href="qrect.html#y">y</a>();
        textXPos = -r.<a href="qrect.html#x">x</a>();
<a name="x114"></a><a name="x110"></a><a name="x107"></a>        br.<a href="qrect.html#moveTopLeft">moveTopLeft</a>( QPoint( -br.<a href="qrect.html#width">width</a>()/2, -br.<a href="qrect.html#height">height</a>()/2 ) );
        break;
      case Image:
<a name="x102"></a>        r = pix.<a href="qpixmap.html#rect">rect</a>();
        break;
      case Picture:
        // ### need QPicture::boundingRect()
        r = QRect(0,0,1000,1000);
        break;
    }
    r.<a href="qrect.html#moveTopLeft">moveTopLeft</a>( QPoint(-r.<a href="qrect.html#width">width</a>()/2, -r.<a href="qrect.html#height">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
<a name="x134"></a><a name="x113"></a>    eraseRect = eraseRect.<a href="qrect.html#unite">unite</a>( mtx.<a href="qwmatrix.html#map">map</a>(r) );
<a name="x109"></a>    eraseRect.<a href="qrect.html#moveBy">moveBy</a>( -1, -1 ); // add border for matrix round off
<a name="x111"></a>    eraseRect.<a href="qrect.html#setSize">setSize</a>( QSize( eraseRect.<a href="qrect.html#width">width</a>() + 2,eraseRect.<a href="qrect.html#height">height</a>() + 2 ) );
    int pw = QMIN(eraseRect.<a href="qrect.html#width">width</a>(),width());
    int ph = QMIN(eraseRect.<a href="qrect.html#height">height</a>(),height());
    <a href="qpixmap.html">QPixmap</a> pm( pw, ph );               // off-screen drawing pixmap
<a name="x99"></a>    pm.<a href="qpixmap.html#fill">fill</a>( <a href="qwidget.html#backgroundColor">backgroundColor</a>() );

<a name="x87"></a>    p.<a href="qpainter.html#begin">begin</a>( &amp;pm );
<a name="x138"></a>    um.<a href="qwmatrix.html#translate">translate</a>( pw/2, ph/2 ); // 0,0 is center
    um = mtx * um;
<a name="x96"></a>    p.<a href="qpainter.html#setWorldMatrix">setWorldMatrix</a>( um );
    switch ( mode() ) {
      case Text:
<a name="x94"></a>        p.<a href="qpainter.html#setFont">setFont</a>( <a href="qwidget.html#font">font</a>() );            // use widget font
<a name="x112"></a><a name="x108"></a>        p.<a href="qpainter.html#drawText">drawText</a>( r.<a href="qrect.html#left">left</a>() + textXPos, r.<a href="qrect.html#top">top</a>() + textYPos, text );
#if 0
        p.<a href="qpainter.html#setPen">setPen</a>( red );
        p.<a href="qpainter.html#drawRect">drawRect</a>( br );
#endif
        break;
      case Image:
<a name="x89"></a><a name="x103"></a><a name="x100"></a>        p.<a href="qpainter.html#drawPixmap">drawPixmap</a>( -pix.<a href="qpixmap.html#width">width</a>()/2, -pix.<a href="qpixmap.html#height">height</a>()/2, pix );
<a name="x104"></a>        //QPixmap rotated = pix.<a href="qpixmap.html#xForm">xForm</a>(mtx);
        //bitBlt( &amp;pm, pm.<a href="qpixmap.html#width">width</a>()/2 - rotated.width()/2,
                //pm.<a href="qpixmap.html#height">height</a>()/2 - rotated.height()/2, &amp;rotated );
        break;
      case Picture:
        // ### need QPicture::boundingRect()
<a name="x93"></a>        p.<a href="qpainter.html#scale">scale</a>(0.25,0.25);
<a name="x97"></a>        p.<a href="qpainter.html#translate">translate</a>(-230,-180);
<a name="x88"></a>        p.<a href="qpainter.html#drawPicture">drawPicture</a>( picture );
    }
<a name="x92"></a>    p.<a href="qpainter.html#end">end</a>();

    int xpos = <a href="qwidget.html#width">width</a>()/2  - pw/2;
    int ypos = <a href="qwidget.html#height">height</a>()/2 - ph/2;
    <a href="qpaintdevice.html#bitBlt-2">bitBlt</a>( this, xpos, ypos,                   // copy pixmap to widget
            &amp;pm, 0, 0, -1, -1 );
    eraseRect =  mtx.<a href="qwmatrix.html#map">map</a>( r );
}


/*
    Grand unifying widget, putting ShowXForm and XFormControl
    together.
*/

class XFormCenter : public <a href="qhbox.html">QHBox</a>, public ModeNames
{
    Q_OBJECT
public:
    XFormCenter( <a href="qwidget.html">QWidget</a> *parent=0, const char *name=0 );
public slots:
    void setFont( const <a href="qfont.html">QFont</a> &amp;f ) { sx-&gt;<a href="qwidget.html#setFont">setFont</a>( f ); }
    void newMode( int );
private:
    ShowXForm   *sx;
    XFormControl *xc;
};

void <a name="f160"></a>XFormCenter::newMode( int m )
{
    static bool first_i = TRUE;
    static bool first_p = TRUE;

    if ( sx-&gt;mode() == m )
        return;
    if ( m == Image &amp;&amp; first_i ) {
        first_i = FALSE;
        <a href="qpixmap.html">QPixmap</a> pm;
<a name="x101"></a>        if ( pm.<a href="qpixmap.html#load">load</a>( "image.any" ) )
            sx-&gt;setPixmap( pm );
        return;
    }
    if ( m == Picture &amp;&amp; first_p ) {
        first_p = FALSE;
        <a href="qpicture.html">QPicture</a> p;
<a name="x98"></a>        if (p.<a href="qpicture.html#load">load</a>( "picture.any" ))
            sx-&gt;setPicture( p );
        return;
    }
    sx-&gt;setMode(m);
}

<a name="f161"></a>XFormCenter::XFormCenter( <a href="qwidget.html">QWidget</a> *parent, const char *name )
    : <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 href="qhbox.html#setStretchFactor">setStretchFactor</a>(sx,1);
    xc-&gt;<a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::Panel | QFrame::Raised );
<a name="x81"></a>    xc-&gt;<a href="qframe.html#setLineWidth">setLineWidth</a>( 2 );
    <a href="qobject.html#connect">connect</a>( xc, SIGNAL(newText(const <a href="qstring.html">QString</a>&amp;)), sx,
                 SLOT(setText(const <a href="qstring.html">QString</a>&amp;)) );
    <a href="qobject.html#connect">connect</a>( xc, SIGNAL(newMatrix(QWMatrix)),
             sx, SLOT(setMatrix(QWMatrix)) );
    <a href="qobject.html#connect">connect</a>( xc, SIGNAL(newFont(const <a href="qfont.html">QFont</a>&amp;)), sx,
                 SLOT(<a href="qwidget.html#setFont">setFont</a>(const <a href="qfont.html">QFont</a>&amp;)) );
    <a href="qobject.html#connect">connect</a>( xc, SIGNAL(newMode(int)), SLOT(newMode(int)) );
    sx-&gt;setText( "Troll" );
    newMode( Image );
    sx-&gt;setMatrix(xc-&gt;matrix());
}


int main( int argc, char **argv )
{
    <a href="qapplication.html">QApplication</a> a( argc, argv );

    XFormCenter *xfc = new XFormCenter;

    a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( xfc );
    xfc-&gt;<a href="qwidget.html#setCaption">setCaption</a>("Qt Example - XForm");
    xfc-&gt;<a href="qwidget.html#show">show</a>();
    return a.<a href="qapplication.html#exec">exec</a>();
}

#include "xform.moc"                  // include metadata generated by the <a href="moc.html#moc">moc</a>
</pre>

<p>See also <a href="examples.html">Examples</a>.

<!-- eof -->
<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2001 
<a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt version 3.0.2</div>
</table></div></address></body>
</html>