1 #ifndef TOOLBARACTION_H 2 #define TOOLBARACTION_H 3 4 #include <QString> 5 #include <QIcon> 6 #include <QObject> 7 8 enum item_enum 9 { 10 itemSeparator, 11 itemAdd, 12 itemAddText, 13 itemAddHtml, 14 itemAddTodo, 15 itemRemove, 16 itemRename, 17 itemBack, 18 itemForward, 19 itemPrev, 20 itemNext, 21 itemCopy, 22 itemSetup, 23 itemInfo, 24 itemRun, 25 itemSearch, 26 itemExit, 27 itemFormatBold, 28 itemFormatItalic, 29 itemFormatStrikeout, 30 itemFormatUnderline, 31 itemFormatColor, 32 itemExportPdf, 33 itemPrintNote, 34 itemPrintPreviewNote, 35 itemMax 36 }; 37 38 class ToolbarAction 39 { 40 public: item_id(id)41 ToolbarAction(item_enum id, bool use_system_icons_theme = false):item_id(id), use_system_icons_theme(use_system_icons_theme) {} 42 // Returning action's title text()43 inline const QString text() const 44 { 45 switch(item_id) 46 { 47 case itemSeparator: return QObject::tr("Separator"); 48 case itemAdd: return QObject::tr("Create new note"); 49 case itemAddText: return QObject::tr("Create new Text note"); 50 case itemAddHtml: return QObject::tr("Create new HTML note"); 51 case itemAddTodo: return QObject::tr("Create new TODO note"); 52 case itemRemove: return QObject::tr("Remove this note"); 53 case itemRename: return QObject::tr("Rename this note"); 54 case itemBack: return QObject::tr("Back"); 55 case itemForward: return QObject::tr("Forward"); 56 case itemPrev: return QObject::tr("Prev note"); 57 case itemNext: return QObject::tr("Next note"); 58 case itemCopy: return QObject::tr("Copy this note to clipboard"); 59 case itemSetup: return QObject::tr("Preferences"); 60 case itemInfo: return QObject::tr("Info"); 61 case itemRun: return QObject::tr("Commands"); 62 case itemSearch: return QObject::tr("Search"); 63 case itemExit: return QObject::tr("Exit"); 64 case itemFormatBold: return QObject::tr("Bold"); 65 case itemFormatItalic: return QObject::tr("Italic"); 66 case itemFormatStrikeout: return QObject::tr("Strikeout"); 67 case itemFormatUnderline: return QObject::tr("Underline"); 68 case itemFormatColor: return QObject::tr("Text color"); 69 case itemExportPdf: return QObject::tr("Export note to PDF"); 70 case itemPrintNote: return QObject::tr("Print..."); 71 case itemPrintPreviewNote: return QObject::tr("Print Preview..."); 72 default: return 0; 73 } 74 } 75 //Returning action's icon icon()76 inline QIcon icon() const 77 { 78 switch(item_id) 79 { 80 case itemAdd: return loadIcon("list-add"); 81 case itemAddText: return loadIcon("list-add"); 82 case itemAddHtml: return loadIcon("list-add"); 83 case itemAddTodo: return loadIcon("list-add"); 84 case itemRemove: return loadIcon("list-remove"); 85 case itemRename: return loadIcon("edit-rename"); 86 case itemBack: return loadIcon("go-previous"); 87 case itemForward: return loadIcon("go-next"); 88 case itemPrev: return loadIcon("go-previous-view"); 89 case itemNext: return loadIcon("go-next-view"); 90 case itemCopy: return loadIcon("edit-copy"); 91 case itemSetup: return loadIcon("configure"); 92 case itemInfo: return loadIcon("help-about"); 93 case itemRun: return loadIcon("run-build"); 94 case itemSearch: return loadIcon("edit-find"); 95 case itemExit: return loadIcon("window-close"); 96 case itemFormatBold: return loadIcon("format-text-bold"); 97 case itemFormatItalic: return loadIcon("format-text-italic"); 98 case itemFormatStrikeout: return loadIcon("format-text-strikethrough"); 99 case itemFormatUnderline: return loadIcon("format-text-underline"); 100 case itemFormatColor: return loadIcon("format-text-color"); 101 case itemExportPdf: return loadIcon("application-pdf"); 102 case itemPrintNote: return loadIcon("printer"); 103 case itemPrintPreviewNote: return loadIcon("document-print-preview"); 104 default: return QIcon(); 105 } 106 } loadIcon(const QString & file_name)107 inline QIcon loadIcon(const QString& file_name) const { 108 auto fallback_icon = QIcon(":/res/toolbar/" + file_name + ".png"); 109 return use_system_icons_theme ? QIcon::fromTheme(file_name, fallback_icon) : fallback_icon; 110 } 111 //Returning action's identifiactor in configuration file pref_name()112 inline const QString pref_name() const 113 { 114 switch(item_id) 115 { 116 case itemAdd: return "Toolbar/itemAdd"; 117 case itemAddText: return "Toolbar/itemAddText"; 118 case itemAddHtml: return "Toolbar/itemAddHtml"; 119 case itemAddTodo: return "Toolbar/itemAddTodo"; 120 case itemRemove: return "Toolbar/itemRemove"; 121 case itemRename: return "Toolbar/itemRename"; 122 case itemBack: return "Toolbar/itemBack"; 123 case itemForward: return "Toolbar/itemForward"; 124 case itemPrev: return "Toolbar/itemPrev"; 125 case itemNext: return "Toolbar/itemNext"; 126 case itemCopy: return "Toolbar/itemCopy"; 127 case itemSetup: return "Toolbar/itemSetup"; 128 case itemInfo: return "Toolbar/itemInfo"; 129 case itemRun: return "Toolbar/itemRun"; 130 case itemSearch: return "Toolbar/itemSearch"; 131 case itemExit: return "Toolbar/itemExit"; 132 case itemFormatBold: return "Toolbar/itemFormatBold"; 133 case itemFormatItalic: return "Toolbar/itemFormatItalic"; 134 case itemFormatStrikeout: return "Toolbar/itemFormatStrikeout"; 135 case itemFormatUnderline: return "Toolbar/itemFormatUnderline"; 136 case itemFormatColor: return "Toolbar/itemFormatColor"; 137 case itemExportPdf: return "Toolbar/itemExportPdf"; 138 case itemPrintNote: return "Toolbar/itemPrint"; 139 case itemPrintPreviewNote: return "Toolbar/itemPrintPreview"; 140 default: return ""; 141 } 142 } isSeparator()143 inline bool isSeparator() { return item_id == itemSeparator; } isCheckable()144 inline bool isCheckable() 145 { 146 switch(item_id) 147 { 148 case itemSearch: 149 case itemFormatBold: 150 case itemFormatItalic: 151 case itemFormatStrikeout: 152 case itemFormatUnderline: 153 return true; 154 default: 155 return false; 156 } 157 } 158 //Is item enabled when notelist is empty isEnabledWhenEmpty()159 inline bool isEnabledWhenEmpty() 160 { 161 switch(item_id) 162 { 163 case itemAdd: 164 case itemAddText: 165 case itemAddHtml: 166 case itemAddTodo: 167 return true; 168 default: 169 return false; 170 } 171 } 172 173 private: 174 item_enum item_id; 175 bool use_system_icons_theme; 176 }; 177 178 #endif // TOOLBARACTION_H 179