From: Juergen Spitzmueller Date: Wed, 3 Jun 2015 14:54:54 +0000 (+0200) Subject: GuiIndices: Improve widget disabling and account for read only status X-Git-Tag: 2.2.0alpha1~563 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=7cce5903906c988f4f3d01002d6ca899e7e00562;p=features.git GuiIndices: Improve widget disabling and account for read only status (bug #9593) --- diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index bfda9ef076..848f38194f 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -2993,7 +2993,7 @@ void GuiDocument::paramsToDialog() biblioChanged_ = false; // indices - indicesModule->update(bp_); + indicesModule->update(bp_, buffer().isReadonly()); // language & quotes int const pos = langModule->languageCO->findData(toqstr( diff --git a/src/frontends/qt4/GuiIndices.cpp b/src/frontends/qt4/GuiIndices.cpp index 8694b98cd7..ff0639b81d 100644 --- a/src/frontends/qt4/GuiIndices.cpp +++ b/src/frontends/qt4/GuiIndices.cpp @@ -44,7 +44,8 @@ namespace frontend { GuiIndices::GuiIndices(QWidget * parent) - : QWidget(parent) + : QWidget(parent), readonly_(false), + use_indices_(false) { setupUi(this); indicesTW->setColumnCount(2); @@ -65,18 +66,39 @@ GuiIndices::GuiIndices(QWidget * parent) newIndexLE->setValidator(new NoNewLineValidator(newIndexLE)); } -void GuiIndices::update(BufferParams const & params) + +void GuiIndices::updateWidgets() +{ + bool const have_sel = + !indicesTW->selectedItems().isEmpty(); + + indexCO->setEnabled(!readonly_); + indexOptionsLE->setEnabled( + indexCO->itemData(indexCO->currentIndex()).toString() != "default"); + indexOptionsLE->setReadOnly(readonly_); + + multipleIndicesCB->setEnabled(!readonly_); + indicesTW->setEnabled(use_indices_); + newIndexLE->setEnabled(use_indices_); + newIndexLE->setReadOnly(readonly_); + newIndexLA->setEnabled(use_indices_); + addIndexPB->setEnabled(use_indices_ && !readonly_ + && !newIndexLE->text().isEmpty()); + availableLA->setEnabled(use_indices_); + removePB->setEnabled(use_indices_ && have_sel && !readonly_); + colorPB->setEnabled(use_indices_ && have_sel && !readonly_); + renamePB->setEnabled(use_indices_ && have_sel && !readonly_); +} + + +void GuiIndices::update(BufferParams const & params, bool const readonly) { + use_indices_ = params.use_indices; + readonly_ = readonly; indiceslist_ = params.indiceslist(); multipleIndicesCB->setChecked(params.use_indices); - bool const state = params.use_indices; - indicesTW->setEnabled(state); - newIndexLE->setEnabled(state); - newIndexLA->setEnabled(state); - addIndexPB->setEnabled(state); - availableLA->setEnabled(state); - removePB->setEnabled(state); - colorPB->setEnabled(state); + + updateWidgets(); string command; string options = @@ -92,8 +114,6 @@ void GuiIndices::update(BufferParams const & params) indexCO->setCurrentIndex(indexCO->findData(toqstr("default"))); indexOptionsLE->clear(); } - indexOptionsLE->setEnabled( - indexCO->currentIndex() != 0); updateView(); } @@ -130,11 +150,8 @@ void GuiIndices::updateView() } } indicesTW->resizeColumnToContents(0); - bool const have_sel = - !indicesTW->selectedItems().isEmpty(); - removePB->setEnabled(have_sel); - renamePB->setEnabled(have_sel); - colorPB->setEnabled(have_sel); + + updateWidgets(); // emit signal changed(); } @@ -156,10 +173,16 @@ void GuiIndices::apply(BufferParams & params) const } -void GuiIndices::on_indexCO_activated(int n) +void GuiIndices::on_indexCO_activated(int) { - indexOptionsLE->setEnabled( - indexCO->itemData(n).toString() != "default"); + updateWidgets(); + changed(); +} + + +void GuiIndices::on_newIndexLE_textChanged(QString) +{ + updateWidgets(); changed(); } @@ -234,11 +257,7 @@ void GuiIndices::on_indicesTW_itemDoubleClicked(QTreeWidgetItem * item, int /*co void GuiIndices::on_indicesTW_itemSelectionChanged() { - bool const have_sel = - !indicesTW->selectedItems().isEmpty(); - removePB->setEnabled(have_sel); - renamePB->setEnabled(have_sel); - colorPB->setEnabled(have_sel); + updateWidgets(); } @@ -248,18 +267,10 @@ void GuiIndices::on_colorPB_clicked() } -void GuiIndices::on_multipleIndicesCB_toggled(bool const state) +void GuiIndices::on_multipleIndicesCB_toggled(bool const b) { - bool const have_sel = - !indicesTW->selectedItems().isEmpty(); - indicesTW->setEnabled(state); - newIndexLE->setEnabled(state); - newIndexLA->setEnabled(state); - addIndexPB->setEnabled(state); - availableLA->setEnabled(state); - removePB->setEnabled(state && have_sel); - colorPB->setEnabled(state && have_sel); - renamePB->setEnabled(state && have_sel); + use_indices_ = b; + updateWidgets(); // emit signal changed(); } diff --git a/src/frontends/qt4/GuiIndices.h b/src/frontends/qt4/GuiIndices.h index a78d07e513..efaec8354f 100644 --- a/src/frontends/qt4/GuiIndices.h +++ b/src/frontends/qt4/GuiIndices.h @@ -33,7 +33,7 @@ class GuiIndices : public QWidget, public Ui::IndicesUi public: GuiIndices(QWidget * parent = 0); - void update(BufferParams const & params); + void update(BufferParams const & params, bool const readonly); void apply(BufferParams & params) const; Q_SIGNALS: @@ -45,6 +45,7 @@ protected: protected Q_SLOTS: void on_indexCO_activated(int n); + void on_newIndexLE_textChanged(QString); void on_indexOptionsLE_textChanged(QString); void on_addIndexPB_pressed(); void on_renamePB_clicked(); @@ -55,8 +56,14 @@ protected Q_SLOTS: void on_multipleIndicesCB_toggled(bool); private: + /// + void updateWidgets(); /// Contains all legal indices for this doc IndicesList indiceslist_; + /// + bool readonly_; + /// + bool use_indices_; }; } // namespace frontend