-
Notifications
You must be signed in to change notification settings - Fork 2
/
ImportDialog.cpp
132 lines (88 loc) · 2.78 KB
/
ImportDialog.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
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
#include "ImportDialog.h"
#include "ui_ImportDialog.h"
#include <QSettings>
ImportDialog::ImportDialog(QWidget *parent) : QDialog(parent),
ui(new Ui::importDialog)
{
ui->setupUi(this);
scene = NULL;
item = NULL;
importImage = QImage();
restoreSettings();
}
ImportDialog::~ImportDialog()
{
saveSettings();
if(item)
delete item;
if(scene)
delete scene;
delete ui;
}
bool ImportDialog::setPreviewImage(QImage image)
{
if(!image.isNull())
{
if(scene == NULL)
{
scene = new QGraphicsScene();
ui->imagePreview->setScene(scene);
}
if(item == NULL)
{
item = new QGraphicsPixmapItem(QPixmap::fromImage(image));
scene->addItem(item);
}
else
item->setPixmap(QPixmap::fromImage(image));
scene->setSceneRect(0, 0, image.width(), image.height());
ui->imagePreview->show();
importImage = image;
return true;
}
return false;
}
void ImportDialog::on_okButton_clicked()
{
this->hide();
importOK(importImage, ui->xFramesBox->value(), ui->yFramesBox->value(), ui->vertFirst->isChecked(), ui->checkSplitAnimations->isChecked());
}
void ImportDialog::on_allButton_clicked()
{
this->hide();
importAll(importImage, ui->xFramesBox->value(), ui->yFramesBox->value(), ui->vertFirst->isChecked(), ui->checkSplitAnimations->isChecked());
}
void ImportDialog::showEvent(QShowEvent *)
{
ui->imagePreview->fitInView(scene->sceneRect(),Qt::KeepAspectRatio);
}
void ImportDialog::resizeEvent(QResizeEvent* event)
{
QDialog::resizeEvent(event);
ui->imagePreview->fitInView(scene->sceneRect(),Qt::KeepAspectRatio);
}
void ImportDialog::saveSettings()
{
QSettings settings("DaxarDev", "SpriteSheeterImport");
//Save other GUI settings
settings.setValue("xFrames", ui->xFramesBox->value());
settings.setValue("yFrames", ui->yFramesBox->value());
settings.setValue("horizFirst", ui->horizFirst->isChecked());
settings.setValue("vertFirst", ui->vertFirst->isChecked());
settings.setValue("splitAnimations", ui->checkSplitAnimations->isChecked());
}
void ImportDialog::restoreSettings()
{
QSettings settings("DaxarDev", "SpriteSheeterImport");
if(settings.value("xFrames", -1).toInt() == -1) //No settings are here
return;
ui->xFramesBox->setValue(settings.value("xFrames").toInt());
ui->yFramesBox->setValue(settings.value("yFrames").toInt());
ui->horizFirst->setChecked(settings.value("horizFirst").toBool());
ui->vertFirst->setChecked(settings.value("vertFirst").toBool());
ui->checkSplitAnimations->setChecked(settings.value("splitAnimations").toBool());
}
void ImportDialog::on_cancelButton_clicked()
{
this->hide();
}