File: keysequencehelper.h

package info (click to toggle)
kdeclarative 5.28.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 26,264 kB
  • ctags: 974
  • sloc: cpp: 7,094; sh: 33; makefile: 5
file content (148 lines) | stat: -rw-r--r-- 4,004 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * <one line to give the library's name and an idea of what it does.>
 * Copyright (C) 2014  David Edmundson <davidedmundson@kde.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#ifndef KEYSEQUENCEHELPER_H
#define KEYSEQUENCEHELPER_H

#include <QObject>
#include <QKeySequence>

/**
 * This class is a clone of Key from XMLGUI
 * It performs only the logic of building shortcuts
 * It is a private class to be used by KeySequenceItem
 *
 */

class KeySequenceHelperPrivate;

class KeySequenceHelper : public QObject
{
    Q_OBJECT

    Q_FLAGS(ShortcutTypes)

    Q_PROPERTY(
        QKeySequence keySequence
        READ keySequence
        WRITE setKeySequence
        NOTIFY keySequenceChanged)

    Q_PROPERTY(
        bool multiKeyShortcutsAllowed
        READ multiKeyShortcutsAllowed
        WRITE setMultiKeyShortcutsAllowed)

    Q_PROPERTY(
        QString shortcutDisplay
        READ shortcutDisplay
        NOTIFY shortcutDisplayChanged)

    Q_PROPERTY(
        bool modifierlessAllowed
        READ isModifierlessAllowed
        WRITE setModifierlessAllowed)

public:

    enum ShortcutType {
        None           = 0x00,      //!< No checking for conflicts
        StandardShortcuts = 0x01,   //!< Check against standard shortcuts. @see KStandardShortcut
        GlobalShortcuts = 0x02      //!< Check against global shortcuts. @see KGlobalAccel
    };
    Q_DECLARE_FLAGS(ShortcutTypes, ShortcutType)

    /**
    * Constructor.
    */
    explicit KeySequenceHelper(QObject* parent = 0);

    /**
    * Destructs the widget.
    */
    virtual ~KeySequenceHelper();

    /**
     * Allow multikey shortcuts?
     */
    void setMultiKeyShortcutsAllowed(bool);
    bool multiKeyShortcutsAllowed() const;

    /**
     * This only applies to user input, not to setShortcut().
     * Set whether to accept "plain" keys without modifiers (like Ctrl, Alt, Meta).
     * Plain keys by our definition include letter and symbol keys and
     * text editing keys (Return, Space, Tab, Backspace, Delete).
     * "Special" keys like F1, Cursor keys, Insert, PageDown will always work.
     */
    void setModifierlessAllowed(bool allow);

    /**
     * @see setModifierlessAllowed()
     */
    bool isModifierlessAllowed();


    bool isRecording() const;
    void setShortcut(bool recording);

    /**
     * Set the default key sequence from a string
     */
    void setKeySequence(const QKeySequence &sequence);

    /**
     * Return the currently selected key sequence as a string
     */
    QKeySequence keySequence() const;
    QString shortcutDisplay() const;

    bool isKeySequenceAvailable(const QKeySequence &keySequence) const;


Q_SIGNALS:
    void keySequenceChanged(const QKeySequence &seq);
    void shortcutDisplayChanged(const QString &string);
    void captureFinished();

public Q_SLOTS:
    void captureKeySequence();
    void keyPressed(int key, int modifiers);
    void keyReleased(int key, int modifiers);

   /**
    * Clear the key sequence.
    */
    void clearKeySequence();

private Q_SLOTS:
    void doneRecording();

private:
    friend class KeySequenceHelperPrivate;
    KeySequenceHelperPrivate *const d;

    Q_DISABLE_COPY(KeySequenceHelper)
};

Q_DECLARE_OPERATORS_FOR_FLAGS(KeySequenceHelper::ShortcutTypes)


#endif // KEYSEQUENCEHELPER_H