mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
refs #454 Adapt sample_hotkeys to new hotkey settings component
This commit is contained in:
committed by
Mathew Sutcliffe
parent
5a82e2e6bf
commit
9b6126c5db
@@ -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 <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QGroupBox>
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -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 <QDialog>
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QScopedPointer>
|
||||
|
||||
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
|
||||
@@ -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 <QPen>
|
||||
#include <QPainter>
|
||||
#include <QPointF>
|
||||
#include <QRadialGradient>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 <QWidget>
|
||||
#include <QPainter>
|
||||
|
||||
//! \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
|
||||
@@ -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 <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
HotkeyDialog w;
|
||||
|
||||
BlackMisc::registerMetadata();
|
||||
BlackGui::Components::CSettingsHotkeyComponent w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user