File: MainWindow.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 (95 lines) | stat: -rw-r--r-- 2,288 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
package MainWindow;

use strict;
use warnings;
use QtCore4;
use QtGui4;
# [0]
use QtCore4::isa qw( Qt::MainWindow );
use QtCore4::slots
    about => [];
use TextEdit;

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

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

# [0]
sub NEW
{
    my ($class, $parent) = @_;
    $class->SUPER::NEW($parent);
    createMenu();

    this->{completingTextEdit} = TextEdit(this);
    this->{completer} = Qt::Completer(this);
    completer->setModel(modelFromFile(':/resources/wordlist.txt'));
    completer->setModelSorting(Qt::Completer::CaseInsensitivelySortedModel());
    completer->setCaseSensitivity(Qt::CaseInsensitive());
    completer->setWrapAround(0);
    completingTextEdit->setCompleter(completer);

    setCentralWidget(completingTextEdit);
    resize(500, 300);
    setWindowTitle(this->tr('Completer'));
}
# [0]

# [1]
sub createMenu
{
    my $exitAction = Qt::Action(this->tr('Exit'), this);
    my $aboutAct = Qt::Action(this->tr('About'), this);
    my $aboutQtAct = Qt::Action(this->tr('About Qt'), this);

    this->connect($exitAction, SIGNAL 'triggered()', qApp, SLOT 'quit()');
    this->connect($aboutAct, SIGNAL 'triggered()', this, SLOT 'about()');
    this->connect($aboutQtAct, SIGNAL 'triggered()', qApp, SLOT 'aboutQt()');

    my $fileMenu = menuBar()->addMenu(this->tr('File'));
    $fileMenu->addAction($exitAction);

    my $helpMenu = menuBar()->addMenu(this->tr('About'));
    $helpMenu->addAction($aboutAct);
    $helpMenu->addAction($aboutQtAct);
}
# [1]

# [2]
sub modelFromFile
{
    my ($fileName) = @_;
    my $file = Qt::File($fileName);
    if (!$file->open(Qt::File::ReadOnly())) {
        return Qt::StringListModel(completer);
    }

    Qt::Application::setOverrideCursor(Qt::Cursor(Qt::WaitCursor()));
    my @words;
    
    while (!$file->atEnd()) {
        my $line = $file->readLine();
        if ($line) {
            push @words, $line->constData;
        }
    }
    chomp(@words);

    Qt::Application::restoreOverrideCursor();
    return Qt::StringListModel(\@words, completer);
}
# [2]

# [3]
sub about
{
    Qt::MessageBox::about(this, this->tr('About'), this->tr('This example demonstrates the ' .
        'different features of the Qt::Completer class.'));
}
# [3]

1;