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 (155 lines) | stat: -rw-r--r-- 3,403 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
package MainWindow;

use strict;
use warnings;
use QtCore4;
use QtGui4;
use QtCore4::isa qw( Qt::MainWindow );
use QtCore4::slots
    about => [],
    showDocumentation => [],
    open => [];

use FindFileDialog;
use Assistant;
use TextEdit;

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

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

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

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

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

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

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

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

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

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


# ![0]
sub NEW
{
    my ($class) = @_;
    $class->SUPER::NEW();
    this->{assistant} = Assistant->new();
# ![0]
    this->{textViewer} = TextEdit();
    textViewer->setContents(Qt::LibraryInfo::location(Qt::LibraryInfo::ExamplesPath())
            . '/help/simpletextviewer/documentation/intro.html');
    setCentralWidget(textViewer);

    createActions();
    createMenus();

    setWindowTitle(this->tr('Simple Text Viewer'));
    resize(750, 400);
# ![1]
}
# [1]

# [2]
sub closeEvent
{
    this->{assistant} = undef;
}
# [2]

sub about
{
    Qt::MessageBox::about(this, this->tr('About Simple Text Viewer'),
                       this->tr("This example demonstrates how to use\n" .
                          "Qt Assistant as help system for your\n" .
                          'own application.'));
}

# [3]
sub showDocumentation
{
    assistant->showDocumentation('index.html');    
}
# [3]

sub open
{
    my $dialog = FindFileDialog(textViewer, assistant);
    $dialog->exec();
}

# [4]
sub createActions
{
    this->{assistantAct} = Qt::Action(this->tr('Help Contents'), this);
    assistantAct->setShortcut(Qt::KeySequence(Qt::KeySequence::HelpContents()));
    this->connect(assistantAct, SIGNAL 'triggered()', this, SLOT 'showDocumentation()');
# [4]

    this->{openAct} = Qt::Action(this->tr('&Open...'), this);
    openAct->setShortcut(Qt::KeySequence(Qt::KeySequence::Open()));
    this->connect(openAct, SIGNAL 'triggered()', this, SLOT 'open()');

    this->{clearAct} = Qt::Action(this->tr('&Clear'), this);
    clearAct->setShortcut(Qt::KeySequence(this->tr('Ctrl+C')));
    this->connect(clearAct, SIGNAL 'triggered()', textViewer, SLOT 'clear()');

    this->{exitAct} = Qt::Action(this->tr('E&xit'), this);
    exitAct->setShortcuts([Qt::KeySequence(Qt::KeySequence::Quit())]);
    this->connect(exitAct, SIGNAL 'triggered()', this, SLOT 'close()');

    this->{aboutAct} = Qt::Action(this->tr('&About'), this);
    this->connect(aboutAct, SIGNAL 'triggered()', this, SLOT 'about()');

    this->{aboutQtAct} = Qt::Action(this->tr('About &Qt'), this);
    this->connect(aboutQtAct, SIGNAL 'triggered()', qApp, SLOT 'aboutQt()');
# [5]
}
# [5]

sub createMenus
{
    this->{fileMenu} = Qt::Menu(this->tr('&File'), this);
    fileMenu->addAction(openAct);
    fileMenu->addAction(clearAct);
    fileMenu->addSeparator();
    fileMenu->addAction(exitAct);

    this->{helpMenu} = Qt::Menu(this->tr('&Help'), this);
    helpMenu->addAction(assistantAct);
    helpMenu->addSeparator();
    helpMenu->addAction(aboutAct);
    helpMenu->addAction(aboutQtAct);


    menuBar()->addMenu(fileMenu);
    menuBar()->addMenu(helpMenu);
}

1;