1 /*************************************************************************** 2 ** ** 3 ** Polyphone, a soundfont editor ** 4 ** Copyright (C) 2013-2020 Davy Triponney ** 5 ** ** 6 ** This program is free software: you can redistribute it and/or modify ** 7 ** it under the terms of the GNU General Public License as published by ** 8 ** the Free Software Foundation, either version 3 of the License, or ** 9 ** (at your option) any later version. ** 10 ** ** 11 ** This program is distributed in the hope that it will be useful, ** 12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** 13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** 14 ** GNU General Public License for more details. ** 15 ** ** 16 ** You should have received a copy of the GNU General Public License ** 17 ** along with this program. If not, see http://www.gnu.org/licenses/. ** 18 ** ** 19 **************************************************************************** 20 ** Author: Davy Triponney ** 21 ** Website/Contact: https://www.polyphone-soundfonts.com ** 22 ** Date: 01.01.2013 ** 23 ***************************************************************************/ 24 25 #ifndef ABSTRACTTOOL_H 26 #define ABSTRACTTOOL_H 27 28 #include "basetypes.h" 29 #include <QObject> 30 class QWidget; 31 class SoundfontManager; 32 class AbstractToolGui; 33 class AbstractToolParameters; 34 class ToolDialog; 35 36 class AbstractTool: public QObject 37 { 38 Q_OBJECT 39 40 public: 41 AbstractTool(AbstractToolParameters * parameters = nullptr, AbstractToolGui * gui = nullptr); 42 virtual ~AbstractTool(); 43 44 /// Initialization of resources shared by all tools 45 static void initialize(QWidget * parent); 46 47 /// Icon, label and category displayed to the user to describe the tool 48 virtual QString getIconName() const = 0; 49 QString getLabel() const; 50 virtual QString getCategory() const = 0; 51 52 /// Internal identifier 53 virtual QString getIdentifier() const = 0; 54 55 /// Set the ids and return true if the tool can be used on the specified ids 56 bool setIds(IdList ids); 57 58 /// Run the tool on the specified list of ids 59 void run(); 60 61 signals: 62 void finished(bool updateNeeded); 63 64 protected: 65 /// Get the name of the tool. It will be then followed by "..." if there is a GUI 66 virtual QString getLabelInternal() const = 0; 67 68 /// Return true if the tool can be used on the specified ids 69 virtual bool isCompatible(IdList ids) = 0; 70 71 /// Run the tool, emit the signal "finished" at the end 72 virtual void runInternal(SoundfontManager * sm, QWidget * parent, IdList ids, AbstractToolParameters * parameters) = 0; 73 74 /// Get the warning to display after the tool is run 75 virtual QString getWarning() { return ""; } 76 77 /// Get a confirmation message after the tool is run 78 virtual QString getConfirmation() { return ""; } 79 80 private slots: 81 void onFinished(bool updateNeeded); 82 void onParametersValidated(); 83 84 private: 85 AbstractToolParameters * _toolParameters; 86 AbstractToolGui * _toolGui; 87 ToolDialog * _toolDialog; 88 IdList _currentIds; 89 90 static QWidget * s_parent; // For opening dialogs 91 static SoundfontManager * s_sm; 92 }; 93 94 #endif // ABSTRACTTOOL_H 95