OSDN Git Service

Add logic to display stacks in notebook tree
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / gui / SavedSearchTreeWidget.java
1 /*\r
2  * This file is part of NeverNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\r
8  * Software distributed under the License is distributed\r
9  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
10  * express or implied. See the GPL for the specific language\r
11  * governing rights and limitations.\r
12  *\r
13  * You should have received a copy of the GPL along with this\r
14  * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
15  * or write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
17  *\r
18 */\r
19 \r
20 package cx.fbn.nevernote.gui;\r
21 \r
22 import java.util.ArrayList;\r
23 import java.util.List;\r
24 \r
25 import com.evernote.edam.type.SavedSearch;\r
26 import com.trolltech.qt.core.Qt.SortOrder;\r
27 import com.trolltech.qt.gui.QAbstractItemView;\r
28 import com.trolltech.qt.gui.QAction;\r
29 import com.trolltech.qt.gui.QContextMenuEvent;\r
30 import com.trolltech.qt.gui.QIcon;\r
31 import com.trolltech.qt.gui.QMenu;\r
32 import com.trolltech.qt.gui.QTreeWidget;\r
33 import com.trolltech.qt.gui.QTreeWidgetItem;\r
34 \r
35 public class SavedSearchTreeWidget extends QTreeWidget {\r
36         private QAction editAction;\r
37         private QAction deleteAction;\r
38         private QAction addAction;\r
39         \r
40         \r
41         public SavedSearchTreeWidget() {\r
42 //              setAcceptDrops(true);\r
43 //              setDragEnabled(true);\r
44                 setProperty("hideTree", true);\r
45                 setAcceptDrops(false);\r
46                 setDragEnabled(false);\r
47 //              setDragDropMode(QAbstractItemView.DragDropMode.DragDrop);\r
48         setHeaderLabel(tr("Saved Searches"));\r
49         setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
50         }\r
51         \r
52         public void setEditAction(QAction e) {\r
53                 editAction = e;\r
54         }\r
55         public void setDeleteAction(QAction d) {\r
56                 deleteAction = d;\r
57         }\r
58         public void setAddAction(QAction a) {\r
59                 addAction = a;\r
60         }\r
61         \r
62         public void load(List<SavedSearch> tempList) {\r
63         SavedSearch search;\r
64         List<QTreeWidgetItem> index = new ArrayList<QTreeWidgetItem>();\r
65                 \r
66         //Clear out the tree & reload\r
67         clear();\r
68         String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
69                 QIcon icon = new QIcon(iconPath+"search.png");\r
70         \r
71                 for (int i=0; i<tempList.size(); i++) {\r
72                         search = tempList.get(i);\r
73                         QTreeWidgetItem child = new QTreeWidgetItem();\r
74                         child.setText(0, search.getName());\r
75                         child.setIcon(0,icon);\r
76                         child.setText(1, search.getGuid());\r
77                         index.add(child);\r
78                         addTopLevelItem(child);\r
79                 } \r
80         sortItems(0, SortOrder.AscendingOrder);\r
81         }\r
82 \r
83         \r
84         public boolean selectGuid(String guid) {\r
85                 QTreeWidgetItem root = invisibleRootItem();\r
86                 QTreeWidgetItem child;\r
87 \r
88                 for (int i=0; i<root.childCount(); i++) {\r
89                         child = root.child(i);\r
90                         if (child.text(1).equals(guid)) {\r
91                                 child.setSelected(true);\r
92                                 return true;\r
93                         }\r
94                 }\r
95                 return false;\r
96         }\r
97         \r
98         \r
99         @Override\r
100         public void contextMenuEvent(QContextMenuEvent event) {\r
101                 QMenu menu = new QMenu(this);\r
102                 menu.addAction(addAction);\r
103                 menu.addAction(editAction);\r
104                 menu.addAction(deleteAction);\r
105                 menu.exec(event.globalPos());\r
106         }\r
107         \r
108         \r
109         public void selectSavedSearch(QTreeWidgetItem item) {\r
110                 QTreeWidgetItem root = invisibleRootItem();\r
111                 QTreeWidgetItem child;\r
112                 \r
113                 for (int i=0; i<root.childCount(); i++) {\r
114                         child = root.child(i); \r
115                         if (child.text(1).equals(item.text(1))) {\r
116                                 child.setSelected(true);\r
117                                 return;\r
118                         }\r
119                 }\r
120         }\r
121 }\r