File_Notebook_Edit // Edit an existing notebook
File_Notebook_Delete // Delete the existing notebook
File_Notebook_Close // Open/Close (i.e. archive) a notebook
+File_Notebook_Icon // Modify the selected notebook icon
File_Tag_Add Ctrl+Shift+T // Add a notebook
File_Tag_Edit // Edit an existing notebook
File_Tag_Delete // Delete the existing notebook
+File_Tag_Icon // Modify the selected tag(s) icon.
File_SavedSearch_Add // Add a notebook
File_SavedSearch_Edit // Edit an existing notebook
File_SavedSearch_Delete // Delete the existing notebook
tagTree.setDeleteAction(menuBar.tagDeleteAction);
tagTree.setEditAction(menuBar.tagEditAction);
tagTree.setAddAction(menuBar.tagAddAction);
+ tagTree.setIconAction(menuBar.tagIconAction);
tagTree.setVisible(Global.isWindowVisible("tagTree"));
tagTree.noteSignal.tagsAdded.connect(this, "tagsAdded(String, String)");
menuBar.hideTags.setChecked(Global.isWindowVisible("tagTree"));
if (selections.size() > 0) {
menuBar.tagEditAction.setEnabled(true);
menuBar.tagDeleteAction.setEnabled(true);
+ menuBar.tagIconAction.setEnabled(true);
}
else {
menuBar.tagEditAction.setEnabled(false);
menuBar.tagDeleteAction.setEnabled(false);
+ menuBar.tagIconAction.setEnabled(true);
}
if (selectedTagGUIDs.size() == 1 && selectedTagGUIDs.get(0).equals(previousSelectedTag)) {
previousSelectedTag = selectedTagGUIDs.get(0);
// selectedTagGUIDs.clear(); // clear out old entries
tagTree.blockSignals(true);
- if (reload)
+ if (reload) {
+ tagTree.setIcons(conn.getTagTable().getAllIcons());
tagTree.load(listManager.getTagIndex());
+ }
for (int i=selectedTagGUIDs.size()-1; i>=0; i--) {
boolean found = tagTree.selectGuid(selectedTagGUIDs.get(i));
if (!found)
menuBar.noteRestoreAction.setVisible(false);
menuBar.tagEditAction.setEnabled(false);
menuBar.tagDeleteAction.setEnabled(false);
+ menuBar.tagIconAction.setEnabled(false);
selectedTagGUIDs.clear();
listManager.setSelectedTags(selectedTagGUIDs);
tagTree.blockSignals(false);
}
+ // Change the icon for a tag
+ // Change the notebook's icon
+ private void setTagIcon() {
+ QTreeWidgetItem currentSelection;
+ List<QTreeWidgetItem> selections = tagTree.selectedItems();
+ if (selections.size() == 0)
+ return;
+
+ currentSelection = selections.get(0);
+ String guid = currentSelection.text(2);
+
+ QIcon currentIcon = currentSelection.icon(0);
+ QIcon icon = conn.getTagTable().getIcon(guid);
+ SetIcon dialog;
+ if (icon == null) {
+ dialog = new SetIcon(currentIcon);
+ dialog.setUseDefaultIcon(true);
+ } else {
+ dialog = new SetIcon(icon);
+ dialog.setUseDefaultIcon(false);
+ }
+ dialog.exec();
+ if (dialog.okPressed()) {
+ QIcon newIcon = dialog.getIcon();
+ conn.getTagTable().setIcon(guid, newIcon, dialog.getFileType());
+ if (newIcon == null)
+ newIcon = new QIcon(iconPath+"tag.png");
+ currentSelection.setIcon(0, newIcon);
+ }
+ }
+
//***************************************************************
//***************************************************************
public QAction tagEditAction; // Edit a tag\r
public QAction tagAddAction; // Add a tag\r
public QAction tagDeleteAction; // Delete a tag\r
+ public QAction tagIconAction; // Change the icon\r
\r
//**************************************************************************\r
//* Menu Bar Titles\r
tagDeleteAction.setEnabled(false); \r
setupShortcut(tagDeleteAction, "File_Tag_Delete");\r
\r
+ tagIconAction = new QAction(tr("Change Icon"), this);\r
+ tagIconAction.triggered.connect(parent, "setTagIcon()");\r
+ tagIconAction.setEnabled(false); \r
+ setupShortcut(tagIconAction, "File_Tag_Icon");\r
+ \r
savedSearchAddAction = new QAction(tr("Add"),this);\r
savedSearchAddAction.triggered.connect(parent, "addSavedSearch()");\r
setupShortcut(savedSearchAddAction, "File_SavedSearch_Add");\r
tagMenu.addAction(tagAddAction);\r
tagMenu.addAction(tagEditAction);\r
tagMenu.addAction(tagDeleteAction);\r
+ tagMenu.addSeparator();\r
+ tagMenu.addAction(tagIconAction);\r
\r
savedSearchMenu.addAction(savedSearchAddAction);\r
savedSearchMenu.addAction(savedSearchEditAction);\r
package cx.fbn.nevernote.gui;\r
\r
import java.util.ArrayList;\r
+import java.util.HashMap;\r
import java.util.List;\r
\r
import com.evernote.edam.type.Tag;\r
private QAction editAction;\r
private QAction deleteAction;\r
private QAction addAction;\r
+ private QAction iconAction;\r
public TagSignal tagSignal;\r
public NoteSignal noteSignal;\r
private boolean showAllTags;\r
private final DatabaseConnection db;\r
+ private HashMap<String, QIcon> icons;\r
\r
\r
public TagTreeWidget(DatabaseConnection d) {\r
public void setAddAction(QAction a) {\r
addAction = a;\r
}\r
+ public void setIconAction(QAction i) {\r
+ iconAction = i;\r
+ }\r
\r
// Insert a new tag into the tree. This is used when we dynamically add a \r
// new tag after the full tag tree has been built. It only adds to the\r
if (tag.getParentGuid()==null || tag.getParentGuid().equals("")) {\r
child = new QTreeWidgetItem();\r
child.setText(0, tag.getName());\r
- child.setIcon(0,icon);\r
+ if (icons != null && !icons.containsKey(tag.getGuid())) {\r
+ child.setIcon(0, icon);\r
+ } else {\r
+ child.setIcon(0, icons.get(tag.getGuid()));\r
+ }\r
+\r
child.setText(2, tag.getGuid());\r
child.setTextAlignment(1, ra.value());\r
index.add(child);\r
menu.addAction(addAction);\r
menu.addAction(editAction);\r
menu.addAction(deleteAction);\r
+ menu.addSeparator();\r
+ menu.addAction(iconAction);\r
menu.exec(event.globalPos());\r
}\r
\r
+ public void setIcons(HashMap<String, QIcon> i) {\r
+ icons = i;\r
+ }\r
+ \r
// Copy an individual item within the tree. I need to do this because\r
// Qt doesn't call the dropMimeData on a move, just a copy.\r
private void copyTreeItem(QTreeWidgetItem source, QTreeWidgetItem target) {\r
package cx.fbn.nevernote.sql;\r
\r
import java.util.ArrayList;\r
+import java.util.HashMap;\r
import java.util.List;\r
\r
import com.evernote.edam.type.Tag;\r
+import com.trolltech.qt.core.QBuffer;\r
+import com.trolltech.qt.core.QByteArray;\r
+import com.trolltech.qt.core.QIODevice;\r
+import com.trolltech.qt.gui.QIcon;\r
+import com.trolltech.qt.gui.QImage;\r
+import com.trolltech.qt.gui.QPixmap;\r
\r
import cx.fbn.nevernote.sql.driver.NSqlQuery;\r
import cx.fbn.nevernote.utilities.ApplicationLogger;\r
public class TagTable {\r
private final ApplicationLogger logger;\r
DatabaseConnection db;\r
+ private HashMap<String, QIcon> icons;\r
\r
public TagTable (ApplicationLogger l, DatabaseConnection d) {\r
logger = l;\r
if (!query.exec())\r
logger.log(logger.EXTREME, "Error resetting tag dirty field.");\r
}\r
+ \r
+ \r
+ // Get the custom icon\r
+ public QIcon getIcon(String guid) {\r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ \r
+ if (!query.prepare("Select icon from tag where guid=:guid"))\r
+ logger.log(logger.EXTREME, "Error preparing tag icon select.");\r
+ query.bindValue(":guid", guid);\r
+ if (!query.exec())\r
+ logger.log(logger.EXTREME, "Error finding tag icon.");\r
+ if (!query.next() || query.getBlob(0) == null)\r
+ return null;\r
+ \r
+ QByteArray blob = new QByteArray(query.getBlob(0));\r
+ QIcon icon = new QIcon(QPixmap.fromImage(QImage.fromData(blob)));\r
+ return icon;\r
+ }\r
+ // Set the custom icon\r
+ public void setIcon(String guid, QIcon icon, String type) {\r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ if (icon == null) {\r
+ if (!query.prepare("update tag set icon=null where guid=:guid"))\r
+ logger.log(logger.EXTREME, "Error preparing tag icon select.");\r
+ } else {\r
+ if (!query.prepare("update tag set icon=:icon where guid=:guid"))\r
+ logger.log(logger.EXTREME, "Error preparing tag icon select.");\r
+ QBuffer buffer = new QBuffer();\r
+ if (!buffer.open(QIODevice.OpenModeFlag.ReadWrite)) {\r
+ logger.log(logger.EXTREME, "Failure to open buffer. Aborting.");\r
+ return;\r
+ }\r
+ QPixmap p = icon.pixmap(32, 32);\r
+ QImage i = p.toImage();\r
+ i.save(buffer, type.toUpperCase());\r
+ buffer.close();\r
+ QByteArray b = new QByteArray(buffer.buffer());\r
+ if (!b.isNull() && !b.isEmpty())\r
+ query.bindValue(":icon", b.toByteArray());\r
+ else\r
+ return;\r
+ }\r
+ query.bindValue(":guid", guid);\r
+ if (!query.exec()) \r
+ logger.log(logger.LOW, "Error setting tag icon. " +query.lastError());\r
+ }\r
+\r
+ // Get a list of all icons\r
+ public HashMap<String, QIcon> getAllIcons() {\r
+ HashMap<String, QIcon> values = new HashMap<String, QIcon>();\r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ \r
+ if (!query.exec("SELECT guid, icon from tag"))\r
+ logger.log(logger.EXTREME, "Error executing notebook getAllIcons select.");\r
+ while (query.next()) {\r
+ if (query.getBlob(1) != null) {\r
+ String guid = query.valueString(0);\r
+ QByteArray blob = new QByteArray(query.getBlob(1));\r
+ QIcon icon = new QIcon(QPixmap.fromImage(QImage.fromData(blob)));\r
+ values.put(guid, icon);\r
+ }\r
+ }\r
+ return values;\r
+ }\r
+\r
}\r