| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2011 Thomas Anderson <ta@nextgenengineering> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library 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 Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
#ifndef GUI_DIALOG_DLGCUSTOMIZESPACEBALL_H |
| 24 |
#define GUI_DIALOG_DLGCUSTOMIZESPACEBALL_H |
| 25 |
|
| 26 |
#include <QAbstractListModel> |
| 27 |
#include <QComboBox> |
| 28 |
#include <QListView> |
| 29 |
#include <QTreeView> |
| 30 |
#include "PropertyPage.h" |
| 31 |
|
| 32 |
#include <boost/foreach.hpp> |
| 33 |
#include <boost/property_tree/ptree.hpp> |
| 34 |
#include <boost/property_tree/xml_parser.hpp> |
| 35 |
|
| 36 |
class Command; |
| 37 |
class QPushButton; |
| 38 |
|
| 39 |
namespace Gui |
| 40 |
{ |
| 41 |
namespace Dialog |
| 42 |
{ |
| 43 |
class ButtonView: public QListView |
| 44 |
{ |
| 45 |
Q_OBJECT |
| 46 |
public: |
| 47 |
explicit ButtonView(QWidget* parent = nullptr); |
| 48 |
void selectButton(int number); |
| 49 |
Q_SIGNALS: |
| 50 |
void changeCommandSelection(const QString& commandName); |
| 51 |
public Q_SLOTS: |
| 52 |
void goSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected); |
| 53 |
void goChangedCommand(const QString& commandName); |
| 54 |
}; |
| 55 |
|
| 56 |
class ButtonModel: public QAbstractListModel |
| 57 |
{ |
| 58 |
Q_OBJECT |
| 59 |
public: |
| 60 |
explicit ButtonModel(QObject* parent); |
| 61 |
int rowCount(const QModelIndex& parent = QModelIndex()) const override; |
| 62 |
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; |
| 63 |
void insertButtonRows(int number); |
| 64 |
void setCommand(int row, QString command); |
| 65 |
void goButtonPress(int number); |
| 66 |
void goMacroRemoved(const QByteArray& macroName); |
| 67 |
void goClear(); |
| 68 |
void loadConfig(const char* RequiredDeviceName); |
| 69 |
|
| 70 |
private: |
| 71 |
void load3DConnexionButtonMapping(boost::property_tree::ptree ButtonMapTree); |
| 72 |
void load3DConnexionButtons(const char* RequiredDeviceName); |
| 73 |
ParameterGrp::handle spaceballButtonGroup() const; |
| 74 |
QString getLabel(const int& number) const; |
| 75 |
}; |
| 76 |
|
| 77 |
class CommandView: public QTreeView |
| 78 |
{ |
| 79 |
Q_OBJECT |
| 80 |
public: |
| 81 |
explicit CommandView(QWidget* parent = nullptr); |
| 82 |
public Q_SLOTS: |
| 83 |
void goChangeCommandSelection(const QString& commandName); |
| 84 |
private Q_SLOTS: |
| 85 |
void goClicked(const QModelIndex& index); |
| 86 |
Q_SIGNALS: |
| 87 |
void changedCommand(const QString& commandName); |
| 88 |
}; |
| 89 |
|
| 90 |
class CommandNode |
| 91 |
{ |
| 92 |
public: |
| 93 |
enum NodeType |
| 94 |
{ |
| 95 |
RootType, |
| 96 |
GroupType, |
| 97 |
CommandType |
| 98 |
}; |
| 99 |
|
| 100 |
explicit CommandNode(NodeType typeIn); |
| 101 |
~CommandNode(); |
| 102 |
|
| 103 |
NodeType nodeType; |
| 104 |
Command* aCommand; |
| 105 |
QString labelText; |
| 106 |
CommandNode* parent; |
| 107 |
QList<CommandNode*> children; |
| 108 |
}; |
| 109 |
|
| 110 |
class CommandModel: public QAbstractItemModel |
| 111 |
{ |
| 112 |
Q_OBJECT |
| 113 |
public: |
| 114 |
explicit CommandModel(QObject* parent = nullptr); |
| 115 |
~CommandModel() override; |
| 116 |
QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; |
| 117 |
QModelIndex parent(const QModelIndex& index) const override; |
| 118 |
int rowCount(const QModelIndex& parent) const override; |
| 119 |
int columnCount(const QModelIndex& parent) const override; |
| 120 |
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; |
| 121 |
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; |
| 122 |
Qt::ItemFlags flags(const QModelIndex& index) const override; |
| 123 |
void goAddMacro(const QByteArray& macroName); |
| 124 |
void goRemoveMacro(const QByteArray& macroName); |
| 125 |
|
| 126 |
private: |
| 127 |
CommandNode* rootNode; |
| 128 |
CommandNode* nodeFromIndex(const QModelIndex& index) const; |
| 129 |
void initialize(); |
| 130 |
void groupCommands(const QString& groupName); |
| 131 |
QStringList orderedGroups(); |
| 132 |
}; |
| 133 |
|
| 134 |
class PrintModel: public QAbstractTableModel |
| 135 |
{ |
| 136 |
Q_OBJECT |
| 137 |
public: |
| 138 |
PrintModel(QObject* parent, ButtonModel* buttonModelIn, CommandModel* commandModelIn); |
| 139 |
int rowCount(const QModelIndex& parent) const override; |
| 140 |
int columnCount(const QModelIndex& parent) const override; |
| 141 |
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; |
| 142 |
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; |
| 143 |
|
| 144 |
private: |
| 145 |
ButtonModel* buttonModel; |
| 146 |
CommandModel* commandModel; |
| 147 |
}; |
| 148 |
|
| 149 |
class DlgCustomizeSpaceball: public CustomizeActionPage |
| 150 |
{ |
| 151 |
Q_OBJECT |
| 152 |
public: |
| 153 |
explicit DlgCustomizeSpaceball(QWidget* parent = nullptr); |
| 154 |
~DlgCustomizeSpaceball() override; |
| 155 |
|
| 156 |
protected: |
| 157 |
void changeEvent(QEvent* e) override; |
| 158 |
bool event(QEvent* event) override; |
| 159 |
void hideEvent(QHideEvent* event) override; |
| 160 |
void showEvent(QShowEvent* event) override; |
| 161 |
|
| 162 |
protected Q_SLOTS: |
| 163 |
void onAddMacroAction(const QByteArray& macroName) override; |
| 164 |
void onRemoveMacroAction(const QByteArray& macroName) override; |
| 165 |
void onModifyMacroAction(const QByteArray& macroName) override; |
| 166 |
|
| 167 |
private Q_SLOTS: |
| 168 |
void goClear(); |
| 169 |
void goPrint(); |
| 170 |
|
| 171 |
private: |
| 172 |
void setupButtonModelView(); |
| 173 |
void setupCommandModelView(); |
| 174 |
void setupLayout(); |
| 175 |
void setMessage(const QString& message); |
| 176 |
QStringList getModels(); |
| 177 |
|
| 178 |
ButtonView* buttonView; |
| 179 |
ButtonModel* buttonModel; |
| 180 |
CommandView* commandView; |
| 181 |
CommandModel* commandModel; |
| 182 |
QPushButton* clearButton; |
| 183 |
QPushButton* printReference; |
| 184 |
QComboBox* devModel; |
| 185 |
}; |
| 186 |
} // namespace Dialog |
| 187 |
} // namespace Gui |
| 188 |
|
| 189 |
#endif // GUI_DIALOG_DLGCUSTOMIZESPACEBALL_H |