File: RegExpDialog.pm

package info (click to toggle)
qt4-perl 4.8.4-1.2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,636 kB
  • ctags: 8,100
  • sloc: perl: 42,963; cpp: 28,039; makefile: 160; xml: 98; sh: 4
file content (223 lines) | stat: -rw-r--r-- 7,022 bytes parent folder | download | duplicates (3)
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
package RegExpDialog;

use strict;
use warnings;
use QtCore4;
use QtGui4;
use QtCore4::isa qw( Qt::Dialog );
use QtCore4::slots
    refresh => [];

use constant { MaxCaptures => 6 };
sub patternLabel() {
    return this->{patternLabel};
}

sub escapedPatternLabel() {
    return this->{escapedPatternLabel};
}

sub syntaxLabel() {
    return this->{syntaxLabel};
}

sub textLabel() {
    return this->{textLabel};
}

sub patternComboBox() {
    return this->{patternComboBox};
}

sub escapedPatternLineEdit() {
    return this->{escapedPatternLineEdit};
}

sub textComboBox() {
    return this->{textComboBox};
}

sub caseSensitiveCheckBox() {
    return this->{caseSensitiveCheckBox};
}

sub minimalCheckBox() {
    return this->{minimalCheckBox};
}

sub syntaxComboBox() {
    return this->{syntaxComboBox};
}

sub indexLabel() {
    return this->{indexLabel};
}

sub matchedLengthLabel() {
    return this->{matchedLengthLabel};
}

sub indexEdit() {
    return this->{indexEdit};
}

sub matchedLengthEdit() {
    return this->{matchedLengthEdit};
}

sub captureLabels() {
    return this->{captureLabels};
}

sub captureEdits() {
    return this->{captureEdits};
}

sub NEW
{
    my ($class, $parent) = @_;
    $class->SUPER::NEW($parent);
    this->{patternComboBox} = Qt::ComboBox();
    patternComboBox->setEditable(1);
    patternComboBox->setSizePolicy(Qt::SizePolicy::Expanding(),
                                   Qt::SizePolicy::Preferred());

    this->{patternLabel} = Qt::Label(this->tr('&Pattern:'));
    patternLabel->setBuddy(patternComboBox);

    this->{escapedPatternLineEdit} = Qt::LineEdit();
    escapedPatternLineEdit->setReadOnly(1);
    my $palette = escapedPatternLineEdit->palette();
    $palette->setBrush(Qt::Palette::Base(),
                     $palette->brush(Qt::Palette::Disabled(), Qt::Palette::Base()));
    escapedPatternLineEdit->setPalette($palette);

    this->{escapedPatternLabel} = Qt::Label(this->tr('&Escaped Pattern:'));
    escapedPatternLabel->setBuddy(escapedPatternLineEdit);

    this->{syntaxComboBox} = Qt::ComboBox();
    syntaxComboBox->addItem(this->tr('Regular expression v1'), Qt::Variant(Qt::Int(${Qt::RegExp::RegExp()})));
    syntaxComboBox->addItem(this->tr('Regular expression v2'), Qt::Variant(Qt::Int(${Qt::RegExp::RegExp2()})));
    syntaxComboBox->addItem(this->tr('Wildcard'), Qt::Variant(Qt::Int(${Qt::RegExp::Wildcard()})));
    syntaxComboBox->addItem(this->tr('Fixed string'), Qt::Variant(Qt::Int(${Qt::RegExp::FixedString()})));
    syntaxComboBox->addItem(this->tr('W3C Xml Schema 1.1'), Qt::Variant(Qt::Int(${Qt::RegExp::W3CXmlSchema11()})));

    this->{syntaxLabel} = Qt::Label(this->tr('&Pattern Syntax:'));
    syntaxLabel->setBuddy(syntaxComboBox);

    this->{textComboBox} = Qt::ComboBox();
    textComboBox->setEditable(1);
    textComboBox->setSizePolicy(Qt::SizePolicy::Expanding(), Qt::SizePolicy::Preferred());

    this->{textLabel} = Qt::Label(this->tr('&Text:'));
    textLabel->setBuddy(textComboBox);

    this->{caseSensitiveCheckBox} = Qt::CheckBox(this->tr('Case &Sensitive'));
    caseSensitiveCheckBox->setChecked(1);
    this->{minimalCheckBox} = Qt::CheckBox(this->tr('&Minimal'));

    this->{indexLabel} = Qt::Label(this->tr('Index of Match:'));
    this->{indexEdit} = Qt::LineEdit();
    indexEdit->setReadOnly(1);

    this->{matchedLengthLabel} = Qt::Label(this->tr('Matched Length:'));
    this->{matchedLengthEdit} = Qt::LineEdit();
    matchedLengthEdit->setReadOnly(1);

    this->{captureLabels} = [];
    this->{captureEdits} = [];
    for (my $i = 0; $i < MaxCaptures; ++$i) {
        push @{captureLabels()}, Qt::Label(sprintf this->tr('Capture %d:'), $i);
        push @{captureEdits()}, Qt::LineEdit();
        captureEdits()->[$i]->setReadOnly(1);
    }
    captureLabels->[0]->setText(this->tr('Match:'));

    my $checkBoxLayout = Qt::HBoxLayout();
    $checkBoxLayout->addWidget(caseSensitiveCheckBox);
    $checkBoxLayout->addWidget(minimalCheckBox);
    $checkBoxLayout->addStretch(1);

    my $mainLayout = Qt::GridLayout();
    $mainLayout->addWidget(patternLabel, 0, 0);
    $mainLayout->addWidget(patternComboBox, 0, 1);
    $mainLayout->addWidget(escapedPatternLabel, 1, 0);
    $mainLayout->addWidget(escapedPatternLineEdit, 1, 1);
    $mainLayout->addWidget(syntaxLabel, 2, 0);
    $mainLayout->addWidget(syntaxComboBox, 2, 1);
    $mainLayout->addLayout($checkBoxLayout, 3, 0, 1, 2);
    $mainLayout->addWidget(textLabel, 4, 0);
    $mainLayout->addWidget(textComboBox, 4, 1);
    $mainLayout->addWidget(indexLabel, 5, 0);
    $mainLayout->addWidget(indexEdit, 5, 1);
    $mainLayout->addWidget(matchedLengthLabel, 6, 0);
    $mainLayout->addWidget(matchedLengthEdit, 6, 1);

    for (my $j = 0; $j < MaxCaptures; ++$j) {
        $mainLayout->addWidget(captureLabels()->[$j], 7 + $j, 0);
        $mainLayout->addWidget(captureEdits()->[$j], 7 + $j, 1);
    }
    this->setLayout($mainLayout);

    this->connect(patternComboBox, SIGNAL 'editTextChanged(QString)',
            this, SLOT 'refresh()');
    this->connect(textComboBox, SIGNAL 'editTextChanged(QString)',
            this, SLOT 'refresh()');
    this->connect(caseSensitiveCheckBox, SIGNAL 'toggled(bool)',
            this, SLOT 'refresh()');
    this->connect(minimalCheckBox, SIGNAL 'toggled(bool)', this, SLOT 'refresh()');
    this->connect(syntaxComboBox, SIGNAL 'currentIndexChanged(int)',
            this, SLOT 'refresh()');

    patternComboBox->addItem(this->tr('[A-Za-z_]+([A-Za-z_0-9]*)'));
    textComboBox->addItem(this->tr('(10 + delta4) * 32'));

    setWindowTitle(this->tr('RegExp'));
    setFixedHeight(sizeHint()->height());
    refresh();
}

sub refresh
{
    setUpdatesEnabled(0);

    my $pattern = patternComboBox->currentText();
    my $text = textComboBox->currentText();

    my $escaped = $pattern;
    $escaped =~ s/\\/\\\\/g;
    $escaped =~ s/'/\\'/g;
    $escaped = "'$escaped'";
    escapedPatternLineEdit->setText($escaped);

    my $rx = Qt::RegExp($pattern);
    my $cs = Qt::CaseInsensitive();
    if (caseSensitiveCheckBox->isChecked()) {
        $cs = Qt::CaseSensitive();
    }
    $rx->setCaseSensitivity($cs);
    $rx->setMinimal(minimalCheckBox->isChecked());
    my $syntax = syntaxComboBox->itemData(syntaxComboBox->currentIndex())->toInt();
    $rx->setPatternSyntax($syntax);

    my $palette = patternComboBox->palette();
    if ($rx->isValid()) {
        $palette->setColor(Qt::Palette::Text(),
                         textComboBox->palette()->color(Qt::Palette::Text()));
    } else {
        $palette->setColor(Qt::Palette::Text(), Qt::Color(Qt::red()));
    }
    patternComboBox->setPalette($palette);

    indexEdit->setText($rx->indexIn($text));
    matchedLengthEdit->setText($rx->matchedLength());
    for (my $i = 0; $i < MaxCaptures; ++$i) {
        captureLabels->[$i]->setEnabled($i <= $rx->captureCount());
        captureEdits->[$i]->setEnabled($i <= $rx->captureCount());
        captureEdits->[$i]->setText($rx->cap($i));
    }

    setUpdatesEnabled(1);
}

1;