summaryrefslogtreecommitdiffstats
path: root/tdeui/tests/knuminputtest.cpp
blob: 9a333dfda474f4fd5a150387cb38ef3761d167bf (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Tests the KNumInput Widget class
*
* Copyright (c) 1999 by Dirk A. Mueller <dmuell@gmx.net>
*
* License: GPL, version 2
* Version: $Id:
*
*/

#include <tqlayout.h>
#include <tqvgroupbox.h>

#include <tdeapplication.h>
#include <knuminput.h>

#include "knuminputtest.h"

TDEApplication *a;

#include <kdebug.h>
void TopLevel::slotPrint( int n ) {
  kdDebug() << "slotPrint( " << n << " )" << endl;
}
void TopLevel::slotPrint( double n ) {
  kdDebug() << "slotPrint( " << n << " )" << endl;
}

#define conn(x,y) connect( x, TQT_SIGNAL(valueChanged(y)), TQT_SLOT(slotPrint(y)))
TopLevel::TopLevel(TQWidget *parent, const char *name)
    : TQWidget(parent, name)
{
    setCaption("KNumInput test application");

    TQBoxLayout* l = new TQHBoxLayout(this, 10);

    TQGroupBox* b1 = new TQVGroupBox("KIntNumInput", this);

    i1 = new KIntNumInput(42, b1, 10, "perc_no_slider");
    i1->setLabel("percent of usage (no slider)");
    i1->setRange(0, 100, 5, false);
    conn(i1,int);

    i2 = new KIntNumInput(i1, 42, b1);
    i2->setLabel("percentage of usage (with slider)");
    i2->setRange(0, 100, 5);
    i2->setSuffix(" %");
    conn(i2,int);

    i3 = new KIntNumInput(i2, 0xAF, b1, 16);
    i3->setLabel("Hex byte (no slider)");
    i3->setRange(0, 255, 1, false);
    i3->setSuffix(" (hex)");
    conn(i3,int);

    i4 = new KIntNumInput(i3, 0xfe, b1, 16);
    i4->setLabel("Hex byte (with slider)");
    i4->setRange(0, 255, 1);
    conn(i4,int);

    i5 = new KIntNumInput(i4, 10, b1, 10);
    i5->setLabel("Width (keeps aspect ratio):");
    i5->setRange(0, 200, 1, false);
    i5->setReferencePoint( 5 );

    i6 = new KIntNumInput(i5, 20, b1, 10);
    i6->setLabel("Height (should be 2xWidth):");
    i6->setRange(0, 200, 1, false);
    i6->setReferencePoint( 10 );
    connect( i5, TQT_SIGNAL(relativeValueChanged(double)),
	     i6, TQT_SLOT(setRelativeValue(double)) );
    connect( i6, TQT_SIGNAL(relativeValueChanged(double)),
	     i5, TQT_SLOT(setRelativeValue(double)) );

    i7 = new KIntNumInput(i6, 0, b1, 10);
    i7->setLabel("math test:", AlignVCenter|AlignLeft );
    i7->setRange( INT_MIN, INT_MAX, 1 );
    conn(i7,int);

    l->addWidget(b1);

    TQGroupBox* b2 = new TQVGroupBox("KDoubleNumInput", this);

    d1 = new KDoubleNumInput(4.0, b2, "perc_double_no_slider");
    d1->setLabel("percent of usage (no slider)", AlignTop | AlignRight);
    d1->setRange(0.0, 4000.0, 0.01, false);
    //d1->setValue(1.00000000000000000001);
    conn(d1,double);

    d2 = new KDoubleNumInput(d1, 0.422, b2, "perc_double_with_slider");
    d2->setLabel("percentage of usage (with slider)", AlignBottom | AlignLeft);
    d2->setRange(0, 1.0, 0.005);
    d2->setSuffix("%");
    conn(d2,double);

    d3 = new KDoubleNumInput(d2, 16.20, b2);
    d3->setLabel("cash: ", AlignVCenter | AlignHCenter);
    d3->setRange(0.10, 100, 0.1);
    d3->setPrefix("p");
    d3->setSuffix("$");
    conn(d3,double);

    d4 = new KDoubleNumInput(d3, INT_MAX/10000.0, b2);
    d4->setPrecision(3);
    d4->setRange(double(INT_MIN+1)/1000.0, double(INT_MAX)/1000.0, 1);
    d4->setLabel("math test: ", AlignVCenter | AlignLeft);
//    d4->setFormat("%g");
    conn(d4,double);

    d5 = new KDoubleNumInput(d4, double(INT_MIN+1)/1e9, double(INT_MAX-1)/1e9,
			     0.1, 0.001, 9, b2, "d5");
    d5->setLabel("math test 2: ", AlignVCenter|AlignLeft);
    conn(d5,double);

    d6 = new KDoubleNumInput(d5, -10, 10, 0, 0.001, 3, b2, "d6");
    d6->setLabel("aspect ratio test with a negative ratio:");
    d6->setReferencePoint( 1 );

    d7 = new KDoubleNumInput(d6, -30, 30, 0, 0.001, 3, b2, "d7");
    d7->setReferencePoint( -3 );

    connect( d6, TQT_SIGNAL(relativeValueChanged(double)),
	     d7, TQT_SLOT(setRelativeValue(double)) );
    connect( d7, TQT_SIGNAL(relativeValueChanged(double)),
	     d6, TQT_SLOT(setRelativeValue(double)) );

    l->addWidget(b2);
}




int main( int argc, char ** argv )
{
    a = new TDEApplication ( argc, argv, "KNuminputTest" );

    TopLevel *toplevel = new TopLevel(0, "knuminputtest");

    toplevel->show();
    a->setMainWidget(toplevel);
    a->exec();
}

#include "knuminputtest.moc"