DiagramDesigner/diagramCavas/source/cornerMonitorLauncher.cpp

78 lines
1.9 KiB
C++
Raw Permalink Normal View History

2025-12-08 20:05:07 +08:00
#include "cornerMonitorLauncher.h"
#include <QMdiArea>
#include <QPainter>
#include <QMouseEvent>
#include <QMenu>
CornerMonitorLauncher::CornerMonitorLauncher(QMdiArea* parent)
: QWidget(parent)
,m_mdiArea(parent)
{
setFixedSize(48, 48);
setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
positionAtCorner();
}
CornerMonitorLauncher::~CornerMonitorLauncher()
{
}
void CornerMonitorLauncher::showDlg()
{
show();
positionAtCorner();
}
void CornerMonitorLauncher::paintEvent(QPaintEvent* event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
// 绘制圆形按钮
painter.setBrush(QColor(255, 255, 255, 240));
painter.setPen(QPen(QColor(200, 200, 200), 1));
painter.drawEllipse(rect().adjusted(1, 1, -1, -1));
// 绘制+号
painter.setPen(QPen(QColor(100, 100, 100), 2));
painter.drawLine(width()/2 - 8, height()/2, width()/2 + 8, height()/2);
painter.drawLine(width()/2, height()/2 - 8, width()/2, height()/2 + 8);
}
void CornerMonitorLauncher::mousePressEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton) {
showQuickMenu();
}
}
void CornerMonitorLauncher::showQuickMenu() {
QMenu menu;
menu.setStyleSheet(R"(
QMenu {
background: white;
border: 1px solid #dee2e6;
border-radius: 4px;
}
QMenu::item {
padding: 6px 20px 6px 10px;
}
QMenu::item:selected {
background: #f8f9fa;
}
)");
menu.addAction("加载运行时监控", [&]{ emit openLoadMonitorDlg();});
menu.exec(mapToGlobal(QPoint(0, height())));
}
void CornerMonitorLauncher::positionAtCorner() {
QPoint topRight = m_mdiArea->mapToGlobal(m_mdiArea->rect().topRight());
int x = topRight.x() - width() - 20;
int y = topRight.y() + 20;
move(x, y);
}