File: Screenshot.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 (273 lines) | stat: -rw-r--r-- 6,662 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
package Screenshot; 

use strict;
use warnings;
use QtCore4;
use QtGui4;
# [0]
use QtCore4::isa qw( Qt::Widget );
use QtCore4::slots
    newScreenshot => [],
    saveScreenshot => [],
    shootScreen => [],
    updateCheckBox => [];

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

sub setOriginalPixmap($) {
    return this->{originalPixmap} = shift;
}

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

sub setScreenshotLabel($) {
    return this->{screenshotLabel} = shift;
}

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

sub setOptionsGroupBox($) {
    return this->{optionsGroupBox} = shift;
}

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

sub setDelaySpinBox($) {
    return this->{delaySpinBox} = shift;
}

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

sub setDelaySpinBoxLabel($) {
    return this->{delaySpinBoxLabel} = shift;
}

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

sub setHideThisWindowCheckBox($) {
    return this->{hideThisWindowCheckBox} = shift;
}

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

sub setNewScreenshotButton($) {
    return this->{newScreenshotButton} = shift;
}

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

sub setSaveScreenshotButton($) {
    return this->{saveScreenshotButton} = shift;
}

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

sub setQuitScreenshotButton($) {
    return this->{quitScreenshotButton} = shift;
}

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

sub setMainLayout($) {
    return this->{mainLayout} = shift;
}

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

sub setOptionsGroupBoxLayout($) {
    return this->{optionsGroupBoxLayout} = shift;
}

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

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

# [0]
sub NEW
{
    my ($class) = @_;
    $class->SUPER::NEW();
    this->setScreenshotLabel( Qt::Label() );
    this->screenshotLabel->setSizePolicy(Qt::SizePolicy::Expanding(),
                                         Qt::SizePolicy::Expanding());
    this->screenshotLabel->setAlignment(Qt::AlignCenter());
    this->screenshotLabel->setMinimumSize(240, 160);

    this->createOptionsGroupBox();
    this->createButtonsLayout();

    this->setMainLayout( Qt::VBoxLayout() );
    this->mainLayout->addWidget(this->screenshotLabel);
    this->mainLayout->addWidget(this->optionsGroupBox);
    this->mainLayout->addLayout(this->buttonsLayout);
    this->setLayout(this->mainLayout);

    this->shootScreen();
    this->delaySpinBox->setValue(5);

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

# [1]
sub resizeEvent
{
    my $scaledSize = this->originalPixmap->size();
    $scaledSize->scale(this->screenshotLabel->size(), Qt::KeepAspectRatio());
    if (!this->screenshotLabel->pixmap()
            || $scaledSize != this->screenshotLabel->pixmap()->size()) {
        this->updateScreenshotLabel();
    }
}
# [1]

# [2]
sub newScreenshot
{
    if (this->hideThisWindowCheckBox->isChecked()) {
        this->hide();
    }
    this->newScreenshotButton->setDisabled(1);

    Qt::Timer::singleShot(this->delaySpinBox->value() * 1000, this, SLOT 'shootScreen()');
}
# [2]

# [3]
sub saveScreenshot
{
    my $format = 'png';
    my $initialPath = Qt::Dir::currentPath() . this->tr('/untitled.') . $format;

    my $fileName = Qt::FileDialog::getSaveFileName(this, this->tr('Save As'),
                               $initialPath,
                       sprintf this->tr('%s Files (*.%s);;All Files (*)'),
                               uc($format),
                               $format);
    if ($fileName) {
        this->originalPixmap->save($fileName, $format);
    }
}
# [3]

# [4]
sub shootScreen
{
    if (this->delaySpinBox->value() != 0) {
        qApp->beep();
    }
# [4]
     # clear image for low memory situations on embedded devices.
    this->setOriginalPixmap( Qt::Pixmap() );
# [5]
    this->setOriginalPixmap( Qt::Pixmap::grabWindow(Qt::Application::desktop()->winId()) );
    this->updateScreenshotLabel();

    this->newScreenshotButton->setDisabled(0);
    if (this->hideThisWindowCheckBox->isChecked()) {
        this->show();
    }
}
# [5]

# [6]
sub updateCheckBox
{
    if (this->delaySpinBox->value() == 0) {
        this->hideThisWindowCheckBox->setDisabled(1);
    }
    else {
        this->hideThisWindowCheckBox->setDisabled(0);
    }
}
# [6]

# [7]
sub createOptionsGroupBox
{
    this->setOptionsGroupBox( Qt::GroupBox(this->tr('Options')) );

    this->setDelaySpinBox( Qt::SpinBox() );
    this->delaySpinBox->setSuffix(this->tr(' s'));
    this->delaySpinBox->setMaximum(60);
    this->connect(this->delaySpinBox, SIGNAL 'valueChanged(int)', this, SLOT 'updateCheckBox()');

    this->setDelaySpinBoxLabel( Qt::Label(this->tr('Screenshot Delay:')) );

    this->setHideThisWindowCheckBox( Qt::CheckBox(this->tr('Hide This Window')) );

    this->setOptionsGroupBoxLayout( Qt::GridLayout() );
    this->optionsGroupBoxLayout->addWidget(this->delaySpinBoxLabel, 0, 0);
    this->optionsGroupBoxLayout->addWidget(this->delaySpinBox, 0, 1);
    this->optionsGroupBoxLayout->addWidget(this->hideThisWindowCheckBox, 1, 0, 1, 2);
    this->optionsGroupBox->setLayout(this->optionsGroupBoxLayout);
}
# [7]

# [8]
sub createButtonsLayout
{
    this->setNewScreenshotButton( createButton(this->tr('New Screenshot'),
                                       this, SLOT 'newScreenshot()') );

    this->setSaveScreenshotButton( createButton(this->tr('Save Screenshot'),
                                        this, SLOT 'saveScreenshot()') );

    this->setQuitScreenshotButton( createButton(this->tr('Quit'), this, SLOT 'close()') );

    this->setButtonsLayout( Qt::HBoxLayout() );
    this->buttonsLayout->addStretch();
    this->buttonsLayout->addWidget(this->newScreenshotButton);
    this->buttonsLayout->addWidget(this->saveScreenshotButton);
    this->buttonsLayout->addWidget(this->quitScreenshotButton);
}
# [8]

# [9]
sub createButton
{
    my ($text, $receiver, $member) = @_;
    my $button = Qt::PushButton($text);
    $button->connect($button, SIGNAL 'clicked()', $receiver, $member);
    return $button;
}
# [9]

# [10]
sub updateScreenshotLabel
{
    this->screenshotLabel->setPixmap(this->originalPixmap->scaled(this->screenshotLabel->size(),
                                                     Qt::KeepAspectRatio(),
                                                     Qt::SmoothTransformation()));
}
# [10]

1;