Crossfire Server, Trunk  R20513
CREHPBarMaker.cpp
Go to the documentation of this file.
1 #include "CREHPBarMaker.h"
2 #include "CREPixmap.h"
3 #include <QtGui>
4 #include <qt4/QtCore/qiodevice.h>
5 #include <qt4/QtCore/qfile.h>
6 
7 extern "C" {
8 #include "global.h"
9 }
10 
12 {
13  QGridLayout* layout = new QGridLayout(this);
14  int line = 0;
15 
16  layout->addWidget(new QLabel(tr("Path where to create items:"), this), line, 0);
17  myDestination = new QLineEdit();
18  layout->addWidget(myDestination, line, 1);
19 
20  QPushButton* browse = new QPushButton(tr("Browse"), this);
21  layout->addWidget(browse, line++, 2);
22  connect(browse, SIGNAL(clicked(bool)), this, SLOT(browse(bool)));
23 
24  layout->addWidget(new QLabel(tr("Archetype name:"), this), line, 0);
25  myName = new QLineEdit();
26  layout->addWidget(myName, line++, 1, 1, 2);
27 
28  layout->addWidget(new QLabel(tr("Color:"), this), line, 0);
29  myColorSelect = new QPushButton();
30  layout->addWidget(myColorSelect, line++, 1, 1, 2);
31  connect(myColorSelect, SIGNAL(clicked(bool)), this, SLOT(selectColor(bool)));
32 
33  layout->addWidget(new QLabel(tr("Y position from top:"), this), line, 0);
34  myShift = new QSpinBox(this);
35  myShift->setRange(1, 31);
36  layout->addWidget(myShift, line++, 1, 1, 2);
37 
38  layout->addWidget(new QLabel(tr("Bar height:"), this), line, 0);
39  myHeight = new QSpinBox(this);
40  myHeight->setRange(1, 31);
41  myHeight->setValue(5);
42  layout->addWidget(myHeight, line++, 1, 1, 2);
43 
44  QDialogButtonBox* box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close, Qt::Horizontal, this);
45  layout->addWidget(box, line++, 1, 1, 3);
46  connect(box, SIGNAL(rejected()), this, SLOT(reject()));
47  connect(box, SIGNAL(accepted()), this, SLOT(makeBar()));
48 
49  myColor = QColor::fromRgb(255, 0, 0, 180);
50  adjustColor();
51 
52  setWindowTitle(tr("HP bar face generator"));
53 }
54 
56 {
57 }
58 
60 {
61  if (myDestination->text().isEmpty())
62  {
63  QMessageBox::warning(this, tr("Oops"), tr("You must select a destination!"));
64  return;
65  }
66 
67  if (myName->text().isEmpty())
68  {
69  QMessageBox::warning(this, tr("Oops"), tr("You must enter a name!"));
70  return;
71  }
72 
73  QString base = myDestination->text() + QDir::separator() + myName->text();
74 
75  if (QFile::exists(base + ".arc"))
76  {
77  if (QMessageBox::question(this, tr("Confirm file overwrite"), tr("File %1 already exists. Overwrite it?").arg(base + ".arc"), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
78  return;
79  }
80 
81  QFile arc(base + ".arc");
82  if (!arc.open(QFile::Truncate | QFile::WriteOnly))
83  {
84  QMessageBox::critical(this, tr("Error"), tr("Error while opening the archetype file %1!").arg(arc.fileName()));
85  return;
86  }
87 
88  int shift = myShift->value();
89  int height = myHeight->value();
90 
91  for (int value = 1; value <= 30; value++)
92  {
93  QString line = tr("Object %1_%2\nface %1_%2.111\nend\n").arg(myName->text()).arg(value);
94  arc.write(line.toLocal8Bit());
95 
96  QPixmap pic(32, 32);
97  pic.fill(QColor(0, 0, 0, 0));
98  QPainter device(&pic);
99  device.fillRect(1, shift, value, height, myColor);
100 
101  QString picName = base + "_" + QString::number(value) + ".base.111.png";
102 
103  if (!pic.save(picName, "PNG"))
104  {
105  QMessageBox::critical(this, tr("Error"), tr("Error while saving the picture %1!").arg(picName));
106  return;
107  }
108 
109  }
110 
111  arc.close();
112 
113  QMessageBox::information(this, tr("Bar created"), tr("The bar was correctly saved as %1").arg(arc.fileName()));
114 }
115 
117 {
118  QString dest = QFileDialog::getExistingDirectory(this, tr("Select destination directory"), "");
119  if (dest.isEmpty())
120  return;
121 
122  myDestination->setText(dest);
123 }
124 
126 {
127  const QString style("QPushButton { background-color : %1; }");
128  myColorSelect->setStyleSheet(style.arg(myColor.name()));
129 }
130 
132 {
133  QColor color = QColorDialog::getColor(myColor, this, tr("Select bar color"), QColorDialog::ShowAlphaChannel);
134  if (!color.isValid())
135  return;
136  myColor = color;
137  adjustColor();
138 }
void selectColor(bool)
void browse(bool)
Global type definitions and header inclusions.
QPushButton * myColorSelect
Definition: CREHPBarMaker.h:32
QSpinBox * myHeight
Definition: CREHPBarMaker.h:29
QLineEdit * myName
Definition: CREHPBarMaker.h:28
virtual ~CREHPBarMaker()
QLineEdit * myDestination
Definition: CREHPBarMaker.h:27
QSpinBox * myShift
Definition: CREHPBarMaker.h:30
Definition: main.c:88