diff options
Diffstat (limited to 'examples/widgets/desktop/systray')
-rw-r--r-- | examples/widgets/desktop/systray/CMakeLists.txt | 45 | ||||
-rw-r--r-- | examples/widgets/desktop/systray/doc/images/systemtray-editor.png | bin | 25407 -> 16137 bytes | |||
-rw-r--r-- | examples/widgets/desktop/systray/doc/images/systemtray-example.png | bin | 47588 -> 49858 bytes | |||
-rw-r--r-- | examples/widgets/desktop/systray/doc/src/systray.qdoc | 37 | ||||
-rw-r--r-- | examples/widgets/desktop/systray/images/bad.png | bin | 2496 -> 2101 bytes | |||
-rw-r--r-- | examples/widgets/desktop/systray/images/heart.png | bin | 25780 -> 1834 bytes | |||
-rw-r--r-- | examples/widgets/desktop/systray/images/trash.png | bin | 12128 -> 1285 bytes | |||
-rw-r--r-- | examples/widgets/desktop/systray/main.cpp | 53 | ||||
-rw-r--r-- | examples/widgets/desktop/systray/window.cpp | 56 | ||||
-rw-r--r-- | examples/widgets/desktop/systray/window.h | 51 |
10 files changed, 35 insertions, 207 deletions
diff --git a/examples/widgets/desktop/systray/CMakeLists.txt b/examples/widgets/desktop/systray/CMakeLists.txt index f52a523ad4..c42469bf59 100644 --- a/examples/widgets/desktop/systray/CMakeLists.txt +++ b/examples/widgets/desktop/systray/CMakeLists.txt @@ -1,38 +1,28 @@ -# Generated from systray.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause cmake_minimum_required(VERSION 3.16) project(systray LANGUAGES CXX) -set(CMAKE_INCLUDE_CURRENT_DIR ON) +find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/desktop/systray") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) +qt_standard_project_setup() qt_add_executable(systray main.cpp window.cpp window.h ) + set_target_properties(systray PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) -target_link_libraries(systray PUBLIC - Qt::Core - Qt::Gui - Qt::Widgets -) +target_link_libraries(systray PRIVATE + Qt6::Core + Qt6::Gui + Qt6::Widgets +) # Resources: set(systray_resource_files @@ -41,7 +31,7 @@ set(systray_resource_files "images/trash.png" ) -qt6_add_resources(systray "systray" +qt_add_resources(systray "systray" PREFIX "/" FILES @@ -49,7 +39,14 @@ qt6_add_resources(systray "systray" ) install(TARGETS systray - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" + BUNDLE DESTINATION . + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) + +qt_generate_deploy_app_script( + TARGET systray + OUTPUT_SCRIPT deploy_script + NO_UNSUPPORTED_PLATFORM_ERROR ) +install(SCRIPT ${deploy_script}) diff --git a/examples/widgets/desktop/systray/doc/images/systemtray-editor.png b/examples/widgets/desktop/systray/doc/images/systemtray-editor.png Binary files differindex f7c23db28a..5537c09fde 100644 --- a/examples/widgets/desktop/systray/doc/images/systemtray-editor.png +++ b/examples/widgets/desktop/systray/doc/images/systemtray-editor.png diff --git a/examples/widgets/desktop/systray/doc/images/systemtray-example.png b/examples/widgets/desktop/systray/doc/images/systemtray-example.png Binary files differindex 98b5c8133e..f2f9f73031 100644 --- a/examples/widgets/desktop/systray/doc/images/systemtray-example.png +++ b/examples/widgets/desktop/systray/doc/images/systemtray-example.png diff --git a/examples/widgets/desktop/systray/doc/src/systray.qdoc b/examples/widgets/desktop/systray/doc/src/systray.qdoc index ae7e925bd8..b0dff58e31 100644 --- a/examples/widgets/desktop/systray/doc/src/systray.qdoc +++ b/examples/widgets/desktop/systray/doc/src/systray.qdoc @@ -1,33 +1,10 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! \example desktop/systray \title System Tray Icon Example + \examplecategory {Desktop} \ingroup examples-widgets \brief The System Tray Icon example shows how to add an icon with a menu and popup messages to a desktop environment's system tray. @@ -173,11 +150,11 @@ We have reimplemented the QWidget::closeEvent() event handler to receive widget close events, showing the above message to the - users when they are closing the editor window. On \macos we need to + users when they are closing the editor window. We need to avoid showing the message and accepting the close event when the - user really intends to quit the application, that is, when the - user has triggered "Quit" in the menu bar or pressed the Command+Q - shortcut. + user really intends to quit the application: that is, when the + user has triggered "Quit" in the menu bar, or in the tray icon's + context menu, or pressed Command+Q shortcut on \macOS. In addition to the functions and slots discussed above, we have also implemented several convenience functions to simplify the diff --git a/examples/widgets/desktop/systray/images/bad.png b/examples/widgets/desktop/systray/images/bad.png Binary files differindex c8701a241a..b09de85869 100644 --- a/examples/widgets/desktop/systray/images/bad.png +++ b/examples/widgets/desktop/systray/images/bad.png diff --git a/examples/widgets/desktop/systray/images/heart.png b/examples/widgets/desktop/systray/images/heart.png Binary files differindex cee1302b7d..5d466b1b89 100644 --- a/examples/widgets/desktop/systray/images/heart.png +++ b/examples/widgets/desktop/systray/images/heart.png diff --git a/examples/widgets/desktop/systray/images/trash.png b/examples/widgets/desktop/systray/images/trash.png Binary files differindex 4c24db926d..454074f9f2 100644 --- a/examples/widgets/desktop/systray/images/trash.png +++ b/examples/widgets/desktop/systray/images/trash.png diff --git a/examples/widgets/desktop/systray/main.cpp b/examples/widgets/desktop/systray/main.cpp index 4e3e628767..d13bde11ce 100644 --- a/examples/widgets/desktop/systray/main.cpp +++ b/examples/widgets/desktop/systray/main.cpp @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include <QApplication> @@ -57,8 +10,6 @@ int main(int argc, char *argv[]) { - Q_INIT_RESOURCE(systray); - QApplication app(argc, argv); if (!QSystemTrayIcon::isSystemTrayAvailable()) { diff --git a/examples/widgets/desktop/systray/window.cpp b/examples/widgets/desktop/systray/window.cpp index e62b5fc0d0..c5632759b0 100644 --- a/examples/widgets/desktop/systray/window.cpp +++ b/examples/widgets/desktop/systray/window.cpp @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "window.h" @@ -111,11 +64,8 @@ void Window::setVisible(bool visible) //! [2] void Window::closeEvent(QCloseEvent *event) { -#ifdef Q_OS_MACOS - if (!event->spontaneous() || !isVisible()) { + if (!event->spontaneous() || !isVisible()) return; - } -#endif if (trayIcon->isVisible()) { QMessageBox::information(this, tr("Systray"), tr("The program will keep running in the " diff --git a/examples/widgets/desktop/systray/window.h b/examples/widgets/desktop/systray/window.h index 001338df0c..69978b1ba2 100644 --- a/examples/widgets/desktop/systray/window.h +++ b/examples/widgets/desktop/systray/window.h @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #ifndef WINDOW_H #define WINDOW_H |