-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathTdwManagerDialog.cpp
158 lines (126 loc) · 4.77 KB
/
TdwManagerDialog.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
146
147
148
149
150
151
152
153
154
155
156
157
158
/****************************************************************************
** Deling Final Fantasy VIII Field Editor
** Copyright (C) 2009-2012 Arzel Jérôme <[email protected]>
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "TdwManagerDialog.h"
TdwManagerDialog::TdwManagerDialog(QWidget *parent) :
QDialog(parent, Qt::Dialog | Qt::WindowCloseButtonHint)
{
setWindowTitle(tr("Gestionnaire de police"));
setSizeGripEnabled(true);
ListWidget *listWidget = new ListWidget(this);
plusAction = listWidget->addAction(ListWidget::Add, tr("Copier"), this, SLOT(addFont()));
minusAction = listWidget->addAction(ListWidget::Rem, tr("Effacer"), this, SLOT(removeFont()));
toolbar1 = listWidget->toolBar();
list1 = listWidget->listWidget();
tdwWidget = new TdwWidget2(false, this);
QHBoxLayout *layout = new QHBoxLayout(this);
layout->addWidget(listWidget);
layout->addWidget(tdwWidget, 1);
fillList1();
setTdw(list1->currentRow());
connect(list1, SIGNAL(currentRowChanged(int)), SLOT(setTdw(int)));
}
void TdwManagerDialog::fillList1()
{
QString currentEncoding = Config::value("encoding", "00").toString();
foreach(const QString &fontName, FF8Font::fontList()) {
QListWidgetItem *item;
if(fontName == "00" || fontName == "01") {
item = new QListWidgetItem(fontName == "00" ? tr("Latin") : tr("Japonais"));
item->setData(Qt::UserRole, fontName);
list1->addItem(item);
} else {
FF8Font *font = FF8Font::font(fontName);
if(font) {
item = new QListWidgetItem(font->name());
item->setData(Qt::UserRole, fontName);
list1->addItem(item);
} else {
continue;
}
}
if(currentEncoding == fontName) {
list1->setCurrentItem(item);
}
}
}
void TdwManagerDialog::setTdw(int id)
{
QListWidgetItem *item = list1->item(id);
if(!item) return;
QString fontName = item->data(Qt::UserRole).toString();
FF8Font *font = FF8Font::font(fontName);
if(font) {
tdwWidget->setFF8Font(font);
}
minusAction->setEnabled(!font->isReadOnly());
}
void TdwManagerDialog::addFont()
{
QListWidgetItem *item = list1->currentItem();
if(!item) return;
QString name, nameId;
if(newNameDialog(name, nameId)) {
if(FF8Font::copyFont(nameId, item->data(Qt::UserRole).toString(), name)) {
item = new QListWidgetItem(name);
item->setData(Qt::UserRole, nameId);
list1->addItem(item);
}
}
}
bool TdwManagerDialog::newNameDialog(QString &name, QString &nameId)
{
QDialog dialog(this, Qt::Dialog | Qt::WindowCloseButtonHint);
QLineEdit *nameEdit = new QLineEdit(&dialog);
QLineEdit *fileNameEdit = new QLineEdit(&dialog);
QPushButton *ok = new QPushButton(tr("OK"));
ok->setDefault(true);
QFormLayout *formLayout = new QFormLayout;
formLayout->addRow(tr("Nom &affiché :"), nameEdit);
formLayout->addRow(tr("Nom du &fichier :"), fileNameEdit);
QVBoxLayout *layout = new QVBoxLayout(&dialog);
layout->addLayout(formLayout, 1);
layout->addWidget(ok, 0, Qt::AlignCenter);
connect(ok, SIGNAL(clicked()), &dialog, SLOT(accept()));
if(dialog.exec() == QDialog::Accepted) {
QString name1 = nameEdit->text();
QString name2 = QDir::cleanPath(fileNameEdit->text());
QStringList fontList = FF8Font::fontList();
if(name1.isEmpty() || name2.isEmpty()
|| fontList.contains(name1)
|| QFile::exists(FF8Font::fontDirPath()+"/"+name2)) {
QMessageBox::warning(this, tr("Choisissez un autre nom"), tr("Ce nom existe déjà ou est invalide, veuillez en choisir un autre."));
return false;
}
name = name1;
nameId = name2;
return true;
}
return false;
}
void TdwManagerDialog::removeFont()
{
QList<QListWidgetItem *> items = list1->selectedItems();
if(items.isEmpty()) return;
if(QMessageBox::Yes != QMessageBox::question(this, tr("Supprimer une police"), tr("Voulez-vous vraiment supprimer la police sélectionnée ?"), QMessageBox::Yes | QMessageBox::Cancel)) {
return;
}
QListWidgetItem *item = items.first();
if(FF8Font::removeFont(item->data(Qt::UserRole).toString())) {
delete item;
}
}