-
Notifications
You must be signed in to change notification settings - Fork 1
/
ICCDialog2.cpp
145 lines (115 loc) · 3.5 KB
/
ICCDialog2.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <QtWidgets>
#include <QSettings>
#include "QtUtil.h"
#include "ICCDialog2.h"
#include "ui_ICCDialog2.h"
QString ICCDialog2::m_rgbProfile;
QString ICCDialog2::m_cmykProfile;
QString ICCDialog2::m_grayProfile;
// don't translate these
#define RGB_SETTINGS_KEY "RGB Profile"
#define CMYK_SETTINGS_KEY "CMYK Profile"
#define GRAY_SETTINGS_KEY "Gray Profile"
ICCDialog2::ICCDialog2(QWidget *parent) :
QDialog(parent),
ui(new Ui::ICCDialog2)
{
ui->setupUi(this);
}
ICCDialog2::~ICCDialog2()
{
delete ui;
}
void ICCDialog2::show()
{
// get previous values from QSettings
QSettings settings;
m_rgbProfile = settings.value(RGB_SETTINGS_KEY, QString("")).toString();
m_cmykProfile = settings.value(CMYK_SETTINGS_KEY, QString("")).toString();
m_grayProfile = settings.value(GRAY_SETTINGS_KEY, QString("")).toString();
refreshUI();
this->setWindowModality(Qt::ApplicationModal);
QDialog::show();
}
void ICCDialog2::on_grayButton_clicked()
{
QString result = askForProfile();
if (!result.isEmpty())
m_grayProfile = result;
refreshUI();
}
void ICCDialog2::on_rgbButton_clicked()
{
QString result = askForProfile();
if (!result.isEmpty())
m_rgbProfile = result;
refreshUI();
}
void ICCDialog2::on_cmykButton_clicked()
{
QString result = askForProfile();
if (!result.isEmpty())
m_cmykProfile = result;
refreshUI();
}
void ICCDialog2::on_okButton_clicked()
{
// save current values using QSettings
QSettings settings;
settings.setValue(RGB_SETTINGS_KEY, m_rgbProfile);
settings.setValue(CMYK_SETTINGS_KEY, m_cmykProfile);
settings.setValue(GRAY_SETTINGS_KEY, m_grayProfile);
close();
}
void ICCDialog2::refreshUI()
{
QString styleEmpty("QLabel { color:red; border: 1px solid; border-color: red;}");
QString styleNotEmpty("QLabel { color:black; border: 0px none;}");
QString emptyText(tr("Not Set"));
ui->rgbLabel->setStyleSheet(styleNotEmpty);
if (m_rgbProfile.isEmpty())
{
ui->rgbLabel->setText(emptyText);
ui->rgbLabel->setStyleSheet(styleEmpty);
}
else
ui->rgbLabel->setText(m_rgbProfile);
ui->cmykLabel->setStyleSheet(styleNotEmpty);
if (m_cmykProfile.isEmpty())
{
ui->cmykLabel->setText(emptyText);
ui->cmykLabel->setStyleSheet(styleEmpty);
}
else
ui->cmykLabel->setText(m_cmykProfile);
ui->grayLabel->setStyleSheet(styleNotEmpty);
if (m_grayProfile.isEmpty())
{
ui->grayLabel->setText(emptyText);
ui->grayLabel->setStyleSheet(styleEmpty);
}
else
ui->grayLabel->setText(m_grayProfile);
}
QString ICCDialog2::askForProfile()
{
// get the last-visited directory. Default is desktop
QString lastDir = QtUtil::getLastOpenFileDir();
// create a dialog for choosing a file
QFileDialog dialog(NULL, tr("Choose a Color Profile"), lastDir);
dialog.setAcceptMode(QFileDialog::AcceptOpen);
dialog.setOption(QFileDialog::DontUseNativeDialog, !USE_NATIVE_FILE_DIALOGS);
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setNameFilter(tr("ICC Profile Files (*.icc *.icm)"));
dialog.setWindowModality(Qt::ApplicationModal);
// show and run the dialog
dialog.show();
int result = dialog.exec();
if (result == QDialog::Accepted)
{
// remember the last-visited directory
QtUtil::setLastOpenFileDir(dialog.directory().absolutePath());
return dialog.selectedFiles().first();
}
return QString("");
}