1 /* 2 * Copyright (C) 2018 Damir Porobic <damir.porobic@gmx.com> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License as published by 6 * the Free Software Foundation; either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef KIMAGEANNOTATOR_TOOLPICKER_H 21 #define KIMAGEANNOTATOR_TOOLPICKER_H 22 23 #include <QWidget> 24 #include <QActionGroup> 25 #include <QToolButton> 26 #include <QMenu> 27 28 #include "CustomToolButton.h" 29 #include "CustomToolButtonAction.h" 30 #include "src/common/enum/Tools.h" 31 #include "src/common/helper/IconLoader.h" 32 #include "src/widgets/misc/FlowLayout.h" 33 34 namespace kImageAnnotator { 35 36 class ToolPicker : public QWidget 37 { 38 Q_OBJECT 39 public: 40 explicit ToolPicker(QWidget *parent); 41 ~ToolPicker() override = default; 42 void setTool(Tools newTool); 43 Tools tool(); 44 45 signals: 46 void toolSelected(Tools newTool); 47 48 private: 49 QActionGroup *mActionGroup; 50 FlowLayout *mLayout; 51 Tools mSelectedToolType; 52 QHash<QAction *, Tools> mActionToTool; 53 QHash<QAction *, CustomToolButton *> mActionToButton; 54 55 void initGui(); 56 QAction *createAction(const QString &tooltip, const QIcon &icon, Qt::Key shortcut, Tools toolType); 57 CustomToolButton *createButton(QAction *defaultAction); 58 CustomToolButton *createButton(QMenu *menu); 59 60 private slots: 61 void actionTriggered(QAction *action); 62 void setToolAndNotify(Tools newTool); 63 }; 64 65 } // namespace kImageAnnotator 66 67 #endif // KIMAGEANNOTATOR_TOOLPICKER_H 68