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);
31 layout->addWidget(
browse, line++, 2);
32 connect(
browse, SIGNAL(clicked(
bool)),
this, SLOT(
browse(
bool)));
34 layout->addWidget(
new QLabel(tr(
"Archetype name:"),
this), line, 0);
36 layout->addWidget(
myName, line++, 1, 1, 2);
38 layout->addWidget(
new QLabel(tr(
"Color:"),
this), line, 0);
43 layout->addWidget(
new QLabel(tr(
"Y position from top:"),
this), line, 0);
46 layout->addWidget(
myShift, line++, 1, 1, 2);
48 layout->addWidget(
new QLabel(tr(
"Bar height:"),
this), line, 0);
52 layout->addWidget(
myHeight, line++, 1, 1, 2);
54 QDialogButtonBox* box =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close, Qt::Horizontal,
this);
55 layout->addWidget(box, line++, 1, 1, 3);
56 connect(box, SIGNAL(rejected()),
this, SLOT(reject()));
57 connect(box, SIGNAL(accepted()),
this, SLOT(
makeBar()));
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()));
101 for (
int value = 1; value <= 30; value++)
103 char c = value < 10 ?
'0' + value :
'a' + value - 10;
104 QString line = QString(
"Object %1_%2\nface %1.11%3\nend\n").arg(
myName->text()).arg(value).arg(c);
105 arc.write(line.toLocal8Bit());
108 pic.fill(QColor(0, 0, 0, 0));
109 QPainter device(&pic);
110 device.fillRect(1, shift, value, height,
myColor);
112 QString picName = base +
".base.11" + c +
".png";
114 if (!pic.save(picName,
"PNG"))
116 QMessageBox::critical(
this, tr(
"Error"), tr(
"Error while saving the picture %1!").arg(picName));
124 QMessageBox::information(
this, tr(
"Bar created"), tr(
"The bar was correctly saved as %1").arg(arc.fileName()));
129 QString dest = QFileDialog::getExistingDirectory(
this, tr(
"Select destination directory"),
"");
138 const QString style(
"QPushButton { background-color : %1; }");
144 QColor color = QColorDialog::getColor(
myColor,
this, tr(
"Select bar color"), QColorDialog::ShowAlphaChannel);
145 if (!color.isValid())