mirror of
https://github.com/riuson/lcd-image-converter.git
synced 2026-03-14 03:57:02 +01:00
69 lines
2.1 KiB
C++
69 lines
2.1 KiB
C++
/*
|
|
* LCD Image Converter. Converts images and fonts for embedded applications.
|
|
* Copyright (C) 2016 riuson
|
|
* mailto: riuson@gmail.com
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* 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, see <http://www.gnu.org/licenses/
|
|
*/
|
|
|
|
#include "imageresize.h"
|
|
#include "dialogcanvasresize.h"
|
|
#include "idocument.h"
|
|
#include "datacontainer.h"
|
|
#include "bitmaphelper.h"
|
|
|
|
namespace Operations
|
|
{
|
|
|
|
ImageResize::ImageResize(QWidget *parentWidget, QObject *parent)
|
|
: QObject(parent)
|
|
{
|
|
this->mParentWidget = parentWidget;
|
|
this->mLeft = 0;
|
|
this->mTop = 0;
|
|
this->mRight = 0;
|
|
this->mBottom = 0;
|
|
}
|
|
|
|
bool ImageResize::prepare(const Data::Containers::IDocument *doc, const QStringList &keys)
|
|
{
|
|
AppUI::CommonDialogs::DialogCanvasResize dialog(doc->dataContainer(), this->mParentWidget);
|
|
dialog.selectKeys(keys);
|
|
|
|
if (dialog.exec() == QDialog::Accepted) {
|
|
dialog.resizeInfo(&this->mLeft, &this->mTop, &this->mRight, &this->mBottom);
|
|
|
|
if (this->mLeft != 0 || this->mTop != 0 || this->mRight != 0 || this->mBottom != 0) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void ImageResize::applyDocument(Data::Containers::IDocument *doc, const QStringList &keys)
|
|
{
|
|
Q_UNUSED(doc)
|
|
Q_UNUSED(keys)
|
|
}
|
|
|
|
void ImageResize::applyItem(Data::Containers::IDocument *doc, const QString &itemKey)
|
|
{
|
|
const QImage *original = doc->dataContainer()->image(itemKey);
|
|
QImage result = Parsing::Conversion::BitmapHelper::crop(original, this->mLeft, this->mTop, this->mRight, this->mBottom, Parsing::Conversion::BitmapHelper::detectBackgroundColor(original));
|
|
doc->dataContainer()->setImage(itemKey, &result);
|
|
}
|
|
|
|
}
|