TizenRefApp-7948 Implement index view 21/112221/2
authorOleksander Kostenko <o.kostenko@samsung.com>
Fri, 27 Jan 2017 15:28:50 +0000 (17:28 +0200)
committerOleksander Kostenko <o.kostenko@samsung.com>
Mon, 30 Jan 2017 09:54:54 +0000 (11:54 +0200)
Change-Id: I46e7e14998405225fe5bc283a81f8c1167274d5c
Signed-off-by: Oleksander Kostenko <o.kostenko@samsung.com>
src/App/inc/IndexView.h [new file with mode: 0644]
src/App/src/IndexView.cpp [new file with mode: 0644]

diff --git a/src/App/inc/IndexView.h b/src/App/inc/IndexView.h
new file mode 100644 (file)
index 0000000..581bc37
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2017  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IndexView_h_
+#define IndexView_h_
+
+#include "View.h"
+
+namespace TaskMngr {
+    class IndexView
+            : public View {
+        public:
+            IndexView(Evas_Object *parent);
+            virtual ~IndexView();
+
+            /**
+             * @brief Sets the selected state of an item.
+             *
+             * This sets the selected state to the given item. @c true for selected,
+             * @c false for not selected.
+             *
+             * Selected items will be highlighted.
+             *
+             * @param[in] index @c number of index item
+             * @param[in] value @c true if selected, @c false otherwise
+             */
+            void setSelectedItem(int index, bool value = true);
+
+            /**
+             * @brief Creates index with the needed amount of items
+             *
+             * @param[in] size @c how many items will be shown
+             */
+            void setItemsCount(int size);
+
+        private:
+            Elm_Widget_Item* findItem(int index);
+            Elm_Widget_Item* appendItem(int index);
+            void clear();
+            void setHorizontal(bool value);
+            void setAutohide(bool value);
+
+        private:
+            int m_IndexSize;
+            int m_SelectedIndex;
+            bool m_IsSelected;
+    };
+}
+#endif /* IndexView_h_ */
+
diff --git a/src/App/src/IndexView.cpp b/src/App/src/IndexView.cpp
new file mode 100644 (file)
index 0000000..74ff0b1
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2017  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "IndexView.h"
+#include <vector>
+#include <string>
+
+using namespace TaskMngr;
+
+namespace {
+    const int maxScrollSize = 19;
+    const int maxHalfOdd = 9;
+    const int maxHalfEven = 10;
+
+    const char *styleEven[] = {
+        "item/even_1",
+        "item/even_2",
+        "item/even_3",
+        "item/even_4",
+        "item/even_5",
+        "item/even_6",
+        "item/even_7",
+        "item/even_8",
+        "item/even_9",
+        "item/even_10",
+        "item/even_11",
+        "item/even_12",
+        "item/even_13",
+        "item/even_14",
+        "item/even_15",
+        "item/even_16",
+        "item/even_17",
+        "item/even_18",
+        "item/even_19",
+        "item/even_20",
+    };
+
+    const char *styleOdd[] = {
+        "item/odd_1",
+        "item/odd_2",
+        "item/odd_3",
+        "item/odd_4",
+        "item/odd_5",
+        "item/odd_6",
+        "item/odd_7",
+        "item/odd_8",
+        "item/odd_9",
+        "item/odd_10",
+        "item/odd_11",
+        "item/odd_12",
+        "item/odd_13",
+        "item/odd_14",
+        "item/odd_15",
+        "item/odd_16",
+        "item/odd_17",
+        "item/odd_18",
+        "item/odd_19",
+    };
+}
+
+IndexView::IndexView(Evas_Object *parent)
+    : m_IndexSize(0)
+    , m_SelectedIndex(-1)
+    , m_IsSelected(false)
+{
+    setEo(elm_index_add(parent));
+    setStyle("circle");
+    expand();
+    setHorizontal(true);
+    setAutohide(false);
+    show(true);
+}
+
+IndexView::~IndexView()
+{
+
+}
+
+void IndexView::setSelectedItem(int index, bool value)
+{
+    if(index != m_SelectedIndex || value != m_IsSelected) {
+        m_SelectedIndex = index;
+        m_IsSelected = value;
+        elm_index_item_selected_set(findItem(index), value);
+    }
+}
+
+void IndexView::setItemsCount(int size)
+{
+    if(size != m_IndexSize)
+    {
+        m_IndexSize = size;
+        clear();
+    }
+
+    if (size > maxScrollSize)
+        size = maxScrollSize;
+
+    int isOdd = size % 2;
+
+    for (int i = 0; i < size; ++i) {
+        int index = isOdd ? maxHalfOdd : maxHalfEven;
+        index -= (size / 2) - i;
+        elm_object_item_style_set(appendItem(i), isOdd ? styleOdd[index] : styleEven[index]);
+    }
+
+    elm_index_level_go(getEo(), 0);
+}
+
+Elm_Widget_Item* IndexView::findItem(int index)
+{
+    return elm_index_item_find(getEo(), (void *)index);
+}
+
+Elm_Widget_Item* IndexView::appendItem(int index)
+{
+    return elm_index_item_append(getEo(), nullptr, nullptr, (void *)index);
+}
+
+void IndexView::clear()
+{
+    elm_index_item_clear(getEo());
+}
+
+void IndexView::setHorizontal(bool value)
+{
+    elm_index_horizontal_set(getEo(), value);
+}
+
+void IndexView::setAutohide(bool value)
+{
+    elm_index_autohide_disabled_set(getEo(), !value);
+}