Skip to content
Snippets Groups Projects
Verified Commit 933580dd authored by Artem Sidyakin's avatar Artem Sidyakin
Browse files

First commit

parent 24efe87b
No related branches found
No related tags found
No related merge requests found
**/build-*/*
*.pro.user*
*.dylib
# WebGL release
A demo and a blog-post for the WebGL release in Qt 5.12
\ No newline at end of file
A demo and a blog-post for the WebGL release in Qt 5.12.
webgl-release-blog
webgl-release-demo/img/camera.png

28 KiB

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QtDebug>
#include <QCameraInfo>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
qDebug() << "cameras found: " << QCameraInfo::availableCameras().count();
QQmlApplicationEngine engine;
QString shotsFolderName = "shots/";
QString shotsPathLastMile = shotsFolderName.prepend("/");
#if defined(Q_OS_MAC)
shotsPathLastMile = shotsFolderName.prepend("/../../..");
#elif defined(Q_OS_WIN)
webPagesPathLastMile = shotsFolderName.prepend("/..");
#endif
QString shotsPath = QString("%1%2")
.arg(app.applicationDirPath())
.arg(shotsPathLastMile);
qDebug() << shotsPath;
engine.rootContext()->setContextProperty("shotsPath", shotsPath);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty()) { return -1; }
return app.exec();
}
import QtQuick 2.11
import QtQuick.Window 2.11
import QtMultimedia 5.11
import QtQuick.Layouts 1.11
import QtQuick.Controls 2.4
import Qt.labs.folderlistmodel 2.11
ApplicationWindow {
id: root
//visibility: "Maximized"
visible: true
width: 900
minimumWidth: 700
height: 500
minimumHeight: 400
title: qsTr("WebGL demo")
// for sliders and button
property int maxSize: 80
property string sliderColor: "transparent"
header: TabBar {
id: tabBar
currentIndex: stck.currentIndex
font.pixelSize: 20
TabButton { id: tabCamera; text: qsTr("Camera") }
TabButton { id: tabPhotos; text: qsTr("Photos") }
}
StackLayout {
id: stck
anchors.fill: parent
currentIndex: tabBar.currentIndex
Item {
GridLayout {
anchors.fill: parent
rows: 2
columns: 2
rowSpacing: 0
columnSpacing: 0
Rectangle {
Layout.row: 0
Layout.column: 0
Layout.fillWidth: true
Layout.fillHeight: true
Text {
id: cameraStatus
anchors.centerIn: parent
width: parent.width
text: qsTr("loading camera...")
font.pixelSize: 40
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WordWrap
}
// Rectangle {
// anchors.fill: parent
// border.width: 5
// border.color: "gray"
VideoOutput {
anchors.fill: parent
orientation: 180
fillMode: VideoOutput.PreserveAspectCrop
source: camera
Camera {
id: camera
cameraState: tabCamera.checked ? Camera.ActiveState : Camera.LoadedState
imageCapture {
onImageCaptured: {
console.log("photo has been captured")
}
onImageSaved: {
console.log("photo has been saved:", camera.imageCapture.capturedImagePath)
}
}
onError: {
cameraStatus.text = qsTr("Error: ") + errorString;
console.log(errorCode, errorString);
}
Component.onCompleted: {
// console.log(qsTr("camera orientation:"), camera.orientation);
// console.log(qsTr("camera state:"), camera.cameraState);
// console.log(qsTr("camera status:"), camera.cameraStatus);
// console.log(qsTr("camera supported resolutions:"), imageCapture.supportedResolutions);
}
}
}
// }
}
Rectangle {
Layout.row: 1
Layout.column: 0
Layout.fillWidth: true
Layout.fillHeight: true
Layout.maximumHeight: root.maxSize
color: root.sliderColor
Slider {
anchors.fill: parent
from: -90
value: 0
to: 90
}
}
Rectangle {
Layout.row: 0
Layout.column: 1
Layout.fillWidth: true
Layout.fillHeight: true
Layout.maximumWidth: root.maxSize
color: root.sliderColor
Slider {
anchors.fill: parent
orientation: Qt.Vertical
from: -90
value: 0
to: 90
}
}
Button {
Layout.row: 1
Layout.column: 1
Layout.fillWidth: true
Layout.fillHeight: true
Layout.maximumWidth: root.maxSize
Layout.maximumHeight: root.maxSize
scale: hovered ? (pressed ? 0.9 : 1.1) : 1
background: Rectangle {
color: "transparent"
}
Image {
id: cameraIcon
anchors.fill: parent
source: "/img/camera.png"
}
onClicked: {
camera.imageCapture.captureToLocation(shotsPath + getCurrentDateTime() + ".jpg");
}
}
}
}
Item {
RowLayout {
anchors.fill: parent
//anchors.topMargin: 15
spacing: 0
Rectangle {
Layout.preferredWidth: parent.width * 0.3
Layout.fillHeight: true
ListView {
id: files
anchors.fill: parent
FolderListModel {
id: folderModel
folder: "file:" + shotsPath
nameFilters: ["*.jpg"]
}
model: folderModel
delegate: ItemDelegate {
width: parent.width
text: model.fileName
font.pixelSize: 15
contentItem: Text {
text: parent.text
font: parent.font
elide: Text.ElideRight
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
wrapMode: Text.Wrap
}
highlighted: ListView.isCurrentItem
onClicked: { files.currentIndex = model.index; }
}
}
// Component.onCompleted: {
// currentPhoto.source = "file:/" + folderModel.get(files.currentIndex, "filePath");
// }
}
Rectangle {
Layout.fillWidth: true
Layout.fillHeight: true
color: "lightgray"
Image {
id: currentPhoto
anchors.fill: parent
anchors.margins: 20
source: folderModel.get(files.currentIndex, "fileURL");
fillMode: Image.PreserveAspectFit
}
}
}
}
}
function getCurrentDateTime()
{
return new Date().toISOString().replace(/[:|.|T]/g, "-").replace("Z", "");
}
}
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>img/camera.png</file>
</qresource>
</RCC>
QT += quick multimedia
#QTPLUGIN += qavfcamera
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment