From 9b6126c5db0b4a8c59d66769746d144f4de2c883 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Tue, 8 Sep 2015 14:59:55 +0000 Subject: [PATCH] refs #454 Adapt sample_hotkeys to new hotkey settings component --- samples/hotkey/hotkey.cpp | 114 ------------------------------- samples/hotkey/hotkey.h | 71 ------------------- samples/hotkey/led.cpp | 67 ------------------ samples/hotkey/led.h | 76 --------------------- samples/hotkey/main.cpp | 7 +- samples/hotkey/sample_hotkey.pro | 3 +- 6 files changed, 6 insertions(+), 332 deletions(-) delete mode 100644 samples/hotkey/hotkey.cpp delete mode 100644 samples/hotkey/hotkey.h delete mode 100644 samples/hotkey/led.cpp delete mode 100644 samples/hotkey/led.h diff --git a/samples/hotkey/hotkey.cpp b/samples/hotkey/hotkey.cpp deleted file mode 100644 index 7a57480a5..000000000 --- a/samples/hotkey/hotkey.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "hotkey.h" - -#include "blackmisc/hardware/keyboardkeylist.h" - -#include -#include -#include - -using namespace BlackMisc::Hardware; - -HotkeyDialog::HotkeyDialog(QWidget *parent) : - QDialog(parent), - m_keyboard(nullptr), - m_pbSelect(nullptr), - m_lblHotkey(nullptr), - m_led(nullptr) -{ - m_keyboard = BlackInput::IKeyboard::getInstance(); - - setupUi(); - setupConnections(); - -} - -HotkeyDialog::~HotkeyDialog() -{ -} - -void HotkeyDialog::selectHotKey() -{ - m_lblHotkey->setText("Press any key..."); - m_keyboard->startCapture(false); -} - -void HotkeyDialog::keySelectionChanged(BlackMisc::Hardware::CKeyboardKey key) -{ - m_lblHotkey->setText(key.toFormattedQString()); -} - -void HotkeyDialog::keySelectionFinished(BlackMisc::Hardware::CKeyboardKey key) -{ - m_lblHotkey->setText(key.toFormattedQString()); - - m_key = key; - - CKeyboardKeyList keyList; - keyList.push_back(key); - m_keyboard->setKeysToMonitor(keyList); -} - -void HotkeyDialog::processKeyDown(const BlackMisc::Hardware::CKeyboardKey &key) -{ - if (key == m_key) setPressed(true); -} - -void HotkeyDialog::processKeyUp(const BlackMisc::Hardware::CKeyboardKey &key) -{ - if (key == m_key) setPressed(false); -} - -void HotkeyDialog::setPressed(bool isPressed) -{ - m_led->setChecked(isPressed); - update(); -} - -void HotkeyDialog::setupUi() -{ - m_pbSelect = new QPushButton(this); - m_pbSelect->setText("Select"); - QFont font; - font.setPointSize(15); - m_lblHotkey = new QLabel(this); - m_lblHotkey->setFont(font); - m_lblHotkey->setAlignment(Qt::AlignCenter); - m_led = new CLed(this); - - // PTT group box - QGroupBox *upperGroup = new QGroupBox; - upperGroup->setTitle("PTT"); - QHBoxLayout *upperLine = new QHBoxLayout; - upperLine->addWidget(m_led); - upperGroup->setLayout(upperLine); - - // Setting group box - QGroupBox *lowerGroup = new QGroupBox; - lowerGroup->setTitle("Setting"); - QVBoxLayout *lowerLine = new QVBoxLayout; - lowerLine->addWidget(m_lblHotkey); - lowerLine->addWidget(m_pbSelect); - lowerGroup->setLayout(lowerLine); - - // Main Layout - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addWidget(upperGroup); - mainLayout->addWidget(lowerGroup); - - setLayout(mainLayout); - setWindowTitle("Sample Hotkey"); - -} -void HotkeyDialog::setupConnections() -{ - connect(m_keyboard, &BlackInput::IKeyboard::keySelectionChanged, this, &HotkeyDialog::keySelectionChanged); - connect(m_keyboard, &BlackInput::IKeyboard::keySelectionFinished, this, &HotkeyDialog::keySelectionFinished); - connect(m_keyboard, &BlackInput::IKeyboard::keyDown, this, &HotkeyDialog::processKeyDown); - connect(m_keyboard, &BlackInput::IKeyboard::keyUp, this, &HotkeyDialog::processKeyUp); - connect(m_pbSelect, &QPushButton::clicked, this, &HotkeyDialog::selectHotKey); -} diff --git a/samples/hotkey/hotkey.h b/samples/hotkey/hotkey.h deleted file mode 100644 index b6f04c327..000000000 --- a/samples/hotkey/hotkey.h +++ /dev/null @@ -1,71 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BLACKSAMPLE_HOTKEY_H -#define BLACKSAMPLE_HOTKEY_H - -#include "led.h" -#include "blackinput/keyboard.h" -#include "blackmisc/hardware/keyboardkey.h" - -#include -#include -#include -#include - -class HotkeyDialog : public QDialog -{ - Q_OBJECT - -public: - /*! - * \brief Constructor - * \param parent - */ - explicit HotkeyDialog(QWidget *parent = 0); - - //! Destructor - ~HotkeyDialog(); - -public slots: - //! \brief Slot to select a new hot key - void selectHotKey(); - -private slots: - /*! - * \brief Slot when the selected key set has changed - * \param keySet - */ - void keySelectionChanged(BlackMisc::Hardware::CKeyboardKey key); - - /*! - * \brief Slot when the key selection is finished - * \param keySet - */ - void keySelectionFinished(BlackMisc::Hardware::CKeyboardKey key); - - void processKeyDown(const BlackMisc::Hardware::CKeyboardKey &); - - void processKeyUp(const BlackMisc::Hardware::CKeyboardKey &); - -private: - /*! - * \brief Set the key status - * \param isPressed - */ - void setPressed(bool isPressed); - -private: - void setupUi(); - void setupConnections(); - - BlackInput::IKeyboard *m_keyboard; - BlackMisc::Hardware::CKeyboardKey m_key; - QPushButton *m_pbSelect; - QLabel *m_lblHotkey; - CLed *m_led; -}; - -#endif // BLACKSAMPLE_HOTKEY_H diff --git a/samples/hotkey/led.cpp b/samples/hotkey/led.cpp deleted file mode 100644 index 995a89512..000000000 --- a/samples/hotkey/led.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "led.h" -#include -#include -#include -#include - -CLed::CLed(QWidget *parent) : - QWidget(parent), - m_isChecked(false) -{ -} - -void CLed::paintEvent(QPaintEvent * /* event */) -{ - qint32 diameter = qMin(width(), height()); - - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); - painter.translate(width() / 2, height() / 2); - painter.scale(diameter / 50.0, diameter / 50.0); - - drawLed(painter); - drawShine(painter); -} - -QSize CLed::minimumSizeHint() const -{ - return QSize(50, 50); -} - -void CLed::drawLed(QPainter &painter) -{ - // Draw circle - QColor backgroundColor; - - if (isChecked()) - backgroundColor = Qt::red; - else - backgroundColor = Qt::gray; - - // Black border color - // Fill color depends on the state - QPen penCircle; - penCircle.setColor(Qt::black); - penCircle.setWidthF(10.0); - painter.setBrush(backgroundColor); - painter.drawEllipse(QPointF(0.0, 0.0), 24.5, 24.5); -} - -void CLed::drawShine(QPainter &painter) -{ - // Draw shine - QColor white1(255,255,255,200); - QColor white0(255,255,255,0); - QRadialGradient shine(QPointF(-10.0,-10.0),30.0,QPointF(-10,-10)); - shine.setColorAt(0.0, white1); - shine.setColorAt(1.0, white0); - painter.setBrush(shine); - painter.drawEllipse(QPointF(0.0, 0.0), 24.0, 24.0); -} - - diff --git a/samples/hotkey/led.h b/samples/hotkey/led.h deleted file mode 100644 index 76a4e951a..000000000 --- a/samples/hotkey/led.h +++ /dev/null @@ -1,76 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / authors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BLACKSAMPLE_LED_H -#define BLACKSAMPLE_LED_H - -#include -#include - -//! \brief LED widget -class CLed : public QWidget -{ - Q_OBJECT -public: - CLed(QWidget *parent = 0); - - /*! - * \brief LED color - * \return - */ - QColor color() const { return m_color; } - - /*! - * \brief Set LED color - * \param color - */ - void setColor(QColor color) { m_color = color; } - - /*! - * \brief isChecked - * \return - */ - bool isChecked () const { return m_isChecked; } - - //! \copydoc QWidget::minimumSizeHint() - virtual QSize minimumSizeHint () const override; - -protected: - //! \copydoc QWidget::minimumSizeHint() - virtual void paintEvent(QPaintEvent * event) override; - -signals: - /*! - * \brief Check value has changed - * \param value - */ - void checkChanged(bool value); - -public slots: - /*! - * \brief setChecked - * \param value - */ - void setChecked(bool value) {m_isChecked = value;} - -private: - /*! - * \brief drawLed - * \param painter - */ - void drawLed(QPainter & painter); - - /*! - * \brief drawShine - * \param painter - */ - void drawShine(QPainter & painter); - - bool m_isChecked; - QColor m_color; - -}; - -#endif // BLACKSAMPLE_LED_H diff --git a/samples/hotkey/main.cpp b/samples/hotkey/main.cpp index e5c3e66d1..540e66334 100644 --- a/samples/hotkey/main.cpp +++ b/samples/hotkey/main.cpp @@ -3,13 +3,16 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "hotkey.h" +#include "blackgui/components/settingshotkeycomponent.h" +#include "blackmisc/blackmiscfreefunctions.h" #include int main(int argc, char *argv[]) { QApplication a(argc, argv); - HotkeyDialog w; + + BlackMisc::registerMetadata(); + BlackGui::Components::CSettingsHotkeyComponent w; w.show(); return a.exec(); diff --git a/samples/hotkey/sample_hotkey.pro b/samples/hotkey/sample_hotkey.pro index 3645eec9c..165501fac 100644 --- a/samples/hotkey/sample_hotkey.pro +++ b/samples/hotkey/sample_hotkey.pro @@ -9,13 +9,12 @@ TARGET = sample_hotkey TEMPLATE = app CONFIG -= app_bundle -CONFIG += blackmisc blackinput blackcore +CONFIG += blackmisc blackinput blackcore blackgui DEPENDPATH += . $$SourceRoot/src INCLUDEPATH += . $$SourceRoot/src SOURCES += *.cpp -HEADERS += *.h DESTDIR = $$BuildRoot/bin