-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmainwindow.cpp
40 lines (33 loc) · 1000 Bytes
/
mainwindow.cpp
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
#include "mainwindow.h"
#include <QPainter>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setupUI();
resize(1000, 618);
}
MainWindow::~MainWindow()
{
qDeleteAll(m_imageVector);
}
void MainWindow::setupUI()
{
auto view = new GridView(this);
m_imageVector.clear();
auto colorNames = QColor::colorNames();
for (const QString &colorName : std::as_const(colorNames)) {
QImage image(WIDTH, WIDTH, QImage::Format_ARGB32);
image.fill(Qt::transparent);
QPainter painter(&image);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::transparent);
painter.setBrush(QColor(colorName));
QRect rect = image.rect();
rect.adjust(1, 1, -1, -1);
double radius = (WIDTH - 2) / 2.0;
painter.drawRoundedRect(rect, radius, radius);
m_imageVector.append(new ImageInfo{image, colorName});
}
view->setImageVector(m_imageVector);
setCentralWidget(view);
}