-
Notifications
You must be signed in to change notification settings - Fork 1
/
palettecontainer.cpp
52 lines (49 loc) · 1.82 KB
/
palettecontainer.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
41
42
43
44
45
46
47
48
49
50
51
52
#include "palettecontainer.h"
#include <QVBoxLayout>
#include <QIcon>
PaletteContainer::PaletteContainer(PaletteView* view, QWidget *parent) : QWidget(parent), m_view(view)
{
setWindowTitle("Palette viewer");
setWindowIcon(QIcon{":/Resources/ButtonIcons/palette.png"});
auto layout = new QVBoxLayout(this);
setLayout(layout);
layout->addWidget(view);
QWidget* buttonContainer = new QWidget(this);
auto buttonLayout = new QHBoxLayout(buttonContainer);
buttonContainer->setLayout(buttonLayout);
savePalette = new QPushButton{"Save Palette to file", buttonContainer};
loadPalette = new QPushButton{"Load Palette from file", buttonContainer};
QObject::connect(loadPalette, &QPushButton::clicked, this, [this]{
QString filename = QFileDialog::getOpenFileName(this, "Open Pal File", "", tr("Palette Files (*.pal)"));
if (filename.length() == 0)
return;
if (!assert_filesize(filename, 768))
return;
SpritePaletteCreator::ReadPaletteFile(0, 16, 16, filename);
m_view->updateForChange(SpritePaletteCreator::MakeFullPalette());
emit paletteChanged();
});
QObject::connect(savePalette, &QPushButton::clicked, this, [this]{
QString filename = QFileDialog::getSaveFileName(this, "Save Pal/Palmask File", "", tr("Palette Files (*.pal)"));
if (filename.length() == 0)
return;
SpritePaletteCreator::PaletteToFile(m_view->getCurrentItem()->pixmap().toImage(), filename);
});
savePalette->adjustSize();
loadPalette->adjustSize();
buttonContainer->adjustSize();
buttonLayout->addWidget(savePalette);
buttonLayout->addWidget(loadPalette);
layout->addWidget(buttonContainer);
adjustSize();
setFixedSize(size());
}
void PaletteContainer::updateContainer(const QPixmap& image) {
m_view->updateForChange(image);
m_view->open();
show();
raise();
}
void PaletteContainer::closeEvent(QCloseEvent *event) {
m_view->close(event);
}