Skip to content

Commit

Permalink
修复了SystemIcon显示Menu的问题,但可能还有些隐患,Menu的部分功能还未完善,如果想要使用该功能还得等等
Browse files Browse the repository at this point in the history
  • Loading branch information
zjhzzy committed Jul 26, 2023
1 parent 69a915c commit e034cdb
Show file tree
Hide file tree
Showing 21 changed files with 189 additions and 222 deletions.
36 changes: 5 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,16 @@ FlareUI库是一个基于Qt库扩展的UI库,是为了开发者减少使用Qss

## 功能特性

1. 较为方便的 API<br>比如在编写程序时不必要为了一些繁琐的操作去重写控件,只需要写一段代码

注:目前FlareWindow类已被删除,将来可能会写一个其他风格的窗口

```cpp
#include "FlareWindow.h"
#include "PushButton.h"
#include <QApplication>
int main(int argc, char* argv[]) {
Q_INIT_RESOURCE(FlareWindow);
QApplication a(argc, argv);
Flare::FlareWindow MainWindow;
Flare::PushButton button("Hello Falre!", &MainWindow);
MainWindow.resize(200, 200);
button.move(40,90);
button.resize(120, 20);
MainWindow.show();
return a.exec();
}
```
便可以实现
![窗口代码](assets/MainWindow.png)
2. 基于Mac的风格,一般实现一种风格需要编写很多代码,这里我将其实现了出来,你只需要new就可以享受成果了
1. 较为方便的 API<br>比如在编写程序时不必要为了一些繁琐的操作去重写控件,只需要写一段代码<br>我们封装了一些颜色,以便于快速开发,无需重载paintEvent去绘制
2. 美观和一致性<br>UI大部分控件都采用圆角矩形,让本库的主风格更加现代化以及美观<br>当然如果不喜欢圆角矩形可以通过设置将其设置为非圆角矩形

## 开发环境

使用的是 **Qt6.6.0** 当然这不是很重要,因为代码并没有用到新版本的特性,这是基于QtWidget的,我对于qml不太熟悉所以没搞
使用的是 **Qt6.6.0 Cpp17** 当然这不是很重要,因为代码并没有用到新版本的特性,这是基于QtWidget的,我对于qml不太熟悉所以没搞

## 安装指南

这个晚些,我写了半天的Bug还没修复
这个就算了吧我自己都没太明白咋搞,你git下去之后自己看看cmake里面有啥要修改的就改了<br>一般要改的也就那么几个路径,改完之后直接构建就可以了,之后的流程都是一样的所以我就不多说了

## 使用示例

Expand Down Expand Up @@ -89,6 +63,6 @@ FlareUI库是一个基于Qt库扩展的UI库,是为了开发者减少使用Qss

## 相关资源

我的博客:[zjhzzy](zjhzzy.github.io)
我的博客:[zjhzzy](https://zjhzzy.github.io)

我会在上面发布一些关于这个库的进展以及一些示例
4 changes: 3 additions & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

This is a UI library based on Qt, which offers modern and visually appealing controls and UI features, fully compatible with Qt's functionality and advantages.

[Chinese](README.md)


[Chinese](README.md)

## Project Description

Expand Down
Binary file removed image/closebutton-hover.png
Binary file not shown.
Binary file removed image/closebutton.png
Binary file not shown.
Binary file removed image/maxbutton-hover.png
Binary file not shown.
Binary file removed image/maxbutton.png
Binary file not shown.
Binary file removed image/minibutton-hover.png
Binary file not shown.
Binary file removed image/minibutton.png
Binary file not shown.
Binary file removed image/restorebutton-hover.png
Binary file not shown.
Binary file removed image/restorebutton.png
Binary file not shown.
22 changes: 13 additions & 9 deletions include/FlareUI/BaseButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ typedef float_t f32;
namespace Flare{
class FLARE_EXPORT BaseButton : public QAbstractButton {
Q_OBJECT
private:
bool isPress;
bool isAbove;
bool isIcon;
QIcon* buttonIcon;
QIcon* buttonHoverIcon;
QIcon* buttonPressedIcon;

protected:
void enterEvent(QEnterEvent* event) override;
void leaveEvent(QEvent* event) override;
Expand All @@ -28,15 +22,20 @@ namespace Flare{
QIcon buttonIcon;
QIcon buttonHoverIcon;
QIcon buttonPressedIcon;
Icon();
Icon setAllIcon(const QIcon& icon);
};

bool IsPress() const;
bool IsAbove() const;

void setAllIcon(const QIcon& icon);
void setIcon(const Icon& icon);
bool isSetIcon() const;
void setIcon(Icon* icon);
bool IsIcon() const;

void setButtonIcon(const QIcon& icon);
void setButtonHoverIcon(const QIcon& icon);
void setButtonPressedIcon(const QIcon& icon);

QIcon ButtonIcon();
QIcon ButtonHoverIcon();
Expand All @@ -46,6 +45,11 @@ namespace Flare{
void moveAbove();
void leaveAbove();

private:
bool isPress;
bool isAbove;
bool isIcon;
Icon* buttonIcon;
};
}

Expand Down
17 changes: 8 additions & 9 deletions include/FlareUI/ListView.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#ifndef FLARELIST_LISTVIEW_H
#define FLARELIST_LISTVIEW_H

#include "QtWidgets/qwidget.h"
#include "Widget.h"
#include <QList>
#include <QWheelEvent>
Expand All @@ -16,13 +15,13 @@ class FLARE_EXPORT ListView : public Widget {

QList<QWidget *> *WidgetList;

int Spacing;
int spacing;

int MarginLeft;
int marginLeft;

bool IsScrollable;
bool isScrollable;

int MoveSpeed;
int moveSpeed;
protected:
void showEvent(QShowEvent *event) override;

Expand All @@ -49,13 +48,13 @@ class FLARE_EXPORT ListView : public Widget {

void setMoveSpeed(const int &s);

int spacing() const;
int Spacing() const;

int marginLeft() const;
int MarginLeft() const;

bool isScrollable() const;
bool IsScrollable() const;

int moveSpeed() const;
int MoveSpeed() const;
};
}

Expand Down
35 changes: 13 additions & 22 deletions include/FlareUI/PushButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,20 @@
namespace Flare {
class FLARE_EXPORT PushButton : public BaseButton {
Q_OBJECT
private:
QColor* buttonBackColor;
QColor* buttonBackHoverColor;
QColor* buttonBackPressedColor;
QColor* buttonBackBrushColor;
QColor* buttonBackBrushHoverColor;
QColor* buttonBackBrushPressedColor;
QColor* buttonTextColor;
QColor* buttonTextHoverColor;
QColor* buttonTextPressedColor;
f32 xRadius;
f32 yRadius;
protected:
void paintEvent(QPaintEvent* event) override;
public:
struct Color {
QColor buttonBackColor;
QColor buttonBackHoverColor;
QColor buttonBackPressedColor;
QColor buttonBackPenColor;
QColor buttonBackPenHoverColor;
QColor buttonBackPenPressedColor;
QColor buttonBackBrushColor;
QColor buttonBackBrushHoverColor;
QColor buttonBackBrushPressedColor;
QColor buttonTextColor;
QColor buttonTextHoverColor;
QColor buttonTextPressedColor;
Color();
Color setAllBackColor(const QColor& color);
Color setAllPenColor(const QColor& color);
Color setAllBrushColor(const QColor& color);
Expand All @@ -43,28 +32,30 @@ namespace Flare {

explicit PushButton(QWidget* parent = nullptr);
explicit PushButton(const QString& Text, QWidget* parent = nullptr);
PushButton(const Icon& icon, const QString& Text, QWidget* parent = nullptr);
PushButton(const Color& color, const Icon& icon, const QString& Text, QWidget* parent = nullptr);
PushButton(Icon *icon, const QString& Text, QWidget* parent = nullptr);
~PushButton();

void setButtonColor(const QColor& color);
void setButtonHoverColor(const QColor& color);
void setButtonPressedColor(const QColor& color);
void setButtonPenColor(const QColor& color);
void setButtonPenHoverColor(const QColor& color);
void setButtonPenPressedColor(const QColor& color);
void setButtonBrushColor(const QColor& color);
void setButtonBrushHoverColor(const QColor& color);
void setButtonBrushPressedColor(const QColor& color);
void setButtonTextColor(const QColor& color);
void setButtonTextHoverColor(const QColor& color);
void setButtonTextPressedColor(const QColor& color);
void setColor(const Color& color);
void setColor(Color* color);


void setXRadius(const f32& Radius);
void setYRadius(const f32& Radius);
void setRadius(const f32& x, const f32& y);
f32 XRadius();
f32 YRadius();

private:
f32 xRadius;
f32 yRadius;
Color* buttonColor;
};
}

Expand Down
17 changes: 6 additions & 11 deletions include/FlareUI/RadioButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@ namespace Flare {
class FLARE_EXPORT RadioButton : public BaseButton {
Q_OBJECT

private:
QColor *buttonBrushColor;
QColor *buttonBrushHoverColor;
QColor *buttonBrushPressedColor;
QColor *buttonPenColor;
QColor *buttonPenHoverColor;
QColor *buttonPenPressedColor;
int penWidget;
bool check;

protected:
void connectSlot();

Expand All @@ -38,8 +30,6 @@ namespace Flare {
QColor buttonPenHoverColor;
QColor buttonPenPressedColor;

Color(const QColor &color);

Color setAllColor(const QColor &color);

Color setAllBrushColor(const QColor &color);
Expand All @@ -62,6 +52,11 @@ namespace Flare {
signals:

void checked();

private:
Color *buttonColor;
int penWidget;
bool check;
};
}
#endif //FLARE_RADIOBUTTON_H
4 changes: 3 additions & 1 deletion include/FlareUI/SystemIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#include <QGuiApplication>
#include <QScreen>
#include "flare_global.h"
#include "Menu.h"


namespace Flare {

class Widget;

class FLARE_EXPORT SystemIcon : public QSystemTrayIcon {
Q_OBJECT

Expand Down
Binary file modified lib/Flare.lib
Binary file not shown.
33 changes: 17 additions & 16 deletions src/BaseButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,11 @@ namespace Flare {
BaseButton::BaseButton(QWidget *parent) :
QAbstractButton(parent),
isAbove(false), isPress(false),
isIcon(false), buttonIcon(new QIcon()),
buttonHoverIcon(new QIcon()),
buttonPressedIcon(new QIcon()) {
isIcon(false), buttonIcon(new Icon()) {
}

BaseButton::~BaseButton() {
delete buttonHoverIcon;
delete buttonIcon;
delete buttonPressedIcon;
}


Expand All @@ -52,9 +48,9 @@ namespace Flare {

void Flare::BaseButton::setAllIcon(const QIcon &icon) {
isIcon = true;
*buttonHoverIcon = icon;
*buttonIcon = icon;
*buttonPressedIcon = icon;
buttonIcon->buttonHoverIcon = icon;
buttonIcon->buttonIcon = icon;
buttonIcon->buttonPressedIcon = icon;
}

Flare::BaseButton::Icon Flare::BaseButton::Icon::setAllIcon(const QIcon &icon) {
Expand All @@ -64,27 +60,32 @@ namespace Flare {
return *this;
}

void Flare::BaseButton::setIcon(const Icon &icon) {
void Flare::BaseButton::setIcon(Icon *icon) {
isIcon = true;
*buttonIcon = icon.buttonIcon;
*buttonHoverIcon = icon.buttonHoverIcon;
*buttonPressedIcon = icon.buttonPressedIcon;
delete buttonIcon;
buttonIcon = icon;
}

bool Flare::BaseButton::isSetIcon() const {
bool Flare::BaseButton::IsIcon() const {
return isIcon;
}

QIcon BaseButton::ButtonIcon() {
return *buttonIcon;
return buttonIcon->buttonIcon;
}

QIcon BaseButton::ButtonHoverIcon() {
return *buttonHoverIcon;
return buttonIcon->buttonHoverIcon;
}

QIcon BaseButton::ButtonPressedIcon() {
return *buttonPressedIcon;
return buttonIcon->buttonPressedIcon;
}
BaseButton::Icon::Icon() {
qDebug()<< "BaseButton Icon 初始化";
buttonIcon = QIcon();
buttonHoverIcon = QIcon();
buttonPressedIcon = QIcon();
}

}
Loading

0 comments on commit e034cdb

Please sign in to comment.