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

📄 desktop-example.html

📁 QT 下载资料仅供参考
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/examples/desktop/desktop.doc:5 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Painting on the Desktop</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: #ffffff; color: black; }--></style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr bgcolor="#E5E5E5"><td valign=center> <a href="index.html"><font color="#004faf">Home</font></a> | <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a> | <a href="functions.html"><font color="#004faf">Functions</font></a></td><td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Painting on the Desktop</h1> <p> The desktop demo contains three routines, each of which drawssomething on the desktop.  It does some nice stuff with <a href="qpainter.html">QPainter</a>,and also demonstrates how one can treat the desktop as a widget likeany other.<p> <hr><p> Implementation:<p> <pre>/****************************************************************************** $Id:  qt/desktop.cpp   3.0.5   edited Oct 12 2001 $**** 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 href="qimage-h.html">qimage.h</a>&gt;#include &lt;<a href="qbitmap-h.html">qbitmap.h</a>&gt;#include &lt;<a href="qpainter-h.html">qpainter.h</a>&gt;#include &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;#include &lt;<a href="qdropsite-h.html">qdropsite.h</a>&gt;#include &lt;<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="x1759"></a>    <a href="qwidget.html">QWidget</a> *d = QApplication::<a href="qapplication.html#desktop">desktop</a>();<a name="x1799"></a>    d-&gt;<a href="qwidget.html#setBackgroundColor">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 href="qpointarray.html">QPointArray</a> *a = new <a href="qpointarray.html">QPointArray</a>[ maxcurves ];    register QPointArray *p;<a name="x1798"></a>    <a href="qrect.html">QRect</a> r = d-&gt;<a href="qwidget.html#rect">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<a name="x1794"></a>        p-&gt;setPoint( i, (kindaRand()&amp;0x7fff) % r.<a href="qrect.html#width">width</a>(),<a name="x1787"></a>                        (kindaRand()&amp;0x7fff) % r.<a href="qrect.html#height">height</a>() );        xvel[i] = velocity(i);        yvel[i] = velocity(i);    }    <a href="qpainter.html">QPainter</a> paint;<a name="x1771"></a>    paint.<a href="qpainter.html#begin">begin</a>( d );                           // start painting desktop    for ( int ntimes=0; ntimes&lt;2000; ntimes++ ) {        paint.<a href="qpainter.html#setBrush">setBrush</a>( QColor(kindaRand()%360, 180, 255, QColor::Hsv) );<a name="x1773"></a>        paint.<a href="qpainter.html#drawPolygon">drawPolygon</a>( a[head] );        if ( ++tail &gt;= maxcurves )            tail = 0;<a name="x1789"></a><a name="x1788"></a>        int minx=r.<a href="qrect.html#left">left</a>(), maxx=r.<a href="qrect.html#right">right</a>();<a name="x1793"></a><a name="x1786"></a>        int miny=r.<a href="qrect.html#top">top</a>(),  maxy=r.<a href="qrect.html#bottom">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 );        }    }<a name="x1775"></a>    paint.<a href="qpainter.html#end">end</a>();                                // painting done    delete[] a;}//// Rotate pattern on desktop.//void rotate(){    int i;    const int w = 64;    const int h = 64;    <a href="qimage.html">QImage</a> image( w, h, 8, 128 );               // create image    for ( i=0; i&lt;128; i++ )                     // build color table<a name="x1768"></a>        image.<a href="qimage.html#setColor">setColor</a>( i, qRgb(i,0,0) );    for ( int y=0; y&lt;h; y++ ) {                 // set image pixels<a name="x1767"></a>        uchar *p = image.<a href="qimage.html#scanLine">scanLine</a>(y);        for ( int x=0; x&lt;w; x++ )            *p++ = (x+y)%128;    }    <a href="qpixmap.html">QPixmap</a> pm;    pm = image;                                 // convert image to pixmap<a name="x1783"></a>    pm.<a href="qpixmap.html#setOptimization">setOptimization</a>( QPixmap::BestOptim );   // rotation will be faster    <a href="qwidget.html">QWidget</a> *d = QApplication::<a href="qapplication.html#desktop">desktop</a>();       // w = desktop widget    for ( i=0; i&lt;=360; i += 2 ) {        <a href="qwmatrix.html">QWMatrix</a> m;<a name="x1802"></a>        m.<a href="qwmatrix.html#rotate">rotate</a>( i );                          // rotate coordinate system<a name="x1785"></a>        <a href="qpixmap.html">QPixmap</a> rpm = pm.<a href="qpixmap.html#xForm">xForm</a>( m );            // rpm = rotated pixmap<a name="x1800"></a>        d-&gt;<a href="qwidget.html#setBackgroundPixmap">setBackgroundPixmap</a>( rpm );          // set desktop pixmap<a name="x1801"></a>        d-&gt;<a href="qwidget.html#update">update</a>();                            // repaint desktop    }}//// Generates a marble-like pattern in pm.//void generateStone( <a href="qpixmap.html">QPixmap</a> *pm,                    const <a href="qcolor.html">QColor</a> &amp;c1, const <a href="qcolor.html">QColor</a> &amp;c2, const <a href="qcolor.html">QColor</a> &amp;c3 ){    <a href="qpainter.html">QPainter</a> p;    <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#begin">begin</a>( pm );<a name="x1784"></a>    for( int i = 0 ; i &lt; pm-&gt;<a href="qpixmap.html#width">width</a>() ; i++ )

⌨️ 快捷键说明

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