From 99f7b916e6b9c3eb3e9d69e7d996ed590248ee53 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Mon, 30 Mar 2015 14:44:11 +0200 Subject: [PATCH] Improve read-only mode of InsetParams derived dialogs * Disable "New Inset" button * Do not disable line edits, but use setReadOnly instead (this allows copying contents) Fixes: #9408 Note that some dialogs still need some care. --- src/frontends/qt4/GuiBibitem.cpp | 4 +++- src/frontends/qt4/GuiBibitem.h | 2 +- src/frontends/qt4/GuiHSpace.cpp | 7 ++++++- src/frontends/qt4/GuiHSpace.h | 2 +- src/frontends/qt4/GuiHyperlink.cpp | 5 ++++- src/frontends/qt4/GuiHyperlink.h | 2 +- src/frontends/qt4/GuiLabel.cpp | 3 ++- src/frontends/qt4/GuiLabel.h | 2 +- src/frontends/qt4/GuiLine.cpp | 8 +++++++- src/frontends/qt4/GuiLine.h | 2 +- src/frontends/qt4/GuiNomenclature.cpp | 4 +++- src/frontends/qt4/GuiNomenclature.h | 2 +- src/frontends/qt4/GuiPrintNomencl.cpp | 5 ++++- src/frontends/qt4/GuiPrintNomencl.h | 2 +- src/frontends/qt4/InsetParamsDialog.cpp | 6 +++--- src/frontends/qt4/InsetParamsWidget.cpp | 2 +- src/frontends/qt4/InsetParamsWidget.h | 2 +- 17 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/frontends/qt4/GuiBibitem.cpp b/src/frontends/qt4/GuiBibitem.cpp index 0b2da16cce..052be00f36 100644 --- a/src/frontends/qt4/GuiBibitem.cpp +++ b/src/frontends/qt4/GuiBibitem.cpp @@ -53,8 +53,10 @@ docstring GuiBibitem::dialogToParams() const } -bool GuiBibitem::checkWidgets() const +bool GuiBibitem::checkWidgets(bool readonly) const { + keyED->setReadOnly(readonly); + labelED->setReadOnly(readonly); if (!InsetParamsWidget::checkWidgets()) return false; return !keyED->text().isEmpty(); diff --git a/src/frontends/qt4/GuiBibitem.h b/src/frontends/qt4/GuiBibitem.h index a64ba72e88..70dcb2aff4 100644 --- a/src/frontends/qt4/GuiBibitem.h +++ b/src/frontends/qt4/GuiBibitem.h @@ -35,7 +35,7 @@ private: FuncCode creationCode() const { return LFUN_INSET_INSERT; } void paramsToDialog(Inset const *); docstring dialogToParams() const; - bool checkWidgets() const; + bool checkWidgets(bool readonly = false) const; //@} }; diff --git a/src/frontends/qt4/GuiHSpace.cpp b/src/frontends/qt4/GuiHSpace.cpp index 57d4e982e0..a85037a181 100644 --- a/src/frontends/qt4/GuiHSpace.cpp +++ b/src/frontends/qt4/GuiHSpace.cpp @@ -299,8 +299,13 @@ docstring GuiHSpace::dialogToParams() const } -bool GuiHSpace::checkWidgets() const +bool GuiHSpace::checkWidgets(bool readonly) const { + spacingCO->setEnabled(!readonly); + unitCO->setEnabled(!readonly); + fillPatternCO->setEnabled(!readonly); + keepCB->setEnabled(!readonly); + valueLE->setReadOnly(readonly); if (!InsetParamsWidget::checkWidgets()) return false; return spacingCO->itemData(spacingCO->currentIndex()).toString() != "custom" diff --git a/src/frontends/qt4/GuiHSpace.h b/src/frontends/qt4/GuiHSpace.h index 6bc45ccc6f..0913475cf6 100644 --- a/src/frontends/qt4/GuiHSpace.h +++ b/src/frontends/qt4/GuiHSpace.h @@ -38,7 +38,7 @@ private: FuncCode creationCode() const { return LFUN_INSET_INSERT; } void paramsToDialog(Inset const *); docstring dialogToParams() const; - bool checkWidgets() const; + bool checkWidgets(bool readonly = false) const; //@} /// bool const math_mode_; diff --git a/src/frontends/qt4/GuiHyperlink.cpp b/src/frontends/qt4/GuiHyperlink.cpp index 6cd9262798..3111d193c4 100644 --- a/src/frontends/qt4/GuiHyperlink.cpp +++ b/src/frontends/qt4/GuiHyperlink.cpp @@ -102,8 +102,11 @@ docstring GuiHyperlink::dialogToParams() const } -bool GuiHyperlink::checkWidgets() const +bool GuiHyperlink::checkWidgets(bool readonly) const { + targetED->setReadOnly(readonly); + nameED->setReadOnly(readonly); + typeGB->setEnabled(!readonly); if (!InsetParamsWidget::checkWidgets()) return false; return !targetED->text().isEmpty() || !nameED->text().isEmpty(); diff --git a/src/frontends/qt4/GuiHyperlink.h b/src/frontends/qt4/GuiHyperlink.h index d2dd0ee0fb..0523aaa8db 100644 --- a/src/frontends/qt4/GuiHyperlink.h +++ b/src/frontends/qt4/GuiHyperlink.h @@ -34,7 +34,7 @@ private: FuncCode creationCode() const { return LFUN_INSET_INSERT; } void paramsToDialog(Inset const *); docstring dialogToParams() const; - bool checkWidgets() const; + bool checkWidgets(bool readonly = false) const; bool initialiseParams(std::string const & data); //@} }; diff --git a/src/frontends/qt4/GuiLabel.cpp b/src/frontends/qt4/GuiLabel.cpp index 5d1ea4a3ef..d5b207f773 100644 --- a/src/frontends/qt4/GuiLabel.cpp +++ b/src/frontends/qt4/GuiLabel.cpp @@ -68,8 +68,9 @@ bool GuiLabel::initialiseParams(std::string const & data) } -bool GuiLabel::checkWidgets() const +bool GuiLabel::checkWidgets(bool readonly) const { + keywordED->setReadOnly(readonly); if (!InsetParamsWidget::checkWidgets()) return false; return !keywordED->text().isEmpty(); diff --git a/src/frontends/qt4/GuiLabel.h b/src/frontends/qt4/GuiLabel.h index d616cbf1f5..6ba60ed216 100644 --- a/src/frontends/qt4/GuiLabel.h +++ b/src/frontends/qt4/GuiLabel.h @@ -34,7 +34,7 @@ private: FuncCode creationCode() const { return LFUN_INSET_INSERT; } void paramsToDialog(Inset const *); docstring dialogToParams() const; - bool checkWidgets() const; + bool checkWidgets(bool readonly = false) const; bool initialiseParams(std::string const &); //@} }; diff --git a/src/frontends/qt4/GuiLine.cpp b/src/frontends/qt4/GuiLine.cpp index 4ab2da8c94..2a8b9de2bc 100644 --- a/src/frontends/qt4/GuiLine.cpp +++ b/src/frontends/qt4/GuiLine.cpp @@ -100,8 +100,14 @@ void GuiLine::paramsToDialog(Inset const * inset) } -bool GuiLine::checkWidgets() const +bool GuiLine::checkWidgets(bool readonly) const { + WidthLE->setReadOnly(readonly); + HeightLE->setReadOnly(readonly); + OffsetLE->setReadOnly(readonly); + OffsetUnitCO->setEnabled(!readonly); + HeightUnitCO->setEnabled(!readonly); + WidthUnitCO->setEnabled(!readonly); if (!InsetParamsWidget::checkWidgets()) return false; // FIXME: this should be handled in unsignedGlueLengthValidator! diff --git a/src/frontends/qt4/GuiLine.h b/src/frontends/qt4/GuiLine.h index 0ad68337f0..9fa3e61146 100644 --- a/src/frontends/qt4/GuiLine.h +++ b/src/frontends/qt4/GuiLine.h @@ -33,7 +33,7 @@ private: FuncCode creationCode() const { return LFUN_INSET_INSERT; } void paramsToDialog(Inset const *); docstring dialogToParams() const; - bool checkWidgets() const; + bool checkWidgets(bool readonly = false) const; //@} }; diff --git a/src/frontends/qt4/GuiNomenclature.cpp b/src/frontends/qt4/GuiNomenclature.cpp index 7415f7f3df..0a52bd1403 100644 --- a/src/frontends/qt4/GuiNomenclature.cpp +++ b/src/frontends/qt4/GuiNomenclature.cpp @@ -70,8 +70,10 @@ bool GuiNomenclature::initialiseParams(std::string const & data) } -bool GuiNomenclature::checkWidgets() const +bool GuiNomenclature::checkWidgets(bool readonly) const { + symbolED->setReadOnly(readonly); + descriptionTE->setReadOnly(readonly); if (!InsetParamsWidget::checkWidgets()) return false; QString const description = descriptionTE->toPlainText(); diff --git a/src/frontends/qt4/GuiNomenclature.h b/src/frontends/qt4/GuiNomenclature.h index dcdd10fab3..9ec016f874 100644 --- a/src/frontends/qt4/GuiNomenclature.h +++ b/src/frontends/qt4/GuiNomenclature.h @@ -35,7 +35,7 @@ private: FuncCode creationCode() const { return LFUN_INSET_INSERT; } void paramsToDialog(Inset const *); docstring dialogToParams() const; - bool checkWidgets() const; + bool checkWidgets(bool readonly = false) const; bool initialiseParams(std::string const &); //@} }; diff --git a/src/frontends/qt4/GuiPrintNomencl.cpp b/src/frontends/qt4/GuiPrintNomencl.cpp index 1e41e3e93b..93e00e9b4c 100644 --- a/src/frontends/qt4/GuiPrintNomencl.cpp +++ b/src/frontends/qt4/GuiPrintNomencl.cpp @@ -101,8 +101,11 @@ docstring GuiPrintNomencl::dialogToParams() const } -bool GuiPrintNomencl::checkWidgets() const +bool GuiPrintNomencl::checkWidgets(bool readonly) const { + valueLE->setReadOnly(readonly); + setWidthCO->setEnabled(!readonly); + unitLC->setEnabled(!readonly); if (!InsetParamsWidget::checkWidgets()) return false; return setWidthCO->itemData( diff --git a/src/frontends/qt4/GuiPrintNomencl.h b/src/frontends/qt4/GuiPrintNomencl.h index 8005f1d506..85897385c9 100644 --- a/src/frontends/qt4/GuiPrintNomencl.h +++ b/src/frontends/qt4/GuiPrintNomencl.h @@ -40,7 +40,7 @@ private: void paramsToDialog(Inset const *); void paramsToDialog(InsetCommandParams const &); docstring dialogToParams() const; - bool checkWidgets() const; + bool checkWidgets(bool readonly = false) const; //@} }; diff --git a/src/frontends/qt4/InsetParamsDialog.cpp b/src/frontends/qt4/InsetParamsDialog.cpp index f76427d68d..9777d5951f 100644 --- a/src/frontends/qt4/InsetParamsDialog.cpp +++ b/src/frontends/qt4/InsetParamsDialog.cpp @@ -166,7 +166,8 @@ void InsetParamsDialog::on_synchronizedCB_stateChanged(int) docstring InsetParamsDialog::checkWidgets(bool immediate) { - bool const widget_ok = d->widget_->checkWidgets(); + bool const read_only = buffer().isReadonly(); + bool const widget_ok = d->widget_->checkWidgets(read_only); Inset const * ins = inset(d->widget_->insetCode()); docstring const argument = d->widget_->dialogToParams(); bool valid_argument = !argument.empty(); @@ -175,14 +176,13 @@ docstring InsetParamsDialog::checkWidgets(bool immediate) FuncCode const code = immediate ? d->widget_->creationCode() : LFUN_INSET_MODIFY; bool const lfun_ok = lyx::getStatus(FuncRequest(code, argument)).enabled(); - bool const read_only = buffer().isReadonly(); okPB->setEnabled(!immediate && widget_ok && !read_only && valid_argument); bool const can_be_restored = !immediate && !read_only && ins && (ins != d->inset_ || d->changed_); restorePB->setEnabled(can_be_restored); applyPB->setEnabled(!immediate && lfun_ok && widget_ok && !read_only && valid_argument); - d->widget_->setEnabled(!read_only); + newPB->setEnabled(widget_ok && !read_only && valid_argument); synchronizedCB->setEnabled(!immediate); return argument; } diff --git a/src/frontends/qt4/InsetParamsWidget.cpp b/src/frontends/qt4/InsetParamsWidget.cpp index 96d39ab37d..91e2e7b595 100644 --- a/src/frontends/qt4/InsetParamsWidget.cpp +++ b/src/frontends/qt4/InsetParamsWidget.cpp @@ -54,7 +54,7 @@ void InsetParamsWidget::addCheckedWidget(QLineEdit * input, QWidget * label) } -bool InsetParamsWidget::checkWidgets() const +bool InsetParamsWidget::checkWidgets(bool readonly) const { bool valid = true; Q_FOREACH(CheckedWidget const & le, checked_widgets_) diff --git a/src/frontends/qt4/InsetParamsWidget.h b/src/frontends/qt4/InsetParamsWidget.h index 00286c9b21..a5316454d2 100644 --- a/src/frontends/qt4/InsetParamsWidget.h +++ b/src/frontends/qt4/InsetParamsWidget.h @@ -70,7 +70,7 @@ public: { return false; } /// \return true if all CheckedWidgets are in a valid state. - virtual bool checkWidgets() const; + virtual bool checkWidgets(bool readonly = false) const; protected: /// Add a widget to the list of all widgets whose validity should -- 2.39.2