diff options
author | Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> | 2012-08-17 13:23:19 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-20 12:20:55 +0200 |
commit | 806dda08d685bc5f9ed71dfe8b61f21848d48066 (patch) | |
tree | a63533a1c4a335ae17adc105abb0ae4e62e2f26e /examples/desktop | |
parent | 9f942014e31842b512c3198de035d041c59f54a9 (diff) |
Moving .qdoc files under examples/widgets/doc
Updated those .qdoc files to refer to the new relative examples
emplacement. Images and snippets to be moved later.
Also grouped all widgets related examples under widgets.
Change-Id: Ib29696e2d8948524537f53e8dda88f9ee26a597f
Reviewed-by: J-P Nurmi <j-p.nurmi@nokia.com>
Diffstat (limited to 'examples/desktop')
-rw-r--r-- | examples/desktop/README | 10 | ||||
-rw-r--r-- | examples/desktop/desktop.pro | 11 | ||||
-rw-r--r-- | examples/desktop/screenshot/main.cpp | 51 | ||||
-rw-r--r-- | examples/desktop/screenshot/screenshot.cpp | 199 | ||||
-rw-r--r-- | examples/desktop/screenshot/screenshot.desktop | 11 | ||||
-rw-r--r-- | examples/desktop/screenshot/screenshot.h | 99 | ||||
-rw-r--r-- | examples/desktop/screenshot/screenshot.pro | 12 | ||||
-rw-r--r-- | examples/desktop/systray/images/bad.png | bin | 2496 -> 0 bytes | |||
-rw-r--r-- | examples/desktop/systray/images/heart.png | bin | 25780 -> 0 bytes | |||
-rw-r--r-- | examples/desktop/systray/images/trash.png | bin | 12128 -> 0 bytes | |||
-rw-r--r-- | examples/desktop/systray/main.cpp | 63 | ||||
-rw-r--r-- | examples/desktop/systray/systray.desktop | 11 | ||||
-rw-r--r-- | examples/desktop/systray/systray.pro | 14 | ||||
-rw-r--r-- | examples/desktop/systray/systray.qrc | 7 | ||||
-rw-r--r-- | examples/desktop/systray/window.cpp | 270 | ||||
-rw-r--r-- | examples/desktop/systray/window.h | 112 |
16 files changed, 0 insertions, 870 deletions
diff --git a/examples/desktop/README b/examples/desktop/README deleted file mode 100644 index 4a949d1cf7..0000000000 --- a/examples/desktop/README +++ /dev/null @@ -1,10 +0,0 @@ -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. - - -Documentation for these examples can be found via the Examples -link in the main Qt documentation. diff --git a/examples/desktop/desktop.pro b/examples/desktop/desktop.pro deleted file mode 100644 index adfa51f130..0000000000 --- a/examples/desktop/desktop.pro +++ /dev/null @@ -1,11 +0,0 @@ -TEMPLATE = subdirs -CONFIG += ordered -SUBDIRS = screenshot 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 - -QT += widgets diff --git a/examples/desktop/screenshot/main.cpp b/examples/desktop/screenshot/main.cpp deleted file mode 100644 index 3f9b2e1126..0000000000 --- a/examples/desktop/screenshot/main.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** 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 deleted file mode 100644 index 12c6bee6d4..0000000000 --- a/examples/desktop/screenshot/screenshot.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** 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 <QtWidgets> - -#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.toLatin1().constData()); -} -//! [3] - -//! [4] -void Screenshot::shootScreen() -{ - if (delaySpinBox->value() != 0) - qApp->beep(); -//! [4] - originalPixmap = QPixmap(); // clear image for low memory situations - // on embedded devices. -//! [5] - QScreen *screen = QGuiApplication::primaryScreen(); - if (screen) - originalPixmap = screen->grabWindow(0); - 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.desktop b/examples/desktop/screenshot/screenshot.desktop deleted file mode 100644 index 236d360123..0000000000 --- a/examples/desktop/screenshot/screenshot.desktop +++ /dev/null @@ -1,11 +0,0 @@ -[Desktop Entry] -Encoding=UTF-8 -Version=1.0 -Type=Application -Terminal=false -Name=Screenshot -Exec=/opt/usr/bin/screenshot -Icon=screenshot -X-Window-Icon= -X-HildonDesk-ShowInToolbar=true -X-Osso-Type=application/x-executable diff --git a/examples/desktop/screenshot/screenshot.h b/examples/desktop/screenshot/screenshot.h deleted file mode 100644 index 98251f3428..0000000000 --- a/examples/desktop/screenshot/screenshot.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** 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 deleted file mode 100644 index e9f53f7450..0000000000 --- a/examples/desktop/screenshot/screenshot.pro +++ /dev/null @@ -1,12 +0,0 @@ -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 - -QT += widgets -simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/desktop/systray/images/bad.png b/examples/desktop/systray/images/bad.png Binary files differdeleted file mode 100644 index c8701a241a..0000000000 --- a/examples/desktop/systray/images/bad.png +++ /dev/null diff --git a/examples/desktop/systray/images/heart.png b/examples/desktop/systray/images/heart.png Binary files differdeleted file mode 100644 index cee1302b7d..0000000000 --- a/examples/desktop/systray/images/heart.png +++ /dev/null diff --git a/examples/desktop/systray/images/trash.png b/examples/desktop/systray/images/trash.png Binary files differdeleted file mode 100644 index 4c24db926d..0000000000 --- a/examples/desktop/systray/images/trash.png +++ /dev/null diff --git a/examples/desktop/systray/main.cpp b/examples/desktop/systray/main.cpp deleted file mode 100644 index 6695113f71..0000000000 --- a/examples/desktop/systray/main.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** 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 <QMessageBox> - -#include "window.h" - -int main(int argc, char *argv[]) -{ - Q_INIT_RESOURCE(systray); - - QApplication app(argc, argv); - - if (!QSystemTrayIcon::isSystemTrayAvailable()) { - QMessageBox::critical(0, QObject::tr("Systray"), - QObject::tr("I couldn't detect any system tray " - "on this system.")); - return 1; - } - QApplication::setQuitOnLastWindowClosed(false); - - Window window; - window.show(); - return app.exec(); -} diff --git a/examples/desktop/systray/systray.desktop b/examples/desktop/systray/systray.desktop deleted file mode 100644 index 0490e71548..0000000000 --- a/examples/desktop/systray/systray.desktop +++ /dev/null @@ -1,11 +0,0 @@ -[Desktop Entry] -Encoding=UTF-8 -Version=1.0 -Type=Application -Terminal=false -Name=System Tray Icon -Exec=/opt/usr/bin/systray -Icon=systray -X-Window-Icon= -X-HildonDesk-ShowInToolbar=true -X-Osso-Type=application/x-executable diff --git a/examples/desktop/systray/systray.pro b/examples/desktop/systray/systray.pro deleted file mode 100644 index 5fdcf1f9c8..0000000000 --- a/examples/desktop/systray/systray.pro +++ /dev/null @@ -1,14 +0,0 @@ -HEADERS = window.h -SOURCES = main.cpp \ - window.cpp -RESOURCES = systray.qrc - -QT += widgets - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/desktop/systray -sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS systray.pro -sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/desktop/systray -INSTALLS += target sources - -simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/desktop/systray/systray.qrc b/examples/desktop/systray/systray.qrc deleted file mode 100644 index a8b6535849..0000000000 --- a/examples/desktop/systray/systray.qrc +++ /dev/null @@ -1,7 +0,0 @@ -<!DOCTYPE RCC><RCC version="1.0"> -<qresource prefix="/"> - <file>images/bad.png</file> - <file>images/heart.png</file> - <file>images/trash.png</file> -</qresource> -</RCC> diff --git a/examples/desktop/systray/window.cpp b/examples/desktop/systray/window.cpp deleted file mode 100644 index c75e3590ba..0000000000 --- a/examples/desktop/systray/window.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** 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 "window.h" -#include <QtGui> - -#include <QAction> -#include <QCheckBox> -#include <QComboBox> -#include <QGroupBox> -#include <QLabel> -#include <QLineEdit> -#include <QMenu> -#include <QPushButton> -#include <QSpinBox> -#include <QTextEdit> -#include <QVBoxLayout> -#include <QMessageBox> - -//! [0] -Window::Window() -{ - createIconGroupBox(); - createMessageGroupBox(); - - iconLabel->setMinimumWidth(durationLabel->sizeHint().width()); - - createActions(); - createTrayIcon(); - - connect(showMessageButton, SIGNAL(clicked()), this, SLOT(showMessage())); - connect(showIconCheckBox, SIGNAL(toggled(bool)), - trayIcon, SLOT(setVisible(bool))); - connect(iconComboBox, SIGNAL(currentIndexChanged(int)), - this, SLOT(setIcon(int))); - connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked())); - connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), - this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); - - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addWidget(iconGroupBox); - mainLayout->addWidget(messageGroupBox); - setLayout(mainLayout); - - iconComboBox->setCurrentIndex(1); - trayIcon->show(); - - setWindowTitle(tr("Systray")); - resize(400, 300); -} -//! [0] - -//! [1] -void Window::setVisible(bool visible) -{ - minimizeAction->setEnabled(visible); - maximizeAction->setEnabled(!isMaximized()); - restoreAction->setEnabled(isMaximized() || !visible); - QDialog::setVisible(visible); -} -//! [1] - -//! [2] -void Window::closeEvent(QCloseEvent *event) -{ - if (trayIcon->isVisible()) { - QMessageBox::information(this, tr("Systray"), - 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.")); - hide(); - event->ignore(); - } -} -//! [2] - -//! [3] -void Window::setIcon(int index) -{ - QIcon icon = iconComboBox->itemIcon(index); - trayIcon->setIcon(icon); - setWindowIcon(icon); - - trayIcon->setToolTip(iconComboBox->itemText(index)); -} -//! [3] - -//! [4] -void Window::iconActivated(QSystemTrayIcon::ActivationReason reason) -{ - switch (reason) { - case QSystemTrayIcon::Trigger: - case QSystemTrayIcon::DoubleClick: - iconComboBox->setCurrentIndex((iconComboBox->currentIndex() + 1) - % iconComboBox->count()); - break; - case QSystemTrayIcon::MiddleClick: - showMessage(); - break; - default: - ; - } -} -//! [4] - -//! [5] -void Window::showMessage() -{ - QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon( - typeComboBox->itemData(typeComboBox->currentIndex()).toInt()); - trayIcon->showMessage(titleEdit->text(), bodyEdit->toPlainText(), icon, - durationSpinBox->value() * 1000); -} -//! [5] - -//! [6] -void Window::messageClicked() -{ - QMessageBox::information(0, tr("Systray"), - tr("Sorry, I already gave what help I could.\n" - "Maybe you should try asking a human?")); -} -//! [6] - -void Window::createIconGroupBox() -{ - iconGroupBox = new QGroupBox(tr("Tray Icon")); - - iconLabel = new QLabel("Icon:"); - - iconComboBox = new QComboBox; - iconComboBox->addItem(QIcon(":/images/bad.png"), tr("Bad")); - iconComboBox->addItem(QIcon(":/images/heart.png"), tr("Heart")); - iconComboBox->addItem(QIcon(":/images/trash.png"), tr("Trash")); - - showIconCheckBox = new QCheckBox(tr("Show icon")); - showIconCheckBox->setChecked(true); - - QHBoxLayout *iconLayout = new QHBoxLayout; - iconLayout->addWidget(iconLabel); - iconLayout->addWidget(iconComboBox); - iconLayout->addStretch(); - iconLayout->addWidget(showIconCheckBox); - iconGroupBox->setLayout(iconLayout); -} - -void Window::createMessageGroupBox() -{ - messageGroupBox = new QGroupBox(tr("Balloon Message")); - - typeLabel = new QLabel(tr("Type:")); - - typeComboBox = new QComboBox; - typeComboBox->addItem(tr("None"), QSystemTrayIcon::NoIcon); - typeComboBox->addItem(style()->standardIcon( - QStyle::SP_MessageBoxInformation), tr("Information"), - QSystemTrayIcon::Information); - typeComboBox->addItem(style()->standardIcon( - QStyle::SP_MessageBoxWarning), tr("Warning"), - QSystemTrayIcon::Warning); - typeComboBox->addItem(style()->standardIcon( - QStyle::SP_MessageBoxCritical), tr("Critical"), - QSystemTrayIcon::Critical); - typeComboBox->setCurrentIndex(1); - - durationLabel = new QLabel(tr("Duration:")); - - durationSpinBox = new QSpinBox; - durationSpinBox->setRange(5, 60); - durationSpinBox->setSuffix(" s"); - durationSpinBox->setValue(15); - - durationWarningLabel = new QLabel(tr("(some systems might ignore this " - "hint)")); - durationWarningLabel->setIndent(10); - - titleLabel = new QLabel(tr("Title:")); - - titleEdit = new QLineEdit(tr("Cannot connect to network")); - - bodyLabel = new QLabel(tr("Body:")); - - bodyEdit = new QTextEdit; - bodyEdit->setPlainText(tr("Don't believe me. Honestly, I don't have a " - "clue.\nClick this balloon for details.")); - - showMessageButton = new QPushButton(tr("Show Message")); - showMessageButton->setDefault(true); - - QGridLayout *messageLayout = new QGridLayout; - messageLayout->addWidget(typeLabel, 0, 0); - messageLayout->addWidget(typeComboBox, 0, 1, 1, 2); - messageLayout->addWidget(durationLabel, 1, 0); - messageLayout->addWidget(durationSpinBox, 1, 1); - messageLayout->addWidget(durationWarningLabel, 1, 2, 1, 3); - messageLayout->addWidget(titleLabel, 2, 0); - messageLayout->addWidget(titleEdit, 2, 1, 1, 4); - messageLayout->addWidget(bodyLabel, 3, 0); - messageLayout->addWidget(bodyEdit, 3, 1, 2, 4); - messageLayout->addWidget(showMessageButton, 5, 4); - messageLayout->setColumnStretch(3, 1); - messageLayout->setRowStretch(4, 1); - messageGroupBox->setLayout(messageLayout); -} - -void Window::createActions() -{ - minimizeAction = new QAction(tr("Mi&nimize"), this); - connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide())); - - maximizeAction = new QAction(tr("Ma&ximize"), this); - connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized())); - - restoreAction = new QAction(tr("&Restore"), this); - connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal())); - - quitAction = new QAction(tr("&Quit"), this); - connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); -} - -void Window::createTrayIcon() -{ - trayIconMenu = new QMenu(this); - trayIconMenu->addAction(minimizeAction); - trayIconMenu->addAction(maximizeAction); - trayIconMenu->addAction(restoreAction); - trayIconMenu->addSeparator(); - trayIconMenu->addAction(quitAction); - - trayIcon = new QSystemTrayIcon(this); - trayIcon->setContextMenu(trayIconMenu); -} diff --git a/examples/desktop/systray/window.h b/examples/desktop/systray/window.h deleted file mode 100644 index 80b7a20754..0000000000 --- a/examples/desktop/systray/window.h +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** 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 WINDOW_H -#define WINDOW_H - -#include <QSystemTrayIcon> -#include <QDialog> - -QT_BEGIN_NAMESPACE -class QAction; -class QCheckBox; -class QComboBox; -class QGroupBox; -class QLabel; -class QLineEdit; -class QMenu; -class QPushButton; -class QSpinBox; -class QTextEdit; -QT_END_NAMESPACE - -//! [0] -class Window : public QDialog -{ - Q_OBJECT - -public: - Window(); - - void setVisible(bool visible); - -protected: - void closeEvent(QCloseEvent *event); - -private slots: - void setIcon(int index); - void iconActivated(QSystemTrayIcon::ActivationReason reason); - void showMessage(); - void messageClicked(); - -private: - void createIconGroupBox(); - void createMessageGroupBox(); - void createActions(); - void createTrayIcon(); - - QGroupBox *iconGroupBox; - QLabel *iconLabel; - QComboBox *iconComboBox; - QCheckBox *showIconCheckBox; - - QGroupBox *messageGroupBox; - QLabel *typeLabel; - QLabel *durationLabel; - QLabel *durationWarningLabel; - QLabel *titleLabel; - QLabel *bodyLabel; - QComboBox *typeComboBox; - QSpinBox *durationSpinBox; - QLineEdit *titleEdit; - QTextEdit *bodyEdit; - QPushButton *showMessageButton; - - QAction *minimizeAction; - QAction *maximizeAction; - QAction *restoreAction; - QAction *quitAction; - - QSystemTrayIcon *trayIcon; - QMenu *trayIconMenu; -}; -//! [0] - -#endif |