Permalink
Browse files

Fixed unicode character codes.

Fixed bug with replacing character 'd' by default image.
Small changed in menu items text.

Added BOM (append/remove) option for unicode font output.
Added font preview dialog.
Added multi characters inserting in font select dialog.

Merge branch 'develop'
  • Loading branch information...
riuson committed Jul 24, 2012
2 parents de6afc9 + d16f926 commit 0421b4dc6c65e9542da2944ec7a90121b44c92ba
Showing with 1,763 additions and 879 deletions.
  1. +312 −0 classes/action-handlers/actionfilehandlers.cpp
  2. +36 −0 classes/action-handlers/actionfilehandlers.h
  3. +179 −0 classes/action-handlers/actionfonthandlers.cpp
  4. +27 −0 classes/action-handlers/actionfonthandlers.h
  5. +21 −0 classes/action-handlers/actionhandlersbase.cpp
  6. +25 −0 classes/action-handlers/actionhandlersbase.h
  7. +16 −0 classes/action-handlers/actionhelphandlers.cpp
  8. +22 −0 classes/action-handlers/actionhelphandlers.h
  9. +188 −0 classes/action-handlers/actionimagehandlers.cpp
  10. +31 −0 classes/action-handlers/actionimagehandlers.h
  11. +28 −0 classes/action-handlers/actionsetuphandlers.cpp
  12. +23 −0 classes/action-handlers/actionsetuphandlers.h
  13. +26 −0 classes/bitmaphelper.cpp
  14. +2 −0 classes/bitmaphelper.h
  15. +59 −9 classes/converter.cpp
  16. +1 −1 classes/converter.h
  17. +7 −4 classes/fontcontainer.cpp
  18. +77 −0 controls/dialogfontpreview.cpp
  19. +35 −0 controls/dialogfontpreview.h
  20. +155 −0 controls/dialogfontpreview.ui
  21. +45 −0 controls/dialogfontselect.cpp
  22. +3 −0 controls/dialogfontselect.h
  23. +10 −0 controls/dialogfontselect.ui
  24. +5 −5 controls/editortabfont.cpp
  25. +1 −2 controls/editortabfont.h
  26. +5 −4 controls/editortabimage.cpp
  27. +1 −2 controls/editortabimage.h
  28. +135 −657 controls/mainwindow.cpp
  29. +27 −30 controls/mainwindow.h
  30. +10 −4 controls/mainwindow.ui
  31. +3 −19 controls/widgetbitmapeditor.cpp
  32. +0 −1 controls/widgetbitmapeditor.h
  33. +2 −0 interfaces/idocument.h
  34. +41 −0 interfaces/imainwindow.h
  35. +20 −3 lcd-image-converter.pro
  36. +1 −0 resources/font.tmpl
  37. +1 −0 resources/image.tmpl
  38. +183 −138 resources/lcd-image-converter-ru.ts
@@ -0,0 +1,312 @@
#include "actionfilehandlers.h"

#include "editortabimage.h"
#include "editortabfont.h"
#include "dialogfontselect.h"
#include <QFileDialog>
#include <QSettings>
#include <QTextStream>
#include <QInputDialog>
#include <QLineEdit>
#include "converter.h"
#include "widgetbitmapeditor.h"
#include "imainwindow.h"
#include "idatacontainer.h"
//-----------------------------------------------------------------------------
ActionFileHandlers::ActionFileHandlers(QObject *parent) :
ActionHandlersBase(parent)
{
}
//-----------------------------------------------------------------------------
void ActionFileHandlers::newImage_triggered()
{
bool ok;
QString name = QInputDialog::getText(this->mMainWindow->parentWidget(),
tr("Enter image name"),
tr("Image name:"),
QLineEdit::Normal,
tr("Image", "new image name"),
&ok);
if (ok)
{
EditorTabImage *ed = new EditorTabImage(this->mMainWindow->parentWidget());
this->connect(ed, SIGNAL(documentChanged(bool,QString,QString)), SLOT(documentChanged(bool,QString,QString)));

name = this->mMainWindow->findAvailableName(name);
ed->setDocumentName(name);
ed->setChanged(false);
emit this->tabCreated(ed, name, ed->fileName());
}
}
//-----------------------------------------------------------------------------
void ActionFileHandlers::newFont_triggered()
{
bool ok;
QString name = QInputDialog::getText(this->mMainWindow->parentWidget(),
tr("Enter font name"),
tr("Font name:"),
QLineEdit::Normal,
tr("Font", "new font name"),
&ok);
if (ok)
{
DialogFontSelect dialog(this->mMainWindow->parentWidget());
if (dialog.exec() == QDialog::Accepted)
{
EditorTabFont *ed = new EditorTabFont(this->mMainWindow->parentWidget());
this->connect(ed, SIGNAL(documentChanged(bool,QString,QString)), SLOT(documentChanged(bool,QString,QString)));

QString chars = dialog.characters();
int size;
QString family, style;
bool monospaced, antialiasing;

family = dialog.fontFamily();
style = dialog.fontStyle();
size = dialog.fontSize();
monospaced = dialog.monospaced();
antialiasing = dialog.antialiasing();

ed->setFontCharacters(chars, family, style, size, monospaced, antialiasing);

name = this->mMainWindow->findAvailableName(name);
ed->setDocumentName(name);
ed->setChanged(false);
emit this->tabCreated(ed, name, ed->fileName());
}
}
}
//-----------------------------------------------------------------------------
void ActionFileHandlers::open_triggered()
{
QFileDialog dialog(this->mMainWindow->parentWidget());
dialog.setAcceptMode(QFileDialog::AcceptOpen);
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setFilter(tr("XML Files (*.xml);;Images (*.bmp *.gif *.jpg *.jpeg *.png *.pbm *.pgm *.ppm *.tiff *.xbm *.xpm)"));
dialog.setWindowTitle(tr("Open file"));

if (dialog.exec() == QDialog::Accepted)
{
QString filename = dialog.selectedFiles().at(0);

this->openFile(filename);
}
}
//-----------------------------------------------------------------------------
void ActionFileHandlers::rename_triggered()
{
bool ok;
IDocument *doc = this->mMainWindow->currentDocument();
if (doc != NULL)
{
QString name = QInputDialog::getText(this->mMainWindow->parentWidget(),
tr("Rename"),
tr("New name:"),
QLineEdit::Normal,
doc->documentName(),
&ok);
if (ok)
{
doc->setDocumentName(name);
}
}
}
//-----------------------------------------------------------------------------
void ActionFileHandlers::save_triggered()
{
IDocument *doc = this->mMainWindow->currentDocument();
if (doc != NULL)
{
if (QFile::exists(doc->fileName()))
doc->save(doc->fileName());
else
this->saveAs_triggered();
}
}
//-----------------------------------------------------------------------------
void ActionFileHandlers::saveAs_triggered()
{
IDocument *doc = this->mMainWindow->currentDocument();
if (doc != NULL)
{
QFileDialog dialog(this->mMainWindow->parentWidget());
dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setFilter(tr("XML Files (*.xml)"));
dialog.setDefaultSuffix(QString("xml"));
dialog.setWindowTitle(tr("Save file as"));
if (dialog.exec() == QDialog::Accepted)
{
QString filename = dialog.selectedFiles().at(0);
doc->save(filename);

emit this->rememberFilename(filename);
}
}
}
//-----------------------------------------------------------------------------
void ActionFileHandlers::close_triggered()
{
emit closeRequest(this->mMainWindow->currentTab());
}
//-----------------------------------------------------------------------------
void ActionFileHandlers::convert_triggered()
{
QSettings sett;
sett.beginGroup("setup");

QString templateImageFileName = sett.value("templateImage", ":/templates/image_convert").toString();
QString templateFontFileName = sett.value("templateFont", ":/templates/font_convert").toString();

sett.endGroup();

QWidget *w = this->mMainWindow->currentTab();
IDocument *doc = dynamic_cast<IDocument *> (w);
if (doc != NULL)
{
QMap<QString, QString> tags;
tags["fileName"] = doc->fileName();
QString docName = doc->documentName();
tags["documentName"] = docName;
docName = docName.remove(QRegExp("\\W", Qt::CaseInsensitive));
tags["documentName_ws"] = docName;

QString templateFileName;

if (EditorTabImage *eti = qobject_cast<EditorTabImage *>(w))
{
Q_UNUSED(eti);
tags["dataType"] = "image";
templateFileName = templateImageFileName;
}
if (EditorTabFont *etf = qobject_cast<EditorTabFont *>(w))
{
QString chars, fontFamily, style;
int size;
bool monospaced, antialiasing;
etf->fontCharacters(&chars, &fontFamily, &style, &size, &monospaced, &antialiasing);

tags["dataType"] = "font";
tags["fontFamily"] = fontFamily;
tags["fontSize"] = QString("%1").arg(size);
tags["fontStyle"] = style;
tags["string"] = chars;
tags["fontAntialiasing"] = antialiasing ? "true" : "false";
tags["fontWidthType"] = monospaced ? "monospaced" : "proportional";

templateFileName = templateFontFileName;
}
Converter conv(this);
QString result = conv.convert(doc, templateFileName, tags);

QFileDialog dialog(this->mMainWindow->parentWidget());
dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setFilter(tr("C Files (*.c);;All Files (*.*)"));
dialog.setDefaultSuffix(QString("c"));
dialog.setWindowTitle(tr("Save result file as"));
if (dialog.exec() == QDialog::Accepted)
{
QString filename = dialog.selectedFiles().at(0);

QFile file(filename);
if (file.open(QFile::WriteOnly))
{
file.write(result.toUtf8());
file.close();
}
}
}
}
//-----------------------------------------------------------------------------
void ActionFileHandlers::openFile(const QString &filename)
{
bool isImage = false;
bool isFont = false;
bool isImageBinary = false;

QFileInfo info(filename);
if (info.exists())
{
if (info.suffix().toLower() == "xml")
{
QFile file(filename);
if (file.open(QIODevice::ReadWrite))
{
QTextStream stream(&file);
while (!stream.atEnd())
{
QString readedLine = stream.readLine();
if (readedLine.contains("<data type=\"image\""))
{
isImage = true;
break;
}
if (readedLine.contains("<data type=\"font\""))
{
isFont = true;
break;
}
}
file.close();

emit this->rememberFilename(filename);
}
}
else
{
QStringList imageExtensions;
imageExtensions << "bmp" << "gif" << "jpg" << "jpeg" << "png" << "pbm" << "pgm" << "ppm" << "tiff" << "xbm" << "xpm";
if (imageExtensions.contains(info.suffix().toLower()))
isImageBinary = true;
}
if (isImage)
{
EditorTabImage *ed = new EditorTabImage(this->mMainWindow->parentWidget());
this->connect(ed, SIGNAL(documentChanged(bool,QString,QString)), SLOT(documentChanged(bool,QString,QString)));

emit this->tabCreated(ed, "", filename);
ed->load(filename);
}
if (isFont)
{
EditorTabFont *ed = new EditorTabFont(this->mMainWindow->parentWidget());
this->connect(ed, SIGNAL(documentChanged(bool,QString,QString)), SLOT(documentChanged(bool,QString,QString)));

emit this->tabCreated(ed, "", filename);
ed->load(filename);
}
if (isImageBinary)
{
QImage image;
if (image.load(filename))
{
EditorTabImage *ed = new EditorTabImage(this->mMainWindow->parentWidget());
this->connect(ed, SIGNAL(documentChanged(bool,QString,QString)), SLOT(documentChanged(bool,QString,QString)));

QString name = this->mMainWindow->findAvailableName(info.baseName());

QString key = ed->editor()->currentImageKey();
ed->dataContainer()->setImage(key, &image);

ed->setDocumentName(name);
ed->setChanged(false);
emit this->tabCreated(ed, name, filename);
}
}
}
}
//-----------------------------------------------------------------------------
void ActionFileHandlers::documentChanged(bool changed, const QString &documentName, const QString &filename)
{
QWidget *w = qobject_cast<QWidget *>(sender());
IDocument *doc = dynamic_cast<IDocument *> (w);
if (doc != NULL)
{
if (changed)
emit this->tabChanged(w, "* " + documentName, filename);
else
emit this->tabChanged(w, documentName, filename);
}
}
//-----------------------------------------------------------------------------
@@ -0,0 +1,36 @@
#ifndef ACTIONFILEHANDLERS_H
#define ACTIONFILEHANDLERS_H
//-----------------------------------------------------------------------------
#include <QObject>

#include "actionhandlersbase.h"
//-----------------------------------------------------------------------------
class IMainWindow;
//-----------------------------------------------------------------------------
class ActionFileHandlers : public ActionHandlersBase
{
Q_OBJECT
public:
explicit ActionFileHandlers(QObject *parent = 0);

signals:
void rememberFilename(const QString &filename);
void closeRequest(QWidget *tab);
void tabChanged(QWidget *w, const QString &documentName, const QString &filename);
void tabCreated(QWidget *w, const QString &documentName, const QString &filename);

public slots:
void newImage_triggered();
void newFont_triggered();
void open_triggered();
void rename_triggered();
void save_triggered();
void saveAs_triggered();
void close_triggered();
void convert_triggered();
void openFile(const QString &filename);
private slots:
void documentChanged(bool changed, const QString &documentName, const QString &filename);
};
//-----------------------------------------------------------------------------
#endif // ACTIONFILEHANDLERS_H
Oops, something went wrong.

0 comments on commit 0421b4d

Please sign in to comment.