progress-example.html

来自「QT 下载资料仅供参考」· HTML 代码 · 共 388 行 · 第 1/2 页

HTML
388
字号
        options = new <a href="qpopupmenu.html">QPopupMenu</a>();        <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( options );        menubar-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "&amp;Options", options );        td_id = options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Timer driven", this, SLOT(timerDriven()) );        ld_id = options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Loop driven", this, SLOT(loopDriven()) );        options-&gt;<a href="qmenudata.html#insertSeparator">insertSeparator</a>();        dl_id = options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Default label", this, SLOT(defaultLabel()) );        cl_id = options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Custom label", this, SLOT(customLabel()) );        options-&gt;<a href="qmenudata.html#insertSeparator">insertSeparator</a>();        md_id = options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "No minimum duration", this, SLOT(toggleMinimumDuration()) );<a name="x49"></a>        options-&gt;<a href="qpopupmenu.html#setCheckable">setCheckable</a>( TRUE );        loopDriven();        defaultLabel();        setFixedSize( 400, 300 );        setBackgroundColor( black );    }public slots:    void doMenuItem(int id)    {        if (id &gt;= first_draw_item &amp;&amp; id &lt;= last_draw_item)            draw(drawItemRects(id));    }    void stopDrawing() { got_stop = TRUE; }    void timerDriven()    {        timer_driven = TRUE;<a name="x39"></a>        options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( td_id, TRUE );        options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( ld_id, FALSE );    }    void loopDriven()    {        timer_driven = FALSE;        options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( ld_id, TRUE );        options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( td_id, FALSE );    }    void defaultLabel()    {        default_label = TRUE;        options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( dl_id, TRUE );        options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( cl_id, FALSE );    }    void customLabel()    {        default_label = FALSE;        options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( dl_id, FALSE );        options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( cl_id, TRUE );    }    void toggleMinimumDuration()    {        options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( md_id,<a name="x38"></a>           !options-&gt;<a href="qmenudata.html#isItemChecked">isItemChecked</a>( md_id ) );    }private:    void timerEvent( <a href="qtimerevent.html">QTimerEvent</a>* )    {<a name="x54"></a><a name="x53"></a>        pb-&gt;<a href="qprogressdialog.html#setProgress">setProgress</a>( pb-&gt;<a href="qprogressdialog.html#totalSteps">totalSteps</a>() - rects );        rects--;        {            <a href="qpainter.html">QPainter</a> p(this);            int ww = width();            int wh = height();            if ( ww &gt; 8 &amp;&amp; wh &gt; 8 ) {                <a href="qcolor.html">QColor</a> c(rand()%255, rand()%255, rand()%255);                int x = rand() % (ww-8);                int y = rand() % (wh-8);                int w = rand() % (ww-x);                int h = rand() % (wh-y);<a name="x43"></a>                p.<a href="qpainter.html#fillRect">fillRect</a>( x, y, w, h, c );            }        }        if (!rects || got_stop) {            pb-&gt;<a href="qprogressdialog.html#setProgress">setProgress</a>( pb-&gt;<a href="qprogressdialog.html#totalSteps">totalSteps</a>() );            <a href="qpainter.html">QPainter</a> p(this);            p.<a href="qpainter.html#fillRect">fillRect</a>(0, 0, width(), height(), backgroundColor());            enableDrawingItems(TRUE);            killTimers();            delete pb;            pb = 0;        }    }    <a href="qprogressdialog.html">QProgressDialog</a>* newProgressDialog( const char* label, int steps, bool modal )    {        <a href="qprogressdialog.html">QProgressDialog</a> *d = new <a href="qprogressdialog.html">QProgressDialog</a>(label, "Cancel", steps, this,                                                 "progress", modal);        if ( options-&gt;<a href="qmenudata.html#isItemChecked">isItemChecked</a>( md_id ) )<a name="x52"></a>            d-&gt;<a href="qprogressdialog.html#setMinimumDuration">setMinimumDuration</a>(0);        if ( !default_label )<a name="x51"></a>            d-&gt;<a href="qprogressdialog.html#setLabel">setLabel</a>( new AnimatedThingy(d,label) );        return d;    }    void enableDrawingItems(bool yes)    {        for (int i=first_draw_item; i&lt;=last_draw_item; i++) {<a name="x40"></a>            menubar-&gt;<a href="qmenudata.html#setItemEnabled">setItemEnabled</a>(i, yes);        }    }    void draw(int n)    {        if ( timer_driven ) {            if ( pb ) {                <a href="qapplication.html#qWarning">qWarning</a>("This cannot happen!");                return;            }            rects = n;            pb = newProgressDialog("Drawing rectangles.\n"                                   "Using timer event.", n, FALSE);            pb-&gt;<a href="qwidget.html#setCaption">setCaption</a>("Please Wait");<a name="x50"></a>            connect(pb, SIGNAL(<a href="qprogressdialog.html#cancelled">cancelled</a>()), this, SLOT(stopDrawing()));            enableDrawingItems(FALSE);            startTimer(0);            got_stop = FALSE;        } else {            <a href="qprogressdialog.html">QProgressDialog</a>* lpb = newProgressDialog(                        "Drawing rectangles.\nUsing loop.", n, TRUE);            lpb-&gt;<a href="qwidget.html#setCaption">setCaption</a>("Please Wait");            <a href="qpainter.html">QPainter</a> p(this);            for (int i=0; i&lt;n; i++) {                lpb-&gt;<a href="qprogressdialog.html#setProgress">setProgress</a>(i);<a name="x55"></a>                if ( lpb-&gt;<a href="qprogressdialog.html#wasCancelled">wasCancelled</a>() )                    break;                <a href="qcolor.html">QColor</a> c(rand()%255, rand()%255, rand()%255);                int x = rand()%(width()-8);                int y = rand()%(height()-8);                int w = rand()%(width()-x);                int h = rand()%(height()-y);                p.<a href="qpainter.html#fillRect">fillRect</a>(x,y,w,h,c);            }            p.<a href="qpainter.html#fillRect">fillRect</a>(0, 0, width(), height(), backgroundColor());            delete lpb;        }    }    <a href="qmenubar.html">QMenuBar</a>* menubar;    <a href="qprogressdialog.html">QProgressDialog</a>* pb;    <a href="qpopupmenu.html">QPopupMenu</a>* options;    int td_id, ld_id;    int dl_id, cl_id;    int md_id;    int rects;    bool timer_driven;    bool default_label;    bool got_stop;};int main( int argc, char **argv ){    <a href="qapplication.html">QApplication</a> a( argc, argv );    int wincount = argc &gt; 1 ? atoi(argv[1]) : 1;    for ( int i=0; i&lt;wincount; i++ ) {        CPUWaster* cpuw = new CPUWaster;        if ( i == 0 ) a.<a href="qapplication.html#setMainWidget">setMainWidget</a>(cpuw);        cpuw-&gt;<a href="qwidget.html#show">show</a>();    }    return a.<a href="qapplication.html#exec">exec</a>();}#include "progress.moc"</pre><p>See also <a href="examples.html">Examples</a>.<!-- eof --><p><address><hr><div align=center><table width=100% cellspacing=0 border=0><tr><td>Copyright &copy; 2002 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a><td align=right><div align=right>Qt version 3.0.5</div></table></div></address></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?