summaryrefslogtreecommitdiffstats
path: root/kdejava/koala/test/kblend/KBlendTest.java
blob: 1395f37997c4bbcfcc007c29653184e4d8ffd3ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import org.kde.qt.*;
import org.kde.koala.*;

//
// Simple little hack to show off blending effects.
//
// (C) KDE Artistic Cristian Tibirna <tibirna@kde.org>
//

/**
 *  Class to test KImageEffect blending effects.
 *
 *  This is a translation to java from kblendtest.cpp in the tests library
 *  of tdeui source.
 *
 * @see TDEApplication
 * @see KImageEffect
 *
 * @author Cristian Tibirna <tibirna@kde.org>, java translation Kenneth J. Pouncey, kjpou@hotmail.com
 * @version 0.1
 */

public class KBlendTest {

   public static void main(String[] args) {
      TDECmdLineArgs.init(args, "kblendtest", "KBlendTest", "It blends!", "0.1");
      TDEApplication app = new TDEApplication();
      KBlendWidget w = new KBlendWidget(null,"KBlendTest");
      w.setCaption(app.name());
      app.setMainWidget(w);
      w.show();
      app.exec();
      return;
   }


   public static class KBlendWidget extends TQWidget {

      TQImage image;
      TQColor bgnd;

      String testImage = "testimage.png";

      public KBlendWidget (TQWidget parent, String name) {

         // change the colors to see the effects.
//         bgnd = new TQColor(TQColor.qRgb(255, 255, 255));
         bgnd = Qt.blue();
//         bgnd = Qt.red();

         image = new TQImage(testImage);

         resize(image.width()*2+60, image.height()*3+80);
         setBackgroundColor(bgnd);
      }

      protected void paintEvent(TQPaintEvent pe ) {

         long it, ft;
         String say = "";

         image = new TQImage(testImage);

         TQPainter p = new TQPainter(this);

         p.setPen(Qt.black());

         // you see here use of anti_dir param (blend from down to up, here)
         it = System.currentTimeMillis();
         KImageEffect.blend(image, 0.2f, bgnd, KImageEffect.VerticalGradient,true);
         ft = System.currentTimeMillis();
         say = (ft - it) + " ms, Vertical";
         p.drawImage(20, 20, image);
         p.drawText(5 , 15, say);

         image = new TQImage(testImage);

         // here a negative initial intensity is used (1/2 of image is unaffected)
         it = System.currentTimeMillis();
         KImageEffect.blend(image, -0.5f, bgnd, KImageEffect.HorizontalGradient);
         ft = System.currentTimeMillis();
         say = (ft - it) + " ms, Horizontal";
         p.drawImage(40+image.width(), 20, image);
         p.drawText(15+image.width() , 15, say);

         image = new TQImage(testImage);

         it = System.currentTimeMillis();
         KImageEffect.blend(image, 0.0f, bgnd, KImageEffect.DiagonalGradient,true);
         ft = System.currentTimeMillis();
         say = (ft - it) + " ms, Diagonal";
         p.drawImage(20, 40+image.height(), image);
         p.drawText(5 , 35+image.height(), say);

         image = new TQImage(testImage);

         it = System.currentTimeMillis();
         KImageEffect.blend(image, 0.1f, bgnd, KImageEffect.CrossDiagonalGradient);
         ft = System.currentTimeMillis();
         say = (ft - it) + " ms, CrossDiagonal";
         p.drawImage(40+image.width(), 40+image.height(), image);
         p.drawText(25+image.width() , 35 + image.height(), say);

         image = new TQImage(testImage);

         it = System.currentTimeMillis();
         KImageEffect.blend(image, -0.6f, bgnd, KImageEffect.RectangleGradient);
         ft = System.currentTimeMillis();
         say = (ft - it) + " ms, Rectangle";
         p.drawImage(20, 60+2*image.height(), image);
         p.drawText(5 , 55+2*image.height(), say);

         image = new TQImage(testImage);

         it = System.currentTimeMillis();
         KImageEffect.blend(image, 0.2f, bgnd, KImageEffect.EllipticGradient);
         ft = System.currentTimeMillis();
         say = (ft - it) + " ms, Elliptic";
         p.drawImage(40+image.width(), 60+2*image.height(), image);
         p.drawText(25+image.width(), 55+2*image.height(), say);
         p.end();
      }
   }

   static {
      qtjava.initialize();
      kdejava.initialize();
   }

}