diff --git a/client/qt_gl_/yuvgl/components/toast.cpp b/client/qt_gl_/yuvgl/components/toast.cpp new file mode 100644 index 0000000..1db4342 --- /dev/null +++ b/client/qt_gl_/yuvgl/components/toast.cpp @@ -0,0 +1,82 @@ +#include "toast.h" +#include +#include +#include +#include +#include + +ToastWidget::ToastWidget(QWidget *parent) + : QWidget(parent) +{ + ui.setupUi(this); + + setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::Tool);// 无边框 无任务栏 + setAttribute(Qt::WA_TranslucentBackground, true); // 背景透明 +} + +ToastWidget::~ToastWidget() +{ + +} + + +void ToastWidget::setText(const QString& text) +{ + ui.label->setText(text); +} + +void ToastWidget::showAnimation(int timeout /*= 2000*/) +{ + // 开始动画 + QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity"); + animation->setDuration(1000); + animation->setStartValue(0); + animation->setEndValue(1); + animation->start(); + show(); + + QTimer::singleShot(timeout, [&] + { + // 结束动画 + QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity"); + animation->setDuration(1000); + animation->setStartValue(1); + animation->setEndValue(0); + animation->start(); + connect(animation, &QPropertyAnimation::finished, [&] + { + close(); + deleteLater();// 关闭后析构 + }); + }); +} + +void ToastWidget::showTip(const QString& text, QWidget* parent /*= nullptr*/) +{ + ToastWidget* toast = new ToastWidget(parent); + toast->setWindowFlags(toast->windowFlags() | Qt::WindowStaysOnTopHint); // 置顶 + toast->setText(text); + toast->setStyleSheet("font:bold;font-size:34px;color:rgb(255,255,255);"); + toast->adjustSize(); //设置完文本后调整下大小 + + // 测试显示位于主屏的70%高度位置 + QScreen* pScreen = QGuiApplication::primaryScreen(); + toast->move((pScreen->size().width() - toast->width()) / 2, + pScreen->size().height() * 5 / 10); + toast->showAnimation(1000); +} + +void ToastWidget::paintEvent(QPaintEvent *event) +{ + QPainter paint(this); + paint.begin(this); + auto kBackgroundColor = QColor(255, 255, 255); + kBackgroundColor.setAlpha(0.0 * 255);// 透明度为0 + paint.setRenderHint(QPainter::Antialiasing, true); + paint.setPen(Qt::NoPen); + paint.setBrush(QBrush(kBackgroundColor, Qt::SolidPattern));//设置画刷形式 + paint.drawRect(0, 0, width(), height()); + paint.end(); +} + + diff --git a/client/qt_gl_/yuvgl/components/toast.h b/client/qt_gl_/yuvgl/components/toast.h new file mode 100644 index 0000000..fcfb9f9 --- /dev/null +++ b/client/qt_gl_/yuvgl/components/toast.h @@ -0,0 +1,35 @@ +/** @file Toast.h + * @brief Qt模拟安卓移动客户端Toast提示消息 + * @note qss set in ui file + * @author lesliefish + * @date 2019/05/31 + */ +#ifndef __TOAST__ +#define __TOAST__ +#include +#include "ui_toast.h" + +class ToastWidget : public QWidget +{ + Q_OBJECT + +public: + ToastWidget(QWidget *parent = Q_NULLPTR); + ~ToastWidget(); + + void setText(const QString& text); + + void showAnimation(int timeout = 2000);// 动画方式show出,默认2秒后消失 + +public: + // 静态调用 + static void showTip(const QString& text, QWidget* parent = nullptr); + +protected: + virtual void paintEvent(QPaintEvent *event); + +private: + Ui::Form ui; +}; + +#endif diff --git a/client/qt_gl_/yuvgl/components/toast.ui b/client/qt_gl_/yuvgl/components/toast.ui new file mode 100644 index 0000000..ba97c7d --- /dev/null +++ b/client/qt_gl_/yuvgl/components/toast.ui @@ -0,0 +1,32 @@ + + + Form + + + + 0 + 0 + 431 + 59 + + + + Form + + + + + 170 + 10 + 231 + 31 + + + + TextLabel + + + + + + diff --git a/client/qt_gl_/yuvgl/inc/utils.h b/client/qt_gl_/yuvgl/inc/utils.h index dc34076..d6b42ba 100644 --- a/client/qt_gl_/yuvgl/inc/utils.h +++ b/client/qt_gl_/yuvgl/inc/utils.h @@ -1,5 +1,21 @@ #pragma once #include #include +#include "guiddef.h" +#include +#include +#include "qedit.h" +extern "C" +{ +#include "libavcodec/avcodec.h" +#include "libavformat/avformat.h" +#include "libavutil/avutil.h" +#include "libswscale/swscale.h" +#include "libavutil/opt.h" +#include "libavutil/imgutils.h" +}; + using namespace std; + +AVPixelFormat GUIDToAvFormat(GUID mediatype); diff --git a/client/qt_gl_/yuvgl/mainwindow.cpp b/client/qt_gl_/yuvgl/mainwindow.cpp index c9be8f6..7c6e46b 100644 --- a/client/qt_gl_/yuvgl/mainwindow.cpp +++ b/client/qt_gl_/yuvgl/mainwindow.cpp @@ -5,7 +5,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), m_bCameraOpen(false), - mCamera(nullptr) + mCamera(nullptr), + m_bRtmpPushing(false) { ui->setupUi(this); std::vector cameras = Camera::EnumAllCamera(); @@ -22,6 +23,7 @@ MainWindow::~MainWindow(){ void MainWindow::on_pushButton_clicked(){ if(nullptr == mPlayerWidget){ mPlayerWidget = new CPlayWidget(nullptr); + //mVideoCoder = new VideoCoder(mCamera->GetWidth(),mCamera->GetHeight(),); } if(!m_bCameraOpen){ mPlayerWidget->SetDataType(CPlayWidget::IMG_TYPE::TYPE_RGB32); @@ -44,3 +46,12 @@ void MainWindow::on_pushButton_clicked(){ ui->pushButton->setText("打开摄像头"); } } + +void MainWindow::on_pushButton_2_clicked() +{ + if(!m_bRtmpPushing){ + if(!m_bCameraOpen){ + ToastWidget::showTip("请打开摄像头",this); + } + } +} diff --git a/client/qt_gl_/yuvgl/mainwindow.h b/client/qt_gl_/yuvgl/mainwindow.h index 86a9b40..1099130 100644 --- a/client/qt_gl_/yuvgl/mainwindow.h +++ b/client/qt_gl_/yuvgl/mainwindow.h @@ -4,6 +4,9 @@ #include #include "media/CameraCapture.h" #include "cplaywidget.h" +#include "media/VideoCoder.h" +#include "media/RtmpPuser.h" +#include "components/toast.h" namespace Ui { class MainWindow; @@ -20,12 +23,17 @@ public: private slots: void on_pushButton_clicked(); + void on_pushButton_2_clicked(); + private: Ui::MainWindow *ui; Camera *mCamera; QStringList mCameraList; bool m_bCameraOpen; CPlayWidget *mPlayerWidget; + VideoCoder *mVideoCoder; + bool m_bRtmpPushing; + }; #endif // MAINWINDOW_H diff --git a/client/qt_gl_/yuvgl/utils/utils.cpp b/client/qt_gl_/yuvgl/utils/utils.cpp index cb5c4fd..b577c78 100644 --- a/client/qt_gl_/yuvgl/utils/utils.cpp +++ b/client/qt_gl_/yuvgl/utils/utils.cpp @@ -15,3 +15,10 @@ wstring char2wchar(const char* cchar) return wstring(L""); } + +AVPixelFormat GUIDToAvFormat(GUID mediatype){ + if(IsEqualIID(MEDIASUBTYPE_RGB32,mediatype)){ + return AV_PIX_FMT_BGRA; + } + return AV_PIX_FMT_NONE; +}