Added setReadOnly() methods to the title block template editor classes.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1473 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2012-01-22 14:35:57 +00:00
parent 0e0e4dfc29
commit 21c8ffbd7b
10 changed files with 152 additions and 10 deletions

View File

@@ -26,7 +26,8 @@
*/ */
TitleBlockDimensionWidget::TitleBlockDimensionWidget(bool complete, QWidget *parent) : TitleBlockDimensionWidget::TitleBlockDimensionWidget(bool complete, QWidget *parent) :
QDialog(parent), QDialog(parent),
complete_(complete) complete_(complete),
read_only_(false)
{ {
initWidgets(); initWidgets();
initLayouts(); initLayouts();
@@ -85,6 +86,30 @@ void TitleBlockDimensionWidget::setValue(const TitleBlockDimension &dim) {
updateSpinBoxSuffix(); 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. Initialize the widgets composing the dialog.
*/ */

View File

@@ -41,6 +41,9 @@ class TitleBlockDimensionWidget : public QDialog {
QSpinBox *spinbox() const; QSpinBox *spinbox() const;
TitleBlockDimension value() const; TitleBlockDimension value() const;
void setValue(const TitleBlockDimension &); void setValue(const TitleBlockDimension &);
bool isReadOnly() const;
void setReadOnly(bool);
private: private:
void initWidgets(); void initWidgets();
void initLayouts(); 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 QRadioButton *remaining_button_; ///< Radio button to indicate the length is relative to the remaining length
QButtonGroup *dimension_type_; ///< QButtonGroup for the three radio buttons QButtonGroup *dimension_type_; ///< QButtonGroup for the three radio buttons
QDialogButtonBox *buttons_; ///< Buttons to validate the dialog QDialogButtonBox *buttons_; ///< Buttons to validate the dialog
bool read_only_; ///< Whether or not this widget allow edition of the displayed dimension
}; };
#endif #endif

View File

@@ -32,8 +32,8 @@
*/ */
QETTitleBlockTemplateEditor::QETTitleBlockTemplateEditor(QWidget *parent) : QETTitleBlockTemplateEditor::QETTitleBlockTemplateEditor(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
read_only(false),
opened_from_file_(false), opened_from_file_(false),
read_only_(false),
tb_template_(0), tb_template_(0),
logo_manager_(0) logo_manager_(0)
{ {
@@ -394,6 +394,7 @@ void QETTitleBlockTemplateEditor::initWidgets() {
*/ */
void QETTitleBlockTemplateEditor::initLogoManager() { void QETTitleBlockTemplateEditor::initLogoManager() {
logo_manager_ = new TitleBlockTemplateLogoManager(tb_template_); logo_manager_ = new TitleBlockTemplateLogoManager(tb_template_);
logo_manager_ -> setReadOnly(read_only_);
connect( connect(
logo_manager_, logo_manager_,
SIGNAL(logosChanged(const TitleBlockTemplate *)), SIGNAL(logosChanged(const TitleBlockTemplate *)),
@@ -420,6 +421,9 @@ QString QETTitleBlockTemplateEditor::currentlyEditedTitle() const {
if (!undo_stack_ -> isClean()) { if (!undo_stack_ -> isClean()) {
tag = tr("[Modifi\351]", "window title tag"); tag = tr("[Modifi\351]", "window title tag");
} }
if (read_only_) {
tag = tr("[Lecture seule]", "window title tag");
}
titleblock_title = QString( titleblock_title = QString(
tr( tr(
"%1 %2", "%1 %2",
@@ -499,6 +503,16 @@ void QETTitleBlockTemplateEditor::updateEditorTitle() {
setWindowTitle(title); 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. Save the template under the provided location.
@see QETProject::setTemplateXmlDescription() @see QETProject::setTemplateXmlDescription()
@@ -644,6 +658,22 @@ bool QETTitleBlockTemplateEditor::saveAsFile() {
return(saving); 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 Ask the user for a title block template location
@param title Title displayed by the dialog window @param title Title displayed by the dialog window

View File

@@ -44,8 +44,6 @@ class QETTitleBlockTemplateEditor : public QMainWindow {
// attributes // attributes
private: private:
/// is the template read-only?
bool read_only;
/// menus TODO /// menus TODO
QMenu *file_menu_, *edit_menu_,/* *paste_from_menu_, */*display_menu_,/* *tools_menu_,*/ *config_menu_, *help_menu_; QMenu *file_menu_, *edit_menu_,/* *paste_from_menu_, */*display_menu_,/* *tools_menu_,*/ *config_menu_, *help_menu_;
/// actions /// actions
@@ -60,6 +58,8 @@ class QETTitleBlockTemplateEditor : public QMainWindow {
QString filepath_; QString filepath_;
/// Whether to consider the location or the filepath /// Whether to consider the location or the filepath
bool opened_from_file_; bool opened_from_file_;
/// whether the currently edited template is considered read only
bool read_only_;
/// Template Object edited /// Template Object edited
TitleBlockTemplate *tb_template_; TitleBlockTemplate *tb_template_;
/// Template preview /// Template preview
@@ -104,6 +104,7 @@ class QETTitleBlockTemplateEditor : public QMainWindow {
bool save(); bool save();
bool saveAs(); bool saveAs();
bool saveAsFile(); bool saveAsFile();
void setReadOnly(bool);
void quit(); void quit();
private slots: private slots:
@@ -112,6 +113,7 @@ class QETTitleBlockTemplateEditor : public QMainWindow {
void pushGridUndoCommand(TitleBlockTemplateCommand *); void pushGridUndoCommand(TitleBlockTemplateCommand *);
void pushUndoCommand(QUndoCommand *); void pushUndoCommand(QUndoCommand *);
void updateEditorTitle(); void updateEditorTitle();
void updateActions();
bool saveAs(const TitleBlockTemplateLocation &); bool saveAs(const TitleBlockTemplateLocation &);
bool saveAs(const QString &); bool saveAs(const QString &);
}; };

View File

@@ -28,7 +28,7 @@
*/ */
TitleBlockTemplateCellWidget::TitleBlockTemplateCellWidget(TitleBlockTemplate *parent_template, QWidget *parent) : TitleBlockTemplateCellWidget::TitleBlockTemplateCellWidget(TitleBlockTemplate *parent_template, QWidget *parent) :
QWidget(parent), QWidget(parent),
read_only(false) read_only_(false)
{ {
initWidgets(); initWidgets();
updateLogosComboBox(parent_template); 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. Emit a horizontal alignment modification command.
@see ModifyTitleBlockCellCommand @see ModifyTitleBlockCellCommand
@@ -339,6 +358,13 @@ int TitleBlockTemplateCellWidget::alignment() const {
return(horizontalAlignment() | verticalAlignment()); 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). Allow the user to edit a translatable string (e.g. value or label).
If the user modified the string, this method emits a If the user modified the string, this method emits a

View File

@@ -41,7 +41,7 @@ class TitleBlockTemplateCellWidget : public QWidget {
// attributes // attributes
private: private:
/// is the template read-only? /// is the template read-only?
bool read_only; bool read_only_;
QLabel *cell_type_label_; QLabel *cell_type_label_;
QComboBox *cell_type_input_; QComboBox *cell_type_input_;
@@ -81,6 +81,7 @@ class TitleBlockTemplateCellWidget : public QWidget {
int horizontalAlignment() const; int horizontalAlignment() const;
int verticalAlignment() const; int verticalAlignment() const;
int alignment() const; int alignment() const;
bool isReadOnly() const;
protected: protected:
void editTranslatableValue(NamesList &, const QString &, const QString &) const; void editTranslatableValue(NamesList &, const QString &, const QString &) const;
@@ -102,6 +103,7 @@ class TitleBlockTemplateCellWidget : public QWidget {
void editAdjust(); void editAdjust();
void editLogo(); void editLogo();
void updateLogosComboBox(const TitleBlockTemplate *); void updateLogosComboBox(const TitleBlockTemplate *);
void setReadOnly(bool);
private slots: private slots:

View File

@@ -50,6 +50,14 @@ QString TitleBlockTemplateLogoManager::currentLogo() const {
return(current_item -> text()); 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. Emit the logosChanged() signal.
*/ */
@@ -329,3 +337,17 @@ void TitleBlockTemplateLogoManager::renameLogo() {
emitLogosChangedSignal(); 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_);
}

View File

@@ -34,6 +34,8 @@ class TitleBlockTemplateLogoManager : public QWidget {
// methods // methods
public: public:
QString currentLogo() const; QString currentLogo() const;
bool isReadOnly() const;
void setReadOnly(bool);
signals: signals:
void logosChanged(const TitleBlockTemplate *); void logosChanged(const TitleBlockTemplate *);
@@ -69,5 +71,6 @@ class TitleBlockTemplateLogoManager : public QWidget {
QLabel *logo_type_; ///< current logo type QLabel *logo_type_; ///< current logo type
QDialogButtonBox *buttons_; ///< ok/cancel buttons QDialogButtonBox *buttons_; ///< ok/cancel buttons
QDir open_dialog_dir_; ///< last opened directory QDir open_dialog_dir_; ///< last opened directory
bool read_only_; ///< Whether this logo manager should allow logo edition (renaming, addition, deletion)
}; };
#endif #endif

View File

@@ -45,7 +45,8 @@ TitleBlockTemplateView::TitleBlockTemplateView(QWidget *parent) :
preview_width_(DEFAULT_PREVIEW_WIDTH), preview_width_(DEFAULT_PREVIEW_WIDTH),
apply_columns_widths_count_(0), apply_columns_widths_count_(0),
apply_rows_heights_count_(0), apply_rows_heights_count_(0),
first_activation_(true) first_activation_(true),
read_only_(false)
{ {
init(); init();
} }
@@ -61,7 +62,8 @@ TitleBlockTemplateView::TitleBlockTemplateView(QGraphicsScene *scene, QWidget *p
preview_width_(DEFAULT_PREVIEW_WIDTH), preview_width_(DEFAULT_PREVIEW_WIDTH),
apply_columns_widths_count_(0), apply_columns_widths_count_(0),
apply_rows_heights_count_(0), apply_rows_heights_count_(0),
first_activation_(true) first_activation_(true),
read_only_(false)
{ {
init(); init();
} }
@@ -133,6 +135,7 @@ void TitleBlockTemplateView::zoomReset() {
menu. menu.
*/ */
void TitleBlockTemplateView::addColumnBefore() { void TitleBlockTemplateView::addColumnBefore() {
if (read_only_) return;
int index = lastContextMenuCellIndex(); int index = lastContextMenuCellIndex();
if (index == -1) return; if (index == -1) return;
requestGridModification(ModifyTemplateGridCommand::addColumn(tbtemplate_, index)); requestGridModification(ModifyTemplateGridCommand::addColumn(tbtemplate_, index));
@@ -143,6 +146,7 @@ void TitleBlockTemplateView::addColumnBefore() {
menu. menu.
*/ */
void TitleBlockTemplateView::addRowBefore() { void TitleBlockTemplateView::addRowBefore() {
if (read_only_) return;
int index = lastContextMenuCellIndex(); int index = lastContextMenuCellIndex();
if (index == -1) return; if (index == -1) return;
requestGridModification(ModifyTemplateGridCommand::addRow(tbtemplate_, index)); requestGridModification(ModifyTemplateGridCommand::addRow(tbtemplate_, index));
@@ -153,6 +157,7 @@ void TitleBlockTemplateView::addRowBefore() {
menu. menu.
*/ */
void TitleBlockTemplateView::addColumnAfter() { void TitleBlockTemplateView::addColumnAfter() {
if (read_only_) return;
int index = lastContextMenuCellIndex(); int index = lastContextMenuCellIndex();
if (index == -1) return; if (index == -1) return;
requestGridModification(ModifyTemplateGridCommand::addColumn(tbtemplate_, index + 1)); requestGridModification(ModifyTemplateGridCommand::addColumn(tbtemplate_, index + 1));
@@ -163,6 +168,7 @@ void TitleBlockTemplateView::addColumnAfter() {
menu. menu.
*/ */
void TitleBlockTemplateView::addRowAfter() { void TitleBlockTemplateView::addRowAfter() {
if (read_only_) return;
int index = lastContextMenuCellIndex(); int index = lastContextMenuCellIndex();
if (index == -1) return; if (index == -1) return;
requestGridModification(ModifyTemplateGridCommand::addRow(tbtemplate_, index + 1)); requestGridModification(ModifyTemplateGridCommand::addRow(tbtemplate_, index + 1));
@@ -179,10 +185,12 @@ void TitleBlockTemplateView::editColumn(HelperCell *cell) {
TitleBlockDimension dimension_before = tbtemplate_ -> columnDimension(index); TitleBlockDimension dimension_before = tbtemplate_ -> columnDimension(index);
TitleBlockDimensionWidget dialog(true, this); 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.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.label() -> setText(tr("Largeur :", "text before the spinbox to change a column width"));
dialog.setValue(dimension_before); 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_); ModifyTemplateDimension *command = new ModifyTemplateDimension(tbtemplate_);
command -> setType(false); command -> setType(false);
command -> setIndex(index); command -> setIndex(index);
@@ -203,10 +211,12 @@ void TitleBlockTemplateView::editRow(HelperCell *cell) {
TitleBlockDimension dimension_before = TitleBlockDimension(tbtemplate_ -> rowDimension(index)); TitleBlockDimension dimension_before = TitleBlockDimension(tbtemplate_ -> rowDimension(index));
TitleBlockDimensionWidget dialog(false, this); 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.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.label() -> setText(tr("Hauteur :", "text before the spinbox to change a row height"));
dialog.setValue(dimension_before); 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_); ModifyTemplateDimension *command = new ModifyTemplateDimension(tbtemplate_);
command -> setType(true); command -> setType(true);
command -> setIndex(index); command -> setIndex(index);
@@ -723,6 +733,22 @@ void TitleBlockTemplateView::columnsDimensionsChanged() {
applyColumnsWidths(); 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 Set the new preview width to width
@param width new preview width @param width new preview width

View File

@@ -72,6 +72,7 @@ class TitleBlockTemplateView : public QGraphicsView {
void updateLayout(); void updateLayout();
void rowsDimensionsChanged(); void rowsDimensionsChanged();
void columnsDimensionsChanged(); void columnsDimensionsChanged();
void setReadOnly(bool);
protected slots: protected slots:
virtual void applyColumnsWidths(bool = true); virtual void applyColumnsWidths(bool = true);
@@ -125,5 +126,6 @@ class TitleBlockTemplateView : public QGraphicsView {
int apply_columns_widths_count_; int apply_columns_widths_count_;
int apply_rows_heights_count_; int apply_rows_heights_count_;
bool first_activation_; ///< Boolean used to detect the first display of this widget 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 #endif