Skip to content

Commit

Permalink
Fixed:
Browse files Browse the repository at this point in the history
 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 6998b5e
Show file tree
Hide file tree
Showing 26 changed files with 331 additions and 346 deletions.
12 changes: 7 additions & 5 deletions classes/action-handlers/actionfilehandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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()));

Expand All @@ -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);
}
}

Expand Down
17 changes: 10 additions & 7 deletions classes/action-handlers/actionimagehandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);;" \
Expand Down Expand Up @@ -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);
}
Expand Down
62 changes: 50 additions & 12 deletions classes/data/datacontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
//-----------------------------------------------------------------------------
Expand All @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions classes/data/datacontainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <QObject>

#include <QMap>
#include <QStringList>
#include <QString>
#include <QStringList>
#include <QVariant>
Expand All @@ -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();
Expand All @@ -64,6 +67,7 @@ class DataContainer : public QObject

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

Expand Down
6 changes: 5 additions & 1 deletion classes/data/fontdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand All @@ -536,6 +538,8 @@ void FontDocument::setFontCharacters(const QString &chars,
}
}

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

this->mContainer->blockSignals(false);

this->setChanged(true);
Expand Down
22 changes: 13 additions & 9 deletions classes/data/historykeeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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);
}
}
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion classes/data/historykeeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <QVariant>
#include <QList>
#include <QMap>

#include <QStringList>
//-----------------------------------------------------------------------------
class HistoryRecord;
//-----------------------------------------------------------------------------
Expand All @@ -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);

Expand All @@ -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);
};
Expand Down
Loading

0 comments on commit 6998b5e

Please sign in to comment.