summaryrefslogtreecommitdiffstats
path: root/examples/desktop
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 12:05:43 +0200
committeraxis <qt-info@nokia.com>2011-04-27 12:05:43 +0200
commit38be0d13830efd2d98281c645c3a60afe05ffece (patch)
tree6ea73f3ec77f7d153333779883e8120f82820abe /examples/desktop
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to 'examples/desktop')
-rw-r--r--examples/desktop/README41
-rw-r--r--examples/desktop/desktop.pro13
-rw-r--r--examples/desktop/screenshot/main.cpp51
-rw-r--r--examples/desktop/screenshot/screenshot.cpp197
-rw-r--r--examples/desktop/screenshot/screenshot.h99
-rw-r--r--examples/desktop/screenshot/screenshot.pro11
6 files changed, 412 insertions, 0 deletions
diff --git a/examples/desktop/README b/examples/desktop/README
new file mode 100644
index 0000000000..efe569a604
--- /dev/null
+++ b/examples/desktop/README
@@ -0,0 +1,41 @@
+Qt provides features to enable applications to integrate with the user's
+preferred desktop environment.
+
+Features such as system tray icons, access to the desktop widget, and
+support for desktop services can be used to improve the appearance of
+applications and take advantage of underlying desktop facilities.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/desktop/desktop.pro b/examples/desktop/desktop.pro
new file mode 100644
index 0000000000..eb3cbaca42
--- /dev/null
+++ b/examples/desktop/desktop.pro
@@ -0,0 +1,13 @@
+TEMPLATE = subdirs
+CONFIG += ordered
+SUBDIRS = screenshot
+
+!symbian:contains(QT_CONFIG, svg): SUBDIRS += systray
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/desktop
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS desktop.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/desktop
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/desktop/screenshot/main.cpp b/examples/desktop/screenshot/main.cpp
new file mode 100644
index 0000000000..c2930f7513
--- /dev/null
+++ b/examples/desktop/screenshot/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "screenshot.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Screenshot screenshot;
+ screenshot.show();
+ return app.exec();
+}
diff --git a/examples/desktop/screenshot/screenshot.cpp b/examples/desktop/screenshot/screenshot.cpp
new file mode 100644
index 0000000000..0d7a18842a
--- /dev/null
+++ b/examples/desktop/screenshot/screenshot.cpp
@@ -0,0 +1,197 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "screenshot.h"
+
+//! [0]
+Screenshot::Screenshot()
+{
+ screenshotLabel = new QLabel;
+ screenshotLabel->setSizePolicy(QSizePolicy::Expanding,
+ QSizePolicy::Expanding);
+ screenshotLabel->setAlignment(Qt::AlignCenter);
+ screenshotLabel->setMinimumSize(240, 160);
+
+ createOptionsGroupBox();
+ createButtonsLayout();
+
+ mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(screenshotLabel);
+ mainLayout->addWidget(optionsGroupBox);
+ mainLayout->addLayout(buttonsLayout);
+ setLayout(mainLayout);
+
+ shootScreen();
+ delaySpinBox->setValue(5);
+
+ setWindowTitle(tr("Screenshot"));
+ resize(300, 200);
+}
+//! [0]
+
+//! [1]
+void Screenshot::resizeEvent(QResizeEvent * /* event */)
+{
+ QSize scaledSize = originalPixmap.size();
+ scaledSize.scale(screenshotLabel->size(), Qt::KeepAspectRatio);
+ if (!screenshotLabel->pixmap()
+ || scaledSize != screenshotLabel->pixmap()->size())
+ updateScreenshotLabel();
+}
+//! [1]
+
+//! [2]
+void Screenshot::newScreenshot()
+{
+ if (hideThisWindowCheckBox->isChecked())
+ hide();
+ newScreenshotButton->setDisabled(true);
+
+ QTimer::singleShot(delaySpinBox->value() * 1000, this, SLOT(shootScreen()));
+}
+//! [2]
+
+//! [3]
+void Screenshot::saveScreenshot()
+{
+ QString format = "png";
+ QString initialPath = QDir::currentPath() + tr("/untitled.") + format;
+
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
+ initialPath,
+ tr("%1 Files (*.%2);;All Files (*)")
+ .arg(format.toUpper())
+ .arg(format));
+ if (!fileName.isEmpty())
+ originalPixmap.save(fileName, format.toAscii());
+}
+//! [3]
+
+//! [4]
+void Screenshot::shootScreen()
+{
+ if (delaySpinBox->value() != 0)
+ qApp->beep();
+//! [4]
+ originalPixmap = QPixmap(); // clear image for low memory situations
+ // on embedded devices.
+//! [5]
+ originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
+ updateScreenshotLabel();
+
+ newScreenshotButton->setDisabled(false);
+ if (hideThisWindowCheckBox->isChecked())
+ show();
+}
+//! [5]
+
+//! [6]
+void Screenshot::updateCheckBox()
+{
+ if (delaySpinBox->value() == 0) {
+ hideThisWindowCheckBox->setDisabled(true);
+ hideThisWindowCheckBox->setChecked(false);
+ }
+ else
+ hideThisWindowCheckBox->setDisabled(false);
+}
+//! [6]
+
+//! [7]
+void Screenshot::createOptionsGroupBox()
+{
+ optionsGroupBox = new QGroupBox(tr("Options"));
+
+ delaySpinBox = new QSpinBox;
+ delaySpinBox->setSuffix(tr(" s"));
+ delaySpinBox->setMaximum(60);
+ connect(delaySpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateCheckBox()));
+
+ delaySpinBoxLabel = new QLabel(tr("Screenshot Delay:"));
+
+ hideThisWindowCheckBox = new QCheckBox(tr("Hide This Window"));
+
+ optionsGroupBoxLayout = new QGridLayout;
+ optionsGroupBoxLayout->addWidget(delaySpinBoxLabel, 0, 0);
+ optionsGroupBoxLayout->addWidget(delaySpinBox, 0, 1);
+ optionsGroupBoxLayout->addWidget(hideThisWindowCheckBox, 1, 0, 1, 2);
+ optionsGroupBox->setLayout(optionsGroupBoxLayout);
+}
+//! [7]
+
+//! [8]
+void Screenshot::createButtonsLayout()
+{
+ newScreenshotButton = createButton(tr("New Screenshot"),
+ this, SLOT(newScreenshot()));
+
+ saveScreenshotButton = createButton(tr("Save Screenshot"),
+ this, SLOT(saveScreenshot()));
+
+ quitScreenshotButton = createButton(tr("Quit"), this, SLOT(close()));
+
+ buttonsLayout = new QHBoxLayout;
+ buttonsLayout->addStretch();
+ buttonsLayout->addWidget(newScreenshotButton);
+ buttonsLayout->addWidget(saveScreenshotButton);
+ buttonsLayout->addWidget(quitScreenshotButton);
+}
+//! [8]
+
+//! [9]
+QPushButton *Screenshot::createButton(const QString &text, QWidget *receiver,
+ const char *member)
+{
+ QPushButton *button = new QPushButton(text);
+ button->connect(button, SIGNAL(clicked()), receiver, member);
+ return button;
+}
+//! [9]
+
+//! [10]
+void Screenshot::updateScreenshotLabel()
+{
+ screenshotLabel->setPixmap(originalPixmap.scaled(screenshotLabel->size(),
+ Qt::KeepAspectRatio,
+ Qt::SmoothTransformation));
+}
+//! [10]
diff --git a/examples/desktop/screenshot/screenshot.h b/examples/desktop/screenshot/screenshot.h
new file mode 100644
index 0000000000..03e0508575
--- /dev/null
+++ b/examples/desktop/screenshot/screenshot.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SCREENSHOT_H
+#define SCREENSHOT_H
+
+#include <QPixmap>
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QCheckBox;
+class QGridLayout;
+class QGroupBox;
+class QHBoxLayout;
+class QLabel;
+class QPushButton;
+class QSpinBox;
+class QVBoxLayout;
+QT_END_NAMESPACE
+
+//! [0]
+class Screenshot : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Screenshot();
+
+protected:
+ void resizeEvent(QResizeEvent *event);
+
+private slots:
+ void newScreenshot();
+ void saveScreenshot();
+ void shootScreen();
+ void updateCheckBox();
+
+private:
+ void createOptionsGroupBox();
+ void createButtonsLayout();
+ QPushButton *createButton(const QString &text, QWidget *receiver,
+ const char *member);
+ void updateScreenshotLabel();
+
+ QPixmap originalPixmap;
+
+ QLabel *screenshotLabel;
+ QGroupBox *optionsGroupBox;
+ QSpinBox *delaySpinBox;
+ QLabel *delaySpinBoxLabel;
+ QCheckBox *hideThisWindowCheckBox;
+ QPushButton *newScreenshotButton;
+ QPushButton *saveScreenshotButton;
+ QPushButton *quitScreenshotButton;
+
+ QVBoxLayout *mainLayout;
+ QGridLayout *optionsGroupBoxLayout;
+ QHBoxLayout *buttonsLayout;
+};
+//! [0]
+
+#endif
diff --git a/examples/desktop/screenshot/screenshot.pro b/examples/desktop/screenshot/screenshot.pro
new file mode 100644
index 0000000000..ab2700fed1
--- /dev/null
+++ b/examples/desktop/screenshot/screenshot.pro
@@ -0,0 +1,11 @@
+HEADERS = screenshot.h
+SOURCES = main.cpp \
+ screenshot.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/desktop/screenshot
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS screenshot.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/desktop/screenshot
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)