完善业务功能

master
DESKTOP-4RNDQIC\29019 2020-06-05 10:18:37 +08:00
parent 57806179f1
commit b385c4dd8b
7 changed files with 192 additions and 1 deletions

View File

@ -0,0 +1,82 @@
#include "toast.h"
#include <QPropertyAnimation>
#include <QScreen>
#include <QGuiApplication>
#include <QPainter>
#include <QTimer>
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();
}

View File

@ -0,0 +1,35 @@
/** @file Toast.h
* @brief QtToast
* @note qss set in ui file
* @author lesliefish
* @date 2019/05/31
*/
#ifndef __TOAST__
#define __TOAST__
#include <QWidget>
#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

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>431</width>
<height>59</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>170</x>
<y>10</y>
<width>231</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -1,5 +1,21 @@
#pragma once
#include <string>
#include <memory>
#include "guiddef.h"
#include <dshow.h>
#include <windows.h>
#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);

View File

@ -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<std::wstring> 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);
}
}
}

View File

@ -4,6 +4,9 @@
#include <QMainWindow>
#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

View File

@ -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;
}