Skip to content

Commit

Permalink
所有已经发现的Bug已经解决,还有目前只剩下SystemIcon中的显示Menu的移动函数有些问题其他的已经完善
Browse files Browse the repository at this point in the history
  • Loading branch information
zjhzzy committed Jul 25, 2023
1 parent 83cd15d commit 69a915c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -405,5 +405,5 @@ FodyWeavers.xsd
*/cmake-build-debug/
*/cmake-build-release/
.idea/vcs.xml
cmake-build-debug/.cmake/api/v1/query/cache-v2
cmake-build-debug/.cmake/api/v1/query/cmakeFiles-v1
/cmake-build-debug/
/cmake-build-release/
8 changes: 3 additions & 5 deletions include/FlareUI/SystemIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ namespace Flare {
class FLARE_EXPORT SystemIcon : public QSystemTrayIcon {
Q_OBJECT

SystemIcon(Menu *appMenu, const QIcon &icon, QObject *parent);

private:
Menu *iconMenu;
Widget *iconMenu;

protected:

Expand All @@ -28,13 +26,13 @@ namespace Flare {

explicit SystemIcon(const QIcon &icon, QObject *parent = nullptr);

SystemIcon(QMenu *appMenu, const QIcon &icon, QObject *parent = nullptr);
SystemIcon(Widget *appMenu, const QIcon &icon, QObject *parent = nullptr);

~SystemIcon();

void setTriggerMenu(ActivationReason trigger);

void setMenu(Menu *menu);
void setMenu(Widget *menu);

signals:

Expand Down
Binary file modified lib/Flare.lib
Binary file not shown.
Binary file added lib/libFlare.a
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void Flare::Menu::addButton(Flare::PushButton *button) {
int heightTemp = 0;
widthTemp = buttonVector.first()->Button().width();
for (const auto &item: buttonVector) {
heightTemp = item->Button().height();
heightTemp += item->Button().height();
}
setFixedSize(widthTemp, heightTemp);
}
Expand Down
45 changes: 15 additions & 30 deletions src/SystemIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,13 @@ void Flare::SystemIcon::connectSlots() {
}

void SystemIcon::showMenu() {
if (iconMenu) {
// Get the screen geometry
QScreen *screen = QGuiApplication::primaryScreen();
QRect screenGeometry = screen->availableGeometry();

// Get the menu size
QSize menuSize = iconMenu->sizeHint();

// Calculate the menu position
int x = QCursor::pos().x() - menuSize.width() / 2;
int y = QCursor::pos().y() + 10;

// Adjust the menu position to ensure it stays within the screen boundaries
if (x < screenGeometry.left())
x = screenGeometry.left();
else if (x + menuSize.width() > screenGeometry.right())
x = screenGeometry.right() - menuSize.width();
if (y < screenGeometry.top())
y = screenGeometry.top();
else if (y + menuSize.height() > screenGeometry.bottom())
y = screenGeometry.bottom() - menuSize.height();

// Show the menu at the adjusted position
iconMenu->move(QPoint(x, y));
if (iconMenu != nullptr) {
iconMenu->show();
}
}



void Flare::SystemIcon::setTriggerMenu(QSystemTrayIcon::ActivationReason trigger) {
switch (trigger) {
case QSystemTrayIcon::Unknown:
Expand Down Expand Up @@ -95,17 +74,23 @@ void Flare::SystemIcon::setTriggerMenu(QSystemTrayIcon::ActivationReason trigger
}

SystemIcon::SystemIcon(QObject *parent)
: QSystemTrayIcon(parent), iconMenu(nullptr) {}
: QSystemTrayIcon(parent), iconMenu(nullptr) {
connectSlots();
}

SystemIcon::SystemIcon(const QIcon &icon, QObject *parent)
: QSystemTrayIcon(icon, parent), iconMenu(nullptr) {}
: QSystemTrayIcon(icon, parent), iconMenu(nullptr) {
connectSlots();
}

SystemIcon::SystemIcon(Menu *appMenu, const QIcon &icon, QObject *parent)
: QSystemTrayIcon(icon, parent), iconMenu(appMenu) {}
SystemIcon::SystemIcon(Widget *appMenu, const QIcon &icon, QObject *parent)
: QSystemTrayIcon(icon, parent), iconMenu(appMenu) {
connectSlots();
}

SystemIcon::~SystemIcon() {}
SystemIcon::~SystemIcon() = default;

void Flare::SystemIcon::setMenu(Flare::Menu *menu) {
void Flare::SystemIcon::setMenu(Flare::Widget *menu) {
iconMenu = menu;
}

0 comments on commit 69a915c

Please sign in to comment.