mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 14:50:53 +01:00
Title block template editor: added an "Integrate logo" button.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1140 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -120,6 +120,79 @@ void TemplateEditor::quit() {
|
|||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Allows the user to easily integrate a logo in to the currently edited title block
|
||||||
|
template.
|
||||||
|
*/
|
||||||
|
void TemplateEditor::integrateLogo() {
|
||||||
|
// we need a filepath
|
||||||
|
QString filepath = QFileDialog::getOpenFileName(
|
||||||
|
this,
|
||||||
|
tr("S\351lectionnez un fichier image"),
|
||||||
|
QString(),
|
||||||
|
tr("Images vectorielles (*.svg);;Images bitmap (*.png *.jpg *.jpeg *.gif *.bmp *.xpm);;Tous les fichiers (*)")
|
||||||
|
);
|
||||||
|
if (filepath.isNull()) return;
|
||||||
|
|
||||||
|
// that filepath needs to point to a valid, readable file
|
||||||
|
QFileInfo filepath_info(filepath);
|
||||||
|
if (!filepath_info.exists() || !filepath_info.isReadable()) {
|
||||||
|
QMessageBox::critical(this, tr("Erreur"), tr("Impossible d'ouvrir le fichier sp\351cifi\351"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QString filename = filepath_info.fileName();
|
||||||
|
|
||||||
|
/// TODO identify whether the given file is a bitmap or vector graphics and integrate it accordingly
|
||||||
|
// now, we need the XML document of the currently edited template
|
||||||
|
QDomDocument xml_template;
|
||||||
|
if (!xml_template.setContent(getXmlString())) {
|
||||||
|
QMessageBox::critical(this, tr("Erreur"), tr("Le code XML du mod\350le ne semble pas \320tre valide."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we need a <logos> section
|
||||||
|
QDomElement logos_section = xml_template.documentElement().firstChildElement("logos");
|
||||||
|
QDomElement logo_xml_elmt;
|
||||||
|
if (logos_section.isNull()) {
|
||||||
|
logos_section = xml_template.createElement("logos");
|
||||||
|
xml_template.documentElement().appendChild(logos_section);
|
||||||
|
} else {
|
||||||
|
// is there a logo of the same name already?
|
||||||
|
QString tag = "logo";
|
||||||
|
for (QDomElement e = logos_section.firstChildElement(tag) ; !e.isNull() ; e = e.nextSiblingElement(tag)) {
|
||||||
|
if (e.attribute("name") == filename) {
|
||||||
|
logo_xml_elmt = e;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// we read the provided logo
|
||||||
|
QFile logo_file(filepath);
|
||||||
|
logo_file.open(QIODevice::ReadOnly);
|
||||||
|
QString base64_string = QString(logo_file.readAll().toBase64());
|
||||||
|
|
||||||
|
// we insert it into our XML document
|
||||||
|
QDomText t = xml_template.createTextNode(base64_string);
|
||||||
|
|
||||||
|
if (!logo_xml_elmt.isNull()) {
|
||||||
|
logo_xml_elmt.setAttribute("storage", "base64");
|
||||||
|
QDomNodeList children = logo_xml_elmt.childNodes();
|
||||||
|
for (int i = 0 ; i < children .count() ; ++ i) logo_xml_elmt.removeChild(children.at(i));
|
||||||
|
logo_xml_elmt.appendChild(t);
|
||||||
|
} else {
|
||||||
|
QDomElement new_logo = xml_template.createElement("logo");
|
||||||
|
new_logo.appendChild(t);
|
||||||
|
new_logo.setAttribute("storage", "base64");
|
||||||
|
new_logo.setAttribute("type", filepath_info.suffix());
|
||||||
|
new_logo.setAttribute("name", filename);
|
||||||
|
logos_section.appendChild(new_logo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// we put back the XML description in the text area
|
||||||
|
setXmlString(xml_template);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Builds the user interface.
|
Builds the user interface.
|
||||||
*/
|
*/
|
||||||
@@ -135,15 +208,18 @@ void TemplateEditor::build() {
|
|||||||
template_xml_edit_ -> setFontFamily("monospace");
|
template_xml_edit_ -> setFontFamily("monospace");
|
||||||
template_xml_edit_ -> setWordWrapMode(QTextOption::NoWrap);
|
template_xml_edit_ -> setWordWrapMode(QTextOption::NoWrap);
|
||||||
|
|
||||||
|
integrate_logo_ = new QPushButton(tr("Int\351grer un logo"));
|
||||||
validate_button_ = new QPushButton(tr("V\351rifier le mod\350le"));
|
validate_button_ = new QPushButton(tr("V\351rifier le mod\350le"));
|
||||||
save_button_ = new QPushButton(tr("Enregistrer et appliquer"));
|
save_button_ = new QPushButton(tr("Enregistrer et appliquer"));
|
||||||
quit_button_ = new QPushButton(tr("Quitter"));
|
quit_button_ = new QPushButton(tr("Quitter"));
|
||||||
|
|
||||||
|
connect(integrate_logo_, SIGNAL(released()), this, SLOT(integrateLogo()));
|
||||||
connect(validate_button_, SIGNAL(released()), this, SLOT(validate()));
|
connect(validate_button_, SIGNAL(released()), this, SLOT(validate()));
|
||||||
connect(save_button_, SIGNAL(released()), this, SLOT(save()));
|
connect(save_button_, SIGNAL(released()), this, SLOT(save()));
|
||||||
connect(quit_button_, SIGNAL(released()), this, SLOT(quit()));
|
connect(quit_button_, SIGNAL(released()), this, SLOT(quit()));
|
||||||
|
|
||||||
QHBoxLayout *h_layout0 = new QHBoxLayout();
|
QHBoxLayout *h_layout0 = new QHBoxLayout();
|
||||||
|
h_layout0 -> addWidget(integrate_logo_);
|
||||||
h_layout0 -> addWidget(validate_button_);
|
h_layout0 -> addWidget(validate_button_);
|
||||||
h_layout0 -> addWidget(save_button_);
|
h_layout0 -> addWidget(save_button_);
|
||||||
h_layout0 -> addWidget(quit_button_);
|
h_layout0 -> addWidget(quit_button_);
|
||||||
@@ -190,3 +266,14 @@ QString TemplateEditor::getXmlString() const {
|
|||||||
xml_str = xml_str.arg(Qt::escape(template_name_edit_ -> text())).arg(template_xml_edit_ -> toPlainText());
|
xml_str = xml_str.arg(Qt::escape(template_name_edit_ -> text())).arg(template_xml_edit_ -> toPlainText());
|
||||||
return(xml_str);
|
return(xml_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Displays the given title block template XML code
|
||||||
|
@param xml_doc The XML description of a title block template
|
||||||
|
*/
|
||||||
|
void TemplateEditor::setXmlString(const QDomDocument &xml_doc) {
|
||||||
|
QString xml_str = xml_doc.toString(4);
|
||||||
|
xml_str.replace(QRegExp("^<titleblocktemplate[^>]*>"), "");
|
||||||
|
xml_str.replace(QRegExp("</titleblocktemplate>"), "");
|
||||||
|
template_xml_edit_ -> setPlainText(" " + xml_str.trimmed());
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#ifndef TEMPLATE_EDITOR_H
|
#ifndef TEMPLATE_EDITOR_H
|
||||||
#define TEMPLATE_EDITOR_H
|
#define TEMPLATE_EDITOR_H
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
#include <QtXml>
|
||||||
class QETProject;
|
class QETProject;
|
||||||
/**
|
/**
|
||||||
This class allows the user to edit a title block template.
|
This class allows the user to edit a title block template.
|
||||||
@@ -41,11 +42,13 @@ class TemplateEditor : public QWidget {
|
|||||||
void validate();
|
void validate();
|
||||||
void save();
|
void save();
|
||||||
void quit();
|
void quit();
|
||||||
|
void integrateLogo();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void build();
|
void build();
|
||||||
void updateProjectLabel();
|
void updateProjectLabel();
|
||||||
QString getXmlString() const;
|
QString getXmlString() const;
|
||||||
|
void setXmlString(const QDomDocument &);
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
private:
|
private:
|
||||||
@@ -55,6 +58,7 @@ class TemplateEditor : public QWidget {
|
|||||||
QLabel *static_xml_3_;
|
QLabel *static_xml_3_;
|
||||||
QLineEdit *template_name_edit_;
|
QLineEdit *template_name_edit_;
|
||||||
QTextEdit *template_xml_edit_;
|
QTextEdit *template_xml_edit_;
|
||||||
|
QPushButton *integrate_logo_;
|
||||||
QPushButton *validate_button_;
|
QPushButton *validate_button_;
|
||||||
QPushButton *save_button_;
|
QPushButton *save_button_;
|
||||||
QPushButton *quit_button_;
|
QPushButton *quit_button_;
|
||||||
|
|||||||
Reference in New Issue
Block a user