16 #include <QtCore/qiodevice.h>
17 #include <QtCore/qfile.h>
23 QGridLayout*
layout =
new QGridLayout(
this);
26 layout->addWidget(
new QLabel(tr(
"Path where to create items:"),
this),
line, 0);
30 QPushButton*
browse =
new QPushButton(tr(
"Browse"),
this);
34 layout->addWidget(
new QLabel(tr(
"Archetype name:"),
this),
line, 0);
38 layout->addWidget(
new QLabel(tr(
"Color:"),
this),
line, 0);
43 layout->addWidget(
new QLabel(tr(
"Y position from top:"),
this),
line, 0);
48 layout->addWidget(
new QLabel(tr(
"Bar height:"),
this),
line, 0);
54 QDialogButtonBox*
box =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close, Qt::Horizontal,
this);
56 connect(
box, SIGNAL(rejected()),
this, SLOT(reject()));
59 myColor = QColor::fromRgb(255, 0, 0, 180);
62 setWindowTitle(tr(
"HP bar face generator"));
73 QMessageBox::warning(
this, tr(
"Oops"), tr(
"You must select a destination!"));
77 if (
myName->text().isEmpty())
79 QMessageBox::warning(
this, tr(
"Oops"), tr(
"You must enter a name!"));
85 if (QFile::exists(base +
".arc"))
87 if (QMessageBox::question(
this, tr(
"Confirm file overwrite"), tr(
"File %1 already exists. Overwrite it?").arg(base +
".arc"), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
91 QFile arc(base +
".arc");
92 if (!arc.open(QFile::Truncate | QFile::WriteOnly))
94 QMessageBox::critical(
this, tr(
"Error"), tr(
"Error while opening the archetype file %1!").arg(arc.fileName()));
103 QString
line = QString(
"Object %1_%2\nface %1_%2.111\nend\n").arg(
myName->text()).arg(
value);
104 arc.write(
line.toLocal8Bit());
107 pic.fill(QColor(0, 0, 0, 0));
108 QPainter device(&pic);
111 QString picName = base +
"_" + QString::number(
value) +
".base.111.png";
113 if (!pic.save(picName,
"PNG"))
115 QMessageBox::critical(
this, tr(
"Error"), tr(
"Error while saving the picture %1!").arg(picName));
123 QMessageBox::information(
this, tr(
"Bar created"), tr(
"The bar was correctly saved as %1").arg(arc.fileName()));
128 QString
dest = QFileDialog::getExistingDirectory(
this, tr(
"Select destination directory"),
"");
137 const QString
style(
"QPushButton { background-color : %1; }");
143 QColor
color = QColorDialog::getColor(
myColor,
this, tr(
"Select bar color"), QColorDialog::ShowAlphaChannel);
144 if (!
color.isValid())