/* * LCD Image Converter. Converts images and fonts for embedded applications. * Copyright (C) 2010 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 #include #include #include #include #include #include #include "widgetbitmapeditor.h" #include "datacontainer.h" #include "parser.h" #include "tags.h" #include "statusdata.h" #include "imagedocument.h" //----------------------------------------------------------------------------- EditorTabImage::EditorTabImage(QWidget *parent) : QWidget(parent), ui(new Ui::EditorTabImage) { ui->setupUi(this); QHBoxLayout *layout = new QHBoxLayout(this); this->setLayout(layout); this->mDocument = new ImageDocument(this); this->mEditor = new WidgetBitmapEditor(this); layout->addWidget(this->mEditor); this->connect(this->mDocument, SIGNAL(documentChanged()), SLOT(mon_documentChanged())); this->connect(this->mEditor, SIGNAL(imageChanged()), SLOT(mon_editor_imageChanged())); this->connect(this->mEditor, SIGNAL(mouseMove(QPoint)), SLOT(mon_editor_mouseMove(QPoint))); this->connect(this->mEditor, SIGNAL(scaleSchanged(int)), SLOT(mon_editor_scaleChanged(int))); this->initStatusData(); this->updateSelectedImage(); } //----------------------------------------------------------------------------- EditorTabImage::~EditorTabImage() { delete ui; } //----------------------------------------------------------------------------- IDocument *EditorTabImage::document() const { return qobject_cast(this->mDocument); } //----------------------------------------------------------------------------- QStringList EditorTabImage::selectedKeys() const { return this->mDocument->dataContainer()->keys(); } //----------------------------------------------------------------------------- StatusData *EditorTabImage::statusData() const { return this->mStatusData; } //----------------------------------------------------------------------------- IEditor::EditorType EditorTabImage::type() const { return EditorImage; } //----------------------------------------------------------------------------- void EditorTabImage::changeEvent(QEvent *e) { QWidget::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: ui->retranslateUi(this); break; default: break; } } //----------------------------------------------------------------------------- void EditorTabImage::initStatusData() { this->mStatusData = new StatusData(this); this->connect(this->mStatusData, SIGNAL(changed()), SIGNAL(statusChanged())); this->updateStatus(); } //----------------------------------------------------------------------------- void EditorTabImage::updateStatus() { QStringList keys = this->mDocument->dataContainer()->keys(); if (keys.length() > 0) { const QImage *currentImage = this->mDocument->dataContainer()->image(keys.at(0)); this->mStatusData->setData(StatusData::ImageSize, QVariant(currentImage->size())); } this->mStatusData->setData(StatusData::Scale, QVariant(this->mEditor->scale())); } //----------------------------------------------------------------------------- void EditorTabImage::updateSelectedImage() { QStringList keys = this->mDocument->dataContainer()->keys(); if (keys.length() > 0) { const QImage *image = this->mDocument->dataContainer()->image(keys.at(0)); this->mEditor->setImage(image); } this->updateStatus(); } //----------------------------------------------------------------------------- void EditorTabImage::mon_documentChanged() { this->updateSelectedImage(); emit this->documentChanged(); } //----------------------------------------------------------------------------- void EditorTabImage::mon_editor_imageChanged() { QStringList keys = this->mDocument->dataContainer()->keys(); const QImage *image = this->mEditor->image(); this->mDocument->dataContainer()->setImage(keys.at(0), image); } //----------------------------------------------------------------------------- void EditorTabImage::mon_editor_mouseMove(QPoint point) { if (point.x() >= 0 && point.y() >= 0) { this->mStatusData->setData(StatusData::MouseCoordinates, QVariant(point)); } else { this->mStatusData->removeData(StatusData::MouseCoordinates); } } //----------------------------------------------------------------------------- void EditorTabImage::mon_editor_scaleChanged(int scale) { this->mStatusData->setData(StatusData::Scale, QVariant(scale)); } //----------------------------------------------------------------------------- /* Storage data format: Base64 string /tmp/font.c iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAA3NCSVQICAjb4U/gAAAACXBIWXMAAAsTAAALEwEAmpwYAAAARklEQVQYlYWPSQrAMAwDpZAX5x/Nl6eHgLMQt8IniRGWAeWqkux+zaD5my5B2z0uzHq0XegjW1+ZdLhbB4mkB0iHjY6fYS/sJjZR2Wu+lAAAAABJRU5ErkJggg== */