-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcustommessagebox.cpp
More file actions
133 lines (111 loc) · 3.84 KB
/
custommessagebox.cpp
File metadata and controls
133 lines (111 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "CustomMessageBox.h"
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QScreen>
#include <QGraphicsDropShadowEffect>
#include <QMouseEvent>
/**
* @brief CustomMessageBox 생성자
* @details 사용자 지정 메시지 박스를 생성합니다.
* @param parent 부모 위젯
* @param title 메시지 박스 타이틀
* @param message 표시할 메시지
*/
CustomMessageBox::CustomMessageBox(QWidget *parent, const QString &title, const QString &message)
: QDialog(parent), m_dragging(false)
{
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::CustomizeWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
QVBoxLayout *outerLayout = new QVBoxLayout(this);
outerLayout->setContentsMargins(20, 20, 20, 20); // 그림자 공간 확보
QFrame *popup = new QFrame(this);
popup->setObjectName("popupFrame");
popup->setStyleSheet(R"(
QFrame#popupFrame {
background-color: #3c405c;
border-radius: 12px;
})");
QVBoxLayout *mainLayout = new QVBoxLayout(popup);
mainLayout->setContentsMargins(24, 24, 24, 24);
QLabel *messageLabel = new QLabel(message);
messageLabel->setStyleSheet("color: white; font-size: 14px;");
messageLabel->setWordWrap(true);
messageLabel->setMaximumWidth(300);
messageLabel->setMinimumWidth(150);
messageLabel->setAlignment(Qt::AlignCenter);
mainLayout->addWidget(messageLabel);
QPushButton *okButton = new QPushButton("확인");
okButton->setFixedSize(100, 36);
okButton->setStyleSheet(R"(
QPushButton {
background-color: #5d6075;
color: white;
border: none;
border-radius: 6px;
font-weight: bold;
}
QPushButton:hover {
background-color: #6f728a;
}
QPushButton:pressed {
background-color: #4b4e65;
})");
// 메시지 아래 간격 추가 (예: 16px)
mainLayout->addSpacing(16);
mainLayout->addWidget(okButton, 0, Qt::AlignCenter);
connect(okButton, &QPushButton::clicked, this, &QDialog::accept);
// 그림자 효과
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(popup);
shadow->setBlurRadius(24);
shadow->setOffset(0, 6);
shadow->setColor(QColor(0, 0, 0, 160));
popup->setGraphicsEffect(shadow);
outerLayout->addWidget(popup);
layout()->activate();
adjustSize();
// 중앙 배치
if (parent) {
QRect parentGeometry = parent->geometry();
int x = parentGeometry.x() + (parentGeometry.width() - width()) / 2;
int y = parentGeometry.y() + (parentGeometry.height() - height()) / 2;
move(x, y);
} else {
// 부모 없을 경우 화면 기준 중앙 배치
QRect screen = QGuiApplication::primaryScreen()->availableGeometry();
move(screen.center() - QPoint(width() / 2, height() / 2));
}
}
/**
* @brief 마우스 클릭 이벤트 처리
* @details 창 이동을 위한 드래그 시작 위치를 저장합니다.
* @param event 마우스 이벤트
*/
void CustomMessageBox::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
m_dragging = true;
m_dragPos = event->globalPosition().toPoint() - frameGeometry().topLeft();
}
}
/**
* @brief 마우스 이동 이벤트 처리
* @details 창을 드래그하여 이동합니다.
* @param event 마우스 이벤트
*/
void CustomMessageBox::mouseMoveEvent(QMouseEvent *event)
{
if (m_dragging && event->buttons() & Qt::LeftButton) {
move(event->globalPosition().toPoint() - m_dragPos);
}
}
/**
* @brief 마우스 릴리즈 이벤트 처리
* @details 드래그 상태를 해제합니다.
* @param event 마우스 이벤트
*/
void CustomMessageBox::mouseReleaseEvent(QMouseEvent *event)
{
Q_UNUSED(event);
m_dragging = false;
}