Permalink
Browse files

Fixed:

 Broken image prepare sequence;
 Russian translation;
 Loading of images in some formats.

Added:
 Optional characters sorting in 'Font Change...' dialog.

Merge branch 'develop'.
  • Loading branch information...
riuson committed Feb 25, 2014
2 parents c026d86 + 0c279e4 commit 6998b5ed23fbb240a14987e38d4563e8d4c8221e
@@ -44,7 +44,7 @@ void ActionFileHandlers::newImage_triggered()
tr("Enter image name"),
tr("Image name:"),
QLineEdit::Normal,
tr("Image", "new image name"),
QString("Image"),
&ok);
if (ok)
{
@@ -65,7 +65,7 @@ void ActionFileHandlers::newFont_triggered()
tr("Enter font name"),
tr("Font name:"),
QLineEdit::Normal,
tr("Font", "new font name"),
QString("Font"),
&ok);
if (ok)
{
@@ -261,9 +261,11 @@ void ActionFileHandlers::openFile(const QString &filename)
}
if (isImageBinary)
{
QImage image;
if (image.load(filename))
QImage imageLoaded;
if (imageLoaded.load(filename))
{
QImage imageConverted = imageLoaded.convertToFormat(QImage::Format_ARGB32);

EditorTabImage *ed = new EditorTabImage(this->mMainWindow->parentWidget());
this->connect(ed, SIGNAL(documentChanged()), SLOT(documentChanged()));

@@ -277,7 +279,7 @@ void ActionFileHandlers::openFile(const QString &filename)
while (iterator.hasNext())
{
QString key = iterator.next();
ed->document()->dataContainer()->setImage(key, &image);
ed->document()->dataContainer()->setImage(key, &imageConverted);
}
}

@@ -314,9 +314,11 @@ void ActionImageHandlers::import_triggered()
{
QString key = iterator.next();

QImage image;
image.load(dialog.selectedFiles().at(0));
this->editor()->document()->dataContainer()->setImage(key, &image);
QImage imageLoaded;
imageLoaded.load(dialog.selectedFiles().at(0));
QImage imageConverted = imageLoaded.convertToFormat(QImage::Format_ARGB32);

this->editor()->document()->dataContainer()->setImage(key, &imageConverted);
}

this->editor()->document()->endChanges();
@@ -331,7 +333,7 @@ void ActionImageHandlers::export_triggered()
QFileDialog dialog(this->mMainWindow->parentWidget());
dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.setFileMode(QFileDialog::AnyFile);
QString filter = tr("Windows Bitmap (*.bmp);;" \
QString filter = QString("Windows Bitmap (*.bmp);;" \
"Joint Photographic Experts Group (*.jpg *.jpeg);;" \
"Portable Network Graphics (*.png);;" \
"Portable Pixmap (*.ppm);;" \
@@ -471,9 +473,10 @@ void ActionImageHandlers::edit_in_external_tool_triggered()
QString key = iterator.next();
QString filename = files.value(key);

QImage image;
image.load(filename);
this->editor()->document()->dataContainer()->setImage(key, &image);
QImage imageLoaded;
imageLoaded.load(filename);
QImage imageConverted = imageLoaded.convertToFormat(QImage::Format_ARGB32);
this->editor()->document()->dataContainer()->setImage(key, &imageConverted);

QFile::remove(filename);
}
@@ -34,23 +34,38 @@ DataContainer::DataContainer(QObject *parent) :
DataContainer::~DataContainer()
{
qDeleteAll(this->mImageMap);
this->mKeys.clear();
delete this->mDefaultImage;

delete this->mHistory;
}
//-----------------------------------------------------------------------------
const QImage *DataContainer::image(const QString &key) const
{
return this->mImageMap.value(key, this->mDefaultImage);
if (this->mKeys.contains(key))
{
return this->mImageMap.value(key, this->mDefaultImage);
}
else
{
return this->mDefaultImage;
}
}
//-----------------------------------------------------------------------------
void DataContainer::setImage(const QString &key, const QImage *image)
{
this->remove(key);
if (this->mKeys.contains(key))
{
this->mImageMap.remove(key);
}
else
{
this->mKeys.append(key);
}
QImage *imageNew = new QImage(*image);
this->mImageMap.insert(key, imageNew);
this->setChanged(true);

this->setChanged(true);
emit this->imagesChanged();
}
//-----------------------------------------------------------------------------
@@ -73,57 +88,80 @@ void DataContainer::setInfo(const QString &key, const QVariant &value)
void DataContainer::clear()
{
qDeleteAll(this->mImageMap);
this->mKeys.clear();
this->mImageMap.clear();
}
//-----------------------------------------------------------------------------
int DataContainer::count() const
{
return this->mImageMap.count();
return this->mKeys.count();
}
//-----------------------------------------------------------------------------
QStringList DataContainer::keys() const
{
QList<QString> tmp = this->mImageMap.keys();
qSort(tmp);
QStringList result(tmp);
QStringList result(this->mKeys);
return result;
}
//-----------------------------------------------------------------------------
void DataContainer::remove(const QString &key)
{
if (this->mImageMap.contains(key))
if (this->mKeys.contains(key))
{
QImage *imageOld = this->mImageMap.value(key);
this->mImageMap.remove(key);
this->mKeys.removeOne(key);
delete imageOld;
}
}
//-----------------------------------------------------------------------------
void DataContainer::reorderTo(const QStringList *keys)
{
if (this->mKeys.length() == keys->length())
{
bool exists = true;
for (int i = 0; i < keys->length(); i++)
{
QString key = keys->at(i);
if (!this->mKeys.contains(key))
{
exists = true;
break;
}
}

if (exists)
{
this->mKeys.clear();
this->mKeys.append(*keys);
}
}
}
//-----------------------------------------------------------------------------
bool DataContainer::historyInitialized() const
{
return this->mHistory->initialized();
}
//-----------------------------------------------------------------------------
void DataContainer::historyInit()
{
this->mHistory->init(&this->mImageMap, &this->mInfoMap);
this->mHistory->init(&this->mKeys, &this->mImageMap, &this->mInfoMap);
}
//-----------------------------------------------------------------------------
void DataContainer::stateSave()
{
this->mHistory->store(&this->mImageMap, &this->mInfoMap);
this->mHistory->store(&this->mKeys, &this->mImageMap, &this->mInfoMap);
}
//-----------------------------------------------------------------------------
void DataContainer::stateUndo()
{
this->mHistory->restorePrevious(&this->mImageMap, &this->mInfoMap);
this->mHistory->restorePrevious(&this->mKeys, &this->mImageMap, &this->mInfoMap);

emit this->imagesChanged();
}
//-----------------------------------------------------------------------------
void DataContainer::stateRedo()
{
this->mHistory->restoreNext(&this->mImageMap, &this->mInfoMap);
this->mHistory->restoreNext(&this->mKeys, &this->mImageMap, &this->mInfoMap);

emit this->imagesChanged();
}
@@ -23,6 +23,7 @@
#include <QObject>

#include <QMap>
#include <QStringList>
#include <QString>
#include <QStringList>
#include <QVariant>
@@ -48,6 +49,8 @@ class DataContainer : public QObject
QStringList keys() const;
void remove(const QString &key);

void reorderTo(const QStringList *keys);

bool historyInitialized() const;
void historyInit();
void stateSave();
@@ -64,6 +67,7 @@ class DataContainer : public QObject

QMap<QString, QImage *> mImageMap;
QMap<QString, QVariant> mInfoMap;
QStringList mKeys;
QImage *mDefaultImage;
HistoryKeeper *mHistory;

@@ -42,7 +42,7 @@ FontDocument::FontDocument(QObject *parent) :
this->mContainer = new DataContainer(this);
this->connect(this->mContainer, SIGNAL(imagesChanged()), SLOT(mon_container_imagesChanged()));

this->setDocumentName(tr("Font", "new font name"));
this->setDocumentName(QString("Font"));
this->setDocumentFilename("");
this->setOutputFilename("");
this->setChanged(true);
@@ -517,9 +517,11 @@ void FontDocument::setFontCharacters(const QString &chars,

// generate new characters
QStringList keys = this->mContainer->keys();
QStringList userOrdered;
for (int i = 0; i < chars.count(); i++)
{
QString key = QString(chars.at(i));
userOrdered.append(key);

// if character not exists, create it
if (!keys.contains(key))
@@ -536,6 +538,8 @@ void FontDocument::setFontCharacters(const QString &chars,
}
}

this->mContainer->reorderTo(&userOrdered);

this->mContainer->blockSignals(false);

this->setChanged(true);
@@ -37,16 +37,17 @@ HistoryKeeper::~HistoryKeeper()
this->mHistory->clear();
}
//-----------------------------------------------------------------------------
void HistoryKeeper::init(const QMap<QString, QImage *> *images, const QMap<QString, QVariant> *info)
void HistoryKeeper::init(const QStringList *keys, const QMap<QString, QImage *> *images, const QMap<QString, QVariant> *info)
{
this->mCurrentIndex = 0;
this->removeAfter(this->mCurrentIndex);

HistoryRecord *record = new HistoryRecord(images, info, this);
HistoryRecord *record = new HistoryRecord(keys, images, info, this);
this->mHistory->append(record);
}
//-----------------------------------------------------------------------------
void HistoryKeeper::store(
const QStringList *keys,
const QMap<QString, QImage *> *images,
const QMap<QString, QVariant> *info)
{
@@ -58,12 +59,13 @@ void HistoryKeeper::store(

this->removeAfter(this->mCurrentIndex);

HistoryRecord *record = new HistoryRecord(images, info, this);
HistoryRecord *record = new HistoryRecord(keys, images, info, this);
this->mHistory->append(record);
this->mCurrentIndex++;
}
//-----------------------------------------------------------------------------
void HistoryKeeper::restorePrevious(
QStringList *keys,
QMap<QString, QImage *> *images,
QMap<QString, QVariant> *info)
{
@@ -76,11 +78,12 @@ void HistoryKeeper::restorePrevious(
if (this->canRestorePrevious())
{
this->mCurrentIndex--;
this->restoreAt(this->mCurrentIndex, images, info);
this->restoreAt(this->mCurrentIndex, keys, images, info);
}
}
//-----------------------------------------------------------------------------
void HistoryKeeper::restoreNext(
QStringList *keys,
QMap<QString, QImage *> *images,
QMap<QString, QVariant> *info)
{
@@ -93,7 +96,7 @@ void HistoryKeeper::restoreNext(
if (this->canRestoreNext())
{
this->mCurrentIndex++;
this->restoreAt(this->mCurrentIndex, images, info);
this->restoreAt(this->mCurrentIndex, keys, images, info);
}
}
//-----------------------------------------------------------------------------
@@ -124,17 +127,19 @@ void HistoryKeeper::removeAfter(int index)
//-----------------------------------------------------------------------------
void HistoryKeeper::restoreAt(
int index,
QStringList *keys,
QMap<QString, QImage *> *images,
QMap<QString, QVariant> *info)
{
HistoryRecord *record = this->mHistory->at(index);

qDeleteAll(*images);
keys->clear();
images->clear();
info->clear();

QStringList keys = record->images()->keys();
QStringListIterator iterator(keys);
keys->append(*record->keys());
QStringListIterator iterator(*keys);
while (iterator.hasNext())
{
QString key = iterator.next();
@@ -145,8 +150,7 @@ void HistoryKeeper::restoreAt(
images->insert(key, newImage);
}

keys = record->info()->keys();
iterator = QStringListIterator(keys);
iterator = QStringListIterator(record->info()->keys());
while (iterator.hasNext())
{
QString key = iterator.next();
@@ -26,7 +26,7 @@
#include <QVariant>
#include <QList>
#include <QMap>

#include <QStringList>
//-----------------------------------------------------------------------------
class HistoryRecord;
//-----------------------------------------------------------------------------
@@ -38,15 +38,19 @@ class HistoryKeeper : public QObject
~HistoryKeeper();

void init(
const QStringList *keys,
const QMap<QString, QImage *> *images,
const QMap<QString, QVariant> *info);
void store(
const QStringList *keys,
const QMap<QString, QImage *> *images,
const QMap<QString, QVariant> *info);
void restorePrevious(
QStringList *keys,
QMap<QString, QImage *> *images,
QMap<QString, QVariant> *info);
void restoreNext(
QStringList *keys,
QMap<QString, QImage *> *images,
QMap<QString, QVariant> *info);

@@ -61,6 +65,7 @@ class HistoryKeeper : public QObject
void removeAfter(int index);
void restoreAt(
int index,
QStringList *keys,
QMap<QString, QImage *> *images,
QMap<QString, QVariant> *info);
};
Oops, something went wrong.

0 comments on commit 6998b5e

Please sign in to comment.