OSDN Git Service

Altered note table to use a display delegate to show dates rather than convert the...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / gui / TrashTreeWidget.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.trolltech.qt.core.QByteArray;\r
26 import com.trolltech.qt.core.Qt;\r
27 import com.trolltech.qt.gui.QAbstractItemView;\r
28 import com.trolltech.qt.gui.QAction;\r
29 import com.trolltech.qt.gui.QBrush;\r
30 import com.trolltech.qt.gui.QColor;\r
31 import com.trolltech.qt.gui.QContextMenuEvent;\r
32 import com.trolltech.qt.gui.QDragEnterEvent;\r
33 import com.trolltech.qt.gui.QHeaderView;\r
34 import com.trolltech.qt.gui.QIcon;\r
35 import com.trolltech.qt.gui.QMenu;\r
36 import com.trolltech.qt.gui.QTreeWidget;\r
37 import com.trolltech.qt.gui.QTreeWidgetItem;\r
38 \r
39 public class TrashTreeWidget extends QTreeWidget {\r
40         private QAction emptyAction;\r
41         private QTreeWidgetItem trashItem;\r
42         private Integer trashCount;     \r
43         \r
44         public void setEmptyAction(QAction a) {\r
45                 emptyAction = a;\r
46         }\r
47         \r
48         \r
49         public TrashTreeWidget() {\r
50         trashCount =  0;\r
51         }\r
52         \r
53         public void updateCounts(Integer cnt) {\r
54                 QBrush gray = new QBrush();\r
55                 gray.setColor(QColor.gray);\r
56                 QBrush black = new QBrush();\r
57                 black.setColor(QColor.black);\r
58                 \r
59                 trashCount = cnt;\r
60                 trashItem.setText(1, trashCount.toString());\r
61                 header().resizeSection(1, 0);\r
62                 if (trashCount > 0) {\r
63                         trashItem.setForeground(0, black);                      \r
64                         trashItem.setForeground(1, black);                      \r
65                 } else {\r
66                         trashItem.setForeground(0, gray);                       \r
67                         trashItem.setForeground(1, gray);                                               \r
68                 }\r
69         }\r
70         \r
71         public void load() {\r
72         String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
73         QIcon trashIcon = new QIcon(iconPath+"trash.png");\r
74         trashItem = new QTreeWidgetItem();\r
75         trashItem.setIcon(0, trashIcon);\r
76         trashItem.setText(0, "Trash");\r
77         Qt.Alignment ra = new Qt.Alignment(Qt.AlignmentFlag.AlignRight);\r
78         trashItem.setTextAlignment(1, ra.value());\r
79         List<String> headers = new ArrayList<String>();\r
80         headers.add("");\r
81         headers.add("");\r
82         setHeaderLabels(headers);\r
83                 setColumnCount(2);\r
84                 header().setResizeMode(0, QHeaderView.ResizeMode.ResizeToContents);\r
85                 header().setResizeMode(1, QHeaderView.ResizeMode.Stretch);\r
86                 header().setMovable(false);\r
87         setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
88         addTopLevelItem(trashItem);\r
89
90         }\r
91 \r
92         @Override\r
93         public void contextMenuEvent(QContextMenuEvent event) {\r
94                 QMenu menu = new QMenu(this);\r
95                 menu.addAction(emptyAction);\r
96                 menu.exec(event.globalPos());\r
97         }\r
98         \r
99         \r
100         @Override\r
101         public void dragEnterEvent(QDragEnterEvent event) {\r
102                 event.mimeData().setData("application/x-nevernote-trash", new QByteArray(currentItem().text(1)));\r
103                 event.accept();\r
104         }\r
105 }\r