qmag-example.html
来自「QT 下载资料仅供参考」· HTML 代码 · 共 447 行 · 第 1/2 页
HTML
447 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/examples/qmag/qmag.doc:4 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>QMag</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 Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped 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>QMag</h1> <p> This is a simple magnifier-type program. It shows how one can dosome quite low-level operations in a portable way using Qt.<p> Run it, click in the magnifier window, then click where you want tomagnify or drag out a rectangle. Two combo boxes let you selectamplification and refresh frequency, a text label tells you the colorof the pixel the cursor is on, and a button lets you save themagnified area as a .bmp file.<p> <hr><p> Implementation:<p> <pre>/****************************************************************************** $Id: qt/qmag.cpp 3.0.5 edited Oct 12 2001 $**** 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 href="qcombobox-h.html">qcombobox.h</a>>#include <<a href="qpushbutton-h.html">qpushbutton.h</a>>#include <<a href="qpixmap-h.html">qpixmap.h</a>>#include <<a href="qimage-h.html">qimage.h</a>>#include <<a href="qlabel-h.html">qlabel.h</a>>#include <<a href="qfiledialog-h.html">qfiledialog.h</a>>#include <<a href="qregexp-h.html">qregexp.h</a>>#include <<a href="qapplication-h.html">qapplication.h</a>>#include <<a href="qpainter-h.html">qpainter.h</a>>#include <<a href="qwmatrix-h.html">qwmatrix.h</a>>class MagWidget : public <a href="qwidget.html">QWidget</a>{ <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>public: MagWidget( <a href="qwidget.html">QWidget</a> *parent=0, const char *name=0 );public slots: void setZoom( int ); void setRefresh( int ); void save(); void multiSave();protected: void paintEvent( <a href="qpaintevent.html">QPaintEvent</a> * ); void mousePressEvent( <a href="qmouseevent.html">QMouseEvent</a> * ); void mouseReleaseEvent( <a href="qmouseevent.html">QMouseEvent</a> * ); void mouseMoveEvent( <a href="qmouseevent.html">QMouseEvent</a> * ); void focusOutEvent( <a href="qfocusevent.html">QFocusEvent</a> * ); void timerEvent( <a href="qtimerevent.html">QTimerEvent</a> * ); void resizeEvent( <a href="qresizeevent.html">QResizeEvent</a> * );private: void grabAround(QPoint pos); void grab(); <a href="qcombobox.html">QComboBox</a> *zoom; <a href="qcombobox.html">QComboBox</a> *refresh; <a href="qpushbutton.html">QPushButton</a> *saveButton; <a href="qpushbutton.html">QPushButton</a> *multiSaveButton; <a href="qpushbutton.html">QPushButton</a> *quitButton; <a href="qpixmap.html">QPixmap</a> pm; // pixmap, magnified <a href="qpixmap.html">QPixmap</a> p; // pixmap <a href="qimage.html">QImage</a> image; // image of pixmap (for RGB) <a href="qlabel.html">QLabel</a> *rgb; int yoffset; // pixels in addition to the actual picture int z; // magnification factor int r; // autorefresh rate (index into refreshrates) bool grabbing; // TRUE if qmag is currently grabbing int grabx, graby; <a href="qstring.html">QString</a> multifn; // filename for multisave};#ifdef COMPLEX_GUIstatic const char *zoomfactors[] = { "100%", "200%", "300%", "400%", "500%", "600%", "700%", "800%", "1600%", 0 };static const char *refreshrates[] = { "No autorefresh", "50 per second", "4 per second", "3 per second", "2 per second", "Every second", "Every two seconds", "Every three seconds", "Every five seconds", "Every ten seconds", 0 };#endifstatic const int timer[] = { 0, 20, 250, 333, 500, 1000, 2000, 3000, 5000, 10000 };<a name="f468"></a>MagWidget::MagWidget( <a href="qwidget.html">QWidget</a> *parent, const char *name ) : <a href="qwidget.html">QWidget</a>( parent, name){ z = 1; // default zoom (100%) r = 0; // default refresh (none)#ifdef COMPLEX_GUI int w=0, x=0, n; zoom = new <a href="qcombobox.html">QComboBox</a>( FALSE, this ); <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>(zoom);<a name="x1626"></a> zoom-><a href="qcombobox.html#insertStrList">insertStrList</a>( zoomfactors, 9 );<a name="x1625"></a> <a href="qobject.html#connect">connect</a>( zoom, SIGNAL(<a href="qcombobox.html#activated">activated</a>(int)), SLOT(setZoom(int)) ); refresh = new <a href="qcombobox.html">QComboBox</a>( FALSE, this ); <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>(refresh); refresh-><a href="qcombobox.html#insertStrList">insertStrList</a>( refreshrates, 9 ); <a href="qobject.html#connect">connect</a>( refresh, SIGNAL(<a href="qcombobox.html#activated">activated</a>(int)), SLOT(setRefresh(int)) ); for( n=0; n<9; n++) {<a name="x1650"></a> int w2 = zoom-><a href="qwidget.html#fontMetrics">fontMetrics</a>().width( zoomfactors[n] ); w = QMAX(w2, w); }<a name="x1660"></a> zoom-><a href="qwidget.html#setGeometry">setGeometry</a>( 2, 2, w+30, 20 ); x = w+34; w = 0; for( n=0; n<9; n++) { int w2 = refresh-><a href="qwidget.html#fontMetrics">fontMetrics</a>().width( refreshrates[n] ); w = QMAX(w2, w); } refresh-><a href="qwidget.html#setGeometry">setGeometry</a>( x, 2, w+30, 20 ); saveButton = new <a href="qpushbutton.html">QPushButton</a>( this ); <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>(saveButton); <a href="qobject.html#connect">connect</a>( saveButton, SIGNAL(<a href="qbutton.html#clicked">clicked</a>()), this, SLOT(save()) );<a name="x1624"></a> saveButton-><a href="qbutton.html#setText">setText</a>( "Save" );<a name="x1641"></a> saveButton-><a href="qwidget.html#setGeometry">setGeometry</a>( x+w+30+2, 2, 10+saveButton-><a href="qwidget.html#fontMetrics">fontMetrics</a>().width("Save"), 20 ); multiSaveButton = new <a href="qpushbutton.html">QPushButton</a>( this );<a name="x1643"></a> multiSaveButton-><a href="qpushbutton.html#setToggleButton">setToggleButton</a>(TRUE); <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>(multiSaveButton); <a href="qobject.html#connect">connect</a>( multiSaveButton, SIGNAL(<a href="qbutton.html#clicked">clicked</a>()), this, SLOT(multiSave()) ); multiSaveButton-><a href="qbutton.html#setText">setText</a>( "MultiSave" );<a name="x1651"></a> multiSaveButton-><a href="qwidget.html#setGeometry">setGeometry</a>( saveButton-><a href="qwidget.html#geometry">geometry</a>().right() + 2, 2, 10+multiSaveButton-><a href="qwidget.html#fontMetrics">fontMetrics</a>().width("MultiSave"), 20 ); quitButton = new <a href="qpushbutton.html">QPushButton</a>( this ); <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>(quitButton); <a href="qobject.html#connect">connect</a>( quitButton, SIGNAL(<a href="qbutton.html#clicked">clicked</a>()), qApp, SLOT(<a href="qapplication.html#quit">quit</a>()) ); quitButton-><a href="qbutton.html#setText">setText</a>( "Quit" ); quitButton-><a href="qwidget.html#setGeometry">setGeometry</a>( multiSaveButton-><a href="qwidget.html#geometry">geometry</a>().right() + 2, 2, 10+quitButton-><a href="qwidget.html#fontMetrics">fontMetrics</a>().width("Quit"), 20 );#else zoom = 0; multiSaveButton = 0;#endif setRefresh(1); setZoom(5); rgb = new <a href="qlabel.html">QLabel</a>( this ); <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( rgb );<a name="x1632"></a> rgb-><a href="qlabel.html#setText">setText</a>( "" ); rgb-><a href="qlabel.html#setAlignment">setAlignment</a>( AlignVCenter ); rgb-><a href="qwidget.html#resize">resize</a>( <a href="qwidget.html#width">width</a>(), rgb-><a href="qwidget.html#fontMetrics">fontMetrics</a>().height() + 4 );#ifdef COMPLEX_GUI<a name="x1652"></a> yoffset = zoom-><a href="qwidget.html#height">height</a>() // top buttons + 4 // space around top buttons + rgb-><a href="qwidget.html#height">height</a>(); // color-value text height<a name="x1657"></a> <a href="qwidget.html#setMinimumSize">setMinimumSize</a>( quitButton-><a href="qwidget.html#pos">pos</a>().x(), yoffset+20 ); <a href="qwidget.html#resize">resize</a>( quitButton-><a href="qwidget.html#geometry">geometry</a>().topRight().x() + 2, yoffset+60 );#else yoffset = 0; <a href="qwidget.html#resize">resize</a>(350,350);#endif grabx = graby = -1; grabbing = FALSE; <a href="qwidget.html#setMouseTracking">setMouseTracking</a>( TRUE ); // and do let me know what pixel I'm at, eh?<a name="x1618"></a> grabAround( QPoint(grabx=qApp-><a href="qapplication.html#desktop">desktop</a>()->width()/2, graby=qApp-><a href="qapplication.html#desktop">desktop</a>()->height()/2) );}void <a name="f469"></a>MagWidget::setZoom( int index ){ if (index == 8) z = 16; else z = index+1; grab();}void <a name="f470"></a>MagWidget::setRefresh( int index )
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?