Make TX volatge for simu more flexible (#7124)
[opentx.git] / companion / src / mdichild.h
blob079205cc13a29884fb42e85742dc0fda7d18e44c
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _MDICHILD_H_
22 #define _MDICHILD_H_
24 #include "eeprominterface.h"
25 #include "modelslist.h"
27 #include <QActionGroup>
28 #include <QtGui>
29 #include <QMessageBox>
30 #include <QProxyStyle>
31 #include <QWidget>
33 class QToolBar;
35 namespace Ui {
36 class MdiChild;
39 class MdiChild : public QWidget
41 Q_OBJECT
43 public:
44 enum Actions {
45 ACT_GEN_EDT, // radio general settings
46 ACT_GEN_CPY,
47 ACT_GEN_PST,
48 ACT_GEN_SIM,
49 ACT_ITM_EDT, // edit model/rename category
50 ACT_ITM_DEL, // delete model or cat
51 ACT_CAT_ADD, // category actions...
52 //ACT_CAT_EDT, // not sure these are needed...
53 //ACT_CAT_DEL, // the ACT_ITM_* actions do the same thing
54 ACT_CAT_SEP, // convenience separator shown/hidden with category actions
55 ACT_MDL_ADD, // model actions...
56 ACT_MDL_CPY,
57 ACT_MDL_CUT,
58 ACT_MDL_PST,
59 ACT_MDL_DUP,
60 ACT_MDL_INS,
61 ACT_MDL_MOV,
62 ACT_MDL_RTR, // ResToRe backup
63 ACT_MDL_WIZ,
64 ACT_MDL_DFT, // set as DeFaulT
65 ACT_MDL_PRT, // print
66 ACT_MDL_SIM,
67 ACT_ENUM_END
70 MdiChild(QWidget *parent = Q_NULLPTR, QWidget * parentWin = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
71 ~MdiChild();
73 QString currentFile() const;
74 QString userFriendlyCurrentFile() const;
75 QVector<int> getSelectedCategories() const;
76 QVector<int> getSelectedModels() const;
77 QList<QAction *> getGeneralActions();
78 QList<QAction *> getEditActions(bool incCatNew = true);
79 QList<QAction *> getModelActions();
80 //QList<QAction *> getCategoryActions();
81 QAction * getAction(const Actions type);
83 public slots:
84 void newFile(bool createDefaults = true);
85 bool loadFile(const QString & fileName, bool resetCurrentFile=true);
86 bool save();
87 bool saveAs(bool isNew=false);
88 bool saveFile(const QString & fileName, bool setCurrent=true);
89 void closeFile(bool force = false);
90 void writeEeprom();
91 void print(int model=-1, const QString & filename="");
92 void onFirmwareChanged();
94 signals:
95 void modified();
96 void newStatusMessage(const QString & msg, const int duration);
98 protected:
99 virtual void changeEvent(QEvent * event);
100 virtual void closeEvent(QCloseEvent * event);
101 virtual void resizeEvent(QResizeEvent * event);
102 virtual QSize sizeHint() const;
104 private slots:
105 void setupNavigation();
106 void updateNavigation();
107 void updateTitle();
108 void setModified();
109 void retranslateUi();
110 void showModelsListContextMenu(const QPoint & pos);
111 void showContextMenu(const QPoint & pos);
112 void adjustToolbarLayout();
114 void initModelsList();
115 void refresh();
116 void onItemActivated(const QModelIndex index);
117 void onItemSelected(const QModelIndex &);
118 void onCurrentItemChanged(const QModelIndex &, const QModelIndex &);
119 void onDataChanged(const QModelIndex & index);
121 void generalEdit();
122 void copyGeneralSettings();
123 void pasteGeneralSettings();
125 void copy();
126 void cut();
127 void paste();
128 void insert();
129 void edit();
130 void confirmDelete();
131 void categoryAdd();
132 void modelAdd();
133 void modelEdit();
134 void wizardEdit();
135 void modelDuplicate();
136 void onModelMoveToCategory();
138 void openModelWizard(int row = -1);
139 void openModelEditWindow(int row = -1);
141 void setDefault();
142 void modelSimulate();
143 void radioSimulate();
144 bool loadBackup();
146 void pasteModelData(const QMimeData * mimeData, const QModelIndex row, bool insert = false, bool move = false);
147 void pasteGeneralData(const QMimeData * mimeData);
149 private:
150 QAction *addAct(Actions actId, const QString & icon, const char * slot = 0, const QKeySequence & shortcut = 0, QObject * slotObj = NULL);
152 QModelIndex getCurrentIndex() const;
153 int getCurrentModel() const;
154 int countSelectedModels() const;
155 bool hasSelectedModel();
156 bool setSelectedModel(const int modelIndex);
157 int getCurrentCategory() const;
158 int countSelectedCats() const;
159 bool hasSelectedCat();
161 bool deleteCategory(int categoryIndex = -1, QString * error = NULL);
162 void deleteSelectedCats();
164 void checkAndInitModel(int row);
165 void findNewDefaultModel(const unsigned startAt = 0);
166 bool insertModelRows(int atModelIdx, int count);
167 int modelAppend(const ModelData model);
168 int newModel(int modelIndex = -1, int categoryIndex = -1);
169 unsigned deleteModels(const QVector<int> modelIndices);
170 bool deleteModel(const int modelIndex);
171 void deleteSelectedModels();
172 void moveModelsToCategory(const QVector<int> models, const int toCategoryId);
173 void moveSelectedModelsToCat(const int toCategoryId);
174 unsigned countUsedModels(const int categoryId = -1);
176 void clearCutList();
177 void removeModelFromCutList(const int modelIndex);
178 bool hasClipboardData(const quint8 type = 0) const;
180 bool maybeSave();
181 void setCurrentFile(const QString & fileName);
182 void forceNewFilename(const QString & suffix = "", const QString & ext = "otx");
183 bool convertStorage(Board::Type from, Board::Type to, bool newFile = false);
184 void showWarning(const QString & msg);
185 int askQuestion(const QString & msg, QMessageBox::StandardButtons buttons = (QMessageBox::Yes | QMessageBox::No), QMessageBox::StandardButton defaultButton = QMessageBox::No);
187 Ui::MdiChild * ui;
188 TreeModel * modelsListModel;
189 QWidget * parentWindow;
191 QString curFile;
192 QVector<int> cutModels;
193 QVector<QAction *> action;
194 QToolBar * radioToolbar;
195 QToolBar * categoriesToolbar;
196 QToolBar * modelsToolbar;
198 Firmware * firmware;
199 RadioData radioData;
201 int lastSelectedModel;
202 bool isUntitled;
203 bool showCatToolbar;
204 bool forceCloseFlag;
205 const quint16 stateDataVersion;
208 // This will draw the drop indicator across all columns of a model View (vs. in just one column), and lets us make the indicator more obvious.
209 class ItemViewProxyStyle: public QProxyStyle
211 public:
212 ItemViewProxyStyle(QStyle * style = 0) : QProxyStyle(style) {}
214 void drawPrimitive(PrimitiveElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget = 0) const
216 if (element == QStyle::PE_IndicatorItemViewItemDrop && !option->rect.isNull()) {
217 painter->save();
218 // set a wider stroke
219 QPen pen(painter->pen());
220 pen.setWidthF(2.5f);
221 painter->setPen(pen);
222 // adjust the rectangle size of the indicator to encompass the whole row
223 QStyleOption opt(*option);
224 opt.rect.setLeft(0);
225 if (widget)
226 opt.rect.setRight(widget->width());
227 // call default handler and exit
228 QProxyStyle::drawPrimitive(element, &opt, painter, widget);
229 painter->restore();
231 else {
232 QProxyStyle::drawPrimitive(element, option, painter, widget);
237 #endif // _MDICHILD_H_