|
| 1 | +#include "WindowWithDeclarativeViewTest.h" |
| 2 | + |
| 3 | +WindowWithDeclarativeViewTestWidget::WindowWithDeclarativeViewTestWidget(QWidget *parent) : |
| 4 | + QWidget(parent) |
| 5 | +{ |
| 6 | + setWindowTitle("Test Window"); |
| 7 | + pLineEdit = new QLineEdit(); |
| 8 | + pLineEdit->setObjectName("inputURL"); |
| 9 | + connect(pLineEdit, SIGNAL(returnPressed()), this, SLOT(loadQML())); |
| 10 | + |
| 11 | + pButton = new QPushButton("Go!"); |
| 12 | + pButton->setObjectName("loadButton"); |
| 13 | + connect(pButton, SIGNAL(clicked()), this, SLOT(loadQML())); |
| 14 | + |
| 15 | + pLabel = new QLabel("Status"); |
| 16 | + pLabel->setObjectName("labelStatus"); |
| 17 | + pLabel->setVisible(true); |
| 18 | + |
| 19 | +#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
| 20 | + pView = new QQuickView(); |
| 21 | +#else |
| 22 | + pView = new QDeclarativeView(); |
| 23 | +#endif |
| 24 | + |
| 25 | + pView->setObjectName("declarativeView"); |
| 26 | + |
| 27 | +#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
| 28 | + connect(pView, SIGNAL(statusChanged(QQuickView::Status)), this, SLOT(displayStatus())); |
| 29 | +#else |
| 30 | + connect(pView, SIGNAL(statusChanged(QDeclarativeView::Status)), this, SLOT(displayStatus())); |
| 31 | +#endif |
| 32 | + |
| 33 | + QHBoxLayout* hbl = new QHBoxLayout(); |
| 34 | + hbl->addWidget(pLineEdit); |
| 35 | + hbl->addWidget(pButton); |
| 36 | + |
| 37 | + QVBoxLayout *vbl = new QVBoxLayout(this); |
| 38 | + vbl->addLayout(hbl); |
| 39 | + vbl->addWidget(pLabel); |
| 40 | +#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
| 41 | + QWidget *container = QWidget::createWindowContainer(pView); |
| 42 | + vbl->addWidget(container); |
| 43 | +#else |
| 44 | + vbl->addWidget(pView); |
| 45 | +#endif |
| 46 | + this->setLayout(vbl); |
| 47 | +} |
| 48 | + |
| 49 | +WindowWithDeclarativeViewTestWidget::~WindowWithDeclarativeViewTestWidget() { } |
| 50 | + |
| 51 | +void WindowWithDeclarativeViewTestWidget::loadQML() { |
| 52 | + pView->setSource(QUrl(pLineEdit->text())); |
| 53 | + pView->show(); |
| 54 | +} |
| 55 | + |
| 56 | +void WindowWithDeclarativeViewTestWidget::displayStatus() { |
| 57 | +#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
| 58 | + if (pView->status() == QQuickView::Ready) |
| 59 | +#else |
| 60 | + if (pView->status() == QDeclarativeView::Ready) |
| 61 | +#endif |
| 62 | + pLabel->setText("Loading successfully"); |
| 63 | + |
| 64 | +#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
| 65 | + if (pView->status() == QQuickView::Error) |
| 66 | +#else |
| 67 | + if (pView->status() == QDeclarativeView::Error) |
| 68 | +#endif |
| 69 | + pLabel->setText("Error"); |
| 70 | +} |
0 commit comments