📄 qmag-qmag-cpp.html
字号:
<!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 - qmag/qmag.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>QMag</h1><br clear="all"> This is a simple magnifier-type program. It shows how one can do some quite low-level operations portably using Qt. Run it, click in the magnifier window, then click where you want to magnify or drag out a rectangle. Two combo boxes let you select amplification and refresh frequency, a text label tells you the color of the pixel the cursor is on, and a button lets you save the magnified area as a .bmp file. <hr> Implementation:<pre>/****************************************************************************** $Id: qt/examples/qmag/qmag.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 <<a name="qcombobox.h"></a><a href="qcombobox-h.html">qcombobox.h</a>>#include <<a name="qpushbutton.h"></a><a href="qpushbutton-h.html">qpushbutton.h</a>>#include <<a name="qpixmap.h"></a><a href="qpixmap-h.html">qpixmap.h</a>>#include <<a name="qimage.h"></a><a href="qimage-h.html">qimage.h</a>>#include <<a name="qlabel.h"></a><a href="qlabel-h.html">qlabel.h</a>>#include <<a name="qfiledialog.h"></a><a href="qfiledialog-h.html">qfiledialog.h</a>>#include <<a name="qregexp.h"></a><a href="qregexp-h.html">qregexp.h</a>>#include <<a name="qapplication.h"></a><a href="qapplication-h.html">qapplication.h</a>>#include <<a name="qpainter.h"></a><a href="qpainter-h.html">qpainter.h</a>>#include <<a name="qwmatrix.h"></a><a href="qwmatrix-h.html">qwmatrix.h</a>>class MagWidget : public QWidget{ Q_OBJECTpublic: MagWidget( <a name="QWidget"></a><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 name="QPaintEvent"></a><a href="qpaintevent.html">QPaintEvent</a> * ); void mousePressEvent( <a name="QMouseEvent"></a><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 name="QFocusEvent"></a><a href="qfocusevent.html">QFocusEvent</a> * ); void timerEvent( <a name="QTimerEvent"></a><a href="qtimerevent.html">QTimerEvent</a> * ); void resizeEvent( <a name="QResizeEvent"></a><a href="qresizeevent.html">QResizeEvent</a> * );private: void grabAround(<a name="QPoint"></a><a href="qpoint.html">QPoint</a> pos); void grab(); <a name="QComboBox"></a><a href="qcombobox.html">QComboBox</a> *zoom; <a href="qcombobox.html">QComboBox</a> *refresh; <a name="QPushButton"></a><a href="qpushbutton.html">QPushButton</a> *saveButton; <a href="qpushbutton.html">QPushButton</a> *multiSaveButton; <a href="qpushbutton.html">QPushButton</a> *quitButton; <a name="QPixmap"></a><a href="qpixmap.html">QPixmap</a> pm; // pixmap, magnified <a href="qpixmap.html">QPixmap</a> p; // pixmap <a name="QImage"></a><a href="qimage.html">QImage</a> image; // image of pixmap (for RGB) <a name="QLabel"></a><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 name="QString"></a><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 };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 ); CHECK_PTR(zoom); zoom-><a name="insertStrList"></a><a href="qcombobox.html#ae9e6b">insertStrList</a>( zoomfactors, 9 ); <a name="connect"></a><a href="qobject.html#fbde73">connect</a>( zoom, SIGNAL(activated(int)), SLOT(<a name="setZoom"></a><a href="#299">setZoom</a>(int)) ); refresh = new <a href="qcombobox.html">QComboBox</a>( FALSE, this ); CHECK_PTR(refresh); refresh-><a href="qcombobox.html#ae9e6b">insertStrList</a>( refreshrates, 9 ); <a href="qobject.html#fbde73">connect</a>( refresh, SIGNAL(activated(int)), SLOT(<a name="setRefresh"></a><a href="#300">setRefresh</a>(int)) ); for( n=0; n<9; n++) { int w2 = zoom-><a name="fontMetrics"></a><a href="qwidget.html#386569">fontMetrics</a>().width( zoomfactors[n] ); w = QMAX(w2, w); } zoom-><a name="setGeometry"></a><a href="qwidget.html#9ede68">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#386569">fontMetrics</a>().width( refreshrates[n] ); w = QMAX(w2, w); } refresh-><a href="qwidget.html#9ede68">setGeometry</a>( x, 2, w+30, 20 ); saveButton = new <a href="qpushbutton.html">QPushButton</a>( this ); CHECK_PTR(saveButton); <a href="qobject.html#fbde73">connect</a>( saveButton, SIGNAL(clicked()), this, SLOT(<a name="save"></a><a href="#301">save</a>()) ); saveButton-><a name="setText"></a><a href="qbutton.html#989f4f">setText</a>( "Save" ); saveButton-><a name="setGeometry"></a><a href="qpushbutton.html#c9b88e">setGeometry</a>( x+w+30+2, 2, 10+saveButton-><a href="qwidget.html#386569">fontMetrics</a>().width("Save"), 20 ); multiSaveButton = new <a href="qpushbutton.html">QPushButton</a>( this ); multiSaveButton-><a name="setToggleButton"></a><a href="qpushbutton.html#cf550e">setToggleButton</a>(TRUE); CHECK_PTR(multiSaveButton); <a href="qobject.html#fbde73">connect</a>( multiSaveButton, SIGNAL(clicked()), this, SLOT(<a name="multiSave"></a><a href="#302">multiSave</a>()) ); multiSaveButton-><a href="qbutton.html#989f4f">setText</a>( "MultiSave" ); multiSaveButton-><a href="qpushbutton.html#c9b88e">setGeometry</a>( saveButton-><a name="geometry"></a><a href="qwidget.html#e515c8">geometry</a>().right() + 2, 2, 10+multiSaveButton-><a href="qwidget.html#386569">fontMetrics</a>().width("MultiSave"), 20 ); quitButton = new <a href="qpushbutton.html">QPushButton</a>( this ); CHECK_PTR(quitButton); <a href="qobject.html#fbde73">connect</a>( quitButton, SIGNAL(clicked()), qApp, SLOT(quit()) ); quitButton-><a href="qbutton.html#989f4f">setText</a>( "Quit" ); quitButton-><a href="qpushbutton.html#c9b88e">setGeometry</a>( multiSaveButton-><a href="qwidget.html#e515c8">geometry</a>().right() + 2, 2, 10+quitButton-><a href="qwidget.html#386569">fontMetrics</a>().width("Quit"), 20 );#else zoom = 0; multiSaveButton = 0;#endif <a href=#300>setRefresh</a>(1); <a href=#299>setZoom</a>(5); rgb = new <a href="qlabel.html">QLabel</a>( this ); CHECK_PTR( rgb ); rgb-><a name="setText"></a><a href="qlabel.html#bc5ea6">setText</a>( "" ); rgb-><a name="setAlignment"></a><a href="qlabel.html#4743c8">setAlignment</a>( AlignVCenter ); rgb-><a name="resize"></a><a href="qwidget.html#ff9d07">resize</a>( <a name="width"></a><a href="qwidget.html#2edab1">width</a>(), rgb-><a href="qwidget.html#386569">fontMetrics</a>().height() + 4 );#ifdef COMPLEX_GUI yoffset = zoom-><a name="height"></a><a href="qwidget.html#e3c588">height</a>() // top buttons + 4 // space around top buttons + rgb-><a href="qwidget.html#e3c588">height</a>(); // color-value text height <a name="setMinimumSize"></a><a href="qwidget.html#c0b5fb">setMinimumSize</a>( quitButton-><a name="pos"></a><a href="qwidget.html#2691c9">pos</a>().x(), yoffset+20 ); <a name="resize"></a><a href="qwidget.html#8fcbbe">resize</a>( quitButton-><a href="qwidget.html#e515c8">geometry</a>().topRight().x() + 2, yoffset+60 );#else yoffset = 0; <a href="qwidget.html#8fcbbe">resize</a>(350,350);#endif grabx = graby = -1; grabbing = FALSE; <a name="setMouseTracking"></a><a href="qwidget.html#36406c">setMouseTracking</a>( TRUE ); // and do let me know what pixel I'm at, eh? <a name="grabAround"></a><a href="#307">grabAround</a>( <a href="qpoint.html">QPoint</a>(grabx=qApp->desktop()->width()/2, graby=qApp->desktop()->height()/2) );}void <a name="299"></a>MagWidget::setZoom( int index ){ if (index == 8)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -