77 |
77 |
78 /* |
78 /* |
79 Calculates and returns the position of the action |
79 Calculates and returns the position of the action |
80 based on the container template. |
80 based on the container template. |
81 */ |
81 */ |
82 int HbActionManager::position(QAction *aAction, QList<QAction *> actions) const |
82 int HbActionManager::position(QAction *aAction, QList<QAction *> actions, int maxPos) const |
83 { |
83 { |
84 if (actions.count() == 0) { |
84 if (actions.count() == 0) { |
85 return 0; |
85 return 0; |
86 } |
86 } |
87 |
87 |
|
88 if (maxPos < 0) { |
|
89 maxPos = actions.count(); |
|
90 } |
88 // try to downcast aAction. If that fails, return a fallback value |
91 // try to downcast aAction. If that fails, return a fallback value |
89 HbAction* action = qobject_cast<HbAction *>(aAction); |
92 HbAction* action = qobject_cast<HbAction *>(aAction); |
90 if (!action){ |
93 if (!action){ |
91 return actions.count(); |
94 return maxPos; |
92 } |
95 } |
93 |
96 |
94 int index = templateIndex(action); |
97 int index = templateIndex(action); |
95 if (index == -1) { |
98 if (index == -1) { |
96 return actions.count(); |
99 return maxPos; |
97 } |
100 } |
98 |
101 |
99 int pos(0); |
102 int pos(0); |
100 foreach (QAction *qaction, actions) { |
103 foreach (QAction *qaction, actions) { |
101 HbAction *containerAction = qobject_cast<HbAction *>(qaction); |
104 HbAction *containerAction = qobject_cast<HbAction *>(qaction); |
|
105 if (!containerAction) { |
|
106 break; |
|
107 } |
102 int containerIndex = templateIndex(containerAction); |
108 int containerIndex = templateIndex(containerAction); |
103 if (index < containerIndex) { |
109 if (index < containerIndex) { |
104 break; |
110 break; |
105 } |
111 } |
106 else { |
112 else { |
107 pos++; |
113 pos++; |
108 } |
114 } |
|
115 } |
|
116 if (pos > maxPos) { |
|
117 pos = maxPos; |
109 } |
118 } |
110 return pos; |
119 return pos; |
111 } |
120 } |
112 |
121 |
113 /* |
122 /* |