[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/examples/scrollview/scrollview.doc:4 -->
|
---|
| 3 | <html>
|
---|
| 4 | <head>
|
---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
| 6 | <title>Scrollview</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>Scrollview</h1>
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | <p>
|
---|
| 36 | This example shows how to use Qt's scrollview. This is a widget
|
---|
| 37 | optimized for very large contents.
|
---|
| 38 | <p> <hr>
|
---|
| 39 | <p> Implementation:
|
---|
| 40 | <p> <pre>/****************************************************************************
|
---|
| 41 | ** $Id: scrollview-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 42 | **
|
---|
| 43 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
| 44 | **
|
---|
| 45 | ** This file is part of an example program for Qt. This example
|
---|
| 46 | ** program may be used, distributed and modified without limitation.
|
---|
| 47 | **
|
---|
| 48 | *****************************************************************************/
|
---|
| 49 |
|
---|
| 50 | #include <<a href="qscrollview-h.html">qscrollview.h</a>>
|
---|
| 51 | #include <<a href="qapplication-h.html">qapplication.h</a>>
|
---|
| 52 | #include <<a href="qmenubar-h.html">qmenubar.h</a>>
|
---|
| 53 | #include <<a href="qpopupmenu-h.html">qpopupmenu.h</a>>
|
---|
| 54 | #include <<a href="qpushbutton-h.html">qpushbutton.h</a>>
|
---|
| 55 | #include <<a href="qpainter-h.html">qpainter.h</a>>
|
---|
| 56 | #include <<a href="qpixmap-h.html">qpixmap.h</a>>
|
---|
| 57 | #include <<a href="qmessagebox-h.html">qmessagebox.h</a>>
|
---|
| 58 | #include <<a href="qlayout-h.html">qlayout.h</a>>
|
---|
| 59 | #include <<a href="qlabel-h.html">qlabel.h</a>>
|
---|
| 60 | #include <<a href="qmultilineedit-h.html">qmultilineedit.h</a>>
|
---|
| 61 | #include <<a href="qsizegrip-h.html">qsizegrip.h</a>>
|
---|
| 62 | #include <stdlib.h>
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | static const int style_id = 0x1000;
|
---|
| 66 | static const int lw_id = 0x2000;
|
---|
| 67 | static const int mlw_id = 0x4000;
|
---|
| 68 | static const int mw_id = 0x8000;
|
---|
| 69 | static const int max_lw = 16;
|
---|
| 70 | static const int max_mlw = 5;
|
---|
| 71 | static const int max_mw = 10;
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | class BigShrinker : public <a href="qframe.html">QFrame</a> {
|
---|
| 75 | <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
|
---|
| 76 | public:
|
---|
| 77 | BigShrinker(QWidget* parent) :
|
---|
| 78 | <a href="qframe.html">QFrame</a>(parent)
|
---|
| 79 | {
|
---|
| 80 | setFrameStyle(QFrame::Box|QFrame::Sunken);
|
---|
| 81 | int h=35;
|
---|
| 82 | int b=0;
|
---|
| 83 | for (int y=0; y<2000-h; y+=h+10) {
|
---|
| 84 | if (y == 0) {
|
---|
| 85 | <a href="qbutton.html">QButton</a>* q=new <a href="qpushbutton.html">QPushButton</a>("Quit", this);
|
---|
| 86 | connect(q, SIGNAL(<a href="qbutton.html#clicked">clicked</a>()), qApp, SLOT(<a href="qapplication.html#quit">quit</a>()));
|
---|
| 87 | } else {
|
---|
| 88 | <a href="qstring.html">QString</a> str;
|
---|
| 89 | if ( b > 0 ) {
|
---|
| 90 | <a name="x656"></a> str.<a href="qstring.html#sprintf">sprintf</a>("Button %d", b++);
|
---|
| 91 | } else {
|
---|
| 92 | str = "I'm shrinking!";
|
---|
| 93 | ++b;
|
---|
| 94 | }
|
---|
| 95 | (new <a href="qpushbutton.html">QPushButton</a>(str, this))->move(y/2,y);
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | resize(1000,2000);
|
---|
| 99 |
|
---|
| 100 | startTimer(250);
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | void timerEvent(QTimerEvent*)
|
---|
| 104 | {
|
---|
| 105 | int w=width();
|
---|
| 106 | int h=height();
|
---|
| 107 | if ( w > 50 ) w -= 1;
|
---|
| 108 | if ( h > 50 ) h -= 2;
|
---|
| 109 | resize(w,h);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | void mouseReleaseEvent(QMouseEvent* e)
|
---|
| 113 | {
|
---|
| 114 | emit clicked(e->x(), e->y());
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | signals:
|
---|
| 118 | void clicked(int,int);
|
---|
| 119 | };
|
---|
| 120 |
|
---|
| 121 | class BigMatrix : public <a href="qscrollview.html">QScrollView</a> {
|
---|
| 122 | <a href="qmultilineedit.html">QMultiLineEdit</a> *dragging;
|
---|
| 123 | public:
|
---|
| 124 | BigMatrix(QWidget* parent) :
|
---|
| 125 | <a href="qscrollview.html">QScrollView</a>(parent,"matrix", WStaticContents),
|
---|
| 126 | bg("bg.ppm")
|
---|
| 127 | {
|
---|
| 128 | <a name="x640"></a> bg.<a href="qpixmap.html#load">load</a>("bg.ppm");
|
---|
| 129 | resizeContents(400000,300000);
|
---|
| 130 |
|
---|
| 131 | dragging = 0;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | void viewportMousePressEvent(QMouseEvent* e)
|
---|
| 135 | {
|
---|
| 136 | int x, y;
|
---|
| 137 | viewportToContents( e->x(), e->y(), x, y );
|
---|
| 138 | dragging = new <a href="qmultilineedit.html">QMultiLineEdit</a>(viewport(),"Another");
|
---|
| 139 | <a name="x657"></a> dragging-><a href="qtextedit.html#setText">setText</a>("Thanks!");
|
---|
| 140 | <a name="x650"></a> dragging-><a href="qwidget.html#resize">resize</a>(100,100);
|
---|
| 141 | addChild(dragging, x, y);
|
---|
| 142 | showChild(dragging);
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | void viewportMouseReleaseEvent(QMouseEvent*)
|
---|
| 146 | {
|
---|
| 147 | dragging = 0;
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | void viewportMouseMoveEvent(QMouseEvent* e)
|
---|
| 151 | {
|
---|
| 152 | if ( dragging ) {
|
---|
| 153 | int mx, my;
|
---|
| 154 | viewportToContents( e->x(), e->y(), mx, my );
|
---|
| 155 | int cx = childX(dragging);
|
---|
| 156 | int cy = childY(dragging);
|
---|
| 157 | int w = mx - cx + 1;
|
---|
| 158 | int h = my - cy + 1;
|
---|
| 159 | <a href="qstring.html">QString</a> msg;
|
---|
| 160 | msg.<a href="qstring.html#sprintf">sprintf</a>("at (%d,%d) %d by %d",cx,cy,w,h);
|
---|
| 161 | dragging-><a href="qtextedit.html#setText">setText</a>(msg);
|
---|
| 162 | dragging-><a href="qwidget.html#resize">resize</a>(w,h);
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | protected:
|
---|
| 167 | void drawContents(QPainter* p, int cx, int cy, int cw, int ch)
|
---|
| 168 | {
|
---|
| 169 | // The Background
|
---|
| 170 | <a name="x639"></a> if ( !bg.<a href="qpixmap.html#isNull">isNull</a>() ) {
|
---|
| 171 | <a name="x638"></a> int rowheight=bg.<a href="qpixmap.html#height">height</a>();
|
---|
| 172 | int toprow=cy/rowheight;
|
---|
| 173 | int bottomrow=(cy+ch+rowheight-1)/rowheight;
|
---|
| 174 | <a name="x641"></a> int colwidth=bg.<a href="qpixmap.html#width">width</a>();
|
---|
| 175 | int leftcol=cx/colwidth;
|
---|
| 176 | int rightcol=(cx+cw+colwidth-1)/colwidth;
|
---|
| 177 | for (int r=toprow; r<=bottomrow; r++) {
|
---|
| 178 | int py=r*rowheight;
|
---|
| 179 | for (int c=leftcol; c<=rightcol; c++) {
|
---|
| 180 | int px=c*colwidth;
|
---|
| 181 | p->drawPixmap(px, py, bg);
|
---|
| 182 | }
|
---|
| 183 | }
|
---|
| 184 | } else {
|
---|
| 185 | p->fillRect(cx, cy, cw, ch, QColor(240,222,208));
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | // The Numbers
|
---|
| 189 | {
|
---|
| 190 | <a href="qfontmetrics.html">QFontMetrics</a> fm=p->fontMetrics();
|
---|
| 191 | <a name="x620"></a> int rowheight=fm.<a href="qfontmetrics.html#lineSpacing">lineSpacing</a>();
|
---|
| 192 | int toprow=cy/rowheight;
|
---|
| 193 | int bottomrow=(cy+ch+rowheight-1)/rowheight;
|
---|
| 194 | <a name="x621"></a> int colwidth=fm.<a href="qfontmetrics.html#width">width</a>("00000,000000 ")+3;
|
---|
| 195 | int leftcol=cx/colwidth;
|
---|
| 196 | int rightcol=(cx+cw+colwidth-1)/colwidth;
|
---|
| 197 | <a href="qstring.html">QString</a> str;
|
---|
| 198 | for (int r=toprow; r<=bottomrow; r++) {
|
---|
| 199 | int py=r*rowheight;
|
---|
| 200 | for (int c=leftcol; c<=rightcol; c++) {
|
---|
| 201 | int px=c*colwidth;
|
---|
| 202 | str.<a href="qstring.html#sprintf">sprintf</a>("%d,%d",c,r);
|
---|
| 203 | <a name="x619"></a> p->drawText(px+3, py+fm.<a href="qfontmetrics.html#ascent">ascent</a>(), str);
|
---|
| 204 | }
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | // The Big Hint
|
---|
| 208 | if (leftcol<10 && toprow<5) {
|
---|
| 209 | p->setFont(QFont("Charter",30));
|
---|
| 210 | p->setPen(red);
|
---|
| 211 | <a href="qstring.html">QString</a> text;
|
---|
| 212 | text.<a href="qstring.html#sprintf">sprintf</a>("HINT: Look at %d,%d",215000/colwidth,115000/rowheight);
|
---|
| 213 | p->drawText(100,50,text);
|
---|
| 214 | }
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | // The Big X
|
---|
| 218 | {
|
---|
| 219 | if (cx+cw>200000 && cy+ch>100000 && cx<230000 && cy<130000) {
|
---|
| 220 | // Note that some X server cannot even handle co-ordinates
|
---|
| 221 | // beyond about 4000, so you might not see this.
|
---|
| 222 | p->drawLine(200000,100000,229999,129999);
|
---|
| 223 | p->drawLine(229999,100000,200000,129999);
|
---|
| 224 |
|
---|
| 225 | // X marks the spot!
|
---|
| 226 | p->setFont(QFont("Charter",100));
|
---|
| 227 | p->setPen(blue);
|
---|
| 228 | p->drawText(215000-500,115000-100,1000,200,AlignCenter,"YOU WIN!!!!!");
|
---|
| 229 | }
|
---|
| 230 | }
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | private:
|
---|
| 234 | <a href="qpixmap.html">QPixmap</a> bg;
|
---|
| 235 | };
|
---|
| 236 |
|
---|
| 237 | class ScrollViewExample : public <a href="qwidget.html">QWidget</a> {
|
---|
| 238 | Q_OBJECT
|
---|
| 239 |
|
---|
| 240 | public:
|
---|
| 241 | ScrollViewExample(int technique, QWidget* parent=0, const char* name=0) :
|
---|
| 242 | <a href="qwidget.html">QWidget</a>(parent,name)
|
---|
| 243 | {
|
---|
| 244 | <a href="qmenubar.html">QMenuBar</a>* menubar = new <a href="qmenubar.html">QMenuBar</a>(this);
|
---|
| 245 | <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( menubar );
|
---|
| 246 |
|
---|
| 247 | <a href="qpopupmenu.html">QPopupMenu</a>* file = new <a href="qpopupmenu.html">QPopupMenu</a>( menubar );
|
---|
| 248 | <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( file );
|
---|
| 249 | <a name="x634"></a> menubar-><a href="qmenudata.html#insertItem">insertItem</a>( "&File", file );
|
---|
| 250 | file-><a href="qmenudata.html#insertItem">insertItem</a>( "Quit", qApp, SLOT(<a href="qapplication.html#quit">quit</a>()) );
|
---|
| 251 |
|
---|
| 252 | vp_options = new <a href="qpopupmenu.html">QPopupMenu</a>( menubar );
|
---|
| 253 | <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( vp_options );
|
---|
| 254 | <a name="x644"></a> vp_options-><a href="qpopupmenu.html#setCheckable">setCheckable</a>( TRUE );
|
---|
| 255 | menubar-><a href="qmenudata.html#insertItem">insertItem</a>( "&ScrollView", vp_options );
|
---|
| 256 | <a name="x642"></a> connect( vp_options, SIGNAL(<a href="qpopupmenu.html#activated">activated</a>(int)),
|
---|
| 257 | this, SLOT(doVPMenuItem(int)) );
|
---|
| 258 |
|
---|
| 259 | vauto_id = vp_options-><a href="qmenudata.html#insertItem">insertItem</a>( "Vertical Auto" );
|
---|
| 260 | vaoff_id = vp_options-><a href="qmenudata.html#insertItem">insertItem</a>( "Vertical AlwaysOff" );
|
---|
| 261 | vaon_id = vp_options-><a href="qmenudata.html#insertItem">insertItem</a>( "Vertical AlwaysOn" );
|
---|
| 262 | <a name="x635"></a> vp_options-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
| 263 | hauto_id = vp_options-><a href="qmenudata.html#insertItem">insertItem</a>( "Horizontal Auto" );
|
---|
| 264 | haoff_id = vp_options-><a href="qmenudata.html#insertItem">insertItem</a>( "Horizontal AlwaysOff" );
|
---|
| 265 | haon_id = vp_options-><a href="qmenudata.html#insertItem">insertItem</a>( "Horizontal AlwaysOn" );
|
---|
| 266 | vp_options-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
| 267 | corn_id = vp_options-><a href="qmenudata.html#insertItem">insertItem</a>( "cornerWidget" );
|
---|
| 268 |
|
---|
| 269 | if (technique == 1) {
|
---|
| 270 | vp = new <a href="qscrollview.html">QScrollView</a>(this);
|
---|
| 271 | <a name="x655"></a> BigShrinker *bs = new BigShrinker(0);//(vp-><a href="qscrollview.html#viewport">viewport</a>());
|
---|
| 272 | <a name="x645"></a> vp-><a href="qscrollview.html#addChild">addChild</a>(bs);
|
---|
| 273 | <a name="x659"></a> bs-><a href="qwidget.html#setAcceptDrops">setAcceptDrops</a>(TRUE);
|
---|
| 274 | QObject::<a href="qobject.html#connect">connect</a>(bs, SIGNAL(clicked(int,int)),
|
---|
| 275 | <a name="x646"></a> vp, SLOT(<a href="qscrollview.html#center">center</a>(int,int)));
|
---|
| 276 | } else {
|
---|
| 277 | vp = new BigMatrix(this);
|
---|
| 278 | if ( technique == 3 )
|
---|
| 279 | <a name="x648"></a> vp-><a href="qscrollview.html#enableClipper">enableClipper</a>(TRUE);
|
---|
| 280 | srand(1);
|
---|
| 281 | for (int i=0; i<30; i++) {
|
---|
| 282 | <a href="qmultilineedit.html">QMultiLineEdit</a> *l = new <a href="qmultilineedit.html">QMultiLineEdit</a>(vp-><a href="qscrollview.html#viewport">viewport</a>(),"First");
|
---|
| 283 | l-><a href="qtextedit.html#setText">setText</a>("Drag out more of these.");
|
---|
| 284 | l-><a href="qwidget.html#resize">resize</a>(100,100);
|
---|
| 285 | vp-><a href="qscrollview.html#addChild">addChild</a>(l, rand()%800, rand()%10000);
|
---|
| 286 | }
|
---|
| 287 | vp-><a href="qscrollview.html#viewport">viewport</a>()->setBackgroundMode(NoBackground);
|
---|
| 288 | }
|
---|
| 289 |
|
---|
| 290 | f_options = new <a href="qpopupmenu.html">QPopupMenu</a>( menubar );
|
---|
| 291 | <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( f_options );
|
---|
| 292 | f_options-><a href="qpopupmenu.html#setCheckable">setCheckable</a>( TRUE );
|
---|
| 293 | menubar-><a href="qmenudata.html#insertItem">insertItem</a>( "F&rame", f_options );
|
---|
| 294 | connect( f_options, SIGNAL(<a href="qpopupmenu.html#activated">activated</a>(int)),
|
---|
| 295 | this, SLOT(doFMenuItem(int)) );
|
---|
| 296 |
|
---|
| 297 | f_options-><a href="qmenudata.html#insertItem">insertItem</a>( "No Frame", style_id );
|
---|
| 298 | f_options-><a href="qmenudata.html#insertItem">insertItem</a>( "Box", style_id|QFrame::Box );
|
---|
| 299 | f_options-><a href="qmenudata.html#insertItem">insertItem</a>( "Panel", style_id|QFrame::Panel );
|
---|
| 300 | f_options-><a href="qmenudata.html#insertItem">insertItem</a>( "WinPanel", style_id|QFrame::WinPanel );
|
---|
| 301 | f_options-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
| 302 | f_options-><a href="qmenudata.html#insertItem">insertItem</a>( "Plain", style_id|QFrame::Plain );
|
---|
| 303 | f_options-><a href="qmenudata.html#insertItem">insertItem</a>( "Raised", style_id|QFrame::Raised );
|
---|
| 304 | <a name="x633"></a> f_laststyle = f_options-><a href="qmenudata.html#indexOf">indexOf</a>(
|
---|
| 305 | f_options-><a href="qmenudata.html#insertItem">insertItem</a>( "Sunken", style_id|QFrame::Sunken ));
|
---|
| 306 | f_options-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
---|
| 307 | lw_options = new <a href="qpopupmenu.html">QPopupMenu</a>( menubar );
|
---|
| 308 | <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( lw_options );
|
---|
| 309 | lw_options-><a href="qpopupmenu.html#setCheckable">setCheckable</a>( TRUE );
|
---|
| 310 | for (int lw = 1; lw <= max_lw; lw++) {
|
---|
| 311 | <a href="qstring.html">QString</a> str;
|
---|
| 312 | str.<a href="qstring.html#sprintf">sprintf</a>("%d Pixels", lw);
|
---|
| 313 | lw_options-><a href="qmenudata.html#insertItem">insertItem</a>( str, lw_id | lw );
|
---|
| 314 | }
|
---|
| 315 | f_options-><a href="qmenudata.html#insertItem">insertItem</a>( "Line Width", lw_options );
|
---|
| 316 | connect( lw_options, SIGNAL(<a href="qpopupmenu.html#activated">activated</a>(int)),
|
---|
| 317 | this, SLOT(doFMenuItem(int)) );
|
---|
| 318 | mlw_options = new <a href="qpopupmenu.html">QPopupMenu</a>( menubar );
|
---|
| 319 | <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( mlw_options );
|
---|
| 320 | mlw_options-><a href="qpopupmenu.html#setCheckable">setCheckable</a>( TRUE );
|
---|
| 321 | for (int mlw = 0; mlw <= max_mlw; mlw++) {
|
---|
| 322 | <a href="qstring.html">QString</a> str;
|
---|
| 323 | str.<a href="qstring.html#sprintf">sprintf</a>("%d Pixels", mlw);
|
---|
| 324 | mlw_options-><a href="qmenudata.html#insertItem">insertItem</a>( str, mlw_id | mlw );
|
---|
| 325 | }
|
---|
| 326 | f_options-><a href="qmenudata.html#insertItem">insertItem</a>( "Midline Width", mlw_options );
|
---|
| 327 | connect( mlw_options, SIGNAL(<a href="qpopupmenu.html#activated">activated</a>(int)),
|
---|
| 328 | this, SLOT(doFMenuItem(int)) );
|
---|
| 329 | mw_options = new <a href="qpopupmenu.html">QPopupMenu</a>( menubar );
|
---|
| 330 | <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( mw_options );
|
---|
| 331 | mw_options-><a href="qpopupmenu.html#setCheckable">setCheckable</a>( TRUE );
|
---|
| 332 | for (int mw = 0; mw <= max_mw; mw++) {
|
---|
| 333 | <a href="qstring.html">QString</a> str;
|
---|
| 334 | str.<a href="qstring.html#sprintf">sprintf</a>("%d Pixels", mw);
|
---|
| 335 | mw_options-><a href="qmenudata.html#insertItem">insertItem</a>( str, mw_id | mw );
|
---|
| 336 | }
|
---|
| 337 | f_options-><a href="qmenudata.html#insertItem">insertItem</a>( "Margin Width", mw_options );
|
---|
| 338 | connect( mw_options, SIGNAL(<a href="qpopupmenu.html#activated">activated</a>(int)),
|
---|
| 339 | this, SLOT(doFMenuItem(int)) );
|
---|
| 340 |
|
---|
| 341 | setVPMenuItems();
|
---|
| 342 | setFMenuItems();
|
---|
| 343 |
|
---|
| 344 | <a href="qvboxlayout.html">QVBoxLayout</a>* vbox = new <a href="qvboxlayout.html">QVBoxLayout</a>(this);
|
---|
| 345 | <a name="x631"></a> vbox-><a href="qlayout.html#setMenuBar">setMenuBar</a>(menubar);
|
---|
| 346 | <a name="x632"></a> menubar-><a href="qmenubar.html#setSeparator">setSeparator</a>(QMenuBar::InWindowsStyle);
|
---|
| 347 | vbox-><a href="qboxlayout.html#addWidget">addWidget</a>(vp);
|
---|
| 348 | <a name="x630"></a> vbox-><a href="qlayout.html#activate">activate</a>();
|
---|
| 349 |
|
---|
| 350 | corner = new <a href="qsizegrip.html">QSizeGrip</a>(this);
|
---|
| 351 | <a name="x658"></a> corner-><a href="qwidget.html#hide">hide</a>();
|
---|
| 352 | }
|
---|
| 353 |
|
---|
| 354 | private slots:
|
---|
| 355 | void doVPMenuItem(int id)
|
---|
| 356 | {
|
---|
| 357 | if (id == vauto_id ) {
|
---|
| 358 | <a name="x653"></a> vp-><a href="qscrollview.html#setVScrollBarMode">setVScrollBarMode</a>(QScrollView::Auto);
|
---|
| 359 | } else if (id == vaoff_id) {
|
---|
| 360 | vp-><a href="qscrollview.html#setVScrollBarMode">setVScrollBarMode</a>(QScrollView::AlwaysOff);
|
---|
| 361 | } else if (id == vaon_id) {
|
---|
| 362 | vp-><a href="qscrollview.html#setVScrollBarMode">setVScrollBarMode</a>(QScrollView::AlwaysOn);
|
---|
| 363 | } else if (id == hauto_id) {
|
---|
| 364 | <a name="x652"></a> vp-><a href="qscrollview.html#setHScrollBarMode">setHScrollBarMode</a>(QScrollView::Auto);
|
---|
| 365 | } else if (id == haoff_id) {
|
---|
| 366 | vp-><a href="qscrollview.html#setHScrollBarMode">setHScrollBarMode</a>(QScrollView::AlwaysOff);
|
---|
| 367 | } else if (id == haon_id) {
|
---|
| 368 | vp-><a href="qscrollview.html#setHScrollBarMode">setHScrollBarMode</a>(QScrollView::AlwaysOn);
|
---|
| 369 | } else if (id == corn_id) {
|
---|
| 370 | <a name="x647"></a> bool corn = !vp-><a href="qscrollview.html#cornerWidget">cornerWidget</a>();
|
---|
| 371 | <a name="x651"></a> vp-><a href="qscrollview.html#setCornerWidget">setCornerWidget</a>(corn ? corner : 0);
|
---|
| 372 | } else {
|
---|
| 373 | return; // Not for us to process.
|
---|
| 374 | }
|
---|
| 375 | setVPMenuItems();
|
---|
| 376 | }
|
---|
| 377 |
|
---|
| 378 | void setVPMenuItems()
|
---|
| 379 | {
|
---|
| 380 | <a name="x654"></a> QScrollView::ScrollBarMode vm = vp-><a href="qscrollview.html#vScrollBarMode">vScrollBarMode</a>();
|
---|
| 381 | <a name="x636"></a> vp_options-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( vauto_id, vm == QScrollView::Auto );
|
---|
| 382 | vp_options-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( vaoff_id, vm == QScrollView::AlwaysOff );
|
---|
| 383 | vp_options-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( vaon_id, vm == QScrollView::AlwaysOn );
|
---|
| 384 |
|
---|
| 385 | <a name="x649"></a> QScrollView::ScrollBarMode hm = vp-><a href="qscrollview.html#hScrollBarMode">hScrollBarMode</a>();
|
---|
| 386 | vp_options-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( hauto_id, hm == QScrollView::Auto );
|
---|
| 387 | vp_options-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( haoff_id, hm == QScrollView::AlwaysOff );
|
---|
| 388 | vp_options-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( haon_id, hm == QScrollView::AlwaysOn );
|
---|
| 389 |
|
---|
| 390 | vp_options-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( corn_id, !!vp-><a href="qscrollview.html#cornerWidget">cornerWidget</a>() );
|
---|
| 391 | }
|
---|
| 392 |
|
---|
| 393 | void doFMenuItem(int id)
|
---|
| 394 | {
|
---|
| 395 | if (id & style_id) {
|
---|
| 396 | int sty;
|
---|
| 397 |
|
---|
| 398 | if (id == style_id) {
|
---|
| 399 | sty = 0;
|
---|
| 400 | } else if (id & QFrame::MShape) {
|
---|
| 401 | <a name="x622"></a> sty = vp-><a href="qframe.html#frameStyle">frameStyle</a>()&QFrame::MShadow;
|
---|
| 402 | sty = (sty ? sty : <a href="qframe.html">QFrame</a>::Plain) | (id&QFrame::MShape);
|
---|
| 403 | } else {
|
---|
| 404 | sty = vp-><a href="qframe.html#frameStyle">frameStyle</a>()&QFrame::MShape;
|
---|
| 405 | sty = (sty ? sty : <a href="qframe.html">QFrame</a>::Box) | (id&QFrame::MShadow);
|
---|
| 406 | }
|
---|
| 407 | <a name="x626"></a> vp-><a href="qframe.html#setFrameStyle">setFrameStyle</a>(sty);
|
---|
| 408 | } else if (id & lw_id) {
|
---|
| 409 | <a name="x627"></a> vp-><a href="qframe.html#setLineWidth">setLineWidth</a>(id&~lw_id);
|
---|
| 410 | } else if (id & mlw_id) {
|
---|
| 411 | <a name="x629"></a> vp-><a href="qframe.html#setMidLineWidth">setMidLineWidth</a>(id&~mlw_id);
|
---|
| 412 | } else {
|
---|
| 413 | <a name="x628"></a> vp-><a href="qframe.html#setMargin">setMargin</a>(id&~mw_id);
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | <a name="x662"></a> vp-><a href="qwidget.html#update">update</a>();
|
---|
| 417 | setFMenuItems();
|
---|
| 418 | }
|
---|
| 419 |
|
---|
| 420 | void setFMenuItems()
|
---|
| 421 | {
|
---|
| 422 | int sty = vp-><a href="qframe.html#frameStyle">frameStyle</a>();
|
---|
| 423 |
|
---|
| 424 | f_options-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( style_id, !sty );
|
---|
| 425 |
|
---|
| 426 | for (int i=1; i <= f_laststyle; i++) {
|
---|
| 427 | <a name="x643"></a> int id = f_options-><a href="qpopupmenu.html#idAt">idAt</a>(i);
|
---|
| 428 | if (id & QFrame::MShape)
|
---|
| 429 | f_options-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( id,
|
---|
| 430 | ((id&QFrame::MShape) == (sty&QFrame::MShape)) );
|
---|
| 431 | else
|
---|
| 432 | f_options-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( id,
|
---|
| 433 | ((id&QFrame::MShadow) == (sty&QFrame::MShadow)) );
|
---|
| 434 | }
|
---|
| 435 |
|
---|
| 436 | for (int lw=1; lw<=max_lw; lw++)
|
---|
| 437 | <a name="x623"></a> lw_options-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( lw_id|lw, vp-><a href="qframe.html#lineWidth">lineWidth</a>() == lw );
|
---|
| 438 |
|
---|
| 439 | for (int mlw=0; mlw<=max_mlw; mlw++)
|
---|
| 440 | <a name="x625"></a> mlw_options-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( mlw_id|mlw, vp-><a href="qframe.html#midLineWidth">midLineWidth</a>() == mlw );
|
---|
| 441 |
|
---|
| 442 | for (int mw=0; mw<=max_mw; mw++)
|
---|
| 443 | <a name="x624"></a> mw_options-><a href="qmenudata.html#setItemChecked">setItemChecked</a>( mw_id|mw, vp-><a href="qframe.html#margin">margin</a>() == mw );
|
---|
| 444 | }
|
---|
| 445 |
|
---|
| 446 | private:
|
---|
| 447 | <a href="qscrollview.html">QScrollView</a>* vp;
|
---|
| 448 | <a href="qpopupmenu.html">QPopupMenu</a>* vp_options;
|
---|
| 449 | <a href="qpopupmenu.html">QPopupMenu</a>* f_options;
|
---|
| 450 | <a href="qpopupmenu.html">QPopupMenu</a>* lw_options;
|
---|
| 451 | <a href="qpopupmenu.html">QPopupMenu</a>* mlw_options;
|
---|
| 452 | <a href="qpopupmenu.html">QPopupMenu</a>* mw_options;
|
---|
| 453 | <a href="qsizegrip.html">QSizeGrip</a>* corner;
|
---|
| 454 |
|
---|
| 455 | int vauto_id, vaoff_id, vaon_id,
|
---|
| 456 | hauto_id, haoff_id, haon_id,
|
---|
| 457 | corn_id;
|
---|
| 458 |
|
---|
| 459 | int f_laststyle;
|
---|
| 460 | };
|
---|
| 461 |
|
---|
| 462 | int main( int argc, char **argv )
|
---|
| 463 | {
|
---|
| 464 | <a href="qapplication.html">QApplication</a> a( argc, argv );
|
---|
| 465 |
|
---|
| 466 | ScrollViewExample ve1(1,0,"ve1");
|
---|
| 467 | ScrollViewExample ve2(2,0,"ve2");
|
---|
| 468 | ScrollViewExample ve3(3,0,"ve3");
|
---|
| 469 | ve1.<a href="qwidget.html#setCaption">setCaption</a>("Qt Example - Scrollviews");
|
---|
| 470 | ve1.<a href="qwidget.html#show">show</a>();
|
---|
| 471 | ve2.<a href="qwidget.html#setCaption">setCaption</a>("Qt Example - Scrollviews");
|
---|
| 472 | ve2.<a href="qwidget.html#show">show</a>();
|
---|
| 473 | ve3.<a href="qwidget.html#setCaption">setCaption</a>("Qt Example - Scrollviews");
|
---|
| 474 | ve3.<a href="qwidget.html#show">show</a>();
|
---|
| 475 |
|
---|
| 476 | QObject::<a href="qobject.html#connect">connect</a>(qApp, SIGNAL(<a href="qapplication.html#lastWindowClosed">lastWindowClosed</a>()), qApp, SLOT(<a href="qapplication.html#quit">quit</a>()));
|
---|
| 477 |
|
---|
| 478 | return a.<a href="qapplication.html#exec">exec</a>();
|
---|
| 479 | }
|
---|
| 480 |
|
---|
| 481 | #include "scrollview.moc"
|
---|
| 482 | </pre>
|
---|
| 483 |
|
---|
| 484 | <p>See also <a href="examples.html">Examples</a>.
|
---|
| 485 |
|
---|
| 486 | <!-- eof -->
|
---|
| 487 | <p><address><hr><div align=center>
|
---|
| 488 | <table width=100% cellspacing=0 border=0><tr>
|
---|
| 489 | <td>Copyright © 2007
|
---|
| 490 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
| 491 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
| 492 | </table></div></address></body>
|
---|
| 493 | </html>
|
---|