增加工具条图标

This commit is contained in:
Barry 2018-11-27 22:46:39 +08:00
commit e21b74ac25
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/render/render.pri)
include ($$PWD/android/android.pri) include ($$PWD/android/android.pri)
include ($$PWD/inputcontrol/inputcontrol.pri) include ($$PWD/inputcontrol/inputcontrol.pri)
include ($$PWD/fontawesome/fontawesome.pri)
# 附加包含路径 # 附加包含路径
INCLUDEPATH += \ INCLUDEPATH += \
@ -57,7 +58,8 @@ INCLUDEPATH += \
$$PWD/decoder \ $$PWD/decoder \
$$PWD/render \ $$PWD/render \
$$PWD/android \ $$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> <RCC>
<qresource prefix="/"> <qresource prefix="/">
<file>res/psblack.css</file> <file>res/psblack.css</file>
<file>res/fontawesome-webfont.ttf</file>
</qresource> </qresource>
</RCC> </RCC>

Binary file not shown.

Binary file not shown.

View file

@ -7,6 +7,7 @@
#include "videoform.h" #include "videoform.h"
#include "ui_videoform.h" #include "ui_videoform.h"
#include "iconhelper.h"
VideoForm::VideoForm(const QString& serial, QWidget *parent) : VideoForm::VideoForm(const QString& serial, QWidget *parent) :
QWidget(parent), QWidget(parent),
@ -94,6 +95,7 @@ VideoForm::VideoForm(const QString& serial, QWidget *parent) :
}); });
updateShowSize(size()); updateShowSize(size());
initStyle();
} }
VideoForm::~VideoForm() VideoForm::~VideoForm()
@ -105,6 +107,12 @@ VideoForm::~VideoForm()
delete ui; 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) void VideoForm::updateShowSize(const QSize &newSize)
{ {
if (frameSize != newSize) { if (frameSize != newSize) {
@ -123,15 +131,18 @@ void VideoForm::updateShowSize(const QSize &newSize)
showSize.setHeight(showSize.width()/2); showSize.setHeight(showSize.width()/2);
} }
// 窗口居中 if (isFullScreen()) {
switchFullScreen();
}
// 窗口居中
move(screenRect.center() - QRect(0, 0, showSize.width(), showSize.height()).center()); move(screenRect.center() - QRect(0, 0, showSize.width(), showSize.height()).center());
} }
int titleBarHeight = style()->pixelMetric(QStyle::PM_TitleBarHeight); int titleBarHeight = style()->pixelMetric(QStyle::PM_TitleBarHeight);
// 减去标题栏高度 // 减去标题栏高度
showSize.setHeight(showSize.height() - titleBarHeight); showSize.setHeight(showSize.height() - titleBarHeight);
if (showSize != size()) { if (showSize != size()) {
resize(showSize); resize(showSize);
} }
} }
} }
@ -149,22 +160,22 @@ void VideoForm::switchFullScreen()
void VideoForm::mousePressEvent(QMouseEvent *event) 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) 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) 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) 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(); switchFullScreen();
} }
//qDebug() << "keyPressEvent" << event->isAutoRepeat(); //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) void VideoForm::keyReleaseEvent(QKeyEvent *event)
{ {
//qDebug() << "keyReleaseEvent" << event->isAutoRepeat(); //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() void VideoForm::on_fullScrcenbtn_clicked()
{ {
switchFullScreen(); switchFullScreen();
} }
void VideoForm::on_returnBtn_clicked()
{
}

View file

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

View file

@ -36,21 +36,39 @@
<widget class="QWidget" name="rightToolWidget" native="true"> <widget class="QWidget" name="rightToolWidget" native="true">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>40</width> <width>60</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>40</width> <width>60</width>
<height>16777215</height> <height>16777215</height>
</size> </size>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <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"> <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"> <property name="text">
<string>F</string> <string/>
</property> </property>
</widget> </widget>
</item> </item>
@ -67,6 +85,25 @@
</property> </property>
</spacer> </spacer>
</item> </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> </layout>
</widget> </widget>
</item> </item>