diff --git a/trikGui/backgroundWidget.cpp b/trikGui/backgroundWidget.cpp index 6d97cf239..00d575f8e 100644 --- a/trikGui/backgroundWidget.cpp +++ b/trikGui/backgroundWidget.cpp @@ -32,6 +32,7 @@ BackgroundWidget::BackgroundWidget( , mController(configPath) , mBatteryIndicator(mController.brick()) , mWiFiIndicator(mController) + , mGamepadIndicator(mController) , mMailboxIndicator("://resources/mailboxConnected.png", mController.mailbox()->isConnected()) , mCommunicatorIndicator("://resources/communicatorConnected.png", mController.communicatorConnectionStatus()) , mStartWidget(mController) @@ -47,6 +48,7 @@ BackgroundWidget::BackgroundWidget( mStatusBarLayout.addWidget(&mBatteryIndicator); mStatusBarLayout.addStretch(); + mStatusBarLayout.addWidget(&mGamepadIndicator); mStatusBarLayout.addWidget(&mMailboxIndicator); mStatusBarLayout.addWidget(&mCommunicatorIndicator); mStatusBarLayout.addWidget(&mWiFiIndicator); diff --git a/trikGui/backgroundWidget.h b/trikGui/backgroundWidget.h index 28ab44ada..5a91b1e71 100644 --- a/trikGui/backgroundWidget.h +++ b/trikGui/backgroundWidget.h @@ -35,6 +35,7 @@ #include "controller.h" #include "batteryIndicator.h" #include "wiFiIndicator.h" +#include "gamepadIndicator.h" #include "openSocketIndicator.h" #include "startWidget.h" #include "runningWidget.h" @@ -114,6 +115,7 @@ private slots: QStackedLayout mMainWidgetsLayout; BatteryIndicator mBatteryIndicator; WiFiIndicator mWiFiIndicator; + GamepadIndicator mGamepadIndicator; OpenSocketIndicator mMailboxIndicator; OpenSocketIndicator mCommunicatorIndicator; StartWidget mStartWidget; diff --git a/trikGui/controller.cpp b/trikGui/controller.cpp index 28f3a262f..750e7e93d 100644 --- a/trikGui/controller.cpp +++ b/trikGui/controller.cpp @@ -49,6 +49,9 @@ Controller::Controller(const QString &configPath) , correctedConfigPath + "model-config.xml"); mGamepad.reset(trikNetwork::GamepadFactory::create(configurer)); + connect(mGamepad.data(), SIGNAL(disconnect()), this, SIGNAL(gamepadDisconnected())); + connect(mGamepad.data(), SIGNAL(connected()), this, SIGNAL(gamepadConnected())); + mMailbox.reset(trikNetwork::MailboxFactory::create(configurer)); mTelemetry.reset(new trikTelemetry::TrikTelemetry(*mBrick, *mGamepad)); mScriptRunner.reset(new trikScriptRunner::TrikScriptRunner(*mBrick, mMailbox.data(), mGamepad.data())); @@ -136,6 +139,15 @@ bool Controller::communicatorConnectionStatus() return mTelemetry->activeConnections() > 0 && mCommunicator->activeConnections() > 0; } +bool Controller::gamepadConnectionStatus() const +{ + if (mGamepad != nullptr) { + return mGamepad->isConnected(); + } else { + return false; + } +} + void Controller::updateCommunicatorStatus() { emit communicatorStatusChanged(communicatorConnectionStatus()); diff --git a/trikGui/controller.h b/trikGui/controller.h index b889dade2..9e034272d 100644 --- a/trikGui/controller.h +++ b/trikGui/controller.h @@ -67,6 +67,9 @@ class Controller : public QObject /// Returns communicator connection status (whether or not both Telemetry and Communicator servers are connected). bool communicatorConnectionStatus(); + /// Returns gamepad connection status. + bool gamepadConnectionStatus() const; + public slots: /// Cancels execution of current program. void abortExecution(); @@ -91,6 +94,12 @@ public slots: /// clutter from videosensors. void brickStopped(); + /// Emitted when a robot is disconnected from a gamepad. + void gamepadDisconnected(); + + /// Emitted when a robot is connected to a gamepad. + void gamepadConnected(); + /// Emitted when a robot is connected to a network. void wiFiConnected(); diff --git a/trikGui/gamepadIndicator.cpp b/trikGui/gamepadIndicator.cpp new file mode 100644 index 000000000..d69dfa8a9 --- /dev/null +++ b/trikGui/gamepadIndicator.cpp @@ -0,0 +1,54 @@ +/* Copyright 2016 Anna Kudryashova + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + +#include "gamepadIndicator.h" + +#include "trikKernel/paths.h" + +using namespace trikGui; + +GamepadIndicator::GamepadIndicator(Controller &controller, QWidget *parent) + : QLabel(parent) + , mController(controller) +{ + connect(&mController, SIGNAL(gamepadDisconnected()), this, SLOT(setOff())); + connect(&mController, SIGNAL(gamepadConnected()), this, SLOT(setOn())); + + updateStatus(); + connect(&mUpdateTimer, SIGNAL(timeout()), this, SLOT(updateStatus())); + mUpdateTimer.start(7000); +} + +void GamepadIndicator::setOn() +{ + QPixmap icon("://resources/gamepad_on.png"); + setPixmap(icon); + show(); +} + +void GamepadIndicator::setOff() +{ + hide(); +} + +void GamepadIndicator::connected(bool connected) +{ + connected ? setOn() : setOff(); +} + +void GamepadIndicator::updateStatus() +{ + connected(mController.gamepadConnectionStatus()); +} + diff --git a/trikGui/gamepadIndicator.h b/trikGui/gamepadIndicator.h new file mode 100644 index 000000000..4d28894f6 --- /dev/null +++ b/trikGui/gamepadIndicator.h @@ -0,0 +1,56 @@ +/* Copyright 2016 Anna Kudryashova + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + +#pragma once + +#include + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + #include +#else + #include +#endif + +#include +#include + +namespace trikGui { + +/// A label that shows gamepad connection status. +class GamepadIndicator : public QLabel +{ + Q_OBJECT +public: + /// @param controller is used to get the current gamepad info + explicit GamepadIndicator(Controller &controller, QWidget *parent = 0); + +public slots: + /// Updates the status to 'connect'. + void setOn(); + + /// Updates the status to 'disconnect'. + void setOff(); + + /// Requests connection info from the controller and updates the status. + void updateStatus(); + + /// Updates the status according to connected parameters. + void connected(bool connected); + +private: + QTimer mUpdateTimer; + Controller &mController; +}; + +} diff --git a/trikGui/resources/gamepad_off.png b/trikGui/resources/gamepad_off.png new file mode 100644 index 000000000..02dcc1be2 Binary files /dev/null and b/trikGui/resources/gamepad_off.png differ diff --git a/trikGui/resources/gamepad_on.png b/trikGui/resources/gamepad_on.png new file mode 100644 index 000000000..833045695 Binary files /dev/null and b/trikGui/resources/gamepad_on.png differ diff --git a/trikGui/trikGui.pro b/trikGui/trikGui.pro index 9f25f0d80..e423c7479 100644 --- a/trikGui/trikGui.pro +++ b/trikGui/trikGui.pro @@ -1,4 +1,4 @@ -# Copyright 2013 Yurii Litvinov +# Copyright 2013 - 2016 Yurii Litvinov, Mikhail Kita, Anna Kudryashova # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -55,6 +55,7 @@ HEADERS += \ $$PWD/sensorSettingsWidget.h \ $$PWD/sensorLever.h \ $$PWD/scriptHolder.h \ + $$PWD/gamepadIndicator.h \ SOURCES += \ $$PWD/autoRunner.cpp \ @@ -95,6 +96,7 @@ SOURCES += \ $$PWD/sensorSettingsWidget.cpp \ $$PWD/sensorLever.cpp \ $$PWD/scriptHolder.cpp \ + $$PWD/gamepadIndicator.cpp \ TRANSLATIONS = \ $$PWD/../translations/ru/trikGui_ru.ts \ diff --git a/trikGui/trikGui.qrc b/trikGui/trikGui.qrc index a65b35f67..d01fc6e56 100644 --- a/trikGui/trikGui.qrc +++ b/trikGui/trikGui.qrc @@ -13,5 +13,7 @@ resources/openWifi.png resources/passwordedWifi.png resources/wait.png + resources/gamepad_off.png + resources/gamepad_on.png