1 #include "gui/formsimulator.h"
3 #include "gui/formmain.h"
4 #include "definitions/definitions.h"
5 #include "miscellaneous/iconfactory.h"
6 #include "miscellaneous/application.h"
7 #include "miscellaneous/skinfactory.h"
8 #include "core/templatesimulator.h"
9 #include "core/templatecore.h"
10 #include "core/templateeditor.h"
13 #include <QCloseEvent>
16 FormSimulator::FormSimulator(
FormMain* parent)
17 : QDialog(parent), m_ui(new Ui::
FormSimulator), m_mainWindow(parent), m_isActive(false), m_activeSimulation(NULL) {
21 m_isVisibleOnStartup = qApp->settings()->value(APP_CFG_SIMULATOR,
"visible_on_startup",
false).toBool();
22 m_isSticked = qApp->settings()->value(APP_CFG_SIMULATOR,
"is_sticked",
false).toBool();
28 connect(parent, SIGNAL(moved()),
this, SLOT(conditionallyAttachToParent()));
29 connect(parent, SIGNAL(resized()),
this, SLOT(conditionallyAttachToParent()));
30 connect(m_ui->m_btnRunSimulation, SIGNAL(clicked()),
this, SLOT(startSimulation()));
31 connect(m_ui->m_btnStopSimulation, SIGNAL(clicked()),
this, SLOT(stopSimulation()));
32 connect(m_ui->m_btnGoBack, SIGNAL(clicked()),
this, SLOT(goBack()));
33 connect(
this, SIGNAL(stopEnableChanged(
bool)), m_ui->m_btnStopSimulation, SLOT(setEnabled(
bool)));
36 setAttribute(Qt::WA_DeleteOnClose,
false);
37 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
40 FormSimulator::~FormSimulator() {
45 qApp->settings()->setValue(APP_CFG_SIMULATOR,
"visible_on_startup", m_isActive);
48 qApp->settings()->setValue(APP_CFG_SIMULATOR,
"position", pos());
49 qApp->settings()->setValue(APP_CFG_SIMULATOR,
"height", height());
55 move(qApp->settings()->value(APP_CFG_SIMULATOR,
"position", pos()).toPoint());
56 resize(width(), qApp->settings()->value(APP_CFG_SIMULATOR,
"height", height()).toInt());
61 if (m_activeSimulation != NULL) {
63 m_activeSimulation->close();
64 m_activeSimulation->deleteLater();
65 m_activeSimulation = NULL;
69 m_activeSimulation = simulation;
70 m_activeSimulation->setParent(m_ui->m_phoneWidget);
71 m_activeSimulation->setGeometry(SIMULATOR_CONTENTS_OFFSET_X, SIMULATOR_CONTENTS_OFFSET_Y,
72 SIMULATOR_CONTENTS_WIDTH, SIMULATOR_CONTENTS_HEIGHT);
73 m_activeSimulation->show();
76 connect(m_activeSimulation, SIGNAL(canGoBackChanged(
bool)), m_ui->m_btnGoBack, SLOT(setEnabled(
bool)));
77 connect(m_activeSimulation, SIGNAL(simulationStopRequested()), m_ui->m_btnStopSimulation, SLOT(click()));
78 connect(m_activeSimulation->
core()->
editor(), SIGNAL(canGenerateChanged(
bool)), m_ui->m_btnRunSimulation, SLOT(setEnabled(
bool)));
84 if (m_activeSimulation != NULL) {
85 m_activeSimulation->
goBack();
90 if (m_activeSimulation != NULL) {
98 if (m_activeSimulation != NULL) {
112 if (is_sticked && !m_isSticked) {
115 else if (!is_sticked && m_isSticked) {
119 m_isSticked = is_sticked;
121 qApp->settings()->setValue(APP_CFG_SIMULATOR,
"is_sticked", is_sticked);
132 QPoint main_window_position = m_mainWindow->pos();
133 QSize main_window_size = m_mainWindow->size();
135 setFixedHeight(main_window_size.height());
138 move(main_window_position.x() + main_window_size.width() + SIMULATOR_OFFSET,
139 main_window_position.y());
143 QPoint main_window_position = m_mainWindow->pos();
144 QSize main_window_size = m_mainWindow->size();
146 setMinimumHeight(SIMULATOR_HEIGHT_MIN);
147 setMaximumHeight(SIMULATOR_HEIGHT_MAX);
149 move(main_window_position.x() + main_window_size.width() + SIMULATOR_WIDTH_OFFSET,
150 main_window_position.y());
153 void FormSimulator::setupPhoneWidget() {
154 m_ui->m_phoneWidget->setFixedSize(SIMULATOR_WIDTH, SIMULATOR_HEIGHT_DEFAULT);
155 m_ui->m_phoneWidget->setPixmap(QPixmap(qApp->skinFactory()->currentSkin().m_simulatorBackgroundMain));
157 setFixedWidth(SIMULATOR_WIDTH + SIMULATOR_WIDTH_OFFSET);
167 void FormSimulator::setupIcons() {
170 setWindowIcon(factory->
fromTheme(
"view-simulator"));
171 m_ui->m_btnStopSimulation->setIcon(factory->
fromTheme(
"simulation-stop"));
172 m_ui->m_btnGoBack->setIcon(factory->
fromTheme(
"simulation-back"));
173 m_ui->m_btnRunSimulation->setIcon(factory->
fromTheme(
"simulation-run"));
virtual bool stopSimulation()=0
Stops simulation and resets its to initial state, all user data from simulation are cleared...
virtual TemplateEditor * editor() const
Access to editor widget of the template.
virtual bool goBack()=0
Gets simulation one step back.
Icon theme manipulator and provider.
TemplateCore * core() const
Access to associated template core.
QIcon fromTheme(const QString &name)
Returns icon from active theme.
virtual bool startSimulation()=0
(Re)starts the simulation.
static IconFactory * instance()
Singleton getter.
Base widget which represents simulator of the template.