-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
261 lines (232 loc) · 9.1 KB
/
mainwindow.cpp
File metadata and controls
261 lines (232 loc) · 9.1 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
* Main Window
*
* Maintainer: Park Jiwoo
*
* Copyright (C) 2024 Park-Jiwoo
*
*/
#include "mainwindow.h"
#include "cmdwindow.h"
#include "ui_mainwindow.h"
#include <QDateTime>
#include <QLabel>
#include <QToolButton>
#include <QPushButton>
#include <QVBoxLayout>
#include <QMessageBox>
#include <QHBoxLayout>
#include <QTimer>
#include <QTime>
#include <QPixmap>
#include <QPoint>
#include <QMenu>
#include <QContextMenuEvent>
/*
* @brief MainWindow 생성자
* @param parent 부모 위젯, 기본값은 nullptr
*/
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
setStyleSheet("background-color: #c0c0c0;");
// 중앙 로고 이미지를 레이아웃으로 감싸고, 창 크기에 맞게 자동으로 크게 표시
QWidget *centralWidget = new QWidget(this);
setCentralWidget(centralWidget);
QVBoxLayout *mainLayout = new QVBoxLayout(centralWidget);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->setSpacing(0);
// 중앙 영역(로고 등) 위젯
QWidget *centerArea = new QWidget(this);
QVBoxLayout *centerLayout = new QVBoxLayout(centerArea);
centerLayout->setContentsMargins(0, 0, 0, 0);
centerLayout->setSpacing(0);
logoLabel = new QLabel(this);
logoLabel->setAlignment(Qt::AlignCenter);
logoLabel->setScaledContents(true);
centerLayout->addStretch();
centerLayout->addWidget(logoLabel, 1);
centerLayout->addStretch();
updateLogoPixmap();
// 작업표시줄(상태표시줄) 위젯
QWidget *taskBar = new QWidget(this);
taskBar->setFixedHeight(40);
taskBar->setStyleSheet("background-color: #FFA500;");
QHBoxLayout *taskBarLayout = new QHBoxLayout(taskBar);
taskBarLayout->setContentsMargins(0, 0, 0, 0);
taskBarLayout->setSpacing(0);
// Start 버튼 생성 및 이미지 적용
QToolButton *startButton = new QToolButton(taskBar);
QPixmap startPixmap(":/start.png");
if (!startPixmap.isNull()) {
startButton->setIcon(QIcon(startPixmap));
startButton->setIconSize(QSize(30, 30));
}
startButton->setFixedSize(40, 40);
taskBarLayout->addWidget(startButton, 0, Qt::AlignLeft);
// 작업표시줄 오른쪽에 시계 표시
QLabel *timeLabel = new QLabel(taskBar);
timeLabel->setStyleSheet("color: white; font-weight: bold;");
timeLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
timeLabel->setFixedHeight(40);
taskBarLayout->addStretch();
taskBarLayout->addWidget(timeLabel, 0, Qt::AlignRight);
// 시계 업데이트를 위한 타이머 설정
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, [this, timeLabel]() {
updateClock(timeLabel);
});
timer->start(1000);
updateClock(timeLabel);
// Start 메뉴 설정(기존 코드 유지)
QMenu *startMenu = new QMenu(this);
QAction *cmdAction = new QAction(QIcon(":/cmd.png"), "cmd", this);
QAction *exitAction = new QAction(QIcon(":/exit.png"), "Exit", this);
startMenu->addAction(cmdAction);
startMenu->addAction(exitAction);
startButton->setMenu(startMenu);
startButton->setPopupMode(QToolButton::InstantPopup);
connect(cmdAction, &QAction::triggered, this, &MainWindow::openCmdWindow);
connect(exitAction, &QAction::triggered, this, &QApplication::quit);
connect(startButton, &QToolButton::clicked, [this, startButton, startMenu]() {
QRect buttonGeometry = startButton->geometry();
QPoint menuPos = startButton->mapToGlobal(buttonGeometry.topLeft());
startMenu->popup(menuPos - QPoint(0, startMenu->sizeHint().height()));
});
// 바탕화면 아이콘 생성 및 이미지 적용 (기존 코드 유지)
QToolButton *computerIcon = new QToolButton(centerArea);
QPixmap computerPixmap(":/mypc.png");
if (!computerPixmap.isNull()) {
computerIcon->setIcon(QIcon(computerPixmap));
computerIcon->setIconSize(QSize(64, 64));
}
computerIcon->setGeometry(20, 20, 100, 100);
computerIcon->setStyleSheet("background: transparent; font-size: 12px;");
computerIcon->setText("My Computer");
computerIcon->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
QToolButton *recycleBinIcon = new QToolButton(centerArea);
QPixmap recycleBinPixmap(":/trashcan.png");
if (!recycleBinPixmap.isNull()) {
recycleBinIcon->setIcon(QIcon(recycleBinPixmap));
recycleBinIcon->setIconSize(QSize(64, 64));
}
recycleBinIcon->setGeometry(20, 140, 100, 100);
recycleBinIcon->setStyleSheet("background: transparent; font-size: 12px;");
recycleBinIcon->setText("Recycle Bin");
recycleBinIcon->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
// ImLLM OS의 앱 LLM 창 생성 및 이미지 적용
QToolButton *imllmIcon = new QToolButton(this);
QPixmap imllmPixmap(":/imllm.png"); // 이미지 경로 확인
if (!imllmPixmap.isNull()) {
imllmIcon->setIcon(QIcon(imllmPixmap));
imllmIcon->setIconSize(QSize(64, 64)); // 이미지 크기 조정
}
imllmIcon->setGeometry(20, 250, 100, 100);
imllmIcon->setStyleSheet("background: transparent; font-size: 12px;");
imllmIcon->setText("ImLLM");
imllmIcon->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); // 아이콘 아래 텍스트 배치
connect(computerIcon, &QToolButton::clicked, this, &MainWindow::showImplementationPopup);
connect(recycleBinIcon, &QToolButton::clicked, this, &MainWindow::showImplementationPopup);
connect(imllmIcon, &QToolButton::clicked, this, &MainWindow::showImplementationPopup);
// 전체 레이아웃에 중앙영역, 작업표시줄 순서로 배치
mainLayout->addWidget(centerArea, 1);
mainLayout->addWidget(taskBar, 0);
// 여기다가 메모장이나 다른 기타 프로그램을 만들어서 이미지를 적용하고 호출 할 수 있음
}
/*
* @brief 소멸자
*/
MainWindow::~MainWindow()
{
delete ui;
}
/*
* @brief CMD 창을 여는 함수
* @details CMD 창을 열어주는 역할을 수행합니다.
*/
void MainWindow::openCmdWindow()
{
CmdWindow *cmdWindow = new CmdWindow(this);
cmdWindow->show();
}
/*
* @brief "구현중" 팝업 표시
* @details 클릭된 아이콘에 대해 구현 중이라는 팝업을 띄웁니다.
*/
void MainWindow::showImplementationPopup()
{
QMessageBox::information(this, "구현중", "이 기능은 구현 중입니다.");
}
/*
* @brief 시계 업데이트 함수
* @param timeLabel 시계를 표시할 QLabel 객체
* @details 현재 시간을 업데이트하여 주어진 QLabel에 표시합니다.
*/
void MainWindow::updateClock(QLabel *timeLabel)
{
timeLabel->setText(QDateTime::currentDateTime().toString("hh:mm:ss"));
}
/*
* @brief MainWindow에서 시간을 업데이트하는 함수
* @details 이 함수는 타이머 또는 다른 이벤트에 의해 호출되어 시간을 업데이트합니다.
*/
void MainWindow::updateTime() {
// 시간 업데이트에 관련된 코드
}
/*
* @brief MainWindow에서 "Open" 액션이 트리거될 때 호출되는 함수
* @details 이 함수는 "Open" 메뉴 항목이나 버튼이 클릭되었을 때 실행됩니다.
*/
void MainWindow::openTriggered() {
// "Open" 동작에 관련된 코드
}
/*
* @brief MainWindow에서 "Delete" 액션이 트리거될 때 호출되는 함수
* @details 이 함수는 "Delete" 메뉴 항목이나 버튼이 클릭되었을 때 실행됩니다.
*/
void MainWindow::deleteTriggered() {
// "Delete" 동작에 관련된 코드
}
/*
* @brief MainWindow에서 컨텍스트 메뉴를 표시하는 함수
* @param pos 컨텍스트 메뉴를 표시할 위치
* @details 이 함수는 사용자가 우클릭했을 때 실행되며, 지정된 위치에 컨텍스트 메뉴를 표시합니다.
*/
void MainWindow::showContextMenu(const QPoint &pos) {
// 컨텍스트 메뉴 표시 코드
}
/*
* @brief MainWindow에서 "Action 1"이 트리거될 때 호출되는 함수
* @details 이 함수는 특정 액션이 실행되었을 때 실행됩니다.
*/
void MainWindow::action1Triggered() {
// "Action 1"에 대한 동작 코드
}
/*
* @brief MainWindow에서 "Action 2"가 트리거될 때 호출되는 함수
* @details 이 함수는 또 다른 특정 액션이 실행되었을 때 실행됩니다.
*/
void MainWindow::action2Triggered() {
// "Action 2"에 대한 동작 코드
}
/*
* @brief MainWindow에서 아이콘에 대한 컨텍스트 메뉴를 표시하는 함수
* @param pos 컨텍스트 메뉴를 표시할 위치
* @details 이 함수는 아이콘을 우클릭했을 때 실행되며, 해당 위치에 컨텍스트 메뉴를 표시합니다.
*/
void MainWindow::showIconContextMenu(const QPoint &pos) {
// 아이콘 컨텍스트 메뉴 표시 코드
}
void MainWindow::resizeEvent(QResizeEvent *event) {
QMainWindow::resizeEvent(event);
updateLogoPixmap();
}
void MainWindow::updateLogoPixmap() {
QPixmap logoPixmap(":/site_logo.png");
if (!logoPixmap.isNull() && logoLabel) {
QSize maxSize = centralWidget()->size();
logoLabel->setPixmap(logoPixmap.scaled(maxSize.width() * 0.7, maxSize.height() * 0.7, Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
}