⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 desktop-desktop-cpp.html

📁 qtopiaphone英文帮助,用于初学者和开发人员,初学者可以用来学习,开发人员可以用来资料查询.
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!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 - desktop/desktop.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>Painting on the Desktop</h1><br clear="all">  The desktop demo contains three routines, each of which draws  something on the desktop.  It does some nice stuff with QPainter,  and also demonstrates how one can treat the desktop as a widget like  any other.  <hr>  Implementation:<pre>/****************************************************************************** &#36;Id&#58; qt/examples/desktop/desktop.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 &lt;<a name="qimage.h"></a><a href="qimage-h.html">qimage.h</a>&gt;#include &lt;<a name="qbitmap.h"></a><a href="qbitmap-h.html">qbitmap.h</a>&gt;#include &lt;<a name="qpainter.h"></a><a href="qpainter-h.html">qpainter.h</a>&gt;#include &lt;<a name="qapplication.h"></a><a href="qapplication-h.html">qapplication.h</a>&gt;#include &lt;<a name="qdropsite.h"></a><a href="qdropsite-h.html">qdropsite.h</a>&gt;#include &lt;<a name="qdragobject.h"></a><a href="qdragobject-h.html">qdragobject.h</a>&gt;#include &lt;stdio.h&gt;static double seed = 0.353535353535;static const int KINDA_RAND_MAX = 32767;static int kindaRand(){    seed = seed*147;    seed = seed - (double) ((int) seed);    return (int) ( seed*(KINDA_RAND_MAX + 1) );}static int velocity( int i )                    // change velocity{    const int velmax = 15;    const int velmin = 4;    if ( i == 1 || i == 2 )        i = (kindaRand()&amp;0x7fff % velmax)/3 + velmin;    else        i = (kindaRand()&amp;0x7fff % velmax) + velmin;    return i;}//// Draw polygon on desktop.//void poly(){    <a name="QWidget"></a><a href="qwidget.html">QWidget</a> *d = QApplication::desktop();    d-&gt;<a name="setBackgroundColor"></a><a href="qwidget.html#c09181">setBackgroundColor</a>( Qt::white );         // white desktop    const int maxpoints = 5;    const int maxcurves = 8;    static int xvel[maxpoints];    static int yvel[maxpoints];    int head = 0;    int tail = -maxcurves + 2;    <a name="QPointArray"></a><a href="qpointarray.html">QPointArray</a> *a = new <a href="qpointarray.html">QPointArray</a>[ maxcurves ];    register QPointArray *p;    <a name="QRect"></a><a href="qrect.html">QRect</a> r = d-&gt;<a name="rect"></a><a href="qwidget.html#75ae71">rect</a>();                        // desktop rectangle    int i;    for ( i=0; i&lt;maxcurves; i++ )        a[i].resize( maxpoints );    p = &amp;a[0];    for ( i=0; i&lt;maxpoints; i++ ) {             // setup first polygon points        p-&gt;setPoint( i, (kindaRand()&amp;0x7fff) % r.<a name="width"></a><a href="qrect.html#45fe95">width</a>(),                        (kindaRand()&amp;0x7fff) % r.<a name="height"></a><a href="qrect.html#581ab8">height</a>() );        xvel[i] = velocity(i);        yvel[i] = velocity(i);    }    <a name="QPainter"></a><a href="qpainter.html">QPainter</a> paint;    paint.<a name="begin"></a><a href="qpainter.html#02ed5d">begin</a>( d );                           // start painting desktop    for ( int ntimes=0; ntimes&lt;2000; ntimes++ ) {        paint.<a name="setBrush"></a><a href="qpainter.html#3e0cc8">setBrush</a>( <a name="QColor"></a><a href="qcolor.html">QColor</a>(kindaRand()%360, 180, 255, QColor::Hsv) );        paint.<a name="drawPolygon"></a><a href="qpainter.html#2efe17">drawPolygon</a>( a[head] );        if ( ++tail &gt;= maxcurves )            tail = 0;        int minx=r.<a name="left"></a><a href="qrect.html#369cab">left</a>(), maxx=r.<a name="right"></a><a href="qrect.html#896e32">right</a>();        int miny=r.<a name="top"></a><a href="qrect.html#4dd27e">top</a>(),  maxy=r.<a name="bottom"></a><a href="qrect.html#2de4b0">bottom</a>();        int x, y;        p = &amp;a[head];        if ( ++head &gt;= maxcurves )            head = 0;        for ( i=0; i&lt;maxpoints; i++ ) {         // calc new curve            p-&gt;point( i, &amp;x, &amp;y );            x += xvel[i];            y += yvel[i];            if ( x &gt;= maxx ) {                x = maxx - (x - maxx + 1);                xvel[i] = -velocity(i);            }            if ( x &lt;= minx ) {                x = minx + (minx - x + 1);                xvel[i] = velocity(i);            }            if ( y &gt;= maxy ) {                y = maxy - (y - maxy + 1);                yvel[i] = -velocity(i);            }            if ( y &lt;= miny ) {                y = miny + (miny - y + 1);                yvel[i] = velocity(i);            }            a[head].setPoint( i, x, y );        }    }    paint.<a name="end"></a><a href="qpainter.html#365784">end</a>();                                // painting done    delete[] a;}//// Rotate pattern on desktop.//void rotate(){    int i;    const int w = 64;    const int h = 64;    <a name="QImage"></a><a href="qimage.html">QImage</a> image( w, h, 8, 128 );               // create image    for ( i=0; i&lt;128; i++ )                     // build color table        image.<a name="setColor"></a><a href="qimage.html#271983">setColor</a>( i, <a name="qRgb"></a><a href="qcolor.html#dab147">qRgb</a>(i,0,0) );    for ( int y=0; y&lt;h; y++ ) {                 // set image pixels        uchar *p = image.<a name="scanLine"></a><a href="qimage.html#7632a9">scanLine</a>(y);        for ( int x=0; x&lt;w; x++ )            *p++ = (x+y)%128;    }    <a name="QPixmap"></a><a href="qpixmap.html">QPixmap</a> pm;    pm = image;                                 // convert image to pixmap    pm.<a name="setOptimization"></a><a href="qpixmap.html#e6ae80">setOptimization</a>( QPixmap::BestOptim );   // rotation will be faster    <a href="qwidget.html">QWidget</a> *d = QApplication::desktop();       // w = desktop widget    for ( i=0; i&lt;=360; i += 2 ) {        <a name="QWMatrix"></a><a href="qwmatrix.html">QWMatrix</a> m;        m.<a name="rotate"></a><a href="qwmatrix.html#71020d">rotate</a>( i );                          // rotate coordinate system        <a href="qpixmap.html">QPixmap</a> rpm = pm.<a name="xForm"></a><a href="qpixmap.html#ff5fcf">xForm</a>( m );            // rpm = rotated pixmap        d-&gt;<a name="setBackgroundPixmap"></a><a href="qwidget.html#7e417f">setBackgroundPixmap</a>( rpm );          // set desktop pixmap        d-&gt;<a name="update"></a><a href="qwidget.html#a66a88">update</a>();                            // repaint desktop    }}//// Generates a marble-like pattern in pm.//void generateStone( <a href="qpixmap.html">QPixmap</a> *pm,                    const QColor &amp;c1, const QColor &amp;c2, const QColor &amp;c3 ){    <a href="qpainter.html">QPainter</a> p;    <a name="QPen"></a><a href="qpen.html">QPen</a> p1 ( c1, 0 );    <a href="qpen.html">QPen</a> p2 ( c2, 0 );    <a href="qpen.html">QPen</a> p3 ( c3, 0 );    p.<a href="qpainter.html#02ed5d">begin</a>( pm );

⌨️ 快捷键说明

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