-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathImageViewerDialog.cpp
More file actions
156 lines (127 loc) · 5.27 KB
/
ImageViewerDialog.cpp
File metadata and controls
156 lines (127 loc) · 5.27 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "ImageViewerDialog.h"
#include "CustomTitleBar.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QScrollArea>
#include <QApplication>
#include <QScreen>
#include <QKeyEvent>
/**
* @brief ImageViewerDialog 생성자
* @details 이미지 뷰어 다이얼로그를 생성하고 UI를 초기화합니다.
* @param parent 부모 위젯
*/
ImageViewerDialog::ImageViewerDialog(QWidget *parent)
: QDialog(parent)
, m_imageLabel(nullptr)
, m_timestampLabel(nullptr)
, m_logTextEdit(nullptr)
, m_scrollArea(nullptr)
{
setupUI();
setWindowTitle("이미지 뷰어");
setModal(true);
// 화면 크기의 80%로 설정
QScreen *screen = QApplication::primaryScreen();
QRect screenGeometry = screen->availableGeometry();
int width = screenGeometry.width() * 0.8;
int height = screenGeometry.height() * 0.8;
resize(width, height);
// 화면 중앙에 배치
move((screenGeometry.width() - width) / 2,
(screenGeometry.height() - height) / 2);
}
/**
* @brief UI 설정 함수
* @details 이미지 뷰어의 UI 요소들을 초기화합니다.
*/
void ImageViewerDialog::setupUI()
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins(0, 0, 0, 0); // 프레임리스 윈도우를 위해 마진 제거
mainLayout->setSpacing(0); // 레이아웃 간격 제거
titleBar = new CustomTitleBar(this);
titleBar->setTitle("Image Viewer Window");
// 시그널과 슬롯 연결
connect(titleBar, &CustomTitleBar::minimizeClicked, this, &ImageViewerDialog::showMinimized);
connect(titleBar, &CustomTitleBar::closeClicked, this, &QDialog::close);
// 전체 레이아웃 설정
mainLayout->addWidget(titleBar);
setStyleSheet("background-color: #2e2e3a; color: white;");
QHBoxLayout *headerLayout = new QHBoxLayout();
m_timestampLabel = new QLabel();
m_timestampLabel->setStyleSheet("font-size: 16px; font-weight: bold; color: #ffffff; padding: 10px;");
headerLayout->addWidget(m_timestampLabel);
headerLayout->addStretch();
mainLayout->addLayout(headerLayout);
m_scrollArea = new QScrollArea();
m_scrollArea->setWidgetResizable(true);
m_scrollArea->setAlignment(Qt::AlignCenter);
m_scrollArea->setStyleSheet("QScrollArea { border: none; background-color: #2e2e3a; }");
m_imageLabel = new QLabel();
m_imageLabel->setAlignment(Qt::AlignCenter);
m_imageLabel->setStyleSheet("background-color: transparent;");
m_scrollArea->setWidget(m_imageLabel);
mainLayout->addWidget(m_scrollArea, 3);
QLabel *logLabel = new QLabel("로그 정보:");
logLabel->setStyleSheet("font-weight: bold; color: #ffffff; margin-top: 10px;");
mainLayout->addWidget(logLabel);
m_logTextEdit = new QTextEdit();
m_logTextEdit->setMaximumHeight(150);
m_logTextEdit->setReadOnly(true);
m_logTextEdit->setStyleSheet(R"(
QTextEdit {
border: 1px solid #555;
background-color: #1e1e2f;
color: white;
font-family: monospace;
font-size: 12px;
})");
mainLayout->addWidget(m_logTextEdit, 1);
setLayout(mainLayout);
}
/**
* @brief 이미지 및 로그 정보 설정
* @details 이미지와 로그 정보를 UI에 표시하고 창 크기를 동적으로 조정합니다.
* @param pixmap 이미지
* @param timestamp 촬영 시간
* @param logText 로그 텍스트
*/
void ImageViewerDialog::setImage(const QPixmap &pixmap, const QString ×tamp, const QString &logText)
{
if (!pixmap.isNull()) {
// 1. 화면 크기 정보 가져오기
QScreen *screen = QApplication::primaryScreen();
QRect screenGeometry = screen->availableGeometry();
const int screenMaxWidth = screenGeometry.width() * 0.7;
const int screenMaxHeight = screenGeometry.height() * 0.7;
const int minWidth = 640;
const int minHeight = 360;
// 2. 이미지 크기 조절
QSize originalSize = pixmap.size();
QSize scaledSize = originalSize;
scaledSize.scale(screenMaxWidth, screenMaxHeight, Qt::KeepAspectRatio);
// 최소 크기 보장
if (scaledSize.width() < minWidth || scaledSize.height() < minHeight) {
scaledSize.setWidth(std::max(scaledSize.width(), minWidth));
scaledSize.setHeight(std::max(scaledSize.height(), minHeight));
}
QPixmap scaledPixmap = pixmap.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
// 3. 이미지 적용
m_imageLabel->setPixmap(scaledPixmap);
m_imageLabel->resize(scaledPixmap.size());
// 4. 창 크기 동적으로 조정
const int headerHeight = 60; // 타이틀 + 버튼 여유
const int logAreaHeight = 180; // 로그 영역 여유
const int margin = 40;
int dialogWidth = scaledSize.width() + margin;
int dialogHeight = scaledSize.height() + headerHeight + logAreaHeight;
resize(dialogWidth, dialogHeight);
move((screenGeometry.width() - dialogWidth) / 2,
(screenGeometry.height() - dialogHeight) / 2);
} else {
m_imageLabel->setText("이미지를 불러올 수 없습니다.");
}
m_timestampLabel->setText(QString("촬영 시간: %1").arg(timestamp));
m_logTextEdit->setPlainText(logText);
}