2 * This file is part of NeverNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\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
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
20 package cx.fbn.nevernote.gui;
\r
22 import java.util.ArrayList;
\r
23 import java.util.List;
\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
39 public class TrashTreeWidget extends QTreeWidget {
\r
40 private QAction emptyAction;
\r
41 private QTreeWidgetItem trashItem;
\r
42 private Integer trashCount;
\r
44 public void setEmptyAction(QAction a) {
\r
49 public TrashTreeWidget() {
\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
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
66 trashItem.setForeground(0, gray);
\r
67 trashItem.setForeground(1, gray);
\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
82 setHeaderLabels(headers);
\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
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
101 public void dragEnterEvent(QDragEnterEvent event) {
\r
102 event.mimeData().setData("application/x-nevernote-trash", new QByteArray(currentItem().text(1)));
\r