Added new UI files
This commit is contained in:
95
src/qt/qt_keybind.cpp
Normal file
95
src/qt/qt_keybind.cpp
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
||||||
|
* running old operating systems and software designed for IBM
|
||||||
|
* PC systems and compatibles from 1981 through fairly recent
|
||||||
|
* system designs based on the PCI bus.
|
||||||
|
*
|
||||||
|
* This file is part of the 86Box distribution.
|
||||||
|
*
|
||||||
|
* Device configuration UI code.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Authors: Joakim L. Gilje <jgilje@jgilje.net>
|
||||||
|
* Cacodemon345
|
||||||
|
*
|
||||||
|
* Copyright 2021 Joakim L. Gilje
|
||||||
|
* Copyright 2022 Cacodemon345
|
||||||
|
*/
|
||||||
|
#include "qt_keybind.hpp"
|
||||||
|
#include "ui_qt_keybind.h"
|
||||||
|
#include "qt_settings.hpp"
|
||||||
|
#include "qt_singlekeyseqedit.hpp"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QFormLayout>
|
||||||
|
#include <QSpinBox>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QFrame>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QKeyEvent>
|
||||||
|
#include <QKeySequence>
|
||||||
|
#include <QKeySequenceEdit>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <86box/86box.h>
|
||||||
|
#include <86box/ini.h>
|
||||||
|
#include <86box/config.h>
|
||||||
|
#include <86box/device.h>
|
||||||
|
#include <86box/midi_rtmidi.h>
|
||||||
|
#include <86box/mem.h>
|
||||||
|
#include <86box/random.h>
|
||||||
|
#include <86box/rom.h>
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "qt_filefield.hpp"
|
||||||
|
#include "qt_models_common.hpp"
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
# include <sys/stat.h>
|
||||||
|
# include <sys/sysmacros.h>
|
||||||
|
#endif
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
KeyBinder::KeyBinder(QWidget *parent)
|
||||||
|
: QDialog(parent)
|
||||||
|
, ui(new Ui::KeyBinder)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
singleKeySequenceEdit *seq = new singleKeySequenceEdit();
|
||||||
|
ui->formLayout->addRow(seq);
|
||||||
|
seq->setObjectName("keySequence");
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyBinder::~KeyBinder()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool KeyBinder::eventFilter(QObject *obj, QEvent *event)
|
||||||
|
{
|
||||||
|
return QObject::eventFilter(obj, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
QKeySequence
|
||||||
|
KeyBinder::BindKey(QString CurValue)
|
||||||
|
{
|
||||||
|
KeyBinder kb;
|
||||||
|
kb.setWindowTitle("Bind Key");
|
||||||
|
kb.setFixedSize(kb.minimumSizeHint());
|
||||||
|
kb.findChild<QKeySequenceEdit*>()->setKeySequence(QKeySequence::fromString(CurValue));
|
||||||
|
|
||||||
|
if (kb.exec() == QDialog::Accepted) {
|
||||||
|
QKeySequenceEdit *seq = kb.findChild<QKeySequenceEdit*>();
|
||||||
|
return (seq->keySequence());
|
||||||
|
} else {
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
}
|
||||||
32
src/qt/qt_keybind.hpp
Normal file
32
src/qt/qt_keybind.hpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#ifndef QT_KeyBinder_HPP
|
||||||
|
#define QT_KeyBinder_HPP
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
#include "qt_settings.hpp"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
struct _device_;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class KeyBinder;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Settings;
|
||||||
|
|
||||||
|
class KeyBinder : public QDialog {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit KeyBinder(QWidget *parent = nullptr);
|
||||||
|
~KeyBinder() override;
|
||||||
|
|
||||||
|
static QKeySequence BindKey(QString CurValue);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::KeyBinder *ui;
|
||||||
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QT_KeyBinder_HPP
|
||||||
85
src/qt/qt_keybind.ui
Normal file
85
src/qt/qt_keybind.ui
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>KeyBinder</class>
|
||||||
|
<widget class="QDialog" name="KeyBinder">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>103</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Enter key combo:</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="Line" name="line">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>KeyBinder</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>KeyBinder</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
||||||
20
src/qt/qt_singlekeyseqedit.cpp
Normal file
20
src/qt/qt_singlekeyseqedit.cpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#include "qt_singlekeyseqedit.hpp"
|
||||||
|
|
||||||
|
/*
|
||||||
|
This subclass of QKeySequenceEdit restricts the input to only a single
|
||||||
|
shortcut instead of an unlimited number with a fixed timeout.
|
||||||
|
*/
|
||||||
|
|
||||||
|
singleKeySequenceEdit::singleKeySequenceEdit(QWidget *parent) : QKeySequenceEdit(parent) {}
|
||||||
|
|
||||||
|
void singleKeySequenceEdit::keyPressEvent(QKeyEvent *event)
|
||||||
|
{
|
||||||
|
QKeySequenceEdit::keyPressEvent(event);
|
||||||
|
if (this->keySequence().count() > 0) {
|
||||||
|
QKeySequenceEdit::setKeySequence(this->keySequence());
|
||||||
|
|
||||||
|
// This could have unintended consequences since it will happen
|
||||||
|
// every single time the user presses a key.
|
||||||
|
emit editingFinished();
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/qt/qt_singlekeyseqedit.hpp
Normal file
16
src/qt/qt_singlekeyseqedit.hpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef SINGLEKEYSEQUENCEEDIT_H
|
||||||
|
#define SINGLEKEYSEQUENCEEDIT_H
|
||||||
|
|
||||||
|
#include <QKeySequenceEdit>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class singleKeySequenceEdit : public QKeySequenceEdit
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
singleKeySequenceEdit(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
void keyPressEvent(QKeyEvent *) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SINGLEKEYSEQUENCEEDIT_H
|
||||||
Reference in New Issue
Block a user