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 (192 lines) | stat: -rw-r--r-- 5,704 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package Dialog;

use strict;
use warnings;
use QtCore4;
use QtGui4;
use QtCore4::isa qw( Qt::Dialog );
use QtCore4::slots
    buttonsOrientationChanged => ['int'],
    rotateWidgets => [],
    help => [];

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

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

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

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

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

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

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

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

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

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

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

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


sub NEW
{
    my ($class, $parent) = @_;
    $class->SUPER::NEW($parent);
    this->createRotableGroupBox();
    this->createOptionsGroupBox();
    this->createButtonBox();

    this->{mainLayout} = Qt::GridLayout();
    this->mainLayout->addWidget(this->rotableGroupBox, 0, 0);
    this->mainLayout->addWidget(this->optionsGroupBox, 1, 0);
    this->mainLayout->addWidget(this->buttonBox, 2, 0);
    this->setLayout(this->mainLayout);

    this->mainLayout->setSizeConstraint(Qt::Layout::SetMinimumSize());

    this->setWindowTitle(this->tr('Dynamic Layouts'));
}

sub buttonsOrientationChanged
{
    my ($index) = @_;
    this->mainLayout->setSizeConstraint(Qt::Layout::SetNoConstraint());
    this->setMinimumSize(0, 0);

    my $orientation = this->buttonsOrientationComboBox->itemData($index)->toInt();

    if ($orientation == this->buttonBox->orientation()) {
        return;
    }

    this->mainLayout->removeWidget(this->buttonBox);

    my $spacing = this->mainLayout->spacing();

    my $oldSizeHint = this->buttonBox->sizeHint() + Qt::Size($spacing, $spacing);
    this->buttonBox->setOrientation($orientation);
    my $newSizeHint = this->buttonBox->sizeHint() + Qt::Size($spacing, $spacing);

    if ($orientation == Qt::Horizontal()) {
        this->mainLayout->addWidget(this->buttonBox, 2, 0);
        this->resize(this->size() + Qt::Size(-($oldSizeHint->width()), $newSizeHint->height()));
    } else {
        this->mainLayout->addWidget(this->buttonBox, 0, 3, 2, 1);
        this->resize(this->size() + Qt::Size($newSizeHint->width(), -($oldSizeHint->height())));
    }

    this->mainLayout->setSizeConstraint(Qt::Layout::SetDefaultConstraint());
}

sub rotateWidgets
{
    die 'ASSERT: $rotableWidgets->count() % 2 == 0' if !(scalar @{this->rotableWidgets} % 2 == 0);

    foreach my $widget ( @{this->rotableWidgets} ) {
        this->rotableLayout->removeWidget($widget);
    }

    push @{this->rotableWidgets}, shift @{this->rotableWidgets};

    my $n = scalar @{this->rotableWidgets};
    for (my $i = 0; $i < $n / 2; ++$i) {
        this->rotableLayout->addWidget(this->rotableWidgets->[$n - $i - 1], 0, $i);
        this->rotableLayout->addWidget(this->rotableWidgets->[$i], 1, $i);
    }
}

sub help
{
    Qt::MessageBox::information(this, this->tr('Dynamic Layouts Help'),
                               this->tr('This example shows how to change layouts ' .
                                  'dynamically.'));
}

sub createRotableGroupBox
{
    this->{rotableGroupBox} = Qt::GroupBox(this->tr('Rotable Widgets'));

    this->{rotableWidgets} = [];
    push @{this->rotableWidgets}, Qt::SpinBox();
    push @{this->rotableWidgets}, Qt::Slider();
    push @{this->rotableWidgets}, Qt::Dial();
    push @{this->rotableWidgets}, Qt::ProgressBar();

    my $n = scalar @{this->rotableWidgets};
    for (my $i = 0; $i < $n; ++$i) {
        this->connect(this->rotableWidgets->[$i], SIGNAL 'valueChanged(int)',
                this->rotableWidgets->[($i + 1) % $n], SLOT 'setValue(int)');
    }

    this->{rotableLayout} = Qt::GridLayout();
    this->rotableGroupBox->setLayout(this->rotableLayout);

    this->rotateWidgets();
}

sub createOptionsGroupBox
{
    this->{optionsGroupBox} = Qt::GroupBox(this->tr('Options'));

    this->{buttonsOrientationLabel} = Qt::Label(this->tr('Orientation of buttons:'));

    this->{buttonsOrientationComboBox} = Qt::ComboBox();
    this->buttonsOrientationComboBox->addItem(this->tr('Horizontal'), Qt::Variant(Qt::Int(${Qt::Horizontal()})));
    this->buttonsOrientationComboBox->addItem(this->tr('Vertical'), Qt::Variant(Qt::Int(${Qt::Vertical()})));

    this->connect(this->buttonsOrientationComboBox, SIGNAL 'currentIndexChanged(int)',
            this, SLOT 'buttonsOrientationChanged(int)');

    this->{optionsLayout} = Qt::GridLayout();
    this->optionsLayout->addWidget(this->buttonsOrientationLabel, 0, 0);
    this->optionsLayout->addWidget(this->buttonsOrientationComboBox, 0, 1);
    this->optionsLayout->setColumnStretch(2, 1);
    this->optionsGroupBox->setLayout(this->optionsLayout);
}

sub createButtonBox
{
    this->{buttonBox} = Qt::DialogButtonBox();

    this->{closeButton} = this->buttonBox->addButton(Qt::DialogButtonBox::Close());
    this->{helpButton} = this->buttonBox->addButton(Qt::DialogButtonBox::Help());
    this->{rotateWidgetsButton} = this->buttonBox->addButton(this->tr('Rotate &Widgets'),
                                               Qt::DialogButtonBox::ActionRole());

    this->connect(this->rotateWidgetsButton, SIGNAL 'clicked()', this, SLOT 'rotateWidgets()');
    this->connect(this->closeButton, SIGNAL 'clicked()', this, SLOT 'close()');
    this->connect(this->helpButton, SIGNAL 'clicked()', this, SLOT 'help()');
}

1;