-
Notifications
You must be signed in to change notification settings - Fork 4
/
importdialog.cpp
127 lines (100 loc) · 2.91 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <QColorDialog>
#include "colormanager.h"
#include "globalstate.h"
#include "importdialog.h"
ImportDialog::ImportDialog(const QImage &image,
QWidget *parent)
: QDialog(parent), Ui::ImportDialog()
{
setupUi(this);
connect(Ui::ImportDialog::width, SIGNAL(valueChanged(int)),
this, SLOT(setWidth(int)));
connect(Ui::ImportDialog::height, SIGNAL(valueChanged(int)),
this, SLOT(setHeight(int)));
connect(Ui::ImportDialog::transparentColor, SIGNAL(released()),
this, SLOT(selectColor()));
transparentColor_ = QColor(255, 255, 255);
origsize_ = image.size();
if (origsize_.height() > origsize_.width())
setHeight(60);
else
setWidth(60);
MetaColorManager *mcm = GlobalState::self()->colorManager();
foreach (ColorManager *cm, mcm->colorManagers())
colorSet->addItem(cm->name(), cm->id());
if (mcm->localSwatches()->count() > 0) {
colorSet->insertSeparator(colorSet->count());
colorSet->addItem(mcm->localSwatches()->name(), "");
}
}
ImportDialog::~ImportDialog()
{
}
int ImportDialog::documentWidth() const
{
return Ui::ImportDialog::width->value();
}
QString ImportDialog::title() const
{
return Ui::ImportDialog::title->text();
}
QString ImportDialog::author() const
{
return Ui::ImportDialog::author->text();
}
ColorManager* ImportDialog::colorManager() const
{
if (colorSet->currentIndex() < 0)
return NULL;
MetaColorManager *mcm = GlobalState::self()->colorManager();
QString id = colorSet->itemData(colorSet->currentIndex()).toString();
if (id == "")
return mcm->localSwatches();
else
return mcm->colorManager(id);
}
bool ImportDialog::hasTransparent() const
{
return transparent->isChecked();
}
const QColor& ImportDialog::transparentColor() const
{
return transparentColor_;
}
void ImportDialog::setWidth(int v)
{
int adjustedh = origsize_.height() / (origsize_.width() / (float) v);
if (adjustedh > 1000) {
setHeight(1000);
return;
}
Ui::ImportDialog::width->blockSignals(true);
Ui::ImportDialog::height->blockSignals(true);
Ui::ImportDialog::width->setValue(v);
Ui::ImportDialog::height->setValue(adjustedh);
Ui::ImportDialog::width->blockSignals(false);
Ui::ImportDialog::height->blockSignals(false);
}
void ImportDialog::setHeight(int v)
{
int adjustedw = origsize_.width() / (origsize_.height() / (float) v);
if (adjustedw > 1000) {
setWidth(1000);
return;
}
Ui::ImportDialog::width->blockSignals(true);
Ui::ImportDialog::height->blockSignals(true);
Ui::ImportDialog::width->setValue(adjustedw);
Ui::ImportDialog::height->setValue(v);
Ui::ImportDialog::width->blockSignals(false);
Ui::ImportDialog::height->blockSignals(false);
}
void ImportDialog::selectColor()
{
QColorDialog cd(transparentColor_, this);
cd.exec();
if (cd.result() != QDialog::Accepted)
return;
transparentColor_ = cd.selectedColor();
Ui::ImportDialog::transparentColor->setText(transparentColor_.name());
}