Title block templates now embed a free field for extra information.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1541 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2012-03-02 17:55:27 +00:00
parent fac0fea239
commit 6bdd166e57
6 changed files with 160 additions and 4 deletions

View File

@@ -300,6 +300,7 @@ void QETTitleBlockTemplateEditor::initActions() {
quit_ = new QAction(QET::Icons::ApplicationExit, tr("&Quitter", "menu entry"), this);
undo_ = undo_stack_ -> createUndoAction(this);
redo_ = undo_stack_ -> createRedoAction(this);
edit_info_ = new QAction(QET::Icons::UserInformations, tr("\311diter les informations compl\351mentaires", "menu entry"), this);
zoom_in_ = new QAction(QET::Icons::ZoomIn, tr("Zoom avant", "menu entry"), this);
zoom_out_ = new QAction(QET::Icons::ZoomOut, tr("Zoom arri\350re", "menu entry"), this);
zoom_fit_ = new QAction(QET::Icons::ZoomFitBest, tr("Zoom adapt\351", "menu entry"), this);
@@ -318,6 +319,7 @@ void QETTitleBlockTemplateEditor::initActions() {
quit_ -> setShortcut(QKeySequence(tr("Ctrl+Q", "shortcut to quit")));
undo_ -> setShortcut(QKeySequence::Undo);
redo_ -> setShortcut(QKeySequence::Redo);
edit_info_ -> setShortcut(QKeySequence(tr("Ctrl+Y", "shortcut to edit extra information")));
merge_cells_ -> setShortcut(QKeySequence(tr("Ctrl+K", "shortcut to merge cells")));
split_cell_ -> setShortcut(QKeySequence(tr("Ctrl+J", "shortcut to split merged cell")));
zoom_in_ -> setShortcut(QKeySequence::ZoomIn);
@@ -336,6 +338,7 @@ void QETTitleBlockTemplateEditor::initActions() {
connect(zoom_out_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomOut()));
connect(zoom_fit_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomFit()));
connect(zoom_reset_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomReset()));
connect(edit_info_, SIGNAL(triggered()), this, SLOT(editTemplateInformation()));
connect(merge_cells_, SIGNAL(triggered()), template_edition_area_view_, SLOT(mergeSelectedCells()));
connect(split_cell_, SIGNAL(triggered()), template_edition_area_view_, SLOT(splitSelectedCell()));
}
@@ -360,9 +363,10 @@ void QETTitleBlockTemplateEditor::initMenus() {
edit_menu_ -> addAction(undo_);
edit_menu_ -> addAction(redo_);
edit_menu_ -> addSeparator();
edit_menu_ -> addAction(merge_cells_);
edit_menu_ -> addAction(split_cell_);
edit_menu_ -> addAction(edit_info_);
display_menu_ -> addAction(zoom_in_);
display_menu_ -> addAction(zoom_out_);
display_menu_ -> addAction(zoom_fit_);
@@ -776,3 +780,46 @@ void QETTitleBlockTemplateEditor::savePreviewWidthToApplicationSettings(int form
Q_UNUSED(former_preview_width)
QETApp::settings().setValue("titleblocktemplateeditor/preview_width", new_preview_width);
}
/**
Edit extra information attached to the template.
*/
void QETTitleBlockTemplateEditor::editTemplateInformation() {
if (!tb_template_) return;
QDialog dialog_author(this);
dialog_author.setModal(true);
#ifdef Q_WS_MAC
dialog_author.setWindowFlags(Qt::Sheet);
#endif
dialog_author.setMinimumSize(400, 260);
dialog_author.setWindowTitle(tr("\311diter les informations compl\351mentaires", "window title"));
QVBoxLayout *dialog_layout = new QVBoxLayout(&dialog_author);
// explanation label
QLabel *information_label = new QLabel(tr("Vous pouvez utiliser ce champ libre pour mentionner les auteurs du cartouche, sa licence, ou tout autre renseignement que vous jugerez utile."));
information_label -> setAlignment(Qt::AlignJustify | Qt::AlignVCenter);
information_label -> setWordWrap(true);
dialog_layout -> addWidget(information_label);
// add a QTextEdit to the dialog
QTextEdit *text_field = new QTextEdit();
text_field -> setAcceptRichText(false);
text_field -> setPlainText(tb_template_ -> information());
text_field -> setReadOnly(read_only_);
dialog_layout -> addWidget(text_field);
// add two buttons to the dialog
QDialogButtonBox *dialog_buttons = new QDialogButtonBox(read_only_ ? QDialogButtonBox::Ok : QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
dialog_layout -> addWidget(dialog_buttons);
connect(dialog_buttons, SIGNAL(accepted()), &dialog_author, SLOT(accept()));
connect(dialog_buttons, SIGNAL(rejected()), &dialog_author, SLOT(reject()));
// run the dialog
if (dialog_author.exec() == QDialog::Accepted && !read_only_) {
QString new_info = text_field -> toPlainText();
if (new_info != tb_template_ -> information()) {
pushUndoCommand(new ChangeTemplateInformationsCommand(tb_template_, tb_template_ -> information(), new_info));
}
}
}

View File

@@ -49,7 +49,7 @@ class QETTitleBlockTemplateEditor : public QETMainWindow {
QMenu *file_menu_, *edit_menu_,/* *paste_from_menu_, */*display_menu_,/* *tools_menu_*/;
/// actions
QAction *new_, *open_, *open_from_file_, *save_, *save_as_, *save_as_file_, *quit_;
QAction *undo_, *redo_, *merge_cells_, *split_cell_;
QAction *undo_, *redo_, *edit_info_, *merge_cells_, *split_cell_;
QAction *zoom_in_, *zoom_out_, *zoom_fit_, *zoom_reset_;
/// Location of the currently edited template
TitleBlockTemplateLocation location_;
@@ -117,6 +117,7 @@ class QETTitleBlockTemplateEditor : public QETMainWindow {
void setReadOnly(bool);
void quit();
void savePreviewWidthToApplicationSettings(int, int);
void editTemplateInformation();
private slots:
TitleBlockTemplateLocation getTitleBlockTemplateLocationFromUser(const QString & = QString(), bool existing_only = true);

View File

@@ -777,3 +777,40 @@ void SplitCellsCommand::redo() {
if (view_) view_ -> updateLayout();
}
/**
Constructor
@param tbt Changed title block template
@param old_info Former information
@param new_info New information
@param parent Parent QUndoCommand
*/
ChangeTemplateInformationsCommand::ChangeTemplateInformationsCommand(TitleBlockTemplate *tbt, const QString &old_info, const QString &new_info, QUndoCommand *parent) :
QUndoCommand(QObject::tr("modification des informations compl\351mentaires", "undo caption"), parent),
tbtemplate_(tbt),
old_information_(old_info),
new_information_(new_info)
{
}
/**
Destructor
*/
ChangeTemplateInformationsCommand::~ChangeTemplateInformationsCommand() {
}
/**
Undo the information change
*/
void ChangeTemplateInformationsCommand::undo() {
if (!tbtemplate_) return;
tbtemplate_ -> setInformation(old_information_);
}
/**
Redo the information change
*/
void ChangeTemplateInformationsCommand::redo() {
tbtemplate_ -> setInformation(new_information_);
}

View File

@@ -222,4 +222,30 @@ class SplitCellsCommand : public TitleBlockTemplateCommand {
int col_span_before_; ///< the col_span attribute of the spanning cell after the merge
};
/**
This class represents the action of changing extra information of a title
block template.
*/
class ChangeTemplateInformationsCommand : public QUndoCommand {
// constructors, destructor
public:
ChangeTemplateInformationsCommand(TitleBlockTemplate *, const QString &, const QString &, QUndoCommand * = 0);
virtual ~ChangeTemplateInformationsCommand();
private:
ChangeTemplateInformationsCommand(const ChangeTemplateInformationsCommand &);
// methods
public:
virtual void undo();
virtual void redo();
// attributes
private:
/// chnged title block template
TitleBlockTemplate *tbtemplate_;
/// Informations before they are modified
QString old_information_;
/// Informations after they were modified
QString new_information_;
};
#endif

View File

@@ -111,6 +111,7 @@ bool TitleBlockTemplate::loadFromXmlElement(const QDomElement &xml_element) {
}
name_ = xml_element.attribute("name");
loadInformation(xml_element);
loadLogos(xml_element, true);
loadGrid(xml_element);
@@ -158,6 +159,7 @@ bool TitleBlockTemplate::saveToXmlElement(QDomElement &xml_element) const {
xml_element.setTagName("titleblocktemplate");
xml_element.setAttribute("name", name_);
saveInformation(xml_element);
saveLogos(xml_element);
saveGrid(xml_element);
return(true);
@@ -170,6 +172,7 @@ bool TitleBlockTemplate::saveToXmlElement(QDomElement &xml_element) const {
TitleBlockTemplate *TitleBlockTemplate::clone() const {
TitleBlockTemplate *copy = new TitleBlockTemplate();
copy -> name_ = name_;
copy -> information_ = information_;
// this does not really duplicates pixmaps, only the objects that hold a key to the implicitly shared pixmaps
foreach (QString logo_key, bitmap_logos_.keys()) {
@@ -214,6 +217,17 @@ TitleBlockTemplate *TitleBlockTemplate::clone() const {
return(copy);
}
/**
Import text informations from a given XML title block template.
*/
void TitleBlockTemplate::loadInformation(const QDomElement &xml_element) {
for (QDomNode n = xml_element.firstChild() ; !n.isNull() ; n = n.nextSibling()) {
if (n.isElement() && n.toElement().tagName() == "information") {
setInformation(n.toElement().text());
}
}
}
/**
Import the logos from a given XML titleblock template.
@param xml_element An XML element representing an titleblock template.
@@ -453,6 +467,18 @@ void TitleBlockTemplate::loadCell(const QDomElement &cell_element) {
}
}
/**
Export this template's extra information.
@param xml_element XML element under which extra informations will be attached
*/
void TitleBlockTemplate::saveInformation(QDomElement &xml_element) const {
QDomNode information_text_node = xml_element.ownerDocument().createTextNode(information());
QDomElement information_element = xml_element.ownerDocument().createElement("information");
information_element.appendChild(information_text_node);
xml_element.appendChild(information_element);
}
/**
Export this template's logos as XML
@param xml_element XML Element under which the \<logos\> element will be attached
@@ -689,6 +715,20 @@ QString TitleBlockTemplate::name() const {
return(name_);
}
/**
@return the information field attached to this template
*/
QString TitleBlockTemplate::information() const {
return(information_);
}
/**
@param info information to be attached to this template
*/
void TitleBlockTemplate::setInformation(const QString &info) {
information_ = info;
}
/**
@param i row index
@return the height of the row at index i

View File

@@ -51,6 +51,8 @@ class TitleBlockTemplate : public QObject {
bool saveToXmlElement(QDomElement &) const;
TitleBlockTemplate *clone() const;
QString name() const;
QString information() const;
void setInformation(const QString &);
int rowDimension(int);
void setRowDimension(int, const TitleBlockDimension &);
TitleBlockDimension columnDimension(int);
@@ -95,11 +97,13 @@ class TitleBlockTemplate : public QObject {
QString toString() const;
protected:
void loadInformation(const QDomElement &);
bool loadLogos(const QDomElement &, bool = false);
bool loadLogo(const QDomElement &);
bool loadGrid(const QDomElement &);
bool loadCells(const QDomElement &);
void loadCell(const QDomElement &);
void saveInformation(QDomElement &) const;
void saveLogos(QDomElement &) const;
void saveLogo(const QString &, QDomElement &) const;
void saveGrid(QDomElement &) const;
@@ -125,7 +129,8 @@ class TitleBlockTemplate : public QObject {
// attributes
private:
QString name_; ///< name identifying the Title Block Template within its parent project
QString name_; ///< name identifying the Title Block Template within its parent collection
QString information_;
QHash<QString, QByteArray > data_logos_; ///< Logos raw data
QHash<QString, QString> storage_logos_; ///< Logos applied storage type (e.g. "xml" or "base64")