-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
实现了FlareWindow窗口和Widget窗口 1. Widget对于QWidget的窗口添加了部分信号和修改了绘制流程,但是绘制圆角还是有部分缺陷,会在下次的更新中修复。 2 . FlareWindow是一个Mac风格的一个MainWindow,但是因为Flare::Widget的圆角实现问题,没法完整的实现Mac风格,但是会在下一次的更新中修复 目前项目正在缓慢进行中,期待有其他开发者的加入😊
- Loading branch information
Showing
16 changed files
with
277 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,120 @@ | ||
#include "FlareWindow.h" | ||
|
||
Flare::FlareWindow::FlareWindow(QWidget* parent) | ||
: QWidget(parent), | ||
CloseButton(new IconButton()), | ||
HideButton(new IconButton()), | ||
EnlargeButton(new IconButton()) { | ||
|
||
: QMainWindow(parent), | ||
CloseButton(new IconButton(this)), | ||
HideButton(new IconButton(this)), | ||
EnlargeButton(new IconButton(this)), | ||
isMax(false), | ||
EnlargeIcon(new IconButton::Icon()), | ||
MinimizeIcon(new IconButton::Icon()), | ||
OriginalSize(new QSize()), | ||
Title(new Widget(this)), | ||
OriginalPoint(new QPoint()), | ||
MousePoint(new QPoint()), | ||
Background(new Widget(this)) { | ||
connectSlot(); | ||
|
||
isTitlePress = false; | ||
|
||
IconButton::Icon CloseIcon; | ||
CloseIcon.setAllIcon(QIcon(":/image/closebutton-hover.png")); | ||
CloseIcon.buttonIcon = QIcon(":/image/closebutton.png"); | ||
CloseButton->setIcon(CloseIcon); | ||
IconButton::Icon HideIcon; | ||
HideIcon.setAllIcon(QIcon(":/image/minibutton-hover.png")); | ||
HideIcon.buttonIcon = QIcon(":/image/minibutton.png"); | ||
HideButton->setIcon(HideIcon); | ||
EnlargeIcon->setAllIcon(QIcon(":/image/maxbutton-hover.png")); | ||
EnlargeIcon->buttonIcon = QIcon(":/image/maxbutton.png"); | ||
EnlargeButton->setIcon(*EnlargeIcon); | ||
MinimizeIcon->setAllIcon(QIcon(":/image/restorebutton-hover.png")); | ||
MinimizeIcon->buttonIcon = QIcon(":/image/restorebutton.png"); | ||
|
||
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);//去掉标题栏 | ||
setAttribute(Qt::WA_TranslucentBackground); | ||
|
||
CloseButton->resize(20, 20); | ||
EnlargeButton->resize(20, 20); | ||
HideButton->resize(20, 20); | ||
CloseButton->setColor(Flare::IconButton::Color().setAllColor(FlareColor::White)); | ||
EnlargeButton->setColor(Flare::IconButton::Color().setAllColor(FlareColor::White)); | ||
HideButton->setColor(Flare::IconButton::Color().setAllColor(FlareColor::White)); | ||
widgetMove(); | ||
Title->move(0, 1); | ||
Background->move(0, Title->y() + Title->height()); | ||
Background->resize(width(), height() - Title->height()); | ||
} | ||
|
||
Flare::FlareWindow::~FlareWindow() {} | ||
|
||
void Flare::FlareWindow::connectSlot() { | ||
connect(CloseButton, &IconButton::clicked, this, &FlareWindow::close); | ||
connect(HideButton, &IconButton::clicked, this, &FlareWindow::hide); | ||
// TODO: 等下要写关于按钮是最大化,还是缩小化的逻辑了 | ||
connect(HideButton, &IconButton::clicked, this, &FlareWindow::showMinimized); | ||
connect(EnlargeButton, &IconButton::clicked, this, [&]() { | ||
if (isMax) { | ||
restoreOriginalSize(); | ||
EnlargeButton->setIcon(*EnlargeIcon); | ||
} else { | ||
OriginalSize->setWidth(width()); | ||
OriginalSize->setHeight(height()); | ||
OriginalPoint->setX(x()); | ||
OriginalPoint->setY(y()); | ||
showMaximized(); | ||
EnlargeButton->setIcon(*MinimizeIcon); | ||
} | ||
isMax = !isMax; | ||
}); | ||
connect(Title, &Widget::press, this, [&](QPoint mouseOffset) { | ||
isTitlePress = true; | ||
*MousePoint = mouseOffset; | ||
}); | ||
connect(Title, &Widget::release, this, [&]() { | ||
isTitlePress = false; | ||
}); | ||
connect(this, &FlareWindow::show, this, [&]() { | ||
MousePoint->setX(x()); | ||
qDebug() << x(); | ||
qDebug() << y(); | ||
MousePoint->setY(y()); | ||
}); | ||
|
||
} | ||
|
||
void Flare::FlareWindow::widgetMove() { | ||
CloseButton->move(width() - 21, 1); | ||
EnlargeButton->move(CloseButton->x() - CloseButton->width(), 1); | ||
HideButton->move(EnlargeButton->x() - EnlargeButton->width(), 1); | ||
Title->resize(width() - 1, 20); | ||
Background->resize(width()-1, height() - Title->height()); | ||
} | ||
|
||
void Flare::FlareWindow::resizeEvent(QResizeEvent* Event) { | ||
QWidget::resizeEvent(Event); | ||
widgetMove(); | ||
} | ||
|
||
void Flare::FlareWindow::restoreOriginalSize() { | ||
resize(*OriginalSize); | ||
move(OriginalPoint->x(), OriginalPoint->y()); | ||
} | ||
|
||
void Flare::FlareWindow::mouseMoveEvent(QMouseEvent* event) { | ||
QMainWindow::mouseMoveEvent(event); | ||
|
||
if (isTitlePress && event->buttons() & Qt::LeftButton) { | ||
// 计算鼠标移动的偏移量 | ||
QPoint delta = event->pos() - *MousePoint; | ||
// 移动窗口到新位置 | ||
move(pos() + delta); | ||
} | ||
} | ||
|
||
Flare::FlareWindow::~FlareWindow() { | ||
delete EnlargeIcon; | ||
delete MinimizeIcon; | ||
delete OriginalPoint; | ||
delete OriginalSize; | ||
delete EnlargeButton; | ||
delete CloseButton; | ||
delete HideButton; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<RCC> | ||
<qresource prefix="/"> | ||
<file>image/closebutton.png</file> | ||
<file>image/closebutton-hover.png</file> | ||
<file>image/maxbutton.png</file> | ||
<file>image/maxbutton-hover.png</file> | ||
<file>image/minibutton.png</file> | ||
<file>image/minibutton-hover.png</file> | ||
<file>image/restorebutton.png</file> | ||
<file>image/restorebutton-hover.png</file> | ||
</qresource> | ||
</RCC> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "Widget.h" | ||
|
||
void Widget::paintEvent(QPaintEvent* Event) { | ||
QPainter painter(this); | ||
painter.setPen(WidgetColor()); | ||
painter.setBrush(WidgetColor()); | ||
painter.setRenderHint(QPainter::Antialiasing, true); | ||
painter.drawRoundedRect(0, 0, width(), height(), XRadius(), YRadius(), Qt::RelativeSize); | ||
painter.end(); | ||
} | ||
|
||
void Widget::enterEvent(QEnterEvent* Event) { | ||
QWidget::enterEvent(Event); | ||
isAbove = true; | ||
} | ||
|
||
void Widget::leaveEvent(QEvent* Event) { | ||
QWidget::leaveEvent(Event); | ||
isAbove = false; | ||
} | ||
|
||
void Widget::mousePressEvent(QMouseEvent* Event) { | ||
QWidget::mousePressEvent(Event); | ||
emit press(Event->pos()); | ||
} | ||
|
||
void Widget::mouseReleaseEvent(QMouseEvent* Event) { | ||
QWidget::mouseReleaseEvent(Event); | ||
emit release(); | ||
} | ||
|
||
Widget::Widget(QWidget *parent) | ||
: QWidget(parent),WidgetBackColor(new QColor(FlareColor::White)){ | ||
xRadius = 0; | ||
yRadius = 0; | ||
isAbove = false; | ||
} | ||
|
||
Widget::~Widget() | ||
{} | ||
|
||
f32 Widget::XRadius() { | ||
return xRadius; | ||
} | ||
|
||
f32 Widget::YRadius() { | ||
return yRadius; | ||
} | ||
|
||
QColor Widget::WidgetColor() { | ||
return *WidgetBackColor; | ||
} | ||
|
||
void Widget::setxRadius(f32 Radius) { | ||
xRadius = Radius; | ||
} | ||
|
||
void Widget::setyRadius(f32 Radius) { | ||
yRadius = Radius; | ||
} | ||
|
||
void Widget::setRadius(f32 XRadius, f32 YRadius) { | ||
xRadius = XRadius; | ||
yRadius = YRadius; | ||
} | ||
|
||
void Widget::setWidgetColor(const QColor& color) { | ||
*WidgetBackColor = color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef FLARE_WIDGET_H | ||
#define FLARE_WIDGET_H | ||
|
||
#include <QWidget> | ||
#include <QPainter> | ||
#include <QMouseEvent> | ||
#include "FlareColor.h" | ||
class Widget : public QWidget | ||
{ | ||
Q_OBJECT | ||
private: | ||
bool isAbove; | ||
f32 xRadius; | ||
f32 yRadius; | ||
QColor *WidgetBackColor; | ||
protected: | ||
void paintEvent(QPaintEvent* Event) override; | ||
void enterEvent(QEnterEvent* Event) override; | ||
void leaveEvent(QEvent* Event) override; | ||
void mousePressEvent(QMouseEvent *Event) override; | ||
void mouseReleaseEvent(QMouseEvent* Event) override; | ||
public: | ||
Widget(QWidget *parent = nullptr); | ||
~Widget(); | ||
|
||
f32 XRadius(); | ||
f32 YRadius(); | ||
QColor WidgetColor(); | ||
|
||
void setxRadius(f32 Radius); | ||
void setyRadius(f32 Radius); | ||
void setRadius(f32 XRadius, f32 YRadius); | ||
void setWidgetColor(const QColor& color); | ||
signals: | ||
void press(QPoint mouseOffset); | ||
void release(); | ||
}; | ||
|
||
#endif |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.