OSDN Git Service

Added the ability to view debugging logs.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / gui / TableViewHeader.java
1 package cx.fbn.nevernote.gui;\r
2 \r
3 import java.util.List;\r
4 \r
5 import com.trolltech.qt.core.Qt.Orientation;\r
6 import com.trolltech.qt.gui.QAction;\r
7 import com.trolltech.qt.gui.QContextMenuEvent;\r
8 import com.trolltech.qt.gui.QHeaderView;\r
9 import com.trolltech.qt.gui.QMenu;\r
10 import com.trolltech.qt.gui.QWidget;\r
11 \r
12 import cx.fbn.nevernote.Global;\r
13 \r
14 public class TableViewHeader extends QHeaderView {\r
15         public QMenu contextMenu;\r
16         public QAction createdDateAction;\r
17         public QAction changedDateAction;\r
18         public QAction subjectDateAction;\r
19         public QAction tagsAction;\r
20         public QAction titleAction;\r
21         public QAction notebookAction;\r
22         public QAction synchronizedAction;\r
23         public QAction authorAction;\r
24         public QAction urlAction;\r
25         public QAction thumbnailAction;\r
26         public QAction guidAction;\r
27         \r
28 \r
29         public TableViewHeader(Orientation orientation, QWidget parent) {\r
30                 super(orientation, parent);\r
31                 \r
32                 setSortIndicatorShown(true);\r
33                 setClickable(true);\r
34                 \r
35                 contextMenu = new QMenu();\r
36 \r
37                 titleAction = new QAction(this);\r
38                 titleAction.setText(tr("Title"));\r
39                 titleAction.setCheckable(true);\r
40                 contextMenu.addAction(titleAction);\r
41                 \r
42                 createdDateAction = new QAction(this);\r
43                 createdDateAction.setText(tr("Date Created"));\r
44                 createdDateAction.setCheckable(true);\r
45                 contextMenu.addAction(createdDateAction);\r
46                 \r
47                 changedDateAction = new QAction(this);\r
48                 changedDateAction.setText(tr("Date Changed"));\r
49                 changedDateAction.setCheckable(true);\r
50                 contextMenu.addAction(changedDateAction);\r
51                 \r
52                 subjectDateAction = new QAction(this);\r
53                 subjectDateAction.setText(tr("Subject Date"));\r
54                 subjectDateAction.setCheckable(true);\r
55                 contextMenu.addAction(subjectDateAction);\r
56                 \r
57                 tagsAction = new QAction(this);\r
58                 tagsAction.setText(tr("Tags"));\r
59                 tagsAction.setCheckable(true);\r
60                 contextMenu.addAction(tagsAction);\r
61                 \r
62                 notebookAction = new QAction(this);\r
63                 notebookAction.setText(tr("Notebook"));\r
64                 notebookAction.setCheckable(true);\r
65                 contextMenu.addAction(notebookAction);\r
66                 \r
67                 synchronizedAction = new QAction(this);\r
68                 synchronizedAction.setText(tr("Synchronized"));\r
69                 synchronizedAction.setCheckable(true);\r
70                 contextMenu.addAction(synchronizedAction);\r
71                 \r
72                 authorAction = new QAction(this);\r
73                 authorAction.setText(tr("Author"));\r
74                 authorAction.setCheckable(true);\r
75                 contextMenu.addAction(authorAction);\r
76                 \r
77                 urlAction = new QAction(this);\r
78                 urlAction.setText(tr("Source URL"));\r
79                 urlAction.setCheckable(true);\r
80                 contextMenu.addAction(urlAction);\r
81                 \r
82                 thumbnailAction = new QAction(this);\r
83                 thumbnailAction.setText(tr("Thumbnail"));\r
84                 thumbnailAction.setCheckable(true);\r
85                 contextMenu.addAction(thumbnailAction);\r
86                 \r
87                 guidAction = new QAction(this);\r
88                 guidAction.setText(tr("Guid"));\r
89                 guidAction.setCheckable(true);\r
90 //              contextMenu.addAction(guidAction);\r
91                 setMouseTracking(true);\r
92                 sectionEntered.connect(this, "sectionClicked(Integer)");\r
93                 \r
94                 checkActions();\r
95         }\r
96 \r
97         private void checkActions() {\r
98                 titleAction.setChecked(Global.isColumnVisible("title"));\r
99                 createdDateAction.setChecked(Global.isColumnVisible("dateCreated"));\r
100                 changedDateAction.setChecked(Global.isColumnVisible("dateChanged"));\r
101                 subjectDateAction.setChecked(Global.isColumnVisible("dateSubject"));\r
102                 tagsAction.setChecked(Global.isColumnVisible("tags"));\r
103                 notebookAction.setChecked(Global.isColumnVisible("notebook"));\r
104                 synchronizedAction.setChecked(Global.isColumnVisible("synchronized"));\r
105                 authorAction.setChecked(Global.isColumnVisible("author"));\r
106                 urlAction.setChecked(Global.isColumnVisible("sourceUrl"));\r
107                 thumbnailAction.setChecked(Global.isColumnVisible("thumbnail"));\r
108                 guidAction.setChecked(Global.isColumnVisible("guid"));\r
109         }\r
110         \r
111         public void sectionClicked(Integer position) {\r
112                 if (position == Global.noteTableThumbnailPosition)\r
113                         setClickable(false);\r
114                 else\r
115                         setClickable(true);\r
116         }\r
117         \r
118         @Override\r
119         public void contextMenuEvent(QContextMenuEvent event) {\r
120                 checkActions();\r
121                 List<QAction> actions = contextMenu.actions();\r
122                 int count = 0;\r
123                 for (int i=0; i<actions.size(); i++) {\r
124                         actions.get(i).setEnabled(true);\r
125                         if (actions.get(i).isChecked()) \r
126                                 count++;\r
127                 }\r
128                 if (count <= 1) {\r
129                         for (int i=0; i<actions.size(); i++) {\r
130                                 if (actions.get(i).isChecked()) \r
131                                         actions.get(i).setEnabled(false);\r
132                         }\r
133                 }\r
134                 contextMenu.exec(event.globalPos());\r
135         }\r
136 }\r