Warning, file /education/parley/src/parleyactions.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2009 Frederik Gladhorn <gladhorn@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 #include "parleyactions.h" 0006 0007 #include "prefs.h" 0008 0009 #include <KActionCollection> 0010 #include <KLocalizedString> 0011 #include <KStandardAction> 0012 #include <KToggleAction> 0013 #include <kns3/knewstuffaction.h> 0014 0015 #include <QIcon> 0016 0017 namespace ParleyActions 0018 { 0019 namespace Private 0020 { 0021 QAction *createCustomAction(const QObject *recvr, 0022 const char *slot, 0023 QObject *parent, 0024 const QString &name, 0025 const QString &text, 0026 const QString &helpText, 0027 const QString &iconName = QString(), 0028 bool toggle = false) 0029 { 0030 // Create QAction or KToggleAction 0031 QAction *pAction; 0032 if (toggle) { 0033 pAction = new KToggleAction(parent); 0034 } else { 0035 pAction = new QAction(parent); 0036 } 0037 // Set ObjectName, Text and HelpText 0038 pAction->setObjectName(name); 0039 pAction->setText(text); 0040 pAction->setToolTip(helpText); 0041 0042 // Icon 0043 if (!iconName.isEmpty()) { 0044 QIcon foundIcon(QIcon::fromTheme(iconName)); 0045 if (foundIcon.isNull()) { 0046 // Note: If you are using an alternative /usr/share/icons directory you need to 0047 // copy the /usr/share/icons/<theme>/index.theme into you alternate directory 0048 qDebug() << "Missing QIcon " << iconName; 0049 } 0050 pAction->setIcon(foundIcon); 0051 } 0052 0053 // Connect the action 0054 pAction->connect(pAction, SIGNAL(triggered(bool)), recvr, slot); 0055 0056 // If parent is a KActionCollection, add the new action to it 0057 KActionCollection *collection = qobject_cast<KActionCollection *>(parent); 0058 if (pAction && collection) 0059 collection->addAction(pAction->objectName(), pAction); 0060 return pAction; 0061 } 0062 } 0063 } 0064 0065 QAction *ParleyActions::create(ParleyAction id, const QObject *recvr, const char *slot, KActionCollection *parent) 0066 { 0067 QAction *pAction = 0; 0068 0069 switch (id) { 0070 case FileNew: 0071 pAction = KStandardAction::openNew(recvr, slot, parent); 0072 pAction->setToolTip(i18n("Creates a new vocabulary collection")); 0073 parent->setDefaultShortcut(pAction, QKeySequence::New); 0074 break; 0075 case FileOpen: 0076 pAction = KStandardAction::open(recvr, slot, parent); 0077 pAction->setToolTip(i18n("Opens an existing vocabulary collection")); 0078 parent->setDefaultShortcut(pAction, QKeySequence::Open); 0079 break; 0080 case FileOpenDownloaded: 0081 pAction = Private::createCustomAction(recvr, 0082 slot, 0083 parent, 0084 QStringLiteral("file_open_downloaded"), 0085 i18n("Open &Downloaded Vocabularies..."), 0086 i18n("Open downloaded vocabulary collections"), 0087 QStringLiteral("get-hot-new-stuff")); 0088 break; 0089 case FileSave: 0090 pAction = KStandardAction::save(recvr, slot, parent); 0091 pAction->setToolTip(i18n("Save the active vocabulary collection")); 0092 parent->setDefaultShortcut(pAction, QKeySequence::Save); 0093 break; 0094 case FileSaveAs: 0095 pAction = KStandardAction::saveAs(recvr, slot, parent); 0096 pAction->setShortcut(QKeySequence::SaveAs); 0097 parent->setDefaultShortcut(pAction, QKeySequence::SaveAs); 0098 pAction->setToolTip(i18n("Save the active vocabulary collection with a different name")); 0099 break; 0100 case FileExport: 0101 pAction = Private::createCustomAction(recvr, 0102 slot, 0103 parent, 0104 QStringLiteral("file_export"), 0105 i18n("&Export..."), 0106 i18n("Export to HTML or CSV"), 0107 QStringLiteral("document-export")); 0108 break; 0109 case FileProperties: 0110 pAction = Private::createCustomAction(recvr, 0111 slot, 0112 parent, 0113 QStringLiteral("file_properties"), 0114 i18n("&Properties..."), 0115 i18n("Edit document properties"), 0116 QStringLiteral("document-properties")); 0117 break; 0118 case FileClose: 0119 pAction = Private::createCustomAction(recvr, 0120 slot, 0121 parent, 0122 QStringLiteral("file_close"), 0123 i18n("Dashboard"), 0124 i18n("Close the current vocabulary collection and show the dashboard"), 0125 QStringLiteral("go-home")); 0126 break; 0127 case FileQuit: 0128 pAction = KStandardAction::quit(recvr, slot, parent); 0129 parent->setDefaultShortcut(pAction, QKeySequence::Quit); 0130 pAction->setToolTip(i18n("Quit Parley")); 0131 break; 0132 case Preferences: 0133 pAction = KStandardAction::preferences(recvr, slot, parent); 0134 parent->setDefaultShortcut(pAction, QKeySequence::Preferences); 0135 pAction->setToolTip(i18n("Show the configuration dialog")); 0136 break; 0137 case LanguagesProperties: 0138 pAction = Private::createCustomAction(recvr, 0139 slot, 0140 parent, 0141 QStringLiteral("edit_languages"), 0142 i18n("&Languages..."), 0143 i18n("Edit which languages are in the collection and their grammar properties."), 0144 QStringLiteral("set-language")); 0145 break; 0146 case RemoveGrades: 0147 pAction = Private::createCustomAction(recvr, 0148 slot, 0149 parent, 0150 QStringLiteral("vocab_remove_grades"), 0151 i18n("Remove Confidence Levels"), 0152 i18n("Remove all confidence levels from the current document"), 0153 QStringLiteral("edit-clear")); 0154 break; 0155 case CheckSpelling: 0156 pAction = KStandardAction::spelling(recvr, slot, parent); 0157 break; 0158 case ToggleShowSublessons: 0159 pAction = Private::createCustomAction(recvr, 0160 slot, 0161 parent, 0162 QStringLiteral("lesson_showsublessonentries"), 0163 i18n("Show Entries from Child Units"), 0164 i18n("Enable to also see the entries of child units in each unit."), 0165 QString(), 0166 true); 0167 pAction->setChecked(Prefs::showSublessonentries()); 0168 break; 0169 case AutomaticTranslation: 0170 pAction = Private::createCustomAction(recvr, 0171 slot, 0172 parent, 0173 QStringLiteral("lesson_automatictranslation"), 0174 i18n("Automatic Translation"), 0175 i18n("Enable automatic translation of the unit entries."), 0176 QString(), 0177 true); 0178 pAction->setChecked(Prefs::automaticTranslation()); 0179 break; 0180 case StartPractice: 0181 pAction = Private::createCustomAction(recvr, 0182 slot, 0183 parent, 0184 QStringLiteral("practice_start"), 0185 i18n("Start Practice..."), 0186 i18n("Start practicing"), 0187 QStringLiteral("practice-start")); 0188 break; 0189 case ConfigurePractice: 0190 pAction = Private::createCustomAction(recvr, 0191 slot, 0192 parent, 0193 QStringLiteral("practice_configure"), 0194 i18n("Configure Practice..."), 0195 i18n("Change practice settings"), 0196 QStringLiteral("practice-setup")); 0197 break; 0198 case ExportPracticeResults: 0199 pAction = Private::createCustomAction(recvr, 0200 slot, 0201 parent, 0202 QStringLiteral("practice_export"), 0203 i18n("Export Results..."), 0204 i18n("Write a file with the results of the practice"), 0205 QStringLiteral("document-export")); 0206 break; 0207 case EnterEditMode: 0208 pAction = Private::createCustomAction(recvr, 0209 slot, 0210 parent, 0211 QStringLiteral("document_edit"), 0212 i18n("Editor"), 0213 i18n("Switch to vocabulary editor"), 0214 QStringLiteral("document-edit")); 0215 break; 0216 case ToggleSearchBar: 0217 pAction = Private::createCustomAction(recvr, 0218 slot, 0219 parent, 0220 QStringLiteral("config_show_search"), 0221 i18n("Show Se&arch"), 0222 i18n("Toggle display of the search bar"), 0223 QString(), 0224 true); 0225 pAction->setChecked(Prefs::showSearch()); 0226 break; 0227 case SearchVocabulary: 0228 pAction = KStandardAction::find(recvr, slot, parent); 0229 parent->setDefaultShortcut(pAction, QKeySequence::Find); 0230 break; 0231 } 0232 0233 Q_ASSERT(pAction); 0234 return pAction; 0235 } 0236 0237 KRecentFilesAction *ParleyActions::createRecentFilesAction(const QObject *recvr, const char *slot, QObject *parent) 0238 { 0239 return KStandardAction::openRecent(recvr, slot, parent); 0240 }