first commit: set up basic project structure, created simple qt+qml application
[quickdice] / src / mainwindow.cpp
1 /******************************************************************************
2 **
3 ** This file is part of quickdice.
4 **
5 ** Copyright (C) 2011 Digia Plc. and/or its subsidiary(-ies).
6 ** Contact: Zoltan Papp <zoltan.papp@digia.com>
7 **
8 ** This library is free software; you can redistribute it and/or modify it
9 ** under the terms of the GNU Lesser General Public License version 2.1 as
10 ** published by the Free Software Foundation.
11 **
12 ** This library is distributed in the hope that it will be useful, but
13 ** WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 ** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 ** License for more details.
16 **
17 ** You should have received a copy of the GNU Lesser General Public License
18 ** along with this library; if not, write to the Free Software Foundation, Inc.,
19 ** 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 **
21 ******************************************************************************/
22
23 #include "mainwindow.h"
24 #include <QtDeclarative/QtDeclarative>
25 #include <QtGui/QAction>
26
27 MainWindow::MainWindow(QWidget *parent)
28     : QMainWindow(parent)
29 {
30     QDeclarativeView *view = new QDeclarativeView;
31     setCentralWidget(view);
32
33     QDeclarativeEngine *engine = view->engine();
34     QDeclarativeContext *context = engine->rootContext();
35     context->setContextProperty(QLatin1String("message"),
36                                 QLatin1String("Hello World!"));
37     context->setContextProperty(QLatin1String("defaultColor"),
38                                 QColor(Qt::lightGray));
39
40     QAction *action = new QAction(this);
41     connect(action,
42             SIGNAL(triggered()),
43             this,
44             SLOT(close()));
45     context->setContextProperty(QLatin1String("action"),
46                                 action);
47
48     // FIXME: load it properly from a resource file
49     QString fn = "test.qml";
50     view->setSource(fn);
51 }
52
53 MainWindow::~MainWindow()
54 {
55 }
56