⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xform-xform-cpp.html

📁 qtopiaphone英文帮助,用于初学者和开发人员,初学者可以用来学习,开发人员可以用来资料查询.
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!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>  <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" align="center" size=32>Qte</font></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>/****************************************************************************** &#36;Id&#58; qt/examples/xform/xform.cpp   2.3.8   edited 2004-05-12 $**** 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 name="qapplication.h"></a><a href="qapplication-h.html">qapplication.h</a>&gt;#include &lt;<a name="qdialog.h"></a><a href="qdialog-h.html">qdialog.h</a>&gt;#include &lt;<a name="qlabel.h"></a><a href="qlabel-h.html">qlabel.h</a>&gt;#include &lt;<a name="qlineedit.h"></a><a href="qlineedit-h.html">qlineedit.h</a>&gt;#include &lt;<a name="qpushbutton.h"></a><a href="qpushbutton-h.html">qpushbutton.h</a>&gt;#include &lt;<a name="qcheckbox.h"></a><a href="qcheckbox-h.html">qcheckbox.h</a>&gt;#include &lt;<a name="qradiobutton.h"></a><a href="qradiobutton-h.html">qradiobutton.h</a>&gt;#include &lt;<a name="qbuttongroup.h"></a><a href="qbuttongroup-h.html">qbuttongroup.h</a>&gt;#include &lt;<a name="qlcdnumber.h"></a><a href="qlcdnumber-h.html">qlcdnumber.h</a>&gt;#include &lt;<a name="qslider.h"></a><a href="qslider-h.html">qslider.h</a>&gt;#include &lt;<a name="qmenubar.h"></a><a href="qmenubar-h.html">qmenubar.h</a>&gt;#include &lt;<a name="qfontdialog.h"></a><a href="qfontdialog-h.html">qfontdialog.h</a>&gt;#include &lt;<a name="qlayout.h"></a><a href="qlayout-h.html">qlayout.h</a>&gt;#include &lt;<a name="qvbox.h"></a><a href="qvbox-h.html">qvbox.h</a>&gt;#include &lt;<a name="qwidgetstack.h"></a><a href="qwidgetstack-h.html">qwidgetstack.h</a>&gt;#include &lt;<a name="qpainter.h"></a><a href="qpainter-h.html">qpainter.h</a>&gt;#include &lt;<a name="qpixmap.h"></a><a href="qpixmap-h.html">qpixmap.h</a>&gt;#include &lt;<a name="qpicture.h"></a><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 QVBox, public ModeNames{    Q_OBJECTpublic:    XFormControl( const QFont &amp;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&amp; );    void newFont( const QFont &amp; );    void newMode( int );private slots:    void newMtx();    void newTxt(const QString&amp;);    void selectFont();    void fontSelected( const QFont &amp; );    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_OBJECTpublic:    ShowXForm( const QFont &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 QString&amp; );    void setMatrix( <a href="qwmatrix.html">QWMatrix</a> );    void setFont( const QFont &amp;f );    void setPixmap( <a href="qpixmap.html">QPixmap</a> );    void setPicture( const QPicture&amp; );    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 &amp;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-&gt;<a name="setSpacing"></a><a href="qhbox.html#0075a0">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#0075a0">setSpacing</a>(6);    optionals-&gt;<a name="addWidget"></a><a href="qwidgetstack.html#562b2f">addWidget</a>(optionals_text,0);    optionals-&gt;<a href="qwidgetstack.html#562b2f">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-&gt;<a name="setFocus"></a><a href="qwidget.html#25775a">setFocus</a>();    rotLCD-&gt;<a name="display"></a><a href="qlcdnumber.html#ecdf88">display</a>( "  0'" );    rotS-&gt;<a name="setRange"></a><a href="qrangecontrol.html#f2409c">setRange</a>( -180, 180 );    rotS-&gt;<a name="setValue"></a><a href="qslider.html#a03234">setValue</a>( 0 );    connect( rotS, SIGNAL(valueChanged(int)), SLOT(newMtx()) );    shearLCD-&gt;<a href="qlcdnumber.html#ecdf88">display</a>( "0.00" );    shearS-&gt;<a href="qrangecontrol.html#f2409c">setRange</a>( -25, 25 );    shearS-&gt;<a href="qslider.html#a03234">setValue</a>( 0 );    connect( shearS, SIGNAL(valueChanged(int)), SLOT(newMtx()) );    mirror-&gt;<a name="setText"></a><a href="qbutton.html#989f4f">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-&gt;<a name="hide"></a><a href="qwidget.html#410481">hide</a>();    bg-&gt;<a name="insert"></a><a href="qbuttongroup.html#10bf2d">insert</a>(rb_txt,0);    bg-&gt;<a href="qbuttongroup.html#10bf2d">insert</a>(rb_img,1);    bg-&gt;<a href="qbuttongroup.html#10bf2d">insert</a>(rb_pic,2);    rb_txt-&gt;<a href="qbutton.html#989f4f">setText</a>( tr("Text") );    rb_img-&gt;<a href="qbutton.html#989f4f">setText</a>( tr("Image") );    rb_img-&gt;<a name="setChecked"></a><a href="qradiobutton.html#0e50fc">setChecked</a>(TRUE);    rb_pic-&gt;<a href="qbutton.html#989f4f">setText</a>( tr("Picture") );    connect( bg, SIGNAL(clicked(int)), SLOT(changeMode(int)) );    fpb-&gt;<a href="qbutton.html#989f4f">setText</a>( tr("Select font...") );    connect( fpb, SIGNAL(clicked()), SLOT(selectFont()) );    textEd-&gt;<a name="setText"></a><a href="qlineedit.html#1ff546">setText</a>( "Troll" );    connect( textEd, SIGNAL(textChanged(const QString&amp;)),                     SLOT(newTxt(const QString&amp;)) );    magLCD = new <a href="qlcdnumber.html">QLCDNumber</a>( 4,optionals_other, "magLCD" );    magLCD-&gt;<a href="qlcdnumber.html#ecdf88">display</a>( "100" );    magS = new <a href="qslider.html">QSlider</a>( QSlider::Horizontal, optionals_other,                           "magnifySlider" );    magS-&gt;<a href="qrangecontrol.html#f2409c">setRange</a>( 0, 800 );    connect( magS, SIGNAL(valueChanged(int)), SLOT(newMtx()) );    magS-&gt;<a href="qslider.html#a03234">setValue</a>( 0 );    connect( magS, SIGNAL(valueChanged(int)), magLCD, SLOT(display(int)));    optionals_text-&gt;<a name="adjustSize"></a><a href="qwidget.html#2ec710">adjustSize</a>();    optionals_other-&gt;<a href="qwidget.html#2ec710">adjustSize</a>();    changeMode(Image);    startTimer(20); // start an initial animation}void <a name="362"></a>XFormControl::timerEvent(<a href="qtimerevent.html">QTimerEvent</a>*){    int v = magS-&gt;<a name="value"></a><a href="qslider.html#7b285c">value</a>();    v = (v+2)+v/10;    if ( v &gt;= 200 ) {        v = 200;        <a name="killTimers"></a><a href="qobject.html#0ef111">killTimers</a>();    }    magS-&gt;<a href="qslider.html#a03234">setValue</a>(v);}/*    Called whenever the user has changed one of the matrix parameters    (i.e. rotate, shear or magnification)*/void <a name="363"></a>XFormControl::newMtx(){    emit newMatrix( <a name="matrix"></a><a href="#365">matrix</a>() );}void <a name="364"></a>XFormControl::newTxt(const QString&amp; s){    emit newText(s);    <a name="changeMode"></a><a href="#368">changeMode</a>(Text);}/*    Calculates the matrix appropriate for the current controls,    and updates the displays.*/<a href="qwmatrix.html">QWMatrix</a> <a name="365"></a>XFormControl::matrix(){    <a href="qwmatrix.html">QWMatrix</a> m;    if (mode != Text) {        double magVal = 1.0*magS-&gt;<a href="qslider.html#7b285c">value</a>()/100;        m.<a name="scale"></a><a href="qwmatrix.html#41a356">scale</a>( magVal, magVal );    }    double shearVal = 1.0*shearS-&gt;<a href="qslider.html#7b285c">value</a>()/25;    m.<a name="shear"></a><a href="qwmatrix.html#b99fbb">shear</a>( shearVal, shearVal );    m.<a name="rotate"></a><a href="qwmatrix.html#71020d">rotate</a>( rotS-&gt;<a href="qslider.html#7b285c">value</a>() );    if ( mirror-&gt;<a name="isChecked"></a><a href="qcheckbox.html#17b182">isChecked</a>() ) {        m.<a href="qwmatrix.html#41a356">scale</a>( 1, -1 );        m.<a href="qwmatrix.html#71020d">rotate</a>( 180 );    }    <a href="qstring.html">QString</a> tmp;    tmp.<a name="sprintf"></a><a href="qstring.html#926f67">sprintf</a>( "%1.2f", shearVal  );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -