[190] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
| 2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/doc/tutorial2.doc:7 -->
|
---|
| 3 | <html>
|
---|
| 4 | <head>
|
---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
| 6 | <title>chart/canvasview.cpp Example File</title>
|
---|
| 7 | <style type="text/css"><!--
|
---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
| 9 | a:link { color: #004faf; text-decoration: none }
|
---|
| 10 | a:visited { color: #672967; text-decoration: none }
|
---|
| 11 | body { background: #ffffff; color: black; }
|
---|
| 12 | --></style>
|
---|
| 13 | </head>
|
---|
| 14 | <body>
|
---|
| 15 |
|
---|
| 16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
| 17 | <tr bgcolor="#E5E5E5">
|
---|
| 18 | <td valign=center>
|
---|
| 19 | <a href="index.html">
|
---|
| 20 | <font color="#004faf">Home</font></a>
|
---|
| 21 | | <a href="classes.html">
|
---|
| 22 | <font color="#004faf">All Classes</font></a>
|
---|
| 23 | | <a href="mainclasses.html">
|
---|
| 24 | <font color="#004faf">Main Classes</font></a>
|
---|
| 25 | | <a href="annotated.html">
|
---|
| 26 | <font color="#004faf">Annotated</font></a>
|
---|
| 27 | | <a href="groups.html">
|
---|
| 28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
| 29 | | <a href="functions.html">
|
---|
| 30 | <font color="#004faf">Functions</font></a>
|
---|
| 31 | </td>
|
---|
| 32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>chart/canvasview.cpp Example File</h1>
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | <pre>#include "canvasview.h"
|
---|
| 36 | #include "chartform.h"
|
---|
| 37 |
|
---|
| 38 | #include <<a href="qcursor-h.html">qcursor.h</a>>
|
---|
| 39 | #include <<a href="qpoint-h.html">qpoint.h</a>>
|
---|
| 40 | #include <<a href="qpopupmenu-h.html">qpopupmenu.h</a>>
|
---|
| 41 | #include <<a href="qstatusbar-h.html">qstatusbar.h</a>>
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | void CanvasView::<a href="qscrollview.html#contentsContextMenuEvent">contentsContextMenuEvent</a>( <a href="qcontextmenuevent.html">QContextMenuEvent</a> * )
|
---|
| 45 | {
|
---|
| 46 | ((ChartForm*)<a href="qobject.html#parent">parent</a>())->optionsMenu->exec( QCursor::<a href="qcursor.html#pos">pos</a>() );
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | void CanvasView::<a href="qscrollview.html#viewportResizeEvent">viewportResizeEvent</a>( <a href="qresizeevent.html">QResizeEvent</a> *e )
|
---|
| 51 | {
|
---|
| 52 | <a href="qcanvasview.html#canvas">canvas</a>()->resize( e-><a href="qresizeevent.html#size">size</a>().width(), e-><a href="qresizeevent.html#size">size</a>().height() );
|
---|
| 53 | ((ChartForm*)<a href="qobject.html#parent">parent</a>())->drawElements();
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 |
|
---|
| 57 | void CanvasView::<a href="qscrollview.html#contentsMousePressEvent">contentsMousePressEvent</a>( <a href="qmouseevent.html">QMouseEvent</a> *e )
|
---|
| 58 | {
|
---|
| 59 | <a href="qcanvasitemlist.html">QCanvasItemList</a> list = <a href="qcanvasview.html#canvas">canvas</a>()->collisions( e-><a href="qmouseevent.html#pos">pos</a>() );
|
---|
| 60 | for ( QCanvasItemList::iterator it = list.<a href="qvaluelist.html#begin">begin</a>(); it != list.<a href="qvaluelist.html#end">end</a>(); ++it )
|
---|
| 61 | if ( (*it)->rtti() == CanvasText::CANVAS_TEXT ) {
|
---|
| 62 | m_movingItem = *it;
|
---|
| 63 | m_pos = e-><a href="qmouseevent.html#pos">pos</a>();
|
---|
| 64 | return;
|
---|
| 65 | }
|
---|
| 66 | m_movingItem = 0;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | void CanvasView::<a href="qscrollview.html#contentsMouseMoveEvent">contentsMouseMoveEvent</a>( <a href="qmouseevent.html">QMouseEvent</a> *e )
|
---|
| 71 | {
|
---|
| 72 | if ( m_movingItem ) {
|
---|
| 73 | <a href="qpoint.html">QPoint</a> offset = e-><a href="qmouseevent.html#pos">pos</a>() - m_pos;
|
---|
| 74 | m_movingItem->moveBy( offset.<a href="qpoint.html#x">x</a>(), offset.<a href="qpoint.html#y">y</a>() );
|
---|
| 75 | m_pos = e-><a href="qmouseevent.html#pos">pos</a>();
|
---|
| 76 | ChartForm *form = (ChartForm*)<a href="qobject.html#parent">parent</a>();
|
---|
| 77 | form->setChanged( TRUE );
|
---|
| 78 | int chartType = form->chartType();
|
---|
| 79 | CanvasText *item = (CanvasText*)m_movingItem;
|
---|
| 80 | int i = item->index();
|
---|
| 81 |
|
---|
| 82 | (*m_elements)[i].setProX( chartType, item->x() / canvas()->width() );
|
---|
| 83 | (*m_elements)[i].setProY( chartType, item->y() / canvas()->height() );
|
---|
| 84 |
|
---|
| 85 | <a href="qcanvasview.html#canvas">canvas</a>()->update();
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 | </pre><!-- eof -->
|
---|
| 91 | <p><address><hr><div align=center>
|
---|
| 92 | <table width=100% cellspacing=0 border=0><tr>
|
---|
| 93 | <td>Copyright © 2007
|
---|
| 94 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
| 95 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
| 96 | </table></div></address></body>
|
---|
| 97 | </html>
|
---|