增加工具条图标

This commit is contained in:
Barry 2018-11-27 22:46:39 +08:00
commit dee95e35da
10 changed files with 139 additions and 14 deletions

View file

@ -47,6 +47,7 @@ include ($$PWD/decoder/decoder.pri)
include ($$PWD/render/render.pri)
include ($$PWD/android/android.pri)
include ($$PWD/inputcontrol/inputcontrol.pri)
include ($$PWD/fontawesome/fontawesome.pri)
# 附加包含路径
INCLUDEPATH += \
@ -57,7 +58,8 @@ INCLUDEPATH += \
$$PWD/decoder \
$$PWD/render \
$$PWD/android \
$$PWD/inputcontrol
$$PWD/inputcontrol \
$$PWD/fontawesome
# ***********************************************************

View file

@ -0,0 +1,5 @@
HEADERS += \
$$PWD/iconhelper.h
SOURCES += \
$$PWD/iconhelper.cpp

View file

@ -0,0 +1,24 @@
#include "iconhelper.h"
IconHelper* IconHelper::_instance = 0;
IconHelper::IconHelper(QObject*):
QObject(qApp)
{
int fontId = QFontDatabase::addApplicationFont(":/res/fontawesome-webfont.ttf");
QString fontName = QFontDatabase::applicationFontFamilies(fontId).at(0);
iconFont = QFont(fontName);
}
void IconHelper::SetIcon(QLabel* lab, QChar c, int size)
{
iconFont.setPointSize(size);
lab->setFont(iconFont);
lab->setText(c);
}
void IconHelper::SetIcon(QPushButton* btn, QChar c, int size)
{
iconFont.setPointSize(size);
btn->setFont(iconFont);
btn->setText(c);
}

View file

@ -0,0 +1,37 @@
#ifndef ICONHELPER_H
#define ICONHELPER_H
#include <QObject>
#include <QFont>
#include <QFontDatabase>
#include <QMutex>
#include <QLabel>
#include <QPushButton>
#include <QApplication>
class IconHelper : public QObject
{
private:
explicit IconHelper(QObject *parent = 0);
QFont iconFont;
static IconHelper* _instance;
public:
static IconHelper* Instance()
{
static QMutex mutex;
if (!_instance) {
QMutexLocker locker(&mutex);
if (!_instance) {
_instance = new IconHelper;
}
}
return _instance;
}
void SetIcon(QLabel* lab, QChar c, int size = 10);
void SetIcon(QPushButton* btn, QChar c, int size = 10);
};
#endif // ICONHELPER_H

View file

@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/">
<file>res/psblack.css</file>
<file>res/fontawesome-webfont.ttf</file>
</qresource>
</RCC>

Binary file not shown.

Binary file not shown.

View file

@ -7,6 +7,7 @@
#include "videoform.h"
#include "ui_videoform.h"
#include "iconhelper.h"
VideoForm::VideoForm(const QString& serial, QWidget *parent) :
QWidget(parent),
@ -94,6 +95,7 @@ VideoForm::VideoForm(const QString& serial, QWidget *parent) :
});
updateShowSize(size());
initStyle();
}
VideoForm::~VideoForm()
@ -105,6 +107,12 @@ VideoForm::~VideoForm()
delete ui;
}
void VideoForm::initStyle()
{
IconHelper::Instance()->SetIcon(ui->fullScrcenbtn, QChar(0xf0b2), 13);
IconHelper::Instance()->SetIcon(ui->returnBtn, QChar(0xf104), 15);
}
void VideoForm::updateShowSize(const QSize &newSize)
{
if (frameSize != newSize) {
@ -123,15 +131,18 @@ void VideoForm::updateShowSize(const QSize &newSize)
showSize.setHeight(showSize.width()/2);
}
// 窗口居中
if (isFullScreen()) {
switchFullScreen();
}
// 窗口居中
move(screenRect.center() - QRect(0, 0, showSize.width(), showSize.height()).center());
}
int titleBarHeight = style()->pixelMetric(QStyle::PM_TitleBarHeight);
// 减去标题栏高度
showSize.setHeight(showSize.height() - titleBarHeight);
if (showSize != size()) {
resize(showSize);
if (showSize != size()) {
resize(showSize);
}
}
}
@ -149,22 +160,22 @@ void VideoForm::switchFullScreen()
void VideoForm::mousePressEvent(QMouseEvent *event)
{
m_inputConvert.mouseEvent(event, ui->videoWidget->frameSize(), size());
m_inputConvert.mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size());
}
void VideoForm::mouseReleaseEvent(QMouseEvent *event)
{
m_inputConvert.mouseEvent(event, ui->videoWidget->frameSize(), size());
m_inputConvert.mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size());
}
void VideoForm::mouseMoveEvent(QMouseEvent *event)
{
m_inputConvert.mouseEvent(event, ui->videoWidget->frameSize(), size());
m_inputConvert.mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size());
}
void VideoForm::wheelEvent(QWheelEvent *event)
{
m_inputConvert.wheelEvent(event, ui->videoWidget->frameSize(), size());
m_inputConvert.wheelEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size());
}
@ -176,16 +187,21 @@ void VideoForm::keyPressEvent(QKeyEvent *event)
switchFullScreen();
}
//qDebug() << "keyPressEvent" << event->isAutoRepeat();
m_inputConvert.keyEvent(event, ui->videoWidget->frameSize(), size());
m_inputConvert.keyEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size());
}
void VideoForm::keyReleaseEvent(QKeyEvent *event)
{
//qDebug() << "keyReleaseEvent" << event->isAutoRepeat();
m_inputConvert.keyEvent(event, ui->videoWidget->frameSize(), size());
m_inputConvert.keyEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size());
}
void VideoForm::on_fullScrcenbtn_clicked()
{
switchFullScreen();
}
void VideoForm::on_returnBtn_clicked()
{
}

View file

@ -24,6 +24,7 @@ public:
private:
void updateShowSize(const QSize &newSize);
void switchFullScreen();
void initStyle();
protected:
void mousePressEvent(QMouseEvent *event);
@ -36,6 +37,8 @@ protected:
private slots:
void on_fullScrcenbtn_clicked();
void on_returnBtn_clicked();
private:
Ui::videoForm *ui;
QSize frameSize;

View file

@ -36,21 +36,39 @@
<widget class="QWidget" name="rightToolWidget" native="true">
<property name="minimumSize">
<size>
<width>40</width>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<width>60</width>
<height>16777215</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<property name="leftMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item alignment="Qt::AlignHCenter">
<widget class="QPushButton" name="fullScrcenbtn">
<property name="minimumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>F</string>
<string/>
</property>
</widget>
</item>
@ -67,6 +85,25 @@
</property>
</spacer>
</item>
<item alignment="Qt::AlignHCenter">
<widget class="QPushButton" name="returnBtn">
<property name="minimumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>