|
| 1 | +/* |
| 2 | + * Project: PiOmxTextures |
| 3 | + * Author: Luca Carlon |
| 4 | + * Date: 11.29.2015 |
| 5 | + * |
| 6 | + * Copyright (c) 2015 Luca Carlon. All rights reserved. |
| 7 | + * |
| 8 | + * This file is part of PiOmxTextures. |
| 9 | + * |
| 10 | + * PiOmxTextures is free software: you can redistribute it and/or modify |
| 11 | + * it under the terms of the GNU General Public License as published by |
| 12 | + * the Free Software Foundation, either version 3 of the License, or |
| 13 | + * (at your option) any later version. |
| 14 | + * |
| 15 | + * PiOmxTextures is distributed in the hope that it will be useful, |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | + * GNU General Public License for more details. |
| 19 | + * |
| 20 | + * You should have received a copy of the GNU General Public License |
| 21 | + * along with PiOmxTextures. If not, see <http://www.gnu.org/licenses/>. |
| 22 | + */ |
| 23 | + |
| 24 | +/*------------------------------------------------------------------------------ |
| 25 | +| includes |
| 26 | ++-----------------------------------------------------------------------------*/ |
| 27 | +#include <QApplication> |
| 28 | +#include <QWebView> |
| 29 | +#include <QQuickView> |
| 30 | +#include <QQuickItem> |
| 31 | +#include <QGraphicsView> |
| 32 | +#include <QGraphicsWebView> |
| 33 | +#include <QGraphicsScene> |
| 34 | +#include <QOpenGLWidget> |
| 35 | +#include <QSurfaceFormat> |
| 36 | + |
| 37 | +/*------------------------------------------------------------------------------ |
| 38 | +| main |
| 39 | ++-----------------------------------------------------------------------------*/ |
| 40 | +int main(int argc, char* argv[]) |
| 41 | +{ |
| 42 | + QApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); |
| 43 | + QApplication a(argc, argv); |
| 44 | + |
| 45 | + QStringList args = a.arguments(); |
| 46 | + const bool opengl = !args.contains("--no-opengl"); |
| 47 | + const bool wk2 = args.contains("--wk2"); |
| 48 | + args.removeAll("--no-opengl"); |
| 49 | + args.removeAll("--wk2"); |
| 50 | + args.removeAll("--wk1"); // Default. |
| 51 | + |
| 52 | + const QString surl = args.at(1); |
| 53 | + |
| 54 | + if (!wk2) { |
| 55 | + QGraphicsWebView* webItem = new QGraphicsWebView; |
| 56 | + QOpenGLWidget* glViewport = new QOpenGLWidget; |
| 57 | + |
| 58 | + QGraphicsView* view = new QGraphicsView; |
| 59 | + |
| 60 | + // Set EGL to 24bit color depth. |
| 61 | + QSurfaceFormat curSurface = glViewport->format(); |
| 62 | + curSurface.setRedBufferSize(8); |
| 63 | + curSurface.setGreenBufferSize(8); |
| 64 | + curSurface.setBlueBufferSize(8); |
| 65 | + curSurface.setAlphaBufferSize(0); |
| 66 | + glViewport->setFormat(curSurface); |
| 67 | + |
| 68 | + view->setRenderHints(QPainter::Antialiasing); |
| 69 | + view->setScene(new QGraphicsScene); |
| 70 | + if (opengl) |
| 71 | + view->setViewport(glViewport); |
| 72 | + else |
| 73 | + QObject::connect(qApp, SIGNAL(aboutToQuit()), |
| 74 | + glViewport, SLOT(deleteLater())); |
| 75 | + view->showFullScreen(); |
| 76 | + |
| 77 | + view->scene()->setBackgroundBrush(QBrush(Qt::red)); |
| 78 | + view->scene()->setSceneRect(QRectF(0, 0, 1910, 1070)); |
| 79 | + view->scene()->addItem(webItem); |
| 80 | + |
| 81 | + webItem->setUrl(QUrl(surl)); |
| 82 | + webItem->setMinimumSize(1910, 1070); |
| 83 | + } |
| 84 | + else { |
| 85 | + QQuickView* view = new QQuickView; |
| 86 | + view->setSource(QUrl("qrc:/main_wk2.qml")); |
| 87 | + view->show(); |
| 88 | + |
| 89 | + QObject* o = view->rootObject(); |
| 90 | + o->setProperty("url", args.at(1)); |
| 91 | + } |
| 92 | + |
| 93 | + return a.exec(); |
| 94 | +} |
0 commit comments