mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
3D PDF: demo window
This commit is contained in:
164
Pdf4QtViewer/pdfmediaviewerdialog.cpp
Normal file
164
Pdf4QtViewer/pdfmediaviewerdialog.cpp
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
// Copyright (C) 2022 Jakub Melka
|
||||||
|
//
|
||||||
|
// This file is part of PDF4QT.
|
||||||
|
//
|
||||||
|
// PDF4QT is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// with the written consent of the copyright owner, any later version.
|
||||||
|
//
|
||||||
|
// PDF4QT is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "pdfmediaviewerdialog.h"
|
||||||
|
#include "ui_pdfmediaviewerdialog.h"
|
||||||
|
#include "pdfwidgetutils.h"
|
||||||
|
#include "pdfdbgheap.h"
|
||||||
|
|
||||||
|
#include <QColor>
|
||||||
|
|
||||||
|
#include <Qt3DCore/QEntity>
|
||||||
|
#include <Qt3DCore/QTransform>
|
||||||
|
#include <Qt3DRender/QCamera>
|
||||||
|
#include <Qt3DExtras/Qt3DWindow>
|
||||||
|
#include <Qt3DExtras/QForwardRenderer>
|
||||||
|
#include <Qt3DExtras/QOrbitCameraController>
|
||||||
|
#include <Qt3DExtras/QTorusMesh>
|
||||||
|
#include <Qt3DExtras/QCylinderMesh>
|
||||||
|
#include <Qt3DExtras/QCuboidMesh>
|
||||||
|
#include <Qt3DExtras/QSphereMesh>
|
||||||
|
#include <Qt3DExtras/QPhongMaterial>
|
||||||
|
#include <Qt3DRender/QPointLight>
|
||||||
|
|
||||||
|
namespace pdfviewer
|
||||||
|
{
|
||||||
|
|
||||||
|
PDFMediaViewerDialog::PDFMediaViewerDialog(QWidget* parent) :
|
||||||
|
QDialog(parent, Qt::Window | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint),
|
||||||
|
ui(new Ui::PDFMediaViewerDialog)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
|
m_3dWindow = new Qt3DExtras::Qt3DWindow(this->screen());
|
||||||
|
m_3dWindow->defaultFrameGraph()->setClearColor(Qt::white);
|
||||||
|
|
||||||
|
QWidget* container = QWidget::createWindowContainer(m_3dWindow, this);
|
||||||
|
container->setMinimumSize(pdf::PDFWidgetUtils::scaleDPI(container, QSize(300, 300)));
|
||||||
|
ui->gridLayout->addWidget(container, 0, 0);
|
||||||
|
|
||||||
|
m_rootEntity = new Qt3DCore::QEntity();
|
||||||
|
m_3dWindow->setRootEntity(m_rootEntity);
|
||||||
|
m_sceneEntity = new Qt3DCore::QEntity(m_rootEntity);
|
||||||
|
|
||||||
|
Qt3DRender::QCamera* camera = m_3dWindow->camera();
|
||||||
|
Qt3DExtras::QOrbitCameraController* cameraController = new Qt3DExtras::QOrbitCameraController(m_rootEntity);
|
||||||
|
cameraController->setCamera(camera);
|
||||||
|
}
|
||||||
|
|
||||||
|
PDFMediaViewerDialog::~PDFMediaViewerDialog()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
delete m_rootEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFMediaViewerDialog::initDemo()
|
||||||
|
{
|
||||||
|
// Setup camera
|
||||||
|
Qt3DRender::QCamera* camera = m_3dWindow->camera();
|
||||||
|
camera->lens()->setPerspectiveProjection(25.0f, 16.0f / 9.0f, 0.001f, 1000.0f);
|
||||||
|
camera->setUpVector(QVector3D(0.0f, -1.0f, 0.0f));
|
||||||
|
camera->setPosition(QVector3D(-20.0f, 0.0f, 0.0f));
|
||||||
|
camera->setViewCenter(QVector3D(0.0f, 0.0f, 0.0f));
|
||||||
|
|
||||||
|
// Sphere
|
||||||
|
Qt3DExtras::QSphereMesh* sphere = new Qt3DExtras::QSphereMesh();
|
||||||
|
sphere->setRadius(2.0);
|
||||||
|
sphere->setRings(60);
|
||||||
|
sphere->setSlices(30);
|
||||||
|
|
||||||
|
Qt3DCore::QTransform* sphereTransform = new Qt3DCore::QTransform();
|
||||||
|
sphereTransform->setTranslation(QVector3D(2.0f, 0.0f, 3.00f));
|
||||||
|
|
||||||
|
Qt3DExtras::QPhongMaterial* sphereMaterial = new Qt3DExtras::QPhongMaterial();
|
||||||
|
sphereMaterial->setDiffuse(Qt::green);
|
||||||
|
|
||||||
|
Qt3DCore::QEntity* sphereEntity = new Qt3DCore::QEntity(m_sceneEntity);
|
||||||
|
sphereEntity->addComponent(sphere);
|
||||||
|
sphereEntity->addComponent(sphereTransform);
|
||||||
|
sphereEntity->addComponent(sphereMaterial);
|
||||||
|
|
||||||
|
// Torus
|
||||||
|
Qt3DExtras::QTorusMesh* torus = new Qt3DExtras::QTorusMesh();
|
||||||
|
torus->setRadius(2.0);
|
||||||
|
torus->setMinorRadius(0.5);
|
||||||
|
torus->setRings(120);
|
||||||
|
torus->setSlices(25);
|
||||||
|
|
||||||
|
Qt3DCore::QTransform* torusTransform = new Qt3DCore::QTransform();
|
||||||
|
torusTransform->setScale(1.74f);
|
||||||
|
torusTransform->setRotationY(25);
|
||||||
|
torusTransform->setTranslation(QVector3D(0.5f, 0.7f, 0.03f));
|
||||||
|
|
||||||
|
Qt3DExtras::QPhongMaterial* torusMaterial = new Qt3DExtras::QPhongMaterial();
|
||||||
|
torusMaterial->setDiffuse(Qt::blue);
|
||||||
|
|
||||||
|
Qt3DCore::QEntity* torusEntity = new Qt3DCore::QEntity(m_sceneEntity);
|
||||||
|
torusEntity->addComponent(torus);
|
||||||
|
torusEntity->addComponent(torusTransform);
|
||||||
|
torusEntity->addComponent(torusMaterial);
|
||||||
|
|
||||||
|
// Cuboid
|
||||||
|
Qt3DExtras::QCuboidMesh* cuboid = new Qt3DExtras::QCuboidMesh();
|
||||||
|
cuboid->setXExtent(1.37f);
|
||||||
|
cuboid->setYExtent(1.74f);
|
||||||
|
cuboid->setZExtent(2.0f);
|
||||||
|
|
||||||
|
Qt3DCore::QTransform* cuboidTransform = new Qt3DCore::QTransform();
|
||||||
|
cuboidTransform->setTranslation(QVector3D(0.0f, 7.0f, 0.00f));
|
||||||
|
|
||||||
|
Qt3DExtras::QPhongMaterial* cuboidMaterial = new Qt3DExtras::QPhongMaterial();
|
||||||
|
cuboidMaterial->setDiffuse(Qt::red);
|
||||||
|
|
||||||
|
Qt3DCore::QEntity* cuboidEntity = new Qt3DCore::QEntity(m_sceneEntity);
|
||||||
|
cuboidEntity->addComponent(cuboid);
|
||||||
|
cuboidEntity->addComponent(cuboidTransform);
|
||||||
|
cuboidEntity->addComponent(cuboidMaterial);
|
||||||
|
|
||||||
|
// Cylinder
|
||||||
|
Qt3DExtras::QCylinderMesh* cylinder = new Qt3DExtras::QCylinderMesh();
|
||||||
|
cylinder->setRadius(2.0);
|
||||||
|
cylinder->setLength(6.0);
|
||||||
|
cylinder->setRings(120);
|
||||||
|
cylinder->setSlices(25);
|
||||||
|
|
||||||
|
Qt3DCore::QTransform* cylinderTransform = new Qt3DCore::QTransform();
|
||||||
|
cylinderTransform->setTranslation(QVector3D(0.0f, -7.0f, 0.00f));
|
||||||
|
|
||||||
|
Qt3DExtras::QPhongMaterial* cylinderMaterial = new Qt3DExtras::QPhongMaterial();
|
||||||
|
cylinderMaterial->setDiffuse(Qt::yellow);
|
||||||
|
|
||||||
|
Qt3DCore::QEntity* cylinderEntity = new Qt3DCore::QEntity(m_sceneEntity);
|
||||||
|
cylinderEntity->addComponent(cylinder);
|
||||||
|
cylinderEntity->addComponent(cylinderTransform);
|
||||||
|
cylinderEntity->addComponent(cylinderMaterial);
|
||||||
|
|
||||||
|
// Light
|
||||||
|
Qt3DCore::QEntity* lightEntity = new Qt3DCore::QEntity(m_sceneEntity);
|
||||||
|
Qt3DRender::QPointLight* light = new Qt3DRender::QPointLight(lightEntity);
|
||||||
|
light->setColor(Qt::white);
|
||||||
|
light->setIntensity(1.0);
|
||||||
|
lightEntity->addComponent(light);
|
||||||
|
|
||||||
|
Qt3DCore::QTransform* lightTransform = new Qt3DCore::QTransform(lightEntity);
|
||||||
|
lightTransform->setTranslation(QVector3D(10.0f, 10.0f, 10.0f));
|
||||||
|
lightEntity->addComponent(lightTransform);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace pdfviewer
|
60
Pdf4QtViewer/pdfmediaviewerdialog.h
Normal file
60
Pdf4QtViewer/pdfmediaviewerdialog.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
// Copyright (C) 2022 Jakub Melka
|
||||||
|
//
|
||||||
|
// This file is part of PDF4QT.
|
||||||
|
//
|
||||||
|
// PDF4QT is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// with the written consent of the copyright owner, any later version.
|
||||||
|
//
|
||||||
|
// PDF4QT is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef PDFMEDIAVIEWERDIALOG_H
|
||||||
|
#define PDFMEDIAVIEWERDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
namespace Qt3DCore
|
||||||
|
{
|
||||||
|
class QEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Qt3DExtras
|
||||||
|
{
|
||||||
|
class Qt3DWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class PDFMediaViewerDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace pdfviewer
|
||||||
|
{
|
||||||
|
|
||||||
|
class PDFMediaViewerDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit PDFMediaViewerDialog(QWidget* parent);
|
||||||
|
virtual ~PDFMediaViewerDialog() override;
|
||||||
|
|
||||||
|
void initDemo();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::PDFMediaViewerDialog* ui;
|
||||||
|
Qt3DExtras::Qt3DWindow* m_3dWindow = nullptr;
|
||||||
|
Qt3DCore::QEntity* m_rootEntity = nullptr;
|
||||||
|
Qt3DCore::QEntity* m_sceneEntity = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace pdfviewer
|
||||||
|
|
||||||
|
#endif // PDFMEDIAVIEWERDIALOG_H
|
71
Pdf4QtViewer/pdfmediaviewerdialog.ui
Normal file
71
Pdf4QtViewer/pdfmediaviewerdialog.ui
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>PDFMediaViewerDialog</class>
|
||||||
|
<widget class="QDialog" name="PDFMediaViewerDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>761</width>
|
||||||
|
<height>580</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Media Viewer</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout" columnstretch="3,1">
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QGroupBox" name="groupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>GroupBox</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" colspan="2">
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>PDFMediaViewerDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>PDFMediaViewerDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
@ -40,6 +40,7 @@
|
|||||||
#include "pdfrecentfilemanager.h"
|
#include "pdfrecentfilemanager.h"
|
||||||
#include "pdftexttospeech.h"
|
#include "pdftexttospeech.h"
|
||||||
#include "pdfencryptionsettingsdialog.h"
|
#include "pdfencryptionsettingsdialog.h"
|
||||||
|
#include "pdfmediaviewerdialog.h"
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QPrinter>
|
#include <QPrinter>
|
||||||
@ -526,6 +527,10 @@ void PDFProgramController::initialize(Features features,
|
|||||||
{
|
{
|
||||||
connect(action, &QAction::triggered, this, &PDFProgramController::onActionDeveloperCreateInstaller);
|
connect(action, &QAction::triggered, this, &PDFProgramController::onActionDeveloperCreateInstaller);
|
||||||
}
|
}
|
||||||
|
if (QAction* action = m_actionManager->getAction(PDFActionManager::DeveloperShow3DWindowDemo))
|
||||||
|
{
|
||||||
|
connect(action, &QAction::triggered, this, &PDFProgramController::onActionDeveloperShow3DWindowDemo);
|
||||||
|
}
|
||||||
if (QAction* action = m_actionManager->getAction(PDFActionManager::GetSource))
|
if (QAction* action = m_actionManager->getAction(PDFActionManager::GetSource))
|
||||||
{
|
{
|
||||||
connect(action, &QAction::triggered, this, &PDFProgramController::onActionGetSource);
|
connect(action, &QAction::triggered, this, &PDFProgramController::onActionGetSource);
|
||||||
@ -2459,6 +2464,13 @@ void PDFProgramController::onActionDeveloperCreateInstaller()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PDFProgramController::onActionDeveloperShow3DWindowDemo()
|
||||||
|
{
|
||||||
|
PDFMediaViewerDialog* dialog = new PDFMediaViewerDialog(getMainWindow());
|
||||||
|
dialog->initDemo();
|
||||||
|
dialog->open();
|
||||||
|
}
|
||||||
|
|
||||||
void PDFProgramController::onActionGetSource()
|
void PDFProgramController::onActionGetSource()
|
||||||
{
|
{
|
||||||
QDesktopServices::openUrl(QUrl("https://github.com/JakubMelka/PDF4QT"));
|
QDesktopServices::openUrl(QUrl("https://github.com/JakubMelka/PDF4QT"));
|
||||||
|
@ -172,6 +172,7 @@ public:
|
|||||||
ToolScreenshot,
|
ToolScreenshot,
|
||||||
ToolExtractImage,
|
ToolExtractImage,
|
||||||
DeveloperCreateInstaller,
|
DeveloperCreateInstaller,
|
||||||
|
DeveloperShow3DWindowDemo,
|
||||||
LastAction
|
LastAction
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -353,6 +354,7 @@ private:
|
|||||||
void onActionOpenTriggered();
|
void onActionOpenTriggered();
|
||||||
void onActionCloseTriggered();
|
void onActionCloseTriggered();
|
||||||
void onActionDeveloperCreateInstaller();
|
void onActionDeveloperCreateInstaller();
|
||||||
|
void onActionDeveloperShow3DWindowDemo();
|
||||||
void onActionGetSource();
|
void onActionGetSource();
|
||||||
void onActionBecomeSponsor();
|
void onActionBecomeSponsor();
|
||||||
void onActionAutomaticDocumentRefresh();
|
void onActionAutomaticDocumentRefresh();
|
||||||
|
@ -180,6 +180,7 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget* parent) :
|
|||||||
m_actionManager->setAction(PDFActionManager::ToolScreenshot, ui->actionScreenshot);
|
m_actionManager->setAction(PDFActionManager::ToolScreenshot, ui->actionScreenshot);
|
||||||
m_actionManager->setAction(PDFActionManager::ToolExtractImage, ui->actionExtractImage);
|
m_actionManager->setAction(PDFActionManager::ToolExtractImage, ui->actionExtractImage);
|
||||||
m_actionManager->setAction(PDFActionManager::DeveloperCreateInstaller, ui->actionDeveloperCreateInstaller);
|
m_actionManager->setAction(PDFActionManager::DeveloperCreateInstaller, ui->actionDeveloperCreateInstaller);
|
||||||
|
m_actionManager->setAction(PDFActionManager::DeveloperShow3DWindowDemo, ui->actionDeveloperShow3DWindowDemo);
|
||||||
m_actionManager->initActions(pdf::PDFWidgetUtils::scaleDPI(this, QSize(24, 24)), true);
|
m_actionManager->initActions(pdf::PDFWidgetUtils::scaleDPI(this, QSize(24, 24)), true);
|
||||||
|
|
||||||
for (QAction* action : m_programController->getRecentFileManager()->getActions())
|
for (QAction* action : m_programController->getRecentFileManager()->getActions())
|
||||||
|
@ -123,6 +123,7 @@
|
|||||||
<addaction name="actionShow_Text_Blocks"/>
|
<addaction name="actionShow_Text_Blocks"/>
|
||||||
<addaction name="actionShow_Text_Lines"/>
|
<addaction name="actionShow_Text_Lines"/>
|
||||||
<addaction name="actionDeveloperCreateInstaller"/>
|
<addaction name="actionDeveloperCreateInstaller"/>
|
||||||
|
<addaction name="actionDeveloperShow3DWindowDemo"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuEdit">
|
<widget class="QMenu" name="menuEdit">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
@ -979,6 +980,11 @@
|
|||||||
<string>Become a Sponsor</string>
|
<string>Become a Sponsor</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionDeveloperShow3DWindowDemo">
|
||||||
|
<property name="text">
|
||||||
|
<string>Show 3D Window Demo</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<resources>
|
<resources>
|
||||||
|
Reference in New Issue
Block a user