From f48bf0293a682aef90e6e5b16cf5a9a06b7a32d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Fri, 14 Feb 2020 16:26:32 +0100 Subject: Remove bearercloud example Bearer management is going away so this example cannot stay as it is Change-Id: I4d44158c95afc90f647741b99cf64ea18588cfb1 Reviewed-by: Timur Pocheptsov --- doc/src/examples/bearercloud.qdoc | 183 ----------- examples/svg/network/bearercloud/bearercloud.cpp | 212 ------------ examples/svg/network/bearercloud/bearercloud.h | 90 ------ examples/svg/network/bearercloud/bearercloud.pro | 19 -- examples/svg/network/bearercloud/bluetooth.svg | 24 -- examples/svg/network/bearercloud/cell.svg | 25 -- examples/svg/network/bearercloud/cloud.cpp | 390 ----------------------- examples/svg/network/bearercloud/cloud.h | 108 ------- examples/svg/network/bearercloud/gprs.svg | 199 ------------ examples/svg/network/bearercloud/icons.qrc | 11 - examples/svg/network/bearercloud/lan.svg | 33 -- examples/svg/network/bearercloud/main.cpp | 90 ------ examples/svg/network/bearercloud/umts.svg | 200 ------------ examples/svg/network/bearercloud/unknown.svg | 76 ----- examples/svg/network/bearercloud/wlan.svg | 151 --------- examples/svg/network/network.pro | 2 - examples/svg/svg.pro | 2 +- 17 files changed, 1 insertion(+), 1814 deletions(-) delete mode 100644 doc/src/examples/bearercloud.qdoc delete mode 100644 examples/svg/network/bearercloud/bearercloud.cpp delete mode 100644 examples/svg/network/bearercloud/bearercloud.h delete mode 100644 examples/svg/network/bearercloud/bearercloud.pro delete mode 100644 examples/svg/network/bearercloud/bluetooth.svg delete mode 100644 examples/svg/network/bearercloud/cell.svg delete mode 100644 examples/svg/network/bearercloud/cloud.cpp delete mode 100644 examples/svg/network/bearercloud/cloud.h delete mode 100644 examples/svg/network/bearercloud/gprs.svg delete mode 100644 examples/svg/network/bearercloud/icons.qrc delete mode 100644 examples/svg/network/bearercloud/lan.svg delete mode 100644 examples/svg/network/bearercloud/main.cpp delete mode 100644 examples/svg/network/bearercloud/umts.svg delete mode 100644 examples/svg/network/bearercloud/unknown.svg delete mode 100644 examples/svg/network/bearercloud/wlan.svg delete mode 100644 examples/svg/network/network.pro diff --git a/doc/src/examples/bearercloud.qdoc b/doc/src/examples/bearercloud.qdoc deleted file mode 100644 index e4a21f1..0000000 --- a/doc/src/examples/bearercloud.qdoc +++ /dev/null @@ -1,183 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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$ -** -****************************************************************************/ - -/*! - \example network/bearercloud - \title Bearer Cloud Example - - The Bearer Cloud example shows how to use the Bearer Management API to monitor the - connectivity state of the local device. - - \image bearercloud-example.png Screenshot of the Bearer Cloud example - - Bearer Management provides the QNetworkConfigurationManager class which can be used to monitor - changes in the available \l {QNetworkConfiguration}{network configurations} and the - QNetworkSession class which is used to \l {QNetworkSession::open()}{open} and - \l {QNetworkSession::close()}{close} a session bringing a network interface up or down if - necessary. - - This example displays all known \l {QNetworkConfiguration}{network configurations} in a cloud - orbiting the local device. There are four orbits representing the four possible - \l {QNetworkConfiguration::StateFlags}{states} that the network configuration can be in. - The closer the orbit the more useful the network configuration is in its current state. - The inner orbit is populated with network configurations that are in the - \l {QNetworkConfiguration::Active}{Active} state. The second orbit is populated with network - configurations that are in the \l {QNetworkConfiguration::Discovered}{Discovered} state. The - third orbit is populated with network configurations that are in the - \l {QNetworkConfiguration::Defined}{Defined} state. Finally the outer orbit is populated by - configurations that are in the \l {QNetworkConfiguration::Undefined}{Undefined} state. - - Hovering the mouse over a network configuration will display information about the network - configuration in a tool tip. - - Double clicking on an Active or Discovered network configuration will - \l {QNetworkSession::close()}{close} or \l {QNetworkSession::open()}{open} a network session, - respectively. - - Lastly you can reorganize the cloud without changing the state of the network configurations by - dragging them around. - - This example consists of two main classes, the BearerCloud and Cloud classes. The Cloud class - represents a single network session and associated network configuration. The BearerCloud - class implements a Graphics View scene and manages the life-cycle of Cloud - objects in response to notification signals from QNetworkConfigurationManager. - - \section1 Setting the Scene - - When constructing the scene we first calculate some random offsets using \l - QRandomGenerator. We will use these offsets to scatter the initial position - of new Cloud objects. - - Next we place a text item in the center of the scene to represent the local device and - surround it with four concentric circles to help visualize the orbits. - - Finally we connect up the network configuration notification signals and queue the initial - population of the scene during the next iteration of the event loop. - - \snippet examples/network/bearercloud/bearercloud.cpp 0 - - Populating the scene with the initial list of known network configuration is easy. Iterate - over the list returned by QNetworkConfigurationManager::allConfigurations(), calling our - configurationAdded() slot on each one. - - We finishing off by calling cloudMoved() to ensure that animations are started. - - \snippet examples/network/bearercloud/bearercloud.cpp 1 - - The configurationAdded() slot gets called when a new network configuration is added to the - system. - - It stores the \l {QNetworkConfiguration::identifier()}{identifier} of the network - configuration in the \e {configStates} map, which is used to keep a count of the number of - network configurations in each state. This in turn is used to calculate the initial position - of new Cloud objects. - - Next we create a new Cloud object for this network configuration. Set its initial position - and store it in the \e {configurations} hash. - - The last step is to add it to the scene by calling QGraphicsScene::addItem(). - - \snippet examples/network/bearercloud/bearercloud.cpp 2 - - The configurationRemoved() slot gets called when a network configuration is removed from the - system. - - First we remove all references to the network configuration from the \e {configStates} and - \e {configurations} member variables. - - Next we initiate animation by setting a final scale value on the Cloud object associated with - the removed network configuration. - - Finally we flag the Cloud object to delete itself after it has finished animating. - - \snippet examples/network/bearercloud/bearercloud.cpp 3 - - The Cloud object will take care of most of the work required when a network configuration - changes. All we do in the configurationChanged() slot is update the \e {configStates} member - variable. - - \snippet examples/network/bearercloud/bearercloud.cpp 4 - - - \section1 Responding to Changes - - Each network session and associated network configuration known to the system is represented in - the scene as a Cloud object. - - In the Cloud constructor we first initialize member variables. Then we create a new - QNetworkSession object bound to the network configuration. Next we connect the QNetworkSession - signals which we use to monitor it for state changes. - - Next we set some QGraphicsItem properties. The QGraphicsItem::ItemIsMovable flag enables mouse - interaction with the Cloud object. - - The Cloud object consists of an icon and a text caption, these are constructed here. We will - assign values to them later, as these will change as the sessions state changes. - - Next we set the initial animation state and call our newConfigurationActivated() slot to finish - setting up the Cloud object based on the state of network session. - - \snippet examples/network/bearercloud/cloud.cpp 0 - - The newConfigurationActivated() slot is called when a session has successfully roamed from one - access point to another. - - The first thing we do is set the icon, inserting it into a shared SVG renderer cache if it is - not already available. Next we set the text caption to the name of the network configuration. - - We then set the position of the icon and text caption so that they are centered horizontally. - - Finally we call our stateChanged() slot. - - \snippet examples/network/bearercloud/cloud.cpp 1 - - The stateChanged() slot is called when the session state changes. - - In this slot we set lower the opacity of Cloud objects with network sessions that cannot be - \l {QNetworkSession::open()}{opened}, and set a detailed tool tip describing the sessions - state. - - \snippet examples/network/bearercloud/cloud.cpp 2 - - In our reimplementation of the QGraphicsItem::mouseDoubleClickEvent() function we call - QNetworkSession::open() or QNetworkSession::close() to open or close the session in response - to a double left click. - - \snippet examples/network/bearercloud/cloud.cpp 3 - - As we support the user dragging Cloud objects around we need to restart animations when the - position of the Cloud object changes. This is accomplished by reimplementing the - QGraphicsItem::itemChanged() function and calling the cloudMoved() function of the BearerCloud - object. - - \snippet examples/network/bearercloud/cloud.cpp 4 - - The remainder of the code for the Cloud object implements the animations. The - calculateForces() function calculates the new position of the Cloud object based on the - position of all the other Cloud objects in the scene. The new position is set when the - advance() function is called to update the Cloud object for the current animation frame. -*/ diff --git a/examples/svg/network/bearercloud/bearercloud.cpp b/examples/svg/network/bearercloud/bearercloud.cpp deleted file mode 100644 index 0f08aec..0000000 --- a/examples/svg/network/bearercloud/bearercloud.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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$ -** -****************************************************************************/ - -#include "bearercloud.h" -#include "cloud.h" - -#include -#include -#include -#include - -#include - -#include - -//! [0] -BearerCloud::BearerCloud(QObject *parent) -: QGraphicsScene(parent), timerId(0) -{ - setSceneRect(-300, -300, 600, 600); - - - offset[QNetworkConfiguration::Active] = QRandomGenerator::global()->bounded(2 * M_PI); - offset[QNetworkConfiguration::Discovered] = offset[QNetworkConfiguration::Active] + M_PI / 6; - offset[QNetworkConfiguration::Defined] = offset[QNetworkConfiguration::Discovered] - M_PI / 6; - offset[QNetworkConfiguration::Undefined] = offset[QNetworkConfiguration::Undefined] + M_PI / 6; - - thisDevice = new QGraphicsTextItem(QHostInfo::localHostName()); - thisDevice->setData(0, QLatin1String("This Device")); - thisDevice->setPos(thisDevice->boundingRect().width() / -2, - thisDevice->boundingRect().height() / -2); - addItem(thisDevice); - - qreal radius = Cloud::getRadiusForState(QNetworkConfiguration::Active); - QGraphicsEllipseItem *orbit = new QGraphicsEllipseItem(-radius, -radius, 2*radius, 2*radius); - orbit->setPen(QColor(Qt::green)); - addItem(orbit); - radius = Cloud::getRadiusForState(QNetworkConfiguration::Discovered); - orbit = new QGraphicsEllipseItem(-radius, -radius, 2*radius, 2*radius); - orbit->setPen(QColor(Qt::blue)); - addItem(orbit); - radius = Cloud::getRadiusForState(QNetworkConfiguration::Defined); - orbit = new QGraphicsEllipseItem(-radius, -radius, 2*radius, 2*radius); - orbit->setPen(QColor(Qt::darkGray)); - addItem(orbit); - radius = Cloud::getRadiusForState(QNetworkConfiguration::Undefined); - orbit = new QGraphicsEllipseItem(-radius, -radius, 2*radius, 2*radius); - orbit->setPen(QColor(Qt::lightGray)); - addItem(orbit); - - connect(&manager, SIGNAL(configurationAdded(QNetworkConfiguration)), - this, SLOT(configurationAdded(QNetworkConfiguration))); - connect(&manager, SIGNAL(configurationRemoved(QNetworkConfiguration)), - this, SLOT(configurationRemoved(QNetworkConfiguration))); - connect(&manager, SIGNAL(configurationChanged(QNetworkConfiguration)), - this, SLOT(configurationChanged(QNetworkConfiguration))); - - QTimer::singleShot(0, this, SLOT(updateConfigurations())); -} -//! [0] - -BearerCloud::~BearerCloud() -{ -} - -void BearerCloud::cloudMoved() -{ - if (!timerId) - timerId = startTimer(1000 / 25); -} - -void BearerCloud::timerEvent(QTimerEvent *) -{ - std::vector clouds; - const auto graphicsItems = items(); - clouds.reserve(graphicsItems.size()); - for (QGraphicsItem *item : graphicsItems) { - if (Cloud *cloud = qgraphicsitem_cast(item)) - clouds.push_back(cloud); - } - - for (Cloud *cloud : clouds) - cloud->calculateForces(); - - bool cloudsMoved = false; - for (Cloud *cloud : clouds) - cloudsMoved |= cloud->advanceAnimation(); - - if (!cloudsMoved) { - killTimer(timerId); - timerId = 0; - } -} - -//! [2] -void BearerCloud::configurationAdded(const QNetworkConfiguration &config) -{ - const QNetworkConfiguration::StateFlags state = config.state(); - - configStates.insert(state, config.identifier()); - - const qreal radius = Cloud::getRadiusForState(state); - const int count = configStates.count(state); - const qreal angle = 2 * M_PI / count; - - Cloud *item = new Cloud(config); - configurations.insert(config.identifier(), item); - - item->setPos(radius * cos((count-1) * angle + offset[state]), - radius * sin((count-1) * angle + offset[state])); - - addItem(item); - - cloudMoved(); -} -//! [2] - -//! [3] -void BearerCloud::configurationRemoved(const QNetworkConfiguration &config) -{ - const auto id = config.identifier(); - for (auto it = configStates.begin(), end = configStates.end(); it != end; /* erasing */) { - if (it.value() == id) - it = configStates.erase(it); - else - ++it; - } - - Cloud *item = configurations.take(config.identifier()); - - item->setFinalScale(0.0); - item->setDeleteAfterAnimation(true); - - cloudMoved(); -} -//! [3] - -//! [4] -void BearerCloud::configurationChanged(const QNetworkConfiguration &config) -{ - const auto id = config.identifier(); - for (auto it = configStates.begin(), end = configStates.end(); it != end; /* erasing */) { - if (it.value() == id) - it = configStates.erase(it); - else - ++it; - } - - configStates.insert(config.state(), id); - - cloudMoved(); -} -//! [4] - -//! [1] -void BearerCloud::updateConfigurations() -{ - const auto allConfigurations = manager.allConfigurations(); - for (const QNetworkConfiguration &config : allConfigurations) - configurationAdded(config); - - cloudMoved(); -} -//! [1] - diff --git a/examples/svg/network/bearercloud/bearercloud.h b/examples/svg/network/bearercloud/bearercloud.h deleted file mode 100644 index a9923ad..0000000 --- a/examples/svg/network/bearercloud/bearercloud.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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$ -** -****************************************************************************/ - -#include - -#include -#include -#include - -QT_USE_NAMESPACE - -class Cloud; - -class BearerCloud : public QGraphicsScene -{ - Q_OBJECT - -public: - BearerCloud(QObject *parent = 0); - ~BearerCloud(); - - void cloudMoved(); - - void timerEvent(QTimerEvent *event) override; - -private Q_SLOTS: - void configurationAdded(const QNetworkConfiguration &config); - void configurationRemoved(const QNetworkConfiguration &config); - void configurationChanged(const QNetworkConfiguration &config); - void updateConfigurations(); - -private: - QNetworkConfigurationManager manager; - - QGraphicsTextItem *thisDevice; - QHash configurations; - - QMap offset; - QMultiMap configStates; - - int timerId; -}; - diff --git a/examples/svg/network/bearercloud/bearercloud.pro b/examples/svg/network/bearercloud/bearercloud.pro deleted file mode 100644 index f69780b..0000000 --- a/examples/svg/network/bearercloud/bearercloud.pro +++ /dev/null @@ -1,19 +0,0 @@ -HEADERS = bearercloud.h \ - cloud.h - -SOURCES = main.cpp \ - bearercloud.cpp \ - cloud.cpp - -RESOURCES = icons.qrc - -TARGET = bearercloud - -QT = core gui widgets network svg -requires(qtConfig(bearermanagement)) - -CONFIG += console - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/svg/network/bearercloud -INSTALLS += target diff --git a/examples/svg/network/bearercloud/bluetooth.svg b/examples/svg/network/bearercloud/bluetooth.svg deleted file mode 100644 index 32e2fa3..0000000 --- a/examples/svg/network/bearercloud/bluetooth.svg +++ /dev/null @@ -1,24 +0,0 @@ - - - - -]> - - - - - - - - - - - - - - diff --git a/examples/svg/network/bearercloud/cell.svg b/examples/svg/network/bearercloud/cell.svg deleted file mode 100644 index 7519868..0000000 --- a/examples/svg/network/bearercloud/cell.svg +++ /dev/null @@ -1,25 +0,0 @@ - - - - -]> - - - - - - - - - - - - - - - - - - diff --git a/examples/svg/network/bearercloud/cloud.cpp b/examples/svg/network/bearercloud/cloud.cpp deleted file mode 100644 index 1117c94..0000000 --- a/examples/svg/network/bearercloud/cloud.cpp +++ /dev/null @@ -1,390 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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$ -** -****************************************************************************/ - -#include "cloud.h" -#include "bearercloud.h" - -#include - -#include -#include -#include -#include -#include - -#include - -#include - -static QMap svgCache; - -//! [0] -Cloud::Cloud(const QNetworkConfiguration &config, QGraphicsItem *parent) -: QGraphicsItem(parent), configuration(config), deleteAfterAnimation(false) -{ - session = new QNetworkSession(configuration, this); - connect(session, SIGNAL(newConfigurationActivated()), - this, SLOT(newConfigurationActivated())); - connect(session, SIGNAL(stateChanged(QNetworkSession::State)), - this, SLOT(stateChanged(QNetworkSession::State))); - - setFlag(ItemIsMovable); - setFlag(ItemSendsGeometryChanges); - setZValue(1); - - icon = new QGraphicsSvgItem(this); - text = new QGraphicsTextItem(this); - - currentScale = 0; - finalScale = 1; - setTransform(QTransform::fromScale(currentScale, currentScale), false); - setOpacity(0); - - newConfigurationActivated(); -} -//! [0] - -Cloud::~Cloud() -{ -} - -void Cloud::setFinalScale(qreal factor) -{ - finalScale = factor; -} - -void Cloud::setDeleteAfterAnimation(bool deleteAfter) -{ - deleteAfterAnimation = deleteAfter; -} - -void Cloud::calculateForces() -{ - if (!scene() || scene()->mouseGrabberItem() == this) { - newPos = pos(); - return; - } - - // sum up all the forces push this item away - qreal xvel = 0; - qreal yvel = 0; - QLineF orbitForce; - const auto graphicsItems = scene()->items(); - for (QGraphicsItem *item : graphicsItems) { - // other clouds - Cloud *cloud = qgraphicsitem_cast(item); - if (!cloud && item->data(0) != QLatin1String("This Device")) - continue; - - qreal factor = 1.0; - - QLineF line(cloud ? item->mapToScene(0, 0) : QPointF(0, 0), mapToScene(0, 0)); - if (item->data(0) == QLatin1String("This Device")) - orbitForce = line; - - if (cloud) - factor = cloud->currentScale; - - qreal dx = line.dx(); - qreal dy = line.dy(); - double l = 2.0 * (dx * dx + dy * dy); - if (l > 0) { - xvel += factor * dx * 200.0 / l; - yvel += factor * dy * 200.0 / l; - } - } - - // tendency to stay at a fixed orbit - qreal orbit = getRadiusForState(configuration.state()); - qreal distance = orbitForce.length(); - - QLineF unit = orbitForce.unitVector(); - - orbitForce.setLength(xvel * unit.dx() + yvel * unit.dy()); - - qreal w = 2 - exp(-pow(distance-orbit, 2)/(2 * 50)); - - if (distance < orbit) { - xvel += orbitForce.dx() * w; - yvel += orbitForce.dy() * w; - } else { - xvel -= orbitForce.dx() * w; - yvel -= orbitForce.dy() * w; - } - - if (qAbs(xvel) < 0.1 && qAbs(yvel) < 0.1) - xvel = yvel = 0; - - QRectF sceneRect = scene()->sceneRect(); - newPos = pos() + QPointF(xvel, yvel); - newPos.setX(qMin(qMax(newPos.x(), sceneRect.left() + 10), sceneRect.right() - 10)); - newPos.setY(qMin(qMax(newPos.y(), sceneRect.top() + 10), sceneRect.bottom() - 10)); -} - -bool Cloud::advanceAnimation() -{ - static const qreal scaleDelta = 0.01; - - bool animated = false; - - if (currentScale < finalScale) { - animated = true; - currentScale = qMin(currentScale + scaleDelta, finalScale); - setTransform(QTransform::fromScale(currentScale, currentScale), false); - } else if (currentScale > finalScale) { - animated = true; - currentScale = qMax(currentScale - scaleDelta, finalScale); - setTransform(QTransform::fromScale(currentScale, currentScale), false); - } - - if (newPos != pos()) { - setPos(newPos); - animated = true; - } - - if (opacity() != finalOpacity) { - animated = true; - if (qAbs(finalScale - currentScale) > 0.0) { - // use scale as reference - setOpacity(opacity() + scaleDelta * (finalOpacity - opacity()) / - qAbs(finalScale - currentScale)); - } else { - setOpacity(finalOpacity); - } - } - - if (!animated && deleteAfterAnimation) - deleteLater(); - - return animated; -} - -QRectF Cloud::boundingRect() const -{ - return childrenBoundingRect(); -} - -void Cloud::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) -{ -} - -//! [4] -QVariant Cloud::itemChange(GraphicsItemChange change, const QVariant &value) -{ - switch (change) { - case ItemPositionHasChanged: - if (BearerCloud *bearercloud = qobject_cast(scene())) - bearercloud->cloudMoved(); - default: - ; - }; - - return QGraphicsItem::itemChange(change, value); -} -//! [4] - -//! [3] -void Cloud::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) -{ - if (event->button() == Qt::LeftButton) { - if (session->isOpen()) - session->close(); - else - session->open(); - - event->accept(); - } -} -//! [3] - -//! [2] -void Cloud::stateChanged(QNetworkSession::State state) -{ - if (configuration.name().isEmpty()) - finalOpacity = qreal(0.1); - else if (session->state() == QNetworkSession::NotAvailable) - finalOpacity = 0.5; - else - finalOpacity = 1.0; - - QString tooltip; - - if (configuration.name().isEmpty()) - tooltip += tr("HIDDEN NETWORK
"); - else - tooltip += tr("%1
").arg(configuration.name()); - -#ifndef QT_NO_NETWORKINTERFACE - const QNetworkInterface interface = session->interface(); - if (interface.isValid()) - tooltip += tr("
Interface: %1").arg(interface.humanReadableName()); - tooltip += tr("
Id: %1").arg(configuration.identifier()); -#endif - - const QString bearerTypeName = configuration.bearerTypeName(); - if (!bearerTypeName.isEmpty()) - tooltip += tr("
Bearer: %1").arg(bearerTypeName); - - QString s = tr("
State: %1 (%2)"); - switch (state) { - case QNetworkSession::Invalid: - s = s.arg(tr("Invalid")); - break; - case QNetworkSession::NotAvailable: - s = s.arg(tr("Not Available")); - break; - case QNetworkSession::Connecting: - s = s.arg(tr("Connecting")); - break; - case QNetworkSession::Connected: - s = s.arg(tr("Connected")); - break; - case QNetworkSession::Closing: - s = s.arg(tr("Closing")); - break; - case QNetworkSession::Disconnected: - s = s.arg(tr("Disconnected")); - break; - case QNetworkSession::Roaming: - s = s.arg(tr("Roaming")); - break; - default: - s = s.arg(tr("Unknown")); - } - - if (session->isOpen()) - s = s.arg(tr("Open")); - else - s = s.arg(tr("Closed")); - - tooltip += s; - - tooltip += tr("

Active time: %1 seconds").arg(session->activeTime()); - tooltip += tr("
Received data: %1 bytes").arg(session->bytesReceived()); - tooltip += tr("
Sent data: %1 bytes").arg(session->bytesWritten()); - - setToolTip(tooltip); -} -//! [2] - -//! [1] -void Cloud::newConfigurationActivated() -{ - QNetworkConfiguration::BearerType bearerType = configuration.bearerType(); - if (!svgCache.contains(bearerType)) { - QSvgRenderer *renderer = 0; - switch (bearerType) { - case QNetworkConfiguration::BearerWLAN: - renderer = new QSvgRenderer(QLatin1String(":wlan.svg")); - break; - case QNetworkConfiguration::BearerEthernet: - renderer = new QSvgRenderer(QLatin1String(":lan.svg")); - break; - case QNetworkConfiguration::Bearer2G: - renderer = new QSvgRenderer(QLatin1String(":cell.svg")); - break; - case QNetworkConfiguration::BearerBluetooth: - renderer = new QSvgRenderer(QLatin1String(":bluetooth.svg")); - break; - case QNetworkConfiguration::BearerCDMA2000: - case QNetworkConfiguration::BearerWCDMA: - case QNetworkConfiguration::BearerHSPA: - renderer = new QSvgRenderer(QLatin1String(":umts.svg")); - break; - default: - renderer = new QSvgRenderer(QLatin1String(":unknown.svg")); - } - - if (renderer) - svgCache.insert(bearerType, renderer); - } - - icon->setSharedRenderer(svgCache[bearerType]); - - if (configuration.name().isEmpty()) { - text->setPlainText(tr("HIDDEN NETWORK")); - } else { - if (configuration.type() == QNetworkConfiguration::ServiceNetwork) - text->setHtml("" + configuration.name() + ""); - else - text->setPlainText(configuration.name()); - } - - const qreal height = icon->boundingRect().height() + text->boundingRect().height(); - - icon->setPos(icon->boundingRect().width() / -2, height / -2); - - text->setPos(text->boundingRect().width() / -2, - height / 2 - text->boundingRect().height()); - - stateChanged(session->state()); -} -//! [1] - -qreal Cloud::getRadiusForState(QNetworkConfiguration::StateFlags state) -{ - switch (state) { - case QNetworkConfiguration::Active: - return 100; - break; - case QNetworkConfiguration::Discovered: - return 150; - break; - case QNetworkConfiguration::Defined: - return 200; - break; - case QNetworkConfiguration::Undefined: - return 250; - break; - default: - return 300; - } -} - diff --git a/examples/svg/network/bearercloud/cloud.h b/examples/svg/network/bearercloud/cloud.h deleted file mode 100644 index a91b994..0000000 --- a/examples/svg/network/bearercloud/cloud.h +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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$ -** -****************************************************************************/ - -#include -#include - -#include -QT_USE_NAMESPACE - -QT_BEGIN_NAMESPACE -class QGraphicsTextItem; -class QGraphicsSvgItem; -QT_END_NAMESPACE - -class Cloud : public QObject, public QGraphicsItem -{ - Q_OBJECT - Q_INTERFACES(QGraphicsItem) - -public: - explicit Cloud(const QNetworkConfiguration &config, QGraphicsItem *parent = 0); - ~Cloud(); - - enum { Type = UserType + 1 }; - int type() const override { return Type; } - - void setFinalScale(qreal factor); - void setDeleteAfterAnimation(bool deleteAfter); - - void calculateForces(); - - bool advanceAnimation(); - QRectF boundingRect() const override; - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override; - - static qreal getRadiusForState(QNetworkConfiguration::StateFlags state); - -protected: - QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override; - -private Q_SLOTS: - void stateChanged(QNetworkSession::State state); - void newConfigurationActivated(); - -private: - QNetworkConfiguration configuration; - QNetworkSession *session; - - QGraphicsTextItem *text; - QGraphicsSvgItem *icon; - - qreal finalOpacity; - qreal finalScale; - qreal currentScale; - - QPointF newPos; - - bool deleteAfterAnimation; -}; - diff --git a/examples/svg/network/bearercloud/gprs.svg b/examples/svg/network/bearercloud/gprs.svg deleted file mode 100644 index 4a992c1..0000000 --- a/examples/svg/network/bearercloud/gprs.svg +++ /dev/null @@ -1,199 +0,0 @@ - - -image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/svg/network/bearercloud/icons.qrc b/examples/svg/network/bearercloud/icons.qrc deleted file mode 100644 index 7dea1f2..0000000 --- a/examples/svg/network/bearercloud/icons.qrc +++ /dev/null @@ -1,11 +0,0 @@ - - - wlan.svg - lan.svg - unknown.svg - bluetooth.svg - cell.svg - gprs.svg - umts.svg - - diff --git a/examples/svg/network/bearercloud/lan.svg b/examples/svg/network/bearercloud/lan.svg deleted file mode 100644 index 4f7f63d..0000000 --- a/examples/svg/network/bearercloud/lan.svg +++ /dev/null @@ -1,33 +0,0 @@ - - - - -]> - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/svg/network/bearercloud/main.cpp b/examples/svg/network/bearercloud/main.cpp deleted file mode 100644 index 33371ce..0000000 --- a/examples/svg/network/bearercloud/main.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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$ -** -****************************************************************************/ - -#include "bearercloud.h" - -#include -#include - -class CloudView : public QGraphicsView -{ - Q_OBJECT - -public: - CloudView(QGraphicsScene *scene); - ~CloudView() { } - -protected: - void resizeEvent(QResizeEvent *) override { - fitInView(sceneRect(), Qt::KeepAspectRatio); - } -}; - -CloudView::CloudView(QGraphicsScene *scene) -: QGraphicsView(scene) -{ - setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing | - QPainter::SmoothPixmapTransform); -} - -#include "main.moc" - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - BearerCloud bearerCloud; - - CloudView view(&bearerCloud); - view.show(); - - return app.exec(); -} - diff --git a/examples/svg/network/bearercloud/umts.svg b/examples/svg/network/bearercloud/umts.svg deleted file mode 100644 index c1b372e..0000000 --- a/examples/svg/network/bearercloud/umts.svg +++ /dev/null @@ -1,200 +0,0 @@ - - -image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/examples/svg/network/bearercloud/unknown.svg b/examples/svg/network/bearercloud/unknown.svg deleted file mode 100644 index fd10298..0000000 --- a/examples/svg/network/bearercloud/unknown.svg +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - - - - - - image/svg+xml - - - - - - NET - - diff --git a/examples/svg/network/bearercloud/wlan.svg b/examples/svg/network/bearercloud/wlan.svg deleted file mode 100644 index 8b86089..0000000 --- a/examples/svg/network/bearercloud/wlan.svg +++ /dev/null @@ -1,151 +0,0 @@ - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - diff --git a/examples/svg/network/network.pro b/examples/svg/network/network.pro deleted file mode 100644 index 4f5c4cf..0000000 --- a/examples/svg/network/network.pro +++ /dev/null @@ -1,2 +0,0 @@ -TEMPLATE = subdirs -qtHaveModule(widgets):qtHaveModule(network): SUBDIRS += bearercloud diff --git a/examples/svg/svg.pro b/examples/svg/svg.pro index 410415b..8aa4c4e 100644 --- a/examples/svg/svg.pro +++ b/examples/svg/svg.pro @@ -1,6 +1,6 @@ TEMPLATE = subdirs qtHaveModule(widgets): SUBDIRS += embeddedsvgviewer svggenerator svgviewer -SUBDIRS += embedded richtext draganddrop network +SUBDIRS += embedded richtext draganddrop qtHaveModule(opengl):!qtConfig(opengles2): SUBDIRS += opengl -- cgit v1.2.1