diff --git a/sources/titleblock/dimensionwidget.cpp b/sources/titleblock/dimensionwidget.cpp index 084647c35..02ccef912 100644 --- a/sources/titleblock/dimensionwidget.cpp +++ b/sources/titleblock/dimensionwidget.cpp @@ -26,7 +26,8 @@ */ TitleBlockDimensionWidget::TitleBlockDimensionWidget(bool complete, QWidget *parent) : QDialog(parent), - complete_(complete) + complete_(complete), + read_only_(false) { initWidgets(); initLayouts(); @@ -85,6 +86,30 @@ void TitleBlockDimensionWidget::setValue(const TitleBlockDimension &dim) { updateSpinBoxSuffix(); } +/** + @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. */ diff --git a/sources/titleblock/dimensionwidget.h b/sources/titleblock/dimensionwidget.h index 145c4a3ec..e16de5605 100644 --- a/sources/titleblock/dimensionwidget.h +++ b/sources/titleblock/dimensionwidget.h @@ -41,6 +41,9 @@ class TitleBlockDimensionWidget : public QDialog { 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 @@ class TitleBlockDimensionWidget : public QDialog { 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 diff --git a/sources/titleblock/qettemplateeditor.cpp b/sources/titleblock/qettemplateeditor.cpp index db1973e40..acdca0037 100644 --- a/sources/titleblock/qettemplateeditor.cpp +++ b/sources/titleblock/qettemplateeditor.cpp @@ -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::initWidgets() { */ 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 @@ QString QETTitleBlockTemplateEditor::currentlyEditedTitle() const { 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", @@ -499,6 +503,16 @@ void QETTitleBlockTemplateEditor::updateEditorTitle() { setWindowTitle(title); } +/** + 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() @@ -644,6 +658,22 @@ bool QETTitleBlockTemplateEditor::saveAsFile() { return(saving); } +/** + @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 diff --git a/sources/titleblock/qettemplateeditor.h b/sources/titleblock/qettemplateeditor.h index 02f0a9f64..a0eda6c00 100644 --- a/sources/titleblock/qettemplateeditor.h +++ b/sources/titleblock/qettemplateeditor.h @@ -44,8 +44,6 @@ class QETTitleBlockTemplateEditor : public QMainWindow { // 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 @@ class QETTitleBlockTemplateEditor : public QMainWindow { 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 @@ class QETTitleBlockTemplateEditor : public QMainWindow { bool save(); bool saveAs(); bool saveAsFile(); + void setReadOnly(bool); void quit(); private slots: @@ -112,6 +113,7 @@ class QETTitleBlockTemplateEditor : public QMainWindow { void pushGridUndoCommand(TitleBlockTemplateCommand *); void pushUndoCommand(QUndoCommand *); void updateEditorTitle(); + void updateActions(); bool saveAs(const TitleBlockTemplateLocation &); bool saveAs(const QString &); }; diff --git a/sources/titleblock/templatecellwidget.cpp b/sources/titleblock/templatecellwidget.cpp index 11b93b971..ae7d2ab5c 100644 --- a/sources/titleblock/templatecellwidget.cpp +++ b/sources/titleblock/templatecellwidget.cpp @@ -28,7 +28,7 @@ */ TitleBlockTemplateCellWidget::TitleBlockTemplateCellWidget(TitleBlockTemplate *parent_template, QWidget *parent) : QWidget(parent), - read_only(false) + read_only_(false) { initWidgets(); updateLogosComboBox(parent_template); @@ -316,6 +316,25 @@ void TitleBlockTemplateCellWidget::updateLogosComboBox(const TitleBlockTemplate } } +/** + @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 @@ -339,6 +358,13 @@ int TitleBlockTemplateCellWidget::alignment() const { return(horizontalAlignment() | verticalAlignment()); } +/** + @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 diff --git a/sources/titleblock/templatecellwidget.h b/sources/titleblock/templatecellwidget.h index e6ee5514c..f9d983c5f 100644 --- a/sources/titleblock/templatecellwidget.h +++ b/sources/titleblock/templatecellwidget.h @@ -41,7 +41,7 @@ class TitleBlockTemplateCellWidget : public QWidget { // 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 @@ class TitleBlockTemplateCellWidget : public QWidget { 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 @@ class TitleBlockTemplateCellWidget : public QWidget { void editAdjust(); void editLogo(); void updateLogosComboBox(const TitleBlockTemplate *); + void setReadOnly(bool); private slots: diff --git a/sources/titleblock/templatelogomanager.cpp b/sources/titleblock/templatelogomanager.cpp index 48e629df0..b0d27af24 100644 --- a/sources/titleblock/templatelogomanager.cpp +++ b/sources/titleblock/templatelogomanager.cpp @@ -50,6 +50,14 @@ QString TitleBlockTemplateLogoManager::currentLogo() const { return(current_item -> text()); } +/** + @return Whether this logo manager should allow logo edition + (renaming, addition, deletion). +*/ +bool TitleBlockTemplateLogoManager::isReadOnly() const { + return(read_only_); +} + /** Emit the logosChanged() signal. */ @@ -329,3 +337,17 @@ void TitleBlockTemplateLogoManager::renameLogo() { 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_); +} diff --git a/sources/titleblock/templatelogomanager.h b/sources/titleblock/templatelogomanager.h index 68c4c65e4..9c90ba3fe 100644 --- a/sources/titleblock/templatelogomanager.h +++ b/sources/titleblock/templatelogomanager.h @@ -34,6 +34,8 @@ class TitleBlockTemplateLogoManager : public QWidget { // methods public: QString currentLogo() const; + bool isReadOnly() const; + void setReadOnly(bool); signals: void logosChanged(const TitleBlockTemplate *); @@ -69,5 +71,6 @@ class TitleBlockTemplateLogoManager : public QWidget { 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 diff --git a/sources/titleblock/templateview.cpp b/sources/titleblock/templateview.cpp index 2d865badf..4d41c7291 100644 --- a/sources/titleblock/templateview.cpp +++ b/sources/titleblock/templateview.cpp @@ -45,7 +45,8 @@ TitleBlockTemplateView::TitleBlockTemplateView(QWidget *parent) : 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 @@ TitleBlockTemplateView::TitleBlockTemplateView(QGraphicsScene *scene, QWidget *p 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 @@ void TitleBlockTemplateView::zoomReset() { menu. */ void TitleBlockTemplateView::addColumnBefore() { + if (read_only_) return; int index = lastContextMenuCellIndex(); if (index == -1) return; requestGridModification(ModifyTemplateGridCommand::addColumn(tbtemplate_, index)); @@ -143,6 +146,7 @@ void TitleBlockTemplateView::addColumnBefore() { menu. */ void TitleBlockTemplateView::addRowBefore() { + if (read_only_) return; int index = lastContextMenuCellIndex(); if (index == -1) return; requestGridModification(ModifyTemplateGridCommand::addRow(tbtemplate_, index)); @@ -153,6 +157,7 @@ void TitleBlockTemplateView::addRowBefore() { 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 @@ void TitleBlockTemplateView::addColumnAfter() { 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 @@ void TitleBlockTemplateView::editColumn(HelperCell *cell) { 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 @@ void TitleBlockTemplateView::editRow(HelperCell *cell) { 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); @@ -723,6 +733,22 @@ void TitleBlockTemplateView::columnsDimensionsChanged() { applyColumnsWidths(); } +/** + @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 diff --git a/sources/titleblock/templateview.h b/sources/titleblock/templateview.h index 8da5d9907..2e6e593b3 100644 --- a/sources/titleblock/templateview.h +++ b/sources/titleblock/templateview.h @@ -72,6 +72,7 @@ class TitleBlockTemplateView : public QGraphicsView { void updateLayout(); void rowsDimensionsChanged(); void columnsDimensionsChanged(); + void setReadOnly(bool); protected slots: virtual void applyColumnsWidths(bool = true); @@ -125,5 +126,6 @@ class TitleBlockTemplateView : public QGraphicsView { 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