feat: 新增UI样式

chen
cbwu 4 weeks ago
parent 6ac274af2f
commit bfbddcb77f

@ -5,8 +5,15 @@ project(VideoClient LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
# set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTORCC ON)
find_package(Qt6 6.5 REQUIRED COMPONENTS Core Widgets OpenGLWidgets Network SerialPort)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")
include(QWindowKit)
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets OpenGLWidgets Network SerialPort)
qt_standard_project_setup()

@ -0,0 +1,9 @@
include(fetchcontent)
fetchcontent_declare( QWindowKit #库名字
GIT_REPOSITORY https://github.com/stdware/qwindowkit #
GIT_TAG 1.3.2 #
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ext/QWindowKit #
)
fetchcontent_makeavailable(QWindowKit)

@ -0,0 +1 @@
Subproject commit bc03db3759e0d8644e626adcbda066ccb2c30062

@ -1,4 +1,5 @@
qt_add_executable(VideoClient
WIN32 MACOSX_BUNDLE
main.cpp
@ -6,25 +7,44 @@ qt_add_executable(VideoClient
mainwindow.h
mainwindow.ui
global.h global.cpp
communicationsettingdlg.h communicationsettingdlg.cpp communicationsettingdlg.ui
commandwidget.h commandwidget.cpp commandwidget.ui
communicationsettingdlg.h communicationsettingdlg.cpp
commandwidget.h commandwidget.cpp
)
qt6_add_resources(VideoClient "resources"
PREFIX "/"
FILES "resources/res.qrc"
)
qt_add_ui(VideoClient SOURCES
commandwidget.ui
communicationsettingdlg.ui
)
set(3RDPARTY_DIR ${CMAKE_CURRENT_LIST_DIR}/3rdparty)
set(FFMPEG_DIR ${3RDPARTY_DIR}/ffmpeg)
add_subdirectory(video)
add_subdirectory(3rdparty)
add_subdirectory(shared)
target_link_libraries(VideoClient
PRIVATE
Qt::Core
Qt::Gui
Qt::Widgets
Qt6::OpenGLWidgets
Qt6::Network
Qt6::SerialPort
video
QWindowKit::Widgets
WidgetFrame
)
#
target_include_directories(VideoClient PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/)
include(GNUInstallDirs)

@ -6,6 +6,9 @@ CommandWidget::CommandWidget(QWidget *parent)
: QWidget(parent), ui(new Ui::CommandWidget) {
ui->setupUi(this);
ui->stopConnectionToolBtn->setDisabled(true);
ui->settingToolBtn->setIcon(QIcon(":/images/settings.png"));
ui->settingToolBtn->setText("通信设置");
ui->settingToolBtn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
udpSocket = new QUdpSocket(this);
connect(&settingDlg, &CommunicationSettingDlg::sendErrorMessage, this,

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>897</width>
<width>1039</width>
<height>105</height>
</rect>
</property>
@ -24,7 +24,7 @@
<number>4</number>
</property>
<property name="bottomMargin">
<number>2</number>
<number>4</number>
</property>
<item>
<spacer name="horizontalSpacer_2">
@ -93,6 +93,9 @@
</property>
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="bottomMargin">
<number>6</number>
</property>
<property name="spacing">
<number>12</number>
</property>

@ -6,6 +6,8 @@ CommunicationSettingDlg::CommunicationSettingDlg(QWidget *parent)
: QDialog(parent), ui(new Ui::CommunicationSettingDlg) {
ui->setupUi(this);
this->setWindowTitle("通信设置");
initCombobox();
initNetworkSetting();
}

@ -38,19 +38,25 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>2</number>
<number>4</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
<number>4</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout" columnstretch="1,0">
<property name="leftMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="horizontalSpacing">
<number>7</number>
</property>

@ -3,6 +3,7 @@
#include "mainwindow.h"
int main(int argc, char *argv[]) {
QGuiApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
QApplication a(argc, argv);
MainWindow w;

@ -1,13 +1,63 @@
#include "mainwindow.h"
#include <QWKWidgets/qwkwidgetsglobal.h>
#include <QWKWidgets/widgetwindowagent.h>
#include <QList>
#include "ui_mainwindow.h"
#include "widgetframe/windowbar.h"
#include "widgetframe/windowbutton.h"
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
this->setWindowTitle("载荷视频播放软件");
// windowAgent = new QWK::WidgetWindowAgent(this);
// windowAgent->setup(this);
// auto windowBar = new QWK::WindowBar();
// auto iconButton = new QWK::WindowButton();
/*
iconButton->setObjectName(QStringLiteral("icon-button"));
iconButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto minButton = new QWK::WindowButton();
minButton->setObjectName(QStringLiteral("min-button"));
minButton->setProperty("system-button", true);
minButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto maxButton = new QWK::WindowButton();
maxButton->setCheckable(true);
maxButton->setObjectName(QStringLiteral("max-button"));
maxButton->setProperty("system-button", true);
maxButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto closeButton = new QWK::WindowButton();
closeButton->setObjectName(QStringLiteral("close-button"));
closeButton->setProperty("system-button", true);
closeButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
windowBar->setIconButton(iconButton);
windowBar->setMinButton(minButton);
windowBar->setMaxButton(maxButton);
windowBar->setCloseButton(closeButton);
windowAgent->setTitleBar(windowBar);
*/
// apply the qss
QFile qssfile(":/Qss/qss.qss");
if (qssfile.open(QFile::ReadOnly)) {
// file.open(QFile::ReadOnly);
QString style = QLatin1String(qssfile.readAll());
qApp->setStyleSheet(style);
// qDebug()<<style;
qssfile.close();
} else {
qDebug() << "Open file fail " << Qt::endl;
}
// QList<QString> list;
// list.append("rtmp://liteavapp.qcloud.com/live/liteavdemoplayerstreamid");
// list.append("rtsp://182.92.130.23/nmyj/video");

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

@ -4,6 +4,17 @@ QWidget{
}
/************************QPushButton按钮设置****************************/
QPushButton{
background-color:rgb(50,50,50);
color:#2f3640;
background-color: #f5f6fa;
border-color: #2f3640;
border-radius: 6px;
border-style: solid;
border-width: 1px;
padding: 5px;
}
/*hover样式*/
QPushButton:hover{
background-color: rgb(155,155,155);
@ -12,15 +23,46 @@ QPushButton:hover{
QPushButton:pressed{
background-color: rgb(180,238,180);
}
QPushButton{
background-color:rgb(50,50,50);
color:rgb(255,255,255);
border-radius: 2px;
border: 1px groove gray;
border-style: outset;
font: 10pt "微软雅黑";
/**按钮失能情况下样式**/
QPushButton::disabled {
color: #b0b0b0;
background-color: #cccccc;
border: 1px solid #cccccc;
opacity: 0.7;
}
/**************************QToolButton设置*************************/
QToolButton{
font: 10pt '微软雅黑';
color: rgba(0,0,0,200); /*#2f3640*/
background-color: #f5f6fa;
border-color: #2f3640;
border-radius: 15px;
border-style: solid;
border-width: 2px;
padding: 5px;
}
/**鼠标停留在按钮上的样式**/
QToolButton::hover{
color: #FFFFFF;
background-color: #718093;
border-color: #2f3640;
}
/**按钮失能情况下样式**/
QToolButton::disabled {
color: #b0b0b0;
background-color: #cccccc;
border: 1px solid #cccccc;
opacity: 0.7;
}
/**************************QLineEdit编辑框设置*************************/
QLineEdit{
color:rgb(255,255,255);
@ -170,8 +212,8 @@ QSpinBox{
/***************************QGroupBox设置***********************/
QGroupBox{
border:1px solid rgb(255,255,255);
border-radius:5px;
margin-top:2ex;/*文字在方框中位置的偏离度*/
border-radius:6px;
margin-top:10px;/*文字在方框中位置的偏离度*/
color:rgb(153,255,153);
font-family:"微软雅黑";
font-size:12pt;

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Before

Width:  |  Height:  |  Size: 81 KiB

After

Width:  |  Height:  |  Size: 81 KiB

Before

Width:  |  Height:  |  Size: 858 B

After

Width:  |  Height:  |  Size: 858 B

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Before

Width:  |  Height:  |  Size: 951 B

After

Width:  |  Height:  |  Size: 951 B

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Before

Width:  |  Height:  |  Size: 839 B

After

Width:  |  Height:  |  Size: 839 B

Before

Width:  |  Height:  |  Size: 863 B

After

Width:  |  Height:  |  Size: 863 B

Before

Width:  |  Height:  |  Size: 872 B

After

Width:  |  Height:  |  Size: 872 B

Before

Width:  |  Height:  |  Size: 817 B

After

Width:  |  Height:  |  Size: 817 B

Before

Width:  |  Height:  |  Size: 837 B

After

Width:  |  Height:  |  Size: 837 B

Before

Width:  |  Height:  |  Size: 838 B

After

Width:  |  Height:  |  Size: 838 B

Before

Width:  |  Height:  |  Size: 863 B

After

Width:  |  Height:  |  Size: 863 B

Before

Width:  |  Height:  |  Size: 854 B

After

Width:  |  Height:  |  Size: 854 B

Before

Width:  |  Height:  |  Size: 760 B

After

Width:  |  Height:  |  Size: 760 B

Before

Width:  |  Height:  |  Size: 863 B

After

Width:  |  Height:  |  Size: 863 B

@ -0,0 +1,13 @@
<RCC>
<qresource prefix="/">
<file>Qss/qss.qss</file>
<file>images/down.png</file>
<file>images/left.png</file>
<file>images/right.png</file>
<file>images/SDFP.png</file>
<file>images/SDFP3.png</file>
<file>images/settings.png</file>
<file>images/up.png</file>
<file>images/wifi4G.png</file>
</qresource>
</RCC>

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before

Width:  |  Height:  |  Size: 465 B

After

Width:  |  Height:  |  Size: 465 B

Before

Width:  |  Height:  |  Size: 464 B

After

Width:  |  Height:  |  Size: 464 B

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before

Width:  |  Height:  |  Size: 330 B

After

Width:  |  Height:  |  Size: 330 B

Before

Width:  |  Height:  |  Size: 328 B

After

Width:  |  Height:  |  Size: 328 B

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

@ -0,0 +1 @@
add_subdirectory(widgetframe)

@ -0,0 +1,37 @@
project(WidgetFrame)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
file(GLOB _src *.h *.cpp)
add_library(${PROJECT_NAME} STATIC "")
target_sources(${PROJECT_NAME}
PRIVATE
windowbar.cpp
windowbutton.cpp
PUBLIC
windowbar_p.h
windowbutton.h
windowbutton_p.h
)
qt6_add_resources(${PROJECT_NAME} "resources"
PREFIX "/"
FILES "resources/shared.qrc"
)
target_link_libraries(${PROJECT_NAME} PRIVATE
Qt6::Core
Qt6::Gui
Qt6::Widgets
)
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED TRUE
)
target_include_directories(${PROJECT_NAME} PUBLIC . ..)

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

@ -0,0 +1,11 @@
<RCC>
<qresource prefix="/">
<file>window-bar/close.svg</file>
<file>window-bar/fullscreen.svg</file>
<file>window-bar/maximize.svg</file>
<file>window-bar/minimize.svg</file>
<file>window-bar/restore.svg</file>
<file>window-bar/more-line.svg</file>
<file>app/example.png</file>
</qresource>
</RCC>

@ -0,0 +1,15 @@
<svg id="图层_1" data-name="图层 1" xmlns="http://www.w3.org/2000/svg" width="10.88" height="10.88"
viewBox="0 0 10.88 10.88">
<defs>
<style>
.cls-1 {
fill: none;
stroke: white;
stroke-miterlimit: 10;
stroke-width: 1.25px;
}
</style>
</defs>
<line class="cls-1" x1="0.44" y1="0.44" x2="10.44" y2="10.44" />
<line class="cls-1" x1="0.44" y1="10.44" x2="10.44" y2="0.44" />
</svg>

After

Width:  |  Height:  |  Size: 444 B

@ -0,0 +1,11 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1594017175519"
class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1933"
xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16">
<defs>
<style type="text/css"></style>
</defs>
<path
d="M874.666667 128h-170.666667a21.333333 21.333333 0 0 0 0 42.666667h119.168l-176.917333 176.917333a21.333333 21.333333 0 1 0 30.165333 30.165333L853.333333 200.832V320a21.333333 21.333333 0 0 0 42.666667 0V149.333333a21.333333 21.333333 0 0 0-21.333333-21.333333zM347.584 646.250667L170.666667 823.168V704a21.333333 21.333333 0 0 0-42.666667 0v170.666667a21.333333 21.333333 0 0 0 21.333333 21.333333h170.666667a21.333333 21.333333 0 0 0 0-42.666667H200.832l176.917333-176.917333a21.333333 21.333333 0 0 0-30.165333-30.165333zM874.666667 682.666667a21.333333 21.333333 0 0 0-21.333334 21.333333v119.168l-176.917333-176.917333a21.333333 21.333333 0 0 0-30.165333 30.165333L823.168 853.333333H704a21.333333 21.333333 0 0 0 0 42.666667h170.666667a21.333333 21.333333 0 0 0 21.333333-21.333333v-170.666667a21.333333 21.333333 0 0 0-21.333333-21.333333zM200.832 170.666667H320a21.333333 21.333333 0 0 0 0-42.666667H149.333333a21.333333 21.333333 0 0 0-21.333333 21.333333v170.666667a21.333333 21.333333 0 0 0 42.666667 0V200.832l176.917333 176.917333a21.333333 21.333333 0 0 0 30.165333-30.165333z"
fill="#ffffff" p-id="1934"></path>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

@ -0,0 +1,12 @@
<svg id="图层_1" data-name="图层 1" xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 10 10">
<defs>
<style>
.cls-1 {
fill: none;
stroke: white;
stroke-miterlimit: 10;
}
</style>
</defs>
<rect class="cls-1" x="0.5" y="0.5" width="9" height="9" />
</svg>

After

Width:  |  Height:  |  Size: 328 B

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.3.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px"
y="0px" viewBox="0 0 10 10" style="enable-background:new 0 0 10 10;" xml:space="preserve">
<style type="text/css">
.st0 {
fill: white;
}
</style>
<rect y="4.5" class="st0" width="10" height="1" />
</svg>

After

Width:  |  Height:  |  Size: 467 B

@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
<path fill="none" d="M0 0h24v24H0z" />
<path fill="white"
d="M4.5 10.5c-.825 0-1.5.675-1.5 1.5s.675 1.5 1.5 1.5S6 12.825 6 12s-.675-1.5-1.5-1.5zm15 0c-.825 0-1.5.675-1.5 1.5s.675 1.5 1.5 1.5S21 12.825 21 12s-.675-1.5-1.5-1.5zm-7.5 0c-.825 0-1.5.675-1.5 1.5s.675 1.5 1.5 1.5 1.5-.675 1.5-1.5-.675-1.5-1.5-1.5z" />
</svg>

After

Width:  |  Height:  |  Size: 419 B

@ -0,0 +1,16 @@
<svg id="图层_1" data-name="图层 1" xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12">
<defs>
<style>
.cls-1 {
fill: none;
stroke: white;
stroke-miterlimit: 10;
}
</style>
</defs>
<rect class="cls-1" x="0.5" y="2.5" width="9" height="9" />
<line class="cls-1" x1="2.5" y1="2.5" x2="2.5" y2="0.5" />
<line class="cls-1" x1="12" y1="0.5" x2="2" y2="0.5" />
<line class="cls-1" x1="11.5" y1="10" x2="11.5" />
<line class="cls-1" x1="10" y1="9.5" x2="12" y2="9.5" />
</svg>

After

Width:  |  Height:  |  Size: 559 B

@ -0,0 +1,298 @@
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
// SPDX-License-Identifier: Apache-2.0
#include "windowbar.h"
#include "windowbar_p.h"
#include <QtCore/QDebug>
#include <QtCore/QLocale>
#include <QtGui/QtEvents>
namespace QWK {
WindowBarPrivate::WindowBarPrivate() {
w = nullptr;
autoTitle = true;
autoIcon = false;
}
WindowBarPrivate::~WindowBarPrivate() = default;
void WindowBarPrivate::init() {
Q_Q(WindowBar);
layout = new QHBoxLayout();
if (QLocale::system().textDirection() == Qt::RightToLeft) {
layout->setDirection(QBoxLayout::RightToLeft);
}
layout->setContentsMargins(QMargins());
layout->setSpacing(0);
for (int i = IconButton; i <= CloseButton; ++i) {
insertDefaultSpace(i);
}
q->setLayout(layout);
}
void WindowBarPrivate::setWidgetAt(int index, QWidget *widget) {
auto item = layout->takeAt(index);
auto orgWidget = item->widget();
if (orgWidget) {
orgWidget->deleteLater();
}
delete item;
if (!widget) {
insertDefaultSpace(index);
} else {
layout->insertWidget(index, widget);
}
}
QWidget *WindowBarPrivate::takeWidgetAt(int index) {
auto item = layout->itemAt(index);
auto orgWidget = item->widget();
if (orgWidget) {
item = layout->takeAt(index);
delete item;
insertDefaultSpace(index);
}
return orgWidget;
}
WindowBar::WindowBar(QWidget *parent) : WindowBar(*new WindowBarPrivate(), parent) {
}
WindowBar::~WindowBar() = default;
QMenuBar *WindowBar::menuBar() const {
Q_D(const WindowBar);
return static_cast<QMenuBar *>(d->widgetAt(WindowBarPrivate::MenuWidget));
}
QLabel *WindowBar::titleLabel() const {
Q_D(const WindowBar);
return static_cast<QLabel *>(d->widgetAt(WindowBarPrivate::TitleLabel));
}
QAbstractButton *WindowBar::iconButton() const {
Q_D(const WindowBar);
return static_cast<QAbstractButton *>(d->widgetAt(WindowBarPrivate::IconButton));
}
QAbstractButton *WindowBar::minButton() const {
Q_D(const WindowBar);
return static_cast<QAbstractButton *>(d->widgetAt(WindowBarPrivate::MinimumButton));
}
QAbstractButton *WindowBar::maxButton() const {
Q_D(const WindowBar);
return static_cast<QAbstractButton *>(d->widgetAt(WindowBarPrivate::MaximumButton));
}
QAbstractButton *WindowBar::closeButton() const {
Q_D(const WindowBar);
return static_cast<QAbstractButton *>(d->widgetAt(WindowBarPrivate::CloseButton));
}
void WindowBar::setMenuBar(QMenuBar *menuBar) {
Q_D(WindowBar);
auto org = takeMenuBar();
if (org)
org->deleteLater();
if (!menuBar)
return;
d->setWidgetAt(WindowBarPrivate::MenuWidget, menuBar);
menuBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
}
void WindowBar::setTitleLabel(QLabel *label) {
Q_D(WindowBar);
auto org = takeTitleLabel();
if (org)
org->deleteLater();
if (!label)
return;
d->setWidgetAt(WindowBarPrivate::TitleLabel, label);
if (d->autoTitle && d->w)
label->setText(d->w->windowTitle());
label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
}
void WindowBar::setIconButton(QAbstractButton *btn) {
Q_D(WindowBar);
auto org = takeIconButton();
if (org)
org->deleteLater();
if (!btn)
return;
d->setWidgetAt(WindowBarPrivate::IconButton, btn);
if (d->autoIcon && d->w)
btn->setIcon(d->w->windowIcon());
btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
}
void WindowBar::setMinButton(QAbstractButton *btn) {
Q_D(WindowBar);
auto org = takeMinButton();
if (org)
org->deleteLater();
if (!btn)
return;
d->setWidgetAt(WindowBarPrivate::MinimumButton, btn);
connect(btn, &QAbstractButton::clicked, this, &WindowBar::minimizeRequested);
}
void WindowBar::setMaxButton(QAbstractButton *btn) {
Q_D(WindowBar);
auto org = takeMaxButton();
if (org)
org->deleteLater();
if (!btn)
return;
d->setWidgetAt(WindowBarPrivate::MaximumButton, btn);
connect(btn, &QAbstractButton::clicked, this, &WindowBar::maximizeRequested);
}
void WindowBar::setCloseButton(QAbstractButton *btn) {
Q_D(WindowBar);
auto org = takeCloseButton();
if (org)
org->deleteLater();
if (!btn)
return;
d->setWidgetAt(WindowBarPrivate::CloseButton, btn);
connect(btn, &QAbstractButton::clicked, this, &WindowBar::closeRequested);
}
QMenuBar *WindowBar::takeMenuBar() {
Q_D(WindowBar);
return static_cast<QMenuBar *>(d->takeWidgetAt(WindowBarPrivate::MenuWidget));
}
QLabel *WindowBar::takeTitleLabel() {
Q_D(WindowBar);
return static_cast<QLabel *>(d->takeWidgetAt(WindowBarPrivate::TitleLabel));
}
QAbstractButton *WindowBar::takeIconButton() {
Q_D(WindowBar);
return static_cast<QAbstractButton *>(d->takeWidgetAt(WindowBarPrivate::IconButton));
}
QAbstractButton *WindowBar::takeMinButton() {
Q_D(WindowBar);
auto btn = static_cast<QAbstractButton *>(d->takeWidgetAt(WindowBarPrivate::MinimumButton));
if (!btn) {
return nullptr;
}
disconnect(btn, &QAbstractButton::clicked, this, &WindowBar::minimizeRequested);
return btn;
}
QAbstractButton *WindowBar::takeMaxButton() {
Q_D(WindowBar);
auto btn = static_cast<QAbstractButton *>(d->takeWidgetAt(WindowBarPrivate::MaximumButton));
if (!btn) {
return nullptr;
}
disconnect(btn, &QAbstractButton::clicked, this, &WindowBar::maximizeRequested);
return btn;
}
QAbstractButton *WindowBar::takeCloseButton() {
Q_D(WindowBar);
auto btn = static_cast<QAbstractButton *>(d->takeWidgetAt(WindowBarPrivate::CloseButton));
if (!btn) {
return nullptr;
}
disconnect(btn, &QAbstractButton::clicked, this, &WindowBar::closeRequested);
return btn;
}
QWidget *WindowBar::hostWidget() const {
Q_D(const WindowBar);
return d->w;
}
void WindowBar::setHostWidget(QWidget *w) {
Q_D(WindowBar);
QWidget *org = d->w;
if (org) {
org->removeEventFilter(this);
}
d_ptr->w = w;
if (w) {
w->installEventFilter(this);
}
}
bool WindowBar::titleFollowWindow() const {
Q_D(const WindowBar);
return d->autoTitle;
}
void WindowBar::setTitleFollowWindow(bool value) {
Q_D(WindowBar);
d->autoTitle = value;
}
bool WindowBar::iconFollowWindow() const {
Q_D(const WindowBar);
return d->autoIcon;
}
void WindowBar::setIconFollowWindow(bool value) {
Q_D(WindowBar);
d->autoIcon = value;
}
bool WindowBar::eventFilter(QObject *obj, QEvent *event) {
Q_D(WindowBar);
auto w = d->w;
if (obj == w) {
QAbstractButton *iconBtn = iconButton();
QLabel *label = titleLabel();
QAbstractButton *maxBtn = maxButton();
switch (event->type()) {
case QEvent::WindowIconChange: {
if (d_ptr->autoIcon && iconBtn) {
iconBtn->setIcon(w->windowIcon());
iconChanged(w->windowIcon());
}
break;
}
case QEvent::WindowTitleChange: {
if (d_ptr->autoTitle && label) {
label->setText(w->windowTitle());
titleChanged(w->windowTitle());
}
break;
}
case QEvent::WindowStateChange: {
if (maxBtn) {
maxBtn->setChecked(w->isMaximized());
}
break;
}
default:
break;
}
}
return QWidget::eventFilter(obj, event);
}
void WindowBar::titleChanged(const QString &text) {
Q_UNUSED(text)
}
void WindowBar::iconChanged(const QIcon &icon){Q_UNUSED(icon)}
WindowBar::WindowBar(WindowBarPrivate &d, QWidget *parent)
: QFrame(parent), d_ptr(&d) {
d.q_ptr = this;
d.init();
}
}

@ -0,0 +1,74 @@
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
// SPDX-License-Identifier: Apache-2.0
#ifndef WINDOWBAR_H
#define WINDOWBAR_H
#include <QFrame>
#include <QAbstractButton>
#include <QMenuBar>
#include <QLabel>
namespace QWK {
class WindowBarPrivate;
class WindowBar : public QFrame {
Q_OBJECT
Q_DECLARE_PRIVATE(WindowBar)
public:
explicit WindowBar(QWidget *parent = nullptr);
~WindowBar();
public:
QMenuBar *menuBar() const;
QLabel *titleLabel() const;
QAbstractButton *iconButton() const;
QAbstractButton *minButton() const;
QAbstractButton *maxButton() const;
QAbstractButton *closeButton() const;
void setMenuBar(QMenuBar *menuBar);
void setTitleLabel(QLabel *label);
void setIconButton(QAbstractButton *btn);
void setMinButton(QAbstractButton *btn);
void setMaxButton(QAbstractButton *btn);
void setCloseButton(QAbstractButton *btn);
QMenuBar *takeMenuBar();
QLabel *takeTitleLabel();
QAbstractButton *takeIconButton();
QAbstractButton *takeMinButton();
QAbstractButton *takeMaxButton();
QAbstractButton *takeCloseButton();
QWidget *hostWidget() const;
void setHostWidget(QWidget *w);
bool titleFollowWindow() const;
void setTitleFollowWindow(bool value);
bool iconFollowWindow() const;
void setIconFollowWindow(bool value);
Q_SIGNALS:
void minimizeRequested();
void maximizeRequested(bool max = false);
void closeRequested();
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
virtual void titleChanged(const QString &text);
virtual void iconChanged(const QIcon &icon);
protected:
WindowBar(WindowBarPrivate &d, QWidget *parent = nullptr);
QScopedPointer<WindowBarPrivate> d_ptr;
};
}
#endif // WINDOWBAR_H

@ -0,0 +1,57 @@
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
// SPDX-License-Identifier: Apache-2.0
#ifndef WINDOWBARPRIVATE_H
#define WINDOWBARPRIVATE_H
#include <QBoxLayout>
#include "windowbar.h"
namespace QWK {
class WindowBarPrivate {
Q_DECLARE_PUBLIC(WindowBar)
public:
WindowBarPrivate();
virtual ~WindowBarPrivate();
void init();
WindowBar *q_ptr;
QWidget *w;
bool autoTitle;
bool autoIcon;
enum WindowBarItem {
IconButton,
MenuWidget,
TitleLabel,
MinimumButton,
MaximumButton,
CloseButton,
};
QHBoxLayout *layout;
inline QWidget *widgetAt(int index) const {
return layout->itemAt(index)->widget();
}
void setWidgetAt(int index, QWidget *widget);
QWidget *takeWidgetAt(int index);
inline void insertDefaultSpace(int index) {
layout->insertSpacerItem(index, new QSpacerItem(0, 0));
}
private:
Q_DISABLE_COPY(WindowBarPrivate)
};
}
#endif // WINDOWBARPRIVATE_H

@ -0,0 +1,94 @@
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
// SPDX-License-Identifier: Apache-2.0
#include "windowbutton.h"
#include "windowbutton_p.h"
#include <QtCore/QDebug>
#include <QtGui/QtEvents>
namespace QWK {
WindowButtonPrivate::WindowButtonPrivate() = default;
WindowButtonPrivate::~WindowButtonPrivate() = default;
void WindowButtonPrivate::init() {
}
void WindowButtonPrivate::reloadIcon() {
Q_Q(WindowButton);
if (!q->isEnabled() && !iconDisabled.isNull()) {
q->setIcon(iconDisabled);
return;
}
if (q->isChecked() && !iconChecked.isNull()) {
q->setIcon(iconChecked);
return;
}
if (!iconNormal.isNull()) {
q->setIcon(iconNormal);
}
}
WindowButton::WindowButton(QWidget *parent) : WindowButton(*new WindowButtonPrivate(), parent) {
}
WindowButton::~WindowButton() = default;
QIcon WindowButton::iconNormal() const {
Q_D(const WindowButton);
return d->iconNormal;
}
void WindowButton::setIconNormal(const QIcon &icon) {
Q_D(WindowButton);
d->iconNormal = icon;
d->reloadIcon();
}
QIcon WindowButton::iconChecked() const {
Q_D(const WindowButton);
return d->iconChecked;
}
void WindowButton::setIconChecked(const QIcon &icon) {
Q_D(WindowButton);
d->iconChecked = icon;
d->reloadIcon();
}
QIcon WindowButton::iconDisabled() const {
Q_D(const WindowButton);
return d->iconDisabled;
}
void WindowButton::setIconDisabled(const QIcon &icon) {
Q_D(WindowButton);
d->iconDisabled = icon;
d->reloadIcon();
}
void WindowButton::checkStateSet() {
Q_D(WindowButton);
d->reloadIcon();
}
void WindowButton::mouseDoubleClickEvent(QMouseEvent *event) {
if (event->button() == Qt::LeftButton) {
Q_EMIT doubleClicked();
}
}
WindowButton::WindowButton(WindowButtonPrivate &d, QWidget *parent)
: QPushButton(parent), d_ptr(&d) {
d.q_ptr = this;
d.init();
}
}

@ -0,0 +1,50 @@
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
// SPDX-License-Identifier: Apache-2.0
#ifndef WINDOWBUTTON_H
#define WINDOWBUTTON_H
#include <QtWidgets/QPushButton>
namespace QWK {
class WindowButtonPrivate;
class WindowButton : public QPushButton {
Q_OBJECT
Q_DECLARE_PRIVATE(WindowButton)
Q_PROPERTY(QIcon iconNormal READ iconNormal WRITE setIconNormal FINAL)
Q_PROPERTY(QIcon iconChecked READ iconChecked WRITE setIconChecked FINAL)
Q_PROPERTY(QIcon iconDisabled READ iconDisabled WRITE setIconDisabled FINAL)
public:
explicit WindowButton(QWidget *parent = nullptr);
~WindowButton();
public:
QIcon iconNormal() const;
void setIconNormal(const QIcon &icon);
QIcon iconChecked() const;
void setIconChecked(const QIcon &icon);
QIcon iconDisabled() const;
void setIconDisabled(const QIcon &icon);
Q_SIGNALS:
void doubleClicked();
protected:
void checkStateSet() override;
void mouseDoubleClickEvent(QMouseEvent *event) override;
protected:
WindowButton(WindowButtonPrivate &d, QWidget *parent = nullptr);
QScopedPointer<WindowButtonPrivate> d_ptr;
};
}
#endif // WINDOWBUTTON_H

@ -0,0 +1,31 @@
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
// SPDX-License-Identifier: Apache-2.0
#ifndef WINDOWBUTTONPRIVATE_H
#define WINDOWBUTTONPRIVATE_H
#include "windowbutton.h"
namespace QWK {
class WindowButtonPrivate {
Q_DECLARE_PUBLIC(WindowButton)
public:
WindowButtonPrivate();
virtual ~WindowButtonPrivate();
void init();
WindowButton *q_ptr;
QIcon iconNormal;
QIcon iconChecked;
QIcon iconDisabled;
void reloadIcon();
};
}
#endif // WINDOWBUTTONPRIVATE_H
Loading…
Cancel
Save