1 /*
2  * This file is part of Maliit Plugins
3  *
4  * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
5  *
6  * Contact: Mohammad Anwari <Mohammad.Anwari@nokia.com>
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * Redistributions of source code must retain the above copyright notice, this list
12  * of conditions and the following disclaimer.
13  * Redistributions in binary form must reproduce the above copyright notice, this list
14  * of conditions and the following disclaimer in the documentation and/or other materials
15  * provided with the distribution.
16  * Neither the name of Nokia Corporation nor the names of its contributors may be
17  * used to endorse or promote products derived from this software without specific
18  * prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23  * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  */
31 
32 #ifndef MALIIT_KEYBOARD_KEY_H
33 #define MALIIT_KEYBOARD_KEY_H
34 
35 #include "models/area.h"
36 
37 #include <QtCore>
38 
39 namespace MaliitKeyboard {
40 
41 class Key
42 {
43 public:
44     enum Action {
45         ActionInsert, //!< Key's label is inserted into text editor.
46         ActionShift, //!< Switches keyboard to shows uppercase variant.
47         ActionBackspace, //!< Key deletes previous character in text editor.
48         ActionSpace, //!< Key inserts space into text editor.
49         ActionCycle, //!< Key loops through set of characters when pressed in
50                      //!< rapid succession and inserts currently shown key
51                      //!< label into text editor after short time out.
52         ActionLayoutMenu, //!< Key brings up a menu to choose other language(s).
53         ActionSym, //!< Switches keyboard to symbol view.
54         ActionReturn, //!< Key inserts return into text editor.
55         ActionCommit, //!< Key commits preedit to text editor.
56         ActionDecimalSeparator, //!< Shown key is a decimal separator that
57                                 //!< might require localization.
58         ActionPlusMinusToggle,
59         ActionSwitch, //!< Key switches through symbol view pages.
60         ActionOnOffToggle,
61         ActionCompose, //!< Key is used to compose character.
62         ActionLeft, //!< Key moves cursor position to left, in text editor.
63         ActionUp, //!< Key moves cursor position to previous line, in text editor.
64         ActionRight, //!< Key moves cursor position to right, in text editor.
65         ActionDown, //!< Key moves cursor position to next line, in text editor.
66         ActionClose, //!< Key closes the virtual keyboard.
67         ActionCommand, //!< Key executes a command.
68         ActionTab, //!< Key moves cursor position by one tab, in text editor.
69         ActionDead, //!< Switches keyboard to deadkey variation, using key's label as lookup.
70         ActionLeftLayout, //!< Switch to left/previous language layout.
71         ActionRightLayout, //!< Switch to right/next language layout.
72         ActionHome, //!< Key moves cursor to beginning of text.
73         ActionEnd, //!< Key moves cursor to end of text.
74         NumActions
75     };
76 
77     enum Style {
78         StyleNormalKey,
79         StyleSpecialKey,
80         StyleDeadKey
81     };
82 
83 private:
84     QPoint m_origin;
85     Area m_area;
86     QString m_label;
87     Action m_action;
88     Style m_style;
89     QMargins m_margins;
90     QByteArray m_icon;
91     bool m_has_extended_keys: 1;
92     int m_flags_padding: 7;
93     QString m_command_sequence;
94 
95 public:
96     explicit Key();
97 
98     // read-only properties:
99     bool valid() const;
100     QRect rect() const;
101 
102     QPoint origin() const;
103     void setOrigin(const QPoint &origin);
104 
105     Area area() const;
106     Area & rArea();
107     void setArea(const Area &area);
108 
109     QString label() const;
110     QString & rLabel();
111     void setLabel(const QString &label);
112 
113     Action action() const;
114     void setAction(Action action);
115 
116     Style style() const;
117     void setStyle(Style style);
118 
119     QMargins margins() const;
120     void setMargins(const QMargins &margins);
121 
122     QByteArray icon() const;
123     void setIcon(const QByteArray &icon);
124 
125     bool hasExtendedKeys() const;
126     void setExtendedKeysEnabled(bool enable);
127 
128     QString commandSequence() const;
129     void setCommandSequence(const QString &command_sequence);
130 };
131 
132 bool operator==(const Key &lhs,
133                 const Key &rhs);
134 
135 bool operator!=(const Key &lhs,
136                 const Key &rhs);
137 
138 } // namespace MaliitKeyboard
139 
140 Q_DECLARE_METATYPE(MaliitKeyboard::Key)
141 
142 #endif // MALIIT_KEYBOARD_KEY_H
143