~ubuntu-branches/ubuntu/natty/kdebindings/natty

« back to all changes in this revision

Viewing changes to perl/qtgui/examples/tools/regexp/RegExpDialog.pm

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-12-01 11:14:38 UTC
  • mfrom: (1.1.41 upstream)
  • Revision ID: james.westby@ubuntu.com-20101201111438-1q61cvs8zw118t3m
Tags: 4:4.5.80-0ubuntu1
* New upstream release
* Remove build-dep on libqimageblitz-dev, causes smoke to segfault

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package RegExpDialog;
 
2
 
 
3
use strict;
 
4
use warnings;
 
5
use QtCore4;
 
6
use QtGui4;
 
7
use QtCore4::isa qw( Qt::Dialog );
 
8
use QtCore4::slots
 
9
    refresh => [];
 
10
 
 
11
use constant { MaxCaptures => 6 };
 
12
sub patternLabel() {
 
13
    return this->{patternLabel};
 
14
}
 
15
 
 
16
sub escapedPatternLabel() {
 
17
    return this->{escapedPatternLabel};
 
18
}
 
19
 
 
20
sub syntaxLabel() {
 
21
    return this->{syntaxLabel};
 
22
}
 
23
 
 
24
sub textLabel() {
 
25
    return this->{textLabel};
 
26
}
 
27
 
 
28
sub patternComboBox() {
 
29
    return this->{patternComboBox};
 
30
}
 
31
 
 
32
sub escapedPatternLineEdit() {
 
33
    return this->{escapedPatternLineEdit};
 
34
}
 
35
 
 
36
sub textComboBox() {
 
37
    return this->{textComboBox};
 
38
}
 
39
 
 
40
sub caseSensitiveCheckBox() {
 
41
    return this->{caseSensitiveCheckBox};
 
42
}
 
43
 
 
44
sub minimalCheckBox() {
 
45
    return this->{minimalCheckBox};
 
46
}
 
47
 
 
48
sub syntaxComboBox() {
 
49
    return this->{syntaxComboBox};
 
50
}
 
51
 
 
52
sub indexLabel() {
 
53
    return this->{indexLabel};
 
54
}
 
55
 
 
56
sub matchedLengthLabel() {
 
57
    return this->{matchedLengthLabel};
 
58
}
 
59
 
 
60
sub indexEdit() {
 
61
    return this->{indexEdit};
 
62
}
 
63
 
 
64
sub matchedLengthEdit() {
 
65
    return this->{matchedLengthEdit};
 
66
}
 
67
 
 
68
sub captureLabels() {
 
69
    return this->{captureLabels};
 
70
}
 
71
 
 
72
sub captureEdits() {
 
73
    return this->{captureEdits};
 
74
}
 
75
 
 
76
sub NEW
 
77
{
 
78
    my ($class, $parent) = @_;
 
79
    $class->SUPER::NEW($parent);
 
80
    this->{patternComboBox} = Qt::ComboBox();
 
81
    patternComboBox->setEditable(1);
 
82
    patternComboBox->setSizePolicy(Qt::SizePolicy::Expanding(),
 
83
                                   Qt::SizePolicy::Preferred());
 
84
 
 
85
    this->{patternLabel} = Qt::Label(this->tr('&Pattern:'));
 
86
    patternLabel->setBuddy(patternComboBox);
 
87
 
 
88
    this->{escapedPatternLineEdit} = Qt::LineEdit();
 
89
    escapedPatternLineEdit->setReadOnly(1);
 
90
    my $palette = escapedPatternLineEdit->palette();
 
91
    $palette->setBrush(Qt::Palette::Base(),
 
92
                     $palette->brush(Qt::Palette::Disabled(), Qt::Palette::Base()));
 
93
    escapedPatternLineEdit->setPalette($palette);
 
94
 
 
95
    this->{escapedPatternLabel} = Qt::Label(this->tr('&Escaped Pattern:'));
 
96
    escapedPatternLabel->setBuddy(escapedPatternLineEdit);
 
97
 
 
98
    this->{syntaxComboBox} = Qt::ComboBox();
 
99
    syntaxComboBox->addItem(this->tr('Regular expression v1'), Qt::Variant(Qt::Int(${Qt::RegExp::RegExp()})));
 
100
    syntaxComboBox->addItem(this->tr('Regular expression v2'), Qt::Variant(Qt::Int(${Qt::RegExp::RegExp2()})));
 
101
    syntaxComboBox->addItem(this->tr('Wildcard'), Qt::Variant(Qt::Int(${Qt::RegExp::Wildcard()})));
 
102
    syntaxComboBox->addItem(this->tr('Fixed string'), Qt::Variant(Qt::Int(${Qt::RegExp::FixedString()})));
 
103
    syntaxComboBox->addItem(this->tr('W3C Xml Schema 1.1'), Qt::Variant(Qt::Int(${Qt::RegExp::W3CXmlSchema11()})));
 
104
 
 
105
    this->{syntaxLabel} = Qt::Label(this->tr('&Pattern Syntax:'));
 
106
    syntaxLabel->setBuddy(syntaxComboBox);
 
107
 
 
108
    this->{textComboBox} = Qt::ComboBox();
 
109
    textComboBox->setEditable(1);
 
110
    textComboBox->setSizePolicy(Qt::SizePolicy::Expanding(), Qt::SizePolicy::Preferred());
 
111
 
 
112
    this->{textLabel} = Qt::Label(this->tr('&Text:'));
 
113
    textLabel->setBuddy(textComboBox);
 
114
 
 
115
    this->{caseSensitiveCheckBox} = Qt::CheckBox(this->tr('Case &Sensitive'));
 
116
    caseSensitiveCheckBox->setChecked(1);
 
117
    this->{minimalCheckBox} = Qt::CheckBox(this->tr('&Minimal'));
 
118
 
 
119
    this->{indexLabel} = Qt::Label(this->tr('Index of Match:'));
 
120
    this->{indexEdit} = Qt::LineEdit();
 
121
    indexEdit->setReadOnly(1);
 
122
 
 
123
    this->{matchedLengthLabel} = Qt::Label(this->tr('Matched Length:'));
 
124
    this->{matchedLengthEdit} = Qt::LineEdit();
 
125
    matchedLengthEdit->setReadOnly(1);
 
126
 
 
127
    this->{captureLabels} = [];
 
128
    this->{captureEdits} = [];
 
129
    for (my $i = 0; $i < MaxCaptures; ++$i) {
 
130
        push @{captureLabels()}, Qt::Label(sprintf this->tr('Capture %d:'), $i);
 
131
        push @{captureEdits()}, Qt::LineEdit();
 
132
        captureEdits()->[$i]->setReadOnly(1);
 
133
    }
 
134
    captureLabels->[0]->setText(this->tr('Match:'));
 
135
 
 
136
    my $checkBoxLayout = Qt::HBoxLayout();
 
137
    $checkBoxLayout->addWidget(caseSensitiveCheckBox);
 
138
    $checkBoxLayout->addWidget(minimalCheckBox);
 
139
    $checkBoxLayout->addStretch(1);
 
140
 
 
141
    my $mainLayout = Qt::GridLayout();
 
142
    $mainLayout->addWidget(patternLabel, 0, 0);
 
143
    $mainLayout->addWidget(patternComboBox, 0, 1);
 
144
    $mainLayout->addWidget(escapedPatternLabel, 1, 0);
 
145
    $mainLayout->addWidget(escapedPatternLineEdit, 1, 1);
 
146
    $mainLayout->addWidget(syntaxLabel, 2, 0);
 
147
    $mainLayout->addWidget(syntaxComboBox, 2, 1);
 
148
    $mainLayout->addLayout($checkBoxLayout, 3, 0, 1, 2);
 
149
    $mainLayout->addWidget(textLabel, 4, 0);
 
150
    $mainLayout->addWidget(textComboBox, 4, 1);
 
151
    $mainLayout->addWidget(indexLabel, 5, 0);
 
152
    $mainLayout->addWidget(indexEdit, 5, 1);
 
153
    $mainLayout->addWidget(matchedLengthLabel, 6, 0);
 
154
    $mainLayout->addWidget(matchedLengthEdit, 6, 1);
 
155
 
 
156
    for (my $j = 0; $j < MaxCaptures; ++$j) {
 
157
        $mainLayout->addWidget(captureLabels()->[$j], 7 + $j, 0);
 
158
        $mainLayout->addWidget(captureEdits()->[$j], 7 + $j, 1);
 
159
    }
 
160
    this->setLayout($mainLayout);
 
161
 
 
162
    this->connect(patternComboBox, SIGNAL 'editTextChanged(QString)',
 
163
            this, SLOT 'refresh()');
 
164
    this->connect(textComboBox, SIGNAL 'editTextChanged(QString)',
 
165
            this, SLOT 'refresh()');
 
166
    this->connect(caseSensitiveCheckBox, SIGNAL 'toggled(bool)',
 
167
            this, SLOT 'refresh()');
 
168
    this->connect(minimalCheckBox, SIGNAL 'toggled(bool)', this, SLOT 'refresh()');
 
169
    this->connect(syntaxComboBox, SIGNAL 'currentIndexChanged(int)',
 
170
            this, SLOT 'refresh()');
 
171
 
 
172
    patternComboBox->addItem(this->tr('[A-Za-z_]+([A-Za-z_0-9]*)'));
 
173
    textComboBox->addItem(this->tr('(10 + delta4) * 32'));
 
174
 
 
175
    setWindowTitle(this->tr('RegExp'));
 
176
    setFixedHeight(sizeHint()->height());
 
177
    refresh();
 
178
}
 
179
 
 
180
sub refresh
 
181
{
 
182
    setUpdatesEnabled(0);
 
183
 
 
184
    my $pattern = patternComboBox->currentText();
 
185
    my $text = textComboBox->currentText();
 
186
 
 
187
    my $escaped = $pattern;
 
188
    $escaped =~ s/\\/\\\\/g;
 
189
    $escaped =~ s/'/\\'/g;
 
190
    $escaped = "'$escaped'";
 
191
    escapedPatternLineEdit->setText($escaped);
 
192
 
 
193
    my $rx = Qt::RegExp($pattern);
 
194
    my $cs = Qt::CaseInsensitive();
 
195
    if (caseSensitiveCheckBox->isChecked()) {
 
196
        $cs = Qt::CaseSensitive();
 
197
    }
 
198
    $rx->setCaseSensitivity($cs);
 
199
    $rx->setMinimal(minimalCheckBox->isChecked());
 
200
    my $syntax = syntaxComboBox->itemData(syntaxComboBox->currentIndex())->toInt();
 
201
    $rx->setPatternSyntax($syntax);
 
202
 
 
203
    my $palette = patternComboBox->palette();
 
204
    if ($rx->isValid()) {
 
205
        $palette->setColor(Qt::Palette::Text(),
 
206
                         textComboBox->palette()->color(Qt::Palette::Text()));
 
207
    } else {
 
208
        $palette->setColor(Qt::Palette::Text(), Qt::Color(Qt::red()));
 
209
    }
 
210
    patternComboBox->setPalette($palette);
 
211
 
 
212
    indexEdit->setText($rx->indexIn($text));
 
213
    matchedLengthEdit->setText($rx->matchedLength());
 
214
    for (my $i = 0; $i < MaxCaptures; ++$i) {
 
215
        captureLabels->[$i]->setEnabled($i <= $rx->captureCount());
 
216
        captureEdits->[$i]->setEnabled($i <= $rx->captureCount());
 
217
        captureEdits->[$i]->setText($rx->cap($i));
 
218
    }
 
219
 
 
220
    setUpdatesEnabled(1);
 
221
}
 
222
 
 
223
1;