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.
24 #include "eeprominterface.h"
25 #include "modelslist.h"
27 #include <QActionGroup>
29 #include <QMessageBox>
30 #include <QProxyStyle>
39 class MdiChild
: public QWidget
45 ACT_GEN_EDT
, // radio general settings
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...
62 ACT_MDL_RTR
, // ResToRe backup
64 ACT_MDL_DFT
, // set as DeFaulT
70 MdiChild(QWidget
*parent
= Q_NULLPTR
, QWidget
* parentWin
= Q_NULLPTR
, Qt::WindowFlags f
= Qt::WindowFlags());
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
);
84 void newFile(bool createDefaults
= true);
85 bool loadFile(const QString
& fileName
, bool resetCurrentFile
=true);
87 bool saveAs(bool isNew
=false);
88 bool saveFile(const QString
& fileName
, bool setCurrent
=true);
89 void closeFile(bool force
= false);
91 void print(int model
=-1, const QString
& filename
="");
92 void onFirmwareChanged();
96 void newStatusMessage(const QString
& msg
, const int duration
);
99 virtual void changeEvent(QEvent
* event
);
100 virtual void closeEvent(QCloseEvent
* event
);
101 virtual void resizeEvent(QResizeEvent
* event
);
102 virtual QSize
sizeHint() const;
105 void setupNavigation();
106 void updateNavigation();
109 void retranslateUi();
110 void showModelsListContextMenu(const QPoint
& pos
);
111 void showContextMenu(const QPoint
& pos
);
112 void adjustToolbarLayout();
114 void initModelsList();
116 void onItemActivated(const QModelIndex index
);
117 void onItemSelected(const QModelIndex
&);
118 void onCurrentItemChanged(const QModelIndex
&, const QModelIndex
&);
119 void onDataChanged(const QModelIndex
& index
);
122 void copyGeneralSettings();
123 void pasteGeneralSettings();
130 void confirmDelete();
135 void modelDuplicate();
136 void onModelMoveToCategory();
138 void openModelWizard(int row
= -1);
139 void openModelEditWindow(int row
= -1);
142 void modelSimulate();
143 void radioSimulate();
146 void pasteModelData(const QMimeData
* mimeData
, const QModelIndex row
, bool insert
= false, bool move
= false);
147 void pasteGeneralData(const QMimeData
* mimeData
);
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);
177 void removeModelFromCutList(const int modelIndex
);
178 bool hasClipboardData(const quint8 type
= 0) const;
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
);
188 TreeModel
* modelsListModel
;
189 QWidget
* parentWindow
;
192 QVector
<int> cutModels
;
193 QVector
<QAction
*> action
;
194 QToolBar
* radioToolbar
;
195 QToolBar
* categoriesToolbar
;
196 QToolBar
* modelsToolbar
;
201 int lastSelectedModel
;
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
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()) {
218 // set a wider stroke
219 QPen
pen(painter
->pen());
221 painter
->setPen(pen
);
222 // adjust the rectangle size of the indicator to encompass the whole row
223 QStyleOption
opt(*option
);
226 opt
.rect
.setRight(widget
->width());
227 // call default handler and exit
228 QProxyStyle::drawPrimitive(element
, &opt
, painter
, widget
);
232 QProxyStyle::drawPrimitive(element
, option
, painter
, widget
);
237 #endif // _MDICHILD_H_