File: Window.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 (400 lines) | stat: -rw-r--r-- 10,677 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
package Window;

use strict;
use warnings;
use QtCore4;
use QtGui4;
# [0]
use QtCore4::isa qw( Qt::Dialog );
use QtCore4::slots
    setIcon => ['int'],
    iconActivated => ['QSystemTrayIcon::ActivationReason'],
    showMessage => [],
    messageClicked => [];

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

sub setIconGroupBox($) {
    return this->{iconGroupBox} = shift;
}

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

sub setIconLabel($) {
    return this->{iconLabel} = shift;
}

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

sub setIconComboBox($) {
    return this->{iconComboBox} = shift;
}

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

sub setShowIconCheckBox($) {
    return this->{showIconCheckBox} = shift;
}

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

sub setMessageGroupBox($) {
    return this->{messageGroupBox} = shift;
}

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

sub setTypeLabel($) {
    return this->{typeLabel} = shift;
}

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

sub setDurationLabel($) {
    return this->{durationLabel} = shift;
}

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

sub setDurationWarningLabel($) {
    return this->{durationWarningLabel} = shift;
}

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

sub setTitleLabel($) {
    return this->{titleLabel} = shift;
}

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

sub setBodyLabel($) {
    return this->{bodyLabel} = shift;
}

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

sub setTypeComboBox($) {
    return this->{typeComboBox} = shift;
}

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

sub setDurationSpinBox($) {
    return this->{durationSpinBox} = shift;
}

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

sub setTitleEdit($) {
    return this->{titleEdit} = shift;
}

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

sub setBodyEdit($) {
    return this->{bodyEdit} = shift;
}

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

sub setShowMessageButton($) {
    return this->{showMessageButton} = shift;
}

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

sub setMinimizeAction($) {
    return this->{minimizeAction} = shift;
}

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

sub setMaximizeAction($) {
    return this->{maximizeAction} = shift;
}

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

sub setRestoreAction($) {
    return this->{restoreAction} = shift;
}

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

sub setQuitAction($) {
    return this->{quitAction} = shift;
}

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

sub setTrayIcon($) {
    return this->{trayIcon} = shift;
}

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

sub setTrayIconMenu($) {
    return this->{trayIconMenu} = shift;
}
# [0]

# [0]
sub NEW
{
    my ( $class ) = @_;
    $class->SUPER::NEW();
    this->createIconGroupBox();
    this->createMessageGroupBox();

    this->iconLabel->setMinimumWidth(this->durationLabel->sizeHint()->width());

    this->createActions();
    this->createTrayIcon();

    this->connect(this->showMessageButton, SIGNAL 'clicked()', this, SLOT 'showMessage()');
    this->connect(this->showIconCheckBox, SIGNAL 'toggled(bool)',
            this->trayIcon, SLOT 'setVisible(bool)');
    this->connect(this->iconComboBox, SIGNAL 'currentIndexChanged(int)',
            this, SLOT 'setIcon(int)');
    this->connect(this->trayIcon, SIGNAL 'messageClicked()', this, SLOT 'messageClicked()');
    this->connect(this->trayIcon, SIGNAL 'activated(QSystemTrayIcon::ActivationReason)',
            this, SLOT 'iconActivated(QSystemTrayIcon::ActivationReason)');

    my $mainLayout = Qt::VBoxLayout();
    $mainLayout->addWidget(this->iconGroupBox);
    $mainLayout->addWidget(this->messageGroupBox);
    this->setLayout($mainLayout);

    this->iconComboBox->setCurrentIndex(1);
    this->trayIcon->show();

    this->setWindowTitle(this->tr('Systray'));
    this->resize(400, 300);
}
# [0]

# [1]
sub setVisible
{
    my ($visible) = @_;
    this->minimizeAction->setEnabled($visible);
    this->maximizeAction->setEnabled(!this->isMaximized());
    this->restoreAction->setEnabled(this->isMaximized() || !$visible);
    this->SUPER::setVisible($visible);
}
# [1]

# [2]
sub closeEvent
{
    my ($event) = @_;
    if (this->trayIcon->isVisible()) {
        Qt::MessageBox::information(this, this->tr('Systray'),
                                 this->tr('The program will keep running in the ' .
                                    'system tray. To terminate the program, ' .
                                    'choose <b>Quit</b> in the context menu ' .
                                    'of the system tray entry.'));
        this->hide();
        $event->ignore();
    }
}
# [2]

# [3]
sub setIcon
{
    my ($index) = @_;
    my $icon = this->iconComboBox->itemIcon($index);
    this->trayIcon->setIcon($icon);
    this->setWindowIcon($icon);

    this->trayIcon->setToolTip(this->iconComboBox->itemText($index));
}
# [3]

# [4]
sub iconActivated
{
    my ($reason) = @_;
    if ($reason == Qt::SystemTrayIcon::Trigger() ||
        $reason == Qt::SystemTrayIcon::DoubleClick()) {
        this->iconComboBox->setCurrentIndex((this->iconComboBox->currentIndex() + 1)
                                      % this->iconComboBox->count());
    }
    elsif ($reason == Qt::SystemTrayIcon::MiddleClick()) {
        this->showMessage();
    }
}
# [4]

# [5]
sub showMessage
{
    my $icon = this->typeComboBox->itemData(this->typeComboBox->currentIndex())->toInt();
    this->trayIcon->showMessage(this->titleEdit->text(), this->bodyEdit->toPlainText(), $icon,
                          this->durationSpinBox->value() * 1000);
}
# [5]

# [6]
sub messageClicked
{
    Qt::MessageBox::information(undef, this->tr('Systray'),
                             this->tr("Sorry, I already gave what help I could.\n" .
                                'Maybe you should try asking a human?'));
}
# [6]

sub createIconGroupBox
{
    this->setIconGroupBox(Qt::GroupBox(this->tr('Tray Icon')));

    this->setIconLabel(Qt::Label('Icon:'));

    this->setIconComboBox(Qt::ComboBox());
    this->iconComboBox->addItem(Qt::Icon('images/bad.svg'), this->tr('Bad'));
    this->iconComboBox->addItem(Qt::Icon('images/heart.svg'), this->tr('Heart'));
    this->iconComboBox->addItem(Qt::Icon('images/trash.svg'), this->tr('Trash'));

    this->setShowIconCheckBox(Qt::CheckBox(this->tr('Show icon')));
    this->showIconCheckBox->setChecked(1);

    my $iconLayout = Qt::HBoxLayout();
    $iconLayout->addWidget(this->iconLabel);
    $iconLayout->addWidget(this->iconComboBox);
    $iconLayout->addStretch();
    $iconLayout->addWidget(this->showIconCheckBox);
    this->iconGroupBox->setLayout($iconLayout);
}

sub createMessageGroupBox
{
    this->setMessageGroupBox(Qt::GroupBox(this->tr('Balloon Message')));

    this->setTypeLabel(Qt::Label(this->tr('Type:')));

    this->setTypeComboBox(Qt::ComboBox());
    this->typeComboBox->addItem(this->tr('None'), Qt::Variant(Qt::Int(${Qt::SystemTrayIcon::NoIcon()})));
    this->typeComboBox->addItem(this->style()->standardIcon(
            Qt::Style::SP_MessageBoxInformation()), this->tr('Information'),
            Qt::Variant(Qt::Int(${Qt::SystemTrayIcon::Information()})));
    this->typeComboBox->addItem(this->style()->standardIcon(
            Qt::Style::SP_MessageBoxWarning()), this->tr('Warning'),
            Qt::Variant(Qt::Int(${Qt::SystemTrayIcon::Warning()})));
    this->typeComboBox->addItem(this->style()->standardIcon(
            Qt::Style::SP_MessageBoxCritical()), this->tr('Critical'),
            Qt::Variant(Qt::Int(${Qt::SystemTrayIcon::Critical()})));
    this->typeComboBox->setCurrentIndex(1);

    this->setDurationLabel(Qt::Label(this->tr('Duration:')));

    this->setDurationSpinBox(Qt::SpinBox());
    this->durationSpinBox->setRange(5, 60);
    this->durationSpinBox->setSuffix(' s');
    this->durationSpinBox->setValue(15);

    this->setDurationWarningLabel(Qt::Label(this->tr('(some systems might ignore this '.
                                         'hint)')));
    this->durationWarningLabel->setIndent(10);

    this->setTitleLabel(Qt::Label(this->tr('Title:')));

    this->setTitleEdit(Qt::LineEdit(this->tr('Cannot connect to network')));

    this->setBodyLabel(Qt::Label(this->tr('Body:')));

    this->setBodyEdit(Qt::TextEdit());
    this->bodyEdit->setPlainText(this->tr('Don\'t believe me. Honestly, I don\'t have a ' .
                              "clue.\nClick this balloon for details."));

    this->setShowMessageButton(Qt::PushButton(this->tr('Show Message')));
    this->showMessageButton->setDefault(1);

    my $messageLayout = Qt::GridLayout();
    $messageLayout->addWidget(this->typeLabel, 0, 0);
    $messageLayout->addWidget(this->typeComboBox, 0, 1, 1, 2);
    $messageLayout->addWidget(this->durationLabel, 1, 0);
    $messageLayout->addWidget(this->durationSpinBox, 1, 1);
    $messageLayout->addWidget(this->durationWarningLabel, 1, 2, 1, 3);
    $messageLayout->addWidget(this->titleLabel, 2, 0);
    $messageLayout->addWidget(this->titleEdit, 2, 1, 1, 4);
    $messageLayout->addWidget(this->bodyLabel, 3, 0);
    $messageLayout->addWidget(this->bodyEdit, 3, 1, 2, 4);
    $messageLayout->addWidget(this->showMessageButton, 5, 4);
    $messageLayout->setColumnStretch(3, 1);
    $messageLayout->setRowStretch(4, 1);
    this->messageGroupBox->setLayout($messageLayout);
}

sub createActions
{
    this->setMinimizeAction(Qt::Action(this->tr('Mi&nimize'), this));
    this->connect(this->minimizeAction, SIGNAL 'triggered()', this, SLOT 'hide()');

    this->setMaximizeAction(Qt::Action(this->tr('Ma&ximize'), this));
    this->connect(this->maximizeAction, SIGNAL 'triggered()', this, SLOT 'showMaximized()');

    this->setRestoreAction(Qt::Action(this->tr('&Restore'), this));
    this->connect(this->restoreAction, SIGNAL 'triggered()', this, SLOT 'showNormal()');

    this->setQuitAction(Qt::Action(this->tr('&Quit'), this));
    this->connect(this->quitAction, SIGNAL 'triggered()', qApp, SLOT 'quit()');
}

sub createTrayIcon
{
    this->setTrayIconMenu(Qt::Menu(this));
    this->trayIconMenu->addAction(this->minimizeAction);
    this->trayIconMenu->addAction(this->maximizeAction);
    this->trayIconMenu->addAction(this->restoreAction);
    this->trayIconMenu->addSeparator();
    this->trayIconMenu->addAction(this->quitAction);

    this->setTrayIcon(Qt::SystemTrayIcon(this));
    trayIcon->setContextMenu(this->trayIconMenu);
}

1;