# kdefx Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kdrawutil.cpp

    00001 /* This file is part of the KDE libraries
    00002    Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org>
    00003
    00004    This library is free software; you can redistribute it and/or
    00005    modify it under the terms of the GNU Library General Public
    00006    License version 2 as published by the Free Software Foundation.
    00007
    00008    This library is distributed in the hope that it will be useful,
    00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00011    Library General Public License for more details.
    00012
    00013    You should have received a copy of the GNU Library General Public License
    00014    along with this library; see the file COPYING.LIB.  If not, write to
    00015    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00016    Boston, MA 02111-1307, USA.
    00017 */
    00018 #include "kdrawutil.h"
    00019 #include <qdrawutil.h>
    00020
    00021 KDEFX_EXPORT void kDrawNextButton(QPainter *p, int x, int y, int w, int h,
    00022                      const QColorGroup &g, bool sunken,
    00023                      const QBrush *fill)
    00024 {
    00025     QPen oldPen = p->pen();
    00026     int x2 = x+w-1;
    00027     int y2 = y+h-1;
    00028     p->fillRect(x+1, y+1, w-2, h-2,
    00029                 fill ? *fill : g.brush(QColorGroup::Button));
    00030     p->setPen(sunken ? Qt::black : g.light());
    00031     p->drawLine(x, y, x2-1, y);
    00032     p->drawLine(x, y, x, y2-1);
    00033     p->setPen(sunken ? g.midlight() : g.mid());
    00034     p->drawLine(x+1, y2-1, x2-1, y2-1);
    00035     p->drawLine(x2-1, y+1, x2-1, y2-1);
    00036     p->setPen(sunken ? g.light() : Qt::black);
    00037     p->drawLine(x, y2, x2, y2);
    00038     p->drawLine(x2, y, x2, y2);
    00039     p->setPen(oldPen);
    00040 }
    00041
    00042
    00043 KDEFX_EXPORT void kDrawNextButton(QPainter *p, const QRect &r, const QColorGroup &g,
    00044                      bool sunken, const QBrush *fill)
    00045 {
    00046     kDrawNextButton(p, r.x(), r.y(), r.width(), r.height(), g, sunken, fill);
    00047 }
    00048
    00049 KDEFX_EXPORT void kDrawBeButton(QPainter *p, int x, int y, int w, int h,
    00050                    const QColorGroup &g, bool sunken, const QBrush *fill)
    00051 {
    00052     QPen oldPen = p->pen();
    00053     int x2 = x+w-1;
    00054     int y2 = y+h-1;
    00055     p->setPen(g.dark());
    00056     p->drawLine(x+1, y, x2-1, y);
    00057     p->drawLine(x, y+1, x, y2-1);
    00058     p->drawLine(x+1, y2, x2-1, y2);
    00059     p->drawLine(x2, y+1, x2, y2-1);
    00060
    00061
    00062     if(!sunken){
    00063         p->setPen(g.light());
    00064         p->drawLine(x+2, y+2, x2-1, y+2);
    00065         p->drawLine(x+2, y+3, x2-2, y+3);
    00066         p->drawLine(x+2, y+4, x+2, y2-1);
    00067         p->drawLine(x+3, y+4, x+3, y2-2);
    00068     }
    00069     else{
    00070         p->setPen(g.mid());
    00071         p->drawLine(x+2, y+2, x2-1, y+2);
    00072         p->drawLine(x+2, y+3, x2-2, y+3);
    00073         p->drawLine(x+2, y+4, x+2, y2-1);
    00074         p->drawLine(x+3, y+4, x+3, y2-2);
    00075     }
    00076
    00077
    00078     p->setPen(sunken? g.light() : g.mid());
    00079     p->drawLine(x2-1, y+2, x2-1, y2-1);
    00080     p->drawLine(x+2, y2-1, x2-1, y2-1);
    00081
    00082     p->setPen(g.mid());
    00083     p->drawLine(x+1, y+1, x2-1, y+1);
    00084     p->drawLine(x+1, y+2, x+1, y2-1);
    00085     p->drawLine(x2-2, y+3, x2-2, y2-2);
    00086
    00087     if(fill)
    00088         p->fillRect(x+4, y+4, w-6, h-6, *fill);
    00089
    00090     p->setPen(oldPen);
    00091 }
    00092
    00093 KDEFX_EXPORT void kDrawBeButton(QPainter *p, QRect &r, const QColorGroup &g, bool sunken,
    00094                    const QBrush *fill)
    00095 {
    00096     kDrawBeButton(p, r.x(), r.y(), r.width(), r.height(), g, sunken, fill);
    00097 }
    00098
    00099 KDEFX_EXPORT void kDrawRoundButton(QPainter *p, const QRect &r, const QColorGroup &g,
    00100                       bool sunken)
    00101 {
    00102     int x, y, x2, y2;
    00103     r.coords(&x, &y, &x2, &y2);
    00104     if(r.width() > 16 && r.height() > 16){
    00105         QPen oldPen = p->pen();
    00106         QPointArray hPntArray, lPntArray;
    00107         hPntArray.putPoints(0, 12, x+4,y+1, x+5,y+1, // top left
    00108                             x+3,y+2, x+2,y+3, x+1,y+4, x+1,y+5,
    00109                             x+1,y2-5, x+1,y2-4, x+2,y2-3, // half corners
    00110                             x2-5,y+1, x2-4,y+1, x2-3,y+2);
    00111
    00112         lPntArray.putPoints(0, 17, x2-5,y2-1, x2-4,y2-1, // btm right
    00113                             x2-3,y2-2, x2-2,y2-3, x2-1,y2-5, x2-1,y2-4,
    00114
    00115                             x+3,y2-2, x+4,y2-1, x+5,y2-1, //half corners
    00116                             x2-2,y+3, x2-1,y+4, x2-1,y+5,
    00117
    00118                             x2-5,y2-2, x2-4,y2-2, // testing
    00119                             x2-3,y2-3,
    00120                             x2-2,y2-5, x2-2,y2-4);
    00121
    00122         p->setPen(sunken ? g.dark() : g.light());
    00123         p->drawLine(x+6, y, x2-6, y);
    00124         p->drawLine(0, y+6, 0, y2-6);
    00125         p->drawPoints(hPntArray);
    00126
    00127         p->setPen(sunken ? g.light() : g.dark());
    00128         p->drawLine(x+6, y2, x2-6, y2);
    00129         p->drawLine(x+6, y2-1, x2-6, y2-1);
    00130         p->drawLine(x2, y+6, x2, y2-6);
    00131         p->drawLine(x2-1, y+6, x2-1, y2-6);
    00132         p->drawPoints(lPntArray);
    00133         p->setPen(oldPen);
    00134     }
    00135     else
    00136         qDrawWinPanel(p, x, y, r.width(), r.height(), g, sunken);
    00137 }
    00138
    00139 KDEFX_EXPORT void kDrawRoundButton(QPainter *p, int x, int y, int w, int h,
    00140                       const QColorGroup &g, bool sunken)
    00141 {
    00142     QRect r(x, y, w, h);
    00143     kDrawRoundButton(p, r, g, sunken);
    00144 }
    00145
    00146 #define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
    00147
    00148 KDEFX_EXPORT void kDrawRoundMask(QPainter *p, int x, int y, int w, int h, bool clear)
    00149 {
    00150     // round edge fills
    00151     static const QCOORD btm_left_fill[]={ 0,0,1,0,2,0,3,0,4,0,0,1,1,1,2,1,3,1,4,1,
    00152     1,2,2,2,3,2,4,2,2,3,3,3,4,3,3,4,4,4 };
    00153
    00154     static const QCOORD btm_right_fill[]={ 0,0,1,0,2,0,3,0,4,0,0,1,1,1,2,1,3,1,4,
    00155     1,0,2,1,2,2,2,3,2,0,3,1,3,2,3,0,4,1,4 };
    00156
    00157     static const QCOORD top_left_fill[]={ 3,0,4,0,2,1,3,1,4,1,1,2,2,2,3,2,4,2,0,3,
    00158     1,3,2,3,3,3,4,3,0,4,1,4,2,4,3,4,4,4 };
    00159
    00160     static const QCOORD top_right_fill[]={ 0,0,1,0,0,1,1,1,2,1,0,2,1,2,2,2,3,2,0,
    00161     3,1,3,2,3,3,3,4,3,0,4,1,4,2,4,3,4,4,4 };
    00162
    00163     if(clear)
    00164         p->fillRect(x, y, w, h, QBrush(Qt::color0, Qt::SolidPattern));
    00165
    00166     QBrush fillBrush(Qt::color1, Qt::SolidPattern);
    00167     p->setPen(Qt::color1);
    00168     if(w > 16 && h > 16){
    00169         int x2 = x+w-1;
    00170         int y2 = y+h-1;
    00171         QPointArray a(QCOORDARRLEN(top_left_fill), top_left_fill);
    00172         a.translate(1, 1);
    00173         p->drawPoints(a);
    00174         a.setPoints(QCOORDARRLEN(btm_left_fill), btm_left_fill);
    00175         a.translate(1, h-6);
    00176         p->drawPoints(a);
    00177         a.setPoints(QCOORDARRLEN(top_right_fill), top_right_fill);
    00178         a.translate(w-6, 1);
    00179         p->drawPoints(a);
    00180         a.setPoints(QCOORDARRLEN(btm_right_fill), btm_right_fill);
    00181         a.translate(w-6, h-6);
    00182         p->drawPoints(a);
    00183
    00184         p->fillRect(x+6, y, w-12, h, fillBrush);
    00185         p->fillRect(x, y+6, x+6, h-12, fillBrush);
    00186         p->fillRect(x2-6, y+6, x2, h-12, fillBrush);
    00187         p->drawLine(x+6, y, x2-6, y);
    00188         p->drawLine(x+6, y2, x2-6, y2);
    00189         p->drawLine(x, y+6, x, y2-6);
    00190         p->drawLine(x2, y+6, x2, y2-6);
    00191
    00192     }
    00193     else
    00194         p->fillRect(x, y, w, h, fillBrush);
    00195 }
    00196
    00197 KDEFX_EXPORT void kRoundMaskRegion(QRegion &r, int x, int y, int w, int h)
    00198 {
    00199     // using a bunch of QRect lines seems much more efficient than bitmaps or
    00200     // point arrays, even tho it uses more statements
    00201     r += QRect(x+6, y+0, w-12, h);
    00202     r += QRect(x+5, y+1, 1, h-2); // left
    00203     r += QRect(x+4, y+1, 1, h-2);
    00204     r += QRect(x+3, y+2, 1, h-4);
    00205     r += QRect(x+2, y+3, 1, h-6);
    00206     r += QRect(x+1, y+4, 1, h-8);
    00207     r += QRect(x, y+6, 1, h-12);
    00208     int x2 = x+w-1;
    00209     r += QRect(x2-5, y+1, 1, h-2); // right
    00210     r += QRect(x2-4, y+1, 1, h-2);
    00211     r += QRect(x2-3, y+2, 1, h-4);
    00212     r += QRect(x2-2, y+3, 1, h-6);
    00213     r += QRect(x2-1, y+4, 1, h-8);
    00214     r += QRect(x2, y+6, 1, h-12);
    00215 }
    00216
    00217 KDEFX_EXPORT void kColorBitmaps(QPainter *p, const QColorGroup &g, int x, int y,
    00218                    QBitmap *lightColor, QBitmap *midColor,
    00219                    QBitmap *midlightColor, QBitmap *darkColor,
    00220                    QBitmap *blackColor, QBitmap *whiteColor)
    00221 {
    00222     QBitmap *bitmaps[]={lightColor, midColor, midlightColor, darkColor,
    00223         blackColor, whiteColor};
    00224
    00225     QColor colors[]={g.light(), g.mid(), g.midlight(), g.dark(),
    00226         Qt::black, Qt::white};
    00227
    00228     int i;
    00229     for(i=0; i < 6; ++i){
    00230         if(bitmaps[i]){
    00231             if(!bitmaps[i]->mask())
    00232                 bitmaps[i]->setMask(*bitmaps[i]);
    00233             p->setPen(colors[i]);
    00234             p->drawPixmap(x, y, *bitmaps[i]);
    00235         }
    00236     }
    00237 }
    00238
    00239 KDEFX_EXPORT void kColorBitmaps(QPainter *p, const QColorGroup &g, int x, int y, int w,
    00240                    int h, bool isXBitmaps, const uchar *lightColor,
    00241                    const uchar *midColor, const uchar *midlightColor,
    00242                    const uchar *darkColor, const uchar *blackColor,
    00243                    const uchar *whiteColor)
    00244 {
    00245     const uchar *data[]={lightColor, midColor, midlightColor, darkColor,
    00246         blackColor, whiteColor};
    00247
    00248     QColor colors[]={g.light(), g.mid(), g.midlight(), g.dark(),
    00249         Qt::black, Qt::white};
    00250
    00251     int i;
    00252     QBitmap b;
    00253     for(i=0; i < 6; ++i){
    00254         if(data[i]){
    00255             b = QBitmap(w, h, data[i], isXBitmaps);
    00256             b.setMask(b);
    00257             p->setPen(colors[i]);
    00258             p->drawPixmap(x, y, b);
    00259         }
    00260     }
    00261 }
    00262
    00263
    00264

This file is part of the documentation for kdefx Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:17:09 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003