OSDN Git Service

Added the ability to show/hide the pinned note column
[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         public QAction pinnedAction;\r
28         \r
29 \r
30         public TableViewHeader(Orientation orientation, QWidget parent) {\r
31                 super(orientation, parent);\r
32                 \r
33                 setSortIndicatorShown(true);\r
34                 setClickable(true);\r
35                 \r
36                 contextMenu = new QMenu();\r
37 \r
38                 titleAction = new QAction(this);\r
39                 titleAction.setText(tr("Title"));\r
40                 titleAction.setCheckable(true);\r
41                 contextMenu.addAction(titleAction);\r
42                 \r
43                 createdDateAction = new QAction(this);\r
44                 createdDateAction.setText(tr("Date Created"));\r
45                 createdDateAction.setCheckable(true);\r
46                 contextMenu.addAction(createdDateAction);\r
47                 \r
48                 changedDateAction = new QAction(this);\r
49                 changedDateAction.setText(tr("Date Changed"));\r
50                 changedDateAction.setCheckable(true);\r
51                 contextMenu.addAction(changedDateAction);\r
52                 \r
53                 subjectDateAction = new QAction(this);\r
54                 subjectDateAction.setText(tr("Subject Date"));\r
55                 subjectDateAction.setCheckable(true);\r
56                 contextMenu.addAction(subjectDateAction);\r
57                 \r
58                 tagsAction = new QAction(this);\r
59                 tagsAction.setText(tr("Tags"));\r
60                 tagsAction.setCheckable(true);\r
61                 contextMenu.addAction(tagsAction);\r
62                 \r
63                 notebookAction = new QAction(this);\r
64                 notebookAction.setText(tr("Notebook"));\r
65                 notebookAction.setCheckable(true);\r
66                 contextMenu.addAction(notebookAction);\r
67                 \r
68                 synchronizedAction = new QAction(this);\r
69                 synchronizedAction.setText(tr("Synchronized"));\r
70                 synchronizedAction.setCheckable(true);\r
71                 contextMenu.addAction(synchronizedAction);\r
72                 \r
73                 authorAction = new QAction(this);\r
74                 authorAction.setText(tr("Author"));\r
75                 authorAction.setCheckable(true);\r
76                 contextMenu.addAction(authorAction);\r
77                 \r
78                 urlAction = new QAction(this);\r
79                 urlAction.setText(tr("Source URL"));\r
80                 urlAction.setCheckable(true);\r
81                 contextMenu.addAction(urlAction);\r
82                 \r
83                 thumbnailAction = new QAction(this);\r
84                 thumbnailAction.setText(tr("Thumbnail"));\r
85                 thumbnailAction.setCheckable(true);\r
86                 contextMenu.addAction(thumbnailAction);\r
87                 \r
88                 pinnedAction = new QAction(this);\r
89                 pinnedAction.setText(tr("Pinned"));\r
90                 pinnedAction.setCheckable(true);\r
91                 contextMenu.addAction(pinnedAction);\r
92                 \r
93                 \r
94                 guidAction = new QAction(this);\r
95                 guidAction.setText(tr("Guid"));\r
96                 guidAction.setCheckable(true);\r
97                 setMouseTracking(true);\r
98                 sectionEntered.connect(this, "sectionClicked(Integer)");\r
99                 \r
100                 checkActions();\r
101         }\r
102 \r
103         private void checkActions() {\r
104                 titleAction.setChecked(Global.isColumnVisible("title"));\r
105                 createdDateAction.setChecked(Global.isColumnVisible("dateCreated"));\r
106                 changedDateAction.setChecked(Global.isColumnVisible("dateChanged"));\r
107                 subjectDateAction.setChecked(Global.isColumnVisible("dateSubject"));\r
108                 tagsAction.setChecked(Global.isColumnVisible("tags"));\r
109                 notebookAction.setChecked(Global.isColumnVisible("notebook"));\r
110                 synchronizedAction.setChecked(Global.isColumnVisible("synchronized"));\r
111                 authorAction.setChecked(Global.isColumnVisible("author"));\r
112                 urlAction.setChecked(Global.isColumnVisible("sourceUrl"));\r
113                 thumbnailAction.setChecked(Global.isColumnVisible("thumbnail"));\r
114                 pinnedAction.setChecked(Global.isColumnVisible("pinned"));\r
115                 guidAction.setChecked(Global.isColumnVisible("guid"));\r
116         }\r
117         \r
118         public void sectionClicked(Integer position) {\r
119                 if (position == Global.noteTableThumbnailPosition)\r
120                         setClickable(false);\r
121                 else\r
122                         setClickable(true);\r
123         }\r
124         \r
125         @Override\r
126         public void contextMenuEvent(QContextMenuEvent event) {\r
127                 checkActions();\r
128                 List<QAction> actions = contextMenu.actions();\r
129                 int count = 0;\r
130                 for (int i=0; i<actions.size(); i++) {\r
131                         actions.get(i).setEnabled(true);\r
132                         if (actions.get(i).isChecked()) \r
133                                 count++;\r
134                 }\r
135                 if (count <= 1) {\r
136                         for (int i=0; i<actions.size(); i++) {\r
137                                 if (actions.get(i).isChecked()) \r
138                                         actions.get(i).setEnabled(false);\r
139                         }\r
140                 }\r
141                 contextMenu.exec(event.globalPos());\r
142         }\r
143 }\r