0
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
| | require 'qte'
require 'qpe'
include Qte
include Qpe
$KCODE = "UTF8"
class MainWindow < QMainWindow
def initialize
super
self.setCaption(tr("QLineEdit さんぷる"))
@hbox = []
@lab = []
@edt = []
@btn = []
@vbox = QVBox.new(self)
self.setCentralWidget(@vbox)
for i in 1..7
@hbox[i] = QHBox.new(@vbox)
@lab[i] = QLabel.new(i.to_s+": ",@hbox[i])
@edt[i] = QLineEdit.new(@hbox[i])
@btn[i] = QPushButton.new(tr("検証"),@hbox[i])
end
@btn[1].setText(tr("ラベルに代入(8文字まで)"))
@edt[1].setText(tr("何か入力。"))
@edt[1].setMaxLength(8)
connect(@btn[1], QSIGNAL("clicked()"), self, 'edtload')
connect(@edt[1], QSIGNAL("returnPressed()"), self, 'edtload')
@btn[2].setText(tr("パスワード入力とラベル代入"))
@edt[2].setText(tr("password"))
@edt[2].setEchoMode(QLineEdit::Password) connect(@btn[1], QSIGNAL("clicked()"), self, 'edtload')
connect(@btn[2], QSIGNAL("clicked()"), self, 'edtload')
@btn[3].setText(tr("無効"))
@btn[3].setEnabled(false)
@edt[3].setText(tr("読み取り専用です。"))
@edt[3].setEnabled(false)
@btn[4].setText(tr("無効"))
@btn[4].setEnabled(false)
@edt[4].setText(tr("ラベル自動変更"))
@edt[4].setMaxLength(16)
connect(@edt[4], QSIGNAL("textChanged(const QString &)"), self, 'edtload_by_changed')
@btn[5].setText(tr("入力内容クリア"))
@edt[5].setText(tr("入力済みのテキスト"))
connect(@btn[5], QSIGNAL("clicked()"), self, 'edtclear')
@btn[6].hide @edt[6].setText(tr("入力済みのテキスト"))
@btn_all = QPushButton.new(tr("全選択"),@hbox[6])
connect(@btn_all, QSIGNAL("clicked()"), self, 'btn_all_func')
@btn_none = QPushButton.new(tr("選択解除"),@hbox[6])
connect(@btn_none, QSIGNAL("clicked()"), self, 'btn_none_func')
@btn_cut = QPushButton.new(tr("切取"),@hbox[6])
connect(@btn_cut, QSIGNAL("clicked()"), self, 'btn_cut_func')
@btn_copy = QPushButton.new(tr("複写"),@hbox[6])
connect(@btn_copy, QSIGNAL("clicked()"), self, 'btn_copy_func')
@btn_paste = QPushButton.new(tr("貼付"),@hbox[6])
connect(@btn_paste, QSIGNAL("clicked()"), self, 'btn_paste_func')
@edt[7].hide @btn[7].setText(tr("子ダイアログで入力しラベル代入"))
connect(@btn[7], QSIGNAL("clicked()"), self, 'btn_subwindow_func')
end
def edtload
@lab[1].setText(@edt[1].text)
@lab[2].setText(@edt[2].text)
end
def edtload_by_changed(opt)
@lab[4].setText(tr(opt))
end
def edtclear
@edt[5].clear
end
def btn_all_func
@edt[6].selectAll
end
def btn_none_func
@edt[6].deselect
end
def btn_cut_func
@edt[6].cut
end
def btn_copy_func
@edt[6].copy
end
def btn_paste_func
@edt[6].paste
end
def btn_subwindow_func
subwin = SubWindow.new(self)
subwin.setText(@lab[7].text.local8Bit.to_str)
if subwin.exec == QMessageBox::Ok then
puts subwin.class
@lab[7].setText(subwin.text)
end
end
end
class SubWindow < QDialog
def initialize(parent=0)
super(parent, "", true) mywidth = 440 myheight = 28
self.setCaption(tr("子ダイアログで文字入力"))
self.resize(mywidth, myheight)
@edt = QLineEdit.new(self)
@edt.resize(mywidth, myheight)
end
def setText(opt="")
@edt.setText(tr(opt))
@edt.selectAll
end
def text
return @edt.text
end
end
class MyApplication < QPEApplication
def initialize
super([$0]+ARGV)
self.setDefaultCodec(QTextCodec::codecForName("utf-8"))
end
end
app = MyApplication.new
win = MainWindow.new
app.showMainWidget(win)
app.exec
|