You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.4 KiB
109 lines
3.4 KiB
15 years ago
|
#include "kgradienttest.h"
|
||
|
#include <kapplication.h>
|
||
|
#include <kpixmapeffect.h>
|
||
15 years ago
|
#include <tqpainter.h>
|
||
|
#include <tqdatetime.h>
|
||
|
#include <tqstring.h>
|
||
15 years ago
|
|
||
|
int cols = 3, rows = 3; // how many
|
||
|
|
||
15 years ago
|
void KGradientWidget::paintEvent(TQPaintEvent */*ev*/)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQTime time;
|
||
15 years ago
|
int it, ft;
|
||
15 years ago
|
TQString say;
|
||
15 years ago
|
|
||
15 years ago
|
TQColor ca = Qt::black, cb = Qt::blue;
|
||
15 years ago
|
|
||
|
int x = 0, y = 0;
|
||
|
|
||
|
pix.resize(width()/cols, height()/rows);
|
||
15 years ago
|
TQPainter p(this);
|
||
15 years ago
|
p.setPen(Qt::white);
|
||
|
|
||
|
// draw once, so that the benchmarking be fair :-)
|
||
|
KPixmapEffect::gradient(pix,ca, cb, KPixmapEffect::VerticalGradient);
|
||
|
|
||
|
// vertical
|
||
|
time.start();
|
||
|
it = time.elapsed();
|
||
|
KPixmapEffect::gradient(pix,ca, cb, KPixmapEffect::VerticalGradient);
|
||
|
ft = time.elapsed();
|
||
|
say.setNum( ft - it); say += " ms, Vertical";
|
||
|
p.drawPixmap(x*width()/cols, y*height()/rows, pix);
|
||
|
p.drawText(5 + (x++)*width()/cols, 15+y*height()/rows, say); // augment x
|
||
|
|
||
|
// horizontal
|
||
|
it = time.elapsed();
|
||
|
KPixmapEffect::gradient(pix,ca, cb, KPixmapEffect::HorizontalGradient);
|
||
|
ft = time.elapsed() ;
|
||
|
say.setNum( ft - it); say += " ms, Horizontal";
|
||
|
p.drawPixmap(x*width()/cols, y*height()/rows, pix);
|
||
|
p.drawText(5+(x++)*width()/cols, 15+y*height()/rows, say);
|
||
|
|
||
|
// elliptic
|
||
|
it = time.elapsed();
|
||
|
KPixmapEffect::gradient(pix, ca, cb, KPixmapEffect::EllipticGradient);
|
||
|
ft = time.elapsed() ;
|
||
|
say.setNum( ft - it); say += " ms, Elliptic";
|
||
|
p.drawPixmap(x*width()/cols, y*height()/rows, pix);
|
||
|
p.drawText(5+(x++)*width()/cols, 15+y*height()/rows, say);
|
||
|
|
||
|
y++; // next row
|
||
|
x = 0; // reset the columns
|
||
|
|
||
|
// diagonal
|
||
|
it = time.elapsed();
|
||
|
KPixmapEffect::gradient(pix,ca, cb, KPixmapEffect::DiagonalGradient);
|
||
|
ft = time.elapsed();
|
||
|
say.setNum( ft - it); say += " ms, Diagonal";
|
||
|
p.drawPixmap(x*width()/cols, y*height()/rows, pix);
|
||
|
p.drawText(5+(x++)*width()/cols, 15+y*height()/rows, say);
|
||
|
|
||
|
// crossdiagonal
|
||
|
it = time.elapsed();
|
||
|
KPixmapEffect::gradient(pix,ca, cb, KPixmapEffect::CrossDiagonalGradient);
|
||
|
ft = time.elapsed();
|
||
|
say.setNum( ft - it); say += " ms, CrossDiagonal";
|
||
|
p.drawPixmap(width()/cols, y*height()/rows, pix);
|
||
|
p.drawText(5+(x++)*width()/cols, 15+y*height()/rows, say);
|
||
|
|
||
|
y++; // next row
|
||
|
x = 0; // reset the columns
|
||
|
|
||
|
// pyramidal
|
||
|
it = time.elapsed();
|
||
|
KPixmapEffect::gradient(pix, ca, cb, KPixmapEffect::PyramidGradient);
|
||
|
ft = time.elapsed();
|
||
|
say.setNum( ft - it); say += " ms, Pyramid";
|
||
|
p.drawPixmap(x*width()/cols, y*height()/rows, pix);
|
||
|
p.drawText(5+(x++)*width()/cols, 15+y*height()/rows, say);
|
||
|
|
||
|
// pattern
|
||
|
it = time.elapsed();
|
||
|
KPixmapEffect::gradient(pix, ca, cb, KPixmapEffect::RectangleGradient);
|
||
|
ft = time.elapsed();
|
||
|
say.setNum( ft - it); say += " ms, Rectangle";
|
||
|
p.drawPixmap(x*width()/cols, y*height()/rows, pix);
|
||
|
p.drawText(5+(x++)*width()/rows, 15+y*height()/rows, say);
|
||
|
|
||
|
// crosspipe
|
||
|
it = time.elapsed();
|
||
|
KPixmapEffect::gradient(pix, ca, cb, KPixmapEffect::PipeCrossGradient);
|
||
|
ft = time.elapsed();
|
||
|
say.setNum( ft - it); say += " ms, PipeCross";
|
||
|
p.drawPixmap(x*width()/cols, y*height()/rows, pix);
|
||
|
p.drawText(5+(x++)*width()/rows, 15+y*height()/rows, say);
|
||
|
}
|
||
|
|
||
|
int main(int argc, char **argv)
|
||
|
{
|
||
|
KApplication *app = new KApplication(argc, argv, "KGradientTest");
|
||
|
KGradientWidget w;
|
||
|
w.resize(250 * cols, 250 * rows);
|
||
|
app->setMainWidget(&w);
|
||
|
w.show();
|
||
|
return(app->exec());
|
||
|
}
|
||
|
|