2026-03-23 11:11:55 +08:00
|
|
|
#ifndef TITLEBAR_H
|
|
|
|
|
#define TITLEBAR_H
|
|
|
|
|
/**
|
|
|
|
|
* 自定义标题栏
|
|
|
|
|
* */
|
|
|
|
|
#include <QDialog>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
|
|
|
|
class TitleBar : public QWidget
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2026-05-18 19:12:28 +08:00
|
|
|
explicit TitleBar(QWidget *parent = nullptr,bool bClose = false,bool bMaxMin = false);
|
2026-03-23 11:11:55 +08:00
|
|
|
|
|
|
|
|
void setTitle(const QString &title);
|
|
|
|
|
void updateMaximizeButton(); // 根据窗口状态更新按钮文本
|
2026-05-18 19:12:28 +08:00
|
|
|
void setCenterText(const QString &text);
|
2026-03-23 11:11:55 +08:00
|
|
|
signals:
|
|
|
|
|
void maximizeClicked();
|
|
|
|
|
void closeClicked();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
|
void mouseMoveEvent(QMouseEvent *event) override;
|
|
|
|
|
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void setupUI();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QPoint m_dragStartPosition;
|
|
|
|
|
QWidget *m_parentWindow;
|
|
|
|
|
|
|
|
|
|
QLabel *m_titleLabel;
|
2026-05-18 19:12:28 +08:00
|
|
|
QLabel *m_centerLabel = nullptr;
|
2026-03-23 11:11:55 +08:00
|
|
|
QPushButton *m_maximizeButton;
|
|
|
|
|
QPushButton *m_closeButton;
|
|
|
|
|
|
|
|
|
|
bool m_isMaximized = false;
|
2026-05-18 19:12:28 +08:00
|
|
|
bool _bShowClose = false;
|
|
|
|
|
bool _bShowMaxMin = false;
|
2026-03-23 11:11:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|