📄 qmag-qmag-cpp.html
字号:
z = 16; else z = index+1; <a name="grab"></a><a href="#303">grab</a>();}void <a name="300"></a>MagWidget::setRefresh( int index ){ r = index; <a name="killTimers"></a><a href="qobject.html#0ef111">killTimers</a>(); if (index && !grabbing) <a name="startTimer"></a><a href="qobject.html#4c6b67">startTimer</a>( timer[r] );}void <a name="301"></a>MagWidget::save(){ if ( !p.<a name="isNull"></a><a href="qpixmap.html#7803c4">isNull</a>() ) { <a href="qobject.html#0ef111">killTimers</a>(); <a href="qstring.html">QString</a> fn = QFileDialog::getSaveFileName(); if ( !fn.<a name="isEmpty"></a><a href="qstring.html#c62623">isEmpty</a>() ) p.<a name="save"></a><a href="qpixmap.html#a38b1c">save</a>( fn, "BMP" ); if ( r ) <a href="qobject.html#4c6b67">startTimer</a>( timer[r] ); }}void <a name="302"></a>MagWidget::multiSave(){ if ( !p.<a href="qpixmap.html#7803c4">isNull</a>() ) { multifn = ""; // stops saving multifn = QFileDialog::getSaveFileName(); if ( multifn.<a href="qstring.html#c62623">isEmpty</a>() ) multiSaveButton-><a name="setOn"></a><a href="qpushbutton.html#15502f">setOn</a>(FALSE); if ( !r ) p.<a href="qpixmap.html#a38b1c">save</a>( multifn, "BMP" ); } else { multiSaveButton-><a href="qpushbutton.html#15502f">setOn</a>(FALSE); }}void <a name="303"></a>MagWidget::grab(){ if ( !isVisible() ) return; // don't eat resources when iconified if ( grabx < 0 || graby < 0 ) return; // don't grab until the user has said to int x,y, w,h; w = (<a href="qwidget.html#2edab1">width</a>()+z-1)/z; h = (<a href="qwidget.html#e3c588">height</a>()+z-1-yoffset)/z; if ( w<1 || h<1 ) return; // don't ask too much from the window system :) x = grabx-w/2; // find a suitable position to grab from y = graby-h/2; if ( x + w > <a name="QApplication::desktop"></a><a href="qapplication.html#d8ed8c">QApplication::desktop</a>()->width() ) x = QApplication::desktop()->width()-w; else if ( x < 0 ) x = 0; if ( y + h > <a href="qapplication.html#d8ed8c">QApplication::desktop</a>()->height() ) y = QApplication::desktop()->height()-h; else if ( y < 0 ) y = 0; p = QPixmap::grabWindow( <a href="qapplication.html#d8ed8c">QApplication::desktop</a>()->winId(), x, y, w, h ); image = p.<a name="convertToImage"></a><a href="qpixmap.html#8c5f15">convertToImage</a>(); <a name="QWMatrix"></a><a href="qwmatrix.html">QWMatrix</a> m; // after getting it, scale it m.scale( (double)z, (double)z ); pm = p.<a name="xForm"></a><a href="qpixmap.html#ff5fcf">xForm</a>( m ); if ( !multiSaveButton || !multiSaveButton-><a name="isOn"></a><a href="qbutton.html#12ce08">isOn</a>() ) <a name="repaint"></a><a href="qwidget.html#7569b1">repaint</a>( FALSE ); // and finally repaint, flicker-free}void <a name="304"></a>MagWidget::paintEvent( <a href="qpaintevent.html">QPaintEvent</a> * ){ if ( !pm.<a href="qpixmap.html#7803c4">isNull</a>() ) { <a name="QPainter"></a><a href="qpainter.html">QPainter</a> paint( this ); paint.<a name="drawPixmap"></a><a href="qpainter.html#c64b89">drawPixmap</a>( 0, zoom ? zoom-><a href="qwidget.html#e3c588">height</a>()+4 : 0, pm, 0,0, <a href="qwidget.html#2edab1">width</a>(), <a href="qwidget.html#e3c588">height</a>()-yoffset ); }}void <a name="305"></a>MagWidget::mousePressEvent( <a href="qmouseevent.html">QMouseEvent</a> *e ){ if ( !grabbing ) { // prepare to grab... grabbing = TRUE; <a href="qobject.html#0ef111">killTimers</a>(); <a name="grabMouse"></a><a href="qwidget.html#5bdd5f">grabMouse</a>( crossCursor ); grabx = -1; graby = -1; } else { // REALLY prepare to grab grabx = mapToGlobal(e-><a name="pos"></a><a href="qmouseevent.html#ac6f25">pos</a>()).x(); graby = mapToGlobal(e-><a href="qmouseevent.html#ac6f25">pos</a>()).y(); }}void <a name="306"></a>MagWidget::mouseReleaseEvent( <a href="qmouseevent.html">QMouseEvent</a> * e ){ if ( grabbing && grabx >= 0 && graby >= 0 ) { grabbing = FALSE; <a href=#307>grabAround</a>(e-><a href="qmouseevent.html#ac6f25">pos</a>()); <a name="releaseMouse"></a><a href="qwidget.html#369707">releaseMouse</a>(); }}void <a name="307"></a>MagWidget::grabAround(<a href="qpoint.html">QPoint</a> pos){ int rx, ry; rx = mapToGlobal(pos).x(); ry = mapToGlobal(pos).y(); int w = QABS(rx-grabx); int h = QABS(ry-graby); if ( w > 10 && h > 10 ) { int pz; pz = 1; while ( w*pz*h*pz < width()*(<a href="qwidget.html#e3c588">height</a>()-yoffset) && w*pz < <a href="qapplication.html#d8ed8c">QApplication::desktop</a>()->width() && h*pz < <a href="qapplication.html#d8ed8c">QApplication::desktop</a>()->height() ) pz++; if ( (w*pz*h*pz - width()*(<a href="qwidget.html#e3c588">height</a>()-yoffset)) > (<a href="qwidget.html#2edab1">width</a>()*(<a href="qwidget.html#e3c588">height</a>()-yoffset) - w*(pz-1)*h*(pz-1)) ) pz--; if ( pz < 1 ) pz = 1; if ( pz > 8 ) pz = 8; if ( zoom ) zoom-><a name="setCurrentItem"></a><a href="qcombobox.html#8a94f7">setCurrentItem</a>( pz-1 ); z = pz; grabx = QMIN(rx, grabx) + w/2; graby = QMIN(ry, graby) + h/2; <a href="qwidget.html#8fcbbe">resize</a>( w*z, h*z+yoffset ); } <a href=#303>grab</a>(); if ( r ) <a href="qobject.html#4c6b67">startTimer</a>( timer[r] );}void <a name="308"></a>MagWidget::mouseMoveEvent( <a href="qmouseevent.html">QMouseEvent</a> *e ){ if ( grabbing || pm.<a href="qpixmap.html#7803c4">isNull</a>() || e-><a href="qmouseevent.html#ac6f25">pos</a>().y() > height() - (zoom ? zoom-><a href="qwidget.html#386569">fontMetrics</a>().height() - 4 : 0) || e-><a href="qmouseevent.html#ac6f25">pos</a>().y() < (zoom ? zoom-><a href="qwidget.html#e3c588">height</a>()+4 : 4) ) { rgb-><a href="qlabel.html#bc5ea6">setText</a>( "" ); } else { int x,y; x = e-><a href="qmouseevent.html#ac6f25">pos</a>().x() / z; y = (e-><a href="qmouseevent.html#ac6f25">pos</a>().y() - ( zoom ? zoom-><a href="qwidget.html#e3c588">height</a>() : 0 ) - 4) / z; <a href="qstring.html">QString</a> pixelinfo; if ( image.<a name="valid"></a><a href="qimage.html#81538b">valid</a>(x,y) ) { QRgb px = image.<a name="pixel"></a><a href="qimage.html#ecfb25">pixel</a>(x,y); pixelinfo.<a name="sprintf"></a><a href="qstring.html#926f67">sprintf</a>(" %3d,%3d,%3d #%02x%02x%02x", <a name="qRed"></a><a href="qcolor.html#2f7325">qRed</a>(px), <a name="qGreen"></a><a href="qcolor.html#1cf303">qGreen</a>(px), <a name="qBlue"></a><a href="qcolor.html#c84970">qBlue</a>(px), <a href="qcolor.html#2f7325">qRed</a>(px), <a href="qcolor.html#1cf303">qGreen</a>(px), <a href="qcolor.html#c84970">qBlue</a>(px)); } <a href="qstring.html">QString</a> label; label.<a href="qstring.html#926f67">sprintf</a>( "x=%d, y=%d %s", x+grabx, y+graby, (const char*)pixelinfo ); rgb-><a href="qlabel.html#bc5ea6">setText</a>( label ); }}void <a name="309"></a>MagWidget::focusOutEvent( <a href="qfocusevent.html">QFocusEvent</a> * ){ rgb-><a href="qlabel.html#bc5ea6">setText</a>( "" );}void <a name="310"></a>MagWidget::timerEvent( <a href="qtimerevent.html">QTimerEvent</a> * ){ <a href=#303>grab</a>();/* if ( multiSaveButton-><a href="qbutton.html#12ce08">isOn</a>() && !multifn.<a href="qstring.html#c62623">isEmpty</a>() ) { <a name="QRegExp"></a><a href="qregexp.html">QRegExp</a> num("[0-9][0-9]*"); int start; int len; if ((start=num.<a name="match"></a><a href="qregexp.html#f6e804">match</a>(multifn,0,&len))>=0) multifn.<a name="replace"></a><a href="qstring.html#034e6e">replace</a>(num, <a href="qstring.html">QString</a>().setNum(multifn.<a name="mid"></a><a href="qstring.html#3b1493">mid</a>(start,len).toInt()+1) ); p.<a href="qpixmap.html#a38b1c">save</a>( multifn, "BMP" ); }*/}void <a name="311"></a>MagWidget::resizeEvent( <a href="qresizeevent.html">QResizeEvent</a> * ){ rgb-><a href="qwidget.html#9ede68">setGeometry</a>( 0, <a href="qwidget.html#e3c588">height</a>() - rgb-><a href="qwidget.html#e3c588">height</a>(), <a href="qwidget.html#2edab1">width</a>(), rgb-><a href="qwidget.html#e3c588">height</a>() ); <a href=#303>grab</a>();}#include "qmag.moc"int main( int argc, char **argv ){ <a name="QApplication"></a><a href="qapplication.html">QApplication</a> a( argc, argv ); MagWidget m; a.<a name="setMainWidget"></a><a href="qapplication.html#7ad759">setMainWidget</a>( &m ); m.<a name="show"></a><a href="qwidget.html#200ee5">show</a>(); return a.<a name="exec"></a><a href="qapplication.html#84c7bf">exec</a>();}</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 + -