|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
|
19 * |
|
20 */ |
|
21 |
|
22 #include "capturerequest.h" |
|
23 |
|
24 #include <QAction> |
|
25 |
|
26 #include "mapping.h" |
|
27 |
|
28 CaptureRequest::CaptureRequest(Mapping *mapping_) |
|
29 { |
|
30 mRequestType = RequestTypeUndefined; |
|
31 mKey = Qt::Key_unknown; |
|
32 mModifiersMap = Qt::NoModifier; |
|
33 mModifier = Qt::NoModifier; |
|
34 mLongFlags = XQKeyCapture::LongNormal; |
|
35 |
|
36 this->mapping = mapping_; |
|
37 } |
|
38 |
|
39 CaptureRequest::~CaptureRequest() |
|
40 { |
|
41 } |
|
42 |
|
43 QString CaptureRequest::toString() |
|
44 { |
|
45 QString res = "Request "; |
|
46 |
|
47 switch (mRequestType) { |
|
48 case CaptureRequest::RequestTypeKey : |
|
49 res +="Key("; |
|
50 break; |
|
51 case CaptureRequest::RequestTypeLongKey : |
|
52 res +="LongKey("; |
|
53 break; |
|
54 case CaptureRequest::RequestTypeKeyUpAndDowns : |
|
55 res +="UpAndDowns("; |
|
56 break; |
|
57 case CaptureRequest::RequestTypeCancelKey : |
|
58 res +="CancelKey("; |
|
59 break; |
|
60 case CaptureRequest::RequestTypeCancelLongKey : |
|
61 res +="CancelLongKey("; |
|
62 break; |
|
63 case CaptureRequest::RequestTypeCancelKeyUpAndDowns : |
|
64 res +="CancelUpAndDowns("; |
|
65 break; |
|
66 default: |
|
67 res +="Unknown"; |
|
68 break; |
|
69 } |
|
70 |
|
71 if ( mRequestType == RequestTypeUndefined) |
|
72 return res; |
|
73 |
|
74 // res +=QString("%1").arg(mKey, 0, 16); |
|
75 |
|
76 res += mapping->name(mKey); |
|
77 |
|
78 res += QString("(0x%1)").arg(mKey, 0, 16); |
|
79 |
|
80 //TODO::put to res mModifiersMap |
|
81 //TODO::put to res mModifier |
|
82 if ( mRequestType == RequestTypeLongKey || mRequestType == RequestTypeCancelLongKey) |
|
83 res +=QString(",%1)").arg(mLongFlags, 0, 16); |
|
84 else |
|
85 res +=")"; |
|
86 |
|
87 return res; |
|
88 } |
|
89 |
|
90 bool CaptureRequest::setType(QAction* action) |
|
91 { |
|
92 if (!action) |
|
93 return false; |
|
94 |
|
95 bool ok; |
|
96 |
|
97 int act = action->data().toInt(&ok); |
|
98 |
|
99 if (ok){ |
|
100 switch (act){ |
|
101 case 1 : mRequestType = RequestTypeKey; break; |
|
102 case 2 : mRequestType = RequestTypeLongKey; break; |
|
103 case 3 : mRequestType = RequestTypeKeyUpAndDowns; break; |
|
104 case 4 : mRequestType = RequestTypeCancelKey; break; |
|
105 case 5 : mRequestType = RequestTypeCancelLongKey; break; |
|
106 case 6 : mRequestType = RequestTypeCancelKeyUpAndDowns; break; |
|
107 } |
|
108 return mRequestType!=RequestTypeUndefined; |
|
109 }else{ |
|
110 return false; |
|
111 } |
|
112 } |
|
113 |
|
114 bool CaptureRequest::setKey(QAction* action, QMap<QString, Qt::Key> *map) |
|
115 { |
|
116 if (!action || !map || map->count()==0) |
|
117 return false; |
|
118 |
|
119 QString key = action->data().toString(); |
|
120 |
|
121 if (!key.isNull() && map->contains(key)) { |
|
122 mKey = map->value(key); |
|
123 return true; |
|
124 } |
|
125 |
|
126 return false; |
|
127 } |
|
128 |
|
129 bool CaptureRequest::setLongFlags(QAction* action, QMap<QString, XQKeyCapture::LongFlags> *map) |
|
130 { |
|
131 if (!action || !map || map->count()==0) |
|
132 return false; |
|
133 |
|
134 QString flag = action->data().toString(); |
|
135 |
|
136 if ( !flag.isNull() && map->contains(flag)){ |
|
137 mLongFlags = map->value(flag); |
|
138 return true; |
|
139 } |
|
140 |
|
141 return false; |
|
142 } |