mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
committed by
Mathew Sutcliffe
parent
be7ac1aa74
commit
08a1de995a
@@ -19,7 +19,6 @@
|
||||
#include "blackmisc/network/clientlist.h"
|
||||
#include "blackmisc/network/textmessagelist.h"
|
||||
#include "blackmisc/network/aircraftmappinglist.h"
|
||||
#include "blackmisc/setkeyboardhotkeylist.h"
|
||||
#include "blackmisc/input/actionhotkeylist.h"
|
||||
#include "blackmisc/simulation/simulatedaircraftlist.h"
|
||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "blackgui/models/simulatedaircraftlistmodel.h"
|
||||
#include "blackgui/models/liverylistmodel.h"
|
||||
#include "blackgui/models/distributorlistmodel.h"
|
||||
#include "blackgui/models/keyboardkeylistmodel.h"
|
||||
#include "blackgui/models/actionhotkeylistmodel.h"
|
||||
|
||||
#endif // guard
|
||||
|
||||
|
||||
@@ -1,157 +0,0 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "keyboardkeylistmodel.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include <QMetaProperty>
|
||||
#include <QComboBox>
|
||||
#include <QTableView>
|
||||
#include <QEvent>
|
||||
#include <QKeyEvent>
|
||||
|
||||
using namespace BlackMisc::Settings;
|
||||
using namespace BlackMisc::Hardware;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
CKeyboardKeyListModel::CKeyboardKeyListModel(QObject *parent) :
|
||||
CListModelBase<CSettingKeyboardHotkey, CSettingKeyboardHotkeyList>("ViewKeyboardKeyList", parent)
|
||||
{
|
||||
const bool editable = true;
|
||||
this->m_columns.addColumn(CColumn("key", CSettingKeyboardHotkey::IndexKeyAsStringRepresentation, new CStringFormatter(), editable));
|
||||
this->m_columns.addColumn(CColumn("modifier 1", CSettingKeyboardHotkey::IndexModifier1AsString, new CStringFormatter(), editable));
|
||||
this->m_columns.addColumn(CColumn("modifier 2", CSettingKeyboardHotkey::IndexModifier2AsString, new CStringFormatter(), editable));
|
||||
this->m_columns.addColumn(CColumn::standardString("function", CSettingKeyboardHotkey::IndexFunctionAsString));
|
||||
|
||||
this->setSortColumnByPropertyIndex(CSettingKeyboardHotkey::IndexFunctionAsString);
|
||||
this->m_sortOrder = Qt::AscendingOrder;
|
||||
|
||||
// force strings for translation in resource files
|
||||
(void)QT_TRANSLATE_NOOP("ViewKeyboardKeyList", "modifier 1");
|
||||
(void)QT_TRANSLATE_NOOP("ViewKeyboardKeyList", "modifier 2");
|
||||
(void)QT_TRANSLATE_NOOP("ViewKeyboardKeyList", "function");
|
||||
(void)QT_TRANSLATE_NOOP("ViewKeyboardKeyList", "key");
|
||||
}
|
||||
|
||||
/*
|
||||
* Display icons
|
||||
*/
|
||||
QVariant CKeyboardKeyListModel::data(const QModelIndex &modelIndex, int role) const
|
||||
{
|
||||
// shortcut, fast check
|
||||
return CListModelBase::data(modelIndex, role);
|
||||
}
|
||||
|
||||
bool CKeyboardKeyListModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (role == Qt::EditRole)
|
||||
{
|
||||
CSettingKeyboardHotkey::ColumnIndex pi = this->modelIndexToPropertyIndex(index).frontCasted<CSettingKeyboardHotkey::ColumnIndex>();
|
||||
if (pi == CSettingKeyboardHotkey::IndexModifier1 || pi == CSettingKeyboardHotkey::IndexModifier2 || pi == CSettingKeyboardHotkey::IndexModifier1AsString || pi == CSettingKeyboardHotkey::IndexModifier2AsString)
|
||||
{
|
||||
if (index.row() >= this->m_container.size()) return true;
|
||||
CSettingKeyboardHotkey key = this->m_container[index.row()];
|
||||
key.setPropertyByIndex(value, pi);
|
||||
key.cleanup();
|
||||
this->m_container[index.row()] = key;
|
||||
return true;
|
||||
}
|
||||
else if (pi == CSettingKeyboardHotkey::IndexKey || pi == CSettingKeyboardHotkey::IndexKeyAsString || pi == CSettingKeyboardHotkey::IndexKeyAsStringRepresentation)
|
||||
{
|
||||
Q_ASSERT(value.canConvert<CSettingKeyboardHotkey>());
|
||||
if (index.row() >= this->m_container.size()) return true;
|
||||
CSettingKeyboardHotkey key = this->m_container[index.row()];
|
||||
key.setPropertyByIndex(value, CSettingKeyboardHotkey::IndexObject);
|
||||
key.cleanup();
|
||||
this->m_container[index.row()] = key;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return CListModelBase::setData(index, value, role);
|
||||
}
|
||||
|
||||
QWidget *CKeyboardKeyItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
const CKeyboardKeyListModel *model = this->model();
|
||||
Q_ASSERT(model);
|
||||
|
||||
if (index.row() < model->rowCount())
|
||||
{
|
||||
CSettingKeyboardHotkey::ColumnIndex pi = model->modelIndexToPropertyIndex(index).frontCasted<CSettingKeyboardHotkey::ColumnIndex>();
|
||||
if (pi == CSettingKeyboardHotkey::IndexModifier1 || pi == CSettingKeyboardHotkey::IndexModifier2 || pi == CSettingKeyboardHotkey::IndexModifier1AsString || pi == CSettingKeyboardHotkey::IndexModifier2AsString)
|
||||
{
|
||||
CSettingKeyboardHotkey key = model->at(index);
|
||||
QString v = (pi == CSettingKeyboardHotkey::IndexModifier1 || pi == CSettingKeyboardHotkey::IndexModifier1AsString) ? key.getModifier1AsString() : key.getModifier2AsString();
|
||||
QComboBox *edit = new QComboBox(parent);
|
||||
edit->addItems(CSettingKeyboardHotkey::modifiers());
|
||||
edit->setCurrentText(v);
|
||||
return edit;
|
||||
}
|
||||
else if (pi == CSettingKeyboardHotkey::IndexKey || pi == CSettingKeyboardHotkey::IndexKeyAsString || pi == CSettingKeyboardHotkey::IndexKeyAsStringRepresentation)
|
||||
{
|
||||
CSettingKeyboardHotkey hotkey = model->at(index);
|
||||
CKeyboardLineEdit *edit = new CKeyboardLineEdit(hotkey, parent);
|
||||
edit->setText(hotkey.getKey().getKeyAsString());
|
||||
return edit;
|
||||
}
|
||||
}
|
||||
return QItemDelegate::createEditor(parent, option, index);
|
||||
}
|
||||
|
||||
void CKeyboardKeyItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
||||
{
|
||||
QItemDelegate::setEditorData(editor, index);
|
||||
}
|
||||
|
||||
void CKeyboardKeyItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
||||
{
|
||||
// with our own line edit we have a special treatment
|
||||
// otherwise (comboboxes) standard handling via QItemDelegate
|
||||
CKeyboardLineEdit *lineEdit = qobject_cast<CKeyboardLineEdit *>(editor);
|
||||
if (lineEdit)
|
||||
model->setData(index, QVariant::fromValue(lineEdit->getKey()) , Qt::EditRole);
|
||||
else
|
||||
QItemDelegate::setModelData(editor, model, index);
|
||||
}
|
||||
|
||||
void CKeyboardKeyItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
QItemDelegate::updateEditorGeometry(editor, option, index);
|
||||
}
|
||||
|
||||
const CKeyboardKeyListModel *CKeyboardKeyItemDelegate::model() const
|
||||
{
|
||||
if (this->parent())
|
||||
{
|
||||
QTableView *tableView = dynamic_cast<QTableView *>(this->parent());
|
||||
if (tableView)
|
||||
{
|
||||
return dynamic_cast<CKeyboardKeyListModel *>(tableView->model());
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CKeyboardLineEdit::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
const Qt::Key k = static_cast<Qt::Key>(event->key());
|
||||
if (k == Qt::Key_Shift || k == Qt::Key_Control || k == Qt::Key_Meta || k == Qt::Key_Alt || k == Qt::Key_CapsLock || k == Qt::Key_NumLock || k == Qt::Key_ScrollLock) return;
|
||||
BlackMisc::Hardware::CKeyboardKey key;
|
||||
key.setKey(k);
|
||||
this->m_hotkey.setKey(key);
|
||||
this->setText(CSettingKeyboardHotkey::toStringRepresentation(event->key()));
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
@@ -1,104 +0,0 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKGUI_KEYBOARDKEYLISTMODEL_H
|
||||
#define BLACKGUI_KEYBOARDKEYLISTMODEL_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackmisc/hardware/keyboardkeylist.h"
|
||||
#include "blackmisc/setkeyboardhotkeylist.h"
|
||||
#include "blackgui/models/listmodelbase.h"
|
||||
#include <QAbstractItemModel>
|
||||
#include <QDBusConnection>
|
||||
#include <QItemDelegate>
|
||||
#include <QLineEdit>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
/*!
|
||||
* Keyboard key list model
|
||||
*/
|
||||
class BLACKGUI_EXPORT CKeyboardKeyListModel : public CListModelBase<BlackMisc::Settings::CSettingKeyboardHotkey, BlackMisc::Settings::CSettingKeyboardHotkeyList>
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//! Constructor
|
||||
explicit CKeyboardKeyListModel(QObject *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CKeyboardKeyListModel() {}
|
||||
|
||||
//! \copydoc CListModelBase::data
|
||||
QVariant data(const QModelIndex &modelIndex, int role = Qt::DisplayRole) const override;
|
||||
|
||||
//! \copydoc CKeyboardKeyList::initAsHotkeyList(bool reset)
|
||||
void initAsHotkeyList() { this->m_container.initAsHotkeyList(); }
|
||||
|
||||
//! \copydoc QAbstractTableModel::setData
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||
};
|
||||
|
||||
/*!
|
||||
* Special edit delegate for key sequence
|
||||
*/
|
||||
class BLACKGUI_EXPORT CKeyboardKeyItemDelegate : public QItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
explicit CKeyboardKeyItemDelegate(QObject *parent = nullptr) :
|
||||
QItemDelegate(parent) {}
|
||||
|
||||
//! \copydoc QItemDelegate::createEditor
|
||||
virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
|
||||
//! \copydoc QItemDelegate::setEditorData
|
||||
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const override;
|
||||
|
||||
//! \copydoc QItemDelegate::setModelData
|
||||
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
||||
|
||||
//! \copydoc QItemDelegate::updateEditorGeometry
|
||||
virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
|
||||
//! correspondig model
|
||||
const CKeyboardKeyListModel *model() const;
|
||||
};
|
||||
|
||||
/*!
|
||||
* Special edit widget for key sequence
|
||||
*/
|
||||
class BLACKGUI_EXPORT CKeyboardLineEdit : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CKeyboardLineEdit(const BlackMisc::Settings::CSettingKeyboardHotkey &hotkey, QWidget *parent = nullptr) :
|
||||
QLineEdit(parent), m_hotkey(hotkey) { }
|
||||
|
||||
//! get key
|
||||
const BlackMisc::Settings::CSettingKeyboardHotkey &getKey() const { return this->m_hotkey; }
|
||||
|
||||
protected:
|
||||
//! Overriding and handling key press
|
||||
virtual void keyPressEvent(QKeyEvent *event) override;
|
||||
|
||||
private:
|
||||
BlackMisc::Settings::CSettingKeyboardHotkey m_hotkey;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // guard
|
||||
@@ -461,7 +461,6 @@ namespace BlackGui
|
||||
template class CListModelBase<BlackMisc::Simulation::CAircraftModel, BlackMisc::Simulation::CAircraftModelList>;
|
||||
template class CListModelBase<BlackMisc::Simulation::CSimulatedAircraft, BlackMisc::Simulation::CSimulatedAircraftList>;
|
||||
template class CListModelBase<BlackMisc::Simulation::CDistributor, BlackMisc::Simulation::CDistributorList>;
|
||||
template class CListModelBase<BlackMisc::Settings::CSettingKeyboardHotkey, BlackMisc::Settings::CSettingKeyboardHotkeyList>;
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "keyboardkeyview.h"
|
||||
#include <QHeaderView>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackGui::Models;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Views
|
||||
{
|
||||
CKeyboardKeyView::CKeyboardKeyView(QWidget *parent) : CViewBase(parent)
|
||||
{
|
||||
this->standardInit(new CKeyboardKeyListModel(this));
|
||||
this->setItemDelegate(new CKeyboardKeyItemDelegate(this)); // for editing
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef BLACKGUI_KEYBOARDKEYVIEW_H
|
||||
#define BLACKGUI_KEYBOARDKEYVIEW_H
|
||||
|
||||
//! \file
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "viewbase.h"
|
||||
#include "../models/keyboardkeylistmodel.h"
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Views
|
||||
{
|
||||
//! Keyboard key view
|
||||
class BLACKGUI_EXPORT CKeyboardKeyView : public CViewBase<Models::CKeyboardKeyListModel, BlackMisc::Settings::CSettingKeyboardHotkeyList, BlackMisc::Settings::CSettingKeyboardHotkey>
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//! Constructor
|
||||
explicit CKeyboardKeyView(QWidget *parent = nullptr);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // guard
|
||||
@@ -405,7 +405,5 @@ namespace BlackGui
|
||||
template class CViewBase<BlackGui::Models::CAircraftModelListModel, BlackMisc::Simulation::CAircraftModelList, BlackMisc::Simulation::CAircraftModel>;
|
||||
template class CViewBase<BlackGui::Models::CDistributorListModel, BlackMisc::Simulation::CDistributorList, BlackMisc::Simulation::CDistributor>;
|
||||
|
||||
template class CViewBase<BlackGui::Models::CKeyboardKeyListModel, BlackMisc::Settings::CSettingKeyboardHotkeyList, BlackMisc::Settings::CSettingKeyboardHotkey>;
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user