2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2016-05-31 19:05:25 +02:00
|
|
|
*
|
2020-08-22 01:19:58 +02:00
|
|
|
* SPDX-FileCopyrightText: 2016 Teo Mrnjavac <teo@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2016-05-31 19:05:25 +02:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2016-05-31 19:05:25 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KEYBOARDLAYOUTMODEL_H
|
|
|
|
#define KEYBOARDLAYOUTMODEL_H
|
|
|
|
|
|
|
|
#include "keyboardwidget/keyboardglobal.h"
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QMetaType>
|
2020-04-03 10:18:07 +02:00
|
|
|
#include <QObject>
|
2016-05-31 19:05:25 +02:00
|
|
|
|
2020-10-28 16:20:02 +01:00
|
|
|
/** @brief A list model with an xkb key and a human-readable string
|
2020-10-28 13:41:21 +01:00
|
|
|
*
|
|
|
|
* This model acts like it has a single selection, as well.
|
|
|
|
*/
|
2020-10-28 16:20:02 +01:00
|
|
|
class XKBListModel : public QAbstractListModel
|
2016-05-31 19:05:25 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2020-03-26 15:57:02 +01:00
|
|
|
Q_PROPERTY( int currentIndex WRITE setCurrentIndex READ currentIndex NOTIFY currentIndexChanged )
|
2016-05-31 19:05:25 +02:00
|
|
|
|
|
|
|
public:
|
2020-10-28 13:41:21 +01:00
|
|
|
enum
|
2016-05-31 19:05:25 +02:00
|
|
|
{
|
2020-10-28 13:41:21 +01:00
|
|
|
LabelRole = Qt::DisplayRole, ///< Human-readable
|
|
|
|
KeyRole = Qt::UserRole ///< xkb identifier
|
2016-05-31 19:05:25 +02:00
|
|
|
};
|
|
|
|
|
2020-10-28 16:20:02 +01:00
|
|
|
explicit XKBListModel( QObject* parent = nullptr );
|
2016-05-31 19:05:25 +02:00
|
|
|
|
2020-10-28 16:28:00 +01:00
|
|
|
int rowCount( const QModelIndex& = QModelIndex() ) const override;
|
2016-05-31 19:05:25 +02:00
|
|
|
QVariant data( const QModelIndex& index, int role ) const override;
|
2020-10-28 13:41:21 +01:00
|
|
|
/** @brief xkb key for a given index (row)
|
|
|
|
*
|
|
|
|
* This is like calling data( QModelIndex( index ), KeyRole ).toString(),
|
|
|
|
* but shorter and faster. Can return an empty string if index is invalid.
|
|
|
|
*/
|
2020-10-28 16:28:00 +01:00
|
|
|
QString key( int index ) const;
|
2020-10-28 13:41:21 +01:00
|
|
|
|
|
|
|
/** @brief human-readable label for a given index (row)
|
|
|
|
*
|
|
|
|
* This is like calling data( QModelIndex( index ), LabelRole ).toString(),
|
|
|
|
* but shorter and faster. Can return an empty string if index is invalid.
|
|
|
|
*/
|
2020-10-28 16:28:00 +01:00
|
|
|
QString label( int index ) const;
|
2016-05-31 19:05:25 +02:00
|
|
|
|
2020-03-26 15:57:02 +01:00
|
|
|
QHash< int, QByteArray > roleNames() const override;
|
2020-04-03 10:18:07 +02:00
|
|
|
|
2020-10-28 13:41:21 +01:00
|
|
|
void setCurrentIndex( int index );
|
|
|
|
int currentIndex() const { return m_currentIndex; }
|
2020-04-03 10:18:07 +02:00
|
|
|
|
|
|
|
signals:
|
2020-03-26 15:57:02 +01:00
|
|
|
void currentIndexChanged( int index );
|
2020-10-28 13:41:21 +01:00
|
|
|
|
2020-10-28 16:20:02 +01:00
|
|
|
protected:
|
2020-10-28 13:41:21 +01:00
|
|
|
struct ModelInfo
|
|
|
|
{
|
|
|
|
/// XKB identifier
|
|
|
|
QString key;
|
|
|
|
/// Human-readable
|
|
|
|
QString label;
|
|
|
|
};
|
|
|
|
QVector< ModelInfo > m_list;
|
2020-10-28 13:52:30 +01:00
|
|
|
int m_currentIndex = -1;
|
2020-10-30 14:38:11 +01:00
|
|
|
const char* m_contextname = nullptr;
|
2020-10-28 16:20:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief A list model of the physical keyboard formats ("models" in xkb)
|
|
|
|
*
|
|
|
|
* This model acts like it has a single selection, as well.
|
|
|
|
*/
|
|
|
|
class KeyboardModelsModel : public XKBListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit KeyboardModelsModel( QObject* parent = nullptr );
|
|
|
|
|
|
|
|
/// @brief Set the index back to PC105 (the default physical model)
|
|
|
|
void setCurrentIndex() { XKBListModel::setCurrentIndex( m_defaultPC105 ); }
|
|
|
|
|
|
|
|
private:
|
2020-10-28 13:52:30 +01:00
|
|
|
int m_defaultPC105 = -1; ///< The index of pc105, if there is one
|
2016-05-31 19:05:25 +02:00
|
|
|
};
|
|
|
|
|
2020-10-28 16:40:43 +01:00
|
|
|
/** @brief A list of keyboard layouts (arrangements of keycaps)
|
|
|
|
*
|
|
|
|
* Layouts can have a list of associated Variants, so this
|
|
|
|
* is slightly more complicated than the "regular" XKBListModel.
|
|
|
|
*/
|
2020-10-28 13:41:21 +01:00
|
|
|
class KeyboardLayoutModel : public QAbstractListModel
|
2020-10-12 14:33:09 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY( int currentIndex WRITE setCurrentIndex READ currentIndex NOTIFY currentIndexChanged )
|
|
|
|
|
|
|
|
public:
|
2020-10-28 13:41:21 +01:00
|
|
|
enum Roles : int
|
|
|
|
{
|
|
|
|
KeyboardVariantsRole = Qt::UserRole,
|
|
|
|
KeyboardLayoutKeyRole
|
|
|
|
};
|
|
|
|
|
|
|
|
KeyboardLayoutModel( QObject* parent = nullptr );
|
|
|
|
|
|
|
|
int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
|
|
|
|
|
2020-10-12 14:33:09 +02:00
|
|
|
QVariant data( const QModelIndex& index, int role ) const override;
|
|
|
|
|
2020-10-28 16:47:52 +01:00
|
|
|
void setCurrentIndex( int index );
|
2020-10-12 14:33:09 +02:00
|
|
|
int currentIndex() const;
|
2020-10-28 13:41:21 +01:00
|
|
|
const QPair< QString, KeyboardGlobal::KeyboardInfo > item( const int& index ) const;
|
2020-10-12 14:33:09 +02:00
|
|
|
|
2020-11-12 14:50:21 +01:00
|
|
|
/** @brief xkb key for a given index (row)
|
|
|
|
*
|
|
|
|
* This is like calling data( QModelIndex( index ), KeyboardLayoutKeyRole ).toString(),
|
|
|
|
* but shorter and faster. Can return an empty string if index is invalid.
|
|
|
|
*/
|
|
|
|
QString key( int index ) const;
|
|
|
|
|
2020-10-12 14:33:09 +02:00
|
|
|
protected:
|
|
|
|
QHash< int, QByteArray > roleNames() const override;
|
|
|
|
|
|
|
|
private:
|
2020-10-28 13:41:21 +01:00
|
|
|
void init();
|
2020-10-12 14:33:09 +02:00
|
|
|
int m_currentIndex = -1;
|
2020-10-28 13:41:21 +01:00
|
|
|
QList< QPair< QString, KeyboardGlobal::KeyboardInfo > > m_layouts;
|
2020-10-12 14:33:09 +02:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void currentIndexChanged( int index );
|
|
|
|
};
|
|
|
|
|
2020-10-28 16:40:43 +01:00
|
|
|
/** @brief A list of variants (xkb id and human-readable)
|
|
|
|
*
|
|
|
|
* The variants that are available depend on the Layout that is used,
|
|
|
|
* so the `setVariants()` function can be used to update the variants
|
|
|
|
* when the two models are related.
|
|
|
|
*/
|
2020-10-28 16:28:00 +01:00
|
|
|
class KeyboardVariantsModel : public XKBListModel
|
2020-10-12 14:33:09 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit KeyboardVariantsModel( QObject* parent = nullptr );
|
|
|
|
|
2020-10-28 16:28:00 +01:00
|
|
|
void setVariants( QMap< QString, QString > variants );
|
2020-10-12 14:33:09 +02:00
|
|
|
};
|
|
|
|
|
2020-11-01 13:46:32 +01:00
|
|
|
/** @brief Adjust to changes in application language.
|
|
|
|
*/
|
|
|
|
void retranslateKeyboardModels();
|
|
|
|
|
2020-03-26 15:57:02 +01:00
|
|
|
#endif // KEYBOARDLAYOUTMODEL_H
|