[qet] [1473] Added setReadOnly() methods to the title block template editor classes.

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


Revision: 1473
Author:   xavier
Date:     2012-01-22 15:35:57 +0100 (Sun, 22 Jan 2012)
Log Message:
-----------
Added setReadOnly() methods to the title block template editor classes.

Modified Paths:
--------------
    branches/0.3/sources/titleblock/dimensionwidget.cpp
    branches/0.3/sources/titleblock/dimensionwidget.h
    branches/0.3/sources/titleblock/qettemplateeditor.cpp
    branches/0.3/sources/titleblock/qettemplateeditor.h
    branches/0.3/sources/titleblock/templatecellwidget.cpp
    branches/0.3/sources/titleblock/templatecellwidget.h
    branches/0.3/sources/titleblock/templatelogomanager.cpp
    branches/0.3/sources/titleblock/templatelogomanager.h
    branches/0.3/sources/titleblock/templateview.cpp
    branches/0.3/sources/titleblock/templateview.h

Modified: branches/0.3/sources/titleblock/dimensionwidget.cpp
===================================================================
--- branches/0.3/sources/titleblock/dimensionwidget.cpp	2012-01-22 12:08:52 UTC (rev 1472)
+++ branches/0.3/sources/titleblock/dimensionwidget.cpp	2012-01-22 14:35:57 UTC (rev 1473)
@@ -26,7 +26,8 @@
 */
 TitleBlockDimensionWidget::TitleBlockDimensionWidget(bool complete, QWidget *parent) :
 	QDialog(parent),
-	complete_(complete)
+	complete_(complete),
+	read_only_(false)
 {
 	initWidgets();
 	initLayouts();
@@ -86,6 +87,30 @@
 }
 
 /**
+	@return Whether or not this widget should allow edition of the displayed
+	dimension.
+*/
+bool TitleBlockDimensionWidget::isReadOnly() const {
+	return(read_only_);
+}
+
+/**
+	@param read_only Whether or not this widget should allow edition of the
+	displayed dimension.
+*/
+void TitleBlockDimensionWidget::setReadOnly(bool read_only) {
+	if (read_only_ == read_only) return;
+	read_only_ = read_only;
+	
+	spinbox_ -> setReadOnly(read_only_);
+	if (complete_) {
+		absolute_button_  -> setEnabled(!read_only_);
+		relative_button_  -> setEnabled(!read_only_);
+		remaining_button_ -> setEnabled(!read_only_);
+	}
+}
+
+/**
 	Initialize the widgets composing the dialog.
 */
 void TitleBlockDimensionWidget::initWidgets() {

Modified: branches/0.3/sources/titleblock/dimensionwidget.h
===================================================================
--- branches/0.3/sources/titleblock/dimensionwidget.h	2012-01-22 12:08:52 UTC (rev 1472)
+++ branches/0.3/sources/titleblock/dimensionwidget.h	2012-01-22 14:35:57 UTC (rev 1473)
@@ -41,6 +41,9 @@
 	QSpinBox *spinbox() const;
 	TitleBlockDimension value() const;
 	void setValue(const TitleBlockDimension &);
+	bool isReadOnly() const;
+	void setReadOnly(bool);
+	
 	private:
 	void initWidgets();
 	void initLayouts();
@@ -58,5 +61,6 @@
 	QRadioButton *remaining_button_;   ///< Radio button to indicate the length is relative to the remaining length
 	QButtonGroup *dimension_type_;     ///< QButtonGroup for the three radio buttons
 	QDialogButtonBox *buttons_;        ///< Buttons to validate the dialog
+	bool read_only_;                   ///< Whether or not this widget allow edition of the displayed dimension
 };
 #endif

Modified: branches/0.3/sources/titleblock/qettemplateeditor.cpp
===================================================================
--- branches/0.3/sources/titleblock/qettemplateeditor.cpp	2012-01-22 12:08:52 UTC (rev 1472)
+++ branches/0.3/sources/titleblock/qettemplateeditor.cpp	2012-01-22 14:35:57 UTC (rev 1473)
@@ -32,8 +32,8 @@
 */
 QETTitleBlockTemplateEditor::QETTitleBlockTemplateEditor(QWidget *parent) :
 	QMainWindow(parent),
-	read_only(false),
 	opened_from_file_(false),
+	read_only_(false),
 	tb_template_(0),
 	logo_manager_(0)
 {
@@ -394,6 +394,7 @@
 */
 void QETTitleBlockTemplateEditor::initLogoManager() {
 	logo_manager_ = new TitleBlockTemplateLogoManager(tb_template_);
+	logo_manager_ -> setReadOnly(read_only_);
 	connect(
 		logo_manager_,
 		SIGNAL(logosChanged(const TitleBlockTemplate *)),
@@ -420,6 +421,9 @@
 		if (!undo_stack_ -> isClean()) {
 			tag = tr("[Modifi\351]", "window title tag");
 		}
+		if (read_only_) {
+			tag = tr("[Lecture seule]", "window title tag");
+		}
 		titleblock_title = QString(
 			tr(
 				"%1 %2",
@@ -500,6 +504,16 @@
 }
 
 /**
+	Ensure the user interface remains consistent by enabling or disabling
+	adequate actions.
+*/
+void QETTitleBlockTemplateEditor::updateActions() {
+	/// TODO complete this method
+	merge_cells_ -> setEnabled(!read_only_);
+	split_cell_ -> setEnabled(!read_only_);
+}
+
+/**
 	Save the template under the provided location.
 	@see QETProject::setTemplateXmlDescription()
 	@param location Location where the title block template should be saved.
@@ -645,6 +659,22 @@
 }
 
 /**
+	@param read_only True to restrict this editor to visualization of the
+	currently edited template, false to allow full edition.
+*/
+void QETTitleBlockTemplateEditor::setReadOnly(bool read_only) {
+	if (read_only == read_only_) return;
+	read_only_ = read_only;
+	if (logo_manager_) {
+		logo_manager_ -> setReadOnly(read_only_);
+	}
+	template_cell_editor_widget_ -> setReadOnly(read_only_);
+	template_edition_area_view_ -> setReadOnly(read_only_);
+	updateActions();
+	updateEditorTitle();
+}
+
+/**
 	Ask the user for a title block template location
 	@param title Title displayed by the dialog window
 	@param existing_only True for the user to be forced to choose an existing

Modified: branches/0.3/sources/titleblock/qettemplateeditor.h
===================================================================
--- branches/0.3/sources/titleblock/qettemplateeditor.h	2012-01-22 12:08:52 UTC (rev 1472)
+++ branches/0.3/sources/titleblock/qettemplateeditor.h	2012-01-22 14:35:57 UTC (rev 1473)
@@ -44,8 +44,6 @@
 	
 	// attributes
 	private:
-	/// is the template read-only?
-	bool read_only;
 	/// menus TODO
 	QMenu *file_menu_, *edit_menu_,/* *paste_from_menu_, */*display_menu_,/* *tools_menu_,*/ *config_menu_, *help_menu_;
 	/// actions
@@ -60,6 +58,8 @@
 	QString filepath_;
 	/// Whether to consider the location or the filepath
 	bool opened_from_file_;
+	/// whether the currently edited template is considered read only
+	bool read_only_;
 	/// Template Object edited
 	TitleBlockTemplate *tb_template_;
 	/// Template preview
@@ -104,6 +104,7 @@
 	bool save();
 	bool saveAs();
 	bool saveAsFile();
+	void setReadOnly(bool);
 	void quit();
 	
 	private slots:
@@ -112,6 +113,7 @@
 	void pushGridUndoCommand(TitleBlockTemplateCommand *);
 	void pushUndoCommand(QUndoCommand *);
 	void updateEditorTitle();
+	void updateActions();
 	bool saveAs(const TitleBlockTemplateLocation &);
 	bool saveAs(const QString &);
 };

Modified: branches/0.3/sources/titleblock/templatecellwidget.cpp
===================================================================
--- branches/0.3/sources/titleblock/templatecellwidget.cpp	2012-01-22 12:08:52 UTC (rev 1472)
+++ branches/0.3/sources/titleblock/templatecellwidget.cpp	2012-01-22 14:35:57 UTC (rev 1473)
@@ -28,7 +28,7 @@
 */
 TitleBlockTemplateCellWidget::TitleBlockTemplateCellWidget(TitleBlockTemplate *parent_template, QWidget *parent) :
 	QWidget(parent),
-	read_only(false)
+	read_only_(false)
 {
 	initWidgets();
 	updateLogosComboBox(parent_template);
@@ -317,6 +317,25 @@
 }
 
 /**
+	@param read_only whether this edition widget should be read only
+*/
+void TitleBlockTemplateCellWidget::setReadOnly(bool read_only) {
+	if (read_only_ == read_only) return;
+	read_only_ = read_only;
+	
+	cell_type_input_ -> setEnabled(!read_only_);
+	logo_input_ -> setEnabled(!read_only_);
+	name_input_ -> setReadOnly(read_only_);
+	label_checkbox_ -> setEnabled(!read_only_);
+	label_edit_ -> setEnabled(!read_only_);
+	value_edit_ -> setEnabled(!read_only_);
+	horiz_align_input_ -> setEnabled(!read_only_);
+	vert_align_input_ -> setEnabled(!read_only_);
+	font_size_input_ -> setReadOnly(read_only_);
+	font_adjust_input_ -> setEnabled(!read_only_);
+}
+
+/**
 	Emit a horizontal alignment modification command.
 	@see ModifyTitleBlockCellCommand
 */
@@ -340,6 +359,13 @@
 }
 
 /**
+	@return whether this edition widget is read only
+*/
+bool TitleBlockTemplateCellWidget::isReadOnly() const {
+	return(read_only_);
+}
+
+/**
 	Allow the user to edit a translatable string (e.g. value or label).
 	If the user modified the string, this method emits a
 	ModifyTitleBlockCellCommand object through the cellModified() signal.

Modified: branches/0.3/sources/titleblock/templatecellwidget.h
===================================================================
--- branches/0.3/sources/titleblock/templatecellwidget.h	2012-01-22 12:08:52 UTC (rev 1472)
+++ branches/0.3/sources/titleblock/templatecellwidget.h	2012-01-22 14:35:57 UTC (rev 1473)
@@ -41,7 +41,7 @@
 	// attributes
 	private:
 	/// is the template read-only?
-	bool read_only;
+	bool read_only_;
 	QLabel    *cell_type_label_;
 	QComboBox *cell_type_input_;
 	
@@ -81,6 +81,7 @@
 	int horizontalAlignment() const;
 	int verticalAlignment() const;
 	int alignment() const;
+	bool isReadOnly() const;
 	
 	protected:
 	void editTranslatableValue(NamesList &, const QString &, const QString &) const;
@@ -102,6 +103,7 @@
 	void editAdjust();
 	void editLogo();
 	void updateLogosComboBox(const TitleBlockTemplate *);
+	void setReadOnly(bool);
 	
 	private slots:
 	

Modified: branches/0.3/sources/titleblock/templatelogomanager.cpp
===================================================================
--- branches/0.3/sources/titleblock/templatelogomanager.cpp	2012-01-22 12:08:52 UTC (rev 1472)
+++ branches/0.3/sources/titleblock/templatelogomanager.cpp	2012-01-22 14:35:57 UTC (rev 1473)
@@ -51,6 +51,14 @@
 }
 
 /**
+	@return Whether this logo manager should allow logo edition
+	(renaming, addition, deletion).
+*/
+bool TitleBlockTemplateLogoManager::isReadOnly() const {
+	return(read_only_);
+}
+
+/**
 	Emit the logosChanged() signal.
 */
 void TitleBlockTemplateLogoManager::emitLogosChangedSignal() {
@@ -329,3 +337,17 @@
 		emitLogosChangedSignal();
 	}
 }
+
+/**
+	@param read_only Whether this logo manager should allow logo edition
+	(renaming, addition, deletion)
+*/
+void TitleBlockTemplateLogoManager::setReadOnly(bool read_only) {
+	if (read_only_ == read_only) return;
+	read_only_ = read_only;
+	
+	add_button_ -> setEnabled(!read_only_);
+	delete_button_ -> setEnabled(!read_only_);
+	rename_button_ -> setEnabled(!read_only_);
+	logo_name_ -> setReadOnly(read_only_);
+}

Modified: branches/0.3/sources/titleblock/templatelogomanager.h
===================================================================
--- branches/0.3/sources/titleblock/templatelogomanager.h	2012-01-22 12:08:52 UTC (rev 1472)
+++ branches/0.3/sources/titleblock/templatelogomanager.h	2012-01-22 14:35:57 UTC (rev 1473)
@@ -34,6 +34,8 @@
 	// methods
 	public:
 	QString currentLogo() const;
+	bool isReadOnly() const;
+	void setReadOnly(bool);
 	
 	signals:
 	void logosChanged(const TitleBlockTemplate *);
@@ -69,5 +71,6 @@
 	QLabel *logo_type_;                    ///< current logo type
 	QDialogButtonBox *buttons_;            ///< ok/cancel buttons
 	QDir open_dialog_dir_;                 ///< last opened directory
+	bool read_only_;                       ///< Whether this logo manager should allow logo edition (renaming, addition, deletion)
 };
 #endif

Modified: branches/0.3/sources/titleblock/templateview.cpp
===================================================================
--- branches/0.3/sources/titleblock/templateview.cpp	2012-01-22 12:08:52 UTC (rev 1472)
+++ branches/0.3/sources/titleblock/templateview.cpp	2012-01-22 14:35:57 UTC (rev 1473)
@@ -45,7 +45,8 @@
 	preview_width_(DEFAULT_PREVIEW_WIDTH),
 	apply_columns_widths_count_(0),
 	apply_rows_heights_count_(0),
-	first_activation_(true)
+	first_activation_(true),
+	read_only_(false)
 {
 	init();
 }
@@ -61,7 +62,8 @@
 	preview_width_(DEFAULT_PREVIEW_WIDTH),
 	apply_columns_widths_count_(0),
 	apply_rows_heights_count_(0),
-	first_activation_(true)
+	first_activation_(true),
+	read_only_(false)
 {
 	init();
 }
@@ -133,6 +135,7 @@
 	menu.
 */
 void TitleBlockTemplateView::addColumnBefore() {
+	if (read_only_) return;
 	int index = lastContextMenuCellIndex();
 	if (index == -1) return;
 	requestGridModification(ModifyTemplateGridCommand::addColumn(tbtemplate_, index));
@@ -143,6 +146,7 @@
 	menu.
 */
 void TitleBlockTemplateView::addRowBefore() {
+	if (read_only_) return;
 	int index = lastContextMenuCellIndex();
 	if (index == -1) return;
 	requestGridModification(ModifyTemplateGridCommand::addRow(tbtemplate_, index));
@@ -153,6 +157,7 @@
 	menu.
 */
 void TitleBlockTemplateView::addColumnAfter() {
+	if (read_only_) return;
 	int index = lastContextMenuCellIndex();
 	if (index == -1) return;
 	requestGridModification(ModifyTemplateGridCommand::addColumn(tbtemplate_, index + 1));
@@ -163,6 +168,7 @@
 	menu.
 */
 void TitleBlockTemplateView::addRowAfter() {
+	if (read_only_) return;
 	int index = lastContextMenuCellIndex();
 	if (index == -1) return;
 	requestGridModification(ModifyTemplateGridCommand::addRow(tbtemplate_, index + 1));
@@ -179,10 +185,12 @@
 	
 	TitleBlockDimension dimension_before = tbtemplate_ -> columnDimension(index);
 	TitleBlockDimensionWidget dialog(true, this);
+	dialog.setReadOnly(read_only_);
 	dialog.setWindowTitle(tr("Changer la largeur de la colonne", "window title when changing a column with"));
 	dialog.label() -> setText(tr("Largeur :", "text before the spinbox to change a column width"));
 	dialog.setValue(dimension_before);
-	if (dialog.exec() == QDialog::Accepted) {
+	int user_answer = dialog.exec();
+	if (!read_only_ && user_answer == QDialog::Accepted) {
 		ModifyTemplateDimension *command = new ModifyTemplateDimension(tbtemplate_);
 		command -> setType(false);
 		command -> setIndex(index);
@@ -203,10 +211,12 @@
 	
 	TitleBlockDimension dimension_before = TitleBlockDimension(tbtemplate_ -> rowDimension(index));
 	TitleBlockDimensionWidget dialog(false, this);
+	dialog.setReadOnly(read_only_);
 	dialog.setWindowTitle(tr("Changer la hauteur de la ligne", "window title when changing a row height"));
 	dialog.label() -> setText(tr("Hauteur :", "text before the spinbox to change a row height"));
 	dialog.setValue(dimension_before);
-	if (dialog.exec() == QDialog::Accepted) {
+	int user_answer = dialog.exec();
+	if (!read_only_ && user_answer == QDialog::Accepted) {
 		ModifyTemplateDimension *command = new ModifyTemplateDimension(tbtemplate_);
 		command -> setType(true);
 		command -> setIndex(index);
@@ -724,6 +734,22 @@
 }
 
 /**
+	@param read_only whether this view should be read only.
+	
+*/
+void TitleBlockTemplateView::setReadOnly(bool read_only) {
+	if (read_only_ == read_only) return;
+	
+	read_only_ = read_only;
+	add_column_before_ -> setEnabled(!read_only_);
+	add_row_before_    -> setEnabled(!read_only_);
+	add_column_after_  -> setEnabled(!read_only_);
+	add_row_after_     -> setEnabled(!read_only_);
+	delete_column_     -> setEnabled(!read_only_);
+	delete_row_        -> setEnabled(!read_only_);
+}
+
+/**
 	Set the new preview width to width
 	@param width new preview width
 */

Modified: branches/0.3/sources/titleblock/templateview.h
===================================================================
--- branches/0.3/sources/titleblock/templateview.h	2012-01-22 12:08:52 UTC (rev 1472)
+++ branches/0.3/sources/titleblock/templateview.h	2012-01-22 14:35:57 UTC (rev 1473)
@@ -72,6 +72,7 @@
 	void updateLayout();
 	void rowsDimensionsChanged();
 	void columnsDimensionsChanged();
+	void setReadOnly(bool);
 	
 	protected slots:
 	virtual void applyColumnsWidths(bool = true);
@@ -125,5 +126,6 @@
 	int apply_columns_widths_count_;
 	int apply_rows_heights_count_;
 	bool first_activation_;                ///< Boolean used to detect the first display of this widget
+	bool read_only_;                       ///< Boolean stating whether this view allows template edition
 };
 #endif


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