summaryrefslogtreecommitdiffstats
path: root/examples/declarative/contacts/main.cpp
blob: 6bf9daf3ecb7ab69de0cf675537591c20ea7e71b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "qml.h"
#include <qfxview.h>

#include <QWidget>
#include <QApplication>
#include <QFile>
#include <QTime>
#include <QVBoxLayout>

const char *defaultFileName("contacts.xml");

class Contacts : public QWidget
{
Q_OBJECT
public:
    Contacts(const QString &fileName, int = 240, int = 320, QWidget *parent=0, Qt::WindowFlags flags=0);

public slots:
    void sceneResized(QSize size)
    {
        if(size.width() > 0 && size.height() > 0)
            canvas->setFixedSize(size.width(), size.height());
    }

private:
    QFxView *canvas;
};

Contacts::Contacts(const QString &fileName, int width, int height, QWidget *parent, Qt::WindowFlags flags)
: QWidget(parent, flags), canvas(0)
{
    setAttribute(Qt::WA_OpaquePaintEvent);
    setAttribute(Qt::WA_NoSystemBackground);

    QVBoxLayout *vbox = new QVBoxLayout;
    vbox->setMargin(0);
    setLayout(vbox);

    canvas = new QFxView(this);
    QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize)));
    canvas->setFixedSize(width, height);
    vbox->addWidget(canvas);

    QFile file(fileName);
    file.open(QFile::ReadOnly);
    QString xml = file.readAll();
    canvas->setXml(xml, fileName);

    canvas->execute();
}

int main(int argc, char ** argv)
{
    QApplication app(argc, argv);

    bool frameless = false;

    int width = 240;
    int height = 320;

    QString fileName;
    for (int i = 1; i < argc; ++i) {
        QString arg = argv[i];
        if (arg == "-frameless") {
            frameless = true;
        } else {
            fileName = arg;
            break;
        }
    }
    if (fileName.isEmpty())
        fileName = QLatin1String(defaultFileName);

    Contacts contacts(fileName, width, height, 0, frameless ? Qt::FramelessWindowHint : Qt::Widget);
    contacts.show();

    return app.exec();
}

#include "main.moc"