mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
TODO: integrate it in YACReader TODO: add icons for groups TODO: add conflicts detection TODO: fix any shortcut used in keyPressEvent TODO: choose new default shortcuts (F5 update, F11 fullscreen, etc...)
93 lines
2.4 KiB
C++
93 lines
2.4 KiB
C++
#include "actions_shortcuts_model.h"
|
|
#include "shortcuts_manager.h"
|
|
|
|
#include <QAction>
|
|
|
|
ActionsShortcutsModel::ActionsShortcutsModel(QObject *parent) :
|
|
QAbstractItemModel(parent)
|
|
{
|
|
|
|
}
|
|
|
|
int ActionsShortcutsModel::rowCount(const QModelIndex &parent) const
|
|
{
|
|
return actions.length();
|
|
}
|
|
|
|
int ActionsShortcutsModel::columnCount(const QModelIndex &parent) const
|
|
{
|
|
return 3;
|
|
}
|
|
|
|
QModelIndex ActionsShortcutsModel::index(int row, int column, const QModelIndex &parent) const
|
|
{
|
|
if (!hasIndex(row, column, parent))
|
|
return QModelIndex();
|
|
|
|
return createIndex(row, column, actions[row]);
|
|
}
|
|
|
|
Qt::ItemFlags ActionsShortcutsModel::flags(const QModelIndex &index) const
|
|
{
|
|
if (!index.isValid())
|
|
return 0;
|
|
if(index.column() == KEYS)
|
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
|
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
|
}
|
|
|
|
QVariant ActionsShortcutsModel::data(const QModelIndex &index, int role) const
|
|
{
|
|
if (!index.isValid())
|
|
return QVariant();
|
|
|
|
if (role == Qt::DecorationRole && index.column() == ICON)
|
|
return QVariant(actions[index.row()]->icon());
|
|
|
|
if (role == Qt::TextAlignmentRole)
|
|
{
|
|
switch(index.column())
|
|
{
|
|
case ICON:
|
|
return QVariant(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
case NAME:
|
|
return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
|
|
case KEYS:
|
|
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
|
}
|
|
}
|
|
|
|
if (role != Qt::DisplayRole)
|
|
return QVariant();
|
|
|
|
if (index.column() == NAME)
|
|
return QVariant(actions[index.row()]->toolTip());
|
|
if (index.column() == KEYS)
|
|
return QVariant(actions[index.row()]->shortcut().toString());
|
|
|
|
return QVariant();
|
|
}
|
|
|
|
bool ActionsShortcutsModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
{
|
|
if(index.column() == KEYS)
|
|
{
|
|
actions[index.row()]->setShortcut(value.toString());
|
|
ShortcutsManager::getShortcutsManager().saveShortcut(actions[index.row()]);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
QModelIndex ActionsShortcutsModel::parent(const QModelIndex &index) const
|
|
{
|
|
return QModelIndex();
|
|
}
|
|
|
|
void ActionsShortcutsModel::addActions(const QList<QAction *> actions)
|
|
{
|
|
beginResetModel();
|
|
this->actions = actions;
|
|
endResetModel();
|
|
}
|