新增部分demo
|
@ -11,3 +11,5 @@
|
|||
7. nettool 网络调试助手
|
||||
8. devicesizetable 硬盘容量控件
|
||||
9. styledemo qss 高仿PS黑色+扁平白色+淡蓝色风格主题
|
||||
10. navbutton 导航按钮控件
|
||||
11. video_splite 视频监控画面分割demo
|
||||
|
|
|
@ -0,0 +1,367 @@
|
|||
#pragma execution_character_set("utf-8")
|
||||
|
||||
#include "frmnavbutton.h"
|
||||
#include "ui_frmnavbutton.h"
|
||||
#include "navbutton.h"
|
||||
#include "iconhelper.h"
|
||||
#include "qdebug.h"
|
||||
|
||||
frmNavButton::frmNavButton(QWidget *parent) : QWidget(parent), ui(new Ui::frmNavButton)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->initForm();
|
||||
}
|
||||
|
||||
frmNavButton::~frmNavButton()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void frmNavButton::initForm()
|
||||
{
|
||||
quint32 size = 15;
|
||||
quint32 pixWidth = 15;
|
||||
quint32 pixHeight = 15;
|
||||
|
||||
//从图形字体获得图片,也可以从资源文件或者路径文件获取
|
||||
QChar icon = 0xf061;
|
||||
QPixmap iconNormal = IconHelper::Instance()->getPixmap(QColor(100, 100, 100).name(), icon, size, pixWidth, pixHeight);
|
||||
QPixmap iconHover = IconHelper::Instance()->getPixmap(QColor(255, 255, 255).name(), icon, size, pixWidth, pixHeight);
|
||||
QPixmap iconCheck = IconHelper::Instance()->getPixmap(QColor(255, 255, 255).name(), icon, size, pixWidth, pixHeight);
|
||||
|
||||
btns1 << ui->navButton11 << ui->navButton12 << ui->navButton13 << ui->navButton14;
|
||||
for (int i = 0; i < btns1.count(); i++) {
|
||||
NavButton *btn = btns1.at(i);
|
||||
btn->setPaddingLeft(32);
|
||||
btn->setLineSpace(6);
|
||||
|
||||
btn->setShowIcon(true);
|
||||
btn->setIconSpace(15);
|
||||
btn->setIconSize(QSize(10, 10));
|
||||
btn->setIconNormal(iconNormal);
|
||||
btn->setIconHover(iconHover);
|
||||
btn->setIconCheck(iconCheck);
|
||||
|
||||
connect(btn, SIGNAL(clicked(bool)), this, SLOT(buttonClick1()));
|
||||
}
|
||||
|
||||
size = 15;
|
||||
pixWidth = 20;
|
||||
pixHeight = 20;
|
||||
|
||||
QList<QChar> pixChar;
|
||||
pixChar << 0xf17b << 0xf002 << 0xf013 << 0xf021 << 0xf0e0 << 0xf135;
|
||||
QColor normalBgColor = QColor("#2D9191");
|
||||
QColor hoverBgColor = QColor("#187294");
|
||||
QColor checkBgColor = QColor("#145C75");
|
||||
QColor normalTextColor = QColor("#FFFFFF");
|
||||
QColor hoverTextColor = QColor("#FFFFFF");
|
||||
QColor checkTextColor = QColor("#FFFFFF");
|
||||
|
||||
btns2 << ui->navButton21 << ui->navButton22 << ui->navButton23 << ui->navButton24;
|
||||
for (int i = 0; i < btns2.count(); i++) {
|
||||
NavButton *btn = btns2.at(i);
|
||||
btn->setPaddingLeft(35);
|
||||
btn->setLineSpace(0);
|
||||
btn->setLineWidth(8);
|
||||
btn->setLineColor(QColor(255, 107, 107));
|
||||
btn->setShowTriangle(true);
|
||||
|
||||
btn->setShowIcon(true);
|
||||
btn->setIconSpace(10);
|
||||
btn->setIconSize(QSize(22, 22));
|
||||
|
||||
//分开设置图标
|
||||
QChar icon = pixChar.at(i);
|
||||
QPixmap iconNormal = IconHelper::Instance()->getPixmap(normalTextColor.name(), icon, size, pixWidth, pixHeight);
|
||||
QPixmap iconHover = IconHelper::Instance()->getPixmap(hoverTextColor.name(), icon, size, pixWidth, pixHeight);
|
||||
QPixmap iconCheck = IconHelper::Instance()->getPixmap(checkTextColor.name(), icon, size, pixWidth, pixHeight);
|
||||
|
||||
btn->setIconNormal(iconNormal);
|
||||
btn->setIconHover(iconHover);
|
||||
btn->setIconCheck(iconCheck);
|
||||
|
||||
btn->setNormalBgColor(normalBgColor);
|
||||
btn->setHoverBgColor(hoverBgColor);
|
||||
btn->setCheckBgColor(checkBgColor);
|
||||
btn->setNormalTextColor(normalTextColor);
|
||||
btn->setHoverTextColor(hoverTextColor);
|
||||
btn->setCheckTextColor(checkTextColor);
|
||||
|
||||
connect(btn, SIGNAL(clicked(bool)), this, SLOT(buttonClick2()));
|
||||
}
|
||||
|
||||
normalBgColor = QColor("#292F38");
|
||||
hoverBgColor = QColor("#1D2025");
|
||||
checkBgColor = QColor("#1D2025");
|
||||
normalTextColor = QColor("#54626F");
|
||||
hoverTextColor = QColor("#FDFDFD");
|
||||
checkTextColor = QColor("#FDFDFD");
|
||||
|
||||
btns3 << ui->navButton31 << ui->navButton32 << ui->navButton33 << ui->navButton34;
|
||||
for (int i = 0; i < btns3.count(); i++) {
|
||||
NavButton *btn = btns3.at(i);
|
||||
btn->setPaddingLeft(35);
|
||||
btn->setLineWidth(10);
|
||||
btn->setLineColor(QColor("#029FEA"));
|
||||
btn->setShowTriangle(true);
|
||||
btn->setTextAlign(NavButton::TextAlign_Left);
|
||||
btn->setTrianglePosition(NavButton::TrianglePosition_Left);
|
||||
btn->setLinePosition(NavButton::LinePosition_Right);
|
||||
|
||||
btn->setShowIcon(true);
|
||||
btn->setIconSpace(10);
|
||||
btn->setIconSize(QSize(22, 22));
|
||||
|
||||
//分开设置图标
|
||||
QChar icon = pixChar.at(i);
|
||||
QPixmap iconNormal = IconHelper::Instance()->getPixmap(normalTextColor.name(), icon, size, pixWidth, pixHeight);
|
||||
QPixmap iconHover = IconHelper::Instance()->getPixmap(hoverTextColor.name(), icon, size, pixWidth, pixHeight);
|
||||
QPixmap iconCheck = IconHelper::Instance()->getPixmap(checkTextColor.name(), icon, size, pixWidth, pixHeight);
|
||||
|
||||
btn->setIconNormal(iconNormal);
|
||||
btn->setIconHover(iconHover);
|
||||
btn->setIconCheck(iconCheck);
|
||||
|
||||
btn->setNormalBgColor(normalBgColor);
|
||||
btn->setHoverBgColor(hoverBgColor);
|
||||
btn->setCheckBgColor(checkBgColor);
|
||||
btn->setNormalTextColor(normalTextColor);
|
||||
btn->setHoverTextColor(hoverTextColor);
|
||||
btn->setCheckTextColor(checkTextColor);
|
||||
|
||||
connect(btn, SIGNAL(clicked(bool)), this, SLOT(buttonClick3()));
|
||||
}
|
||||
|
||||
size = 15;
|
||||
pixWidth = 15;
|
||||
pixHeight = 15;
|
||||
|
||||
icon = 0xf105;
|
||||
iconNormal = IconHelper::Instance()->getPixmap(QColor(100, 100, 100).name(), icon, size, pixWidth, pixHeight);
|
||||
iconHover = IconHelper::Instance()->getPixmap(QColor(255, 255, 255).name(), icon, size, pixWidth, pixHeight);
|
||||
iconCheck = IconHelper::Instance()->getPixmap(QColor(255, 255, 255).name(), icon, size, pixWidth, pixHeight);
|
||||
|
||||
btns4 << ui->navButton41 << ui->navButton42 << ui->navButton43 << ui->navButton44;
|
||||
for (int i = 0; i < btns4.count(); i++) {
|
||||
NavButton *btn = btns4.at(i);
|
||||
btn->setLineSpace(10);
|
||||
btn->setLineWidth(10);
|
||||
btn->setPaddingRight(25);
|
||||
btn->setShowTriangle(true);
|
||||
btn->setTextAlign(NavButton::TextAlign_Right);
|
||||
btn->setTrianglePosition(NavButton::TrianglePosition_Left);
|
||||
btn->setLinePosition(NavButton::LinePosition_Right);
|
||||
|
||||
btn->setShowIcon(true);
|
||||
btn->setIconSpace(25);
|
||||
btn->setIconSize(QSize(15, 15));
|
||||
btn->setIconNormal(iconNormal);
|
||||
btn->setIconHover(iconHover);
|
||||
btn->setIconCheck(iconCheck);
|
||||
|
||||
connect(btn, SIGNAL(clicked(bool)), this, SLOT(buttonClick4()));
|
||||
}
|
||||
|
||||
size = 15;
|
||||
pixWidth = 20;
|
||||
pixHeight = 20;
|
||||
|
||||
QFont font;
|
||||
font.setPixelSize(15);
|
||||
font.setBold(true);
|
||||
|
||||
normalBgColor = QColor("#292929");
|
||||
hoverBgColor = QColor("#064077");
|
||||
checkBgColor = QColor("#10689A");
|
||||
normalTextColor = QColor("#FFFFFF");
|
||||
hoverTextColor = Qt::yellow;
|
||||
checkTextColor = QColor("#FFFFFF");
|
||||
|
||||
btns5 << ui->navButton51 << ui->navButton52 << ui->navButton53 << ui->navButton54 << ui->navButton55;
|
||||
for (int i = 0; i < btns5.count(); i++) {
|
||||
NavButton *btn = btns5.at(i);
|
||||
btn->setFont(font);
|
||||
btn->setPaddingLeft(20);
|
||||
btn->setShowLine(false);
|
||||
btn->setTextAlign(NavButton::TextAlign_Center);
|
||||
btn->setLinePosition(NavButton::LinePosition_Bottom);
|
||||
|
||||
btn->setShowIcon(true);
|
||||
btn->setIconSpace(15);
|
||||
btn->setIconSize(QSize(22, 22));
|
||||
|
||||
//分开设置图标
|
||||
QChar icon = pixChar.at(i);
|
||||
QPixmap iconNormal = IconHelper::Instance()->getPixmap(normalTextColor.name(), icon, size, pixWidth, pixHeight);
|
||||
QPixmap iconHover = IconHelper::Instance()->getPixmap(hoverTextColor.name(), icon, size, pixWidth, pixHeight);
|
||||
QPixmap iconCheck = IconHelper::Instance()->getPixmap(checkTextColor.name(), icon, size, pixWidth, pixHeight);
|
||||
|
||||
btn->setIconNormal(iconNormal);
|
||||
btn->setIconHover(iconHover);
|
||||
btn->setIconCheck(iconCheck);
|
||||
|
||||
btn->setNormalBgColor(normalBgColor);
|
||||
btn->setHoverBgColor(hoverBgColor);
|
||||
btn->setCheckBgColor(checkBgColor);
|
||||
btn->setNormalTextColor(normalTextColor);
|
||||
btn->setHoverTextColor(hoverTextColor);
|
||||
btn->setCheckTextColor(checkTextColor);
|
||||
|
||||
connect(btn, SIGNAL(clicked(bool)), this, SLOT(buttonClick5()));
|
||||
}
|
||||
|
||||
normalBgColor = QColor("#E6393D");
|
||||
hoverBgColor = QColor("#EE0000");
|
||||
checkBgColor = QColor("#A40001");
|
||||
normalTextColor = QColor("#FFFFFF");
|
||||
hoverTextColor = QColor("#FFFFFF");
|
||||
checkTextColor = QColor("#FFFFFF");
|
||||
|
||||
btns6 << ui->navButton61 << ui->navButton62 << ui->navButton63 << ui->navButton64 << ui->navButton65;
|
||||
for (int i = 0; i < btns6.count(); i++) {
|
||||
NavButton *btn = btns6.at(i);
|
||||
btn->setFont(font);
|
||||
btn->setPaddingLeft(20);
|
||||
btn->setShowLine(false);
|
||||
btn->setTextAlign(NavButton::TextAlign_Center);
|
||||
btn->setLinePosition(NavButton::LinePosition_Bottom);
|
||||
|
||||
btn->setShowIcon(true);
|
||||
btn->setIconSpace(15);
|
||||
btn->setIconSize(QSize(22, 22));
|
||||
|
||||
//分开设置图标
|
||||
QChar icon = pixChar.at(i);
|
||||
QPixmap iconNormal = IconHelper::Instance()->getPixmap(normalTextColor.name(), icon, size, pixWidth, pixHeight);
|
||||
QPixmap iconHover = IconHelper::Instance()->getPixmap(hoverTextColor.name(), icon, size, pixWidth, pixHeight);
|
||||
QPixmap iconCheck = IconHelper::Instance()->getPixmap(checkTextColor.name(), icon, size, pixWidth, pixHeight);
|
||||
|
||||
btn->setIconNormal(iconNormal);
|
||||
btn->setIconHover(iconHover);
|
||||
btn->setIconCheck(iconCheck);
|
||||
|
||||
btn->setNormalBgColor(normalBgColor);
|
||||
btn->setHoverBgColor(hoverBgColor);
|
||||
btn->setCheckBgColor(checkBgColor);
|
||||
btn->setNormalTextColor(normalTextColor);
|
||||
btn->setHoverTextColor(hoverTextColor);
|
||||
btn->setCheckTextColor(checkTextColor);
|
||||
|
||||
connect(btn, SIGNAL(clicked(bool)), this, SLOT(buttonClick6()));
|
||||
}
|
||||
|
||||
//设置背景色为画刷
|
||||
QLinearGradient normalBgBrush(0, 0, 0, ui->navButton61->height());
|
||||
normalBgBrush.setColorAt(0.0, QColor("#3985BF"));
|
||||
normalBgBrush.setColorAt(0.5, QColor("#2972A9"));
|
||||
normalBgBrush.setColorAt(1.0, QColor("#1C6496"));
|
||||
|
||||
QLinearGradient hoverBgBrush(0, 0, 0, ui->navButton61->height());
|
||||
hoverBgBrush.setColorAt(0.0, QColor("#4897D1"));
|
||||
hoverBgBrush.setColorAt(0.5, QColor("#3283BC"));
|
||||
hoverBgBrush.setColorAt(1.0, QColor("#3088C3"));
|
||||
|
||||
btns7 << ui->navButton71 << ui->navButton72 << ui->navButton73 << ui->navButton74 << ui->navButton75 << ui->navButton76;
|
||||
for (int i = 0; i < btns7.count(); i++) {
|
||||
NavButton *btn = btns7.at(i);
|
||||
btn->setFont(font);
|
||||
btn->setPaddingLeft(0);
|
||||
btn->setLineSpace(0);
|
||||
btn->setShowTriangle(true);
|
||||
btn->setTextAlign(NavButton::TextAlign_Center);
|
||||
btn->setTrianglePosition(NavButton::TrianglePosition_Bottom);
|
||||
btn->setLinePosition(NavButton::LinePosition_Top);
|
||||
|
||||
btn->setNormalTextColor(normalTextColor);
|
||||
btn->setHoverTextColor(hoverTextColor);
|
||||
btn->setCheckTextColor(checkTextColor);
|
||||
|
||||
btn->setNormalBgBrush(normalBgBrush);
|
||||
btn->setHoverBgBrush(hoverBgBrush);
|
||||
btn->setCheckBgBrush(hoverBgBrush);
|
||||
|
||||
connect(btn, SIGNAL(clicked(bool)), this, SLOT(buttonClick7()));
|
||||
}
|
||||
|
||||
ui->navButton11->setChecked(true);
|
||||
ui->navButton23->setChecked(true);
|
||||
ui->navButton31->setChecked(true);
|
||||
ui->navButton44->setChecked(true);
|
||||
ui->navButton53->setChecked(true);
|
||||
ui->navButton61->setChecked(true);
|
||||
ui->navButton75->setChecked(true);
|
||||
|
||||
//设置整体圆角
|
||||
ui->widgetNav5->setStyleSheet(".QWidget{background:#292929;border:1px solid #292929;border-radius:20px;}");
|
||||
}
|
||||
|
||||
void frmNavButton::buttonClick1()
|
||||
{
|
||||
NavButton *b = (NavButton *)sender();
|
||||
qDebug() << "当前按下" << b->text();
|
||||
for (int i = 0; i < btns1.count(); i++) {
|
||||
NavButton *btn = btns1.at(i);
|
||||
btn->setChecked(b == btn);
|
||||
}
|
||||
}
|
||||
|
||||
void frmNavButton::buttonClick2()
|
||||
{
|
||||
NavButton *b = (NavButton *)sender();
|
||||
qDebug() << "当前按下" << b->text();
|
||||
for (int i = 0; i < btns2.count(); i++) {
|
||||
NavButton *btn = btns2.at(i);
|
||||
btn->setChecked(b == btn);
|
||||
}
|
||||
}
|
||||
|
||||
void frmNavButton::buttonClick3()
|
||||
{
|
||||
NavButton *b = (NavButton *)sender();
|
||||
qDebug() << "当前按下" << b->text();
|
||||
for (int i = 0; i < btns3.count(); i++) {
|
||||
NavButton *btn = btns3.at(i);
|
||||
btn->setChecked(b == btn);
|
||||
}
|
||||
}
|
||||
|
||||
void frmNavButton::buttonClick4()
|
||||
{
|
||||
NavButton *b = (NavButton *)sender();
|
||||
qDebug() << "当前按下" << b->text();
|
||||
for (int i = 0; i < btns4.count(); i++) {
|
||||
NavButton *btn = btns4.at(i);
|
||||
btn->setChecked(b == btn);
|
||||
}
|
||||
}
|
||||
|
||||
void frmNavButton::buttonClick5()
|
||||
{
|
||||
NavButton *b = (NavButton *)sender();
|
||||
qDebug() << "当前按下" << b->text();
|
||||
for (int i = 0; i < btns5.count(); i++) {
|
||||
NavButton *btn = btns5.at(i);
|
||||
btn->setChecked(b == btn);
|
||||
}
|
||||
}
|
||||
|
||||
void frmNavButton::buttonClick6()
|
||||
{
|
||||
NavButton *b = (NavButton *)sender();
|
||||
qDebug() << "当前按下" << b->text();
|
||||
for (int i = 0; i < btns6.count(); i++) {
|
||||
NavButton *btn = btns6.at(i);
|
||||
btn->setChecked(b == btn);
|
||||
}
|
||||
}
|
||||
|
||||
void frmNavButton::buttonClick7()
|
||||
{
|
||||
NavButton *b = (NavButton *)sender();
|
||||
qDebug() << "当前按下" << b->text();
|
||||
for (int i = 0; i < btns7.count(); i++) {
|
||||
NavButton *btn = btns7.at(i);
|
||||
btn->setChecked(b == btn);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef FRMNAVBUTTON_H
|
||||
#define FRMNAVBUTTON_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class NavButton;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class frmNavButton;
|
||||
}
|
||||
|
||||
class frmNavButton : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit frmNavButton(QWidget *parent = 0);
|
||||
~frmNavButton();
|
||||
|
||||
private:
|
||||
Ui::frmNavButton *ui;
|
||||
QList<NavButton *> btns1;
|
||||
QList<NavButton *> btns2;
|
||||
QList<NavButton *> btns3;
|
||||
QList<NavButton *> btns4;
|
||||
QList<NavButton *> btns5;
|
||||
QList<NavButton *> btns6;
|
||||
QList<NavButton *> btns7;
|
||||
|
||||
private slots:
|
||||
void initForm();
|
||||
void buttonClick1();
|
||||
void buttonClick2();
|
||||
void buttonClick3();
|
||||
void buttonClick4();
|
||||
void buttonClick5();
|
||||
void buttonClick6();
|
||||
void buttonClick7();
|
||||
};
|
||||
|
||||
#endif // FRMNAVBUTTON_H
|
|
@ -0,0 +1,547 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>frmNavButton</class>
|
||||
<widget class="QWidget" name="frmNavButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>500</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>500</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>500</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="3" column="0" colspan="4">
|
||||
<widget class="QWidget" name="widgetNav7" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton71">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>首页</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton72">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>论坛</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton73">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Qt下载</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton74">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>作品展</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton75">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>群组</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton76">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>个人中心</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QWidget" name="widgetNav1" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton11">
|
||||
<property name="text">
|
||||
<string>学生管理</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton12">
|
||||
<property name="text">
|
||||
<string>教师管理</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton13">
|
||||
<property name="text">
|
||||
<string>成绩管理</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton14">
|
||||
<property name="text">
|
||||
<string>记录查询</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QWidget" name="widgetNav2" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton21">
|
||||
<property name="text">
|
||||
<string>访客登记</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton22">
|
||||
<property name="text">
|
||||
<string>记录查询</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton23">
|
||||
<property name="text">
|
||||
<string>系统设置</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton24">
|
||||
<property name="text">
|
||||
<string>系统重启</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="4">
|
||||
<widget class="QWidget" name="widgetNav5" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton51">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>首页</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton52">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>论坛</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton53">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>作品</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton54">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>群组</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton55">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>帮助</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="4">
|
||||
<widget class="QWidget" name="widgetNav6" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton61">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>首页</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton62">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>论坛</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton63">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>作品</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton64">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>群组</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton65">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>帮助</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QWidget" name="widgetNav3" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton31">
|
||||
<property name="text">
|
||||
<string>学生管理</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton32">
|
||||
<property name="text">
|
||||
<string>教师管理</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton33">
|
||||
<property name="text">
|
||||
<string>成绩管理</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton34">
|
||||
<property name="text">
|
||||
<string>记录查询</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QWidget" name="widgetNav4" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton41">
|
||||
<property name="text">
|
||||
<string>学生管理</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton42">
|
||||
<property name="text">
|
||||
<string>教师管理</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton43">
|
||||
<property name="text">
|
||||
<string>成绩管理</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NavButton" name="navButton44">
|
||||
<property name="text">
|
||||
<string>记录查询</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="4">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>NavButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>navbutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,240 @@
|
|||
#include "iconhelper.h"
|
||||
|
||||
QScopedPointer<IconHelper> IconHelper::self;
|
||||
IconHelper *IconHelper::Instance()
|
||||
{
|
||||
if (self.isNull()) {
|
||||
static QMutex mutex;
|
||||
QMutexLocker locker(&mutex);
|
||||
if (self.isNull()) {
|
||||
self.reset(new IconHelper);
|
||||
}
|
||||
}
|
||||
|
||||
return self.data();
|
||||
}
|
||||
|
||||
IconHelper::IconHelper(QObject *parent) : QObject(parent)
|
||||
{
|
||||
//判断图形字体是否存在,不存在则加入
|
||||
QFontDatabase fontDb;
|
||||
if (!fontDb.families().contains("FontAwesome")) {
|
||||
int fontId = fontDb.addApplicationFont(":/image/fontawesome-webfont.ttf");
|
||||
QStringList fontName = fontDb.applicationFontFamilies(fontId);
|
||||
if (fontName.count() == 0) {
|
||||
qDebug() << "load fontawesome-webfont.ttf error";
|
||||
}
|
||||
}
|
||||
|
||||
if (fontDb.families().contains("FontAwesome")) {
|
||||
iconFont = QFont("FontAwesome");
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(4,8,0))
|
||||
iconFont.setHintingPreference(QFont::PreferNoHinting);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void IconHelper::setIcon(QLabel *lab, const QChar &str, quint32 size)
|
||||
{
|
||||
iconFont.setPixelSize(size);
|
||||
lab->setFont(iconFont);
|
||||
lab->setText(str);
|
||||
}
|
||||
|
||||
void IconHelper::setIcon(QAbstractButton *btn, const QChar &str, quint32 size)
|
||||
{
|
||||
iconFont.setPixelSize(size);
|
||||
btn->setFont(iconFont);
|
||||
btn->setText(str);
|
||||
}
|
||||
|
||||
QPixmap IconHelper::getPixmap(const QColor &color, const QChar &str, quint32 size,
|
||||
quint32 pixWidth, quint32 pixHeight, int flags)
|
||||
{
|
||||
QPixmap pix(pixWidth, pixHeight);
|
||||
pix.fill(Qt::transparent);
|
||||
|
||||
QPainter painter;
|
||||
painter.begin(&pix);
|
||||
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
|
||||
painter.setPen(color);
|
||||
|
||||
iconFont.setPixelSize(size);
|
||||
painter.setFont(iconFont);
|
||||
painter.drawText(pix.rect(), flags, str);
|
||||
painter.end();
|
||||
|
||||
return pix;
|
||||
}
|
||||
|
||||
QPixmap IconHelper::getPixmap(QToolButton *btn, bool normal)
|
||||
{
|
||||
QPixmap pix;
|
||||
int index = btns.indexOf(btn);
|
||||
|
||||
if (index >= 0) {
|
||||
if (normal) {
|
||||
pix = pixNormal.at(index);
|
||||
} else {
|
||||
pix = pixDark.at(index);
|
||||
}
|
||||
}
|
||||
|
||||
return pix;
|
||||
}
|
||||
|
||||
void IconHelper::setStyle(QWidget *widget, const QString &type, int borderWidth, const QString &borderColor,
|
||||
const QString &normalBgColor, const QString &darkBgColor,
|
||||
const QString &normalTextColor, const QString &darkTextColor)
|
||||
{
|
||||
QString strBorder;
|
||||
if (type == "top") {
|
||||
strBorder = QString("border-width:%1px 0px 0px 0px;padding:%1px %2px %2px %2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "right") {
|
||||
strBorder = QString("border-width:0px %1px 0px 0px;padding:%2px %1px %2px %2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "bottom") {
|
||||
strBorder = QString("border-width:0px 0px %1px 0px;padding:%2px %2px %1px %2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "left") {
|
||||
strBorder = QString("border-width:0px 0px 0px %1px;padding:%2px %2px %2px %1px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
}
|
||||
|
||||
QStringList qss;
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton{border-style:none;border-radius:0px;padding:5px;color:%2;background:%3;}")
|
||||
.arg(type).arg(normalTextColor).arg(normalBgColor));
|
||||
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton:hover,"
|
||||
"QWidget[flag=\"%1\"] QAbstractButton:pressed,"
|
||||
"QWidget[flag=\"%1\"] QAbstractButton:checked{"
|
||||
"border-style:solid;%2border-color:%3;color:%4;background:%5;}")
|
||||
.arg(type).arg(strBorder).arg(borderColor).arg(darkTextColor).arg(darkBgColor));
|
||||
|
||||
widget->setStyleSheet(qss.join(""));
|
||||
}
|
||||
|
||||
void IconHelper::setStyle(QWidget *widget, QList<QToolButton *> btns, QList<int> pixChar,
|
||||
quint32 iconSize, quint32 iconWidth, quint32 iconHeight,
|
||||
const QString &type, int borderWidth, const QString &borderColor,
|
||||
const QString &normalBgColor, const QString &darkBgColor,
|
||||
const QString &normalTextColor, const QString &darkTextColor)
|
||||
{
|
||||
int btnCount = btns.count();
|
||||
int charCount = pixChar.count();
|
||||
if (btnCount <= 0 || charCount <= 0 || btnCount != charCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString strBorder;
|
||||
if (type == "top") {
|
||||
strBorder = QString("border-width:%1px 0px 0px 0px;padding:%1px %2px %2px %2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "right") {
|
||||
strBorder = QString("border-width:0px %1px 0px 0px;padding:%2px %1px %2px %2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "bottom") {
|
||||
strBorder = QString("border-width:0px 0px %1px 0px;padding:%2px %2px %1px %2px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
} else if (type == "left") {
|
||||
strBorder = QString("border-width:0px 0px 0px %1px;padding:%2px %2px %2px %1px;")
|
||||
.arg(borderWidth).arg(borderWidth * 2);
|
||||
}
|
||||
|
||||
//如果图标是左侧显示则需要让没有选中的按钮左侧也有加深的边框,颜色为背景颜色
|
||||
QStringList qss;
|
||||
if (btns.at(0)->toolButtonStyle() == Qt::ToolButtonTextBesideIcon) {
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton{border-style:solid;border-radius:0px;%2border-color:%3;color:%4;background:%5;}")
|
||||
.arg(type).arg(strBorder).arg(normalBgColor).arg(normalTextColor).arg(normalBgColor));
|
||||
} else {
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton{border-style:none;border-radius:0px;padding:5px;color:%2;background:%3;}")
|
||||
.arg(type).arg(normalTextColor).arg(normalBgColor));
|
||||
}
|
||||
|
||||
qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton:hover,"
|
||||
"QWidget[flag=\"%1\"] QAbstractButton:pressed,"
|
||||
"QWidget[flag=\"%1\"] QAbstractButton:checked{"
|
||||
"border-style:solid;%2border-color:%3;color:%4;background:%5;}")
|
||||
.arg(type).arg(strBorder).arg(borderColor).arg(darkTextColor).arg(darkBgColor));
|
||||
|
||||
qss.append(QString("QWidget#%1{background:%2;}").arg(widget->objectName()).arg(normalBgColor));
|
||||
|
||||
qss.append(QString("QWidget>QToolButton{border-width:0px;}"));
|
||||
qss.append(QString("QWidget>QToolButton{background-color:%1;color:%2;}")
|
||||
.arg(normalBgColor).arg(normalTextColor));
|
||||
qss.append(QString("QWidget>QToolButton:hover,QWidget>QToolButton:pressed,QWidget>QToolButton:checked{background-color:%1;color:%2;}")
|
||||
.arg(darkBgColor).arg(darkTextColor));
|
||||
|
||||
widget->setStyleSheet(qss.join(""));
|
||||
|
||||
for (int i = 0; i < btnCount; i++) {
|
||||
//存储对应按钮对象,方便鼠标移上去的时候切换图片
|
||||
QPixmap pixNormal = getPixmap(normalTextColor, QChar(pixChar.at(i)), iconSize, iconWidth, iconHeight);
|
||||
QPixmap pixDark = getPixmap(darkTextColor, QChar(pixChar.at(i)), iconSize, iconWidth, iconHeight);
|
||||
|
||||
btns.at(i)->setIcon(QIcon(pixNormal));
|
||||
btns.at(i)->setIconSize(QSize(iconWidth, iconHeight));
|
||||
btns.at(i)->installEventFilter(this);
|
||||
|
||||
this->btns.append(btns.at(i));
|
||||
this->pixNormal.append(pixNormal);
|
||||
this->pixDark.append(pixDark);
|
||||
}
|
||||
}
|
||||
|
||||
void IconHelper::setStyle(QFrame *frame, QList<QToolButton *> btns, QList<int> pixChar,
|
||||
quint32 iconSize, quint32 iconWidth, quint32 iconHeight,
|
||||
const QString &normalBgColor, const QString &darkBgColor,
|
||||
const QString &normalTextColor, const QString &darkTextColor)
|
||||
{
|
||||
int btnCount = btns.count();
|
||||
int charCount = pixChar.count();
|
||||
if (btnCount <= 0 || charCount <= 0 || btnCount != charCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList qss;
|
||||
qss.append(QString("QFrame>QToolButton{border-style:none;border-width:0px;}"));
|
||||
qss.append(QString("QFrame>QToolButton{background-color:%1;color:%2;}")
|
||||
.arg(normalBgColor).arg(normalTextColor));
|
||||
qss.append(QString("QFrame>QToolButton:hover,QFrame>QToolButton:pressed,QFrame>QToolButton:checked{background-color:%1;color:%2;}")
|
||||
.arg(darkBgColor).arg(darkTextColor));
|
||||
|
||||
frame->setStyleSheet(qss.join(""));
|
||||
|
||||
for (int i = 0; i < btnCount; i++) {
|
||||
//存储对应按钮对象,方便鼠标移上去的时候切换图片
|
||||
QPixmap pixNormal = getPixmap(normalTextColor, QChar(pixChar.at(i)), iconSize, iconWidth, iconHeight);
|
||||
QPixmap pixDark = getPixmap(darkTextColor, QChar(pixChar.at(i)), iconSize, iconWidth, iconHeight);
|
||||
|
||||
btns.at(i)->setIcon(QIcon(pixNormal));
|
||||
btns.at(i)->setIconSize(QSize(iconWidth, iconHeight));
|
||||
btns.at(i)->installEventFilter(this);
|
||||
|
||||
this->btns.append(btns.at(i));
|
||||
this->pixNormal.append(pixNormal);
|
||||
this->pixDark.append(pixDark);
|
||||
}
|
||||
}
|
||||
|
||||
bool IconHelper::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched->inherits("QToolButton")) {
|
||||
QToolButton *btn = (QToolButton *)watched;
|
||||
int index = btns.indexOf(btn);
|
||||
if (index >= 0) {
|
||||
if (event->type() == QEvent::Enter) {
|
||||
btn->setIcon(QIcon(pixDark.at(index)));
|
||||
} else if (event->type() == QEvent::Leave) {
|
||||
if (btn->isChecked()) {
|
||||
btn->setIcon(QIcon(pixDark.at(index)));
|
||||
} else {
|
||||
btn->setIcon(QIcon(pixNormal.at(index)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QObject::eventFilter(watched, event);
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
#ifndef ICONHELPER_H
|
||||
#define ICONHELPER_H
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtGui>
|
||||
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
|
||||
#include <QtWidgets>
|
||||
#endif
|
||||
|
||||
//图形字体处理类
|
||||
class IconHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static IconHelper *Instance();
|
||||
explicit IconHelper(QObject *parent = 0);
|
||||
|
||||
void setIcon(QLabel *lab, const QChar &str, quint32 size = 12);
|
||||
void setIcon(QAbstractButton *btn, const QChar &str, quint32 size = 12);
|
||||
QPixmap getPixmap(const QColor &color, const QChar &str, quint32 size = 12,
|
||||
quint32 pixWidth = 15, quint32 pixHeight = 15,
|
||||
int flags = Qt::AlignCenter);
|
||||
|
||||
//根据按钮获取该按钮对应的图标
|
||||
QPixmap getPixmap(QToolButton *btn, bool normal);
|
||||
|
||||
//指定导航面板样式,不带图标
|
||||
static void setStyle(QWidget *widget, const QString &type = "left", int borderWidth = 3,
|
||||
const QString &borderColor = "#029FEA",
|
||||
const QString &normalBgColor = "#292F38",
|
||||
const QString &darkBgColor = "#1D2025",
|
||||
const QString &normalTextColor = "#54626F",
|
||||
const QString &darkTextColor = "#FDFDFD");
|
||||
|
||||
//指定导航面板样式,带图标和效果切换
|
||||
void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<int> pixChar,
|
||||
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
|
||||
const QString &type = "left", int borderWidth = 3,
|
||||
const QString &borderColor = "#029FEA",
|
||||
const QString &normalBgColor = "#292F38",
|
||||
const QString &darkBgColor = "#1D2025",
|
||||
const QString &normalTextColor = "#54626F",
|
||||
const QString &darkTextColor = "#FDFDFD");
|
||||
|
||||
//指定导航按钮样式,带图标和效果切换
|
||||
void setStyle(QFrame *frame, QList<QToolButton *> btns, QList<int> pixChar,
|
||||
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
|
||||
const QString &normalBgColor = "#2FC5A2",
|
||||
const QString &darkBgColor = "#3EA7E9",
|
||||
const QString &normalTextColor = "#EEEEEE",
|
||||
const QString &darkTextColor = "#FFFFFF");
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<IconHelper> self;
|
||||
QFont iconFont; //图形字体
|
||||
QList<QToolButton *> btns; //按钮队列
|
||||
QList<QPixmap> pixNormal; //正常图片队列
|
||||
QList<QPixmap> pixDark; //加深图片队列
|
||||
};
|
||||
#endif // ICONHELPER_H
|
|
@ -0,0 +1,31 @@
|
|||
#pragma execution_character_set("utf-8")
|
||||
|
||||
#include "frmnavbutton.h"
|
||||
#include <QApplication>
|
||||
#include <QTextCodec>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
a.setFont(QFont("Microsoft Yahei", 9));
|
||||
|
||||
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
|
||||
#if _MSC_VER
|
||||
QTextCodec *codec = QTextCodec::codecForName("gbk");
|
||||
#else
|
||||
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
||||
#endif
|
||||
QTextCodec::setCodecForLocale(codec);
|
||||
QTextCodec::setCodecForCStrings(codec);
|
||||
QTextCodec::setCodecForTr(codec);
|
||||
#else
|
||||
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
||||
QTextCodec::setCodecForLocale(codec);
|
||||
#endif
|
||||
|
||||
frmNavButton w;
|
||||
w.setWindowTitle("导航按钮控件");
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>image/fontawesome-webfont.ttf</file>
|
||||
</qresource>
|
||||
</RCC>
|
|
@ -0,0 +1,629 @@
|
|||
#pragma execution_character_set("utf-8")
|
||||
|
||||
#include "navbutton.h"
|
||||
#include "qpainter.h"
|
||||
#include "qdebug.h"
|
||||
|
||||
NavButton::NavButton(QWidget *parent) : QPushButton(parent)
|
||||
{
|
||||
paddingLeft = 20;
|
||||
paddingRight = 5;
|
||||
paddingTop = 5;
|
||||
paddingBottom = 5;
|
||||
textAlign = TextAlign_Left;
|
||||
|
||||
showTriangle = false;
|
||||
triangleLen = 5;
|
||||
trianglePosition = TrianglePosition_Right;
|
||||
triangleColor = QColor(255, 255, 255);
|
||||
|
||||
showIcon = false;
|
||||
iconSpace = 10;
|
||||
iconSize = QSize(16, 16);
|
||||
iconNormal = QPixmap();
|
||||
iconHover = QPixmap();
|
||||
iconCheck = QPixmap();
|
||||
|
||||
showLine = true;
|
||||
lineSpace = 0;
|
||||
lineWidth = 5;
|
||||
linePosition = LinePosition_Left;
|
||||
lineColor = QColor(0, 187, 158);
|
||||
|
||||
normalBgColor = QColor(230, 230, 230);
|
||||
hoverBgColor = QColor(130, 130, 130);
|
||||
checkBgColor = QColor(80, 80, 80);
|
||||
normalTextColor = QColor(100, 100, 100);
|
||||
hoverTextColor = QColor(255, 255, 255);
|
||||
checkTextColor = QColor(255, 255, 255);
|
||||
|
||||
normalBgBrush = Qt::NoBrush;
|
||||
hoverBgBrush = Qt::NoBrush;
|
||||
checkBgBrush = Qt::NoBrush;
|
||||
|
||||
hover = false;
|
||||
setCheckable(true);
|
||||
}
|
||||
|
||||
void NavButton::enterEvent(QEvent *)
|
||||
{
|
||||
hover = true;
|
||||
this->update();
|
||||
}
|
||||
|
||||
void NavButton::leaveEvent(QEvent *)
|
||||
{
|
||||
hover = false;
|
||||
this->update();
|
||||
}
|
||||
|
||||
void NavButton::paintEvent(QPaintEvent *)
|
||||
{
|
||||
//绘制准备工作,启用反锯齿
|
||||
QPainter painter(this);
|
||||
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
|
||||
|
||||
//绘制背景
|
||||
drawBg(&painter);
|
||||
//绘制文字
|
||||
drawText(&painter);
|
||||
//绘制图标
|
||||
drawIcon(&painter);
|
||||
//绘制边框线条
|
||||
drawLine(&painter);
|
||||
//绘制倒三角
|
||||
drawTriangle(&painter);
|
||||
}
|
||||
|
||||
void NavButton::drawBg(QPainter *painter)
|
||||
{
|
||||
painter->save();
|
||||
painter->setPen(Qt::NoPen);
|
||||
|
||||
int width = this->width();
|
||||
int height = this->height();
|
||||
|
||||
QRect bgRect;
|
||||
if (linePosition == LinePosition_Left) {
|
||||
bgRect = QRect(lineSpace, 0, width - lineSpace, height);
|
||||
} else if (linePosition == LinePosition_Right) {
|
||||
bgRect = QRect(0, 0, width - lineSpace, height);
|
||||
} else if (linePosition == LinePosition_Top) {
|
||||
bgRect = QRect(0, lineSpace, width, height - lineSpace);
|
||||
} else if (linePosition == LinePosition_Bottom) {
|
||||
bgRect = QRect(0, 0, width, height - lineSpace);
|
||||
}
|
||||
|
||||
//如果画刷存在则取画刷
|
||||
QBrush bgBrush;
|
||||
if (isChecked()) {
|
||||
bgBrush = checkBgBrush;
|
||||
} else if (hover) {
|
||||
bgBrush = hoverBgBrush;
|
||||
} else {
|
||||
bgBrush = normalBgBrush;
|
||||
}
|
||||
|
||||
if (bgBrush != Qt::NoBrush) {
|
||||
painter->setBrush(bgBrush);
|
||||
} else {
|
||||
//根据当前状态选择对应颜色
|
||||
QColor bgColor;
|
||||
if (isChecked()) {
|
||||
bgColor = checkBgColor;
|
||||
} else if (hover) {
|
||||
bgColor = hoverBgColor;
|
||||
} else {
|
||||
bgColor = normalBgColor;
|
||||
}
|
||||
|
||||
painter->setBrush(bgColor);
|
||||
}
|
||||
|
||||
painter->drawRect(bgRect);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void NavButton::drawText(QPainter *painter)
|
||||
{
|
||||
painter->save();
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
|
||||
//根据当前状态选择对应颜色
|
||||
QColor textColor;
|
||||
if (isChecked()) {
|
||||
textColor = checkTextColor;
|
||||
} else if (hover) {
|
||||
textColor = hoverTextColor;
|
||||
} else {
|
||||
textColor = normalTextColor;
|
||||
}
|
||||
|
||||
QRect textRect = QRect(paddingLeft, paddingTop, width() - paddingLeft - paddingRight, height() - paddingTop - paddingBottom);
|
||||
painter->setPen(textColor);
|
||||
painter->drawText(textRect, textAlign | Qt::AlignVCenter, text());
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void NavButton::drawIcon(QPainter *painter)
|
||||
{
|
||||
if (!showIcon) {
|
||||
return;
|
||||
}
|
||||
|
||||
painter->save();
|
||||
|
||||
QPixmap pix;
|
||||
if (isChecked()) {
|
||||
pix = iconCheck;
|
||||
} else if (hover) {
|
||||
pix = iconHover;
|
||||
} else {
|
||||
pix = iconNormal;
|
||||
}
|
||||
|
||||
if (!pix.isNull()) {
|
||||
//等比例平滑缩放图标
|
||||
pix = pix.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
painter->drawPixmap(iconSpace, (height() - iconSize.height()) / 2, pix);
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void NavButton::drawLine(QPainter *painter)
|
||||
{
|
||||
if (!showLine) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isChecked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
painter->save();
|
||||
|
||||
QPen pen;
|
||||
pen.setWidth(lineWidth);
|
||||
pen.setColor(lineColor);
|
||||
painter->setPen(pen);
|
||||
|
||||
//根据线条位置设置线条坐标
|
||||
QPoint pointStart, pointEnd;
|
||||
if (linePosition == LinePosition_Left) {
|
||||
pointStart = QPoint(0, 0);
|
||||
pointEnd = QPoint(0, height());
|
||||
} else if (linePosition == LinePosition_Right) {
|
||||
pointStart = QPoint(width(), 0);
|
||||
pointEnd = QPoint(width(), height());
|
||||
} else if (linePosition == LinePosition_Top) {
|
||||
pointStart = QPoint(0, 0);
|
||||
pointEnd = QPoint(width(), 0);
|
||||
} else if (linePosition == LinePosition_Bottom) {
|
||||
pointStart = QPoint(0, height());
|
||||
pointEnd = QPoint(width(), height());
|
||||
}
|
||||
|
||||
painter->drawLine(pointStart, pointEnd);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void NavButton::drawTriangle(QPainter *painter)
|
||||
{
|
||||
if (!showTriangle) {
|
||||
return;
|
||||
}
|
||||
|
||||
//选中或者悬停显示
|
||||
if (!hover && !isChecked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
painter->save();
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(triangleColor);
|
||||
|
||||
//绘制在右侧中间,根据设定的倒三角的边长设定三个点位置
|
||||
int width = this->width();
|
||||
int height = this->height();
|
||||
int midWidth = width / 2;
|
||||
int midHeight = height / 2;
|
||||
|
||||
QPolygon pts;
|
||||
if (trianglePosition == TrianglePosition_Left) {
|
||||
pts.setPoints(3, triangleLen, midHeight, 0, midHeight - triangleLen, 0, midHeight + triangleLen);
|
||||
} else if (trianglePosition == TrianglePosition_Right) {
|
||||
pts.setPoints(3, width - triangleLen, midHeight, width, midHeight - triangleLen, width, midHeight + triangleLen);
|
||||
} else if (trianglePosition == TrianglePosition_Top) {
|
||||
pts.setPoints(3, midWidth, triangleLen, midWidth - triangleLen, 0, midWidth + triangleLen, 0);
|
||||
} else if (trianglePosition == TrianglePosition_Bottom) {
|
||||
pts.setPoints(3, midWidth, height - triangleLen, midWidth - triangleLen, height, midWidth + triangleLen, height);
|
||||
}
|
||||
|
||||
painter->drawPolygon(pts);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
int NavButton::getPaddingLeft() const
|
||||
{
|
||||
return this->paddingLeft;
|
||||
}
|
||||
|
||||
int NavButton::getPaddingRight() const
|
||||
{
|
||||
return this->paddingRight;
|
||||
}
|
||||
|
||||
int NavButton::getPaddingTop() const
|
||||
{
|
||||
return this->paddingTop;
|
||||
}
|
||||
|
||||
int NavButton::getPaddingBottom() const
|
||||
{
|
||||
return this->paddingBottom;
|
||||
}
|
||||
|
||||
NavButton::TextAlign NavButton::getTextAlign() const
|
||||
{
|
||||
return this->textAlign;
|
||||
}
|
||||
|
||||
bool NavButton::getShowTriangle() const
|
||||
{
|
||||
return this->showTriangle;
|
||||
}
|
||||
|
||||
int NavButton::getTriangleLen() const
|
||||
{
|
||||
return this->triangleLen;
|
||||
}
|
||||
|
||||
NavButton::TrianglePosition NavButton::getTrianglePosition() const
|
||||
{
|
||||
return this->trianglePosition;
|
||||
}
|
||||
|
||||
QColor NavButton::getTriangleColor() const
|
||||
{
|
||||
return this->triangleColor;
|
||||
}
|
||||
|
||||
bool NavButton::getShowIcon() const
|
||||
{
|
||||
return this->showIcon;
|
||||
}
|
||||
|
||||
int NavButton::getIconSpace() const
|
||||
{
|
||||
return this->iconSpace;
|
||||
}
|
||||
|
||||
QSize NavButton::getIconSize() const
|
||||
{
|
||||
return this->iconSize;
|
||||
}
|
||||
|
||||
QPixmap NavButton::getIconNormal() const
|
||||
{
|
||||
return this->iconNormal;
|
||||
}
|
||||
|
||||
QPixmap NavButton::getIconHover() const
|
||||
{
|
||||
return this->iconHover;
|
||||
}
|
||||
|
||||
QPixmap NavButton::getIconCheck() const
|
||||
{
|
||||
return this->iconCheck;
|
||||
}
|
||||
|
||||
bool NavButton::getShowLine() const
|
||||
{
|
||||
return this->showLine;
|
||||
}
|
||||
|
||||
int NavButton::getLineSpace() const
|
||||
{
|
||||
return this->lineSpace;
|
||||
}
|
||||
|
||||
int NavButton::getLineWidth() const
|
||||
{
|
||||
return this->lineWidth;
|
||||
}
|
||||
|
||||
NavButton::LinePosition NavButton::getLinePosition() const
|
||||
{
|
||||
return this->linePosition;
|
||||
}
|
||||
|
||||
QColor NavButton::getLineColor() const
|
||||
{
|
||||
return this->lineColor;
|
||||
}
|
||||
|
||||
QColor NavButton::getNormalBgColor() const
|
||||
{
|
||||
return this->normalBgColor;
|
||||
}
|
||||
|
||||
QColor NavButton::getHoverBgColor() const
|
||||
{
|
||||
return this->hoverBgColor;
|
||||
}
|
||||
|
||||
QColor NavButton::getCheckBgColor() const
|
||||
{
|
||||
return this->checkBgColor;
|
||||
}
|
||||
|
||||
QColor NavButton::getNormalTextColor() const
|
||||
{
|
||||
return this->normalTextColor;
|
||||
}
|
||||
|
||||
QColor NavButton::getHoverTextColor() const
|
||||
{
|
||||
return this->hoverTextColor;
|
||||
}
|
||||
|
||||
QColor NavButton::getCheckTextColor() const
|
||||
{
|
||||
return this->checkTextColor;
|
||||
}
|
||||
|
||||
QSize NavButton::sizeHint() const
|
||||
{
|
||||
return QSize(100, 30);
|
||||
}
|
||||
|
||||
QSize NavButton::minimumSizeHint() const
|
||||
{
|
||||
return QSize(20, 10);
|
||||
}
|
||||
|
||||
void NavButton::setPaddingLeft(int paddingLeft)
|
||||
{
|
||||
if (this->paddingLeft != paddingLeft) {
|
||||
this->paddingLeft = paddingLeft;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setPaddingRight(int paddingRight)
|
||||
{
|
||||
if (this->paddingRight != paddingRight) {
|
||||
this->paddingRight = paddingRight;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setPaddingTop(int paddingTop)
|
||||
{
|
||||
if (this->paddingTop != paddingTop) {
|
||||
this->paddingTop = paddingTop;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setPaddingBottom(int paddingBottom)
|
||||
{
|
||||
if (this->paddingBottom != paddingBottom) {
|
||||
this->paddingBottom = paddingBottom;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setPadding(int padding)
|
||||
{
|
||||
setPadding(padding, padding, padding, padding);
|
||||
}
|
||||
|
||||
void NavButton::setPadding(int paddingLeft, int paddingRight, int paddingTop, int paddingBottom)
|
||||
{
|
||||
this->paddingLeft = paddingLeft;
|
||||
this->paddingRight = paddingRight;
|
||||
this->paddingTop = paddingTop;
|
||||
this->paddingBottom = paddingBottom;
|
||||
this->update();
|
||||
}
|
||||
|
||||
void NavButton::setTextAlign(const NavButton::TextAlign &textAlign)
|
||||
{
|
||||
if (this->textAlign != textAlign) {
|
||||
this->textAlign = textAlign;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setShowTriangle(bool showTriangle)
|
||||
{
|
||||
if (this->showTriangle != showTriangle) {
|
||||
this->showTriangle = showTriangle;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setTriangleLen(int triangleLen)
|
||||
{
|
||||
if (this->triangleLen != triangleLen) {
|
||||
this->triangleLen = triangleLen;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setTrianglePosition(const NavButton::TrianglePosition &trianglePosition)
|
||||
{
|
||||
if (this->trianglePosition != trianglePosition) {
|
||||
this->trianglePosition = trianglePosition;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setTriangleColor(const QColor &triangleColor)
|
||||
{
|
||||
if (this->triangleColor != triangleColor) {
|
||||
this->triangleColor = triangleColor;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setShowIcon(bool showIcon)
|
||||
{
|
||||
if (this->showIcon != showIcon) {
|
||||
this->showIcon = showIcon;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setIconSpace(int iconSpace)
|
||||
{
|
||||
if (this->iconSpace != iconSpace) {
|
||||
this->iconSpace = iconSpace;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setIconSize(const QSize &iconSize)
|
||||
{
|
||||
if (this->iconSize != iconSize) {
|
||||
this->iconSize = iconSize;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setIconNormal(const QPixmap &iconNormal)
|
||||
{
|
||||
this->iconNormal = iconNormal;
|
||||
this->update();
|
||||
}
|
||||
|
||||
void NavButton::setIconHover(const QPixmap &iconHover)
|
||||
{
|
||||
this->iconHover = iconHover;
|
||||
this->update();
|
||||
}
|
||||
|
||||
void NavButton::setIconCheck(const QPixmap &iconCheck)
|
||||
{
|
||||
this->iconCheck = iconCheck;
|
||||
this->update();
|
||||
}
|
||||
|
||||
void NavButton::setShowLine(bool showLine)
|
||||
{
|
||||
if (this->showLine != showLine) {
|
||||
this->showLine = showLine;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setLineSpace(int lineSpace)
|
||||
{
|
||||
if (this->lineSpace != lineSpace) {
|
||||
this->lineSpace = lineSpace;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setLineWidth(int lineWidth)
|
||||
{
|
||||
if (this->lineWidth != lineWidth) {
|
||||
this->lineWidth = lineWidth;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setLinePosition(const NavButton::LinePosition &linePosition)
|
||||
{
|
||||
if (this->linePosition != linePosition) {
|
||||
this->linePosition = linePosition;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setLineColor(const QColor &lineColor)
|
||||
{
|
||||
if (this->lineColor != lineColor) {
|
||||
this->lineColor = lineColor;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setNormalBgColor(const QColor &normalBgColor)
|
||||
{
|
||||
if (this->normalBgColor != normalBgColor) {
|
||||
this->normalBgColor = normalBgColor;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setHoverBgColor(const QColor &hoverBgColor)
|
||||
{
|
||||
if (this->hoverBgColor != hoverBgColor) {
|
||||
this->hoverBgColor = hoverBgColor;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setCheckBgColor(const QColor &checkBgColor)
|
||||
{
|
||||
if (this->checkBgColor != checkBgColor) {
|
||||
this->checkBgColor = checkBgColor;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setNormalTextColor(const QColor &normalTextColor)
|
||||
{
|
||||
if (this->normalTextColor != normalTextColor) {
|
||||
this->normalTextColor = normalTextColor;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setHoverTextColor(const QColor &hoverTextColor)
|
||||
{
|
||||
if (this->hoverTextColor != hoverTextColor) {
|
||||
this->hoverTextColor = hoverTextColor;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setCheckTextColor(const QColor &checkTextColor)
|
||||
{
|
||||
if (this->checkTextColor != checkTextColor) {
|
||||
this->checkTextColor = checkTextColor;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setNormalBgBrush(const QBrush &normalBgBrush)
|
||||
{
|
||||
if (this->normalBgBrush != normalBgBrush) {
|
||||
this->normalBgBrush = normalBgBrush;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setHoverBgBrush(const QBrush &hoverBgBrush)
|
||||
{
|
||||
if (this->hoverBgBrush != hoverBgBrush) {
|
||||
this->hoverBgBrush = hoverBgBrush;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void NavButton::setCheckBgBrush(const QBrush &checkBgBrush)
|
||||
{
|
||||
if (this->checkBgBrush != checkBgBrush) {
|
||||
this->checkBgBrush = checkBgBrush;
|
||||
this->update();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,251 @@
|
|||
#ifndef NAVBUTTON_H
|
||||
#define NAVBUTTON_H
|
||||
|
||||
/**
|
||||
* 导航按钮控件 作者:feiyangqingyun(QQ:517216493) 2017-12-19
|
||||
* 1:可设置文字的左侧+右侧+顶部+底部间隔
|
||||
* 2:可设置文字对齐方式
|
||||
* 3:可设置显示倒三角/倒三角边长/倒三角位置/倒三角颜色
|
||||
* 4:可设置显示图标/图标间隔/图标尺寸/正常状态图标/悬停状态图标/选中状态图标
|
||||
* 5:可设置显示边框线条/线条宽度/线条间隔/线条位置/线条颜色
|
||||
* 6:可设置正常背景颜色/悬停背景颜色/选中背景颜色
|
||||
* 7:可设置正常文字颜色/悬停文字颜色/选中文字颜色
|
||||
* 8:可设置背景颜色为画刷颜色
|
||||
*/
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
#ifdef quc
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
|
||||
#include <QtDesigner/QDesignerExportWidget>
|
||||
#else
|
||||
#include <QtUiPlugin/QDesignerExportWidget>
|
||||
#endif
|
||||
|
||||
class QDESIGNER_WIDGET_EXPORT NavButton : public QPushButton
|
||||
#else
|
||||
class NavButton : public QPushButton
|
||||
#endif
|
||||
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(TextAlign)
|
||||
Q_ENUMS(TrianglePosition)
|
||||
Q_ENUMS(LinePosition)
|
||||
Q_ENUMS(IconPosition)
|
||||
|
||||
Q_PROPERTY(int paddingLeft READ getPaddingLeft WRITE setPaddingLeft)
|
||||
Q_PROPERTY(int paddingRight READ getPaddingRight WRITE setPaddingRight)
|
||||
Q_PROPERTY(int paddingTop READ getPaddingTop WRITE setPaddingTop)
|
||||
Q_PROPERTY(int paddingBottom READ getPaddingBottom WRITE setPaddingBottom)
|
||||
Q_PROPERTY(TextAlign textAlign READ getTextAlign WRITE setTextAlign)
|
||||
|
||||
Q_PROPERTY(bool showTriangle READ getShowTriangle WRITE setShowTriangle)
|
||||
Q_PROPERTY(int triangleLen READ getTriangleLen WRITE setTriangleLen)
|
||||
Q_PROPERTY(TrianglePosition trianglePosition READ getTrianglePosition WRITE setTrianglePosition)
|
||||
Q_PROPERTY(QColor triangleColor READ getTriangleColor WRITE setTriangleColor)
|
||||
|
||||
Q_PROPERTY(bool showIcon READ getShowIcon WRITE setShowIcon)
|
||||
Q_PROPERTY(int iconSpace READ getIconSpace WRITE setIconSpace)
|
||||
Q_PROPERTY(QSize iconSize READ getIconSize WRITE setIconSize)
|
||||
Q_PROPERTY(QPixmap iconNormal READ getIconNormal WRITE setIconNormal)
|
||||
Q_PROPERTY(QPixmap iconHover READ getIconHover WRITE setIconHover)
|
||||
Q_PROPERTY(QPixmap iconCheck READ getIconCheck WRITE setIconCheck)
|
||||
|
||||
Q_PROPERTY(bool showLine READ getShowLine WRITE setShowLine)
|
||||
Q_PROPERTY(int lineSpace READ getLineSpace WRITE setLineSpace)
|
||||
Q_PROPERTY(int lineWidth READ getLineWidth WRITE setLineWidth)
|
||||
Q_PROPERTY(LinePosition linePosition READ getLinePosition WRITE setLinePosition)
|
||||
Q_PROPERTY(QColor lineColor READ getLineColor WRITE setLineColor)
|
||||
|
||||
Q_PROPERTY(QColor normalBgColor READ getNormalBgColor WRITE setNormalBgColor)
|
||||
Q_PROPERTY(QColor hoverBgColor READ getHoverBgColor WRITE setHoverBgColor)
|
||||
Q_PROPERTY(QColor checkBgColor READ getCheckBgColor WRITE setCheckBgColor)
|
||||
Q_PROPERTY(QColor normalTextColor READ getNormalTextColor WRITE setNormalTextColor)
|
||||
Q_PROPERTY(QColor hoverTextColor READ getHoverTextColor WRITE setHoverTextColor)
|
||||
Q_PROPERTY(QColor checkTextColor READ getCheckTextColor WRITE setCheckTextColor)
|
||||
|
||||
public:
|
||||
enum TextAlign {
|
||||
TextAlign_Left = 0x0001, //左侧对齐
|
||||
TextAlign_Right = 0x0002, //右侧对齐
|
||||
TextAlign_Top = 0x0020, //顶部对齐
|
||||
TextAlign_Bottom = 0x0040, //底部对齐
|
||||
TextAlign_Center = 0x0004 //居中对齐
|
||||
};
|
||||
|
||||
enum TrianglePosition {
|
||||
TrianglePosition_Left = 0, //左侧
|
||||
TrianglePosition_Right = 1, //右侧
|
||||
TrianglePosition_Top = 2, //顶部
|
||||
TrianglePosition_Bottom = 3 //底部
|
||||
};
|
||||
|
||||
enum IconPosition {
|
||||
IconPosition_Left = 0, //左侧
|
||||
IconPosition_Right = 1, //右侧
|
||||
IconPosition_Top = 2, //顶部
|
||||
IconPosition_Bottom = 3 //底部
|
||||
};
|
||||
|
||||
enum LinePosition {
|
||||
LinePosition_Left = 0, //左侧
|
||||
LinePosition_Right = 1, //右侧
|
||||
LinePosition_Top = 2, //顶部
|
||||
LinePosition_Bottom = 3 //底部
|
||||
};
|
||||
|
||||
explicit NavButton(QWidget *parent = 0);
|
||||
|
||||
protected:
|
||||
void enterEvent(QEvent *);
|
||||
void leaveEvent(QEvent *);
|
||||
void paintEvent(QPaintEvent *);
|
||||
void drawBg(QPainter *painter);
|
||||
void drawText(QPainter *painter);
|
||||
void drawIcon(QPainter *painter);
|
||||
void drawLine(QPainter *painter);
|
||||
void drawTriangle(QPainter *painter);
|
||||
|
||||
private:
|
||||
int paddingLeft; //文字左侧间隔
|
||||
int paddingRight; //文字右侧间隔
|
||||
int paddingTop; //文字顶部间隔
|
||||
int paddingBottom; //文字底部间隔
|
||||
TextAlign textAlign; //文字对齐
|
||||
|
||||
bool showTriangle; //显示倒三角
|
||||
int triangleLen; //倒三角边长
|
||||
TrianglePosition trianglePosition; //倒三角位置
|
||||
QColor triangleColor; //倒三角颜色
|
||||
|
||||
bool showIcon; //显示图标
|
||||
int iconSpace; //图标间隔
|
||||
QSize iconSize; //图标尺寸
|
||||
QPixmap iconNormal; //正常图标
|
||||
QPixmap iconHover; //悬停图标
|
||||
QPixmap iconCheck; //选中图标
|
||||
|
||||
bool showLine; //显示线条
|
||||
int lineSpace; //线条间隔
|
||||
int lineWidth; //线条宽度
|
||||
LinePosition linePosition; //线条位置
|
||||
QColor lineColor; //线条颜色
|
||||
|
||||
QColor normalBgColor; //正常背景颜色
|
||||
QColor hoverBgColor; //悬停背景颜色
|
||||
QColor checkBgColor; //选中背景颜色
|
||||
QColor normalTextColor; //正常文字颜色
|
||||
QColor hoverTextColor; //悬停文字颜色
|
||||
QColor checkTextColor; //选中文字颜色
|
||||
|
||||
QBrush normalBgBrush; //正常背景画刷
|
||||
QBrush hoverBgBrush; //悬停背景画刷
|
||||
QBrush checkBgBrush; //选中背景画刷
|
||||
|
||||
bool hover; //悬停标志位
|
||||
|
||||
public:
|
||||
int getPaddingLeft() const;
|
||||
int getPaddingRight() const;
|
||||
int getPaddingTop() const;
|
||||
int getPaddingBottom() const;
|
||||
TextAlign getTextAlign() const;
|
||||
|
||||
bool getShowTriangle() const;
|
||||
int getTriangleLen() const;
|
||||
TrianglePosition getTrianglePosition()const;
|
||||
QColor getTriangleColor() const;
|
||||
|
||||
bool getShowIcon() const;
|
||||
int getIconSpace() const;
|
||||
QSize getIconSize() const;
|
||||
QPixmap getIconNormal() const;
|
||||
QPixmap getIconHover() const;
|
||||
QPixmap getIconCheck() const;
|
||||
|
||||
bool getShowLine() const;
|
||||
int getLineSpace() const;
|
||||
int getLineWidth() const;
|
||||
LinePosition getLinePosition() const;
|
||||
QColor getLineColor() const;
|
||||
|
||||
QColor getNormalBgColor() const;
|
||||
QColor getHoverBgColor() const;
|
||||
QColor getCheckBgColor() const;
|
||||
QColor getNormalTextColor() const;
|
||||
QColor getHoverTextColor() const;
|
||||
QColor getCheckTextColor() const;
|
||||
|
||||
QSize sizeHint() const;
|
||||
QSize minimumSizeHint() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
//设置文字间隔
|
||||
void setPaddingLeft(int paddingLeft);
|
||||
void setPaddingRight(int paddingRight);
|
||||
void setPaddingTop(int paddingTop);
|
||||
void setPaddingBottom(int paddingBottom);
|
||||
void setPadding(int padding);
|
||||
void setPadding(int paddingLeft, int paddingRight, int paddingTop, int paddingBottom);
|
||||
|
||||
//设置文字对齐
|
||||
void setTextAlign(const TextAlign &textAlign);
|
||||
|
||||
//设置显示倒三角
|
||||
void setShowTriangle(bool showTriangle);
|
||||
//设置倒三角边长
|
||||
void setTriangleLen(int triangleLen);
|
||||
//设置倒三角位置
|
||||
void setTrianglePosition(const TrianglePosition &trianglePosition);
|
||||
//设置倒三角颜色
|
||||
void setTriangleColor(const QColor &triangleColor);
|
||||
|
||||
//设置显示图标
|
||||
void setShowIcon(bool showIcon);
|
||||
//设置图标间隔
|
||||
void setIconSpace(int iconSpace);
|
||||
//设置图标尺寸
|
||||
void setIconSize(const QSize &iconSize);
|
||||
//设置正常图标
|
||||
void setIconNormal(const QPixmap &iconNormal);
|
||||
//设置悬停图标
|
||||
void setIconHover(const QPixmap &iconHover);
|
||||
//设置按下图标
|
||||
void setIconCheck(const QPixmap &iconCheck);
|
||||
|
||||
//设置显示线条
|
||||
void setShowLine(bool showLine);
|
||||
//设置线条间隔
|
||||
void setLineSpace(int lineSpace);
|
||||
//设置线条宽度
|
||||
void setLineWidth(int lineWidth);
|
||||
//设置线条位置
|
||||
void setLinePosition(const LinePosition &linePosition);
|
||||
//设置线条颜色
|
||||
void setLineColor(const QColor &lineColor);
|
||||
|
||||
//设置正常背景颜色
|
||||
void setNormalBgColor(const QColor &normalBgColor);
|
||||
//设置悬停背景颜色
|
||||
void setHoverBgColor(const QColor &hoverBgColor);
|
||||
//设置选中背景颜色
|
||||
void setCheckBgColor(const QColor &checkBgColor);
|
||||
|
||||
//设置正常文字颜色
|
||||
void setNormalTextColor(const QColor &normalTextColor);
|
||||
//设置悬停文字颜色
|
||||
void setHoverTextColor(const QColor &hoverTextColor);
|
||||
//设置选中文字颜色
|
||||
void setCheckTextColor(const QColor &checkTextColor);
|
||||
|
||||
//设置正常背景画刷
|
||||
void setNormalBgBrush(const QBrush &normalBgBrush);
|
||||
//设置悬停背景画刷
|
||||
void setHoverBgBrush(const QBrush &hoverBgBrush);
|
||||
//设置选中背景画刷
|
||||
void setCheckBgBrush(const QBrush &checkBgBrush);
|
||||
|
||||
};
|
||||
|
||||
#endif // NAVBUTTON_H
|
|
@ -0,0 +1,27 @@
|
|||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2017-02-08T15:12:35
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = navbutton
|
||||
TEMPLATE = app
|
||||
DESTDIR = $$PWD/../bin
|
||||
CONFIG += warn_off
|
||||
|
||||
SOURCES += main.cpp
|
||||
SOURCES += iconhelper.cpp
|
||||
SOURCES += frmnavbutton.cpp
|
||||
SOURCES += navbutton.cpp
|
||||
|
||||
HEADERS += frmnavbutton.h
|
||||
HEADERS += iconhelper.h
|
||||
HEADERS += navbutton.h
|
||||
|
||||
FORMS += frmnavbutton.ui
|
||||
|
||||
RESOURCES += main.qrc
|
After Width: | Height: | Size: 4.7 KiB |
|
@ -0,0 +1,378 @@
|
|||
#include "frmmain.h"
|
||||
#include "ui_frmmain.h"
|
||||
|
||||
#pragma execution_character_set("utf-8")
|
||||
|
||||
frmMain::frmMain(QWidget *parent) : QWidget(parent), ui(new Ui::frmMain)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->initForm();
|
||||
this->initMenu();
|
||||
this->show_video_all();
|
||||
QTimer::singleShot(1000, this, SLOT(play_video_all()));
|
||||
}
|
||||
|
||||
frmMain::~frmMain()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
bool frmMain::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::MouseButtonDblClick) {
|
||||
QLabel *widget = (QLabel *) watched;
|
||||
if (!videoMax) {
|
||||
videoMax = true;
|
||||
hide_video_all();
|
||||
ui->gridLayout->addWidget(widget, 0, 0);
|
||||
widget->setVisible(true);
|
||||
} else {
|
||||
videoMax = false;
|
||||
show_video_all();
|
||||
}
|
||||
|
||||
widget->setFocus();
|
||||
} else if (event->type() == QEvent::MouseButtonPress) {
|
||||
if (qApp->mouseButtons() == Qt::RightButton) {
|
||||
videoMenu->exec(QCursor::pos());
|
||||
}
|
||||
}
|
||||
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void frmMain::initForm()
|
||||
{
|
||||
//设置样式表
|
||||
QStringList qss;
|
||||
qss.append("QFrame{border:2px solid #000000;}");
|
||||
qss.append("QLabel{font:75 25px;color:#F0F0F0;border:2px solid #AAAAAA;background:#000000;}");
|
||||
qss.append("QLabel:focus{border:2px solid #00BB9E;background:#555555;}");
|
||||
ui->frame->setStyleSheet(qss.join(""));
|
||||
|
||||
videoMax = false;
|
||||
videoCount = 16;
|
||||
videoType = "1_16";
|
||||
|
||||
for (int i = 0; i < videoCount; i++) {
|
||||
QLabel *widget = new QLabel;
|
||||
widget->setObjectName(QString("video%1").arg(i + 1));
|
||||
widget->installEventFilter(this);
|
||||
widget->setFocusPolicy(Qt::StrongFocus);
|
||||
widget->setAlignment(Qt::AlignCenter);
|
||||
|
||||
//二选一可以选择显示文字,也可以选择显示背景图片
|
||||
//widget->setText(QString("通道 %1").arg(i + 1));
|
||||
widget->setPixmap(QPixmap(":/bg_novideo.png"));
|
||||
widgets.append(widget);
|
||||
}
|
||||
}
|
||||
|
||||
void frmMain::initMenu()
|
||||
{
|
||||
videoMenu = new QMenu(this);
|
||||
videoMenu->addAction("截图当前视频", this, SLOT(snapshot_video_one()));
|
||||
videoMenu->addAction("截图所有视频", this, SLOT(snapshot_video_all()));
|
||||
videoMenu->addSeparator();
|
||||
|
||||
QMenu *menu4 = videoMenu->addMenu("切换到4画面");
|
||||
menu4->addAction("通道1-通道4", this, SLOT(show_video_4()));
|
||||
menu4->addAction("通道5-通道8", this, SLOT(show_video_4()));
|
||||
menu4->addAction("通道9-通道12", this, SLOT(show_video_4()));
|
||||
menu4->addAction("通道13-通道16", this, SLOT(show_video_4()));
|
||||
|
||||
QMenu *menu6 = videoMenu->addMenu("切换到6画面");
|
||||
menu6->addAction("通道1-通道6", this, SLOT(show_video_6()));
|
||||
menu6->addAction("通道6-通道11", this, SLOT(show_video_6()));
|
||||
menu6->addAction("通道11-通道16", this, SLOT(show_video_6()));
|
||||
|
||||
QMenu *menu8 = videoMenu->addMenu("切换到8画面");
|
||||
menu8->addAction("通道1-通道8", this, SLOT(show_video_8()));
|
||||
menu8->addAction("通道9-通道16", this, SLOT(show_video_8()));
|
||||
|
||||
QMenu *menu9 = videoMenu->addMenu("切换到9画面");
|
||||
menu9->addAction("通道1-通道9", this, SLOT(show_video_9()));
|
||||
menu9->addAction("通道8-通道16", this, SLOT(show_video_9()));
|
||||
|
||||
videoMenu->addAction("切换到16画面", this, SLOT(show_video_16()));
|
||||
}
|
||||
|
||||
void frmMain::play_video_all()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void frmMain::snapshot_video_one()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void frmMain::snapshot_video_all()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void frmMain::show_video_all()
|
||||
{
|
||||
if (videoType == "1_4") {
|
||||
change_video_4(0);
|
||||
} else if (videoType == "5_8") {
|
||||
change_video_4(4);
|
||||
} else if (videoType == "9_12") {
|
||||
change_video_4(8);
|
||||
} else if (videoType == "13_16") {
|
||||
change_video_4(12);
|
||||
} else if (videoType == "1_6") {
|
||||
change_video_6(0);
|
||||
} else if (videoType == "6_11") {
|
||||
change_video_6(5);
|
||||
} else if (videoType == "11_16") {
|
||||
change_video_6(10);
|
||||
} else if (videoType == "1_8") {
|
||||
change_video_8(0);
|
||||
} else if (videoType == "9_16") {
|
||||
change_video_8(8);
|
||||
} else if (videoType == "1_9") {
|
||||
change_video_9(0);
|
||||
} else if (videoType == "8_16") {
|
||||
change_video_9(7);
|
||||
} else if (videoType == "1_16") {
|
||||
change_video_16(0);
|
||||
}
|
||||
}
|
||||
|
||||
void frmMain::show_video_4()
|
||||
{
|
||||
videoMax = false;
|
||||
QString videoType;
|
||||
int index = 0;
|
||||
|
||||
QAction *action = (QAction *)sender();
|
||||
QString name = action->text();
|
||||
|
||||
if (name == "通道1-通道4") {
|
||||
index = 0;
|
||||
videoType = "1_4";
|
||||
} else if (name == "通道5-通道8") {
|
||||
index = 4;
|
||||
videoType = "5_8";
|
||||
} else if (name == "通道9-通道12") {
|
||||
index = 8;
|
||||
videoType = "9_12";
|
||||
} else if (name == "通道13-通道16") {
|
||||
index = 12;
|
||||
videoType = "13_16";
|
||||
}
|
||||
|
||||
if (this->videoType != videoType) {
|
||||
this->videoType = videoType;
|
||||
change_video_4(index);
|
||||
}
|
||||
}
|
||||
|
||||
void frmMain::show_video_6()
|
||||
{
|
||||
videoMax = false;
|
||||
QString videoType;
|
||||
int index = 0;
|
||||
|
||||
QAction *action = (QAction *)sender();
|
||||
QString name = action->text();
|
||||
|
||||
if (name == "通道1-通道6") {
|
||||
index = 0;
|
||||
videoType = "1_6";
|
||||
} else if (name == "通道6-通道11") {
|
||||
index = 5;
|
||||
videoType = "6_11";
|
||||
} else if (name == "通道11-通道16") {
|
||||
index = 10;
|
||||
videoType = "11_16";
|
||||
}
|
||||
|
||||
if (this->videoType != videoType) {
|
||||
this->videoType = videoType;
|
||||
change_video_6(index);
|
||||
}
|
||||
}
|
||||
|
||||
void frmMain::show_video_8()
|
||||
{
|
||||
videoMax = false;
|
||||
QString videoType;
|
||||
int index = 0;
|
||||
|
||||
QAction *action = (QAction *)sender();
|
||||
QString name = action->text();
|
||||
|
||||
if (name == "通道1-通道8") {
|
||||
index = 0;
|
||||
videoType = "1_8";
|
||||
} else if (name == "通道9-通道16") {
|
||||
index = 8;
|
||||
videoType = "9_16";
|
||||
}
|
||||
|
||||
if (this->videoType != videoType) {
|
||||
this->videoType = videoType;
|
||||
change_video_8(index);
|
||||
}
|
||||
}
|
||||
|
||||
void frmMain::show_video_9()
|
||||
{
|
||||
videoMax = false;
|
||||
QString videoType;
|
||||
int index = 0;
|
||||
|
||||
QAction *action = (QAction *)sender();
|
||||
QString name = action->text();
|
||||
|
||||
if (name == "通道1-通道9") {
|
||||
index = 0;
|
||||
videoType = "1_9";
|
||||
} else if (name == "通道8-通道16") {
|
||||
index = 7;
|
||||
videoType = "8_16";
|
||||
}
|
||||
|
||||
if (this->videoType != videoType) {
|
||||
this->videoType = videoType;
|
||||
change_video_9(index);
|
||||
}
|
||||
}
|
||||
|
||||
void frmMain::show_video_16()
|
||||
{
|
||||
videoMax = false;
|
||||
QString videoType;
|
||||
int index = 0;
|
||||
videoType = "1_16";
|
||||
|
||||
if (this->videoType != videoType) {
|
||||
this->videoType = videoType;
|
||||
change_video_16(index);
|
||||
}
|
||||
}
|
||||
|
||||
void frmMain::hide_video_all()
|
||||
{
|
||||
for (int i = 0; i < videoCount; i++) {
|
||||
ui->gridLayout->removeWidget(widgets.at(i));
|
||||
widgets.at(i)->setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
void frmMain::change_video(int index, int flag)
|
||||
{
|
||||
int count = 0;
|
||||
int row = 0;
|
||||
int column = 0;
|
||||
|
||||
for (int i = 0; i < videoCount; i++) {
|
||||
if (i >= index) {
|
||||
ui->gridLayout->addWidget(widgets.at(i), row, column);
|
||||
widgets.at(i)->setVisible(true);
|
||||
|
||||
count++;
|
||||
column++;
|
||||
if (column == flag) {
|
||||
row++;
|
||||
column = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == (flag * flag)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void frmMain::change_video_4(int index)
|
||||
{
|
||||
hide_video_all();
|
||||
change_video(index, 2);
|
||||
}
|
||||
|
||||
void frmMain::change_video_6(int index)
|
||||
{
|
||||
hide_video_all();
|
||||
if (index == 0) {
|
||||
ui->gridLayout->addWidget(widgets.at(0), 0, 0, 2, 2);
|
||||
ui->gridLayout->addWidget(widgets.at(1), 0, 2, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(2), 1, 2, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(3), 2, 2, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(4), 2, 1, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(5), 2, 0, 1, 1);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
widgets.at(i)->setVisible(true);
|
||||
}
|
||||
} else if (index == 5) {
|
||||
ui->gridLayout->addWidget(widgets.at(5), 0, 0, 2, 2);
|
||||
ui->gridLayout->addWidget(widgets.at(6), 0, 2, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(7), 1, 2, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(8), 2, 2, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(9), 2, 1, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(10), 2, 0, 1, 1);
|
||||
|
||||
for (int i = 5; i < 11; i++) {
|
||||
widgets.at(i)->setVisible(true);
|
||||
}
|
||||
} else if (index == 10) {
|
||||
ui->gridLayout->addWidget(widgets.at(10), 0, 0, 2, 2);
|
||||
ui->gridLayout->addWidget(widgets.at(11), 0, 2, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(12), 1, 2, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(13), 2, 2, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(14), 2, 1, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(15), 2, 0, 1, 1);
|
||||
|
||||
for (int i = 10; i < 16; i++) {
|
||||
widgets.at(i)->setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void frmMain::change_video_8(int index)
|
||||
{
|
||||
hide_video_all();
|
||||
if (index == 0) {
|
||||
ui->gridLayout->addWidget(widgets.at(0), 0, 0, 3, 3);
|
||||
ui->gridLayout->addWidget(widgets.at(1), 0, 3, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(2), 1, 3, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(3), 2, 3, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(4), 3, 3, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(5), 3, 2, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(6), 3, 1, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(7), 3, 0, 1, 1);
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
widgets.at(i)->setVisible(true);
|
||||
}
|
||||
} else if (index == 8) {
|
||||
ui->gridLayout->addWidget(widgets.at(8), 0, 0, 3, 3);
|
||||
ui->gridLayout->addWidget(widgets.at(9), 0, 3, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(10), 1, 3, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(11), 2, 3, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(12), 3, 3, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(13), 3, 2, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(14), 3, 1, 1, 1);
|
||||
ui->gridLayout->addWidget(widgets.at(15), 3, 0, 1, 1);
|
||||
|
||||
for (int i = 8; i < 16; i++) {
|
||||
widgets.at(i)->setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void frmMain::change_video_9(int index)
|
||||
{
|
||||
hide_video_all();
|
||||
change_video(index, 3);
|
||||
}
|
||||
|
||||
void frmMain::change_video_16(int index)
|
||||
{
|
||||
hide_video_all();
|
||||
change_video(index, 4);
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
#ifndef FRMMAIN_H
|
||||
#define FRMMAIN_H
|
||||
|
||||
#include <QtGui>
|
||||
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
|
||||
#include <QtWidgets>
|
||||
#endif
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class frmMain;
|
||||
}
|
||||
|
||||
class frmMain : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit frmMain(QWidget *parent = 0);
|
||||
~frmMain();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
Ui::frmMain *ui;
|
||||
|
||||
bool videoMax;
|
||||
int videoCount;
|
||||
QString videoType;
|
||||
QMenu *videoMenu;
|
||||
QList<QLabel *> widgets;
|
||||
|
||||
private slots:
|
||||
void initForm();
|
||||
void initMenu();
|
||||
|
||||
private slots:
|
||||
void play_video_all();
|
||||
void snapshot_video_one();
|
||||
void snapshot_video_all();
|
||||
|
||||
void show_video_all();
|
||||
void show_video_4();
|
||||
void show_video_6();
|
||||
void show_video_8();
|
||||
void show_video_9();
|
||||
void show_video_16();
|
||||
|
||||
void hide_video_all();
|
||||
void change_video(int index, int flag);
|
||||
void change_video_4(int index);
|
||||
void change_video_6(int index);
|
||||
void change_video_8(int index);
|
||||
void change_video_9(int index);
|
||||
void change_video_16(int index);
|
||||
};
|
||||
|
||||
#endif // FRMMAIN_H
|
|
@ -0,0 +1,64 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>frmMain</class>
|
||||
<widget class="QWidget" name="frmMain">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1000</width>
|
||||
<height>750</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="spacing">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,31 @@
|
|||
#include "frmmain.h"
|
||||
#include "qcoreapplication.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
||||
QFont font;
|
||||
font.setFamily("MicroSoft Yahei");
|
||||
font.setPixelSize(12);
|
||||
a.setFont(font);
|
||||
|
||||
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
|
||||
#if _MSC_VER
|
||||
QTextCodec *codec = QTextCodec::codecForName("gbk");
|
||||
#else
|
||||
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
||||
#endif
|
||||
QTextCodec::setCodecForLocale(codec);
|
||||
QTextCodec::setCodecForCStrings(codec);
|
||||
QTextCodec::setCodecForTr(codec);
|
||||
#else
|
||||
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
||||
QTextCodec::setCodecForLocale(codec);
|
||||
#endif
|
||||
|
||||
frmMain w;
|
||||
w.showMaximized();
|
||||
|
||||
return a.exec();
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>bg_novideo.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
After Width: | Height: | Size: 53 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 50 KiB |
After Width: | Height: | Size: 55 KiB |
After Width: | Height: | Size: 50 KiB |
After Width: | Height: | Size: 28 KiB |
|
@ -0,0 +1,24 @@
|
|||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2016-09-29T09:37:26
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = video_splite
|
||||
TEMPLATE = app
|
||||
MOC_DIR = temp/moc
|
||||
RCC_DIR = temp/rcc
|
||||
UI_DIR = temp/ui
|
||||
OBJECTS_DIR = temp/obj
|
||||
DESTDIR = bin
|
||||
|
||||
SOURCES += main.cpp
|
||||
SOURCES += frmmain.cpp
|
||||
HEADERS += frmmain.h
|
||||
FORMS += frmmain.ui
|
||||
RESOURCES += main.qrc
|
||||
CONFIG += warn_off
|