diff --git a/debian/control b/debian/control index 9b77f9cc..571e03bd 100644 --- a/debian/control +++ b/debian/control @@ -4,9 +4,9 @@ Priority: optional Maintainer: Deepin Packages Builder Build-Depends: debhelper (>=9),cmake, - pkg-config,qtbase5-dev,libdtkgui-dev,libdtkwidget-dev,qtmultimedia5-dev, - libavutil-dev, libavformat-dev, libavcodec-dev,libavfilter-dev,qttools5-dev, - qttools5-dev-tools,deepin-gettext-tools, + pkg-config,qt6-base-dev,libdtk6gui-dev,libdtk6widget-dev,qt6-multimedia-dev, + libavutil-dev, libavformat-dev, libavcodec-dev,libavfilter-dev,qt6-tools-dev, + qt6-tools-dev-tools,deepin-gettext-tools, qt6-svg-dev, libv4l-dev,libsdl2-dev,portaudio19-dev,libpng-dev,libasound2-dev,libpciaccess-dev, libusb-1.0-0-dev,zlib1g-dev,libudev-dev,libswscale-dev,libswresample-dev,libffmpegthumbnailer-dev, libx11-dev,libva-dev,libimageeditor-dev, @@ -20,9 +20,8 @@ Depends: ${shlibs:Depends}, ${misc:Depends}, libavcodec58 (>= 7:4.0) | libavcodec60, libavformat58 (>= 7:4.1) | libavformat60, libavutil56 (>= 7:4.0) | libavutil58, libswresample3 (>= 7:4.0) | libswresample4, libswscale5 (>= 7:4.0) | libswscale7, - libdtkcore5, libdtkgui5, libdtkwidget5, libffmpegthumbnailer4v5, libgl1, libpng16-16 (>= 1.6.2-1), libportaudio2 (>= 19+svn20101113), libqt5concurrent5 (>= 5.0.2), libqt5core5a (>= 5.11.0~rc1), - libqt5dbus5 (>= 5.0.2), libqt5gui5 (>= 5.8.0), libqt5network5 (>= 5.0.2), libqt5printsupport5 (>= 5.0.2), libqt5widgets5 (>= 5.2.0~alpha1), libqt5x11extras5 (>= 5.6.0), libasound2 (>= 1.0.16), - libqt5xml5 (>= 5.0.2), libsdl2-2.0-0 (>= 2.0.9), libstdc++6 (>= 7), libudev1 (>= 183), libusb-1.0-0 (>= 2:1.0.8), libv4l-0 (>= 0.5.0), zlib1g (>= 1:1.1.4), libgstreamer-plugins-base1.0-0 (>= 1.0.0), libgstreamer1.0-0 (>= 1.4.0), dde-api + libdtkcore6, libdtkgui6, libdtkwidget6, libffmpegthumbnailer4v5, libgl1, libpng16-16 (>= 1.6.2-1), libportaudio2 (>= 19+svn20101113), libqt6concurrent6 (>= 6.8.0), libqt6core6 (>= 6.8.0), libqt6gui6 (>= 6.8.0), libqt6network6 (>= 6.8.0), libqt6printsupport6 (>= 6.8.0), libqt6widgets6 (>= 6.8.0), libasound2 (>= 1.0.16), + libqt6xml6 (>= 6.8.0), libsdl2-2.0-0 (>= 2.0.9), libstdc++6 (>= 7), libudev1 (>= 183), libusb-1.0-0 (>= 2:1.0.8), libv4l-0 (>= 0.5.0), zlib1g (>= 1:1.1.4), libgstreamer-plugins-base1.0-0 (>= 1.0.0), libgstreamer1.0-0 (>= 1.4.0), dde-api Recommends: libimageeditor, uos-reporter, deepin-event-log Description:this package software for UOS deepin-camera is a tool to view camera, and also a smart take photo and video in life. diff --git a/debian/rules b/debian/rules index 0a27c703..ab103517 100755 --- a/debian/rules +++ b/debian/rules @@ -1,6 +1,6 @@ #!/usr/bin/make -f include /usr/share/dpkg/default.mk -export QT_SELECT=5 +export QT_SELECT=6 DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) MODULE_NAME=deepin-camera diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fa7dba51..418db346 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,11 @@ project(deepin-camera VERSION 1.0.0) set(CMD_NAME deepin-camera) set(TARGET_NAME deepin-camera) +set(QT_VERSION_MAJOR 6) +if (${QT_VERSION_MAJOR} GREATER_EQUAL 6) + set(DTK_VERSION 6) +endif() + #option (__mips__ "Use UNITTEST" ON) # cube文件目录,libvisualresult在打包时,会自动将cube文件安装到share目录下 @@ -33,9 +38,9 @@ elseif(MAJOR_VERSION MATCHES "25") endif() include(GNUInstallDirs) -if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) +# if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX /usr) -endif () +# endif () if(DEFINED LINGLONG_BUILD_ON) # 玲珑构建编译开关 @@ -79,10 +84,10 @@ set(PROJECT_INCLUDE ) # 设置Qt模块 -set(QtModule Core Gui Widgets DBus Concurrent LinguistTools Multimedia PrintSupport Svg) +set(QtModule Core Gui Widgets DBus Concurrent LinguistTools Multimedia PrintSupport Svg SvgWidgets OpenGL OpenGLWidgets) # 查找Qt相关的库链接 -find_package(Qt5 REQUIRED ${QtModule}) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED ${QtModule}) find_package(PkgConfig REQUIRED) include(FindPkgConfig) @@ -110,8 +115,28 @@ file (GLOB_RECURSE HEADERS file (GLOB_RECURSE RESOURCES ${PROJECT_SOURCE_DIR}/assets/assets.qrc) +if (${QT_VERSION_MAJOR} GREATER_EQUAL 6) + set(CXX_FILES_TO_REMOVE + ${PROJECT_SOURCE_DIR}/./src/videosurface.cpp + ) + set(HEAD_FILES_TO_REMOVE + ${PROJECT_SOURCE_DIR}/./src/videosurface.h + ) +else() +endif() + +foreach(file ${CXX_FILES_TO_REMOVE}) + list(REMOVE_ITEM CXXSOURCES ${file}) + # list(REMOVE_ITEM HEAD_FILES_TO_REMOVE ${file}) +endforeach() +foreach(file ${HEAD_FILES_TO_REMOVE}) + list(REMOVE_ITEM HEADERS ${file}) +endforeach() + pkg_check_modules(3rd_lib REQUIRED - dtkwidget dtkcore gobject-2.0 + dtk${DTK_VERSION}widget + dtk${DTK_VERSION}core + gobject-2.0 pciaccess # libv4l2 # libudev @@ -140,11 +165,7 @@ file (GLOB TS LIST_DIRECTORIES false ${PROJECT_SOURCE_DIR}/translations/${TARGET set_source_files_properties(${TS} PROPERTIES OUTPUT_LOCATION ${PROJECT_SOURCE_DIR}/translations) -qt5_create_translation(QM ${CXXSOURCES} ${TS}) - -if (NOT (${CMAKE_BUILD_TYPE} MATCHES "Debug")) - qt5_create_translation(QM ${CXXSOURCES} ${TS}) -endif () +qt_create_translation(QM ${CXXSOURCES} ${TS}) # 设置不删除生成的文件夹内容文件 set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM 1) @@ -159,13 +180,16 @@ target_link_libraries(${TARGET_NAME} ${3rd_lib_LIBRARIES} dl imagevisualresult ${LIBS} + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Multimedia + Qt${QT_VERSION_MAJOR}::Svg + Qt${QT_VERSION_MAJOR}::SvgWidgets + Qt${QT_VERSION_MAJOR}::OpenGL + Qt${QT_VERSION_MAJOR}::OpenGLWidgets ) include_directories("${CMAKE_INSTALL_PREFIX}/include") -# 将工程与Qt模块链接起来 -qt5_use_modules(${TARGET_NAME} ${QtModule}) - #application install(TARGETS ${TARGET_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/main.cpp b/src/main.cpp index 0a34fb82..71e6f6ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,7 +23,9 @@ extern "C" { #include #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include @@ -59,7 +61,17 @@ static bool CheckFFmpegEnv() QString path = QLibraryInfo::location(QLibraryInfo::LibrariesPath); dir.setPath(path); QStringList list = dir.entryList(QStringList() << (QString("libavcodec") + "*"), QDir::NoDotAndDotDot | QDir::Files); - QString libName = "libavcodec.so"; // set default name for load if not find in LibrariesPath + QString libName = "libavcodec.so"; // set default name for load if not find in LibrariesPath +#if QT_VERSION_MAJOR > 5 + QRegularExpression re("libavcodec.so.*"); //Sometimes libavcodec.so may not exist, so find it through regular expression. + for (int i = 0; i < list.count(); i++) { + QRegularExpressionMatch match = re.match(list[i]); + if (match.hasMatch()) { + libName = list[i]; + break; + } + } +#else QRegExp re("libavcodec.so.*"); //Sometimes libavcodec.so may not exist, so find it through regular expression. for (int i = 0; i < list.count(); i++) { if (re.exactMatch(list[i])) { @@ -67,6 +79,7 @@ static bool CheckFFmpegEnv() break; } } +#endif QLibrary libavcodec; //检查编码器是否存在 libavcodec.setFileName(libName); @@ -158,7 +171,11 @@ int main(int argc, char *argv[]) qInfo() << "last mp4EncodeMode value is:" << get_pugx_status(); } +#if QT_VERSION_MAJOR > 5 + QElapsedTimer time; +#else QTime time; +#endif time.start(); QString lutDir = LUT_DIR; initFilters(lutDir.toStdString().c_str()); @@ -199,7 +216,9 @@ int main(int argc, char *argv[]) dc::Settings::get().init(); +#if QT_VERSION_MAJOR <= 5 DApplicationSettings saveTheme; +#endif if (!qApp->setSingleInstance("deepin-camera")) { qDebug() << "another deepin camera instance has started"; diff --git a/src/src/Settings.cpp b/src/src/Settings.cpp index cd6d58ed..9c34bfe4 100644 --- a/src/src/Settings.cpp +++ b/src/src/Settings.cpp @@ -223,7 +223,7 @@ void Settings::onValueChanged(const QString & key, const QVariant & value) { if (key.startsWith("outsetting.resolutionsetting.resolution")) { auto mode_opt = m_settings->option("outsetting.resolutionsetting.resolution"); - if (value >= 0 && mode_opt->data("items").toStringList().size() > value.toInt()) { + if (value.toInt() >= 0 && mode_opt->data("items").toStringList().size() > value.toInt()) { QString mode = mode_opt->data("items").toStringList()[value.toInt()]; emit resolutionchanged(mode); } @@ -231,14 +231,14 @@ void Settings::onValueChanged(const QString & key, const QVariant & value) if (key.startsWith("base.photogrid.photogrids")) { auto grid_opt1 = m_settings->option("base.photogrid.photogrids"); - if (value >= 0 && grid_opt1->data("items").toStringList().size() > value.toInt()) { + if (value.toInt() >= 0 && grid_opt1->data("items").toStringList().size() > value.toInt()) { emit gridTypeChanged(value.toInt()); } } if (key.startsWith("photosetting.photosdelay.photodelays")) { auto mode_opt1 = m_settings->option("photosetting.photosdelay.photodelays"); - if (value >= 0 && mode_opt1->data("items").toStringList().size() > value.toInt()) { + if (value.toInt() >= 0 && mode_opt1->data("items").toStringList().size() > value.toInt()) { QString mode1 = mode_opt1->data("items").toStringList()[value.toInt()]; emit delayTimeChanged(mode1); } @@ -256,7 +256,7 @@ void Settings::onValueChanged(const QString & key, const QVariant & value) if (key.startsWith("outsetting.outformat.vidformat")) { QPointer formatOpt = m_settings->option("outsetting.outformat.vidformat"); - if (value >= 0 && formatOpt->data("items").toStringList().size() > value.toInt()) { + if (value.toInt() >= 0 && formatOpt->data("items").toStringList().size() > value.toInt()) { QString videoFormat = formatOpt->data("items").toStringList()[value.toInt()]; emit videoFormatChanged(videoFormat); } diff --git a/src/src/camera.cpp b/src/src/camera.cpp index 5883e717..25b057c9 100755 --- a/src/src/camera.cpp +++ b/src/src/camera.cpp @@ -6,7 +6,10 @@ #define TMPPATH "/tmp/tmp.jpg" #include "camera.h" +#if QT_VERSION_MAJOR > 5 +#else #include "videosurface.h" +#endif #include "datamanager.h" #ifdef __cplusplus @@ -22,7 +25,9 @@ extern "C" { #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #define MAXLINE 100 @@ -75,9 +80,12 @@ Camera::~Camera() Camera::Camera() : m_camera(nullptr) , m_mediaRecoder(nullptr) +#if QT_VERSION_MAJOR > 5 +#else , m_imageCapture(nullptr) , m_videoSurface(nullptr) , m_curDevName("") +#endif , m_bReadyRecord(false) , m_bRecording(false) { @@ -88,8 +96,11 @@ Camera::Camera() void Camera::initMember() { // 连接相机surface,能够发送每帧QImage数据到外部 +#if QT_VERSION_MAJOR > 5 +#else m_videoSurface = new VideoSurface(this); connect(m_videoSurface, &VideoSurface::presentImage, this, &Camera::presentImage); +#endif // 初始设备名为空,默认启动config中的摄像头设备,若config设备名为空,则启动defaultCamera switchCamera(); @@ -99,6 +110,17 @@ void Camera::switchCamera() { refreshCamDevList(); +#if QT_VERSION_MAJOR > 5 + QCameraDevice nextDevice; + + if (!m_cameraDeviceList.isEmpty()) { + int nCurIndex = m_cameraDeviceList.indexOf(m_curDevice); + nCurIndex = (nCurIndex + 1) % m_cameraDeviceList.size(); + nextDevice = m_cameraDeviceList[nCurIndex]; + } + nextDevice = QMediaDevices::defaultVideoInput(); + startCamera(nextDevice); +#else QString nextDevName; if (!m_cameraDevList.isEmpty()) { @@ -110,10 +132,12 @@ void Camera::switchCamera() if (nextDevName.isEmpty()) nextDevName = camConfig.device_location; - if (nextDevName.isEmpty()) + if (nextDevName.isEmpty()) { nextDevName = QCameraInfo::defaultCamera().deviceName(); - + } startCamera(nextDevName); +#endif + } void Camera::refreshCamera() @@ -121,31 +145,57 @@ void Camera::refreshCamera() refreshCamDevList(); // 设备链表找不到当前设备,发送设备断开信号 +#if QT_VERSION_MAJOR > 5 + if (!m_curDevice.isNull() && m_cameraDeviceList.indexOf(m_curDevice) == -1) { + m_curDevice = QCameraDevice(); + emit currentCameraDisConnected(); + } +#else if (!m_curDevName.isEmpty() && m_cameraDevList.indexOf(m_curDevName) == -1) { m_curDevName = ""; emit currentCameraDisConnected(); } +#endif // 若没有摄像头工作,则重启摄像头 restartCamera(); } +#include // 重启摄像头 void Camera::restartCamera() { +#if QT_VERSION_MAJOR > 5 + if (!m_camera) { + QList availableCams = QMediaDevices::videoInputs(); + if ((availableCams.isEmpty() || (m_camera && availableCams.indexOf(m_camera->cameraDevice()) != -1)) +#if QT_VERSION_MAJOR > 5 + && !m_cameraDeviceList.isEmpty()) { +#else + && !m_cameraDevList.isEmpty()) { +#endif + emit cameraCannotUsed(); + return; + } +#else if (!m_camera || m_camera->status() == QCamera::UnloadedStatus) { QList availableCams = QCameraInfo::availableCameras(); if ((availableCams.isEmpty() || (m_camera && availableCams.indexOf(QCameraInfo(*m_camera)) != -1)) - && !m_cameraDevList.isEmpty()) { + && !m_cameraDevList.isEmpty()) { emit cameraCannotUsed(); return; } +#endif } if (DataManager::instance()->getdevStatus() == CAM_CANUSE) return; +#if QT_VERSION_MAJOR > 5 + startCamera(QMediaDevices::defaultVideoInput()); +#else startCamera(QCameraInfo::defaultCamera().deviceName()); +#endif DataManager::instance()->setdevStatus(CAM_CANUSE); @@ -154,13 +204,19 @@ void Camera::restartCamera() void Camera::refreshCamDevList() { +#if QT_VERSION_MAJOR > 5 + m_cameraDeviceList.clear(); + m_cameraDeviceList = QMediaDevices::videoInputs(); +#else m_cameraDevList.clear(); v4l2_device_list_t *devlist = get_device_list(); for (int i = 0; i < devlist->num_devices; i++) m_cameraDevList.push_back(devlist->list_devices[i].device); +#endif } +#if QT_VERSION_MAJOR <= 5 void Camera::onCameraStatusChanged(QCamera::Status status) { if (m_mediaRecoder) { @@ -170,6 +226,7 @@ void Camera::onCameraStatusChanged(QCamera::Status status) } } } +#endif QStringList Camera::getSupportResolutions() { @@ -192,8 +249,14 @@ QStringList Camera::getSupportResolutions() QList Camera::getSupportResolutionsSize() { QList resolutions; +#if QT_VERSION_MAJOR > 5 + if (m_camera) { + resolutions = m_camera->cameraDevice().photoResolutions(); + } +#else if (m_imageCapture) resolutions = m_imageCapture->supportedResolutions(); +#endif return resolutions; } @@ -201,6 +264,9 @@ QList Camera::getSupportResolutionsSize() // 设置相机分辨率 void Camera::setCameraResolution(QSize size) { +#if QT_VERSION_MAJOR > 5 + //TODO +#else // 设置图片捕获器分辨率到相机 if (m_imageCapture) { QImageEncoderSettings imageSettings = m_imageCapture->encodingSettings(); @@ -208,7 +274,7 @@ void Camera::setCameraResolution(QSize size) m_imageCapture->setEncodingSettings(imageSettings); } - // 设置视频分辨率到相机 + // 设置视频分辨率到相机 if (m_mediaRecoder) { QAudioEncoderSettings audioSettings = m_mediaRecoder->audioSettings(); QVideoEncoderSettings videoSettings = m_mediaRecoder->videoSettings(); @@ -217,12 +283,13 @@ void Camera::setCameraResolution(QSize size) m_mediaRecoder->setEncodingSettings(audioSettings, videoSettings, "video/webm"); } - // 设置分辨率到相机 + // 设置分辨率到相机 if (m_camera) { QCameraViewfinderSettings viewfinderSettings = m_camera->viewfinderSettings(); viewfinderSettings.setResolution(size); m_camera->setViewfinderSettings(viewfinderSettings); } +#endif // 同步有变更的分辨率到config camConfig.width = size.rwidth(); @@ -235,17 +302,26 @@ QSize Camera::getCameraResolution() return QSize(camConfig.width,camConfig.height); } +#if QT_VERSION_MAJOR > 5 +void Camera::startCamera(const QCameraDevice &device) +#else void Camera::startCamera(const QString &devName) +#endif { // 存在上一相机,先停止 if (m_camera) stopCamera(); +#if QT_VERSION_MAJOR > 5 + m_camera = new QCamera(device); + m_videoSink = new QVideoSink(this); + m_curDevice = device; +#else m_camera = new QCamera(devName.toStdString().c_str()); QCameraInfo cameraInfo(*m_camera); - m_curDevName = devName; - connect(m_camera, SIGNAL(statusChanged(QCamera::Status)), this, SLOT(onCameraStatusChanged(QCamera::Status))); + m_curDevName = device.description(); + m_imageCapture = new QCameraImageCapture(m_camera); m_mediaRecoder = new QMediaRecorder(m_camera); @@ -260,7 +336,7 @@ void Camera::startCamera(const QString &devName) m_camera->start(); - // 同步设备名称到config + // 同步设备名称到config if (camConfig.device_name) { free(camConfig.device_name); camConfig.device_name = nullptr; @@ -277,19 +353,19 @@ void Camera::startCamera(const QString &devName) // 当前设备与config设备名不同,重置分辨率到最大值,并同步到config文件 QString configDevName = QString(camConfig.device_location); if (m_curDevName != configDevName - || (m_curDevName.isEmpty() && m_curDevName == configDevName)) { + || (m_curDevName.isEmpty() && m_curDevName == configDevName)) { if (!supportList.isEmpty()) { camConfig.width = supportList.last().rwidth(); camConfig.height = supportList.last().rheight(); } } - // 若当前摄像头不支持该分辨率,重置为当前摄像头最大分辨率 + // 若当前摄像头不支持该分辨率,重置为当前摄像头最大分辨率 if (!supportList.isEmpty()) { bool bResetResolution = true; for (int i = 0; i < supportList.size(); i++) { if (supportList[i].width() == camConfig.width && - supportList[i].height() == camConfig.height) { + supportList[i].height() == camConfig.height) { bResetResolution = false; break; } @@ -300,26 +376,32 @@ void Camera::startCamera(const QString &devName) } } - // 同步config分辨率到相机,并保存到文件 + // 同步config分辨率到相机,并保存到文件 setCameraResolution(QSize(camConfig.width, camConfig.height)); - // 发送相机名称变更信号 + // 发送相机名称变更信号 emit cameraSwitched(cameraInfo.description()); +#endif } void Camera::stopCamera() { if (m_camera) { +#if QT_VERSION_MAJOR <= 5 connect(m_camera, SIGNAL(statusChanged(QCamera::Status)), this, SLOT(onCameraStatusChanged(QCamera::Status))); +#endif m_camera->stop(); m_camera->deleteLater(); m_camera = nullptr; } +#if QT_VERSION_MAJOR > 5 +#else if (m_imageCapture) { m_imageCapture->deleteLater(); m_imageCapture = nullptr; } +#endif if (m_mediaRecoder) { m_mediaRecoder->deleteLater(); @@ -335,22 +417,28 @@ void Camera::setVideoOutPutPath(QString &path) void Camera::startRecoder() { +#if QT_VERSION_MAJOR > 5 +#else m_bReadyRecord = true; if (m_camera && m_camera->captureMode() != QCamera::CaptureVideo) { m_camera->setCaptureMode(QCamera::CaptureVideo); } m_bRecording = true; +#endif } void Camera::stopRecoder() { +#if QT_VERSION_MAJOR > 5 +#else if (m_mediaRecoder) m_mediaRecoder->stop(); if (m_camera && m_camera->captureMode() != QCamera::CaptureStillImage) m_camera->setCaptureMode(QCamera::CaptureStillImage); m_bRecording = false; +#endif } qint64 Camera::getRecoderTime() @@ -362,6 +450,16 @@ qint64 Camera::getRecoderTime() return nRecTime; } +#if QT_VERSION_MAJOR > 5 +QMediaRecorder::RecorderState Camera::getRecoderState() +{ + QMediaRecorder::RecorderState recState = QMediaRecorder::StoppedState; + if (m_mediaRecoder) + recState = m_mediaRecoder->recorderState(); + + return recState; +} +#else QMediaRecorder::State Camera::getRecoderState() { QMediaRecorder::State recState = QMediaRecorder::StoppedState; @@ -370,6 +468,7 @@ QMediaRecorder::State Camera::getRecoderState() return recState; } +#endif bool Camera::isRecording() { diff --git a/src/src/camera.h b/src/src/camera.h index 145d2cb8..4e852e10 100644 --- a/src/src/camera.h +++ b/src/src/camera.h @@ -9,9 +9,15 @@ #include #include #include -#include #include +#if QT_VERSION_MAJOR > 5 +#include +#include +#include +#else +#include #include +#endif typedef struct _cam_config_t { int width; /*width*/ @@ -25,7 +31,10 @@ typedef struct _cam_config_t { int fps_num; int fps_denom; } cam_config; +#if QT_VERSION_MAJOR > 5 +#else class VideoSurface; +#endif class Camera : public QObject { Q_OBJECT @@ -69,7 +78,11 @@ class Camera : public QObject /** * @brief startCamera 开始当前相机 */ +#if QT_VERSION_MAJOR > 5 + void startCamera(const QCameraDevice& device); +#else void startCamera(const QString& devName); +#endif /** * @brief stopCamera 停止当前相机 @@ -94,7 +107,11 @@ class Camera : public QObject qint64 getRecoderTime(); +#if QT_VERSION_MAJOR > 5 + QMediaRecorder::RecorderState getRecoderState(); +#else QMediaRecorder::State getRecoderState(); +#endif bool isRecording(); @@ -124,10 +141,12 @@ public slots: */ void refreshCamDevList(); +#if QT_VERSION_MAJOR <= 5 /** * @brief onCameraStatusChanged 相机状态监听 */ void onCameraStatusChanged(QCamera::Status status); +#endif signals: // 发送摄像头每帧画面 @@ -152,12 +171,18 @@ public slots: static Camera *m_instance; QCamera *m_camera; QMediaRecorder *m_mediaRecoder; +#if QT_VERSION_MAJOR > 5 + QVideoSink *m_videoSink; + QCameraDevice m_curDevice; + QList m_cameraDeviceList; +#else QCameraImageCapture *m_imageCapture; - VideoSurface *m_videoSurface; - - QString m_curDevName; // 当前摄像头设备名 QCameraViewfinderSettings m_viewfinderSettings; + QString m_curDevName; // 当前摄像头设备名 QList m_cameraDevList; // 摄像头设备名列表 + VideoSurface *m_videoSurface; +#endif + bool m_bReadyRecord; bool m_bRecording; diff --git a/src/src/circlepushbutton.cpp b/src/src/circlepushbutton.cpp index 3b5f72cc..df72dadd 100644 --- a/src/src/circlepushbutton.cpp +++ b/src/src/circlepushbutton.cpp @@ -54,7 +54,11 @@ void circlePushButton::paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter painter(this); +#if QT_VERSION_MAJOR > 5 + painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing); +#else painter.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform | QPainter::Antialiasing); +#endif int distance = 2; int tmpWidth = width(); @@ -141,7 +145,11 @@ void circlePushButton::paintEvent(QPaintEvent *event) painter.restore(); } +#if QT_VERSION_MAJOR > 5 +void circlePushButton::enterEvent(QEnterEvent *event) +#else void circlePushButton::enterEvent(QEvent *event) +#endif { Q_UNUSED(event); m_hover = true; diff --git a/src/src/circlepushbutton.h b/src/src/circlepushbutton.h index 08acfb23..8d50454d 100644 --- a/src/src/circlepushbutton.h +++ b/src/src/circlepushbutton.h @@ -7,7 +7,11 @@ #define CIRCLEPUSHBUTTON_H #include +#if QT_VERSION_MAJOR <= 5 #include +#else +#include +#endif class QColor; class QSvgRenderer; @@ -115,7 +119,11 @@ public slots: * @brief enterEvent 鼠标进入事件 * @param event 事件参数 */ +#if QT_VERSION_MAJOR > 5 + void enterEvent(QEnterEvent *event) override; +#else void enterEvent(QEvent *event) override; +#endif /** * @brief focusInEvent 焦点进入事件 diff --git a/src/src/closedialog.cpp b/src/src/closedialog.cpp index f2e5a88f..8b5d3de8 100644 --- a/src/src/closedialog.cpp +++ b/src/src/closedialog.cpp @@ -11,7 +11,11 @@ #include #include +#if QT_VERSION_MAJOR > 5 +#include +#else #include +#endif #include DWIDGET_USE_NAMESPACE diff --git a/src/src/exposureslider.cpp b/src/src/exposureslider.cpp index dc443962..c7dc6c0d 100644 --- a/src/src/exposureslider.cpp +++ b/src/src/exposureslider.cpp @@ -136,7 +136,11 @@ void ExposureSlider::showContent(bool show, bool isShortCut) void ExposureSlider::paintEvent(QPaintEvent *event) { QPainter painter(this); +#if QT_VERSION_MAJOR > 5 + painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); +#else painter.setRenderHint(QPainter::HighQualityAntialiasing, true); +#endif QRectF topRect(rect().topLeft(), QSize(WIDTH, WIDTH)); QRectF centerRect(rect().topLeft() + QPoint(0, WIDTH / 2.0), QSize(WIDTH, HEIGHT - WIDTH)); diff --git a/src/src/filterpreviewbutton.cpp b/src/src/filterpreviewbutton.cpp index e833caf4..16fd92a8 100644 --- a/src/src/filterpreviewbutton.cpp +++ b/src/src/filterpreviewbutton.cpp @@ -12,7 +12,12 @@ extern "C" { #include #include +#if QT_VERSION_MAJOR <= 5 #include +#else +#include +DGUI_USE_NAMESPACE +#endif DWIDGET_USE_NAMESPACE; @@ -83,7 +88,11 @@ void filterPreviewButton::paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter painter(this); +#if QT_VERSION_MAJOR > 5 + painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing); +#else painter.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform | QPainter::Antialiasing); +#endif QRect imageRect = QRect(MARGIN, MARGIN, IMAGE_SIZE, IMAGE_SIZE); @@ -146,7 +155,11 @@ void filterPreviewButton::paintEvent(QPaintEvent *event) QWidget::paintEvent(event); } +#if QT_VERSION_MAJOR > 5 +void filterPreviewButton::enterEvent(QEnterEvent *event) +#else void filterPreviewButton::enterEvent(QEvent *event) +#endif { Q_UNUSED(event); this->setFocus(); diff --git a/src/src/filterpreviewbutton.h b/src/src/filterpreviewbutton.h index 8b4cfbe7..7fe212da 100644 --- a/src/src/filterpreviewbutton.h +++ b/src/src/filterpreviewbutton.h @@ -104,7 +104,11 @@ public slots: * @brief enterEvent 鼠标进入事件 * @param event 事件参数 */ +#if QT_VERSION_MAJOR > 5 + void enterEvent(QEnterEvent *event) override; +#else void enterEvent(QEvent *event) override; +#endif /** * @brief focusInEvent 焦点进入事件 diff --git a/src/src/gstvideowriter.cpp b/src/src/gstvideowriter.cpp index 197657b0..07000990 100644 --- a/src/src/gstvideowriter.cpp +++ b/src/src/gstvideowriter.cpp @@ -12,7 +12,11 @@ extern "C" { #include "audio.h" } +#if QT_VERSION_MAJOR > 5 +#include +#else #include +#endif GST_DEBUG_CATEGORY(appsrc_pipeline_debug); diff --git a/src/src/imageitem.cpp b/src/src/imageitem.cpp index 1e5ef355..4cb196a3 100644 --- a/src/src/imageitem.cpp +++ b/src/src/imageitem.cpp @@ -10,7 +10,9 @@ #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include @@ -23,7 +25,6 @@ #include #include #include - #include extern "C" { @@ -183,7 +184,11 @@ void ImageItem::paintEvent(QPaintEvent *event) QFileInfo fileinfo(m_path); QString str = fileinfo.suffix(); +#if QT_VERSION_MAJOR > 5 + painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing); +#else painter.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform | QPainter::Antialiasing); +#endif pixmapRect.setX(rect().x() + 1); pixmapRect.setY(rect().y() + 1); @@ -518,7 +523,11 @@ void ImageItem::paintRequestedAsyn(DPrinter *_printer, const QVector &pageR if (!img.isNull()) { painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::SmoothPixmapTransform); +#if QT_VERSION_MAJOR > 5 + QRect wRect = this->rect(); +#else QRect wRect = _printer->pageRect(); +#endif QImage tmpMap; if (img.width() > wRect.width() || img.height() > wRect.height()) @@ -552,7 +561,11 @@ void ImageItem::paintRequestSync(DPrinter *_printer) if (!img.isNull()) { painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::SmoothPixmapTransform); +#if QT_VERSION_MAJOR > 5 + QRect wRect = this->rect(); +#else QRect wRect = _printer->pageRect(); +#endif QImage tmpMap; if (img.width() > wRect.width() || img.height() > wRect.height()) @@ -585,7 +598,11 @@ void AnimationWidget::paintEvent(QPaintEvent *e) QPainter painter(this); QPainterPath path; +#if QT_VERSION_MAJOR > 5 + painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing); +#else painter.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform | QPainter::Antialiasing); +#endif path.addRoundedRect(pixmapRect, width(), height()); painter.fillPath(path, QBrush(m_animatePix)); diff --git a/src/src/mainwindow.cpp b/src/src/mainwindow.cpp index 27e00e8a..a94e9b6e 100755 --- a/src/src/mainwindow.cpp +++ b/src/src/mainwindow.cpp @@ -271,7 +271,9 @@ static QWidget *createPicSelectableLineEditOptionHandle(QObject *opt) optionLayout->setContentsMargins(0, 0, 0, 0); optionLayout->setSpacing(0); optionLayout->setVerticalSpacing(0); +#if QT_VERSION_MAJOR <= 5 optionLayout->setMargin(0); +#endif main->setMinimumWidth(240); DLabel *lab = new DLabel(QObject::tr(option->name().toStdString().c_str())); @@ -431,10 +433,10 @@ static QWidget *createPicSelectableLineEditOptionHandle(QObject *opt) auto pi = ElideText(value.toString(), { pathEditWidth, tem_fontmetrics.height() }, QTextOption::WrapAnywhere, picPathLineEdit->font(), Qt::ElideMiddle, tem_fontmetrics.height(), pathEditWidth); picPathLineEdit->setText(pi); - qDebug() << "picPathLineEdit text:" << picPathLineEdit->text() << endl; + qDebug() << "picPathLineEdit text:" << picPathLineEdit->text() << Qt::endl; lastPicPath = value.toString(); option->setValue(value.toString()); - qDebug() << "save pic last path:" << value.toString() << endl; + qDebug() << "save pic last path:" << value.toString() << Qt::endl; picPathLineEdit->update(); }); @@ -699,10 +701,10 @@ static QWidget *createVdSelectableLineEditOptionHandle(QObject *opt) QTextOption::WrapAnywhere, videoPathLineEdit->font(), Qt::ElideMiddle, tem_fontmetrics.height(), pathEditWidth); videoPathLineEdit->setText(pi); - qDebug() << "picPathLineEdit text:" << videoPathLineEdit->text() << endl; + qDebug() << "picPathLineEdit text:" << videoPathLineEdit->text() << Qt::endl; lastVideoPath = value.toString(); option->setValue(value.toString()); - qDebug() << "save video last path:" << value.toString() << endl; + qDebug() << "save video last path:" << value.toString() << Qt::endl; videoPathLineEdit->update(); }); @@ -1394,7 +1396,11 @@ void CMainWindow::onSwitchCameraSuccess(const QString &cameraName) if (!tmpList.isEmpty()) { m_labelCameraName->setText(tmpList[0]); } +#if QT_VERSION_MAJOR > 5 + int width = m_labelCameraName->fontMetrics().boundingRect(tmpList[0]).width(); +#else int width = m_labelCameraName->fontMetrics().width(tmpList[0]); +#endif m_labelCameraName->setFixedWidth(width); m_labelCameraName->show(); m_filterName->hide(); @@ -1403,7 +1409,7 @@ void CMainWindow::onSwitchCameraSuccess(const QString &cameraName) void CMainWindow::onTimeoutLock(const QString &serviceName, QVariantMap key2value, QStringList) { - qDebug() << serviceName << key2value << endl; + qDebug() << serviceName << key2value << Qt::endl; //仅wayland需要锁屏结束录制并停止使用摄像头,从锁屏恢复重新开启摄像头 //wayland下只需要停止录像,不需要停止线程,需要在锁屏状态下继续处理摄像头状态 // if (m_bWayland) { @@ -1676,7 +1682,7 @@ void CMainWindow::initUI() m_filterName->hide(); m_filterName->setFixedSize(labelFilterNameWidth, labelFilterNameHeight); QPalette paletteFilterName = m_filterName->palette(); - paletteFilterName.setColor(QPalette::Background, QColor(0, 0, 0, 0)); + paletteFilterName.setColor(QPalette::Window, QColor(0, 0, 0, 0)); paletteFilterName.setColor(QPalette::WindowText, QColor(255, 255, 255, 255)); m_filterName->setAutoFillBackground(true); m_filterName->setPalette(paletteFilterName); @@ -1745,13 +1751,17 @@ void CMainWindow::initUI() m_showCameraNameTimer->setInterval(2000); m_labelCameraName->setFixedSize(labelCameraNameWidth, labelCameraNameHeight); QPalette paletteName = m_labelCameraName->palette(); - paletteName.setColor(QPalette::Background, QColor(0, 0, 0, 0)); //深色 + paletteName.setColor(QPalette::Window, QColor(0, 0, 0, 0)); //深色 paletteName.setColor(QPalette::WindowText, QColor(255, 255, 255, 255)); m_labelCameraName->setAutoFillBackground(true); m_labelCameraName->setPalette(paletteName); QFont ft; ft.setFamily("SourceHanSansSC, SourceHanSansSC-Normal"); +#if QT_VERSION_MAJOR > 5 + ft.setWeight(QFont::Thin); +#else ft.setWeight(20); +#endif ft.setPointSize(14); m_labelCameraName->setFont(ft); m_labelCameraName->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); diff --git a/src/src/photorecordbtn.cpp b/src/src/photorecordbtn.cpp index c70fda94..5995bdce 100644 --- a/src/src/photorecordbtn.cpp +++ b/src/src/photorecordbtn.cpp @@ -5,12 +5,15 @@ #include "photorecordbtn.h" +#if QT_VERSION_MAJOR <= 5 #include +#else +#include +#endif #include #include #include -#include #include photoRecordBtn::photoRecordBtn(QWidget *parent/* = nullptr*/) @@ -29,7 +32,9 @@ void photoRecordBtn::paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter painter(this); +#if QT_VERSION_MAJOR <= 5 painter.setRenderHint(QPainter::HighQualityAntialiasing, true); +#endif painter.setBrush(Qt::NoBrush); QPainterPath path; @@ -104,7 +109,11 @@ void photoRecordBtn::paintEvent(QPaintEvent *event) } } +#if QT_VERSION_MAJOR > 5 +void photoRecordBtn::enterEvent(QEnterEvent *event) +#else void photoRecordBtn::enterEvent(QEvent *event) +#endif { Q_UNUSED(event); m_bFocus = true; diff --git a/src/src/photorecordbtn.h b/src/src/photorecordbtn.h index 26a18f49..79069ba4 100644 --- a/src/src/photorecordbtn.h +++ b/src/src/photorecordbtn.h @@ -42,7 +42,11 @@ class photoRecordBtn : public QWidget void clicked(); protected: void paintEvent(QPaintEvent *event) override; +#if QT_VERSION_MAJOR > 5 + void enterEvent(QEnterEvent *event) override; +#else void enterEvent(QEvent *event) override; +#endif void leaveEvent(QEvent *event) override; void mousePressEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; diff --git a/src/src/previewopenglwidget.cpp b/src/src/previewopenglwidget.cpp index 40b5c239..abec6dd6 100644 --- a/src/src/previewopenglwidget.cpp +++ b/src/src/previewopenglwidget.cpp @@ -5,8 +5,13 @@ #include "previewopenglwidget.h" +#if QT_VERSION_MAJOR > 5 +#include +#include +#else #include #include +#endif #include diff --git a/src/src/previewopenglwidget.h b/src/src/previewopenglwidget.h index 1fb0789b..f712ac8f 100644 --- a/src/src/previewopenglwidget.h +++ b/src/src/previewopenglwidget.h @@ -11,9 +11,16 @@ #include #include #include -#include #include +#if QT_VERSION_MAJOR > 5 +#include +#include +#include +#include +#else +#include #include +#endif QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram) QT_FORWARD_DECLARE_CLASS(QOpenGLTexture) diff --git a/src/src/rollingbox.cpp b/src/src/rollingbox.cpp index 62107ec3..e6b33cde 100644 --- a/src/src/rollingbox.cpp +++ b/src/src/rollingbox.cpp @@ -10,7 +10,11 @@ #include #include +#if QT_VERSION_MAJOR <= 5 #include +#else +#include +#endif #define BTN_WIDTH 50 #define BTN_HEIGHT 26 @@ -135,6 +139,18 @@ void RollingBox::mouseReleaseEvent(QMouseEvent *e) void RollingBox::wheelEvent(QWheelEvent *e) { +#if QT_VERSION_MAJOR > 5 + if (e->angleDelta().y() > 0 && m_currentIndex <= m_rangeMin) + return; + if (e->angleDelta().y() < 0 && m_currentIndex >= m_rangeMax) + return; + + if(e->angleDelta().y() / 90 > 0) { + m_deviation = (this->height()) / 4; + } else { + m_deviation = -(this->height()) / 4; + } +#else if (e->delta() > 0 && m_currentIndex <= m_rangeMin) return; if (e->delta() < 0 && m_currentIndex >= m_rangeMax) @@ -145,6 +161,7 @@ void RollingBox::wheelEvent(QWheelEvent *e) } else { m_deviation = -(this->height()) / 4; } +#endif homing(); update(); diff --git a/src/src/switchcamerabtn.cpp b/src/src/switchcamerabtn.cpp index e9da48c8..94ff41b8 100644 --- a/src/src/switchcamerabtn.cpp +++ b/src/src/switchcamerabtn.cpp @@ -24,7 +24,9 @@ void SwitchCameraBtn::paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter painter(this); +#if QT_VERSION_MAJOR <= 5 painter.setRenderHint(QPainter::HighQualityAntialiasing, true); +#endif QPainterPath path; if (nullptr == m_normalSvg @@ -68,7 +70,11 @@ void SwitchCameraBtn::paintEvent(QPaintEvent *event) } } +#if QT_VERSION_MAJOR > 5 +void SwitchCameraBtn::enterEvent(QEnterEvent *event) +#else void SwitchCameraBtn::enterEvent(QEvent *event) +#endif { Q_UNUSED(event); m_bFocus = true; diff --git a/src/src/switchcamerabtn.h b/src/src/switchcamerabtn.h index 5af9e1d4..8508006c 100644 --- a/src/src/switchcamerabtn.h +++ b/src/src/switchcamerabtn.h @@ -20,7 +20,11 @@ class SwitchCameraBtn : public QWidget void clicked(); protected: void paintEvent(QPaintEvent *event) override; +#if QT_VERSION_MAJOR > 5 + void enterEvent(QEnterEvent *event) override; +#else void enterEvent(QEvent *event) override; +#endif void leaveEvent(QEvent *event) override; void mousePressEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; diff --git a/src/src/takephotosettingareawidget.cpp b/src/src/takephotosettingareawidget.cpp index 3297e8b5..9f8f1f0b 100644 --- a/src/src/takephotosettingareawidget.cpp +++ b/src/src/takephotosettingareawidget.cpp @@ -1105,7 +1105,9 @@ void takePhotoSettingAreaWidget::keyEnterClick() void takePhotoSettingAreaWidget::paintEvent(QPaintEvent *event) { QPainter painter(this); +#if QT_VERSION_MAJOR <= 5 painter.setRenderHint(QPainter::HighQualityAntialiasing, true); +#endif int width, height; diff --git a/src/src/videowidget.cpp b/src/src/videowidget.cpp index f3967a19..f7d62f85 100644 --- a/src/src/videowidget.cpp +++ b/src/src/videowidget.cpp @@ -30,8 +30,13 @@ #include #include #include -#include +#if QT_VERSION_MAJOR <= 5 #include +#include +#else +#include +#include +#endif #define COUNTDOWN_WIDTH 32 #define COUNTDOWN_HEIGHT 61 @@ -83,17 +88,31 @@ videowidget::videowidget(DWidget *parent) m_pNormalItem->setZValue(0); m_bActive = false; //是否录制中 +#if QT_VERSION_MAJOR > 5 + m_player = new QMediaPlayer(this); + m_audioOutput = new QAudioOutput(this); + m_player->setAudioOutput(m_audioOutput); + m_player->setSource(QUrl("qrc:/resource/Camera.wav")); +#else m_takePicSound = new QSound(":/resource/Camera.wav"); +#endif m_countTimer = new QTimer(this); m_flashTimer = new QTimer(this); m_recordingTimer = new QTimer(this); m_pNormalView = new QGraphicsViewEx(this); m_gridlinewidget = new GridLineWidget(this); m_gridlinewidget->setGridType(Grid_None); +#if QT_VERSION_MAJOR > 5 + QScreen *screen = QGuiApplication::primaryScreen(); + //获取设备屏幕大小 + QRect screenRect = screen->geometry(); + m_flashLabel = new DLabel(); +#else QDesktopWidget *desktopWidget = QApplication::desktop(); //获取设备屏幕大小 QRect screenRect = desktopWidget->screenGeometry(); m_flashLabel = new DLabel(desktopWidget); +#endif m_flashLabel->setWindowFlags(m_flashLabel->windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); m_flashLabel->move(0, 0); m_flashLabel->setFixedSize(screenRect.width(), screenRect.height()); @@ -170,7 +189,7 @@ videowidget::videowidget(DWidget *parent) //wayland平台设置背景色为黑色 if (get_wayland_status() == true) { QPalette pal(palette()); - pal.setColor(QPalette::Background, Qt::black); + pal.setColor(QPalette::Window, Qt::black); setAutoFillBackground(true); setPalette(pal); } @@ -191,7 +210,7 @@ videowidget::videowidget(DWidget *parent) m_dLabel->setPalette(pltLabel); QPalette pa_cb = m_recordingTime->palette();//不用槽函数,程序打开如果是深色主题,可以正常切换颜色,其他主题不行,DTK的bug? - pa_cb.setColor(QPalette::Background, QColor(255, 0, 0, 30)); + pa_cb.setColor(QPalette::Window, QColor(255, 0, 0, 30)); pa_cb.setColor(QPalette::WindowText, QColor(255, 255, 255)); QFont ft("SourceHanSansSC-Medium"); ft.setWeight(QFont::Medium); @@ -208,7 +227,7 @@ videowidget::videowidget(DWidget *parent) //设置相机背景色为灰色 QColor bgColor(25, 25, 25); QPalette pal(this->palette()); - pal.setColor(QPalette::Background, bgColor); + pal.setColor(QPalette::Window, bgColor); this->setAutoFillBackground(true); this->setPalette(pal); m_pNormalScene->setBackgroundBrush(bgColor); @@ -336,7 +355,7 @@ void videowidget::showNocam() void videowidget::showCamUsed() { - qDebug() << "show camUsed" << endl; + qDebug() << "show camUsed" << Qt::endl; if (!m_pNormalView->isVisible()) m_pNormalView->show(); @@ -654,8 +673,13 @@ void videowidget::showCountdown() if (g_Enum_Camera_State == PICTRUE) { if (m_nInterval == 0 && m_curTakePicTime >= 0) { if (m_flashEnable && 1 == m_nMaxContinuous) { +#if QT_VERSION_MAJOR > 5 + QScreen *screen = QGuiApplication::primaryScreen(); + QRect rt = screen->geometry(); +#else int index = QApplication::desktop()->screenNumber(this); QRect rt = QApplication::desktop()->screenGeometry(index); +#endif m_flashLabel->setGeometry(rt); m_flashLabel->setFixedSize(rt.size()); m_flashLabel->show(); @@ -833,8 +857,13 @@ void videowidget::showRecTime() void videowidget::flash() { - if (get_sound_of_takeing_photo()) + if (get_sound_of_takeing_photo()) { +#if QT_VERSION_MAJOR > 5 + m_player->play(); +#else m_takePicSound->play(); +#endif + } #ifndef __mips__ if (!get_wayland_status()) @@ -952,7 +981,11 @@ void videowidget::onEndBtnClicked() recordBtn->blockSignals(true); #endif +#if QT_VERSION_MAJOR > 5 + QElapsedTimer time; +#else QTime time; +#endif time.start(); int duration = 0; if (getCapStatus()) { //录制完成处理 @@ -1579,17 +1612,22 @@ videowidget::~videowidget() delete m_flashLabel; m_flashLabel = nullptr; - delete m_takePicSound; - m_takePicSound = nullptr; - delete m_pNormalView; m_pNormalView = nullptr; delete m_pNormalScene; m_pNormalScene = nullptr; +#if QT_VERSION_MAJOR > 5 + delete m_player; + m_player = nullptr; + + delete m_audioOutput; + m_audioOutput = nullptr; +#else delete m_takePicSound; m_takePicSound = nullptr; +#endif delete m_pGridLayout; m_pGridLayout = nullptr; diff --git a/src/src/videowidget.h b/src/src/videowidget.h index d769086c..83b7ef42 100644 --- a/src/src/videowidget.h +++ b/src/src/videowidget.h @@ -12,14 +12,21 @@ #include #include #include +#if QT_VERSION_MAJOR <= 5 #include #include -#include #include #include -#include #include +#else +#include +#include +#include +#include +#endif +#include +#include #include #include "LPF_V4L2.h" @@ -43,7 +50,12 @@ class QGridLayout; class QVBoxLayout; class QHBoxLayout; class QSpacerItem; +#if QT_VERSION_MAJOR > 5 +class QMediaPlayer; +class QAudioOutput; +#else class QSound; +#endif class QGraphicsSvgItem; #define FLASH_TIME 500//拍照闪光时间,500毫秒 @@ -440,7 +452,12 @@ private slots: DLabel *m_recordingTime; //录制时长 QString m_videoFormat; //录制视频格式 +#if QT_VERSION_MAJOR > 5 + QMediaPlayer *m_player; + QAudioOutput *m_audioOutput; +#else QSound *m_takePicSound; //拍照声音 +#endif QString m_savePicFolder; //图片文件夹路径 QString m_saveVdFolder; //视频文件夹路径 QTimer *m_countTimer; //倒计时定时器