File indexing completed on 2025-01-26 05:19:14
0001 /* Atelier KDE Printer Host for 3D Printing 0002 Copyright (C) <2017> 0003 Author: Patrick José Pereira - patrickjp@kde.org 0004 Chris Rizzitello - rizzitello@kde.org 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License as 0008 published by the Free Software Foundation; either version 3 of 0009 the License or any later version accepted by the membership of 0010 KDE e.V. (or its successor approved by the membership of KDE 0011 e.V.), which shall act as a proxy defined in Section 14 of 0012 version 3 of the license. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 #include <QDebug> 0023 #include <QDirIterator> 0024 #include <QHBoxLayout> 0025 #include <QObject> 0026 #include <QQmlContext> 0027 #include <QQmlEngine> 0028 #include <QQuickItem> 0029 #include <QQuickView> 0030 #include <QString> 0031 0032 #include "axisgnomonentity.h" 0033 #include "bedproperties.h" 0034 #include "cameracontroller.h" 0035 #include "gridmesh.h" 0036 #include "linemesh.h" 0037 #include "viewer3d.h" 0038 0039 Viewer3D::Viewer3D(QWidget *parent) 0040 : QWidget(parent) 0041 , _lineMesh(new LineMesh) 0042 { 0043 Q_INIT_RESOURCE(viewer3d); 0044 0045 qmlRegisterType<AxisGnomonEntity>("Atelier", 1, 0, "AxisGnomonEntity"); 0046 qmlRegisterType<CameraController>("Atelier", 1, 0, "CameraController"); 0047 qmlRegisterType<GridMesh>("Atelier", 1, 0, "GridMesh"); 0048 qmlRegisterType<LineMesh>("Atelier", 1, 0, "LineMesh"); 0049 qmlRegisterType<BedProperties>("Atelier", 1, 0, "BedProperties"); 0050 0051 _view = new QQuickView(&_engine, nullptr); 0052 0053 auto format = QSurfaceFormat(); 0054 format.setVersion(3, 1); 0055 format.setProfile(QSurfaceFormat::CoreProfile); 0056 _view->setFormat(format); 0057 0058 _view->rootContext()->setContextProperty("viewer3d", this); 0059 _view->setResizeMode(QQuickView::SizeRootObjectToView); 0060 _view->setSource(QUrl(QStringLiteral("qrc:/viewer3d.qml"))); 0061 auto mainLayout = new QHBoxLayout; 0062 mainLayout->addWidget(QWidget::createWindowContainer(_view)); 0063 QObject *item = _view->rootObject(); 0064 // Connect the drop pass from the QML part. 0065 connect(item, SIGNAL(droppedUrls(QVariant)), this, SLOT(dropCatch(QVariant))); 0066 this->setLayout(mainLayout); 0067 } 0068 0069 void Viewer3D::dropCatch(const QVariant &var) 0070 { 0071 emit droppedUrls(var.value<QList<QUrl>>()); 0072 } 0073 0074 void Viewer3D::drawModel(const QString &file) 0075 { 0076 QObject *object = _view->rootObject(); 0077 auto fileName = object->findChild<QObject *>(QStringLiteral("fileName")); 0078 fileName->setProperty("text", QVariant(file)); 0079 } 0080 0081 void Viewer3D::setBedSize(const QSize &newBedSize) 0082 { 0083 if (newBedSize != _bedSize) { 0084 _bedSize = newBedSize; 0085 emit bedSizeChanged(_bedSize); 0086 } 0087 } 0088 0089 QSize Viewer3D::bedSize() 0090 { 0091 return _bedSize; 0092 }