import com.trolltech.qt.gui.QMenu;\r
import com.trolltech.qt.gui.QTreeWidget;\r
import com.trolltech.qt.gui.QTreeWidgetItem;\r
+import com.trolltech.qt.gui.QTreeWidgetItem.ChildIndicatorPolicy;\r
\r
import cx.fbn.nevernote.Global;\r
import cx.fbn.nevernote.filters.NotebookCounter;\r
private QAction iconAction;\r
public NoteSignal noteSignal;\r
private HashMap<String, QIcon> icons;\r
+ private final HashMap<String, QTreeWidgetItem> stacks;\r
// private final QTreeWidgetItem previousMouseOver;\r
// private boolean previousMouseOverWasSelected;\r
\r
\r
public NotebookTreeWidget() {\r
noteSignal = new NoteSignal();\r
- setProperty("hideTree", true);\r
+// setProperty("hideTree", true);\r
List<String> labels = new ArrayList<String>();\r
labels.add("Notebooks");\r
labels.add("");\r
} else\r
setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection);\r
\r
+ stacks = new HashMap<String, QTreeWidgetItem>();\r
// int width = Global.getColumnWidth("notebookTreeName");\r
// if (width>0)\r
// setColumnWidth(0, width);\r
for (int i=0; i<books.size(); i++) {\r
book = books.get(i);\r
child = new QTreeWidgetItem();\r
+ child.setChildIndicatorPolicy(ChildIndicatorPolicy.DontShowIndicatorWhenChildless);\r
child.setText(0, book.getName());\r
if (icons != null && !icons.containsKey(book.getGuid())) {\r
QIcon icon = findDefaultIcon(book.getGuid(), book.getName(), localBooks, book.isPublished());\r
}\r
child.setTextAlignment(1, ra.value());\r
child.setText(2, book.getGuid());\r
- addTopLevelItem(child);\r
+ if (book.getStack() == null || book.getStack().equalsIgnoreCase(""))\r
+ addTopLevelItem(child); \r
+ else {\r
+ String stackName = book.getStack();\r
+ QTreeWidgetItem parent;\r
+ if (!stacks.containsKey(stackName)) {\r
+ String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
+ QIcon stackIcon = new QIcon(iconPath+"books2.png");\r
+ parent = new QTreeWidgetItem();\r
+ stacks.put(stackName, parent);\r
+ parent.setText(0, stackName);\r
+ parent.setIcon(0, stackIcon);\r
+ parent.setText(2, "STACK");\r
+ parent.setTextAlignment(1, ra.value());\r
+ addTopLevelItem(parent);\r
+ } else\r
+ parent = stacks.get(stackName);\r
+ parent.addChild(child);\r
+ \r
+ }\r
}\r
\r
sortItems(0, SortOrder.AscendingOrder); \r
child = new QTreeWidgetItem();\r
child.setIcon(0, greenIcon);\r
child.setText(0, "All Notebooks");\r
-// child.setText(1, "0");\r
child.setText(2, "");\r
child.setTextAlignment(1, ra.value());\r
insertTopLevelItem(0,child);\r
resizeColumnToContents(0);\r
resizeColumnToContents(1);\r
}\r
+\r
// update the display with the current number of notes\r
public void updateCounts(List<Notebook> books, List<NotebookCounter> counts) {\r
QTreeWidgetItem root = invisibleRootItem();\r
QTreeWidgetItem child;\r
+ HashMap<String, Integer> stackCounts = new HashMap<String, Integer>();\r
\r
QBrush blue = new QBrush();\r
QBrush black = new QBrush();\r
blue.setColor(QColor.black);\r
int total=0;\r
\r
-// for (int i=0; i<counts.size(); i++) {\r
-// total=total+counts.get(i).getCount();\r
-// }\r
\r
int size = books.size();\r
if (Global.mimicEvernoteInterface)\r
size++;\r
\r
for (int i=0; i<size; i++) {\r
- child = root.child(i); \r
- if (child != null) {\r
- String guid = child.text(2);\r
- child.setText(1,"0");\r
- child.setForeground(0, black);\r
- child.setForeground(1, black);\r
- for (int j=0; j<counts.size(); j++) {\r
- if (counts.get(j).getGuid().equals(guid)) {\r
- child.setText(1, new Integer(counts.get(j).getCount()).toString());\r
- total = total+counts.get(j).getCount();\r
- if (counts.get(j).getCount() > 0) {\r
- child.setForeground(0, blue);\r
- child.setForeground(1, blue);\r
- }\r
- }\r
-// if (guid.equals("") && Global.mimicEvernoteInterface) {\r
-// child.setText(1, new Integer(total).toString());\r
-// }\r
+ child = root.child(i);\r
+ if (child != null && child.childCount() > 0) {\r
+ int count = child.childCount();\r
+ QTreeWidgetItem parent = child;\r
+ int localTotal = 0;\r
+ for (int j=0; j<count; j++) {\r
+ child = parent.child(j);\r
+ int childCount = updateCounts(child, books, counts, blue, black);\r
+ total = total+childCount;\r
+ localTotal = localTotal+childCount;\r
}\r
- }\r
+ parent.setText(1, new Integer(localTotal).toString());\r
+ } else\r
+ total = total+updateCounts(child, books, counts, blue, black);\r
}\r
\r
for (int i=0; i<size; i++) {\r
}\r
}\r
}\r
+ \r
+ private int updateCounts(QTreeWidgetItem child, List<Notebook> books, List<NotebookCounter> counts, QBrush blue, QBrush black) {\r
+ int total=0;\r
+ if (child != null) {\r
+ String guid = child.text(2);\r
+ child.setText(1,"0");\r
+ child.setForeground(0, black);\r
+ child.setForeground(1, black);\r
+ for (int j=0; j<counts.size(); j++) {\r
+ if (counts.get(j).getGuid().equals(guid)) {\r
+ child.setText(1, new Integer(counts.get(j).getCount()).toString());\r
+ total = counts.get(j).getCount();\r
+ if (counts.get(j).getCount() > 0) {\r
+ child.setForeground(0, blue);\r
+ child.setForeground(1, blue);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ return total;\r
+ }\r
+ \r
// Return a list of the notebook guids, ordered by the current display order.\r
public List<String> getNotebookGuids() {\r
List<String> names = new ArrayList<String>();\r