/*
Copyright (C) 2022 Lari Varjonen <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "draw_pixmap.h"
void DrawPixmap::draw_pixmap(const QString SIGNATURE_TEXT)
{
if (images.isEmpty())
{
return;
}
QPixmap *pixmap = new QPixmap(width_spin, starting_height);
pixmap->fill(Qt::black);
QPainter *painter = new QPainter(pixmap);
painter->setPen(Qt::white);
QFont font;
font.setFamily("Arial");
font.setPixelSize(16);
font.setItalic(true);
font.setWeight(QFont::Thin);
painter->setFont(font);
QPoint point;
int y_pos = 0;
if (!file_text.isEmpty())
{
y_pos += 16;
point = QPoint(2, y_pos);
painter->drawText(point, QString("File: ") + file_text);
y_pos += 2;
}
if (!size_text.isEmpty())
{
y_pos += 16;
point = QPoint(2, y_pos);
painter->drawText(point, QString("Size: ") + size_text);
y_pos += 2;
}
if (!audio_text.isEmpty())
{
y_pos += 16;
point = QPoint(2, y_pos);
painter->drawText(point, QString("Audio: ") + audio_text);
y_pos += 2;
}
if (!video_text.isEmpty())
{
y_pos += 16;
point = QPoint(2, y_pos);
painter->drawText(point, QString("Video: ") + video_text);
y_pos += 2;
}
if (!hide_signature)
{
y_pos += 16;
point = QPoint(2, y_pos);
painter->drawText(point, QString("Generated by ") + SIGNATURE_TEXT);
y_pos += 2;
}
if (y_pos != 0)
{
y_pos += 4;
}
int x = 0;
int f = divider_spin;
int img_scaled_height = images.at(0).height();
for (qsizetype i = 0; i < images.size(); i++)
{
if (i == f)
{
f = i + divider_spin;
y_pos += images.at(i).height();
x = 0;
}
if (y_pos + images.at(i).height() > starting_height)
{
starting_height = y_pos + images.at(i).height();
QPixmap *new_pixmap = new QPixmap(width_spin, starting_height);
new_pixmap->fill(Qt::black);
QPainter *new_painter = new QPainter(new_pixmap);
new_painter->drawPixmap(0, 0, pixmap->width(), pixmap->height(), *pixmap);
delete painter;
delete pixmap;
pixmap = new_pixmap;
painter = new_painter;
}
point = QPoint(x, y_pos);
painter->drawImage(point, images.at(i));
if (!hide_timestamp)
{
font.setFamily("Arial");
font.setStyle(QFont::StyleItalic);
font.setStyleHint(QFont::AnyStyle);
font.setPixelSize(12);
font.setItalic(true);
font.setWeight(QFont::Thin);
painter->setFont(font);
QString time = time_stamps[i];
QFontMetrics fm(font);
int text_width = fm.horizontalAdvance(time);
int text_x = x + images.at(i).width() - text_width - 1;
int text_y = (y_pos + images.at(i).height()) - 1;
point = QPoint(text_x, text_y);
painter->setPen(Qt::black);
painter->drawText(point, time);
point = QPoint(text_x - 1, text_y - 1);
painter->setPen(Qt::white);
painter->drawText(point, time);
}
x += images.at(i).width();
}
QRect rect(0, 0, width_spin, y_pos + img_scaled_height);
generated_pixmap = pixmap->copy(rect);
delete painter;
delete pixmap;
}
/* Copyright (C) 2022 Lari Varjonen <[email protected]> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "draw_pixmap.h" void DrawPixmap::draw_pixmap(const QString SIGNATURE_TEXT) { if (images.isEmpty()) { return; } QPixmap *pixmap = new QPixmap(width_spin, starting_height); pixmap->fill(Qt::black); QPainter *painter = new QPainter(pixmap); painter->setPen(Qt::white); QFont font; font.setFamily("Arial"); font.setPixelSize(16); font.setItalic(true); font.setWeight(QFont::Thin); painter->setFont(font); QPoint point; int y_pos = 0; if (!file_text.isEmpty()) { y_pos += 16; point = QPoint(2, y_pos); painter->drawText(point, QString("File: ") + file_text); y_pos += 2; } if (!size_text.isEmpty()) { y_pos += 16; point = QPoint(2, y_pos); painter->drawText(point, QString("Size: ") + size_text); y_pos += 2; } if (!audio_text.isEmpty()) { y_pos += 16; point = QPoint(2, y_pos); painter->drawText(point, QString("Audio: ") + audio_text); y_pos += 2; } if (!video_text.isEmpty()) { y_pos += 16; point = QPoint(2, y_pos); painter->drawText(point, QString("Video: ") + video_text); y_pos += 2; } if (!hide_signature) { y_pos += 16; point = QPoint(2, y_pos); painter->drawText(point, QString("Generated by ") + SIGNATURE_TEXT); y_pos += 2; } if (y_pos != 0) { y_pos += 4; } int x = 0; int f = divider_spin; int img_scaled_height = images.at(0).height(); for (qsizetype i = 0; i < images.size(); i++) { if (i == f) { f = i + divider_spin; y_pos += images.at(i).height(); x = 0; } if (y_pos + images.at(i).height() > starting_height) { starting_height = y_pos + images.at(i).height(); QPixmap *new_pixmap = new QPixmap(width_spin, starting_height); new_pixmap->fill(Qt::black); QPainter *new_painter = new QPainter(new_pixmap); new_painter->drawPixmap(0, 0, pixmap->width(), pixmap->height(), *pixmap); delete painter; delete pixmap; pixmap = new_pixmap; painter = new_painter; } point = QPoint(x, y_pos); painter->drawImage(point, images.at(i)); if (!hide_timestamp) { font.setFamily("Arial"); font.setStyle(QFont::StyleItalic); font.setStyleHint(QFont::AnyStyle); font.setPixelSize(12); font.setItalic(true); font.setWeight(QFont::Thin); painter->setFont(font); QString time = time_stamps[i]; QFontMetrics fm(font); int text_width = fm.horizontalAdvance(time); int text_x = x + images.at(i).width() - text_width - 1; int text_y = (y_pos + images.at(i).height()) - 1; point = QPoint(text_x, text_y); painter->setPen(Qt::black); painter->drawText(point, time); point = QPoint(text_x - 1, text_y - 1); painter->setPen(Qt::white); painter->drawText(point, time); } x += images.at(i).width(); } QRect rect(0, 0, width_spin, y_pos + img_scaled_height); generated_pixmap = pixmap->copy(rect); delete painter; delete pixmap; }
/*
    Copyright (C) 2022 Lari Varjonen <[email protected]>

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    version 2 as published by the Free Software Foundation.

    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, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "draw_pixmap.h"


void DrawPixmap::draw_pixmap(const QString SIGNATURE_TEXT)
{
    if (images.isEmpty())
    {
        return;
    }

    QPixmap *pixmap = new QPixmap(width_spin, starting_height);
    pixmap->fill(Qt::black);

    QPainter *painter = new QPainter(pixmap);
    painter->setPen(Qt::white);

    QFont font;
    font.setFamily("Arial");
    font.setPixelSize(16);
    font.setItalic(true);
    font.setWeight(QFont::Thin);
    painter->setFont(font);

    QPoint point;
    int y_pos = 0;

    if (!file_text.isEmpty())
    {
        y_pos += 16;
        point = QPoint(2, y_pos);
        painter->drawText(point, QString("File: ") + file_text);
        y_pos += 2;
    }

    if (!size_text.isEmpty())
    {
        y_pos += 16;
        point = QPoint(2, y_pos);
        painter->drawText(point, QString("Size: ") + size_text);
        y_pos += 2;
    }

    if (!audio_text.isEmpty())
    {
        y_pos += 16;
        point = QPoint(2, y_pos);
        painter->drawText(point, QString("Audio: ") + audio_text);
        y_pos += 2;
    }

    if (!video_text.isEmpty())
    {
        y_pos += 16;
        point = QPoint(2, y_pos);
        painter->drawText(point, QString("Video: ") + video_text);
        y_pos += 2;
    }

    if (!hide_signature)
    {
        y_pos += 16;
        point = QPoint(2, y_pos);
        painter->drawText(point, QString("Generated by ") + SIGNATURE_TEXT);
        y_pos += 2;
    }

    if (y_pos != 0)
    {
        y_pos += 4;
    }

    int x = 0;
    int f = divider_spin;
    int img_scaled_height = images.at(0).height();

    for (qsizetype i = 0; i < images.size(); i++)
    {
        if (i == f)
        {
            f = i + divider_spin;
            y_pos += images.at(i).height();
            x = 0;
        }

        if (y_pos + images.at(i).height() > starting_height)
        {
            starting_height = y_pos + images.at(i).height();

            QPixmap *new_pixmap = new QPixmap(width_spin, starting_height);
            new_pixmap->fill(Qt::black);

            QPainter *new_painter = new QPainter(new_pixmap);
            new_painter->drawPixmap(0, 0, pixmap->width(), pixmap->height(), *pixmap);

            delete painter;
            delete pixmap;

            pixmap = new_pixmap;
            painter = new_painter;
        }

        point = QPoint(x, y_pos);
        painter->drawImage(point, images.at(i));

        if (!hide_timestamp)
        {
            font.setFamily("Arial");
            font.setStyle(QFont::StyleItalic);
            font.setStyleHint(QFont::AnyStyle);
            font.setPixelSize(12);
            font.setItalic(true);
            font.setWeight(QFont::Thin);
            painter->setFont(font);

            QString time = time_stamps[i];
            QFontMetrics fm(font);
            int text_width = fm.horizontalAdvance(time);

            int text_x = x + images.at(i).width() - text_width - 1;
            int text_y = (y_pos + images.at(i).height()) - 1;

            point = QPoint(text_x, text_y);
            painter->setPen(Qt::black);
            painter->drawText(point, time);

            point = QPoint(text_x - 1, text_y - 1);
            painter->setPen(Qt::white);
            painter->drawText(point, time);
        }

        x += images.at(i).width();
    }

    QRect rect(0, 0, width_spin, y_pos + img_scaled_height);
    generated_pixmap = pixmap->copy(rect);

    delete painter;
    delete pixmap;
}