]> git.lyx.org Git - lyx.git/commitdiff
GuiIndices: Improve widget disabling and account for read only status
authorJuergen Spitzmueller <spitz@lyx.org>
Wed, 3 Jun 2015 14:54:54 +0000 (16:54 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Wed, 3 Jun 2015 14:54:54 +0000 (16:54 +0200)
(bug #9593)

src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiIndices.cpp
src/frontends/qt4/GuiIndices.h

index bfda9ef07613f6f80e651e1b5e0dc7a5046c6d9f..848f38194f181b3bef42a259d35910e0aa274b17 100644 (file)
@@ -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(
index 8694b98cd74184171128ceb621e881138e5a1176..ff0639b81d8d501f6d25b609afd1512d03ee67a1 100644 (file)
@@ -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();
 }
index a78d07e513053a732aac78b47c998656cab55cb8..efaec8354f7884a9a3f12da939467aa05c2e7519 100644 (file)
@@ -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