[qet] [1803] TBT editor: logos manager: added an "export" button.

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


Revision: 1803
Author:   xavier
Date:     2012-05-11 19:47:38 +0200 (Fri, 11 May 2012)
Log Message:
-----------
TBT editor: logos manager: added an "export" button.

Modified Paths:
--------------
    trunk/sources/titleblock/templatelogomanager.cpp
    trunk/sources/titleblock/templatelogomanager.h
    trunk/sources/titleblocktemplate.cpp
    trunk/sources/titleblocktemplate.h

Modified: trunk/sources/titleblock/templatelogomanager.cpp
===================================================================
--- trunk/sources/titleblock/templatelogomanager.cpp	2012-05-11 10:14:51 UTC (rev 1802)
+++ trunk/sources/titleblock/templatelogomanager.cpp	2012-05-11 17:47:38 UTC (rev 1803)
@@ -85,6 +85,7 @@
 	logos_view_ -> setMovement(QListView::Static);
 	logos_view_ -> setResizeMode(QListView::Adjust);
 	add_button_ = new QPushButton(QET::Icons::Add, tr("Ajouter un logo"));
+	export_button_ = new QPushButton(QET::Icons::DocumentExport, tr("Exporter ce logo"));
 	delete_button_ = new QPushButton(QET::Icons::Remove, tr("Supprimer ce logo"));
 	logo_box_ = new QGroupBox(tr("Propri\351t\351s"));
 	logo_name_label_ = new QLabel(tr("Nom :"));
@@ -99,7 +100,7 @@
 	hlayout1_ -> addWidget(rename_button_);
 	
 	hlayout0_ = new QHBoxLayout();
-	hlayout0_ -> addWidget(add_button_);
+	hlayout0_ -> addWidget(export_button_);
 	hlayout0_ -> addWidget(delete_button_);
 	
 	vlayout1_ = new QVBoxLayout();
@@ -110,6 +111,7 @@
 	vlayout0_ = new QVBoxLayout();
 	vlayout0_ -> addWidget(logos_label_);
 	vlayout0_ -> addWidget(logos_view_);
+	vlayout0_ -> addWidget(add_button_);
 	vlayout0_ -> addLayout(hlayout0_);
 	vlayout0_ -> addWidget(logo_box_);
 	setLayout(vlayout0_);
@@ -121,6 +123,7 @@
 		SLOT(updateLogoInformations(QListWidgetItem *, QListWidgetItem *))
 	);
 	connect(add_button_, SIGNAL(released()), this, SLOT(addLogo()));
+	connect(export_button_, SIGNAL(released()), this, SLOT(exportLogo()));
 	connect(delete_button_, SIGNAL(released()), this, SLOT(removeLogo()));
 	connect(rename_button_, SIGNAL(released()), this, SLOT(renameLogo()));
 }
@@ -286,6 +289,29 @@
 }
 
 /**
+	Export the currently selected logo
+*/
+void TitleBlockTemplateLogoManager::exportLogo() {
+	QString current_logo = currentLogo();
+	if (current_logo.isNull()) return;
+	
+	QString filepath = QFileDialog::getSaveFileName(
+		this,
+		tr("Choisir un fichier pour exporter ce logo"),
+		open_dialog_dir_.absolutePath() + "/" + current_logo,
+		tr("Tous les fichiers (*);;Images vectorielles (*.svg);;Images bitmap (*.png *.jpg *.jpeg *.gif *.bmp *.xpm)")
+	);
+	if (filepath.isEmpty()) return;
+	
+	bool save_logo = managed_template_ -> saveLogoToFile(current_logo, filepath);
+	if (!save_logo) {
+		QMessageBox::critical(this, tr("Erreur"), QString(tr("Impossible d'exporter vers le fichier sp\351cifi\351")));
+	} else {
+		open_dialog_dir_ = QDir(filepath);
+	}
+}
+
+/**
 	Delete the currently selected logo.
 */
 void TitleBlockTemplateLogoManager::removeLogo() {

Modified: trunk/sources/titleblock/templatelogomanager.h
===================================================================
--- trunk/sources/titleblock/templatelogomanager.h	2012-05-11 10:14:51 UTC (rev 1802)
+++ trunk/sources/titleblock/templatelogomanager.h	2012-05-11 17:47:38 UTC (rev 1803)
@@ -52,6 +52,7 @@
 	private slots:
 	void updateLogoInformations(QListWidgetItem *, QListWidgetItem *);
 	void addLogo();
+	void exportLogo();
 	void removeLogo();
 	void renameLogo();
 	
@@ -63,7 +64,8 @@
 	QLabel *logos_label_;                  ///< simple displayed label
 	QListWidget *logos_view_;              ///< area showing the logos
 	QPushButton *add_button_;              ///< button to add a new logo
-	QPushButton *delete_button_;           ///< button to delete an embeded logo
+	QPushButton *export_button_;           ///< button to export an embedded logo
+	QPushButton *delete_button_;           ///< button to delete an embedded logo
 	QGroupBox *logo_box_;                  ///< current logo properties box
 	QLabel *logo_name_label_;              ///< "name:" label
 	QLineEdit *logo_name_;                 ///< current logo name

Modified: trunk/sources/titleblocktemplate.cpp
===================================================================
--- trunk/sources/titleblocktemplate.cpp	2012-05-11 10:14:51 UTC (rev 1802)
+++ trunk/sources/titleblocktemplate.cpp	2012-05-11 17:47:38 UTC (rev 1803)
@@ -1079,7 +1079,7 @@
 
 /**
 	@param filepath Path of the image file to add as a logo
-	@param logo_name Name used to store the logo; if none is provided, the
+	@param name Name used to store the logo; if none is provided, the
 	basename of the first argument is used.
 	@return true if the logo could be deleted, false otherwise
 */
@@ -1100,6 +1100,26 @@
 	return addLogo(filename, &file_content, filepath_info.suffix(), "base64");
 }
 
+/*
+	@param logo_name Name used to store the logo
+	@param filepath Path the logo will be saved as
+	@return true if the logo could be exported, false otherwise
+*/
+bool TitleBlockTemplate::saveLogoToFile(const QString &logo_name, const QString &filepath) {
+	if (!data_logos_.contains(logo_name)) {
+		return(false);
+	}
+	
+	QFile target_file(filepath);
+	if (!target_file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
+		return(false);
+	}
+	
+	target_file.write(data_logos_[logo_name]);
+	target_file.close();
+	return(true);
+}
+
 /**
 	@param logo_name Name of the logo to remove
 	@return true if the logo could be deleted, false otherwise

Modified: trunk/sources/titleblocktemplate.h
===================================================================
--- trunk/sources/titleblocktemplate.h	2012-05-11 10:14:51 UTC (rev 1802)
+++ trunk/sources/titleblocktemplate.h	2012-05-11 17:47:38 UTC (rev 1803)
@@ -87,6 +87,7 @@
 	void setAllSpans(const QHash<TitleBlockCell *, QPair<int, int> > &);
 	bool addLogo(const QString &, QByteArray *, const QString & = "svg", const QString & = "xml");
 	bool addLogoFromFile(const QString &, const QString & = QString());
+	bool saveLogoToFile(const QString &, const QString &);
 	bool removeLogo(const QString &);
 	bool renameLogo(const QString &, const QString &);
 	void setLogoStorage(const QString &, const QString &);


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