]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiRef.cpp
some remnaming
[lyx.git] / src / frontends / qt4 / GuiRef.cpp
index b268a3f478c71d1573bf5893a0609bc0bb3fa428..cdb6e59c9440da780fd3add1b48427648fd03c20 100644 (file)
 #include <config.h>
 
 #include "GuiRef.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
 
-#include "ButtonController.h"
+#include "ControlRef.h"
+#include "qt_helpers.h"
 
 #include "insets/InsetRef.h"
 
@@ -35,20 +34,19 @@ using std::string;
 namespace lyx {
 namespace frontend {
 
-/////////////////////////////////////////////////////////////////////
-//
-// GuiRefDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-GuiRefDialog::GuiRefDialog(GuiRef * form)
-       : form_(form)
+GuiRefDialog::GuiRefDialog(LyXView & lv)
+       : GuiDialog(lv, "ref")
 {
        setupUi(this);
+       setController(new ControlRef(*this));
+       setViewTitle(_("Cross-reference"));
 
-       connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
+       sort_ = false;
+       at_ref_ = false;
+
+       connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
+       connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
+       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
        connect(closePB, SIGNAL(clicked()), this, SLOT(reset_dialog()));
        connect(this, SIGNAL(rejected()), this, SLOT(reset_dialog()));
 
@@ -74,28 +72,42 @@ GuiRefDialog::GuiRefDialog(GuiRef * form)
                this, SLOT(updateClicked()));
 
        setFocusProxy(refsLW);
+
+       bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
+       bc().setOK(okPB);
+       bc().setApply(applyPB);
+       bc().setCancel(closePB);
+       bc().addReadOnly(refsLW);
+       bc().addReadOnly(sortCB);
+       bc().addReadOnly(nameED);
+       bc().addReadOnly(referenceED);
+       bc().addReadOnly(typeCO);
+       bc().addReadOnly(bufferCO);
+
+       restored_buffer_ = -1;
 }
 
-void GuiRefDialog::show()
+
+ControlRef & GuiRefDialog::controller()
 {
-       QDialog::show();
+       return static_cast<ControlRef &>(GuiDialog::controller());
 }
 
 
 void GuiRefDialog::changed_adaptor()
 {
-       form_->changed();
+       changed();
 }
 
 
 void GuiRefDialog::gotoClicked()
 {
-       form_->gotoRef();
+       gotoRef();
 }
 
 void GuiRefDialog::selectionChanged()
 {
-       if (form_->readOnly())
+       if (controller().isBufferReadonly())
                return;
 
        QList<QListWidgetItem *> selections = refsLW->selectedItems();
@@ -109,7 +121,7 @@ void GuiRefDialog::selectionChanged()
 
 void GuiRefDialog::refHighlighted(QListWidgetItem * sel)
 {
-       if (form_->readOnly())
+       if (controller().isBufferReadonly())
                return;
 
 /*     int const cur_item = refsLW->currentRow();
@@ -120,19 +132,19 @@ void GuiRefDialog::refHighlighted(QListWidgetItem * sel)
        if (cur_item_selected)
                referenceED->setText(sel->text());
 
-       if (form_->at_ref_)
-               form_->gotoRef();
+       if (at_ref_)
+               gotoRef();
        gotoPB->setEnabled(true);
-       if (form_->typeAllowed())
+       if (typeAllowed())
                typeCO->setEnabled(true);
-       if (form_->nameAllowed())
+       if (nameAllowed())
                nameED->setEnabled(true);
 }
 
 
 void GuiRefDialog::refSelected(QListWidgetItem * sel)
 {
-       if (form_->readOnly())
+       if (controller().isBufferReadonly())
                return;
 
 /*     int const cur_item = refsLW->currentRow();
@@ -143,158 +155,125 @@ void GuiRefDialog::refSelected(QListWidgetItem * sel)
        if (cur_item_selected)
                referenceED->setText(sel->text());
        // <enter> or double click, inserts ref and closes dialog
-       form_->slotOK();
+       slotOK();
 }
 
 
 void GuiRefDialog::sortToggled(bool on)
 {
-       form_->sort_ = on;
-       form_->redoRefs();
+       sort_ = on;
+       redoRefs();
 }
 
 
 void GuiRefDialog::updateClicked()
 {
-       form_->updateRefs();
+       updateRefs();
 }
 
 
-void GuiRefDialog::reset_dialog() {
-       form_->at_ref_ = false;
-       form_->setGotoRef();
+void GuiRefDialog::reset_dialog()
+{
+       at_ref_ = false;
+       setGotoRef();
 }
 
 
 void GuiRefDialog::closeEvent(QCloseEvent * e)
 {
-       form_->slotWMHide();
+       slotClose();
        reset_dialog();
        e->accept();
 }
 
 
-/////////////////////////////////////////////////////////////////////
-//
-// GuiRef
-//
-/////////////////////////////////////////////////////////////////////
-
-
-GuiRef::GuiRef(Dialog & parent)
-       : GuiView<GuiRefDialog>(parent, _("Cross-reference")),
-       sort_(false), at_ref_(false)
-{
-}
-
-
-void GuiRef::build_dialog()
-{
-       dialog_.reset(new GuiRefDialog(this));
-
-       bcview().setOK(dialog_->okPB);
-       bcview().setApply(dialog_->applyPB);
-       bcview().setCancel(dialog_->closePB);
-       bcview().addReadOnly(dialog_->refsLW);
-       bcview().addReadOnly(dialog_->sortCB);
-       bcview().addReadOnly(dialog_->nameED);
-       bcview().addReadOnly(dialog_->referenceED);
-       bcview().addReadOnly(dialog_->typeCO);
-       bcview().addReadOnly(dialog_->bufferCO);
-
-       restored_buffer_ = -1;
-}
-
-
-void GuiRef::update_contents()
+void GuiRefDialog::updateContents()
 {
        InsetCommandParams const & params = controller().params();
 
-       int orig_type = dialog_->typeCO->currentIndex();
+       int orig_type = typeCO->currentIndex();
 
-       dialog_->referenceED->setText(toqstr(params["reference"]));
+       referenceED->setText(toqstr(params["reference"]));
 
-       dialog_->nameED->setText(toqstr(params["name"]));
-       dialog_->nameED->setReadOnly(!nameAllowed() && !readOnly());
+       nameED->setText(toqstr(params["name"]));
+       nameED->setReadOnly(!nameAllowed() && !controller().isBufferReadonly());
 
        // restore type settings for new insets
        if (params["reference"].empty())
-               dialog_->typeCO->setCurrentIndex(orig_type);
+               typeCO->setCurrentIndex(orig_type);
        else
-               dialog_->typeCO->setCurrentIndex(InsetRef::getType(params.getCmdName()));
-       dialog_->typeCO->setEnabled(typeAllowed() && !readOnly());
+               typeCO->setCurrentIndex(InsetRef::getType(params.getCmdName()));
+       typeCO->setEnabled(typeAllowed() && !controller().isBufferReadonly());
        if (!typeAllowed())
-               dialog_->typeCO->setCurrentIndex(0);
+               typeCO->setCurrentIndex(0);
 
-       dialog_->sortCB->setChecked(sort_);
+       sortCB->setChecked(sort_);
 
        // insert buffer list
-       dialog_->bufferCO->clear();
+       bufferCO->clear();
        vector<string> const buffers = controller().getBufferList();
        for (vector<string>::const_iterator it = buffers.begin();
                it != buffers.end(); ++it) {
-               dialog_->bufferCO->addItem(toqstr(*it));
+               bufferCO->addItem(toqstr(*it));
        }
        // restore the buffer combo setting for new insets
        if (params["reference"].empty() && restored_buffer_ != -1
-       && restored_buffer_ < dialog_->bufferCO->count())
-               dialog_->bufferCO->setCurrentIndex(restored_buffer_);
+       && restored_buffer_ < bufferCO->count())
+               bufferCO->setCurrentIndex(restored_buffer_);
        else
-               dialog_->bufferCO->setCurrentIndex(controller().getBufferNum());
+               bufferCO->setCurrentIndex(controller().getBufferNum());
 
        updateRefs();
-       bc().valid(false);
+       bc().setValid(false);
 }
 
 
-void GuiRef::apply()
+void GuiRefDialog::applyView()
 {
        InsetCommandParams & params = controller().params();
 
-       last_reference_ = dialog_->referenceED->text();
+       last_reference_ = referenceED->text();
 
-       params.setCmdName(InsetRef::getName(dialog_->typeCO->currentIndex()));
+       params.setCmdName(InsetRef::getName(typeCO->currentIndex()));
        params["reference"] = qstring_to_ucs4(last_reference_);
-       params["name"] = qstring_to_ucs4(dialog_->nameED->text());
+       params["name"] = qstring_to_ucs4(nameED->text());
 
-       restored_buffer_ = dialog_->bufferCO->currentIndex();
+       restored_buffer_ = bufferCO->currentIndex();
 }
 
 
-bool GuiRef::nameAllowed()
+bool GuiRefDialog::nameAllowed()
 {
-       Kernel::DocType const doc_type = kernel().docType();
-       return doc_type != Kernel::LATEX &&
-               doc_type != Kernel::LITERATE;
+       KernelDocType const doc_type = controller().docType();
+       return doc_type != LATEX && doc_type != LITERATE;
 }
 
 
-bool GuiRef::typeAllowed()
+bool GuiRefDialog::typeAllowed()
 {
-       Kernel::DocType const doc_type = kernel().docType();
-       return doc_type != Kernel::DOCBOOK;
+       return controller().docType() != DOCBOOK;
 }
 
 
-void GuiRef::setGoBack()
+void GuiRefDialog::setGoBack()
 {
-       dialog_->gotoPB->setText(qt_("&Go Back"));
-       dialog_->gotoPB->setToolTip("");
-       dialog_->gotoPB->setToolTip(qt_("Jump back"));
+       gotoPB->setText(qt_("&Go Back"));
+       gotoPB->setToolTip("");
+       gotoPB->setToolTip(qt_("Jump back"));
 }
 
 
-void GuiRef::setGotoRef()
+void GuiRefDialog::setGotoRef()
 {
-       dialog_->gotoPB->setText(qt_("&Go to Label"));
-       dialog_->gotoPB->setToolTip("");
-       dialog_->gotoPB->setToolTip(qt_("Jump to label"));
+       gotoPB->setText(qt_("&Go to Label"));
+       gotoPB->setToolTip("");
+       gotoPB->setToolTip(qt_("Jump to label"));
 }
 
 
-void GuiRef::gotoRef()
+void GuiRefDialog::gotoRef()
 {
-       string ref(fromqstr(dialog_->referenceED->text()));
+       string ref = fromqstr(referenceED->text());
 
        if (at_ref_) {
                // go back
@@ -309,29 +288,29 @@ void GuiRef::gotoRef()
 }
 
 
-void GuiRef::redoRefs()
+void GuiRefDialog::redoRefs()
 {
        // Prevent these widgets from emitting any signals whilst
        // we modify their state.
-       dialog_->refsLW->blockSignals(true);
-       dialog_->referenceED->blockSignals(true);
-       dialog_->refsLW->setUpdatesEnabled(false);
+       refsLW->blockSignals(true);
+       referenceED->blockSignals(true);
+       refsLW->setUpdatesEnabled(false);
 
-       dialog_->refsLW->clear();
+       refsLW->clear();
 
        // need this because Qt will send a highlight() here for
        // the first item inserted
-       QString const oldSelection(dialog_->referenceED->text());
+       QString const oldSelection(referenceED->text());
 
        for (std::vector<docstring>::const_iterator iter = refs_.begin();
                iter != refs_.end(); ++iter) {
-               dialog_->refsLW->addItem(toqstr(*iter));
+               refsLW->addItem(toqstr(*iter));
        }
 
        if (sort_)
-               dialog_->refsLW->sortItems();
+               refsLW->sortItems();
 
-       dialog_->referenceED->setText(oldSelection);
+       referenceED->setText(oldSelection);
 
        // restore the last selection or, for new insets, highlight
        // the previous selection
@@ -339,13 +318,13 @@ void GuiRef::redoRefs()
                bool const newInset = oldSelection.isEmpty();
                QString textToFind = newInset ? last_reference_ : oldSelection;
                bool foundItem = false;
-               for (int i = 0; !foundItem && i < dialog_->refsLW->count(); ++i) {
-                       QListWidgetItem * item = dialog_->refsLW->item(i);
+               for (int i = 0; !foundItem && i < refsLW->count(); ++i) {
+                       QListWidgetItem * item = refsLW->item(i);
                        if (textToFind == item->text()) {
-                               dialog_->refsLW->setCurrentItem(item);
-                               dialog_->refsLW->setItemSelected(item, !newInset);
+                               refsLW->setCurrentItem(item);
+                               refsLW->setItemSelected(item, !newInset);
                                //Make sure selected item is visible
-                               dialog_->refsLW->scrollToItem(item);
+                               refsLW->scrollToItem(item);
                                foundItem = true;
                        }
                }
@@ -353,29 +332,30 @@ void GuiRef::redoRefs()
                        last_reference_ = textToFind;
                else last_reference_ = "";
        }
-       dialog_->refsLW->setUpdatesEnabled(true);
-       dialog_->refsLW->update();
+       refsLW->setUpdatesEnabled(true);
+       refsLW->update();
 
        // Re-activate the emission of signals by these widgets.
-       dialog_->refsLW->blockSignals(false);
-       dialog_->referenceED->blockSignals(false);
+       refsLW->blockSignals(false);
+       referenceED->blockSignals(false);
 }
 
 
-void GuiRef::updateRefs()
+void GuiRefDialog::updateRefs()
 {
        refs_.clear();
-       string const name = controller().getBufferName(dialog_->bufferCO->currentIndex());
+       string const name = controller().getBufferName(bufferCO->currentIndex());
        refs_ = controller().getLabelList(name);
-       dialog_->sortCB->setEnabled(!refs_.empty());
-       dialog_->refsLW->setEnabled(!refs_.empty());
-       dialog_->gotoPB->setEnabled(!refs_.empty());
+       sortCB->setEnabled(!refs_.empty());
+       refsLW->setEnabled(!refs_.empty());
+       gotoPB->setEnabled(!refs_.empty());
        redoRefs();
 }
 
-bool GuiRef::isValid()
+
+bool GuiRefDialog::isValid()
 {
-       return !dialog_->referenceED->text().isEmpty();
+       return !referenceED->text().isEmpty();
 }
 
 } // namespace frontend