File: Dialog.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 (174 lines) | stat: -rw-r--r-- 4,038 bytes parent folder | download | duplicates (4)
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
package Dialog;

use strict;
use warnings;
use QtCore4;
use QtGui4;
# [0]
use QtCore4::isa qw( Qt::Dialog );
use constant {
    NumGridRows => 3,
    NumButtons => 4
};

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

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

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

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

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

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

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

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

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

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

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

sub exitAction() {
    return this->{exitAction};
}
# [0]

# [0]
sub NEW
{
    my ($class) = @_;
    $class->SUPER::NEW();
    this->createMenu();
    this->createHorizontalGroupBox();
    this->createGridGroupBox();
    this->createFormGroupBox();
# [0]

# [1]
    this->{bigEditor} = Qt::TextEdit();
    this->bigEditor->setPlainText(this->tr('This widget takes up all the remaining space ' .
                               'in the top-level layout.'));

    this->{buttonBox} = Qt::DialogButtonBox(Qt::DialogButtonBox::Ok()
                                     | Qt::DialogButtonBox::Cancel());

    this->connect(this->buttonBox, SIGNAL 'accepted()', this, SLOT 'accept()');
    this->connect(this->buttonBox, SIGNAL 'rejected()', this, SLOT 'reject()');
# [1]

# [2]
    my $mainLayout = Qt::VBoxLayout();
# [2] //! [3]
    $mainLayout->setMenuBar(this->menuBar);
# [3] //! [4]
    $mainLayout->addWidget(this->horizontalGroupBox);
    $mainLayout->addWidget(this->gridGroupBox);
    $mainLayout->addWidget(this->formGroupBox);
    $mainLayout->addWidget(this->bigEditor);
    $mainLayout->addWidget(this->buttonBox);
# [4] //! [5]
    this->setLayout($mainLayout);

    this->setWindowTitle(this->tr('Basic Layouts'));
}
# [5]

# [6]
sub createMenu
{
    this->{menuBar} = Qt::MenuBar();

    this->{fileMenu} = Qt::Menu(this->tr('&File'), this);
    this->{exitAction} = this->fileMenu->addAction(this->tr('E&xit'));
    this->menuBar->addMenu(this->fileMenu);

    this->connect(this->exitAction, SIGNAL 'triggered()', this, SLOT 'accept()');
}
# [6]

# [7]
sub createHorizontalGroupBox
{
    this->{horizontalGroupBox} = Qt::GroupBox(this->tr('Horizontal layout'));
    my $layout = Qt::HBoxLayout();

    this->{buttons} = [];
    for (my $i = 0; $i < NumButtons; ++$i) {
        this->buttons->[$i] = Qt::PushButton(sprintf this->tr('Button %s'), $i + 1);
        $layout->addWidget(this->buttons->[$i]);
    }
    this->horizontalGroupBox->setLayout($layout);
}
# [7]

# [8]
sub createGridGroupBox
{
    this->{gridGroupBox} = Qt::GroupBox(this->tr('Grid layout'));
# [8]
    my $layout = Qt::GridLayout();

# [9]
    this->{labels} = [];
    this->{lineEdits} = [];
    for (my $i = 0; $i < NumGridRows; ++$i) {
        this->labels->[$i] = Qt::Label( sprintf this->tr('Line %s'), $i + 1);
        this->lineEdits->[$i] = Qt::LineEdit();
        $layout->addWidget(this->labels->[$i], $i + 1, 0);
        $layout->addWidget(this->lineEdits->[$i], $i + 1, 1);
    }

# [9] //! [10]
    this->{smallEditor} = Qt::TextEdit();
    this->smallEditor->setPlainText(this->tr('This widget takes up about two thirds of the ' .
                                 'grid layout.'));
    $layout->addWidget(this->smallEditor, 0, 2, 4, 1);
# [10]

# [11]
    $layout->setColumnStretch(1, 10);
    $layout->setColumnStretch(2, 20);
    this->gridGroupBox->setLayout($layout);
}
# [11]

# [12]
sub createFormGroupBox
{
    this->{formGroupBox} = Qt::GroupBox(this->tr('Form layout'));
    my $layout = Qt::FormLayout();
    $layout->addRow(Qt::Label(this->tr('Line 1:')), Qt::LineEdit());
    $layout->addRow(Qt::Label(this->tr('Line 2, long text:')), Qt::ComboBox());
    $layout->addRow(Qt::Label(this->tr('Line 3:')), Qt::SpinBox());
    this->formGroupBox->setLayout($layout);
}
# [12]

1;