📄 xform-xform-cpp.html
字号:
if ( shearVal >= 0 ) tmp.<a name="insert"></a><a href="qstring.html#3ca271">insert</a>( 0, " " ); shearLCD-><a href="qlcdnumber.html#ecdf88">display</a>( tmp ); int rot = rotS-><a href="qslider.html#7b285c">value</a>(); if ( rot < 0 ) rot = rot + 360; tmp.<a href="qstring.html#926f67">sprintf</a>( "%3i'", rot ); rotLCD-><a href="qlcdnumber.html#ecdf88">display</a>( tmp ); return m;}void <a name="366"></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="#367">fontSelected</a>( f ); }}void <a name="367"></a>XFormControl::fontSelected( const QFont &font ){ emit newFont( font ); <a href=#368>changeMode</a>(Text);}/* Sets the mode - Text, Image, or Picture.*/void <a name="368"></a>XFormControl::changeMode(int m){ mode = (Mode)m; emit newMode( m ); <a name="newMtx"></a><a href="#363">newMtx</a>(); if ( mode == Text ) { optionals-><a name="raiseWidget"></a><a href="qwidgetstack.html#08475e">raiseWidget</a>(0); rb_txt-><a href="qradiobutton.html#0e50fc">setChecked</a>(TRUE); } else { optionals-><a href="qwidgetstack.html#08475e">raiseWidget</a>(1); if ( mode == Image ) rb_img-><a href="qradiobutton.html#0e50fc">setChecked</a>(TRUE); else rb_pic-><a href="qradiobutton.html#0e50fc">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#090d60">setFont</a>( initialFont ); <a name="setBackgroundColor"></a><a href="qwidget.html#c09181">setBackgroundColor</a>( white ); m = Text; eraseRect = QRect( 0, 0, 0, 0 );}<a href="qsizepolicy.html">QSizePolicy</a> <a name="350"></a>ShowXForm::sizePolicy() const{ return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );}<a href="qsize.html">QSize</a> <a name="351"></a>ShowXForm::sizeHint() const{ return QSize(400,400);}void <a name="352"></a>ShowXForm::paintEvent( <a href="qpaintevent.html">QPaintEvent</a> * ){ <a name="showIt"></a><a href="#360">showIt</a>();}void <a name="353"></a>ShowXForm::resizeEvent( <a href="qresizeevent.html">QResizeEvent</a> * ){ eraseRect = QRect( <a name="width"></a><a href="qwidget.html#2edab1">width</a>()/2, <a name="height"></a><a href="qwidget.html#e3c588">height</a>()/2, 0, 0 ); <a name="repaint"></a><a href="qwidget.html#7569b1">repaint</a>(rect());}void <a name="354"></a>ShowXForm::setText( const QString& s ){ text = s; <a href=#360>showIt</a>();}void <a name="355"></a>ShowXForm::setMatrix( <a href="qwmatrix.html">QWMatrix</a> w ){ mtx = w; <a href=#360>showIt</a>();}void <a name="356"></a>ShowXForm::setFont( const QFont &f ){ m = Text; <a href="qwidget.html#090d60">QWidget::setFont</a>( f );}void <a name="357"></a>ShowXForm::setPixmap( <a href="qpixmap.html">QPixmap</a> pm ){ pix = pm; m = Image; <a href=#360>showIt</a>();}void <a name="358"></a>ShowXForm::setPicture( const QPicture& p ){ picture = p; m = Picture; <a href=#360>showIt</a>();}void <a name="359"></a>ShowXForm::setMode( int mode ){ m = (Mode)mode;}void <a name="360"></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#386569">fontMetrics</a>() ); // get widget font metrics switch ( mode() ) { case Text: br = fm.<a name="boundingRect"></a><a href="qfontmetrics.html#b1cd55">boundingRect</a>( text ); // rectangle covering text r = br; textYPos = -r.<a name="y"></a><a href="qrect.html#f448f7">y</a>(); textXPos = -r.<a name="x"></a><a href="qrect.html#fccae7">x</a>(); br.<a name="moveTopLeft"></a><a href="qrect.html#3b6044">moveTopLeft</a>( <a name="QPoint"></a><a href="qpoint.html">QPoint</a>( -br.<a name="width"></a><a href="qrect.html#45fe95">width</a>()/2, -br.<a name="height"></a><a href="qrect.html#581ab8">height</a>()/2 ) ); break; case Image: r = pix.<a name="rect"></a><a href="qpixmap.html#fbdfe3">rect</a>(); break; case Picture: // ### need QPicture::boundingRect() r = QRect(0,0,1000,1000); break; } r.<a href="qrect.html#3b6044">moveTopLeft</a>( <a href="qpoint.html">QPoint</a>(-r.<a href="qrect.html#45fe95">width</a>()/2, -r.<a href="qrect.html#581ab8">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#81e8a3">unite</a>( mtx.<a name="map"></a><a href="qwmatrix.html#83c725">map</a>(r) ); eraseRect.<a name="moveBy"></a><a href="qrect.html#3de222">moveBy</a>( -1, -1 ); // add border for matrix round off eraseRect.<a name="setSize"></a><a href="qrect.html#94caa4">setSize</a>( <a href="qsize.html">QSize</a>( eraseRect.<a href="qrect.html#45fe95">width</a>() + 2,eraseRect.<a href="qrect.html#581ab8">height</a>() + 2 ) ); int pw = QMIN(eraseRect.<a href="qrect.html#45fe95">width</a>(),<a href="qwidget.html#2edab1">width</a>()); int ph = QMIN(eraseRect.<a href="qrect.html#581ab8">height</a>(),<a href="qwidget.html#e3c588">height</a>()); <a href="qpixmap.html">QPixmap</a> pm( pw, ph ); // off-screen drawing pixmap pm.<a name="fill"></a><a href="qpixmap.html#6910a0">fill</a>( <a name="backgroundColor"></a><a href="qwidget.html#d5be64">backgroundColor</a>() ); p.begin( &pm ); um.<a name="translate"></a><a href="qwmatrix.html#e4b716">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#167922">font</a>() ); // use widget font p.drawText( r.<a name="left"></a><a href="qrect.html#369cab">left</a>() + textXPos, r.<a name="top"></a><a href="qrect.html#4dd27e">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#86dbc5">width</a>()/2, -pix.<a name="height"></a><a href="qpixmap.html#d5bb33">height</a>()/2, pix ); //QPixmap rotated = pix.<a name="xForm"></a><a href="qpixmap.html#ff5fcf">xForm</a>(mtx); //bitBlt( &pm, pm.<a href="qpixmap.html#86dbc5">width</a>()/2 - rotated.width()/2, //pm.<a href="qpixmap.html#d5bb33">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#35ae2e">bitBlt</a>( this, xpos, ypos, // copy pixmap to widget &pm, 0, 0, -1, -1 ); eraseRect = mtx.<a href="qwmatrix.html#83c725">map</a>( r );}/* Grand unifying widget, putting ShowXForm and XFormControl together.*/class XFormCenter : public QHBox, public ModeNames{ Q_OBJECTpublic: 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#090d60">setFont</a>( f ); } void newMode( int );private: ShowXForm *sx; XFormControl *xc;};void <a name="361"></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#a728cf">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#f0cc08">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#8601c4">setStretchFactor</a>(sx,1); xc-><a name="setFrameStyle"></a><a href="qframe.html#558f79">setFrameStyle</a>( QFrame::Panel | QFrame::Raised ); xc-><a name="setLineWidth"></a><a href="qframe.html#b76184">setLineWidth</a>( 2 ); <a name="connect"></a><a href="qobject.html#fbde73">connect</a>( xc, SIGNAL(newText(const QString&)), sx, SLOT(setText(const QString&)) ); <a href="qobject.html#fbde73">connect</a>( xc, SIGNAL(newMatrix(<a href="qwmatrix.html">QWMatrix</a>)), sx, SLOT(setMatrix(<a href="qwmatrix.html">QWMatrix</a>)) ); <a href="qobject.html#fbde73">connect</a>( xc, SIGNAL(newFont(const QFont&)), sx, SLOT(<a href="qwidget.html#090d60">setFont</a>(const QFont&)) ); <a href="qobject.html#fbde73">connect</a>( xc, SIGNAL(<a name="newMode"></a><a href="#361">newMode</a>(int)), SLOT(<a href=#361>newMode</a>(int)) ); sx->setText( "Troll" ); <a href=#361>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#7ad759">setMainWidget</a>( xfc ); xfc-><a name="setCaption"></a><a href="qwidget.html#d6a291">setCaption</a>("Qt Example - XForm"); xfc-><a name="show"></a><a href="qwidget.html#200ee5">show</a>(); return a.<a name="exec"></a><a href="qapplication.html#84c7bf">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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -