final ports and first fixes
This commit is contained in:
1 parent
77690cbd96
commit
6f3556009a
23 files changed
+2302
-41
No files matched your search
@@ -86,14 +86,40 @@ void GraphicSet::loadFromFile(const QString &fileName)
|
||||
QXmlStreamReader xml(&file);
|
||||
while (!xml.atEnd()) {
|
||||
xml.readNext();
|
||||
if (xml.isStartElement() && xml.name() == QLatin1String("Item")) {
|
||||
const QXmlStreamAttributes attrs = xml.attributes();
|
||||
GraphicSetItem *newItem = addNew(attrs.value("Name").toString());
|
||||
newItem->left = attrs.value("Left").toInt();
|
||||
newItem->top = attrs.value("Top").toInt();
|
||||
newItem->width = attrs.value("Width").toInt();
|
||||
newItem->height = attrs.value("Height").toInt();
|
||||
if (!xml.isStartElement() || xml.name() != QLatin1String("Item"))
|
||||
continue;
|
||||
// The original format stores each field as a child element (<Name>, <Left>, ...);
|
||||
// attributes are accepted too.
|
||||
const QXmlStreamAttributes attrs = xml.attributes();
|
||||
QString name = attrs.value("Name").toString();
|
||||
int left = attrs.value("Left").toInt();
|
||||
int top = attrs.value("Top").toInt();
|
||||
int width = attrs.value("Width").toInt();
|
||||
int height = attrs.value("Height").toInt();
|
||||
while (!xml.atEnd()) {
|
||||
xml.readNext();
|
||||
if (xml.isEndElement() && xml.name() == QLatin1String("Item"))
|
||||
break;
|
||||
if (!xml.isStartElement())
|
||||
continue;
|
||||
const QString field = xml.name().toString();
|
||||
const QString text = xml.readElementText();
|
||||
if (field == QLatin1String("Name"))
|
||||
name = text;
|
||||
else if (field == QLatin1String("Left"))
|
||||
left = text.toInt();
|
||||
else if (field == QLatin1String("Top"))
|
||||
top = text.toInt();
|
||||
else if (field == QLatin1String("Width"))
|
||||
width = text.toInt();
|
||||
else if (field == QLatin1String("Height"))
|
||||
height = text.toInt();
|
||||
}
|
||||
GraphicSetItem *newItem = addNew(name);
|
||||
newItem->left = left;
|
||||
newItem->top = top;
|
||||
newItem->width = width;
|
||||
newItem->height = height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,11 +136,11 @@ void GraphicSet::saveToFile(const QString &fileName) const
|
||||
xml.writeStartElement(QLatin1String("Items"));
|
||||
for (GraphicSetItem *item : m_items) {
|
||||
xml.writeStartElement(QLatin1String("Item"));
|
||||
xml.writeAttribute(QLatin1String("Name"), item->name);
|
||||
xml.writeAttribute(QLatin1String("Left"), QString::number(item->left));
|
||||
xml.writeAttribute(QLatin1String("Top"), QString::number(item->top));
|
||||
xml.writeAttribute(QLatin1String("Width"), QString::number(item->width));
|
||||
xml.writeAttribute(QLatin1String("Height"), QString::number(item->height));
|
||||
xml.writeTextElement(QLatin1String("Name"), item->name);
|
||||
xml.writeTextElement(QLatin1String("Left"), QString::number(item->left));
|
||||
xml.writeTextElement(QLatin1String("Top"), QString::number(item->top));
|
||||
xml.writeTextElement(QLatin1String("Width"), QString::number(item->width));
|
||||
xml.writeTextElement(QLatin1String("Height"), QString::number(item->height));
|
||||
xml.writeEndElement();
|
||||
}
|
||||
xml.writeEndElement();
|
||||
|
||||
@@ -956,6 +956,19 @@ void paintLogo(Dpi::Canvas &canvas, int x, int y, QColor lightColor, QColor shad
|
||||
canvas.copyRect(QRect(x, y, logo->width, logo->height), drawBuffer.canvas(), QRect(0, 0, logo->width, logo->height));
|
||||
}
|
||||
|
||||
void darkenImage(Dpi::Bitmap &bitmap, int change)
|
||||
{
|
||||
QImage &image = bitmap.image();
|
||||
for (int y = 0; y < image.height(); ++y) {
|
||||
for (int x = 0; x < image.width(); ++x) {
|
||||
const QRgb c = image.pixel(x, y);
|
||||
image.setPixel(x, y,
|
||||
qRgba(std::max(qRed(c) - change, 0), std::max(qGreen(c) - change, 0),
|
||||
std::max(qBlue(c) - change, 0), qAlpha(c)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
bool ornamentInitialized = false;
|
||||
}
|
||||
|
||||
@@ -31,13 +31,12 @@
|
||||
namespace Dpi {
|
||||
|
||||
PixelPointer::PixelPointer(QImage *image, int baseX, int baseY)
|
||||
: m_image(image)
|
||||
: m_image(image), m_baseX(baseX), m_baseY(baseY)
|
||||
{
|
||||
if (m_image) {
|
||||
m_width = m_image->width();
|
||||
m_height = m_image->height();
|
||||
}
|
||||
setXY(baseX, baseY);
|
||||
}
|
||||
|
||||
void PixelPointer::setXY(int x, int y)
|
||||
@@ -64,30 +63,34 @@ void PixelPointer::previousPixel()
|
||||
void PixelPointer::nextLine()
|
||||
{
|
||||
++m_y;
|
||||
m_x = 0;
|
||||
}
|
||||
|
||||
void PixelPointer::previousLine()
|
||||
{
|
||||
--m_y;
|
||||
m_x = 0;
|
||||
}
|
||||
|
||||
bool PixelPointer::posValid() const
|
||||
{
|
||||
return m_image && m_x >= 0 && m_x < m_width && m_y >= 0 && m_y < m_height;
|
||||
const int x = m_baseX + m_x;
|
||||
const int y = m_baseY + m_y;
|
||||
return m_image && x >= 0 && x < m_width && y >= 0 && y < m_height;
|
||||
}
|
||||
|
||||
QRgb PixelPointer::pixelARGB() const
|
||||
{
|
||||
if (!posValid())
|
||||
return 0;
|
||||
return reinterpret_cast<const QRgb *>(m_image->constScanLine(m_y))[m_x];
|
||||
return reinterpret_cast<const QRgb *>(m_image->constScanLine(m_baseY + m_y))[m_baseX + m_x];
|
||||
}
|
||||
|
||||
void PixelPointer::setPixelARGB(QRgb value)
|
||||
{
|
||||
if (!posValid())
|
||||
return;
|
||||
reinterpret_cast<QRgb *>(m_image->scanLine(m_y))[m_x] = value;
|
||||
reinterpret_cast<QRgb *>(m_image->scanLine(m_baseY + m_y))[m_baseX + m_x] = value;
|
||||
}
|
||||
|
||||
QRgb PixelPointer::pixelRGB() const
|
||||
|
||||
Reference in new issue
Block a user