1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #include <QtGui>
- #include <QtDeclarative>
- #include "qmlapplicationviewer.h"
- #include "qmllineitem.h"
-
- class QmlWindow : public QMainWindow
- {
- Q_OBJECT
- public:
- QmlWindow(QWidget *parent = NULL);
- Q_INVOKABLE QAction *addMenuItem(QString menu, QString item);
- private:
- QHash<QString,QMenu *> menus;
- };
-
- QmlWindow::QmlWindow(QWidget *parent) : QMainWindow(parent)
- {
-
- }
-
- QAction *QmlWindow::addMenuItem(QString menu, QString item)
- {
- QMenu *theMenu;
- if(menus.contains(menu))
- {
- theMenu = menus.value(menu);
- }
- else
- {
- theMenu = menuBar()->addMenu(menu);
- menus.insert(menu, theMenu);
- }
- return theMenu->addAction(item);
- }
-
- QML_DECLARE_TYPE(QmlWindow)
-
- int main(int argc, char *argv[])
- {
- QApplication app(argc, argv);
-
- qmlRegisterType<QmlLineItem>("CustomComponents", 1, 0, "Line");
- qmlRegisterType<QmlWindow>("CustomComponents", 1, 0, "Window");
-
- QmlWindow *window = new QmlWindow(NULL);
- window->setWindowTitle("BrewPlot");
- QmlApplicationViewer *viewer = new QmlApplicationViewer;
- viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
- viewer->rootContext()->setContextProperty("window", window);
- viewer->setSource(QUrl("qrc:/qml/qml/BrewPlot/main.qml"));
- app.connect(viewer->engine(), SIGNAL(quit()), SLOT(quit()));
- window->setCentralWidget(viewer);
- viewer->setMinimumSize(viewer->sizeHint());
- window->show();
-
- return app.exec();
- }
-
- #include "moc_main.cpp"
|