1
// openhomm - open source clone of Heroes of Might and Magic III
2
// Copyright (C) 2009-2010 openhomm developers team (see AUTHORS)
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU 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.
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.
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
17
#include "precompiled.hpp"
20
Q_SCRIPT_DECLARE_QMETAOBJECT(hrPushButton, QObject*)
22
hrUI::hrUI(QObject *parent) : QObject(parent)
24
QScriptValue button = engine.scriptValueFromQMetaObject<hrPushButton>();
25
engine.globalObject().setProperty("Button", button);
27
addGlobalObject(this, "UI");
30
void hrUI::addGlobalObject(QObject *obj, QString name)
32
QScriptValue val = engine.newQObject(obj);
33
engine.globalObject().setProperty(name, val);
36
void hrUI::addWidget(hrWidget *widget)
38
qDebug() << "add widget" << widget->getX() << widget->getY()
39
<< "name" << dynamic_cast<hrPushButton*>(widget)->getName();
40
widgets.append(widget);
43
void hrUI::onMousePress(const QPoint &p)
45
for (int i = 0; i < widgets.size(); i++)
47
hrWidget *widget = widgets.at(i);
48
if (widget->getRect().contains(p))
50
hrPushButton *button = dynamic_cast<hrPushButton*>(widget);
53
button->onMousePress();
59
void hrUI::onMouseRelease(const QPoint &p)
61
for (int i = 0; i < widgets.size(); i++)
63
hrWidget *widget = widgets.at(i);
64
if (widget->getRect().contains(p))
66
hrPushButton *button = dynamic_cast<hrPushButton*>(widget);
69
button->onMouseRelease();
76
QListIterator<hrGraphicsItem> hrUI::getItems()
79
return QListIterator<hrGraphicsItem>(items);
85
for (int i = 0; i < widgets.size(); i++)
87
hrWidget *widget = widgets.at(i);
88
QVectorIterator<hrGraphicsItem> it = widget->getItems();
91
hrGraphicsItem item = it.next();
92
item.setPoint(widget->getRect().topLeft());
98
void hrUI::script(QString path)
101
file.open(QIODevice::ReadOnly);
104
qDebug() << file.errorString();
106
QTextStream stream(&file);
107
QString contents = stream.readAll();
112
QScriptValue result = engine.evaluate(contents, path);
114
QScriptValueIterator it(result);
118
qDebug() << it.name() << ": " << it.value().toString();