OSDN Git Service

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