mirror of
				https://github.com/YACReader/yacreader
				synced 2025-11-03 16:54:39 -05:00 
			
		
		
		
	added a hack for fixing fullscreen context menus with QOpengGLWidget in YACReader
This commit is contained in:
		
							
								
								
									
										86
									
								
								shortcuts_management/actions_groups_model.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										86
									
								
								shortcuts_management/actions_groups_model.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,86 @@
 | 
			
		||||
#include "actions_groups_model.h"
 | 
			
		||||
 | 
			
		||||
ActionsGroupsModel::ActionsGroupsModel(QObject *parent) :
 | 
			
		||||
    QAbstractItemModel(parent)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ActionsGroupsModel::rowCount(const QModelIndex &parent) const
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(parent);
 | 
			
		||||
 | 
			
		||||
    return groups.length();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ActionsGroupsModel::columnCount(const QModelIndex &parent) const
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(parent);
 | 
			
		||||
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QModelIndex ActionsGroupsModel::index(int row, int column, const QModelIndex &parent) const
 | 
			
		||||
{
 | 
			
		||||
    if (!hasIndex(row, column, parent))
 | 
			
		||||
        return QModelIndex();
 | 
			
		||||
 | 
			
		||||
    return createIndex(row, column);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QVariant ActionsGroupsModel::data(const QModelIndex &index, int role) const
 | 
			
		||||
{
 | 
			
		||||
    if (!index.isValid())
 | 
			
		||||
        return QVariant();
 | 
			
		||||
 | 
			
		||||
    if (role == Qt::DecorationRole)
 | 
			
		||||
        return QVariant(groups.at(index.row()).getIcon());
 | 
			
		||||
 | 
			
		||||
    if (role != Qt::DisplayRole)
 | 
			
		||||
        return QVariant();
 | 
			
		||||
 | 
			
		||||
    return QVariant(groups[index.row()].getName());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QModelIndex ActionsGroupsModel::parent(const QModelIndex &index) const
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(index);
 | 
			
		||||
 | 
			
		||||
    return QModelIndex();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ActionsGroupsModel::addActionsGroup(const ActionsGroup &group)
 | 
			
		||||
{
 | 
			
		||||
    beginInsertRows(QModelIndex(),groups.length(),groups.length());
 | 
			
		||||
    groups.push_back(group);
 | 
			
		||||
    endInsertRows();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QList<QAction *> ActionsGroupsModel::getActions(const QModelIndex &mi)
 | 
			
		||||
{
 | 
			
		||||
    if(mi.isValid())
 | 
			
		||||
        return groups[mi.row()].getActions();
 | 
			
		||||
    return QList<QAction *>();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//-------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
ActionsGroup::ActionsGroup(const QString &name, const QIcon &icon, QList<QAction *> &actions)
 | 
			
		||||
    :name(name), icon(icon), actions(actions)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString ActionsGroup::getName() const
 | 
			
		||||
{
 | 
			
		||||
    return name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QIcon ActionsGroup::getIcon() const
 | 
			
		||||
{
 | 
			
		||||
    return icon;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QList<QAction *> ActionsGroup::getActions() const
 | 
			
		||||
{
 | 
			
		||||
    return actions;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										44
									
								
								shortcuts_management/actions_groups_model.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								shortcuts_management/actions_groups_model.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,44 @@
 | 
			
		||||
#ifndef ACTIONS_GROUPS_MODEL_H
 | 
			
		||||
#define ACTIONS_GROUPS_MODEL_H
 | 
			
		||||
 | 
			
		||||
#include <QAbstractItemModel>
 | 
			
		||||
#include <QIcon>
 | 
			
		||||
 | 
			
		||||
class QAction;
 | 
			
		||||
 | 
			
		||||
class ActionsGroup
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    ActionsGroup(const QString & name, const QIcon & icon, QList<QAction *> & actions);
 | 
			
		||||
    QString getName() const;
 | 
			
		||||
    QIcon getIcon() const;
 | 
			
		||||
    QList<QAction *> getActions() const;
 | 
			
		||||
protected:
 | 
			
		||||
    QString name;
 | 
			
		||||
    QIcon icon;
 | 
			
		||||
    QList<QAction *> actions;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class ActionsGroupsModel : public QAbstractItemModel
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
    explicit ActionsGroupsModel(QObject *parent = 0);
 | 
			
		||||
 | 
			
		||||
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
 | 
			
		||||
    int columnCount(const QModelIndex &parent = QModelIndex()) const;
 | 
			
		||||
    QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
 | 
			
		||||
    QVariant data(const QModelIndex &index, int role) const;
 | 
			
		||||
    QModelIndex parent(const QModelIndex &index) const;
 | 
			
		||||
 | 
			
		||||
    void addActionsGroup(const ActionsGroup & group);
 | 
			
		||||
    QList<QAction *> getActions(const QModelIndex & mi);
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    QList<ActionsGroup> groups;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // ACTIONS_GROUPS_MODEL_H
 | 
			
		||||
							
								
								
									
										114
									
								
								shortcuts_management/actions_shortcuts_model.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										114
									
								
								shortcuts_management/actions_shortcuts_model.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,114 @@
 | 
			
		||||
#include "actions_shortcuts_model.h"
 | 
			
		||||
#include "shortcuts_manager.h"
 | 
			
		||||
 | 
			
		||||
#include <QAction>
 | 
			
		||||
 | 
			
		||||
ActionsShortcutsModel::ActionsShortcutsModel(QObject *parent) :
 | 
			
		||||
    QAbstractItemModel(parent)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ActionsShortcutsModel::rowCount(const QModelIndex &parent) const
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(parent);
 | 
			
		||||
 | 
			
		||||
    return actions.length();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ActionsShortcutsModel::columnCount(const QModelIndex &parent) const
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(parent);
 | 
			
		||||
 | 
			
		||||
    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::ForegroundRole && index.column() == KEYS && actions[index.row()]->shortcut().isEmpty())
 | 
			
		||||
        return QBrush(QColor("#AAAAAA"));
 | 
			
		||||
 | 
			
		||||
    if (role != Qt::DisplayRole)
 | 
			
		||||
        return QVariant();
 | 
			
		||||
 | 
			
		||||
    if (index.column() == NAME)
 | 
			
		||||
        return QVariant(actions[index.row()]->toolTip());
 | 
			
		||||
    if (index.column() == KEYS)
 | 
			
		||||
    {
 | 
			
		||||
        QKeySequence ks = actions[index.row()]->shortcut();
 | 
			
		||||
        if(ks.isEmpty())
 | 
			
		||||
            return tr("None");
 | 
			
		||||
        return QVariant(ks.toString(QKeySequence::NativeText));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return QVariant();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ActionsShortcutsModel::setData(const QModelIndex &index, const QVariant &value, int role)
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(role);
 | 
			
		||||
 | 
			
		||||
    if(index.column() == KEYS)
 | 
			
		||||
    {
 | 
			
		||||
        ShortcutsManager sm = ShortcutsManager::getShortcutsManager();
 | 
			
		||||
        if(sm.checkConflicts(value.toString(), actions[index.row()]))
 | 
			
		||||
            emit conflict(value.toString());
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            actions[index.row()]->setShortcut(value.toString());
 | 
			
		||||
            ShortcutsManager::getShortcutsManager().saveShortcut(actions[index.row()]);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QModelIndex ActionsShortcutsModel::parent(const QModelIndex &index) const
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(index);
 | 
			
		||||
 | 
			
		||||
    return QModelIndex();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ActionsShortcutsModel::addActions(const QList<QAction *> actions)
 | 
			
		||||
{
 | 
			
		||||
    beginResetModel();
 | 
			
		||||
    this->actions = actions;
 | 
			
		||||
    endResetModel();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										38
									
								
								shortcuts_management/actions_shortcuts_model.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								shortcuts_management/actions_shortcuts_model.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,38 @@
 | 
			
		||||
#ifndef ACTIONS_SHORTCUTS_MODEL_H
 | 
			
		||||
#define ACTIONS_SHORTCUTS_MODEL_H
 | 
			
		||||
 | 
			
		||||
#include <QAbstractItemModel>
 | 
			
		||||
 | 
			
		||||
class QAction;
 | 
			
		||||
 | 
			
		||||
class ActionsShortcutsModel : public QAbstractItemModel
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
    explicit ActionsShortcutsModel(QObject *parent = 0);
 | 
			
		||||
 | 
			
		||||
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
 | 
			
		||||
    int columnCount(const QModelIndex &parent = QModelIndex()) const;
 | 
			
		||||
    QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
 | 
			
		||||
    QVariant data(const QModelIndex &index, int role) const;
 | 
			
		||||
    bool setData(const QModelIndex &index, const QVariant &value, int role);
 | 
			
		||||
    QModelIndex parent(const QModelIndex &index) const;
 | 
			
		||||
 | 
			
		||||
    void addActions(const QList<QAction *> actions);
 | 
			
		||||
    Qt::ItemFlags flags(const QModelIndex &index) const;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    enum Columns {
 | 
			
		||||
        ICON = 0,
 | 
			
		||||
        NAME,
 | 
			
		||||
        KEYS
 | 
			
		||||
    };
 | 
			
		||||
signals:
 | 
			
		||||
    void conflict(QString);
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    QList<QAction *> actions;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // ACTIONS_SHORTCUTS_MODEL_H
 | 
			
		||||
							
								
								
									
										150
									
								
								shortcuts_management/edit_shortcut_item_delegate.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										150
									
								
								shortcuts_management/edit_shortcut_item_delegate.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,150 @@
 | 
			
		||||
#include "edit_shortcut_item_delegate.h"
 | 
			
		||||
 | 
			
		||||
#include <QAction>
 | 
			
		||||
 | 
			
		||||
EditShortcutItemDelegate::EditShortcutItemDelegate(QObject *parent) :
 | 
			
		||||
    QItemDelegate(parent)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QWidget *EditShortcutItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(option);
 | 
			
		||||
    Q_UNUSED(index);
 | 
			
		||||
 | 
			
		||||
    KeySequenceLineEdit * editor = new KeySequenceLineEdit(parent);
 | 
			
		||||
    connect(editor,SIGNAL(editingFinished()),this,SLOT(closeShortcutEditor()));
 | 
			
		||||
    return editor;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EditShortcutItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
 | 
			
		||||
{
 | 
			
		||||
    QString value = index.model()->data(index, Qt::DisplayRole).toString();
 | 
			
		||||
 | 
			
		||||
    KeySequenceLineEdit * lineEdit = static_cast<KeySequenceLineEdit*>(editor);
 | 
			
		||||
    lineEdit->setText(value);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EditShortcutItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
 | 
			
		||||
{
 | 
			
		||||
    KeySequenceLineEdit *lineEdit = static_cast<KeySequenceLineEdit*>(editor);
 | 
			
		||||
 | 
			
		||||
    model->setData(index, lineEdit->text(), Qt::EditRole);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EditShortcutItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &mi) const
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(mi);
 | 
			
		||||
 | 
			
		||||
   editor->setGeometry(option.rect);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool EditShortcutItemDelegate::eventFilter(QObject* editor, QEvent* event)
 | 
			
		||||
{
 | 
			
		||||
     if(event->type()==QEvent::KeyPress)
 | 
			
		||||
          return false;
 | 
			
		||||
     return QItemDelegate::eventFilter(editor, event);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EditShortcutItemDelegate::closeShortcutEditor()
 | 
			
		||||
{
 | 
			
		||||
    emit commitData(static_cast<QWidget *>(sender()));
 | 
			
		||||
    emit closeEditor(static_cast<QWidget *>(sender()),QAbstractItemDelegate::NoHint);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//TODO uncoment commented code for enabling concatenated shortcuts
 | 
			
		||||
KeySequenceLineEdit::KeySequenceLineEdit(QWidget *parent)
 | 
			
		||||
    :QLineEdit(parent)//,numKeys(0)
 | 
			
		||||
{
 | 
			
		||||
    //keys[0] = keys[1] = keys[2] = keys[3] = 0;
 | 
			
		||||
    setAlignment(Qt::AlignRight);
 | 
			
		||||
 | 
			
		||||
    QPixmap clearPixmap(":/images/clear_shortcut.png");
 | 
			
		||||
    QPixmap acceptPixmap(":/images/accept_shortcut.png");
 | 
			
		||||
 | 
			
		||||
    clearButton = new QToolButton(this);
 | 
			
		||||
    acceptButton = new QToolButton(this);
 | 
			
		||||
    QString buttonsStyle = "QToolButton { border: none; padding: 0px; }";
 | 
			
		||||
 | 
			
		||||
    clearButton->setIcon(QIcon(clearPixmap));
 | 
			
		||||
    clearButton->setIconSize(clearPixmap.size());
 | 
			
		||||
    clearButton->setCursor(Qt::ArrowCursor);
 | 
			
		||||
    clearButton->setStyleSheet(buttonsStyle);
 | 
			
		||||
 | 
			
		||||
    acceptButton->setIcon(QIcon(acceptPixmap));
 | 
			
		||||
    acceptButton->setIconSize(acceptPixmap.size());
 | 
			
		||||
    acceptButton->setCursor(Qt::ArrowCursor);
 | 
			
		||||
    acceptButton->setStyleSheet(buttonsStyle);
 | 
			
		||||
 | 
			
		||||
    connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
 | 
			
		||||
    connect(acceptButton, SIGNAL(clicked()), this, SIGNAL(editingFinished()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void KeySequenceLineEdit::resizeEvent(QResizeEvent * e)
 | 
			
		||||
{
 | 
			
		||||
    QSize szClear = clearButton->sizeHint();
 | 
			
		||||
    //int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
 | 
			
		||||
    int leftMargin = style()->pixelMetric(QStyle::PM_LayoutLeftMargin);
 | 
			
		||||
    //int topMargin = style()->pixelMetric(QStyle::PM_LayoutTopMargin);
 | 
			
		||||
    clearButton->move(0 + leftMargin,(e->size().height()-19)/2); //16 is the icon height+1blank pixel
 | 
			
		||||
 | 
			
		||||
    acceptButton->move( leftMargin + szClear.width(),(e->size().height()-19)/2);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void KeySequenceLineEdit::keyPressEvent(QKeyEvent * e)
 | 
			
		||||
{
 | 
			
		||||
    int key = e->key();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    //if ( numKeys > 3 ||
 | 
			
		||||
    if ( key == Qt::Key_Control ||
 | 
			
		||||
         key == Qt::Key_Shift ||
 | 
			
		||||
         key == Qt::Key_Meta ||
 | 
			
		||||
         key == Qt::Key_Alt )
 | 
			
		||||
         return;
 | 
			
		||||
 | 
			
		||||
    key |= translateModifiers(e->modifiers(), e->text());
 | 
			
		||||
 | 
			
		||||
    /*switch (numKeys) {
 | 
			
		||||
        case 0:
 | 
			
		||||
            keys[0] = nextKey;
 | 
			
		||||
            break;
 | 
			
		||||
        case 1:
 | 
			
		||||
            keys[1] = nextKey;
 | 
			
		||||
            break;
 | 
			
		||||
        case 2:
 | 
			
		||||
            keys[2] = nextKey;
 | 
			
		||||
            break;
 | 
			
		||||
        case 3:
 | 
			
		||||
            keys[3] = nextKey;
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            break;
 | 
			
		||||
    }*/
 | 
			
		||||
    //numKeys++;
 | 
			
		||||
    QKeySequence keySequence = QKeySequence(key);
 | 
			
		||||
    setText(keySequence.toString(QKeySequence::NativeText));
 | 
			
		||||
    e->accept();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int KeySequenceLineEdit::translateModifiers(Qt::KeyboardModifiers state,
 | 
			
		||||
                                         const QString &text)
 | 
			
		||||
{
 | 
			
		||||
    int result = 0;
 | 
			
		||||
    // The shift modifier only counts when it is not used to type a symbol
 | 
			
		||||
    // that is only reachable using the shift key anyway
 | 
			
		||||
    if ((state & Qt::ShiftModifier) && (text.size() == 0
 | 
			
		||||
                                        || !text.at(0).isPrint()
 | 
			
		||||
                                        || text.at(0).isLetterOrNumber()
 | 
			
		||||
                                        || text.at(0).isSpace()))
 | 
			
		||||
        result |= Qt::SHIFT;
 | 
			
		||||
    if (state & Qt::ControlModifier)
 | 
			
		||||
        result |= Qt::CTRL;
 | 
			
		||||
    if (state & Qt::MetaModifier)
 | 
			
		||||
        result |= Qt::META;
 | 
			
		||||
    if (state & Qt::AltModifier)
 | 
			
		||||
        result |= Qt::ALT;
 | 
			
		||||
    return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										48
									
								
								shortcuts_management/edit_shortcut_item_delegate.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								shortcuts_management/edit_shortcut_item_delegate.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,48 @@
 | 
			
		||||
#ifndef EDIT_SHORTCUT_ITEM_DELEGATE_H
 | 
			
		||||
#define EDIT_SHORTCUT_ITEM_DELEGATE_H
 | 
			
		||||
 | 
			
		||||
#include <QItemDelegate>
 | 
			
		||||
#include <QLineEdit>
 | 
			
		||||
#include <QKeyEvent>
 | 
			
		||||
#include <QKeySequence>
 | 
			
		||||
#include <QToolButton>
 | 
			
		||||
 | 
			
		||||
class KeySequenceLineEdit : public QLineEdit
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
    explicit KeySequenceLineEdit(QWidget *parent = 0);
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    //int numKeys;
 | 
			
		||||
    //int keys[4];
 | 
			
		||||
    void keyPressEvent(QKeyEvent *);
 | 
			
		||||
    int translateModifiers(Qt::KeyboardModifiers state, const QString &text);
 | 
			
		||||
    void resizeEvent(QResizeEvent *);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    QToolButton *clearButton;
 | 
			
		||||
    QToolButton *acceptButton;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class EditShortcutItemDelegate : public QItemDelegate
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
    explicit EditShortcutItemDelegate(QObject *parent = 0);
 | 
			
		||||
 | 
			
		||||
    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
 | 
			
		||||
                          const QModelIndex &index) const;
 | 
			
		||||
    void setEditorData(QWidget *editor, const QModelIndex &index) const;
 | 
			
		||||
    void setModelData(QWidget *editor, QAbstractItemModel *model,
 | 
			
		||||
                      const QModelIndex &index) const;
 | 
			
		||||
    void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex & mi) const;
 | 
			
		||||
    bool eventFilter(QObject *editor, QEvent *event);
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    void closeShortcutEditor();
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // EDIT_SHORTCUT_ITEM_DELEGATE_H
 | 
			
		||||
							
								
								
									
										97
									
								
								shortcuts_management/edit_shortcuts_dialog.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								shortcuts_management/edit_shortcuts_dialog.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,97 @@
 | 
			
		||||
#include "edit_shortcuts_dialog.h"
 | 
			
		||||
 | 
			
		||||
#include "actions_groups_model.h"
 | 
			
		||||
#include "actions_shortcuts_model.h"
 | 
			
		||||
#include "edit_shortcut_item_delegate.h"
 | 
			
		||||
 | 
			
		||||
#include <QVBoxLayout>
 | 
			
		||||
#include <QSplitter>
 | 
			
		||||
#include <QListView>
 | 
			
		||||
#include <QTableView>
 | 
			
		||||
#include <QPushButton>
 | 
			
		||||
#include <QHeaderView>
 | 
			
		||||
#include <QLabel>
 | 
			
		||||
#include <QMessageBox>
 | 
			
		||||
 | 
			
		||||
#include "QsLog.h"
 | 
			
		||||
 | 
			
		||||
EditShortcutsDialog::EditShortcutsDialog(QWidget *parent) :
 | 
			
		||||
    QDialog(parent)
 | 
			
		||||
{
 | 
			
		||||
    QPushButton * resetButton = new QPushButton(tr("Restore defaults"),this);
 | 
			
		||||
    QLabel * infoLabel = new QLabel(tr("To change a shortcut, double click in the key combination and type the new keys."));
 | 
			
		||||
    QVBoxLayout * layout = new QVBoxLayout(this);
 | 
			
		||||
    QSplitter * splitter = new QSplitter(this);
 | 
			
		||||
    actionsGroupsListView = new QListView(this);
 | 
			
		||||
 | 
			
		||||
    actionsTableView = new QTableView(this);
 | 
			
		||||
    actionsTableView->verticalHeader()->setHidden(true);
 | 
			
		||||
    actionsTableView->horizontalHeader()->setHidden(true);
 | 
			
		||||
    splitter->addWidget(actionsGroupsListView);
 | 
			
		||||
    splitter->addWidget(actionsTableView);
 | 
			
		||||
    splitter->setStretchFactor(1,1);
 | 
			
		||||
    splitter->setSizes(QList<int>() << 200 << 400);
 | 
			
		||||
 | 
			
		||||
    layout->addWidget(infoLabel,0);
 | 
			
		||||
    layout->addWidget(splitter,1);
 | 
			
		||||
    layout->addWidget(resetButton,0,Qt::AlignRight);
 | 
			
		||||
 | 
			
		||||
    setLayout(layout);
 | 
			
		||||
 | 
			
		||||
    groupsModel = new ActionsGroupsModel();
 | 
			
		||||
    actionsModel = new ActionsShortcutsModel();
 | 
			
		||||
    actionsGroupsListView->setModel(groupsModel);
 | 
			
		||||
    actionsGroupsListView->setFocus();
 | 
			
		||||
    actionsTableView->setModel(actionsModel);
 | 
			
		||||
    actionsTableView->setColumnWidth(0,30);
 | 
			
		||||
    actionsTableView->setColumnWidth(1,360);
 | 
			
		||||
    //actionsTableView->horizontalHeader()->sectionResizeMode(QHeaderView::Custom);
 | 
			
		||||
    actionsTableView->horizontalHeader()->setStretchLastSection(true);
 | 
			
		||||
    actionsTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
 | 
			
		||||
    actionsTableView->setShowGrid(false);
 | 
			
		||||
    actionsTableView->setItemDelegateForColumn(ActionsShortcutsModel::KEYS,new EditShortcutItemDelegate(this));
 | 
			
		||||
    actionsTableView->installEventFilter(this);
 | 
			
		||||
    /*actionsTableView->setStyleSheet("QTableView {outline: 0px;}"
 | 
			
		||||
                                      "QTableView::item {outline: 0px;}");
 | 
			
		||||
                                      "QTableView {border:0px;}"
 | 
			
		||||
                                      "QTableView::item:selected {outline: 0px; border: 0px;}"
 | 
			
		||||
                                      "");*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    connect(resetButton,SIGNAL(clicked()),this,SLOT(resetToDefaults()));
 | 
			
		||||
    connect(actionsGroupsListView->selectionModel(),SIGNAL(currentChanged(QModelIndex,QModelIndex)),this,SLOT(loadShortcuts(QModelIndex,QModelIndex))); //clicked(QModelIndex) doesn't work :S
 | 
			
		||||
    connect(actionsModel,SIGNAL(conflict(QString)),this,SLOT(processConflict(QString)));
 | 
			
		||||
 | 
			
		||||
#ifdef Q_OS_MAC
 | 
			
		||||
    setFixedSize(760,500);
 | 
			
		||||
#else
 | 
			
		||||
    setFixedSize(804,500); //extra width for modifiers
 | 
			
		||||
#endif
 | 
			
		||||
    setWindowTitle(tr("Shortcuts settings"));
 | 
			
		||||
 | 
			
		||||
    setModal(true);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EditShortcutsDialog::addActionsGroup(const QString &name, const QIcon &ico, QList<QAction *> &group)
 | 
			
		||||
{
 | 
			
		||||
    groupsModel->addActionsGroup(ActionsGroup(name,ico,group));
 | 
			
		||||
    if(actionsTableView->model()->rowCount()==0)//first group added
 | 
			
		||||
        actionsGroupsListView->selectionModel()->select(groupsModel->index(0,0),QItemSelectionModel::Select);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EditShortcutsDialog::resetToDefaults()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EditShortcutsDialog::loadShortcuts(const QModelIndex &mi,const QModelIndex &mi2)
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(mi2);
 | 
			
		||||
 | 
			
		||||
    actionsModel->addActions(groupsModel->getActions(mi));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EditShortcutsDialog::processConflict(const QString &shortcutInConflict)
 | 
			
		||||
{
 | 
			
		||||
    QMessageBox::warning(this,tr("Shortcut in use"), QString(tr("The shortcut \"%1\" is already assigned to other function")).arg(shortcutInConflict));
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										33
									
								
								shortcuts_management/edit_shortcuts_dialog.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								shortcuts_management/edit_shortcuts_dialog.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,33 @@
 | 
			
		||||
#ifndef EDIT_SHORTCUTS_DIALOG_H
 | 
			
		||||
#define EDIT_SHORTCUTS_DIALOG_H
 | 
			
		||||
 | 
			
		||||
#include <QDialog>
 | 
			
		||||
#include <QModelIndex>
 | 
			
		||||
 | 
			
		||||
class QListView;
 | 
			
		||||
class QTableView;
 | 
			
		||||
 | 
			
		||||
class ActionsGroupsModel;
 | 
			
		||||
class ActionsShortcutsModel;
 | 
			
		||||
 | 
			
		||||
class EditShortcutsDialog : public QDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
    explicit EditShortcutsDialog(QWidget * parent = 0);
 | 
			
		||||
    void addActionsGroup(const QString & name, const QIcon & ico, QList<QAction *> & group);
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    void resetToDefaults();
 | 
			
		||||
    void loadShortcuts(const QModelIndex & mi,const QModelIndex &mi2);
 | 
			
		||||
    void processConflict(const QString & shortcutInConflict);
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    QListView * actionsGroupsListView;
 | 
			
		||||
    QTableView * actionsTableView;
 | 
			
		||||
    ActionsGroupsModel * groupsModel;
 | 
			
		||||
    ActionsShortcutsModel * actionsModel;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // EDIT_SHORTCUTS_DIALOG_H
 | 
			
		||||
							
								
								
									
										16
									
								
								shortcuts_management/shortcuts_management.pri
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								shortcuts_management/shortcuts_management.pri
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
			
		||||
INCLUDEPATH += $$PWD
 | 
			
		||||
DEPENDPATH += $$PWD
 | 
			
		||||
 | 
			
		||||
HEADERS += \
 | 
			
		||||
    $$PWD/edit_shortcuts_dialog.h \
 | 
			
		||||
    $$PWD/actions_groups_model.h \
 | 
			
		||||
    $$PWD/actions_shortcuts_model.h \
 | 
			
		||||
    $$PWD/edit_shortcut_item_delegate.h \
 | 
			
		||||
    $$PWD/shortcuts_manager.h
 | 
			
		||||
 | 
			
		||||
SOURCES += \
 | 
			
		||||
    $$PWD/edit_shortcuts_dialog.cpp \
 | 
			
		||||
    $$PWD/actions_groups_model.cpp \
 | 
			
		||||
    $$PWD/actions_shortcuts_model.cpp \
 | 
			
		||||
    $$PWD/edit_shortcut_item_delegate.cpp \
 | 
			
		||||
    $$PWD/shortcuts_manager.cpp
 | 
			
		||||
							
								
								
									
										129
									
								
								shortcuts_management/shortcuts_manager.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										129
									
								
								shortcuts_management/shortcuts_manager.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,129 @@
 | 
			
		||||
#include "shortcuts_manager.h"
 | 
			
		||||
 | 
			
		||||
#include <QSettings>
 | 
			
		||||
#include <QAction>
 | 
			
		||||
#include "yacreader_global.h"
 | 
			
		||||
 | 
			
		||||
ShortcutsManager::ShortcutsManager()
 | 
			
		||||
{
 | 
			
		||||
    initDefaultShorcuts();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ShortcutsManager::initDefaultShorcuts()
 | 
			
		||||
{
 | 
			
		||||
#ifdef YACREADER_LIBRARY
 | 
			
		||||
    //ACTIONS
 | 
			
		||||
    defaultShorcuts.insert(CREATE_LIBRARY_ACTION_YL,Qt::Key_A);
 | 
			
		||||
    defaultShorcuts.insert(OPEN_LIBRARY_ACTION_YL,Qt::Key_O);
 | 
			
		||||
    defaultShorcuts.insert(UPDATE_LIBRARY_ACTION_YL,Qt::Key_U);
 | 
			
		||||
    defaultShorcuts.insert(RENAME_LIBRARY_ACTION_YL,Qt::Key_R);
 | 
			
		||||
    defaultShorcuts.insert(OPEN_COMIC_ACTION_YL,Qt::Key_Return);
 | 
			
		||||
    defaultShorcuts.insert(SHOW_HIDE_MARKS_ACTION_YL,Qt::Key_M);
 | 
			
		||||
    defaultShorcuts.insert(TOGGLE_FULL_SCREEN_ACTION_YL,Qt::Key_F);
 | 
			
		||||
    defaultShorcuts.insert(HELP_ABOUT_ACTION_YL,Qt::Key_F1);
 | 
			
		||||
    defaultShorcuts.insert(SET_ROOT_INDEX_ACTION_YL,Qt::Key_0);
 | 
			
		||||
    defaultShorcuts.insert(EXPAND_ALL_NODES_ACTION_YL,Qt::Key_Plus);
 | 
			
		||||
    defaultShorcuts.insert(COLAPSE_ALL_NODES_ACTION_YL,Qt::Key_Minus);
 | 
			
		||||
    defaultShorcuts.insert(OPTIONS_ACTION_YL,Qt::Key_C);
 | 
			
		||||
    defaultShorcuts.insert(SERVER_CONFIG_ACTION_YL,Qt::Key_S);
 | 
			
		||||
    defaultShorcuts.insert(TOGGLE_COMICS_VIEW_ACTION_YL,Qt::Key_V);
 | 
			
		||||
 | 
			
		||||
    //COMMANDS (used in keypressevent)
 | 
			
		||||
#else
 | 
			
		||||
    defaultShorcuts.insert(OPEN_ACTION_Y, Qt::Key_O);
 | 
			
		||||
    defaultShorcuts.insert(OPEN_FOLDER_ACTION_Y, Qt::CTRL | Qt::Key_O);
 | 
			
		||||
    defaultShorcuts.insert(OPEN_PREVIOUS_COMIC_ACTION_Y, Qt::CTRL | Qt::Key_Left);
 | 
			
		||||
    defaultShorcuts.insert(OPEN_NEXT_COMIC_ACTION_Y, Qt::CTRL | Qt::Key_Right);
 | 
			
		||||
    defaultShorcuts.insert(PREV_ACTION_Y, Qt::Key_Left);
 | 
			
		||||
    defaultShorcuts.insert(NEXT_ACTION_Y, Qt::Key_Right);
 | 
			
		||||
    defaultShorcuts.insert(LEFT_ROTATION_ACTION_Y, Qt::Key_L);
 | 
			
		||||
    defaultShorcuts.insert(RIGHT_ROTATION_ACTION_Y, Qt::Key_R);
 | 
			
		||||
    defaultShorcuts.insert(DOUBLE_PAGE_ACTION_Y, Qt::Key_D);
 | 
			
		||||
    defaultShorcuts.insert(DOUBLE_MANGA_PAGE_ACTION_Y, Qt::Key_J);
 | 
			
		||||
    defaultShorcuts.insert(GO_TO_PAGE_ACTION_Y, Qt::Key_G);
 | 
			
		||||
    defaultShorcuts.insert(OPTIONS_ACTION_Y, Qt::Key_C);
 | 
			
		||||
    defaultShorcuts.insert(HELP_ABOUT_ACTION_Y, Qt::Key_F1);
 | 
			
		||||
    defaultShorcuts.insert(SHOW_MAGNIFYING_GLASS_ACTION_Y, Qt::Key_Z);
 | 
			
		||||
    defaultShorcuts.insert(SET_BOOKMARK_ACTION_Y, Qt::CTRL | Qt::Key_M);
 | 
			
		||||
    defaultShorcuts.insert(SHOW_BOOKMARKS_ACTION_Y, Qt::Key_M);
 | 
			
		||||
    defaultShorcuts.insert(SHOW_INFO_ACTION_Y, Qt::Key_I);
 | 
			
		||||
    defaultShorcuts.insert(CLOSE_ACTION_Y, Qt::Key_Escape);
 | 
			
		||||
    defaultShorcuts.insert(SHOW_DICTIONARY_ACTION_Y, Qt::Key_T);
 | 
			
		||||
    defaultShorcuts.insert(ALWAYS_ON_TOP_ACTION_Y, Qt::Key_Q); //deprecated
 | 
			
		||||
    defaultShorcuts.insert(ADJUST_TO_FULL_SIZE_ACTION_Y, Qt::Key_W);
 | 
			
		||||
    defaultShorcuts.insert(SHOW_FLOW_ACTION_Y, Qt::Key_S);
 | 
			
		||||
    defaultShorcuts.insert(ZOOM_PLUS_ACTION_Y, Qt::Key_Plus);
 | 
			
		||||
    defaultShorcuts.insert(ZOOM_MINUS_ACTION_Y, Qt::Key_Minus);
 | 
			
		||||
    defaultShorcuts.insert(RESET_ZOOM_ACTION_Y, Qt::CTRL | Qt::Key_0);
 | 
			
		||||
 | 
			
		||||
    //main_window_viewer
 | 
			
		||||
    defaultShorcuts.insert(TOGGLE_FULL_SCREEN_ACTION_Y, Qt::Key_F);
 | 
			
		||||
    defaultShorcuts.insert(TOGGLE_TOOL_BARS_ACTION_Y, Qt::Key_H);
 | 
			
		||||
    defaultShorcuts.insert(CHANGE_FIT_ACTION_Y, Qt::Key_A);
 | 
			
		||||
    //viewer
 | 
			
		||||
    defaultShorcuts.insert(AUTO_SCROLL_FORWARD_ACTION_Y, Qt::Key_Space);
 | 
			
		||||
    defaultShorcuts.insert(AUTO_SCROLL_BACKWARD_ACTION_Y, Qt::Key_B);
 | 
			
		||||
    defaultShorcuts.insert(MOVE_DOWN_ACTION_Y, Qt::Key_Down);
 | 
			
		||||
    defaultShorcuts.insert(MOVE_UP_ACTION_Y, Qt::Key_Up);
 | 
			
		||||
    defaultShorcuts.insert(GO_TO_FIRST_PAGE_ACTION_Y, Qt::Key_Home);
 | 
			
		||||
    defaultShorcuts.insert(GO_TO_LAST_PAGE_ACTION_Y, Qt::Key_End);
 | 
			
		||||
    //mglass
 | 
			
		||||
    defaultShorcuts.insert(SIZE_UP_MGLASS_ACTION_Y, Qt::Key_Plus);
 | 
			
		||||
    defaultShorcuts.insert(SIZE_DOWN_MGLASS_ACTION_Y, Qt::Key_Minus);
 | 
			
		||||
    defaultShorcuts.insert(ZOOM_IN_MGLASS_ACTION_Y, Qt::Key_Asterisk);
 | 
			
		||||
    defaultShorcuts.insert(ZOOM_OUT_MGLASS_ACTION_Y, Qt::Key_Underscore);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ShortcutsManager::resetToDefaults()
 | 
			
		||||
{
 | 
			
		||||
    //TODO reset to defaults
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString ShortcutsManager::getShortcut(const QString &name)
 | 
			
		||||
{
 | 
			
		||||
#ifdef YACREADER
 | 
			
		||||
    QString filePath = "/YACReader.ini";
 | 
			
		||||
#else
 | 
			
		||||
    QString filePath = "/YACReaderLibrary.ini";
 | 
			
		||||
#endif
 | 
			
		||||
    QSettings s(YACReader::getSettingsPath()+filePath,QSettings::IniFormat);
 | 
			
		||||
    s.beginGroup("shortcuts");
 | 
			
		||||
 | 
			
		||||
    return s.value(name,defaultShorcuts.value(name)).toString();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ShortcutsManager::saveShortcut(QAction *action)
 | 
			
		||||
{
 | 
			
		||||
#ifdef YACREADER
 | 
			
		||||
    QString filePath = "/YACReader.ini";
 | 
			
		||||
#else
 | 
			
		||||
    QString filePath = "/YACReaderLibrary.ini";
 | 
			
		||||
#endif
 | 
			
		||||
    QSettings s(YACReader::getSettingsPath()+filePath,QSettings::IniFormat);
 | 
			
		||||
    s.beginGroup("shortcuts");
 | 
			
		||||
 | 
			
		||||
    return s.setValue(action->data().toString() , action->shortcut().toString());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ShortcutsManager::registerActions(const QList<QAction *> &a)
 | 
			
		||||
{
 | 
			
		||||
    actions = a;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ShortcutsManager::checkConflicts(const QKeySequence & shortcut, const QAction *dest)
 | 
			
		||||
{
 | 
			
		||||
    if(shortcut.isEmpty())
 | 
			
		||||
        return false;
 | 
			
		||||
 | 
			
		||||
    foreach(QAction * action, actions)
 | 
			
		||||
    {
 | 
			
		||||
        if(action != dest) //if the same shortcut is setted there is no conflict
 | 
			
		||||
            if(action->shortcut() == shortcut)
 | 
			
		||||
                return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										140
									
								
								shortcuts_management/shortcuts_manager.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										140
									
								
								shortcuts_management/shortcuts_manager.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,140 @@
 | 
			
		||||
#ifndef SHORTCUTS_MANAGER_H
 | 
			
		||||
#define SHORTCUTS_MANAGER_H
 | 
			
		||||
 | 
			
		||||
#include <QObject>
 | 
			
		||||
#include <QKeySequence>
 | 
			
		||||
#include <QString>
 | 
			
		||||
#include <QMap>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class QAction;
 | 
			
		||||
 | 
			
		||||
//QAction: used setData() and data() for storing (userData) an identifier for each QAction. This value is ussed in QSettings
 | 
			
		||||
 | 
			
		||||
class ShortcutsManager
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    ShortcutsManager();
 | 
			
		||||
    QMap<QString,QKeySequence> defaultShorcuts;
 | 
			
		||||
    QList<QAction *> actions; //all actions registered, used for checking conflicts
 | 
			
		||||
 | 
			
		||||
    void initDefaultShorcuts();
 | 
			
		||||
public:
 | 
			
		||||
    static ShortcutsManager & getShortcutsManager()
 | 
			
		||||
    {
 | 
			
		||||
        static ShortcutsManager manager;
 | 
			
		||||
        return manager;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resetToDefaults();
 | 
			
		||||
    QString getShortcut(const QString & name);
 | 
			
		||||
    void saveShortcut(QAction * action);
 | 
			
		||||
    void registerActions(const QList<QAction *> & actions);
 | 
			
		||||
    bool checkConflicts(const QKeySequence &shortcut, const QAction *dest);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
//ACTION NAMES YACReaderLibrary
 | 
			
		||||
#define BACK_ACTION_YL "BACK_ACTION_YL"
 | 
			
		||||
#define FORWARD_ACTION_YL "FORWARD_ACTION_YL"
 | 
			
		||||
#define CREATE_LIBRARY_ACTION_YL "CREATE_LIBRARY_ACTION_YL"
 | 
			
		||||
#define OPEN_LIBRARY_ACTION_YL "OPEN_LIBRARY_ACTION_YL"
 | 
			
		||||
#define EXPORT_COMICS_INFO_ACTION_YL "EXPORT_COMICS_INFO_ACTION_YL"
 | 
			
		||||
#define IMPORT_COMICS_INFO_ACTION_YL "IMPORT_COMICS_INFO_ACTION_YL"
 | 
			
		||||
#define EXPORT_LIBRARY_ACTION_YL "EXPORT_LIBRARY_ACTION_YL"
 | 
			
		||||
#define IMPORT_LIBRARY_ACTION_YL "IMPORT_LIBRARY_ACTION_YL"
 | 
			
		||||
#define UPDATE_LIBRARY_ACTION_YL "UPDATE_LIBRARY_ACTION_YL"
 | 
			
		||||
#define RENAME_LIBRARY_ACTION_YL "RENAME_LIBRARY_ACTION_YL"
 | 
			
		||||
#define REMOVE_LIBRARY_ACTION_YL "REMOVE_LIBRARY_ACTION_YL"
 | 
			
		||||
#define OPEN_COMIC_ACTION_YL "OPEN_COMIC_ACTION_YL"
 | 
			
		||||
#define SET_AS_READ_ACTION_YL "SET_AS_READ_ACTION_YL"
 | 
			
		||||
#define SET_AS_NON_READ_ACTION_YL "SET_AS_NON_READ_ACTION_YL"
 | 
			
		||||
#define SHOW_HIDE_MARKS_ACTION_YL "SHOW_HIDE_MARKS_ACTION_YL"
 | 
			
		||||
#define TOGGLE_FULL_SCREEN_ACTION_YL "TOGGLE_FULL_SCREEN_ACTION_YL"
 | 
			
		||||
#define HELP_ABOUT_ACTION_YL "HELP_ABOUT_ACTION_YL"
 | 
			
		||||
#define SET_ROOT_INDEX_ACTION_YL "SET_ROOT_INDEX_ACTION_YL"
 | 
			
		||||
#define EXPAND_ALL_NODES_ACTION_YL "EXPAND_ALL_NODES_ACTION_YL"
 | 
			
		||||
#define COLAPSE_ALL_NODES_ACTION_YL "COLAPSE_ALL_NODES_ACTION_YL"
 | 
			
		||||
#define OPTIONS_ACTION_YL "OPTIONS_ACTION_YL"
 | 
			
		||||
#define SERVER_CONFIG_ACTION_YL "SERVER_CONFIG_ACTION_YL"
 | 
			
		||||
#define TOGGLE_COMICS_VIEW_ACTION_YL "TOGGLE_COMICS_VIEW_ACTION_YL"
 | 
			
		||||
#define OPEN_CONTAINING_FOLDER_ACTION_YL "OPEN_CONTAINING_FOLDER_ACTION_YL"
 | 
			
		||||
#define SET_FOLDER_AS_NOT_COMPLETED_ACTION_YL "SET_FOLDER_AS_NOT_COMPLETED_ACTION_YL"
 | 
			
		||||
#define SET_FOLDER_AS_COMPLETED_ACTION_YL "SET_FOLDER_AS_COMPLETED_ACTION_YL"
 | 
			
		||||
#define SET_FOLDER_AS_READ_ACTION_YL "SET_FOLDER_AS_READ_ACTION_YL"
 | 
			
		||||
#define SET_FOLDER_AS_UNREAD_ACTION_YL "SET_FOLDER_AS_UNREAD_ACTION_YL"
 | 
			
		||||
#define OPEN_CONTAINING_FOLDER_COMIC_ACTION_YL "OPEN_CONTAINING_FOLDER_COMIC_ACTION_YL"
 | 
			
		||||
#define RESET_COMIC_RATING_ACTION_YL "RESET_COMIC_RATING_ACTION_YL"
 | 
			
		||||
#define SELECT_ALL_COMICS_ACTION_YL "SELECT_ALL_COMICS_ACTION_YL"
 | 
			
		||||
#define EDIT_SELECTED_COMICS_ACTION_YL "EDIT_SELECTED_COMICS_ACTION_YL"
 | 
			
		||||
#define ASIGN_ORDER_ACTION_YL "ASIGN_ORDER_ACTION_YL"
 | 
			
		||||
#define FORCE_COVER_EXTRACTED_ACTION_YL "FORCE_COVER_EXTRACTED_ACTION_YL"
 | 
			
		||||
#define DELETE_COMICS_ACTION_YL "DELETE_COMICS_ACTION_YL"
 | 
			
		||||
#define HIDE_COMIC_VIEW_ACTION_YL "HIDE_COMIC_VIEW_ACTION_YL"
 | 
			
		||||
#define GET_INFO_ACTION_YL "GET_INFO_ACTION_YL"
 | 
			
		||||
#define SHOW_EDIT_SHORTCUTS_ACTION_YL "SHOW_EDIT_SHORTCUTS_ACTION_YL"
 | 
			
		||||
#define UPDATE_CURRENT_FOLDER_ACTION_YL "UPDATE_CURRENT_FOLDER_ACTION_YL"
 | 
			
		||||
#define ADD_FOLDER_ACTION_YL "ADD_FOLDER_ACTION_YL"
 | 
			
		||||
#define REMOVE_FOLDER_ACTION_YL "REMOVE_FOLDER_ACTION_YL"
 | 
			
		||||
#define ADD_READING_LIST_ACTION_YL "ADD_READING_LIST_ACTION_YL"
 | 
			
		||||
#define REMOVE_READING_LIST_ACTION_YL "REMOVE_READING_LIST_ACTION_YL"
 | 
			
		||||
#define ADD_LABEL_ACTION_YL "ADD_LABEL_ACTION_YL"
 | 
			
		||||
#define RENAME_LIST_ACTION_YL "RENAME_LIST_ACTION_YL"
 | 
			
		||||
#define ADD_TO_FAVORITES_ACTION_YL "ADD_TO_FAVORITES_ACTION_YL"
 | 
			
		||||
#define SAVE_COVERS_TO_ACTION_YL "SAVE_COVERS_TO_ACTION_YL"
 | 
			
		||||
//COMMANDS YACReaderLibrary
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//ACTION NAMES YACReader
 | 
			
		||||
#define OPEN_ACTION_Y "OPEN_ACTION_Y"
 | 
			
		||||
#define OPEN_FOLDER_ACTION_Y "OPEN_FOLDER_ACTION_Y"
 | 
			
		||||
#define SAVE_IMAGE_ACTION_Y "SAVE_IMAGE_ACTION_Y"
 | 
			
		||||
#define OPEN_PREVIOUS_COMIC_ACTION_Y "OPEN_PREVIOUS_COMIC_ACTION_Y"
 | 
			
		||||
#define OPEN_NEXT_COMIC_ACTION_Y "OPEN_NEXT_COMIC_ACTION_Y"
 | 
			
		||||
#define PREV_ACTION_Y "PREV_ACTION_Y"
 | 
			
		||||
#define NEXT_ACTION_Y "NEXT_ACTION_Y"
 | 
			
		||||
#define ADJUST_HEIGHT_ACTION_Y "ADJUST_HEIGHT_Y"
 | 
			
		||||
#define ADJUST_WIDTH_ACTION_Y "ADJUST_WIDTH_Y"
 | 
			
		||||
#define LEFT_ROTATION_ACTION_Y "LEFT_ROTATION_ACTION_Y"
 | 
			
		||||
#define RIGHT_ROTATION_ACTION_Y "RIGHT_ROTATION_ACTION_Y"
 | 
			
		||||
#define DOUBLE_PAGE_ACTION_Y "DOUBLE_PAGE_ACTION_Y"
 | 
			
		||||
#define DOUBLE_MANGA_PAGE_ACTION_Y "DOUBLE_MANGA_PAGE_ACTION_Y"
 | 
			
		||||
#define GO_TO_PAGE_ACTION_Y "GO_TO_PAGE_ACTION_Y"
 | 
			
		||||
#define OPTIONS_ACTION_Y "OPTIONS_ACTION_Y"
 | 
			
		||||
#define HELP_ABOUT_ACTION_Y "HELP_ABOUT_ACTION_Y"
 | 
			
		||||
#define SHOW_MAGNIFYING_GLASS_ACTION_Y "SHOW_MAGNIFYING_GLASS_ACTION_Y"
 | 
			
		||||
#define SET_BOOKMARK_ACTION_Y "SET_BOOKMARK_ACTION_Y"
 | 
			
		||||
#define SHOW_BOOKMARKS_ACTION_Y "SHOW_BOOKMARKS_ACTION_Y"
 | 
			
		||||
#define SHOW_SHORCUTS_ACTION_Y "SHOW_SHORCUTS_ACTION_Y"
 | 
			
		||||
#define SHOW_INFO_ACTION_Y "SHOW_INFO_ACTION_Y"
 | 
			
		||||
#define CLOSE_ACTION_Y "CLOSE_ACTION_Y"
 | 
			
		||||
#define SHOW_DICTIONARY_ACTION_Y "SHOW_DICTIONARY_ACTION_Y"
 | 
			
		||||
#define ALWAYS_ON_TOP_ACTION_Y "ALWAYS_ON_TOP_ACTION_Y"
 | 
			
		||||
#define ADJUST_TO_FULL_SIZE_ACTION_Y "ADJUST_TO_FULL_SIZE_ACTION_Y"
 | 
			
		||||
#define FIT_TO_PAGE_ACTION_Y "FIT_TO_PAGE_ACTION_Y"
 | 
			
		||||
#define SHOW_FLOW_ACTION_Y "SHOW_FLOW_ACTION_Y"
 | 
			
		||||
#define SHOW_EDIT_SHORTCUTS_ACTION_Y "SHOW_EDIT_SHORTCUTS_ACTION_Y"
 | 
			
		||||
 | 
			
		||||
//COMMANDS YACReader
 | 
			
		||||
//main_viewer_window
 | 
			
		||||
#define TOGGLE_FULL_SCREEN_ACTION_Y "TOGGLE_FULL_SCREEN_ACTION_Y"
 | 
			
		||||
#define TOGGLE_TOOL_BARS_ACTION_Y "TOGGLE_TOOL_BARS_ACTION_Y"
 | 
			
		||||
#define CHANGE_FIT_ACTION_Y "CHANGE_FIT_ACTION_Y"
 | 
			
		||||
#define ZOOM_PLUS_ACTION_Y "ZOOM_PLUS_ACTION_Y"
 | 
			
		||||
#define ZOOM_MINUS_ACTION_Y "ZOOM_MINUS_ACTION_Y"
 | 
			
		||||
#define RESET_ZOOM_ACTION_Y "RESET_ZOOM_ACTION_Y"
 | 
			
		||||
//viewer
 | 
			
		||||
#define AUTO_SCROLL_FORWARD_ACTION_Y "AUTO_SCROLL_FORWARD_ACTION_Y"
 | 
			
		||||
#define AUTO_SCROLL_BACKWARD_ACTION_Y "AUTO_SCROLL_BACKWARD_ACTION_Y"
 | 
			
		||||
#define MOVE_DOWN_ACTION_Y "MOVE_DOWN_ACTION_Y"
 | 
			
		||||
#define MOVE_UP_ACTION_Y "MOVE_UP_ACTION_Y"
 | 
			
		||||
#define MOVE_LEFT_ACTION_Y "MOVE_LEFT_ACTION_Y"
 | 
			
		||||
#define MOVE_RIGHT_ACTION_Y "MOVE_RIGHT_ACTION_Y"
 | 
			
		||||
#define GO_TO_FIRST_PAGE_ACTION_Y "GO_TO_FIRST_PAGE_ACTION_Y"
 | 
			
		||||
#define GO_TO_LAST_PAGE_ACTION_Y "GO_TO_LAST_PAGE_ACTION_Y"
 | 
			
		||||
//mglass
 | 
			
		||||
#define SIZE_UP_MGLASS_ACTION_Y "SIZE_UP_MGLASS_ACTION_Y"
 | 
			
		||||
#define SIZE_DOWN_MGLASS_ACTION_Y "SIZE_DOWN_MGLASS_ACTION_Y"
 | 
			
		||||
#define ZOOM_IN_MGLASS_ACTION_Y "ZOOM_IN_MGLASS_ACTION_Y"
 | 
			
		||||
#define ZOOM_OUT_MGLASS_ACTION_Y "ZOOM_OUT_MGLASS_ACTION_Y"
 | 
			
		||||
 | 
			
		||||
#endif // SHORTCUTS_MANAGER_H
 | 
			
		||||
		Reference in New Issue
	
	Block a user