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
|
package PreviewForm;
use strict;
use warnings;
use QtCore4;
use QtGui4;
use QtCore4::isa qw( Qt::Dialog );
use QtCore4::slots
updateTextEdit => [];
sub decodedString() { return decodedStr(); }
sub encodedData() {
return this->{encodedData};
}
sub decodedStr() {
return this->{decodedStr};
}
sub encodingComboBox() {
return this->{encodingComboBox};
}
sub encodingLabel() {
return this->{encodingLabel};
}
sub textEdit() {
return this->{textEdit};
}
sub buttonBox() {
return this->{buttonBox};
}
sub NEW
{
my ($class, $parent) = @_;
$class->SUPER::NEW($parent);
this->{encodingComboBox} = Qt::ComboBox();
this->{encodingLabel} = Qt::Label(this->tr('&Encoding:'));
encodingLabel->setBuddy(encodingComboBox);
this->{textEdit} = Qt::TextEdit();
textEdit->setLineWrapMode(Qt::TextEdit::NoWrap());
textEdit->setReadOnly(1);
this->{buttonBox} = Qt::DialogButtonBox(Qt::DialogButtonBox::Ok()
| Qt::DialogButtonBox::Cancel());
this->connect(encodingComboBox, SIGNAL 'activated(int)',
this, SLOT 'updateTextEdit()');
this->connect(buttonBox, SIGNAL 'accepted()', this, SLOT 'accept()');
this->connect(buttonBox, SIGNAL 'rejected()', this, SLOT 'reject()');
my $mainLayout = Qt::GridLayout();
$mainLayout->addWidget(encodingLabel, 0, 0);
$mainLayout->addWidget(encodingComboBox, 0, 1);
$mainLayout->addWidget(textEdit, 1, 0, 1, 2);
$mainLayout->addWidget(buttonBox, 2, 0, 1, 2);
this->setLayout($mainLayout);
setWindowTitle(this->tr('Choose Encoding'));
resize(400, 300);
}
sub setCodecList
{
my ($list) = @_;
encodingComboBox->clear();
foreach my $codec ( @{$list} ) {
encodingComboBox->addItem($codec->name()->constData(), Qt::Variant(Qt::Int($codec->mibEnum())));
}
}
sub setEncodedData
{
my ($data) = @_;
this->{encodedData} = $data;
updateTextEdit();
}
sub updateTextEdit
{
my $mib = encodingComboBox->itemData(
encodingComboBox->currentIndex())->toInt();
my $codec = Qt::TextCodec::codecForMib($mib);
my $in = Qt::TextStream(encodedData);
$in->setAutoDetectUnicode(0);
$in->setCodec($codec);
this->{decodedStr} = $in->readAll();
textEdit->setPlainText(decodedStr);
}
1;
|