1 /****************************************************************************
3 ** Copyright (C) 2008 Trolltech ASA. All rights reserved.
5 ** This file is part of the Qt Script Generator project on Trolltech Labs.
7 ** This file may be used under the terms of the GNU General Public
8 ** License version 2.0 as published by the Free Software Foundation
9 ** and appearing in the file LICENSE.GPL included in the packaging of
10 ** this file. Please review the following information to ensure GNU
11 ** General Public Licensing requirements will be met:
12 ** http://www.trolltech.com/products/qt/opensource.html
14 ** If you are unsure which license is appropriate for your use, please
15 ** review the following information:
16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
17 ** sales department at sales@trolltech.com.
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 ****************************************************************************/
24 function tr(s) { return s; }
26 function Screenshot(parent) {
27 QWidget.call(this, parent);
29 this.screenshotLabel = new QLabel();
30 this.screenshotLabel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding);
31 this.screenshotLabel.alignment = Qt.Alignment(Qt.AlignCenter);
32 this.screenshotLabel.setMinimumSize(240, 160);
34 this.createOptionsGroupBox();
35 this.createButtonsLayout();
37 this.mainLayout = new QVBoxLayout();
38 this.mainLayout.addWidget(this.screenshotLabel,0 ,0);
39 this.mainLayout.addWidget(this.optionsGroupBox,0 ,0);
40 this.mainLayout.addLayout(this.buttonsLayout);
41 this.setLayout(this.mainLayout);
44 this.delaySpinBox.setValue(5);
46 this.windowIcon = new QIcon("classpath:com/trolltech/images/qt-logo.png");
47 this.windowTitle = tr("Screenshot");
48 this.resize(300, 200);
51 Screenshot.prototype = new QWidget();
53 Screenshot.prototype.resizeEvent = function(event) {
54 var scaledSize = this.originalPixmap.size();
55 scaledSize.scale(this.screenshotLabel.size, Qt.AspectRatioMode.KeepAspectRatio);
56 if (this.screenshotLabel.pixmap != null
57 || scaledSize != this.screenshotLabel.pixmap.size())
58 this.updateScreenshotLabel();
61 Screenshot.prototype.newScreenshot = function() {
62 if ( this.hideThisWindowCheckBox.checked)
64 this.newScreenshotButton.setDisabled(true);
67 // QTimer.singleShot(this.delaySpinBox.value * 1000,
68 // this, this.shootScreen);
69 var singleShot = new QTimer();
70 singleShot.singleShot = true;
71 singleShot.timeout.connect(this, this.shootScreen);
72 singleShot.start(this.delaySpinBox.value * 1000);
75 Screenshot.prototype.saveScreenshot = function() {
77 var initialPath = QDir.currentPath() + tr("/untitled.") + format;
78 var filter = tr(format.toUpperCase() + " Files (*." + format + ");;All Files (*)");
79 var fileName = QFileDialog.getSaveFileName(this, tr("Save As"), initialPath, filter, null, null);
80 // new QFileDialog.Option.Filter(filter)); //FIXME
83 this.originalPixmap.save(fileName); //, format); //FIXME
86 Screenshot.prototype.shootScreen = function() {
87 if ( this.delaySpinBox.value != 0)
90 this.originalPixmap = null;
92 this.originalPixmap = QPixmap.grabWindow(
93 QApplication.desktop().winId());
94 this.updateScreenshotLabel();
96 this.newScreenshotButton.enabled = true;
97 if (this.hideThisWindowCheckBox.checked)
101 Screenshot.prototype.updateCheckBox = function() {
102 if (this.delaySpinBox.value)
103 this.hideThisWindowCheckBox.setDisabled(true);
105 this.hideThisWindowCheckBox.setDisabled(false);
108 Screenshot.prototype.createOptionsGroupBox = function() {
109 this.optionsGroupBox = new QGroupBox(tr("Options"));
111 this.delaySpinBox = new QSpinBox();
112 this.delaySpinBox.suffix = tr(" s");
113 this.delaySpinBox.maximum = 60;
114 this.delaySpinBox.valueChanged.connect(this, this.updateCheckBox);
116 this.delaySpinBoxLabel = new QLabel(tr("Screenshot Delay:"));
118 this.hideThisWindowCheckBox = new QCheckBox(tr("Hide This Window"));
120 this.optionsGroupBoxLayout = new QGridLayout();
121 this.optionsGroupBoxLayout.addWidget(this.delaySpinBoxLabel, 0, 0);
122 this.optionsGroupBoxLayout.addWidget(this.delaySpinBox, 0, 1);
123 this.optionsGroupBoxLayout.addWidget(this.hideThisWindowCheckBox, 1, 0, 1, 2);
124 this.optionsGroupBox.setLayout(this.optionsGroupBoxLayout);
127 Screenshot.prototype.createButtonsLayout = function() {
128 this.newScreenshotButton = this.createButton(tr("New Screenshot"), this,
131 this.saveScreenshotButton = this.createButton(tr("Save Screenshot"), this,
132 this.saveScreenshot);
134 this.quitScreenshotButton = this.createButton(tr("Quit"), this, this.close);
136 this.buttonsLayout = new QHBoxLayout();
137 this.buttonsLayout.addStretch();
138 this.buttonsLayout.addWidget(this.newScreenshotButton, 0, 0);
139 this.buttonsLayout.addWidget(this.saveScreenshotButton, 0, 0);
140 this.buttonsLayout.addWidget(this.quitScreenshotButton, 0, 0);
143 Screenshot.prototype.createButton = function(text, receiver, member) {
144 var button = new QPushButton(text);
145 button.clicked.connect(receiver, member);
149 Screenshot.prototype.updateScreenshotLabel = function() {
150 this.screenshotLabel.setPixmap(this.originalPixmap.scaled(this.screenshotLabel.size,
152 Qt.SmoothTransformation));
155 var screenshot = new Screenshot(null);
158 QCoreApplication.exec();