From 20f2690c6dd6e0851c0a23840e5eb4ef7f761f65 Mon Sep 17 00:00:00 2001 From: John Levon Date: Sun, 26 Aug 2001 00:29:39 +0000 Subject: [PATCH] ref dialog, more updates (BC stuff should now be OK along with the coming controllers/ patch) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2586 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 17 ++ src/frontends/qt2/Dialogs.C | 5 +- src/frontends/qt2/QAbout.C | 2 +- src/frontends/qt2/QAbout.h | 2 +- src/frontends/qt2/QCitation.C | 4 +- src/frontends/qt2/QCitation.h | 2 +- src/frontends/qt2/QCitationDialog.C | 6 +- src/frontends/qt2/QDocument.C | 2 +- src/frontends/qt2/QDocument.h | 2 +- src/frontends/qt2/QIndex.C | 10 +- src/frontends/qt2/QIndex.h | 2 +- src/frontends/qt2/QRef.C | 331 +++++++++------------------- src/frontends/qt2/QRef.h | 118 ++++------ src/frontends/qt2/QRefDialog.C | 87 ++++---- src/frontends/qt2/QRefDialog.h | 17 +- src/frontends/qt2/QURL.C | 2 +- src/frontends/qt2/QURL.h | 2 +- src/frontends/qt2/Qt2BC.C | 3 - src/frontends/qt2/Qt2Base.C | 2 - src/frontends/qt2/Qt2Base.h | 34 ++- src/frontends/qt2/README | 8 +- src/frontends/qt2/ui/QRefDialog.ui | 89 +++++--- 22 files changed, 326 insertions(+), 421 deletions(-) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index fc88887c01..db1ff7b015 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,20 @@ +2001-08-26 John Levon + + * Dialogs.C: + * QRef.[Ch]: + * ui/QRefDialog.ui: add Ref dialog back + + * QAbout.[Ch]: + * QCitation.[Ch]: + * QDocument.[Ch]: + * QIndex.[Ch]: + * QURL.[Ch]: + * Qt2Base.h: protect build() with updating_ too + + * QCitationDialog.C: use Qt2Base::readOnly + + * README: update + 2001-08-25 John Levon * Dialogs.C: add URL diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index 9aeb6129f0..dc5928e6d1 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -15,15 +15,16 @@ #include "QAboutDialog.h" #include "QCitationDialog.h" #include "QIndexDialog.h" +#include "QRefDialog.h" #include "QURLDialog.h" -// the controller interface #include "QAbout.h" #include "QCharacter.h" #include "QCitation.h" #include "QIndex.h" #include "QParagraph.h" #include "QPrint.h" +#include "QRef.h" #include "QSearch.h" #include "QSplash.h" #include "QTabularCreate.h" @@ -45,6 +46,7 @@ #include "controllers/ControlAboutlyx.h" #include "controllers/ControlCitation.h" #include "controllers/ControlIndex.h" +#include "controllers/ControlRef.h" #include "controllers/ControlSplash.h" #include "controllers/ControlUrl.h" #if 0 @@ -90,6 +92,7 @@ Dialogs::Dialogs(LyXView * lv) add(new GUICitation(*lv, *this)); add(new GUIAboutlyx(*lv, *this)); add(new GUIIndex(*lv, *this)); + add(new GUIRef(*lv, *this)); add(new GUIUrl(*lv, *this)); // reduce the number of connections needed in diff --git a/src/frontends/qt2/QAbout.C b/src/frontends/qt2/QAbout.C index f5c2432b1d..e4a296ca3e 100644 --- a/src/frontends/qt2/QAbout.C +++ b/src/frontends/qt2/QAbout.C @@ -32,7 +32,7 @@ QAbout::QAbout(ControlAboutlyx & c) } -void QAbout::build() +void QAbout::build_dialog() { dialog_.reset(new QAboutDialog()); connect(dialog_.get()->closePB, SIGNAL(clicked()), diff --git a/src/frontends/qt2/QAbout.h b/src/frontends/qt2/QAbout.h index eafe752b6c..525038b683 100644 --- a/src/frontends/qt2/QAbout.h +++ b/src/frontends/qt2/QAbout.h @@ -30,7 +30,7 @@ private: /// not needed virtual void update_contents() {} // build the dialog - virtual void build(); + virtual void build_dialog(); }; #endif // FORMABOUT_H diff --git a/src/frontends/qt2/QCitation.C b/src/frontends/qt2/QCitation.C index cf15eba6d9..0d1770deda 100644 --- a/src/frontends/qt2/QCitation.C +++ b/src/frontends/qt2/QCitation.C @@ -65,13 +65,13 @@ void QCitation::hide() } -void QCitation::build() +void QCitation::build_dialog() { dialog_.reset(new QCitationDialog(this)); dialog_->searchTypeCB->setChecked(false); dialog_->searchCaseCB->setChecked(false); - + // Manage the ok, apply, restore and cancel/close buttons bc().setOK(dialog_->okPB); bc().setApply(dialog_->applyPB); diff --git a/src/frontends/qt2/QCitation.h b/src/frontends/qt2/QCitation.h index 4713784fb8..248337f714 100644 --- a/src/frontends/qt2/QCitation.h +++ b/src/frontends/qt2/QCitation.h @@ -42,7 +42,7 @@ private: /// Set the Params variable for the Controller. virtual void apply(); /// Build the dialog. - virtual void build(); + virtual void build_dialog(); /// Hide the dialog. virtual void hide(); /// Update dialog before/whilst showing it. diff --git a/src/frontends/qt2/QCitationDialog.C b/src/frontends/qt2/QCitationDialog.C index 3e1a15b2a8..1aefb79d0d 100644 --- a/src/frontends/qt2/QCitationDialog.C +++ b/src/frontends/qt2/QCitationDialog.C @@ -62,7 +62,7 @@ void QCitationDialog::slotBibSelected(int sel) { slotBibHighlighted(sel); - if (form_->controller().isReadonly()) + if (form_->readOnly()) return; slotAddClicked(); @@ -98,7 +98,7 @@ void QCitationDialog::slotBibHighlighted(int sel) citeLB->setTopItem(n); } - if (!form_->controller().isReadonly()) { + if (!form_->readOnly()) { if (cit != form_->citekeys.end()) { form_->setBibButtons(QCitation::OFF); form_->setCiteButtons(QCitation::ON); @@ -119,7 +119,7 @@ void QCitationDialog::slotCiteHighlighted(int sel) return; } - if (!form_->controller().isReadonly()) { + if (!form_->readOnly()) { form_->setBibButtons(QCitation::OFF); form_->setCiteButtons(QCitation::ON); } diff --git a/src/frontends/qt2/QDocument.C b/src/frontends/qt2/QDocument.C index aeea3dc206..1bf777f304 100644 --- a/src/frontends/qt2/QDocument.C +++ b/src/frontends/qt2/QDocument.C @@ -49,7 +49,7 @@ QDocument::QDocument(ControlDocument & c) #endif -void QDocument::build() +void QDocument::build_dialog() { int n; diff --git a/src/frontends/qt2/QDocument.h b/src/frontends/qt2/QDocument.h index f8aa0265a7..c58f4a5b89 100644 --- a/src/frontends/qt2/QDocument.h +++ b/src/frontends/qt2/QDocument.h @@ -71,7 +71,7 @@ private: /// Pointer to the actual instantiation of the ButtonController. virtual Qt2BC & bc(); /// Build the dialog - virtual void build(); + virtual void build_dialog(); // /// Filter the inputs // virtual bool input( FL_OBJECT *, long ); /// Update the dialog. diff --git a/src/frontends/qt2/QIndex.C b/src/frontends/qt2/QIndex.C index e684e77225..d99e60407f 100644 --- a/src/frontends/qt2/QIndex.C +++ b/src/frontends/qt2/QIndex.C @@ -10,15 +10,9 @@ #include "QIndexDialog.h" #include "ControlIndex.h" -#include "QtLyXView.h" -#include "BufferView.h" - -#include "Dialogs.h" -#include "Qt2BC.h" #include "QIndex.h" +#include "Qt2BC.h" #include "gettext.h" -#include "buffer.h" -#include "lyxfunc.h" #include #include @@ -31,7 +25,7 @@ QIndex::QIndex(ControlIndex & c) } -void QIndex::build() +void QIndex::build_dialog() { dialog_.reset(new QIndexDialog(this)); diff --git a/src/frontends/qt2/QIndex.h b/src/frontends/qt2/QIndex.h index d77b82bcf2..44d8c965e5 100644 --- a/src/frontends/qt2/QIndex.h +++ b/src/frontends/qt2/QIndex.h @@ -33,7 +33,7 @@ private: /// update virtual void update_contents(); /// build the dialog - virtual void build(); + virtual void build_dialog(); }; #endif // QINDEX_H diff --git a/src/frontends/qt2/QRef.C b/src/frontends/qt2/QRef.C index 2d04c8fc86..3c9deea407 100644 --- a/src/frontends/qt2/QRef.C +++ b/src/frontends/qt2/QRef.C @@ -8,135 +8,132 @@ #include +#include "support/lstrings.h" + #include "QRefDialog.h" - -#include "QtLyXView.h" -#include "BufferView.h" -#include "Dialogs.h" +#include "ControlRef.h" #include "QRef.h" +#include "Qt2BC.h" #include "gettext.h" -#include "buffer.h" -#include "lyxfunc.h" -#include "debug.h" +#include "insets/insetref.h" -#include #include +#include #include #include -#include +#include +#include using std::endl; -QRef::QRef(LyXView *v, Dialogs *d) - : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0), - sort(0), gotowhere(GOTOREF), type(REF), refs(0) +typedef Qt2CB > base_class; + +QRef::QRef(ControlRef & c) + : base_class(c, _("Cross Reference")), + sort_(false), at_ref_(false) { - // let the dialog be shown - // This is a permanent connection so we won't bother - // storing a copy because we won't be disconnecting. - d->showRef.connect(slot(this, &QRef::showRef)); - d->createRef.connect(slot(this, &QRef::createRef)); } -QRef::~QRef() +void QRef::build_dialog() { - delete dialog_; -} + dialog_.reset(new QRefDialog(this)); - -void QRef::showRef(InsetCommand * const inset) -{ - // FIXME: when could inset be 0 here ? - if (inset==0) - return; - - inset_ = inset; - readonly = lv_->buffer()->isReadonly(); - //ih_ = inset_->hide.connect(slot(this,&QRef::hide)); - params = inset->params(); - - show(); -} - - -void QRef::createRef(string const & arg) -{ - if (inset_) - close(); - - readonly = lv_->buffer()->isReadonly(); - params.setFromString(arg); - show(); -} - - -void QRef::select(const char *text) -{ - highlight(text); - goto_ref(); + bc().setOK(dialog_->okPB); + bc().setCancel(dialog_->closePB); + bc().addReadOnly(dialog_->refsLB); + bc().addReadOnly(dialog_->sortCB); + bc().addReadOnly(dialog_->nameED); + bc().addReadOnly(dialog_->referenceED); + bc().addReadOnly(dialog_->typeCO); } -void QRef::highlight(const char *text) +void QRef::update_contents() { - if (gotowhere==GOTOBACK) - goto_ref(); + dialog_->referenceED->setText(controller().params().getContents().c_str()); + dialog_->nameED->setText(controller().params().getOptions().c_str()); - dialog_->gotoPB->setEnabled(true); - if (!readonly) { - dialog_->typeCO->setEnabled(true); - dialog_->referenceED->setText(text); - dialog_->okPB->setEnabled(true); + dialog_->typeCO->setCurrentItem(InsetRef::getType(controller().params().getCmdName())); + + dialog_->nameED->setReadOnly(!nameAllowed() && !readOnly()); + + dialog_->typeCO->setEnabled(!typeAllowed() && !readOnly()); + if (!typeAllowed()) + dialog_->typeCO->setCurrentItem(0); + + dialog_->sortCB->setChecked(sort_); + + updateRefs(); +} + + +void QRef::apply() +{ + controller().params().setCmdName(InsetRef::getName(dialog_->typeCO->currentItem())); + controller().params().setContents(dialog_->referenceED->text().latin1()); + controller().params().setOptions(dialog_->nameED->text().latin1()); +} + + +bool QRef::nameAllowed() +{ + return controller().docType() != ControlRef::LATEX && + controller().docType() != ControlRef::LITERATE; +} + + +bool QRef::typeAllowed() +{ + return controller().docType() == ControlRef::LINUXDOC || + controller().docType() == ControlRef::DOCBOOK; +} + + +void QRef::setGoBack() +{ + dialog_->gotoPB->setText(_("&Go back")); + QToolTip::remove(dialog_->gotoPB); + QToolTip::add(dialog_->gotoPB, _("Go back")); +} + + +void QRef::setGotoRef() +{ + dialog_->gotoPB->setText(_("&Go to reference")); + QToolTip::remove(dialog_->gotoPB); + QToolTip::add(dialog_->gotoPB, _("Go to reference")); +} + + +void QRef::gotoRef() +{ + string ref(dialog_->referenceED->text()); + + if (at_ref_) { + // go back + setGotoRef(); + controller().gotoBookmark(); + } else { + // go to the ref + setGoBack(); + controller().gotoRef(ref); } + at_ref_ = !at_ref_; } -void QRef::set_sort(bool on) +void QRef::redoRefs() { - if (on!=sort) { - sort=on; - dialog_->refsLB->clear(); - updateRefs(); - } -} - - -void QRef::goto_ref() -{ - switch (gotowhere) { - case GOTOREF: - lv_->getLyXFunc()->dispatch(LFUN_REF_GOTO, dialog_->referenceED->text().latin1()); - gotowhere=GOTOBACK; - dialog_->gotoPB->setText(_("&Go back")); - break; - case GOTOBACK: - //FIXME lv_->getLyXFunc()->dispatch(LFUN_REF_BACK); - gotowhere=GOTOREF; - dialog_->gotoPB->setText(_("&Goto reference")); - break; - } -} - - -void QRef::updateRefs() -{ - // list will be re-done, should go back if necessary - if (gotowhere==GOTOBACK) { - //FIXME lv_->getLyXFunc()->dispatch(LFUN_REF_BACK); - gotowhere = GOTOREF; - dialog_->gotoPB->setText(_("&Goto reference")); - } - dialog_->refsLB->setAutoUpdate(false); // need this because Qt will send a highlight() here for // the first item inserted string tmp(dialog_->referenceED->text()); - for (std::vector< string >::const_iterator iter = refs.begin(); - iter != refs.end(); ++iter) { - if (sort) + for (std::vector::const_iterator iter = refs_.begin(); + iter != refs_.end(); ++iter) { + if (sort_) dialog_->refsLB->inSort(iter->c_str()); else dialog_->refsLB->insertItem(iter->c_str()); @@ -145,7 +142,7 @@ void QRef::updateRefs() dialog_->referenceED->setText(tmp.c_str()); for (unsigned int i = 0; i < dialog_->refsLB->count(); ++i) { - if (!strcmp(dialog_->referenceED->text(),dialog_->refsLB->text(i))) + if (!compare(tmp.c_str(), dialog_->refsLB->text(i).latin1())) dialog_->refsLB->setCurrentItem(i); } @@ -153,135 +150,15 @@ void QRef::updateRefs() dialog_->refsLB->update(); } - -void QRef::do_ref_update() + +void QRef::updateRefs() { - refs.clear(); + refs_.clear(); + if (at_ref_) + gotoRef(); dialog_->refsLB->clear(); - refs = lv_->buffer()->getLabelList(); - if (!refs.empty()) - dialog_->sortCB->setEnabled(true); - updateRefs(); -} - - -void QRef::update() -{ - // FIXME: needs updating - - dialog_->referenceED->setText(params.getContents().c_str()); - dialog_->nameED->setText(params.getOptions().c_str()); - - if (params.getCmdName()=="pageref") { - type = PAGEREF; - dialog_->typeCO->setCurrentItem(1); - } else if (params.getCmdName()=="vref") { - type = VREF; - dialog_->typeCO->setCurrentItem(2); - } else if (params.getCmdName()=="vpageref") { - type = VPAGEREF; - dialog_->typeCO->setCurrentItem(3); - } else if (params.getCmdName()=="prettyref") { - type = PRETTYREF; - dialog_->typeCO->setCurrentItem(4); - } else { - type = REF; - dialog_->typeCO->setCurrentItem(0); - } - - dialog_->gotoPB->setText(_("&Goto reference")); - - gotowhere = GOTOREF; - - dialog_->sortCB->setChecked(sort); - - do_ref_update(); - - dialog_->gotoPB->setEnabled(params.getContents()!=""); - dialog_->okPB->setEnabled(params.getContents()!=""); - - dialog_->typeCO->setEnabled(!readonly); - dialog_->sortCB->setEnabled(!readonly); - dialog_->refsLB->setEnabled(!readonly); - dialog_->okPB->setEnabled(!readonly); - dialog_->updatePB->setEnabled(!readonly); - if (readonly) - dialog_->cancelPB->setText(_("&Close")); - else - dialog_->cancelPB->setText(_("&Cancel")); -} - - -void QRef::apply() -{ - if (readonly) - return; - - if (!lv_->view()->available()) - return; - - switch (dialog_->typeCO->currentItem()) { - case 0: - params.setCmdName("ref"); - break; - case 1: - params.setCmdName("pageref"); - break; - case 2: - params.setCmdName("vref"); - break; - case 3: - params.setCmdName("vpageref"); - break; - case 4: - params.setCmdName("prettyref"); - break; - default: - lyxerr[Debug::GUI] << "Unknown Ref Type" << endl; - } - - params.setContents(dialog_->referenceED->text().latin1()); - params.setOptions(dialog_->nameED->text().latin1()); - - if (inset_ != 0) { - if (params != inset_->params()) { - inset_->setParams(params); - lv_->view()->updateInset(inset_, true); - } - } else - lv_->getLyXFunc()->dispatch(LFUN_REF_INSERT, params.getAsString().c_str()); -} - - -void QRef::show() -{ - if (!dialog_) - dialog_ = new QRefDialog(this, 0, _("LyX: Cross Reference"), false); - - if (!dialog_->isVisible()) { - h_ = d_->hideBufferDependent.connect(slot(this, &QRef::hide)); - //u_ = d_->updateBufferDependent.connect(slot(this, &QRef::update)); - } - - dialog_->raise(); - dialog_->setActiveWindow(); - - update(); - dialog_->show(); -} - - -void QRef::close() -{ - h_.disconnect(); - u_.disconnect(); - ih_.disconnect(); - inset_ = 0; -} - - -void QRef::hide() -{ - dialog_->hide(); - close(); + refs_ = controller().getLabelList(); + dialog_->sortCB->setEnabled(!refs_.empty()); + dialog_->refsLB->setEnabled(!refs_.empty()); + redoRefs(); } diff --git a/src/frontends/qt2/QRef.h b/src/frontends/qt2/QRef.h index 60116d7c57..59f35802ab 100644 --- a/src/frontends/qt2/QRef.h +++ b/src/frontends/qt2/QRef.h @@ -1,104 +1,68 @@ -// -*- C++ -*- /** * \file QRef.h * Copyright 2001 the LyX Team * Read the file COPYING * - * \author John Levon - * \author Kalle Dalheimer + * \author John Levon */ #ifndef QREF_H #define QREF_H -#include "DialogBase.h" +#include +#include #include "LString.h" -#include "boost/utility.hpp" -#include "insets/insetcommand.h" + +#include "Qt2Base.h" -class Dialogs; -class LyXView; +class ControlRef; class QRefDialog; -class QRef : public DialogBase { +class QRef : + public Qt2CB > +{ + friend class QRefDialog; + public: - QRef(LyXView *, Dialogs *); - ~QRef(); + QRef(ControlRef & c); - /// double-click a ref - void select(const char *); - /// highlight a ref - void highlight(const char *); - /// set sort - void set_sort(bool); - /// goto a ref (or back) - void goto_ref(); +private: + /// apply changes + virtual void apply(); + /// build dialog + virtual void build_dialog(); /// update dialog - void update(); - /// update just the refs - void do_ref_update(); - /// Apply changes - void apply(); - /// close the connections - void close(); - -private: - enum Type { - REF, PAGEREF, VREF, VPAGEREF, PRETTYREF - }; + virtual void update_contents(); - enum GotoType { - GOTOREF, GOTOBACK - }; - - /// Create the dialog if necessary, update it and display it. - void show(); - /// Hide the dialog. - void hide(); - - /// create a Reference inset - void createRef(string const &); - /// edit a Reference inset - void showRef(InsetCommand * const); - - /// update the keys list - void updateRefs(void); - - /// Real GUI implementation. - QRefDialog * dialog_; + /// is name allowed for this ? + bool nameAllowed(); - /// the LyXView we belong to - LyXView * lv_; + /// is type allowed for this ? + bool typeAllowed(); - /** Which Dialogs do we belong to? - Used so we can get at the signals we have to connect to. - */ - Dialogs * d_; - /// pointer to the inset if any - InsetCommand * inset_; - /// insets params - InsetCommandParams params; - /// is the inset we are reading from a readonly buffer ? - bool readonly; - - /// Hide connection. - SigC::Connection h_; - /// Update connection. - SigC::Connection u_; - /// Inset hide connection. - SigC::Connection ih_; + /// go to current reference + void gotoRef(); - /// to sort or not to sort - bool sort; + /// set go back button + void setGoBack(); - /// where to go - GotoType gotowhere; + /// set goto ref button + void setGotoRef(); - /// current type - Type type; + /// re-enter references + void redoRefs(); - /// available references - std::vector< string > refs; + /// update references + void updateRefs(); + + /// sort or not persistent state + bool sort_; + + /// at a reference ? + bool at_ref_; + + /// the references + std::vector refs_; }; #endif // QREF_H diff --git a/src/frontends/qt2/QRefDialog.C b/src/frontends/qt2/QRefDialog.C index 050c2b826b..4530a3ea0f 100644 --- a/src/frontends/qt2/QRefDialog.C +++ b/src/frontends/qt2/QRefDialog.C @@ -4,72 +4,83 @@ * Read the file COPYING * * \author Kalle Dalheimer + * \author John Levon */ +#include + +#include +#include +#include +#include + #include "QRefDialog.h" +#include "ControlRef.h" #include "Dialogs.h" #include "QRef.h" +#include "debug.h" -QRefDialog::QRefDialog(QRef * form, QWidget * parent, const char * name, bool modal, WFlags fl) - : QRefDialogBase(parent, name, modal, fl), +QRefDialog::QRefDialog(QRef * form) + : QRefDialogBase(0, 0, false, 0), form_(form) { + connect(okPB, SIGNAL(clicked()), + form_, SLOT(slotOK())); + connect(closePB, SIGNAL(clicked()), + form_, SLOT(slotClose())); } -QRefDialog::~QRefDialog() +void QRefDialog::changed_adaptor() { + form_->changed(); +} + + +void QRefDialog::gotoClicked() +{ + form_->gotoRef(); +} + + +void QRefDialog::refHighlighted(const QString & sel) +{ + if (form_->readOnly()) + return; + + referenceED->setText(sel); + if (form_->at_ref_) + form_->gotoRef(); + gotoPB->setEnabled(true); + if (form_->typeAllowed()) + typeCO->setEnabled(true); + if (form_->nameAllowed()) + nameED->setEnabled(true); } -void QRefDialog::apply_adaptor() +void QRefDialog::refSelected(const QString & sel) { - form_->apply(); - form_->close(); - hide(); + form_->gotoRef(); } -void QRefDialog::goto_adaptor() +void QRefDialog::sortToggled(bool on) { - form_->goto_ref(); + form_->sort_ = on; + refsLB->clear(); + form_->redoRefs(); } -void QRefDialog::highlight_adaptor(const QString & sel) +void QRefDialog::updateClicked() { - form_->highlight(sel); + form_->updateRefs(); } -void QRefDialog::close_adaptor() -{ - form_->close(); - hide(); -} - - -void QRefDialog::select_adaptor(const QString & sel) -{ - form_->select(sel); -} - - -void QRefDialog::sort_adaptor(bool sort) -{ - form_->set_sort(sort); -} - - -void QRefDialog::update_adaptor() -{ - form_->do_ref_update(); -} - - - void QRefDialog::closeEvent(QCloseEvent * e) { - form_->close(); + form_->slotWMHide(); e->accept(); } diff --git a/src/frontends/qt2/QRefDialog.h b/src/frontends/qt2/QRefDialog.h index cdd1eb8e21..5813579393 100644 --- a/src/frontends/qt2/QRefDialog.h +++ b/src/frontends/qt2/QRefDialog.h @@ -4,6 +4,7 @@ * Read the file COPYING * * \author Kalle Dalheimer + * \author John Levon */ #ifndef QREFDIALOG_H @@ -19,17 +20,15 @@ class QRefDialog : public QRefDialogBase { Q_OBJECT public: - QRefDialog(QRef * form, QWidget * parent = 0, const char * name = 0, bool modal = FALSE, WFlags fl = 0); - ~QRefDialog(); + QRefDialog(QRef * form); public slots: - void apply_adaptor(); - void goto_adaptor(); - void highlight_adaptor(const QString &); - void close_adaptor(); - void select_adaptor(const QString &); - void sort_adaptor(bool); - void update_adaptor(); + void changed_adaptor(); + void gotoClicked(); + void refHighlighted(const QString &); + void refSelected(const QString &); + void sortToggled(bool); + void updateClicked(); protected: void closeEvent(QCloseEvent * e); diff --git a/src/frontends/qt2/QURL.C b/src/frontends/qt2/QURL.C index 45c8eb4d95..d633baad36 100644 --- a/src/frontends/qt2/QURL.C +++ b/src/frontends/qt2/QURL.C @@ -27,7 +27,7 @@ QURL::QURL(ControlUrl & c) } -void QURL::build() +void QURL::build_dialog() { dialog_.reset(new QURLDialog(this)); diff --git a/src/frontends/qt2/QURL.h b/src/frontends/qt2/QURL.h index af6ab0727e..70d3339dc6 100644 --- a/src/frontends/qt2/QURL.h +++ b/src/frontends/qt2/QURL.h @@ -28,7 +28,7 @@ private: /// apply dialog virtual void apply(); /// build dialog - virtual void build(); + virtual void build_dialog(); /// update dialog virtual void update_contents(); }; diff --git a/src/frontends/qt2/Qt2BC.C b/src/frontends/qt2/Qt2BC.C index 46b7b47524..437be48308 100644 --- a/src/frontends/qt2/Qt2BC.C +++ b/src/frontends/qt2/Qt2BC.C @@ -35,9 +35,6 @@ void Qt2BC::setButtonEnabled(QButton * obj, bool enabled) void Qt2BC::setWidgetEnabled(QWidget * obj, bool enabled) { - lyxerr << "Qt2BC: setting " - << obj << " to " << enabled << std::endl; - // yuck, rtti, but the user comes first if (obj->inherits("QLineEdit")) { QLineEdit * le(static_cast(obj)); diff --git a/src/frontends/qt2/Qt2Base.C b/src/frontends/qt2/Qt2Base.C index 71bf92afd5..5d23347d99 100644 --- a/src/frontends/qt2/Qt2Base.C +++ b/src/frontends/qt2/Qt2Base.C @@ -65,8 +65,6 @@ bool Qt2Base::isValid() void Qt2Base::changed() { - lyxerr << "got changed() during updating:" << updating_ << std::endl; - if (updating_) return; diff --git a/src/frontends/qt2/Qt2Base.h b/src/frontends/qt2/Qt2Base.h index a6a660b425..2bdc6ad7be 100644 --- a/src/frontends/qt2/Qt2Base.h +++ b/src/frontends/qt2/Qt2Base.h @@ -27,6 +27,7 @@ #include "ViewBase.h" #include "LString.h" +#include "debug.h" #include "ButtonPolicies.h" #include "ControlButtons.h" @@ -46,8 +47,8 @@ public: virtual ~Qt2Base() {} protected: - /// Build the dialog - virtual void build() = 0; + /// build the actual dialog + virtual void build_dialog() = 0; /// Hide the dialog. virtual void hide(); /// Create the dialog if necessary, update it and display it. @@ -99,8 +100,12 @@ protected: /// update the dialog virtual void update(); + /// Build the dialog + virtual void build(); + /// Pointer to the actual instantiation of the Qt dialog virtual QDialog * form() const; + /// Real GUI implementation. boost::scoped_ptr dialog_; @@ -125,11 +130,8 @@ void Qt2DB::update() { form()->setUpdatesEnabled(false); - // this is tricky. First we process pending events - // as a result of the bc() state change (if any). - // then we lock out any bc() changes as a result of - // "innocent" updates during update_contents() - // then we enable normal behaviour again. + // protect the BC from unwarranted state transitions + qApp->processEvents(); updating_ = true; update_contents(); @@ -141,9 +143,27 @@ void Qt2DB::update() } +template +void Qt2DB::build() +{ + // protect the BC from unwarranted state transitions + + qApp->processEvents(); + updating_ = true; + build_dialog(); + qApp->processEvents(); + updating_ = false; +} + + template class Qt2CB: public Base { +public: + bool readOnly() const { + return controller().isReadonly(); + } + protected: /// Qt2CB(ControlButtons &, const QString&); diff --git a/src/frontends/qt2/README b/src/frontends/qt2/README index c6e300a8ed..ff2905f15b 100644 --- a/src/frontends/qt2/README +++ b/src/frontends/qt2/README @@ -19,7 +19,9 @@ of the current dialog's contents. OK/Apply/Restore/Close should be connected in the derived class's constructor to call form_->slotOK() etc. Refer to close/cancel as close in the source. -Override update_contents() to update the dialog, not update() +Override update_contents() to update the dialog, not update(), and build_dialog(), +not build(). Only these functions may change dialog widgets that may emit changed() +during initialisation, to prevent the button controller from changing its state. Never call buttoncontroller functions directly from dialogs. In general, you should use Qt2Base::changed() in all circumstances. However, if you must call @@ -58,10 +60,10 @@ Document Kalle Waiting for MVC Index Kalle Done Paragraph Edwin Waiting for MVC Print Edwin -Ref Kalle +Ref Kalle Done Search Edwin Splash Edwin Tabular Waiting for MVC TabularCreate Edwin Toc Kalle -Url Kalle +Url Kalle Done diff --git a/src/frontends/qt2/ui/QRefDialog.ui b/src/frontends/qt2/ui/QRefDialog.ui index 353c17c6af..cb10bb4607 100644 --- a/src/frontends/qt2/ui/QRefDialog.ui +++ b/src/frontends/qt2/ui/QRefDialog.ui @@ -11,7 +11,7 @@ 0 0 - 417 + 401 277 @@ -49,6 +49,10 @@ name refsLB + + toolTip + Available references + QLayoutWidget @@ -96,6 +100,10 @@ text &Update + + toolTip + Update the reference list + @@ -130,7 +138,7 @@ toolTip - Sort references in alphabetical order ? + Sort references in alphabetical order @@ -383,6 +391,10 @@ text &Goto reference + + toolTip + Move the document cursor + @@ -439,11 +451,11 @@ QPushButton name - cancelPB + closePB text - &Cancel + &Close @@ -453,54 +465,65 @@ + + typeCO + activated(int) + QRefDialogBase + changed_adaptor() + + + referenceED + textChanged(const QString&) + QRefDialogBase + changed_adaptor() + + + nameED + textChanged(const QString&) + QRefDialogBase + changed_adaptor() + refsLB highlighted(const QString&) QRefDialogBase - highlight_adaptor(const QString&) + refHighlighted(const QString&) refsLB selected(const QString&) QRefDialogBase - select_adaptor(const QString&) + refSelected(const QString&) + + + refsLB + highlighted(const QString&) + QRefDialogBase + changed_adaptor() sortCB toggled(bool) QRefDialogBase - sort_adaptor(bool) - - - updatePB - clicked() - QRefDialogBase - update_adaptor() - - - okPB - clicked() - QRefDialogBase - apply_adaptor() - - - cancelPB - clicked() - QRefDialogBase - close_adaptor() + sortToggled(bool) gotoPB clicked() QRefDialogBase - goto_adaptor() + gotoClicked() - apply_adaptor() - goto_adaptor() - highlight_adaptor(const QString&) - close_adaptor() - select_adaptor(const QString&) - sort_adaptor(bool) - update_adaptor() + + updatePB + clicked() + QRefDialogBase + updateClicked() + + changed_adaptor() + gotoClicked() + refHighlighted(const QString&) + refSelected(const QString&) + sortToggled(bool) + updateClicked()