summaryrefslogtreecommitdiffstats
path: root/korundum/rubylib/examples/uimodules/uimisc.rb
blob: f9d7016114de62b9d6c1812807f35011e2c14757 (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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
=begin
This is a ruby version of Jim Bublitz's pykde program, translated by Richard Dale
=end

require 'Korundum'

module UIMisc

class Page3 < Qt::Object
	slots 'ivChanged()', 'fvChanged()', 'dvChanged()'
	
    def initialize(parent)
		super
        page = parent.addPage()
        x = 10
        y = 15

        green  = Qt::Color.new(0, 255, 0)
        yellow = Qt::Color.new(255, 255, 0)
        red    = Qt::Color.new(255, 0, 0)

        ivLbl  = Qt::Label.new("KIntValidator", page)
        ivLbl.setGeometry(x, y, 100, 20)
        ivLbl.show()

        @iv = KDE::LineEdit.new(page)
        @iv.setGeometry(x, y + 20, 100, 20)
        @iv.show()
        connect(@iv, SIGNAL("textChanged(const QString&)"), SLOT('ivChanged()'))

        @ivVal = KDE::IntValidator.new(page)
        @ivVal.setRange(20, 50)

        ivRngLbl = Qt::Label.new("Range is 20 - 50", page)
        ivRngLbl.setGeometry(x, y + 45, 100, 20)
        ivRngLbl.show()

        ivAccLbl   = Qt::Label.new("Acceptable", page)
        ivAccLbl.setGeometry(x + 125, y + 45, 85, 20)
        ivAccLbl.show()
        ivInterLbl = Qt::Label.new("Intermediate", page)
        ivInterLbl.setGeometry(x + 125, y + 20, 85, 20)
        ivInterLbl.show()
        ivInvalLbl = Qt::Label.new("Invalid", page)
        ivInvalLbl.setGeometry(x + 125, y - 5, 85, 20)
        ivInvalLbl.show()
        @ivInvalLed = KDE::Led.new(red, KDE::Led::Off, KDE::Led::Sunken, KDE::Led::Circular,page)
        @ivInvalLed.setGeometry(x + 215, y - 5, 18, 18)
        @ivInvalLed.show()
        @ivInterLed = KDE::Led.new(yellow, KDE::Led::Off, KDE::Led::Sunken, KDE::Led::Circular,page)
        @ivInterLed.setGeometry(x + 215, y + 20, 18, 18)
        @ivInterLed.show()
        @ivAccLed = KDE::Led.new(green, KDE::Led::On, KDE::Led::Sunken, KDE::Led::Circular,page)
        @ivAccLed.setGeometry(x + 215, y + 45, 18, 18)
        @ivAccLed.show()

        y = y + 100

        fvLbl  = Qt::Label.new("KDoubleValidator", page)
        fvLbl.setGeometry(x, y, 100, 20)
        fvLbl.show()

        @fv = KDE::LineEdit.new(page)
        @fv.setGeometry(x, y + 20, 100, 20)
        @fv.show()
        connect(@fv, SIGNAL("textChanged(const QString&)"), SLOT('fvChanged()'))

        @fvVal = KDE::DoubleValidator.new(page)
        @fvVal.setRange(10.0, 40.0)

        fvRngLbl = Qt::Label.new("Range is 10.0 - 40.0", page)
        fvRngLbl.setGeometry(x, y + 45, 100, 20)
        fvRngLbl.show()

        fvAccLbl   = Qt::Label.new("Acceptable", page)
        fvAccLbl.setGeometry(x + 125, y + 45, 85, 20)
        fvAccLbl.show()
        fvInterLbl = Qt::Label.new("Intermediate", page)
        fvInterLbl.setGeometry(x + 125, y + 20, 95, 20)
        fvInterLbl.show()
        fvInvalLbl = Qt::Label.new("Invalid", page)
        fvInvalLbl.setGeometry(x + 125, y - 5, 85, 20)
        fvInvalLbl.show()
        @fvInvalLed = KDE::Led.new(red, KDE::Led::Off, KDE::Led::Sunken, KDE::Led::Circular,page)
        @fvInvalLed.setGeometry(x + 215, y - 5, 18, 18)
        @fvInvalLed.show()
        @fvInterLed = KDE::Led.new(yellow, KDE::Led::Off, KDE::Led::Sunken, KDE::Led::Circular,page)
        @fvInterLed.setGeometry(x + 215, y + 20, 18, 18)
        @fvInterLed.show()
        @fvAccLed = KDE::Led.new(green, KDE::Led::On, KDE::Led::Sunken, KDE::Led::Circular,page)
        @fvAccLed.setGeometry(x + 215, y + 45, 18, 18)
        @fvAccLed.show()

        y = y + 100

        dvLbl  = Qt::Label.new("KDateValidator", page)
        dvLbl.setGeometry(x, y, 100, 20)
        dvLbl.show()

        @dv = KDE::LineEdit.new(page)
        @dv.setGeometry(x, y + 20, 100, 20)
        @dv.show()
#        connect(dv, SIGNAL("textChanged(const QString&)"), SLOT('dvChanged()'))

        @dvVal = KDE::DateValidator.new(page)
#        dvVal.setRange(10.0, 40.0)

#        dvRngLbl = Qt::Label.new("Range is 10.0 - 40.0", page)
#        dvRngLbl.setGeometry(x, y + 45, 100, 20)
#        dvRngLbl.show()

        dvBtn = Qt::PushButton.new("Validate", page)
        dvBtn.setGeometry(x, y + 45, 60, 22)
        dvBtn.show()
        connect(dvBtn, SIGNAL("clicked()"), SLOT('dvChanged()'))

        dvNoteLbl = Qt::Label.new("Format is locale dependent\nShort date only\nTry DD-MM-YY", page)
        dvNoteLbl.setGeometry(x, y + 70, 150, 60)
        dvNoteLbl.show()

        dvAccLbl   = Qt::Label.new("Acceptable", page)
        dvAccLbl.setGeometry(x + 125, y + 45, 85, 20)
        dvAccLbl.show()
        dvInterLbl = Qt::Label.new("Intermediate", page)
        dvInterLbl.setGeometry(x + 125, y + 20, 85, 20)
        dvInterLbl.show()
        dvInvalLbl = Qt::Label.new("Invalid", page)
        dvInvalLbl.setGeometry(x + 125, y - 5, 85, 20)
        dvInvalLbl.show()
        @dvInvalLed = KDE::Led.new(red, KDE::Led::Off, KDE::Led::Sunken, KDE::Led::Circular,page)
        @dvInvalLed.setGeometry(x + 215, y - 5, 18, 18)
        @dvInvalLed.show()
        @dvInterLed = KDE::Led.new(yellow, KDE::Led::Off, KDE::Led::Sunken, KDE::Led::Circular,page)
        @dvInterLed.setGeometry(x + 215, y + 20, 18, 18)
        @dvInterLed.show()
        @dvAccLed = KDE::Led.new(green, KDE::Led::On, KDE::Led::Sunken, KDE::Led::Circular,page)
        @dvAccLed.setGeometry(x + 215, y + 45, 18, 18)
        @dvAccLed.show()
	end

    def ivChanged()
        @ivInvalLed.off()
        @ivInterLed.off()
        @ivAccLed.off()

		i = Qt::Integer.new(0)
        state = @ivVal.validate(@iv.text(), i)

        if state == Qt::Validator::Acceptable
            @ivAccLed.on()
        elsif state == Qt::Validator::Intermediate
            @ivInterLed.on()
        else
            @ivInvalLed.on()
		end
	end

    def fvChanged()
        @fvInvalLed.off()
        @fvInterLed.off()
        @fvAccLed.off()

		i = Qt::Integer.new(0)
        state = @fvVal.validate(@fv.text(), i)

        if state == Qt::Validator::Acceptable
            @fvAccLed.on()
        elsif state == Qt::Validator::Intermediate
            @fvInterLed.on()
        else
            @fvInvalLed.on()
		end
	end

    def dvChanged()
        @dvInvalLed.off()
        @dvInterLed.off()
        @dvAccLed.off()

		i = Qt::Integer.new(0)
        state = @dvVal.validate(@dv.text(), i)

        if state == Qt::Validator::Acceptable
            @dvAccLed.on()
        elsif state == Qt::Validator::Intermediate
            @dvInterLed.on()
        else
            @dvInvalLed.on()
		end
	end
end

class PageNotImpl
    def initialize(parent)
        page = parent.addPage()

        x = 10
        y = 10

        niLbl   = Qt::Label.new("Nothing is currently implemented for this widget", page)
        niLbl.setGeometry(x, y, 300, 20)
        niLbl.show()
	end
end

def UIMisc.miscKAlphaPainter(parent)
    parent.currentPageObj = PageNotImpl.new(parent)
end

def UIMisc.miscKCModule(parent)
    parent.currentPageObj = PageNotImpl.new(parent)
end

def UIMisc.miscKColor(parent)
    parent.currentPageObj = PageNotImpl.new(parent)
end

def UIMisc.miscKColorDrag(parent)
    parent.currentPageObj = PageNotImpl.new(parent)
end

def UIMisc.miscKCommand(parent)
    parent.currentPageObj = PageNotImpl.new(parent)
end

def UIMisc.miscKCommandHistory(parent)
    parent.currentPageObj = PageNotImpl.new(parent)
end

def UIMisc.miscKDockWindow(parent)
    parent.currentPageObj = PageNotImpl.new(parent)
end

def UIMisc.miscKDoubleValidator(parent)
    parent.currentPageObj = Page3.new(parent)
end

def UIMisc.miscKDateValidator(parent)
    parent.currentPageObj = Page3.new(parent)
end

def UIMisc.miscKIntValidator(parent)
    parent.currentPageObj = Page3.new(parent)
end

def UIMisc.miscKPixmapIO(parent)
    parent.currentPageObj = PageNotImpl.new(parent)
end

def UIMisc.miscKSharedPixmap(parent)
    parent.currentPageObj = PageNotImpl.new(parent)
end

def UIMisc.miscKSystemTray(parent)
    KDE::MessageBox.information(parent, "See the systray.rb example in the templates/ subdirectories")
end

def UIMisc.miscKThemeBase(parent)
    parent.currentPageObj = PageNotImpl.new(parent)
end

def UIMisc.miscQXEmbed(parent)
    parent.currentPageObj = PageNotImpl.new(parent)
end

if $0 == __FILE__
    puts
    puts "Please run uisampler.rb"
    puts
end

end