OSDN Git Service

Added the ability to show/hide the pinned note column
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / gui / TableView.java
1 /*\r
2  * This file is part of NixNote \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 package cx.fbn.nevernote.gui;\r
20 \r
21 import java.util.List;\r
22 import java.util.SortedMap;\r
23 \r
24 import com.evernote.edam.type.Note;\r
25 import com.trolltech.qt.core.QByteArray;\r
26 import com.trolltech.qt.core.QModelIndex;\r
27 import com.trolltech.qt.core.Qt;\r
28 import com.trolltech.qt.core.Qt.Orientation;\r
29 import com.trolltech.qt.core.Qt.SortOrder;\r
30 import com.trolltech.qt.gui.QAbstractItemView;\r
31 import com.trolltech.qt.gui.QAction;\r
32 import com.trolltech.qt.gui.QApplication;\r
33 import com.trolltech.qt.gui.QColor;\r
34 import com.trolltech.qt.gui.QContextMenuEvent;\r
35 import com.trolltech.qt.gui.QDragEnterEvent;\r
36 import com.trolltech.qt.gui.QDropEvent;\r
37 import com.trolltech.qt.gui.QFontMetrics;\r
38 import com.trolltech.qt.gui.QKeyEvent;\r
39 import com.trolltech.qt.gui.QKeySequence.StandardKey;\r
40 import com.trolltech.qt.gui.QMenu;\r
41 import com.trolltech.qt.gui.QTableView;\r
42 \r
43 import cx.fbn.nevernote.Global;\r
44 import cx.fbn.nevernote.evernote.NoteMetadata;\r
45 import cx.fbn.nevernote.filters.NoteSortFilterProxyModel;\r
46 import cx.fbn.nevernote.signals.NoteSignal;\r
47 import cx.fbn.nevernote.utilities.ApplicationLogger;\r
48 import cx.fbn.nevernote.utilities.ListManager;\r
49 \r
50 public class TableView extends QTableView {\r
51         private final ListManager                               runner;\r
52         private final ApplicationLogger         logger;\r
53     public NoteSortFilterProxyModel     proxyModel;             // note sort model\r
54     private QAction deleteAction;\r
55     private QAction addAction;\r
56     private QAction restoreAction;\r
57     private QAction noteHistoryAction;\r
58     private QAction duplicateAction;\r
59     private QAction     mergeNotesAction;\r
60     \r
61     // Note title colors\r
62     private QAction     noteTitleColorWhite;\r
63     private QAction     noteTitleColorRed;\r
64     private QAction     noteTitleColorBlue;\r
65     private QAction     noteTitleColorGreen;\r
66     private QAction     noteTitleColorYellow;\r
67     private QAction     noteTitleColorBlack;\r
68     private QAction     noteTitleColorGray;\r
69     private QAction     noteTitleColorCyan;\r
70     private QAction     noteTitleColorMagenta;\r
71     private QAction notePinned;\r
72     private QAction copyAsUrlAction;\r
73 \r
74 \r
75     \r
76     public TableViewHeader header;\r
77     int fontHeight;\r
78     public Signal1<String> rowChanged;\r
79     public Signal0      resetViewport;\r
80     public NoteSignal noteSignal;\r
81         \r
82         public TableView(ApplicationLogger l, ListManager m) {\r
83                 logger = l;\r
84                 header = new TableViewHeader(Orientation.Horizontal,this);\r
85                 setHorizontalHeader(header);\r
86                 header.setMovable(true);\r
87                 header.subjectDateAction.toggled.connect(this, "toggleSubjectDate(Boolean)");\r
88                 header.createdDateAction.toggled.connect(this, "toggleCreationDate(Boolean)");\r
89                 header.changedDateAction.toggled.connect(this, "toggleChangedDate(Boolean)");\r
90                 header.authorAction.toggled.connect(this, "toggleAuthor(Boolean)");\r
91                 header.urlAction.toggled.connect(this, "toggleSourceUrl(Boolean)");\r
92                 header.pinnedAction.toggled.connect(this, "togglePinned(Boolean)");\r
93                 header.tagsAction.toggled.connect(this, "toggleTags(Boolean)");\r
94                 header.notebookAction.toggled.connect(this, "toggleNotebook(Boolean)");\r
95                 header.synchronizedAction.toggled.connect(this, "toggleSynchronized(Boolean)");\r
96                 header.guidAction.toggled.connect(this, "toggleGuid(Boolean)");\r
97                 header.thumbnailAction.toggled.connect(this, "toggleThumbnail(Boolean)");\r
98                 header.titleAction.toggled.connect(this, "toggleTitle(Boolean)");\r
99                 \r
100                 noteSignal = new NoteSignal();\r
101                 setAcceptDrops(true);\r
102                 setDragEnabled(true);\r
103                 setDragDropMode(QAbstractItemView.DragDropMode.DragDrop);\r
104                 setDropIndicatorShown(false);\r
105                 \r
106                 runner = m;     \r
107                 \r
108         runner.getNoteTableModel().setHeaderData(Global.noteTableCreationPosition, Qt.Orientation.Horizontal, tr("Date Created"), Qt.ItemDataRole.DisplayRole);\r
109         runner.getNoteTableModel().setHeaderData(Global.noteTableTagPosition, Qt.Orientation.Horizontal, tr("Tags"), Qt.ItemDataRole.DisplayRole);\r
110         runner.getNoteTableModel().setHeaderData(Global.noteTableGuidPosition, Qt.Orientation.Horizontal, tr("Guid"), Qt.ItemDataRole.DisplayRole);\r
111         runner.getNoteTableModel().setHeaderData(Global.noteTableNotebookPosition, Qt.Orientation.Horizontal, tr("Notebook"), Qt.ItemDataRole.DisplayRole);\r
112         runner.getNoteTableModel().setHeaderData(Global.noteTableTitlePosition, Qt.Orientation.Horizontal, tr("Title"), Qt.ItemDataRole.DisplayRole);\r
113         runner.getNoteTableModel().setHeaderData(Global.noteTableChangedPosition, Qt.Orientation.Horizontal, tr("Date Changed"), Qt.ItemDataRole.DisplayRole);\r
114         runner.getNoteTableModel().setHeaderData(Global.noteTableAuthorPosition, Qt.Orientation.Horizontal, tr("Author"), Qt.ItemDataRole.DisplayRole);\r
115         runner.getNoteTableModel().setHeaderData(Global.noteTableSourceUrlPosition, Qt.Orientation.Horizontal, tr("Source Url"), Qt.ItemDataRole.DisplayRole);\r
116         runner.getNoteTableModel().setHeaderData(Global.noteTableSubjectDatePosition, Qt.Orientation.Horizontal, tr("Subject Date"), Qt.ItemDataRole.DisplayRole);\r
117         runner.getNoteTableModel().setHeaderData(Global.noteTableSynchronizedPosition, Qt.Orientation.Horizontal, tr("Synchronized"), Qt.ItemDataRole.DisplayRole);\r
118         runner.getNoteTableModel().setHeaderData(Global.noteTablePinnedPosition, Qt.Orientation.Horizontal, tr("Pinned"), Qt.ItemDataRole.DisplayRole);\r
119         runner.getNoteTableModel().setHeaderData(Global.noteTableThumbnailPosition, Qt.Orientation.Horizontal, tr("Thumbnail"), Qt.ItemDataRole.DisplayRole);\r
120         header.sortIndicatorChanged.connect(this, "resetViewport()");\r
121        \r
122         proxyModel = new NoteSortFilterProxyModel(this);\r
123         proxyModel.setSourceModel(runner.getNoteTableModel());\r
124         setAlternatingRowColors(false);\r
125         setModel(proxyModel);\r
126         runner.getNoteTableModel().setSortProxyModel(proxyModel);\r
127                \r
128         setSortingEnabled(true);\r
129         int sortCol = proxyModel.sortColumn();\r
130                 SortOrder sortOrder = proxyModel.sortOrder();\r
131                 sortByColumn(sortCol, sortOrder);\r
132 \r
133                 setSelectionBehavior(SelectionBehavior.SelectRows);\r
134                 setSelectionMode(SelectionMode.SingleSelection);\r
135                 verticalHeader().setVisible(false);\r
136                 hideColumn(Global.noteTableGuidPosition);  // Hide the guid column\r
137                 setShowGrid(false);\r
138                 setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers);\r
139                 \r
140                 QFontMetrics f = QApplication.fontMetrics();\r
141                 fontHeight = f.height();\r
142                 rowChanged = new Signal1<String>();\r
143                 resetViewport = new Signal0();\r
144                 \r
145                 NoteTableDateDelegate dateDelegate = new NoteTableDateDelegate();\r
146                 setItemDelegateForColumn(Global.noteTableCreationPosition, dateDelegate);\r
147                 setItemDelegateForColumn(Global.noteTableChangedPosition, dateDelegate);\r
148                 setItemDelegateForColumn(Global.noteTableSubjectDatePosition, dateDelegate);\r
149                 \r
150         }\r
151         \r
152         // This should rescroll to the current item in the list when a column is \r
153         // sorted.  Somehow I can't get this to work, but this part is correct.\r
154         @SuppressWarnings("unused")\r
155         private void resetViewport() {\r
156 //              if (currentIndex() == null) \r
157 //                      return;\r
158                 \r
159 //              resetViewport.emit();\r
160         }\r
161         \r
162                 \r
163         public void load(boolean reload) {\r
164                 proxyModel.clear();\r
165                 setSortingEnabled(false);\r
166                 QFontMetrics f = QApplication.fontMetrics();\r
167                 if (!Global.isColumnVisible("thumbnail"))\r
168                                 verticalHeader().setDefaultSectionSize(f.height());\r
169                 else {\r
170                         if (Global.getListView() == Global.View_List_Wide)\r
171                                 verticalHeader().setDefaultSectionSize(Global.smallThumbnailSize.height());\r
172                         else\r
173                                 verticalHeader().setDefaultSectionSize(Global.largeThumbnailSize.height());\r
174                 }\r
175                 for (int i=0; i<runner.getNoteIndex().size(); i++) {\r
176                         String guid = runner.getNoteIndex().get(i).getGuid();\r
177                         NoteMetadata metaInfo = runner.getNoteMetadata().get(guid);\r
178                         if (Global.showDeleted == true && !runner.getNoteIndex().get(i).isActive()) {\r
179                                 proxyModel.addGuid(guid, null);\r
180                         }\r
181                         if (!Global.showDeleted == true && \r
182                                         (runner.getNoteIndex().get(i).isActive() || \r
183                                                         metaInfo.isPinned())) {         \r
184                                 proxyModel.addGuid(guid, metaInfo);\r
185                         }\r
186                 }\r
187 \r
188                 if (!reload) {\r
189                         logger.log(logger.EXTREME, "TableView.load() reload starting.");\r
190                         proxyModel.filter();\r
191                         setSortingEnabled(true);\r
192                         logger.log(logger.EXTREME, "TableView.load() leaving reload.");\r
193                         return;\r
194                 }\r
195                 logger.log(logger.EXTREME, "TableView.load() Filling table data from scratch");\r
196         \r
197                 for (int i=0; i<runner.getMasterNoteIndex().size(); i++) {\r
198                         if (runner.getMasterNoteIndex().get(i) != null) {       \r
199                                 Note note = runner.getMasterNoteIndex().get(i);\r
200                                 NoteMetadata meta = runner.getNoteMetadata().get(note.getGuid());\r
201                                 insertRow(runner.getMasterNoteIndex().get(i), meta, false, i);                                                  \r
202                         }\r
203                 } \r
204                 proxyModel.invalidate();\r
205                 \r
206                 resizeColumnWidths();\r
207                 repositionColumns();\r
208                 \r
209                 proxyModel.filter();\r
210                 \r
211                 setSortingEnabled(true);\r
212                 resetViewport.emit();\r
213         }\r
214         \r
215         public void repositionColumns() {\r
216                 int from = header.visualIndex(Global.noteTableCreationPosition);\r
217                 int to = Global.getColumnPosition("noteTableCreationPosition");\r
218                 if (to>=0) header.moveSection(from, to);\r
219 \r
220                 from = header.visualIndex(Global.noteTableTitlePosition);\r
221                 to = Global.getColumnPosition("noteTableTitlePosition");\r
222                 if (to>=0) header.moveSection(from, to);\r
223                 \r
224                 from = header.visualIndex(Global.noteTableTagPosition);\r
225                 to = Global.getColumnPosition("noteTableTagPosition");\r
226                 if (to>=0) header.moveSection(from, to);\r
227                 \r
228                 from = header.visualIndex(Global.noteTableNotebookPosition);\r
229                 to = Global.getColumnPosition("noteTableNotebookPosition");\r
230                 if (to>=0) header.moveSection(from, to);\r
231                 \r
232                 from = header.visualIndex(Global.noteTableChangedPosition);\r
233                 to = Global.getColumnPosition("noteTableChangedPosition");\r
234                 if (to>=0) header.moveSection(from, to);\r
235                 \r
236                 from = header.visualIndex(Global.noteTableSourceUrlPosition);\r
237                 to = Global.getColumnPosition("noteTableSourceUrlPosition");\r
238                 if (to>=0) header.moveSection(from, to);\r
239                 \r
240                 from = header.visualIndex(Global.noteTableAuthorPosition);\r
241                 to = Global.getColumnPosition("noteTableAuthorPosition");\r
242                 if (to>=0) header.moveSection(from, to);\r
243                 \r
244                 from = header.visualIndex(Global.noteTableSubjectDatePosition);\r
245                 to = Global.getColumnPosition("noteTableSubjectDatePosition");\r
246                 if (to>=0) header.moveSection(from, to);\r
247                 \r
248                 from = header.visualIndex(Global.noteTableSynchronizedPosition);\r
249                 to = Global.getColumnPosition("noteTableSynchronizedPosition");\r
250                 if (to>=0) header.moveSection(from, to);\r
251 \r
252                 from = header.visualIndex(Global.noteTablePinnedPosition);\r
253                 to = Global.getColumnPosition("noteTablePinnedPosition");\r
254                 if (to>=0) header.moveSection(from, to);\r
255 \r
256                 \r
257                 from = header.visualIndex(Global.noteTableGuidPosition);\r
258                 to = Global.getColumnPosition("noteTableGuidPosition");\r
259                 if (to>=0) header.moveSection(from, to);\r
260                 \r
261                 \r
262                 from = header.visualIndex(Global.noteTableThumbnailPosition);\r
263                 to = Global.getColumnPosition("noteTableThumbnailPosition");\r
264                 if (to>=0) header.moveSection(from, to);\r
265 \r
266         }\r
267         \r
268         public void resizeColumnWidths() {\r
269                 int width;\r
270                 width = Global.getColumnWidth("noteTableCreationPosition");\r
271                 if (width>0) setColumnWidth(Global.noteTableCreationPosition, width);\r
272                 width = Global.getColumnWidth("noteTableChangedPosition");\r
273                 if (width>0) setColumnWidth(Global.noteTableChangedPosition, width);\r
274                 width = Global.getColumnWidth("noteTableTitlePosition");\r
275                 if (width>0) setColumnWidth(Global.noteTableTitlePosition, width);\r
276                 width = Global.getColumnWidth("noteTableTagPosition");\r
277                 if (width>0) setColumnWidth(Global.noteTableTagPosition, width);\r
278                 width = Global.getColumnWidth("noteTableGuidPosition");\r
279                 if (width>0) setColumnWidth(Global.noteTableGuidPosition, width);\r
280                 width = Global.getColumnWidth("noteTableNotebookPosition");\r
281                 if (width>0) setColumnWidth(Global.noteTableNotebookPosition, width);\r
282                 width = Global.getColumnWidth("noteTableSourceUrlPosition");\r
283                 if (width>0) setColumnWidth(Global.noteTableSourceUrlPosition, width);\r
284                 width = Global.getColumnWidth("noteTableAuthorPosition");\r
285                 if (width>0) setColumnWidth(Global.noteTableAuthorPosition, width);\r
286                 width = Global.getColumnWidth("noteTableSubjectDatePosition");\r
287                 if (width>0) setColumnWidth(Global.noteTableSubjectDatePosition, width);\r
288                 width = Global.getColumnWidth("noteTableSynchronizedPosition");\r
289                 if (width>0) setColumnWidth(Global.noteTableSynchronizedPosition, width);\r
290                 width = Global.getColumnWidth("noteTableThumbnailPosition");\r
291                 if (width>0) setColumnWidth(Global.noteTablePinnedPosition, width);\r
292                 width = Global.getColumnWidth("noteTablePinnedPosition");\r
293                 if (width>0) setColumnWidth(Global.noteTableThumbnailPosition, width);\r
294                 width = Global.getColumnWidth("noteTableGuidPosition");\r
295                 if (width>0) setColumnWidth(Global.noteTableGuidPosition, width);\r
296 \r
297         }\r
298         \r
299         public void resizeRowHeights() {\r
300                 int height;\r
301                 if (!Global.isColumnVisible("thumbnail") || !Global.enableThumbnails()) {\r
302                         QFontMetrics f = QApplication.fontMetrics();\r
303                         verticalHeader().setDefaultSectionSize(f.height());\r
304                         height = fontHeight;\r
305                 } else {\r
306                         if (Global.getListView() == Global.View_List_Wide) {\r
307                                 verticalHeader().setDefaultSectionSize(Global.smallThumbnailSize.height());\r
308                                 height = Global.smallThumbnailSize.height();\r
309                         } else {\r
310                                 verticalHeader().setDefaultSectionSize(Global.largeThumbnailSize.height());\r
311                                 height = Global.largeThumbnailSize.height();\r
312                         }\r
313                 }\r
314                 for (int i=0; i<runner.getNoteTableModel().rowCount(); i++) {\r
315                         setRowHeight(i, height);\r
316                 }\r
317         }\r
318         \r
319         public void insertRow(Note tempNote, NoteMetadata meta, boolean newNote, int row) {\r
320                 if (newNote)\r
321                         proxyModel.addGuid(tempNote.getGuid(), meta);\r
322                 if (row > runner.getNoteTableModel().rowCount())\r
323                         runner.getNoteTableModel().insertRow(0);\r
324                 \r
325                 if (row < 0) {\r
326                         row  = runner.getNoteTableModel().rowCount();\r
327                         runner.getNoteTableModel().insertRow(row);\r
328                 }\r
329                 if (newNote) {\r
330                         resizeRowHeights();\r
331                 }\r
332         }\r
333         protected boolean filterAcceptsRow(int sourceRow, QModelIndex sourceParent) {\r
334                 return true;\r
335         }\r
336 \r
337         public void setAddAction(QAction a) {\r
338                 addAction = a;\r
339         }\r
340         \r
341         public void setMergeNotesAction(QAction a) {\r
342                 mergeNotesAction = a;\r
343         }\r
344         \r
345         public void setCopyAsUrlAction(QAction a) {\r
346                 copyAsUrlAction = a;\r
347         }\r
348         \r
349         public void setNoteHistoryAction(QAction a) {\r
350                 noteHistoryAction = a;\r
351         }\r
352         \r
353         public void setDeleteAction(QAction d) {\r
354                 deleteAction = d;\r
355         }\r
356          \r
357         public void setRestoreAction(QAction r) {\r
358                 restoreAction = r;\r
359         }\r
360         public void setNoteDuplicateAction(QAction d) {\r
361                 duplicateAction = d;\r
362         }\r
363         \r
364         @Override\r
365         public void keyPressEvent(QKeyEvent e) {\r
366                 if (e.matches(StandardKey.MoveToStartOfDocument)) {\r
367                         if (runner.getNoteTableModel().rowCount() > 0) {\r
368                                 clearSelection();\r
369                                 selectRow(0);\r
370                         }\r
371                 }\r
372                 if (e.matches(StandardKey.MoveToEndOfDocument)) {\r
373                         if (runner.getNoteTableModel().rowCount() > 0) {\r
374                                 clearSelection();\r
375                                 selectRow(model().rowCount()-1);\r
376                         }\r
377                 }\r
378                 super.keyPressEvent(e);\r
379         }\r
380         \r
381         @Override\r
382         public void contextMenuEvent(QContextMenuEvent event) {\r
383                 QMenu menu = new QMenu(this);\r
384                 if (Global.showDeleted) {\r
385                         menu.addAction(restoreAction);\r
386                 } else {\r
387                         menu.addAction(addAction);\r
388                 }\r
389                 menu.addAction(deleteAction);\r
390                 menu.addSeparator();\r
391                 menu.addAction(duplicateAction);\r
392                 menu.addAction(copyAsUrlAction);\r
393                 menu.addSeparator();\r
394                 menu.addAction(noteHistoryAction);\r
395                 menu.addAction(mergeNotesAction);\r
396                 \r
397                 QMenu titleColorMenu = new QMenu();\r
398                 titleColorMenu.setTitle(tr("Title Color"));\r
399                 menu.addMenu(titleColorMenu);\r
400                 noteTitleColorWhite = new QAction(titleColorMenu);\r
401             noteTitleColorRed = new QAction(titleColorMenu);\r
402             noteTitleColorBlue = new QAction(titleColorMenu);\r
403             noteTitleColorGreen = new QAction(titleColorMenu);\r
404             noteTitleColorYellow = new QAction(titleColorMenu);\r
405             noteTitleColorBlack = new QAction(titleColorMenu);\r
406             noteTitleColorGray = new QAction(titleColorMenu);\r
407             noteTitleColorCyan = new QAction(titleColorMenu);\r
408             noteTitleColorMagenta = new QAction(titleColorMenu);\r
409             \r
410             notePinned = new QAction(titleColorMenu);\r
411             menu.addAction(notePinned);\r
412     \r
413             noteTitleColorWhite.setText(tr("White"));\r
414             noteTitleColorRed.setText(tr("Red"));\r
415             noteTitleColorBlue.setText(tr("Blue"));\r
416             noteTitleColorGreen.setText(tr("Green"));\r
417             noteTitleColorYellow.setText(tr("Yellow"));\r
418             noteTitleColorBlack.setText(tr("Black"));\r
419             noteTitleColorGray.setText(tr("Gray"));\r
420             noteTitleColorCyan.setText(tr("Cyan"));\r
421             noteTitleColorMagenta.setText(tr("Magenta"));\r
422             notePinned.setText(tr("Pin/Unpin"));\r
423             \r
424             titleColorMenu.addAction(noteTitleColorWhite);\r
425             titleColorMenu.addAction(noteTitleColorRed);\r
426             titleColorMenu.addAction(noteTitleColorBlue);\r
427             titleColorMenu.addAction(noteTitleColorGreen);\r
428             titleColorMenu.addAction(noteTitleColorYellow);\r
429             titleColorMenu.addAction(noteTitleColorBlack);\r
430             titleColorMenu.addAction(noteTitleColorGray);\r
431             titleColorMenu.addAction(noteTitleColorCyan);\r
432             titleColorMenu.addAction(noteTitleColorMagenta);\r
433             \r
434             noteTitleColorWhite.triggered.connect(this, "titleColorWhite()");\r
435             \r
436             noteTitleColorWhite.triggered.connect(this, "titleColorWhite()");\r
437             noteTitleColorRed.triggered.connect(this, "titleColorRed()");\r
438             noteTitleColorBlue.triggered.connect(this, "titleColorBlue()");\r
439             noteTitleColorGreen.triggered.connect(this, "titleColorGreen()");\r
440             noteTitleColorYellow.triggered.connect(this, "titleColorYellow()");\r
441             noteTitleColorBlack.triggered.connect(this, "titleColorBlack()");\r
442             noteTitleColorGray.triggered.connect(this, "titleColorGray()");\r
443             noteTitleColorCyan.triggered.connect(this, "titleColorCyan()");\r
444             noteTitleColorMagenta.triggered.connect(this, "titleColorMagenta()");\r
445             notePinned.triggered.connect(this, "notePinned()");\r
446                 menu.exec(event.globalPos());\r
447         }\r
448         \r
449         \r
450     @SuppressWarnings("unused")\r
451         private void titleColorWhite() {noteSignal.titleColorChanged.emit(QColor.white.rgb());}\r
452     @SuppressWarnings("unused")\r
453         private void titleColorRed() {noteSignal.titleColorChanged.emit(QColor.red.rgb());}\r
454     @SuppressWarnings("unused")\r
455         private void titleColorBlue() {noteSignal.titleColorChanged.emit(QColor.blue.rgb());}\r
456     @SuppressWarnings("unused")\r
457         private void titleColorGreen() {noteSignal.titleColorChanged.emit(QColor.green.rgb());}\r
458     @SuppressWarnings("unused")\r
459         private void titleColorYellow(){noteSignal.titleColorChanged.emit(QColor.yellow.rgb());}\r
460     @SuppressWarnings("unused")\r
461         private void titleColorBlack() {noteSignal.titleColorChanged.emit(QColor.black.rgb());}\r
462     @SuppressWarnings("unused")\r
463         private void titleColorGray() {noteSignal.titleColorChanged.emit(QColor.gray.rgb());}\r
464     @SuppressWarnings("unused")\r
465         private void titleColorCyan() {noteSignal.titleColorChanged.emit(QColor.cyan.rgb());}\r
466     @SuppressWarnings("unused")\r
467         private void titleColorMagenta() {noteSignal.titleColorChanged.emit(QColor.magenta.rgb());}\r
468         @SuppressWarnings("unused")\r
469         private void notePinned() {noteSignal.notePinned.emit();}\r
470         \r
471 \r
472         @Override\r
473         public void dragEnterEvent(QDragEnterEvent event) {\r
474                 StringBuffer guid = new StringBuffer(1000);\r
475                 \r
476                 showColumn(Global.noteTableGuidPosition);\r
477                 List<QModelIndex> selections = selectionModel().selectedRows();\r
478                 hideColumn(Global.noteTableGuidPosition);\r
479                 \r
480         if (selections.size() > 0) {\r
481                 QModelIndex index;\r
482                 for (int i=0; i<selections.size(); i++) {\r
483                         int row = selections.get(i).row();\r
484                         index = proxyModel.index(row, Global.noteTableGuidPosition);\r
485                         SortedMap<Integer, Object> ix = proxyModel.itemData(index);\r
486                         guid.append((String)ix.values().toArray()[0]);\r
487                         guid.append(" ");\r
488                 }\r
489         }\r
490                 event.mimeData().setData("application/x-nevernote-note", new QByteArray(guid.toString()));\r
491                 event.accept();\r
492                                 \r
493         }\r
494         \r
495         @Override\r
496         public void dropEvent(QDropEvent event) {\r
497                 if (event.source() == this)\r
498                         event.ignore();\r
499         }\r
500         \r
501         // Return a column width\r
502         public int getColumnWidth(int col) {\r
503                 return columnWidth(col);\r
504         }\r
505         \r
506         public void toggleSubjectDate(Boolean toggle) {\r
507                 Global.saveColumnVisible("dateSubject", toggle);\r
508                 setColumnHidden(Global.noteTableSubjectDatePosition, !toggle);\r
509         }\r
510         \r
511         public void toggleChangedDate(Boolean toggle) {\r
512                 Global.saveColumnVisible("dateChanged", toggle);\r
513                 setColumnHidden(Global.noteTableChangedPosition, !toggle);\r
514         }\r
515         \r
516         \r
517         public void toggleCreationDate(Boolean toggle) {\r
518                 Global.saveColumnVisible("dateCreated", toggle);\r
519                 setColumnHidden(Global.noteTableCreationPosition, !toggle);\r
520         }\r
521         \r
522         public void toggleSourceUrl(Boolean toggle) {\r
523                 Global.saveColumnVisible("sourceUrl", toggle);\r
524                 setColumnHidden(Global.noteTableSourceUrlPosition, !toggle);\r
525         }\r
526         \r
527         public void toggleAuthor(Boolean toggle) {\r
528                 Global.saveColumnVisible("author", toggle);\r
529                 setColumnHidden(Global.noteTableAuthorPosition, !toggle);\r
530         }\r
531         \r
532         public void toggleNotebook(Boolean toggle) {\r
533                 Global.saveColumnVisible("notebook", toggle);\r
534                 setColumnHidden(Global.noteTableNotebookPosition, !toggle);\r
535         }\r
536 \r
537         public void toggleTitle(Boolean toggle) {\r
538                 Global.saveColumnVisible("title", toggle);\r
539                 setColumnHidden(Global.noteTableTitlePosition, !toggle);\r
540         }\r
541 \r
542         public void toggleTags(Boolean toggle) {\r
543                 Global.saveColumnVisible("tags", toggle);\r
544                 setColumnHidden(Global.noteTableTagPosition, !toggle);\r
545         }\r
546         \r
547         public void toggleSynchronized(Boolean toggle) {\r
548                 Global.saveColumnVisible("synchronized", toggle);\r
549                 setColumnHidden(Global.noteTableSynchronizedPosition, !toggle);\r
550         }\r
551         public void togglePinned(Boolean toggle) {\r
552                 Global.saveColumnVisible("pinned", toggle);\r
553                 setColumnHidden(Global.noteTablePinnedPosition, !toggle);\r
554         }\r
555         public void toggleGuid(Boolean toggle) {\r
556                 Global.saveColumnVisible("guid", toggle);\r
557                 setColumnHidden(Global.noteTableGuidPosition, !toggle);\r
558         }       \r
559         public void toggleThumbnail(Boolean toggle) {\r
560                 Global.saveColumnVisible("thumbnail", toggle);\r
561                 int size;\r
562                 if (!toggle) {\r
563                         QFontMetrics f = QApplication.fontMetrics();\r
564                         size = f.height();\r
565                         verticalHeader().setDefaultSectionSize(f.height());\r
566                 } else\r
567                         size = Global.smallThumbnailSize.height();\r
568                 for (int i=0; i<runner.getNoteTableModel().rowCount(); i++) {\r
569                         setRowHeight(i, size);\r
570                 }\r
571                         \r
572                 setColumnHidden(Global.noteTableThumbnailPosition, !toggle);\r
573         }\r
574         \r
575 }\r