summaryrefslogtreecommitdiff
path: root/src/gui/widgets/setuptouchitem.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-12-31 19:26:21 +0300
committerAndrei Karas <akaras@inbox.ru>2012-12-31 19:26:21 +0300
commitf355fe070293a3f80b33ee0bc0154b2fe767fc4d (patch)
tree2a7a3015791dabcae946f2b12259233b4e38876c /src/gui/widgets/setuptouchitem.cpp
parent6fbb71142de5b2b12c2153b41a21b6dc34284343 (diff)
downloadmanaplus-f355fe070293a3f80b33ee0bc0154b2fe767fc4d.tar.gz
manaplus-f355fe070293a3f80b33ee0bc0154b2fe767fc4d.tar.bz2
manaplus-f355fe070293a3f80b33ee0bc0154b2fe767fc4d.tar.xz
manaplus-f355fe070293a3f80b33ee0bc0154b2fe767fc4d.zip
Sort onscreen keyboard actions list.
Diffstat (limited to 'src/gui/widgets/setuptouchitem.cpp')
-rw-r--r--src/gui/widgets/setuptouchitem.cpp57
1 files changed, 56 insertions, 1 deletions
diff --git a/src/gui/widgets/setuptouchitem.cpp b/src/gui/widgets/setuptouchitem.cpp
index 59f33b6a5..06faf7b19 100644
--- a/src/gui/widgets/setuptouchitem.cpp
+++ b/src/gui/widgets/setuptouchitem.cpp
@@ -27,6 +27,62 @@
#include "debug.h"
+class SortTouchActionFunctor final
+{
+ public:
+ bool operator() (const SetupActionData *const data1,
+ const SetupActionData *const data2) const
+ {
+ if (!data1 || !data2)
+ return false;
+ return data1->name < data2->name;
+ }
+} touchActionSorter;
+
+TouchActionsModel::TouchActionsModel()
+{
+ std::vector<SetupActionData*> data;
+
+ for (int f = 0, sz = touchActionDataSize; f < sz; f ++)
+ {
+ int k = 0;
+ while (!touchActionData[f][k].name.empty())
+ {
+ data.push_back(&touchActionData[f][k]);
+ k ++;
+ }
+ }
+
+ std::sort(data.begin(), data.end(), touchActionSorter);
+ int cnt = 0;
+ for (std::vector<SetupActionData*>::iterator it = data.begin(),
+ it_end = data.end(); it != it_end; ++ it)
+ {
+ const SetupActionData *data1 = *it;
+ mNames.push_back(data1->name);
+ mActionId.push_back(data1->actionId);
+ mActionToSelection[data1->actionId] = cnt;
+ cnt ++;
+ }
+}
+
+int TouchActionsModel::getActionFromSelection(int sel)
+{
+ if (sel < 0 || sel > mActionId.size())
+ return -1;
+ return mActionId[sel];
+}
+
+int TouchActionsModel::getSelectionFromAction(int action)
+{
+ std::map<int, int>::const_iterator it
+ = mActionToSelection.find(action);
+ if (it == mActionToSelection.end())
+ return 0;
+ return (*it).second;
+}
+
+
SetupActionDropDown::SetupActionDropDown(std::string text,
std::string description,
std::string keyName,
@@ -89,7 +145,6 @@ void SetupActionDropDown::createControls()
atoi(mValue.c_str())));
mWidget = mDropDown;
-// mTextField->setWidth(50);
fixFirstItemSize(mLabel);
mHorizont->add(mLabel);
mHorizont->add(mDropDown);