[qet] [1541] Title block templates now embed a free field for extra information.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 1541
Author:   xavier
Date:     2012-03-02 18:55:27 +0100 (Fri, 02 Mar 2012)
Log Message:
-----------
Title block templates now embed a free field for extra information.

Modified Paths:
--------------
    branches/0.3/sources/titleblock/qettemplateeditor.cpp
    branches/0.3/sources/titleblock/qettemplateeditor.h
    branches/0.3/sources/titleblock/templatecommands.cpp
    branches/0.3/sources/titleblock/templatecommands.h
    branches/0.3/sources/titleblocktemplate.cpp
    branches/0.3/sources/titleblocktemplate.h

Modified: branches/0.3/sources/titleblock/qettemplateeditor.cpp
===================================================================
--- branches/0.3/sources/titleblock/qettemplateeditor.cpp	2012-02-28 18:54:34 UTC (rev 1540)
+++ branches/0.3/sources/titleblock/qettemplateeditor.cpp	2012-03-02 17:55:27 UTC (rev 1541)
@@ -300,6 +300,7 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 	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));
+		}
+	}
+}

Modified: branches/0.3/sources/titleblock/qettemplateeditor.h
===================================================================
--- branches/0.3/sources/titleblock/qettemplateeditor.h	2012-02-28 18:54:34 UTC (rev 1540)
+++ branches/0.3/sources/titleblock/qettemplateeditor.h	2012-03-02 17:55:27 UTC (rev 1541)
@@ -49,7 +49,7 @@
 	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 @@
 	void setReadOnly(bool);
 	void quit();
 	void savePreviewWidthToApplicationSettings(int, int);
+	void editTemplateInformation();
 	
 	private slots:
 	TitleBlockTemplateLocation getTitleBlockTemplateLocationFromUser(const QString & = QString(), bool existing_only = true);

Modified: branches/0.3/sources/titleblock/templatecommands.cpp
===================================================================
--- branches/0.3/sources/titleblock/templatecommands.cpp	2012-02-28 18:54:34 UTC (rev 1540)
+++ branches/0.3/sources/titleblock/templatecommands.cpp	2012-03-02 17:55:27 UTC (rev 1541)
@@ -777,3 +777,40 @@
 	
 	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_);
+}

Modified: branches/0.3/sources/titleblock/templatecommands.h
===================================================================
--- branches/0.3/sources/titleblock/templatecommands.h	2012-02-28 18:54:34 UTC (rev 1540)
+++ branches/0.3/sources/titleblock/templatecommands.h	2012-03-02 17:55:27 UTC (rev 1541)
@@ -222,4 +222,30 @@
 	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

Modified: branches/0.3/sources/titleblocktemplate.cpp
===================================================================
--- branches/0.3/sources/titleblocktemplate.cpp	2012-02-28 18:54:34 UTC (rev 1540)
+++ branches/0.3/sources/titleblocktemplate.cpp	2012-03-02 17:55:27 UTC (rev 1541)
@@ -111,6 +111,7 @@
 	}
 	name_ = xml_element.attribute("name");
 	
+	loadInformation(xml_element);
 	loadLogos(xml_element, true);
 	loadGrid(xml_element);
 	
@@ -158,6 +159,7 @@
 	
 	xml_element.setTagName("titleblocktemplate");
 	xml_element.setAttribute("name", name_);
+	saveInformation(xml_element);
 	saveLogos(xml_element);
 	saveGrid(xml_element);
 	return(true);
@@ -170,6 +172,7 @@
 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()) {
@@ -215,6 +218,17 @@
 }
 
 /**
+	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.
 	@param reset true to delete all previously known logos before, false
@@ -454,6 +468,18 @@
 }
 
 /**
+	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
 */
@@ -690,6 +716,20 @@
 }
 
 /**
+	@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
 */

Modified: branches/0.3/sources/titleblocktemplate.h
===================================================================
--- branches/0.3/sources/titleblocktemplate.h	2012-02-28 18:54:34 UTC (rev 1540)
+++ branches/0.3/sources/titleblocktemplate.h	2012-03-02 17:55:27 UTC (rev 1541)
@@ -51,6 +51,8 @@
 	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 @@
 	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 @@
 	
 	// 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")
@@ -134,7 +139,7 @@
 	QHash<QString, QPixmap>        bitmap_logos_;    ///< Pixmaps for bitmap logos
 	
 	QList<int> rows_heights_;                        ///< rows heights -- simple integers
-	QList<TitleBlockDimension> columns_width_;    ///< columns widths -- @see TitleBlockColDimension
+	QList<TitleBlockDimension> columns_width_;       ///< columns widths -- @see TitleBlockColDimension
 	QList<TitleBlockCell *> registered_cells_;       ///< Cells objects created rattached to this template, but not mandatorily used
 	QList< QList<TitleBlockCell *> > cells_;         ///< Cells grid
 };


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/