From c9ea6e6eef090b863fb54445010f24443b15eb23 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 5 Sep 2007 20:33:29 +0000 Subject: [PATCH] the fun begins.... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20077 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/Dialogs.cpp | 2 +- src/frontends/controllers/ControlExternal.cpp | 2 +- src/frontends/controllers/ControlGraphics.cpp | 2 +- .../controllers/ControlSpellchecker.cpp | 4 +- src/frontends/controllers/ControlTabular.cpp | 4 +- src/frontends/controllers/Dialog.cpp | 46 +- src/frontends/controllers/Dialog.h | 124 ++-- src/frontends/qt4/Dialogs.cpp | 187 ++---- src/frontends/qt4/DockView.h | 2 + src/frontends/qt4/GuiAbout.cpp | 50 +- src/frontends/qt4/GuiAbout.h | 32 +- src/frontends/qt4/GuiApplication.cpp | 2 +- src/frontends/qt4/GuiApplication.h | 2 - src/frontends/qt4/GuiBibitem.cpp | 69 +- src/frontends/qt4/GuiBibitem.h | 47 +- src/frontends/qt4/GuiBibtex.cpp | 136 ++-- src/frontends/qt4/GuiBibtex.h | 76 +-- src/frontends/qt4/GuiBox.cpp | 218 +++---- src/frontends/qt4/GuiBox.h | 53 +- src/frontends/qt4/GuiBranch.cpp | 72 +-- src/frontends/qt4/GuiBranch.h | 47 +- src/frontends/qt4/GuiBranches.cpp | 3 +- src/frontends/qt4/GuiBranches.h | 4 +- src/frontends/qt4/GuiChanges.cpp | 72 +-- src/frontends/qt4/GuiChanges.h | 56 +- src/frontends/qt4/GuiCharacter.cpp | 185 +++--- src/frontends/qt4/GuiCharacter.h | 40 +- src/frontends/qt4/GuiCitation.cpp | 168 +++-- src/frontends/qt4/GuiCitation.h | 43 +- src/frontends/qt4/GuiCommandBuffer.h | 4 +- src/frontends/qt4/GuiCommandEdit.h | 3 +- src/frontends/qt4/GuiDelimiter.cpp | 104 ++- src/frontends/qt4/GuiDelimiter.h | 38 +- src/frontends/qt4/GuiDialog.cpp | 105 ++- src/frontends/qt4/GuiDialog.h | 48 +- src/frontends/qt4/GuiDialogView.cpp | 131 ---- src/frontends/qt4/GuiDialogView.h | 116 ---- src/frontends/qt4/GuiDocument.cpp | 212 +++--- src/frontends/qt4/GuiDocument.h | 38 +- src/frontends/qt4/GuiERT.cpp | 64 +- src/frontends/qt4/GuiEmbeddedFiles.cpp | 66 +- src/frontends/qt4/GuiEmbeddedFiles.h | 25 +- src/frontends/qt4/GuiErrorList.cpp | 73 +-- src/frontends/qt4/GuiErrorList.h | 39 +- src/frontends/qt4/GuiExternal.cpp | 341 +++++----- src/frontends/qt4/GuiExternal.h | 72 +-- src/frontends/qt4/GuiFloat.cpp | 67 +- src/frontends/qt4/GuiFloat.h | 46 +- src/frontends/qt4/GuiFontExample.h | 8 +- src/frontends/qt4/GuiFontLoader.h | 3 +- src/frontends/qt4/GuiFontMetrics.h | 1 - src/frontends/qt4/GuiGraphics.cpp | 388 ++++++----- src/frontends/qt4/GuiGraphics.h | 69 +- src/frontends/qt4/GuiImage.h | 3 +- src/frontends/qt4/GuiInclude.cpp | 164 +++-- src/frontends/qt4/GuiInclude.h | 66 +- src/frontends/qt4/GuiIndex.cpp | 76 +-- src/frontends/qt4/GuiIndex.h | 67 +- src/frontends/qt4/GuiKeySymbol.h | 3 +- src/frontends/qt4/GuiListings.cpp | 230 +++---- src/frontends/qt4/GuiListings.h | 45 +- src/frontends/qt4/GuiLog.cpp | 95 +-- src/frontends/qt4/GuiLog.h | 64 +- src/frontends/qt4/GuiMathMatrix.cpp | 28 +- src/frontends/qt4/GuiMathMatrix.h | 41 +- src/frontends/qt4/GuiMenubar.h | 3 +- src/frontends/qt4/GuiNomencl.cpp | 81 +-- src/frontends/qt4/GuiNomencl.h | 52 +- src/frontends/qt4/GuiNote.cpp | 72 +-- src/frontends/qt4/GuiNote.h | 47 +- src/frontends/qt4/GuiParagraph.cpp | 146 ++--- src/frontends/qt4/GuiParagraph.h | 50 +- src/frontends/qt4/GuiPrefs.cpp | 113 ++-- src/frontends/qt4/GuiPrefs.h | 102 ++- src/frontends/qt4/GuiPrint.cpp | 112 ++-- src/frontends/qt4/GuiPrint.h | 50 +- src/frontends/qt4/GuiRef.cpp | 225 ++++--- src/frontends/qt4/GuiRef.h | 54 +- src/frontends/qt4/GuiSearch.cpp | 94 ++- src/frontends/qt4/GuiSearch.h | 55 +- src/frontends/qt4/GuiSelectionManager.cpp | 294 ++++----- src/frontends/qt4/GuiSelectionManager.h | 161 ++--- src/frontends/qt4/GuiSendto.cpp | 113 ++-- src/frontends/qt4/GuiSendto.h | 54 +- src/frontends/qt4/GuiSetBorder.h | 7 +- src/frontends/qt4/GuiShowFile.cpp | 48 +- src/frontends/qt4/GuiShowFile.h | 44 +- src/frontends/qt4/GuiSpellchecker.cpp | 118 ++-- src/frontends/qt4/GuiSpellchecker.h | 61 +- src/frontends/qt4/GuiTabular.cpp | 604 +++++++++--------- src/frontends/qt4/GuiTabular.h | 125 ++-- src/frontends/qt4/GuiTabularCreate.cpp | 55 +- src/frontends/qt4/GuiTabularCreate.h | 40 +- src/frontends/qt4/GuiTexinfo.cpp | 102 ++- src/frontends/qt4/GuiTexinfo.h | 57 +- src/frontends/qt4/GuiThesaurus.cpp | 79 +-- src/frontends/qt4/GuiThesaurus.h | 63 +- src/frontends/qt4/GuiToc.cpp | 33 +- src/frontends/qt4/GuiToc.h | 12 +- src/frontends/qt4/GuiToolbar.h | 6 +- src/frontends/qt4/GuiURL.cpp | 67 +- src/frontends/qt4/GuiURL.h | 42 +- src/frontends/qt4/GuiVSpace.cpp | 158 ++--- src/frontends/qt4/GuiVSpace.h | 44 +- src/frontends/qt4/GuiView.h | 8 +- src/frontends/qt4/GuiViewSource.cpp | 62 +- src/frontends/qt4/GuiViewSource.h | 23 +- src/frontends/qt4/GuiWrap.cpp | 82 +-- src/frontends/qt4/GuiWrap.h | 41 +- src/frontends/qt4/Makefile.am | 2 - src/frontends/qt4/README | 69 +- src/frontends/qt4/TocWidget.cpp | 26 +- src/frontends/qt4/TocWidget.h | 9 +- 113 files changed, 3581 insertions(+), 5075 deletions(-) delete mode 100644 src/frontends/qt4/GuiDialogView.cpp delete mode 100644 src/frontends/qt4/GuiDialogView.h diff --git a/src/frontends/Dialogs.cpp b/src/frontends/Dialogs.cpp index a26ed15883..cb6bc88f25 100644 --- a/src/frontends/Dialogs.cpp +++ b/src/frontends/Dialogs.cpp @@ -181,7 +181,7 @@ void Dialogs::updateBufferDependent(bool switched) const Dialog * dialog = it->second.get(); if (switched && dialog->controller().isBufferDependent()) { if (dialog->isVisible() && dialog->controller().initialiseParams("")) - dialog->view().updateView(); + dialog->updateView(); else dialog->hide(); } else { diff --git a/src/frontends/controllers/ControlExternal.cpp b/src/frontends/controllers/ControlExternal.cpp index 89b564431c..2f7f4eab0d 100644 --- a/src/frontends/controllers/ControlExternal.cpp +++ b/src/frontends/controllers/ControlExternal.cpp @@ -92,7 +92,7 @@ void ControlExternal::editExternal() { BOOST_ASSERT(params_.get()); - dialog().view().applyView(); + dialog().applyView(); string const lfun = InsetExternalMailer::params2string(params(), kernel().buffer()); kernel().dispatch(FuncRequest(LFUN_EXTERNAL_EDIT, lfun)); diff --git a/src/frontends/controllers/ControlGraphics.cpp b/src/frontends/controllers/ControlGraphics.cpp index 93d3c354d0..960e99b75e 100644 --- a/src/frontends/controllers/ControlGraphics.cpp +++ b/src/frontends/controllers/ControlGraphics.cpp @@ -142,7 +142,7 @@ void ControlGraphics::editGraphics() { BOOST_ASSERT(params_.get()); - dialog().view().applyView(); + dialog().applyView(); string const lfun = InsetGraphicsMailer::params2string(params(), kernel().buffer()); kernel().dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun)); diff --git a/src/frontends/controllers/ControlSpellchecker.cpp b/src/frontends/controllers/ControlSpellchecker.cpp index 34ad420c4e..ba459536ad 100644 --- a/src/frontends/controllers/ControlSpellchecker.cpp +++ b/src/frontends/controllers/ControlSpellchecker.cpp @@ -233,7 +233,7 @@ void ControlSpellchecker::check() LYXERR(Debug::GUI) << "Updating spell progress." << endl; oldval_ = newvalue_; // set progress bar - dialog().view().partialUpdateView(SPELL_PROGRESSED); + dialog().partialUpdateView(SPELL_PROGRESSED); } // speller might be dead ... @@ -261,7 +261,7 @@ void ControlSpellchecker::check() // set suggestions if (res != SpellBase::OK && res != SpellBase::IGNORED_WORD) { LYXERR(Debug::GUI) << "Found a word needing checking." << endl; - dialog().view().partialUpdateView(SPELL_FOUND_WORD); + dialog().partialUpdateView(SPELL_FOUND_WORD); } } diff --git a/src/frontends/controllers/ControlTabular.cpp b/src/frontends/controllers/ControlTabular.cpp index 46d79761eb..6ae68801d2 100644 --- a/src/frontends/controllers/ControlTabular.cpp +++ b/src/frontends/controllers/ControlTabular.cpp @@ -142,14 +142,14 @@ void ControlTabular::setWidth(string const & width) else set(Tabular::SET_PWIDTH, width); - dialog().view().updateView(); + dialog().updateView(); } void ControlTabular::toggleMultiColumn() { set(Tabular::MULTICOLUMN); - dialog().view().updateView(); + dialog().updateView(); } diff --git a/src/frontends/controllers/Dialog.cpp b/src/frontends/controllers/Dialog.cpp index bbebbbd45e..a6e4ebaf9e 100644 --- a/src/frontends/controllers/Dialog.cpp +++ b/src/frontends/controllers/Dialog.cpp @@ -51,7 +51,7 @@ void Dialog::show(string const & data) } preShow(); - view().showView(); + showView(); postShow(); } @@ -68,7 +68,7 @@ void Dialog::update(string const & data) } preUpdate(); - view().updateView(); + updateView(); postUpdate(); } @@ -80,11 +80,11 @@ void Dialog::checkStatus() void Dialog::hide() { - if (!view().isVisibleView()) + if (!isVisibleView()) return; controller().clearParams(); - view().hideView(); + hideView(); kernel().disconnect(name()); } @@ -93,31 +93,30 @@ void Dialog::apply() { if (controller().isBufferDependent()) { if (!kernel().isBufferAvailable() || - (kernel().isBufferReadonly() && - !controller().canApplyToReadOnly())) + (kernel().isBufferReadonly() && !controller().canApplyToReadOnly())) return; } - view().applyView(); + applyView(); controller().dispatchParams(); if (controller().disconnectOnApply() && !is_closing_) { kernel().disconnect(name()); controller().initialiseParams(string()); - view().updateView(); + updateView(); } } bool Dialog::isVisible() const { - return view().isVisibleView(); + return isVisibleView(); } void Dialog::redraw() { - view().redrawView(); + redrawView(); } @@ -128,14 +127,6 @@ void Dialog::setController(Controller * i) } -void Dialog::setView(View * v) -{ - BOOST_ASSERT(v && !view_ptr_.get()); - view_ptr_.reset(v); -} - - - Dialog::Controller::Controller(Dialog & parent) : parent_(parent) {} @@ -156,32 +147,17 @@ Dialog::Controller & Dialog::controller() const } -Dialog::View::View(Dialog & parent, docstring title) : - p_(parent), title_(title) -{} - - -Dialog::View & Dialog::view() const -{ - BOOST_ASSERT(view_ptr_.get()); - return *view_ptr_.get(); -} - - -void Dialog::View::setViewTitle(docstring const & newtitle) +void Dialog::setViewTitle(docstring const & newtitle) { title_ = newtitle; } -docstring const & Dialog::View::getViewTitle() const +docstring const & Dialog::getViewTitle() const { return title_; } -void Dialog::View::partialUpdateView(int) -{} - } // namespace frontend } // namespace lyx diff --git a/src/frontends/controllers/Dialog.h b/src/frontends/controllers/Dialog.h index 86122ff5bb..1dac6f5c13 100644 --- a/src/frontends/controllers/Dialog.h +++ b/src/frontends/controllers/Dialog.h @@ -87,13 +87,13 @@ public: * show() and update() methods. */ Kernel & kernel() { return kernel_; } + Kernel const & kernel() const { return kernel_; } /** Different dialogs will have different Controllers and Views. * deriving from these base classes. */ //@{ class Controller; - class View; //@} /** \name Dialog Specialization @@ -103,20 +103,60 @@ public: //@{ /// \param ptr is stored and destroyed by \c Dialog. void setController(Controller * ptr); - /// \param ptr is stored and destroyed by \c Dialog. - void setView(View * ptr); //@} /** \name Dialog Components * Methods to access the various components making up a dialog. */ //@{ - Controller & controller() const; - View & view() const; + virtual Controller & controller() const; //@} - + /** \c Button controller part + */ virtual void setButtonsValid(bool valid); + + + /** \c View part + * of a Model-Controller-View split of a generic dialog. + * These few methods are all that a generic dialog needs of a + * view. + */ + //@{ + /** A request to modify the data structures stored by the + * accompanying Controller in preparation for their dispatch to + * the LyX kernel. + */ + virtual void applyView() = 0; + + /// Hide the dialog from sight + virtual void hideView() = 0; + + /// Redraw the dialog (e.g. if the colors have been remapped). + virtual void redrawView() {} + + /// Create the dialog if necessary, update it and display it. + virtual void showView() = 0; + + /// Update the display of the dialog whilst it is still visible. + virtual void updateView() = 0; + + /// \return true if the dialog is visible. + virtual bool isVisibleView() const = 0; + //@} + + /** Defaults to nothing. Can be used by the Controller, however, to + * indicate to the View that something has changed and that the + * dialog therefore needs updating. + * \param id identifies what should be updated. + */ + virtual void partialUpdateView(int /*id*/) {} + + /// sets the title of the dialog (window caption) + void setViewTitle(docstring const &); + /// gets the title of the dialog (window caption) + docstring const & getViewTitle() const; + protected: void apply(); @@ -124,7 +164,8 @@ protected: Kernel kernel_; std::string name_; boost::scoped_ptr controller_ptr_; - boost::scoped_ptr view_ptr_; + + docstring title_; }; @@ -223,75 +264,6 @@ private: }; -/** \c Dialog::View is an abstract base class to the View - * of a Model-Controller-View split of a generic dialog. - */ -class Dialog::View : boost::noncopyable { -public: - /** \param parent Dialog owning this Controller. - * \param title is the dialog title displayed by the WM. - */ - View(Dialog & parent, docstring title); - virtual ~View() {} - - /** \name Generic View - * These few methods are all that a generic dialog needs of a - * view. - */ - //@{ - /** A request to modify the data structures stored by the - * accompanying Controller in preparation for their dispatch to - * the LyX kernel. - */ - virtual void applyView() = 0; - - /// Hide the dialog from sight - virtual void hideView() = 0; - - /// Redraw the dialog (e.g. if the colors have been remapped). - virtual void redrawView() {} - - /// Create the dialog if necessary, update it and display it. - virtual void showView() = 0; - - /// Update the display of the dialog whilst it is still visible. - virtual void updateView() = 0; - - /// \return true if the dialog is visible. - virtual bool isVisibleView() const = 0; - //@} - - /** Defaults to nothing. Can be used by the Controller, however, to - * indicate to the View that something has changed and that the - * dialog therefore needs updating. - * \param id identifies what should be updated. - */ - virtual void partialUpdateView(int id); - - /// sets the title of the dialog (window caption) - void setViewTitle(docstring const &); - /// gets the title of the dialog (window caption) - docstring const & getViewTitle() const; - - /** \name View Access - * Enable the derived classes to access the other parts of the whole. - */ - //@{ - Dialog & dialog() { return p_; } - Dialog const & dialog() const { return p_; } - -protected: - Kernel & kernel() { return p_.kernel(); } - Kernel const & kernel() const { return p_.kernel(); } - - Controller & getController() { return p_.controller(); } - Controller const & getController() const { return p_.controller(); } - //@} - -private: - Dialog & p_; - docstring title_; -}; } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/Dialogs.cpp b/src/frontends/qt4/Dialogs.cpp index 78fa8e9e4b..26f1213ffc 100644 --- a/src/frontends/qt4/Dialogs.cpp +++ b/src/frontends/qt4/Dialogs.cpp @@ -114,195 +114,92 @@ Dialog * Dialogs::build(string const & name) { BOOST_ASSERT(isValidName(name)); - GuiDialog * dialog = new GuiDialog(lyxview_, name); + Dialog * dialog = 0; if (name == "aboutlyx") { - dialog->setController(new ControlAboutlyx(*dialog)); - dialog->setView(new GuiAbout(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::OkCancelPolicy); + dialog = new GuiAboutDialog(lyxview_); } else if (name == "bibitem") { - dialog->setController(new ControlCommand(*dialog, name, name)); - dialog->setView(new GuiBibitem(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::OkCancelReadOnlyPolicy); + dialog = new GuiBibitemDialog(lyxview_); } else if (name == "bibtex") { - dialog->setController(new ControlBibtex(*dialog)); - dialog->setView(new GuiBibtex(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiBibtexDialog(lyxview_); } else if (name == "box") { - dialog->setController(new ControlBox(*dialog)); - dialog->setView(new GuiBox(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); + dialog = new GuiBoxDialog(lyxview_); } else if (name == "branch") { - dialog->setController(new ControlBranch(*dialog)); - dialog->setView(new GuiBranch(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiBranchDialog(lyxview_); } else if (name == "changes") { - dialog->setController(new ControlChanges(*dialog)); - dialog->setView(new GuiChanges(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiChangesDialog(lyxview_); } else if (name == "character") { - dialog->setController(new ControlCharacter(*dialog)); - dialog->setView(new GuiCharacter(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); + dialog = new GuiCharacterDialog(lyxview_); } else if (name == "citation") { - GuiCitation * ci = new GuiCitation(*dialog); - dialog->setController(ci); - dialog->setView(new GuiCitationDialog(*dialog, ci)); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiCitationDialog(lyxview_); } else if (name == "document") { - dialog->setController(new ControlDocument(*dialog)); - dialog->setView(new GuiDocument(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiDocumentDialog(lyxview_); } else if (name == "embedding") { - GuiViewBase & gui_view = static_cast(lyxview_); - GuiEmbeddedFiles * qef = new GuiEmbeddedFiles(*dialog); - dialog->setController(qef); - dialog->setView(new DockView( - *dialog, qef, &gui_view, _("Embedded Files"), Qt::RightDockWidgetArea)); - dialog->bc().setPolicy(ButtonPolicy::OkCancelPolicy); + dialog = new GuiEmbeddedFilesDialog(lyxview_); } else if (name == "errorlist") { - dialog->setController(new ControlErrorList(*dialog)); - dialog->setView(new GuiErrorList(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::OkCancelPolicy); + dialog = new GuiErrorListDialog(lyxview_); } else if (name == "ert") { - dialog->setController(new ControlERT(*dialog)); - dialog->setView(new GuiERT(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiERTDialog(lyxview_); } else if (name == "external") { - dialog->setController(new ControlExternal(*dialog)); - dialog->setView(new GuiExternal(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiExternalDialog(lyxview_); } else if (name == "file") { - dialog->setController(new ControlShowFile(*dialog)); - dialog->setView(new GuiShowFile(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::OkCancelPolicy); + dialog = new GuiShowFileDialog(lyxview_); } else if (name == "findreplace") { - dialog->setController(new ControlSearch(*dialog)); - dialog->setView(new GuiSearch(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiSearchDialog(lyxview_); } else if (name == "float") { - dialog->setController(new ControlFloat(*dialog)); - dialog->setView(new GuiFloat(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiFloatDialog(lyxview_); } else if (name == "graphics") { - dialog->setController(new ControlGraphics(*dialog)); - dialog->setView(new GuiGraphics(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiGraphicsDialog(lyxview_); } else if (name == "include") { - dialog->setController(new ControlInclude(*dialog)); - dialog->setView(new GuiInclude(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); + dialog = new GuiIncludeDialog(lyxview_); } else if (name == "index") { - dialog->setController(new ControlCommand(*dialog, name, name)); - dialog->setView(new GuiIndex(*dialog, - _("Index Entry"), - qt_("&Keyword:"))); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiIndexDialog(lyxview_); } else if (name == "nomenclature") { - dialog->setController(new ControlCommand(*dialog, name, name)); - dialog->setView(new GuiNomencl(*dialog, _("Nomenclature Entry"))); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiNomenclDialog(lyxview_); } else if (name == "label") { - dialog->setController(new ControlCommand(*dialog, name, name)); - dialog->setView(new GuiIndex(*dialog, - _("Label"), - qt_("&Label:"))); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiLabelDialog(lyxview_); } else if (name == "log") { - dialog->setController(new ControlLog(*dialog)); - dialog->setView(new GuiLog(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::OkCancelPolicy); + dialog = new GuiLogDialog(lyxview_); } else if (name == "view-source") { - GuiViewSource * qvs = new GuiViewSource(*dialog); - dialog->setController(qvs); - GuiViewBase & gui_view = static_cast(lyxview_); - dialog->setView(new DockView( - *dialog, qvs, &gui_view, _("LaTeX Source"), Qt::BottomDockWidgetArea)); - dialog->bc().setPolicy(ButtonPolicy::OkCancelPolicy); + dialog = new GuiViewSourceDialog(lyxview_); } else if (name == "mathdelimiter") { - dialog->setController(new ControlMath(*dialog)); - dialog->setView(new GuiDelimiter(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::IgnorantPolicy); + dialog = new GuiDelimiterDialog(lyxview_); } else if (name == "mathmatrix") { - dialog->setController(new ControlMath(*dialog)); - dialog->setView(new GuiMathMatrix(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::IgnorantPolicy); + dialog = new GuiMathMatrixDialog(lyxview_); } else if (name == "note") { - dialog->setController(new ControlNote(*dialog)); - dialog->setView(new GuiNote(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiNoteDialog(lyxview_); } else if (name == "paragraph") { - dialog->setController(new ControlParagraph(*dialog)); - dialog->setView(new GuiParagraph(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); + dialog = new GuiParagraphDialog(lyxview_); } else if (name == "prefs") { - dialog->setController(new ControlPrefs(*dialog)); - dialog->setView(new GuiPrefs(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::PreferencesPolicy); + dialog = new GuiPrefsDialog(lyxview_); } else if (name == "print") { - dialog->setController(new ControlPrint(*dialog)); - dialog->setView(new GuiPrint(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy); + dialog = new GuiPrintDialog(lyxview_); } else if (name == "ref") { - // full qualification because qt4 has also a ControlRef type - dialog->setController(new ControlRef(*dialog)); - dialog->setView(new GuiRef(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiRefDialog(lyxview_); } else if (name == "sendto") { - dialog->setController(new ControlSendto(*dialog)); - dialog->setView(new GuiSendto(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy); + dialog = new GuiSendtoDialog(lyxview_); } else if (name == "spellchecker") { - dialog->setController(new ControlSpellchecker(*dialog)); - dialog->setView(new GuiSpellchecker(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiSpellcheckerDialog(lyxview_); } else if (name == "tabular") { - dialog->setController(new ControlTabular(*dialog)); - dialog->setView(new GuiTabular(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiTabularDialog(lyxview_); } else if (name == "tabularcreate") { - dialog->setController(new ControlTabularCreate(*dialog)); - dialog->setView(new GuiTabularCreate(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::IgnorantPolicy); + dialog = new GuiTabularCreateDialog(lyxview_); } else if (name == "texinfo") { - dialog->setController(new ControlTexinfo(*dialog)); - dialog->setView(new GuiTexinfo(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::OkCancelPolicy); + dialog = new GuiTexinfoDialog(lyxview_); #ifdef HAVE_LIBAIKSAURUS } else if (name == "thesaurus") { - dialog->setController(new ControlThesaurus(*dialog)); - dialog->setView(new GuiThesaurus(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); + dialog = new GuiThesaurusDialog(lyxview_); #endif } else if (name == "toc") { - GuiViewBase & gui_view = static_cast(lyxview_); - GuiToc * qtoc = new GuiToc(*dialog, &gui_view); - dialog->setController(qtoc); -#ifdef Q_WS_MACX - // On Mac show as a drawer at the right - dialog->setView(new DockView( - *dialog, qtoc, &gui_view, _("Outline"), Qt::RightDockWidgetArea, Qt::Drawer)); -#else - dialog->setView(new DockView( - *dialog, qtoc, &gui_view, _("Outline"))); -#endif - dialog->bc().setPolicy(ButtonPolicy::OkCancelPolicy); + dialog = new GuiToc(lyxview_); } else if (name == "url") { - dialog->setController(new ControlCommand(*dialog, name, name)); - dialog->setView(new UrlView(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiURLDialog(lyxview_); } else if (name == "vspace") { - dialog->setController(new ControlVSpace(*dialog)); - dialog->setView(new GuiVSpace(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); + dialog = new GuiVSpaceDialog(lyxview_); } else if (name == "wrap") { - dialog->setController(new ControlWrap(*dialog)); - dialog->setView(new GuiWrap(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiWrapDialog(lyxview_); } else if (name == "listings") { - dialog->setController(new ControlListings(*dialog)); - dialog->setView(new GuiListings(*dialog)); - dialog->bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + dialog = new GuiListingsDialog(lyxview_); } return dialog; diff --git a/src/frontends/qt4/DockView.h b/src/frontends/qt4/DockView.h index 6113077362..0a2f6bb876 100644 --- a/src/frontends/qt4/DockView.h +++ b/src/frontends/qt4/DockView.h @@ -23,6 +23,7 @@ namespace lyx { namespace frontend { +/* /// Dock Widget container for LyX dialogs. /// This template class that encapsulates a given Widget inside a /// DockWidget and presents a Dialog::View interface @@ -65,6 +66,7 @@ private: /// The encapsulated widget. boost::scoped_ptr widget_; }; +*/ } // frontend } // lyx diff --git a/src/frontends/qt4/GuiAbout.cpp b/src/frontends/qt4/GuiAbout.cpp index 36ef8ace72..4c05af2c10 100644 --- a/src/frontends/qt4/GuiAbout.cpp +++ b/src/frontends/qt4/GuiAbout.cpp @@ -31,29 +31,30 @@ using std::istringstream; using std::ostringstream; using std::string; + namespace lyx { namespace frontend { - -GuiAbout::GuiAbout(GuiDialog & parent) - : GuiView(parent, _("About LyX")) +GuiAboutDialog::GuiAboutDialog(LyXView & lv) + : GuiDialog(lv, "aboutlyx") { -} + setupUi(this); + setViewTitle(_("About LyX")); + setController(new ControlAboutlyx(*this)); -void GuiAbout::build_dialog() -{ - dialog_.reset(new GuiAboutDialog); - connect(dialog_.get()->closePB, SIGNAL(clicked()), + connect(closePB, SIGNAL(clicked()), this, SLOT(reject())); + + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); - dialog_->copyrightTB->setPlainText(toqstr(controller().getCopyright())); - dialog_->copyrightTB->append(""); - dialog_->copyrightTB->append(toqstr(controller().getLicense())); - dialog_->copyrightTB->append(""); - dialog_->copyrightTB->append(toqstr(controller().getDisclaimer())); + copyrightTB->setPlainText(toqstr(controller().getCopyright())); + copyrightTB->append(""); + copyrightTB->append(toqstr(controller().getLicense())); + copyrightTB->append(""); + copyrightTB->append(toqstr(controller().getDisclaimer())); - dialog_->versionLA->setText(toqstr(controller().getVersion())); + versionLA->setText(toqstr(controller().getVersion())); // The code below should depend on a autoconf test. (Lgb) #if 1 @@ -100,17 +101,24 @@ void GuiAbout::build_dialog() } #endif - dialog_->creditsTB->setHtml(toqstr(out.str())); + creditsTB->setHtml(toqstr(out.str())); // try to resize to a good size - dialog_->copyrightTB->hide(); - dialog_->setMinimumSize(dialog_->copyrightTB->sizeHint()); - dialog_->copyrightTB->show(); - dialog_->setMinimumSize(dialog_->sizeHint()); + copyrightTB->hide(); + setMinimumSize(copyrightTB->sizeHint()); + copyrightTB->show(); + setMinimumSize(sizeHint()); // Manage the cancel/close button - bc().setCancel(dialog_->closePB); - //FIXME bc().refresh(); + bc().setPolicy(ButtonPolicy::OkCancelPolicy); + bc().setCancel(closePB); + bc().refresh(); +} + + +ControlAboutlyx & GuiAboutDialog::controller() const +{ + return static_cast(Dialog::controller()); } } // namespace frontend diff --git a/src/frontends/qt4/GuiAbout.h b/src/frontends/qt4/GuiAbout.h index d75f9a8602..5d1b8ccd27 100644 --- a/src/frontends/qt4/GuiAbout.h +++ b/src/frontends/qt4/GuiAbout.h @@ -12,7 +12,7 @@ #ifndef GUIABOUT_H #define GUIABOUT_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlAboutlyx.h" #include "ui_AboutUi.h" @@ -21,35 +21,15 @@ namespace lyx { namespace frontend { -class GuiAboutDialog : public QDialog, public Ui::AboutUi { +class GuiAboutDialog : public GuiDialog, public Ui::AboutUi +{ Q_OBJECT -public: - GuiAboutDialog(QWidget * parent = 0) - : QDialog(parent) - { - setupUi(this); - connect(closePB, SIGNAL(clicked()), this, SLOT(reject())); - } -}; - -class GuiAbout : public GuiView -{ public: - GuiAbout(GuiDialog &); - /// parent controller - ControlAboutlyx & controller() - { return static_cast(this->getController()); } + // Constructor + GuiAboutDialog(LyXView & lv); /// parent controller - ControlAboutlyx const & controller() const - { return static_cast(this->getController()); } -private: - /// not needed - virtual void applyView() {} - /// not needed - virtual void update_contents() {} - // build the dialog - virtual void build_dialog(); + ControlAboutlyx & controller() const; }; } // namespace frontend diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index f316019b13..fa3a2bb549 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -1,5 +1,5 @@ /** - * \file qt4/GuiApplication.cpp + * \file GuiApplication.cpp * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index be7b69276d..46a50b45f4 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -123,8 +123,6 @@ public: extern GuiApplication * guiApp; } // namespace frontend - } // namespace lyx - #endif // GUIAPPLICATION_H diff --git a/src/frontends/qt4/GuiBibitem.cpp b/src/frontends/qt4/GuiBibitem.cpp index 83b488dc16..8adff58415 100644 --- a/src/frontends/qt4/GuiBibitem.cpp +++ b/src/frontends/qt4/GuiBibitem.cpp @@ -11,6 +11,7 @@ #include #include "GuiBibitem.h" +#include "ControlCommand.h" #include "qt_helpers.h" #include @@ -21,80 +22,66 @@ namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiBibItemDialog -// -///////////////////////////////////////////////////////////////////// -GuiBibitemDialog::GuiBibitemDialog(GuiBibitem * form) - : form_(form) +GuiBibitemDialog::GuiBibitemDialog(LyXView & lv) + : GuiDialog(lv, "bibitem") { setupUi(this); - connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK())); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + setViewTitle(_("Bibliography Entry Settings")); + setController(new ControlCommand(*this, "bibitem", "bibitem")); + + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(keyED, SIGNAL(textChanged(const QString &)), this, SLOT(change_adaptor())); connect(labelED, SIGNAL(textChanged(const QString &)), this, SLOT(change_adaptor())); -} - -void GuiBibitemDialog::change_adaptor() -{ - form_->changed(); + bc().setPolicy(ButtonPolicy::OkCancelReadOnlyPolicy); + bc().setOK(okPB); + bc().setCancel(closePB); + bc().addReadOnly(keyED); + bc().addReadOnly(labelED); } -void GuiBibitemDialog::closeEvent(QCloseEvent *e) +ControlCommand & GuiBibitemDialog::controller() const { - form_->slotWMHide(); - e->accept(); + return static_cast(Dialog::controller()); } -///////////////////////////////////////////////////////////////////// -// -// GuiBibItem -// -///////////////////////////////////////////////////////////////////// - - -GuiBibitem::GuiBibitem(GuiDialog & parent) - : GuiView(parent, _("Bibliography Entry Settings")) +void GuiBibitemDialog::change_adaptor() { + changed(); } -void GuiBibitem::build_dialog() +void GuiBibitemDialog::closeEvent(QCloseEvent *e) { - dialog_.reset(new GuiBibitemDialog(this)); - - bc().setOK(dialog_->okPB); - bc().setCancel(dialog_->closePB); - bc().addReadOnly(dialog_->keyED); - bc().addReadOnly(dialog_->labelED); + slotWMHide(); + e->accept(); } -void GuiBibitem::update_contents() +void GuiBibitemDialog::update_contents() { - dialog_->keyED->setText(toqstr(controller().params()["key"])); - dialog_->labelED->setText(toqstr(controller().params()["label"])); + keyED->setText(toqstr(controller().params()["key"])); + labelED->setText(toqstr(controller().params()["label"])); } -void GuiBibitem::applyView() +void GuiBibitemDialog::applyView() { - controller().params()["key"] = qstring_to_ucs4(dialog_->keyED->text()); - controller().params()["label"] = qstring_to_ucs4(dialog_->labelED->text()); + controller().params()["key"] = qstring_to_ucs4(keyED->text()); + controller().params()["label"] = qstring_to_ucs4(labelED->text()); } -bool GuiBibitem::isValid() +bool GuiBibitemDialog::isValid() { - return !dialog_->keyED->text().isEmpty(); + return !keyED->text().isEmpty(); } } // namespace frontend diff --git a/src/frontends/qt4/GuiBibitem.h b/src/frontends/qt4/GuiBibitem.h index d5bfe816b6..c46c0d9533 100644 --- a/src/frontends/qt4/GuiBibitem.h +++ b/src/frontends/qt4/GuiBibitem.h @@ -12,53 +12,36 @@ #ifndef GUIBIBITEM_H #define GUIBIBITEM_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlCommand.h" #include "ui_BibitemUi.h" -#include - - namespace lyx { namespace frontend { -class GuiBibitem; - -class GuiBibitemDialog : public QDialog, public Ui::BibitemUi { +class GuiBibitemDialog : public GuiDialog, public Ui::BibitemUi +{ Q_OBJECT -public: - GuiBibitemDialog(GuiBibitem * form); -protected Q_SLOTS: - virtual void change_adaptor(); -protected: - virtual void closeEvent(QCloseEvent * e); -private: - GuiBibitem * form_; -}; +public: + GuiBibitemDialog(LyXView & lv); +private Q_SLOTS: + void change_adaptor(); -class GuiBibitem : public GuiView -{ -public: +private: /// - GuiBibitem(GuiDialog &); + void closeEvent(QCloseEvent * e); /// parent controller - ControlCommand & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlCommand const & controller() const - { return static_cast(this->getController()); } -protected: - virtual bool isValid(); + ControlCommand & controller() const; + private: - friend class GuiBibitemDialog; + /// + bool isValid(); /// Apply changes - virtual void applyView(); + void applyView(); /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); + void update_contents(); }; } // namespace frontend diff --git a/src/frontends/qt4/GuiBibtex.cpp b/src/frontends/qt4/GuiBibtex.cpp index aacca6a257..b5c29ba81f 100644 --- a/src/frontends/qt4/GuiBibtex.cpp +++ b/src/frontends/qt4/GuiBibtex.cpp @@ -19,8 +19,8 @@ #include "Validator.h" #include "LyXRC.h" -#include "controllers/ControlBibtex.h" -#include "controllers/ButtonPolicy.h" +#include "ControlBibtex.h" +#include "ButtonPolicy.h" #include "support/filetools.h" // changeExtension #include "support/lstrings.h" @@ -47,27 +47,25 @@ using support::split; using support::trim; -///////////////////////////////////////////////////////////////////// -// -// GuiBibtexDialog -// -///////////////////////////////////////////////////////////////////// - -GuiBibtexDialog::GuiBibtexDialog(GuiBibtex * form) - : form_(form) +GuiBibtexDialog::GuiBibtexDialog(LyXView & lv) + : GuiDialog(lv, "bibtex") { setupUi(this); + + setViewTitle( _("BibTeX Bibliography")); + setController(new ControlBibtex(*this)); + QDialog::setModal(true); connect(okPB, SIGNAL(clicked()), - form, SLOT(slotOK())); + this, SLOT(slotOK())); connect(closePB, SIGNAL(clicked()), - form, SLOT(slotClose())); + this, SLOT(slotClose())); connect(stylePB, SIGNAL(clicked()), this, SLOT(browsePressed())); connect(deletePB, SIGNAL(clicked()), this, SLOT(deletePressed())); - connect(styleCB, SIGNAL(editTextChanged (const QString &)), + connect(styleCB, SIGNAL(editTextChanged(const QString &)), this, SLOT(change_adaptor())); connect(databaseLW, SIGNAL(itemSelectionChanged()), this, SLOT(databaseChanged())); @@ -78,7 +76,7 @@ GuiBibtexDialog::GuiBibtexDialog(GuiBibtex * form) connect(addBibPB, SIGNAL(clicked()), this, SLOT(addPressed())); - add_ = new UiDialog(this, true); + add_ = new GuiBibtexAddDialog(this); add_bc_.setPolicy(ButtonPolicy::OkCancelPolicy); add_bc_.setOK(add_->addPB); add_bc_.setCancel(add_->closePB); @@ -100,6 +98,22 @@ GuiBibtexDialog::GuiBibtexDialog(GuiBibtex * form) this, SLOT(browseBibPressed())); connect(add_->closePB, SIGNAL(clicked()), add_, SLOT(reject())); + + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + bc().setOK(okPB); + bc().setCancel(closePB); + bc().addReadOnly(databaseLW); + bc().addReadOnly(stylePB); + bc().addReadOnly(styleCB); + bc().addReadOnly(bibtocCB); + bc().addReadOnly(addBibPB); + bc().addReadOnly(deletePB); +} + + +ControlBibtex & GuiBibtexDialog::controller() const +{ + return static_cast(Dialog::controller()); } @@ -114,13 +128,13 @@ void GuiBibtexDialog::bibEDChanged() void GuiBibtexDialog::change_adaptor() { - form_->changed(); + changed(); } void GuiBibtexDialog::browsePressed() { - docstring const file = form_->controller().browseBst(docstring()); + docstring const file = controller().browseBst(docstring()); if (!file.empty()) { // FIXME UNICODE @@ -139,14 +153,14 @@ void GuiBibtexDialog::browsePressed() styleCB->insertItem(0, toqstr(filen)); styleCB->setCurrentIndex(pres); - form_->changed(); + changed(); } } void GuiBibtexDialog::browseBibPressed() { - docstring const file = trim(form_->controller().browseBib(docstring())); + docstring const file = trim(controller().browseBib(docstring())); if (!file.empty()) { // FIXME UNICODE @@ -160,7 +174,7 @@ void GuiBibtexDialog::browseBibPressed() if (!present) { add_->bibLW->addItem(f); - form_->changed(); + changed(); } add_->bibED->setText(f); @@ -205,21 +219,21 @@ void GuiBibtexDialog::addDatabase() databaseLW->addItem(f); } - form_->changed(); + changed(); } void GuiBibtexDialog::deletePressed() { databaseLW->takeItem(databaseLW->currentRow()); - form_->changed(); + changed(); } void GuiBibtexDialog::databaseChanged() { - deletePB->setEnabled(!form_->readOnly() && databaseLW->currentRow() != -1); + deletePB->setEnabled(!readOnly() && databaseLW->currentRow() != -1); } @@ -231,44 +245,16 @@ void GuiBibtexDialog::availableChanged() void GuiBibtexDialog::closeEvent(QCloseEvent *e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } -///////////////////////////////////////////////////////////////////// -// -// GuiBibTex -// -///////////////////////////////////////////////////////////////////// - - -GuiBibtex::GuiBibtex(GuiDialog & parent) - : GuiView(parent, _("BibTeX Bibliography")) -{ -} - - -void GuiBibtex::build_dialog() -{ - dialog_.reset(new GuiBibtexDialog(this)); - - bc().setOK(dialog_->okPB); - bc().setCancel(dialog_->closePB); - bc().addReadOnly(dialog_->databaseLW); - bc().addReadOnly(dialog_->stylePB); - bc().addReadOnly(dialog_->styleCB); - bc().addReadOnly(dialog_->bibtocCB); - bc().addReadOnly(dialog_->addBibPB); - bc().addReadOnly(dialog_->deletePB); -} - - -void GuiBibtex::update_contents() +void GuiBibtexDialog::update_contents() { bool bibtopic = controller().usingBibtopic(); - dialog_->databaseLW->clear(); + databaseLW->clear(); docstring bibs(controller().params()["bibfiles"]); docstring bib; @@ -277,23 +263,23 @@ void GuiBibtex::update_contents() bibs = split(bibs, bib, ','); bib = trim(bib); if (!bib.empty()) - dialog_->databaseLW->addItem(toqstr(bib)); + databaseLW->addItem(toqstr(bib)); } - dialog_->add_->bibLW->clear(); + add_->bibLW->clear(); vector bib_str; controller().getBibFiles(bib_str); for (vector::const_iterator it = bib_str.begin(); it != bib_str.end(); ++it) { string bibItem(changeExtension(*it, "")); - dialog_->add_->bibLW->addItem(toqstr(bibItem)); + add_->bibLW->addItem(toqstr(bibItem)); } string bibstyle(controller().getStylefile()); - dialog_->bibtocCB->setChecked(controller().bibtotoc() && !bibtopic); - dialog_->bibtocCB->setEnabled(!bibtopic); + bibtocCB->setChecked(controller().bibtotoc() && !bibtopic); + bibtocCB->setEnabled(!bibtopic); docstring btprint(controller().params()["btprint"]); int btp = 0; @@ -302,10 +288,10 @@ void GuiBibtex::update_contents() else if (btprint == "btPrintAll") btp = 2; - dialog_->btPrintCO->setCurrentIndex(btp); - dialog_->btPrintCO->setEnabled(bibtopic); + btPrintCO->setCurrentIndex(btp); + btPrintCO->setEnabled(bibtopic); - dialog_->styleCB->clear(); + styleCB->clear(); int item_nr(-1); @@ -316,35 +302,35 @@ void GuiBibtex::update_contents() string item(changeExtension(*it, "")); if (item == bibstyle) item_nr = int(it - str.begin()); - dialog_->styleCB->addItem(toqstr(item)); + styleCB->addItem(toqstr(item)); } if (item_nr == -1 && !bibstyle.empty()) { - dialog_->styleCB->addItem(toqstr(bibstyle)); - item_nr = dialog_->styleCB->count() - 1; + styleCB->addItem(toqstr(bibstyle)); + item_nr = styleCB->count() - 1; } if (item_nr != -1) - dialog_->styleCB->setCurrentIndex(item_nr); + styleCB->setCurrentIndex(item_nr); else - dialog_->styleCB->clearEditText(); + styleCB->clearEditText(); } -void GuiBibtex::applyView() +void GuiBibtexDialog::applyView() { - docstring dbs(qstring_to_ucs4(dialog_->databaseLW->item(0)->text())); + docstring dbs = qstring_to_ucs4(databaseLW->item(0)->text()); - unsigned int maxCount = dialog_->databaseLW->count(); + unsigned int maxCount = databaseLW->count(); for (unsigned int i = 1; i < maxCount; i++) { dbs += ','; - dbs += qstring_to_ucs4(dialog_->databaseLW->item(i)->text()); + dbs += qstring_to_ucs4(databaseLW->item(i)->text()); } controller().params()["bibfiles"] = dbs; - docstring const bibstyle(qstring_to_ucs4(dialog_->styleCB->currentText())); - bool const bibtotoc(dialog_->bibtocCB->isChecked()); + docstring const bibstyle(qstring_to_ucs4(styleCB->currentText())); + bool const bibtotoc(bibtocCB->isChecked()); if (bibtotoc && (!bibstyle.empty())) { // both bibtotoc and style @@ -363,7 +349,7 @@ void GuiBibtex::applyView() // 1. sections that include all cited references of the database(s) // 2. sections that include all uncited references of the database(s) // 3. sections that include all references of the database(s), cited or not - int btp = dialog_->btPrintCO->currentIndex(); + int btp = btPrintCO->currentIndex(); switch (btp) { case 0: @@ -382,9 +368,9 @@ void GuiBibtex::applyView() } -bool GuiBibtex::isValid() +bool GuiBibtexDialog::isValid() { - return dialog_->databaseLW->count() != 0; + return databaseLW->count() != 0; } } // namespace frontend diff --git a/src/frontends/qt4/GuiBibtex.h b/src/frontends/qt4/GuiBibtex.h index f18dfa339a..77fef6a21f 100644 --- a/src/frontends/qt4/GuiBibtex.h +++ b/src/frontends/qt4/GuiBibtex.h @@ -12,81 +12,61 @@ #ifndef GUIBIBTEX_H #define GUIBIBTEX_H -#include "GuiDialogView.h" -#include "ButtonController.h" +#include "GuiDialog.h" #include "ControlBibtex.h" +#include "ButtonController.h" #include "ui_BibtexUi.h" #include "ui_BibtexAddUi.h" -#include - namespace lyx { namespace frontend { -class GuiBibtex; - -template -class UiDialog : public QDialog, public UI +class GuiBibtexAddDialog : public QDialog, public Ui::BibtexAddUi { public: - UiDialog(QWidget * parent=0, bool modal=false, Qt::WFlags f=0) - : QDialog(parent, f) + GuiBibtexAddDialog(QWidget * parent) : QDialog(parent) { - UI::setupUi(this); - QDialog::setModal(modal); + Ui::BibtexAddUi::setupUi(this); + QDialog::setModal(true); } }; -class GuiBibtexDialog : public QDialog, public Ui::BibtexUi { +class GuiBibtexDialog : public GuiDialog, public Ui::BibtexUi +{ Q_OBJECT public: - GuiBibtexDialog(GuiBibtex * form); - - UiDialog * add_; - -protected Q_SLOTS: - virtual void change_adaptor(); - virtual void browsePressed(); - virtual void browseBibPressed(); - virtual void addPressed(); - virtual void addDatabase(); - virtual void deletePressed(); - virtual void databaseChanged(); - virtual void availableChanged(); + GuiBibtexDialog(LyXView & lv); + +private Q_SLOTS: + void change_adaptor(); + void browsePressed(); + void browseBibPressed(); + void addPressed(); + void addDatabase(); + void deletePressed(); + void databaseChanged(); + void availableChanged(); void bibEDChanged(); -protected: - virtual void closeEvent(QCloseEvent * e); - private: - GuiBibtex * form_; - ButtonController add_bc_; -}; + void closeEvent(QCloseEvent * e); - -class GuiBibtex : public GuiView -{ -public: - friend class GuiBibtexDialog; - - GuiBibtex(GuiDialog &); - /// parent controller - ControlBibtex & controller() - { return static_cast(this->getController()); } +private: /// parent controller - ControlBibtex const & controller() const - { return static_cast(this->getController()); } -protected: + ControlBibtex & controller() const; + /// virtual bool isValid(); -private: /// Apply changes virtual void applyView(); /// update virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); + + /// + GuiBibtexAddDialog * add_; + /// + ButtonController add_bc_; }; } // namespace frontend diff --git a/src/frontends/qt4/GuiBox.cpp b/src/frontends/qt4/GuiBox.cpp index eee87f8790..9514a7262b 100644 --- a/src/frontends/qt4/GuiBox.cpp +++ b/src/frontends/qt4/GuiBox.cpp @@ -14,6 +14,8 @@ #include "GuiBox.h" +#include "ControlBox.h" + #include "LengthCombo.h" #include "qt_helpers.h" #include "lengthcommon.h" @@ -41,20 +43,29 @@ using std::string; namespace lyx { namespace frontend { -////////////////////////////////////////////////////////////////// -// -// GuiBoxDialog -// -////////////////////////////////////////////////////////////////// -GuiBoxDialog::GuiBoxDialog(GuiBox * form) - : form_(form) +GuiBoxDialog::GuiBoxDialog(LyXView & lv) + : GuiDialog(lv, "box") { setupUi(this); - connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore())); - connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + setViewTitle(_("Box Settings")); + setController(new ControlBox(*this)); + + // fill the box type choice + box_gui_tokens(ids_, gui_names_); + for (unsigned int i = 0; i < gui_names_.size(); ++i) + typeCO->addItem(toqstr(gui_names_[i])); + + // add the special units to the height choice + // width needs different handling + box_gui_tokens_special_length(ids_spec_, gui_names_spec_); + for (unsigned int i = 1; i < gui_names_spec_.size(); ++i) + heightUnitsLC->addItem(toqstr(gui_names_spec_[i])); + + connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore())); + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(widthED, SIGNAL(textChanged(const QString &)), this, SLOT(change_adaptor())); @@ -77,19 +88,46 @@ GuiBoxDialog::GuiBoxDialog(GuiBox * form) heightED->setValidator(unsignedLengthValidator(heightED)); widthED->setValidator(unsignedLengthValidator(widthED)); + + bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); + + bc().addReadOnly(typeCO); + bc().addReadOnly(innerBoxCO); + bc().addReadOnly(valignCO); + bc().addReadOnly(ialignCO); + bc().addReadOnly(halignCO); + bc().addReadOnly(widthED); + bc().addReadOnly(heightED); + bc().addReadOnly(widthUnitsLC); + bc().addReadOnly(heightUnitsLC); + + bc().setRestore(restorePB); + bc().setOK(okPB); + bc().setApply(applyPB); + bc().setCancel(closePB); + + // initialize the length validator + bc().addCheckedLineEdit(widthED, widthLA); + bc().addCheckedLineEdit(heightED, heightLA); +} + + +ControlBox & GuiBoxDialog::controller() const +{ + return static_cast(Dialog::controller()); } void GuiBoxDialog::closeEvent(QCloseEvent * e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } void GuiBoxDialog::change_adaptor() { - form_->changed(); + changed(); } @@ -101,7 +139,7 @@ void GuiBoxDialog::innerBoxChanged(const QString & str) halignCO->setEnabled(!ibox); heightED->setEnabled(ibox); heightUnitsLC->setEnabled(ibox); - form_->setSpecial(ibox); + setSpecial(ibox); } @@ -114,16 +152,16 @@ void GuiBoxDialog::typeChanged(int index) halignCO->setEnabled(false); heightED->setEnabled(true); heightUnitsLC->setEnabled(true); - form_->setSpecial(true); + setSpecial(true); } int itype = innerBoxCO->currentIndex(); - form_->setInnerType(frameless, itype); + setInnerType(frameless, itype); } void GuiBoxDialog::restoreClicked() { - form_->setInnerType(true, 2); + setInnerType(true, 2); widthED->setText("100"); widthUnitsLC->setCurrentItem(Length::PCW); heightED->setText("1"); @@ -134,60 +172,12 @@ void GuiBoxDialog::restoreClicked() } -////////////////////////////////////////////////////////////////// -// -// GuiBox -// -////////////////////////////////////////////////////////////////// - - -GuiBox::GuiBox(GuiDialog & parent) - : GuiView(parent, _("Box Settings")) -{} - - -void GuiBox::build_dialog() -{ - dialog_.reset(new GuiBoxDialog(this)); - - // fill the box type choice - box_gui_tokens(ids_, gui_names_); - for (unsigned int i = 0; i < gui_names_.size(); ++i) - dialog_->typeCO->addItem(toqstr(gui_names_[i])); - - // add the special units to the height choice - // width needs different handling - box_gui_tokens_special_length(ids_spec_, gui_names_spec_); - for (unsigned int i = 1; i < gui_names_spec_.size(); ++i) - dialog_->heightUnitsLC->addItem(toqstr(gui_names_spec_[i])); - - bc().addReadOnly(dialog_->typeCO); - bc().addReadOnly(dialog_->innerBoxCO); - bc().addReadOnly(dialog_->valignCO); - bc().addReadOnly(dialog_->ialignCO); - bc().addReadOnly(dialog_->halignCO); - bc().addReadOnly(dialog_->widthED); - bc().addReadOnly(dialog_->heightED); - bc().addReadOnly(dialog_->widthUnitsLC); - bc().addReadOnly(dialog_->heightUnitsLC); - - bc().setRestore(dialog_->restorePB); - bc().setOK(dialog_->okPB); - bc().setApply(dialog_->applyPB); - bc().setCancel(dialog_->closePB); - - // initialize the length validator - bc().addCheckedLineEdit(dialog_->widthED, dialog_->widthLA); - bc().addCheckedLineEdit(dialog_->heightED, dialog_->heightLA); -} - - -void GuiBox::update_contents() +void GuiBoxDialog::update_contents() { string type(controller().params().type); for (unsigned int i = 0; i < gui_names_.size(); ++i) { if (type == ids_[i]) - dialog_->typeCO->setCurrentIndex(i); + typeCO->setCurrentIndex(i); } // default: minipage @@ -202,22 +192,22 @@ void GuiBox::update_contents() setInnerType(frameless, inner_type); char c = controller().params().pos; - dialog_->valignCO->setCurrentIndex(string("tcb").find(c, 0)); + valignCO->setCurrentIndex(string("tcb").find(c, 0)); c = controller().params().inner_pos; - dialog_->ialignCO->setCurrentIndex(string("tcbs").find(c, 0)); + ialignCO->setCurrentIndex(string("tcbs").find(c, 0)); c = controller().params().hor_pos; - dialog_->halignCO->setCurrentIndex(string("lcrs").find(c, 0)); + halignCO->setCurrentIndex(string("lcrs").find(c, 0)); bool ibox = controller().params().inner_box; - dialog_->valignCO->setEnabled(ibox); - dialog_->ialignCO->setEnabled(ibox); - dialog_->halignCO->setEnabled(!ibox); + valignCO->setEnabled(ibox); + ialignCO->setEnabled(ibox); + halignCO->setEnabled(!ibox); setSpecial(ibox); Length::UNIT default_unit = (lyxrc.default_papersize > 3) ? Length::CM : Length::IN; - lengthToWidgets(dialog_->widthED, dialog_->widthUnitsLC, + lengthToWidgets(widthED, widthUnitsLC, (controller().params().width).asString(), default_unit); string const special(controller().params().special); @@ -227,13 +217,13 @@ void GuiBox::update_contents() if (special == ids_spec_[i]) spc = toqstr(gui_names_spec_[i].c_str()); } - for (int j = 0; j < dialog_->widthUnitsLC->count(); j++) { - if (dialog_->widthUnitsLC->itemText(j) == spc) - dialog_->widthUnitsLC->setCurrentIndex(j); + for (int j = 0; j < widthUnitsLC->count(); j++) { + if (widthUnitsLC->itemText(j) == spc) + widthUnitsLC->setCurrentIndex(j); } } - lengthToWidgets(dialog_->heightED, dialog_->heightUnitsLC, + lengthToWidgets(heightED, heightUnitsLC, (controller().params().height).asString(), default_unit); string const height_special(controller().params().height_special); @@ -244,39 +234,39 @@ void GuiBox::update_contents() hspc = toqstr(gui_names_spec_[i].c_str()); } } - for (int j = 0; j < dialog_->heightUnitsLC->count(); j++) { - if (dialog_->heightUnitsLC->itemText(j) == hspc) { - dialog_->heightUnitsLC->setCurrentIndex(j); + for (int j = 0; j < heightUnitsLC->count(); j++) { + if (heightUnitsLC->itemText(j) == hspc) { + heightUnitsLC->setCurrentIndex(j); } } } - dialog_->heightED->setEnabled(ibox); - dialog_->heightUnitsLC->setEnabled(ibox); + heightED->setEnabled(ibox); + heightUnitsLC->setEnabled(ibox); } -void GuiBox::applyView() +void GuiBoxDialog::applyView() { controller().params().type = - ids_[dialog_->typeCO->currentIndex()]; + ids_[typeCO->currentIndex()]; controller().params().inner_box = - dialog_->innerBoxCO->currentText() != qt_("None"); + innerBoxCO->currentText() != qt_("None"); controller().params().use_parbox = - dialog_->innerBoxCO->currentText() == qt_("Parbox"); + innerBoxCO->currentText() == qt_("Parbox"); controller().params().pos = - "tcb"[dialog_->valignCO->currentIndex()]; + "tcb"[valignCO->currentIndex()]; controller().params().inner_pos = - "tcbs"[dialog_->ialignCO->currentIndex()]; + "tcbs"[ialignCO->currentIndex()]; controller().params().hor_pos = - "lcrs"[dialog_->halignCO->currentIndex()]; + "lcrs"[halignCO->currentIndex()]; int i = 0; bool spec = false; - QString special = dialog_->widthUnitsLC->currentText(); - QString value = dialog_->widthED->text(); + QString special = widthUnitsLC->currentText(); + QString value = widthED->text(); if (special == qt_("Height")) { i = 1; spec = true; @@ -303,14 +293,14 @@ void GuiBox::applyView() // beware: bogosity! the unit is simply ignored in this case width += "in"; } else - width = widgetsToLength(dialog_->widthED, dialog_->widthUnitsLC); + width = widgetsToLength(widthED, widthUnitsLC); controller().params().width = Length(width); i = 0; spec = false; - special = dialog_->heightUnitsLC->currentText(); - value = dialog_->heightED->text(); + special = heightUnitsLC->currentText(); + value = heightED->text(); if (special == qt_("Height")) { i = 1; spec = true; @@ -332,56 +322,56 @@ void GuiBox::applyView() controller().params().height_special = ids_spec_[i]; string height; - if (spec && !isValidLength(fromqstr(dialog_->heightED->text()))) { + if (spec && !isValidLength(fromqstr(heightED->text()))) { height = fromqstr(value); // beware: bogosity! the unit is simply ignored in this case height += "in"; } else - height = widgetsToLength(dialog_->heightED, dialog_->heightUnitsLC); + height = widgetsToLength(heightED, heightUnitsLC); controller().params().height = Length(height); } -void GuiBox::setSpecial(bool ibox) +void GuiBoxDialog::setSpecial(bool ibox) { box_gui_tokens_special_length(ids_spec_, gui_names_spec_); // check if the widget contains the special units - int count = dialog_->widthUnitsLC->count(); + int count = widthUnitsLC->count(); bool has_special = false; for (int i = 0; i < count; i++) - if (dialog_->widthUnitsLC->itemText(i).contains(qt_("Total Height")) > 0) + if (widthUnitsLC->itemText(i).contains(qt_("Total Height")) > 0) has_special = true; // insert 'em if needed... if (!ibox && !has_special) { for (unsigned int i = 1; i < gui_names_spec_.size(); i++) - dialog_->widthUnitsLC->addItem(toqstr(gui_names_spec_[i])); + widthUnitsLC->addItem(toqstr(gui_names_spec_[i])); // ... or remove 'em if needed } else if (ibox && has_special) { - dialog_->widthUnitsLC->clear(); + widthUnitsLC->clear(); for (int i = 0; i < num_units; i++) - dialog_->widthUnitsLC->addItem(qt_(unit_name_gui[i])); + widthUnitsLC->addItem(qt_(unit_name_gui[i])); } } -void GuiBox::setInnerType(bool frameless, int i) +void GuiBoxDialog::setInnerType(bool frameless, int i) { // with "frameless" boxes, inner box is mandatory (i.e. is the actual box) // we have to remove "none" then and adjust the combo if (frameless) { - dialog_->innerBoxCO->clear(); - dialog_->innerBoxCO->addItem(qt_("Parbox")); - dialog_->innerBoxCO->addItem(qt_("Minipage")); - dialog_->innerBoxCO->setCurrentIndex(i - 1); + innerBoxCO->clear(); + innerBoxCO->addItem(qt_("Parbox")); + innerBoxCO->addItem(qt_("Minipage")); + innerBoxCO->setCurrentIndex(i - 1); } else { - if (dialog_->innerBoxCO->count() == 2) + if (innerBoxCO->count() == 2) i += 1; - dialog_->innerBoxCO->clear(); - dialog_->innerBoxCO->addItem(qt_("None")); - dialog_->innerBoxCO->addItem(qt_("Parbox")); - dialog_->innerBoxCO->addItem(qt_("Minipage")); - dialog_->innerBoxCO->setCurrentIndex(i); + innerBoxCO->clear(); + innerBoxCO->addItem(qt_("None")); + innerBoxCO->addItem(qt_("Parbox")); + innerBoxCO->addItem(qt_("Minipage")); + innerBoxCO->setCurrentIndex(i); } } diff --git a/src/frontends/qt4/GuiBox.h b/src/frontends/qt4/GuiBox.h index cba4d4b45d..badaf7eb5d 100644 --- a/src/frontends/qt4/GuiBox.h +++ b/src/frontends/qt4/GuiBox.h @@ -13,60 +13,43 @@ #ifndef GUIBOX_H #define GUIBOX_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlBox.h" #include "ui_BoxUi.h" -#include - #include - namespace lyx { namespace frontend { -class GuiBox; - -class GuiBoxDialog : public QDialog, public Ui::BoxUi { +class GuiBoxDialog : public GuiDialog, public Ui::BoxUi +{ Q_OBJECT + public: - GuiBoxDialog(GuiBox * form); -protected Q_SLOTS: - virtual void change_adaptor(); - virtual void innerBoxChanged(const QString &); - virtual void typeChanged(int); - virtual void restoreClicked(); -protected: - virtual void closeEvent(QCloseEvent * e); -private: - GuiBox * form_; -}; + GuiBoxDialog(LyXView & lv); +private Q_SLOTS: + void change_adaptor(); + void innerBoxChanged(const QString &); + void typeChanged(int); + void restoreClicked(); + +private: + void closeEvent(QCloseEvent * e); -class GuiBox : public GuiView -{ -public: - /// - GuiBox(GuiDialog &); - /// parent controller - ControlBox & controller() - { return static_cast(this->getController()); } /// parent controller - ControlBox const & controller() const - { return static_cast(this->getController()); } + ControlBox & controller() const; /// add and remove special lengths void setSpecial(bool ibox); /// only show valid inner box items void setInnerType(bool frameless, int i); -private: - /// - friend class GuiBoxDialog; + /// Apply changes - virtual void applyView(); + void applyView(); /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); + void update_contents(); + /// std::vector ids_; /// diff --git a/src/frontends/qt4/GuiBranch.cpp b/src/frontends/qt4/GuiBranch.cpp index 17d53df241..eac0eda6d9 100644 --- a/src/frontends/qt4/GuiBranch.cpp +++ b/src/frontends/qt4/GuiBranch.cpp @@ -11,8 +11,10 @@ #include #include "GuiBranch.h" -#include "qt_helpers.h" +#include "ControlBranch.h" + +#include "qt_helpers.h" #include "BranchList.h" #include "insets/InsetBranch.h" @@ -20,70 +22,54 @@ #include #include + namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiBranchDialog -// -///////////////////////////////////////////////////////////////////// - -GuiBranchDialog::GuiBranchDialog(GuiBranch * form) - : form_(form) +GuiBranchDialog::GuiBranchDialog(LyXView & lv) + : GuiDialog(lv, "branch") { setupUi(this); - connect(okPB, SIGNAL(clicked()), - form, SLOT(slotOK())); - connect(closePB, SIGNAL(clicked()), - form, SLOT(slotClose())); - connect(branchCO, SIGNAL( activated(int) ), - this, SLOT( change_adaptor() ) ); -} + setController(new ControlBranch(*this)); + setViewTitle(_("Branch Settings")); + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); + connect(branchCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); -void GuiBranchDialog::closeEvent(QCloseEvent * e) -{ - form_->slotWMHide(); - e->accept(); + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + bc().setOK(okPB); + bc().setCancel(closePB); } -void GuiBranchDialog::change_adaptor() +ControlBranch & GuiBranchDialog::controller() const { - form_->changed(); + return static_cast(Dialog::controller()); } -///////////////////////////////////////////////////////////////////// -// -// GuiBranch -// -///////////////////////////////////////////////////////////////////// - - -GuiBranch::GuiBranch(GuiDialog & parent) - : GuiView(parent, _("Branch Settings")) -{} +void GuiBranchDialog::closeEvent(QCloseEvent * e) +{ + slotWMHide(); + e->accept(); +} -void GuiBranch::build_dialog() +void GuiBranchDialog::change_adaptor() { - dialog_.reset(new GuiBranchDialog(this)); - - bc().setOK(dialog_->okPB); - bc().setCancel(dialog_->closePB); + changed(); } -void GuiBranch::update_contents() +void GuiBranchDialog::update_contents() { typedef BranchList::const_iterator const_iterator; BranchList const & branchlist = controller().branchlist(); docstring const cur_branch = controller().params().branch; - dialog_->branchCO->clear(); + branchCO->clear(); const_iterator const begin = branchlist.begin(); const_iterator const end = branchlist.end(); @@ -91,18 +77,18 @@ void GuiBranch::update_contents() int count = 0; for (const_iterator it = begin; it != end; ++it, ++count) { docstring const & branch = it->getBranch(); - dialog_->branchCO->addItem(toqstr(branch)); + branchCO->addItem(toqstr(branch)); if (cur_branch == branch) id = count; } - dialog_->branchCO->setCurrentIndex(id); + branchCO->setCurrentIndex(id); } -void GuiBranch::applyView() +void GuiBranchDialog::applyView() { - docstring const type = qstring_to_ucs4(dialog_->branchCO->currentText()); + docstring const type = qstring_to_ucs4(branchCO->currentText()); controller().params().branch = type; } diff --git a/src/frontends/qt4/GuiBranch.h b/src/frontends/qt4/GuiBranch.h index c2edce47ad..eb8512132f 100644 --- a/src/frontends/qt4/GuiBranch.h +++ b/src/frontends/qt4/GuiBranch.h @@ -12,54 +12,35 @@ #ifndef GUIBRANCH_H #define GUIBRANCH_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlBranch.h" #include "ui_BranchUi.h" -#include - namespace lyx { namespace frontend { -class GuiBranch; - -class GuiBranchDialog : public QDialog, public Ui::BranchUi { +class GuiBranchDialog : public GuiDialog, public Ui::BranchUi +{ Q_OBJECT + public: - GuiBranchDialog(GuiBranch * form); -protected Q_SLOTS: - virtual void change_adaptor(); -protected: - virtual void closeEvent(QCloseEvent * e); -private: - GuiBranch * form_; -}; + GuiBranchDialog(LyXView & lv); +private Q_SLOTS: + void change_adaptor(); -/** This class provides a QT implementation of the Branch Dialog. - */ -class GuiBranch : public GuiView -{ -public: - /// Constructor - GuiBranch(GuiDialog &); - /// parent controller - ControlBranch & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlBranch const & controller() const - { return static_cast(this->getController()); } private: - friend class GuiBranchDialog; - + /// + void closeEvent(QCloseEvent * e); + /// parent controller + ControlBranch & controller() const; /// Apply changes - virtual void applyView(); - /// Build the dialog - virtual void build_dialog(); + void applyView(); /// Update dialog before showing it - virtual void update_contents(); + void update_contents(); }; + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiBranches.cpp b/src/frontends/qt4/GuiBranches.cpp index dd3cdba6cf..2198506ff5 100644 --- a/src/frontends/qt4/GuiBranches.cpp +++ b/src/frontends/qt4/GuiBranches.cpp @@ -13,12 +13,13 @@ #include "GuiBranches.h" +#include "ControlBranch.h" +#include "ControlDocument.h" #include "GuiApplication.h" #include "Validator.h" #include "qt_helpers.h" #include "BufferParams.h" -#include "controllers/ControlDocument.h" #include "support/lstrings.h" diff --git a/src/frontends/qt4/GuiBranches.h b/src/frontends/qt4/GuiBranches.h index 7e36a120ee..cb97d9364f 100644 --- a/src/frontends/qt4/GuiBranches.h +++ b/src/frontends/qt4/GuiBranches.h @@ -12,8 +12,8 @@ #ifndef GUIBRANCHES_H #define GUIBRANCHES_H -#include "ui_BranchesUi.h" #include "GuiDocument.h" +#include "ui_BranchesUi.h" #include "BranchList.h" #include @@ -30,7 +30,7 @@ class BufferParams; namespace frontend { -class GuiBranches: public QWidget, public Ui::BranchesUi +class GuiBranches : public QWidget, public Ui::BranchesUi { Q_OBJECT public: diff --git a/src/frontends/qt4/GuiChanges.cpp b/src/frontends/qt4/GuiChanges.cpp index 6375e79318..467d47f3dd 100644 --- a/src/frontends/qt4/GuiChanges.cpp +++ b/src/frontends/qt4/GuiChanges.cpp @@ -12,6 +12,8 @@ #include #include "GuiChanges.h" +#include "ControlChanges.h" + #include "qt_helpers.h" #include "support/lstrings.h" @@ -25,73 +27,39 @@ using lyx::support::bformat; namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiChangesDialog -// -///////////////////////////////////////////////////////////////////// - -GuiChangesDialog::GuiChangesDialog(GuiChanges * form) - : form_(form) +GuiChangesDialog::GuiChangesDialog(LyXView & lv) + : GuiDialog(lv, "changes") { setupUi(this); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + setController(new ControlChanges(*this)); + setViewTitle(_("Merge Changes")); + + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(nextPB, SIGNAL(clicked()), this, SLOT(nextPressed())); connect(rejectPB, SIGNAL(clicked()), this, SLOT(rejectPressed())); connect(acceptPB, SIGNAL(clicked()), this, SLOT(acceptPressed())); -} - - -void GuiChangesDialog::nextPressed() -{ - form_->next(); -} - -void GuiChangesDialog::acceptPressed() -{ - form_->accept(); + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + bc().setCancel(closePB); + bc().addReadOnly(acceptPB); + bc().addReadOnly(rejectPB); } -void GuiChangesDialog::rejectPressed() +ControlChanges & GuiChangesDialog::controller() const { - form_->reject(); + return static_cast(Dialog::controller()); } void GuiChangesDialog::closeEvent(QCloseEvent *e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } - -///////////////////////////////////////////////////////////////////// -// -// GuiChanges -// -///////////////////////////////////////////////////////////////////// - - -GuiChanges::GuiChanges(GuiDialog & parent) - : GuiView(parent, _("Merge Changes")) -{ -} - - -void GuiChanges::build_dialog() -{ - dialog_.reset(new GuiChangesDialog(this)); - - bc().setCancel(dialog_->closePB); - bc().addReadOnly(dialog_->acceptPB); - bc().addReadOnly(dialog_->rejectPB); -} - - -void GuiChanges::update_contents() +void GuiChangesDialog::update_contents() { docstring text; docstring author = controller().getChangeAuthor(); @@ -102,23 +70,23 @@ void GuiChanges::update_contents() if (!date.empty()) text += bformat(_("Change made at %1$s\n"), date); - dialog_->changeTB->setPlainText(toqstr(text)); + changeTB->setPlainText(toqstr(text)); } -void GuiChanges::next() +void GuiChangesDialog::nextPressed() { controller().next(); } -void GuiChanges::accept() +void GuiChangesDialog::acceptPressed() { controller().accept(); } -void GuiChanges::reject() +void GuiChangesDialog::rejectPressed() { controller().reject(); } diff --git a/src/frontends/qt4/GuiChanges.h b/src/frontends/qt4/GuiChanges.h index 54e3611066..5fcee96d19 100644 --- a/src/frontends/qt4/GuiChanges.h +++ b/src/frontends/qt4/GuiChanges.h @@ -12,63 +12,29 @@ #ifndef GUICHANGES_H #define GUICHANGES_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlChanges.h" #include "ui_ChangesUi.h" -#include - namespace lyx { namespace frontend { -class GuiChanges; - -class GuiChangesDialog : public QDialog, public Ui::ChangesUi { +class GuiChangesDialog : public GuiDialog, public Ui::ChangesUi +{ Q_OBJECT -public: - - GuiChangesDialog(GuiChanges * form); - -protected Q_SLOTS: - - virtual void nextPressed(); - virtual void acceptPressed(); - virtual void rejectPressed(); - -protected: - virtual void closeEvent(QCloseEvent * e); -private: - GuiChanges * form_; -}; - - -class GuiChanges : public GuiView -{ public: - /// - GuiChanges(GuiDialog &); - /// parent controller - ControlChanges & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlChanges const & controller() const - { return static_cast(this->getController()); } - - void accept(); + GuiChangesDialog(LyXView & lv); - void reject(); - - void next(); +protected Q_SLOTS: + void nextPressed(); + void acceptPressed(); + void rejectPressed(); private: - friend class GuiChangesDialog; - /// Apply changes - virtual void applyView() {}; - /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); + void closeEvent(QCloseEvent * e); + ControlChanges & controller() const; + void update_contents(); }; } // namespace frontend diff --git a/src/frontends/qt4/GuiCharacter.cpp b/src/frontends/qt4/GuiCharacter.cpp index e49e5c3328..35f0a7f1bf 100644 --- a/src/frontends/qt4/GuiCharacter.cpp +++ b/src/frontends/qt4/GuiCharacter.cpp @@ -12,6 +12,8 @@ #include #include "GuiCharacter.h" + +#include "ControlCharacter.h" #include "qt_helpers.h" #include "frontend_helpers.h" #include "Color.h" @@ -23,19 +25,16 @@ using std::vector; namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiCharacterDialog -// -///////////////////////////////////////////////////////////////////// - -GuiCharacterDialog::GuiCharacterDialog(GuiCharacter * form) - : form_(form) +GuiCharacterDialog::GuiCharacterDialog(LyXView & lv) + : GuiDialog(lv, "character") { setupUi(this); - connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose())); + setController(new ControlCharacter(*this)); + setViewTitle(_("Text Style")); + + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(miscCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); connect(sizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); @@ -45,54 +44,6 @@ GuiCharacterDialog::GuiCharacterDialog(GuiCharacter * form) connect(colorCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); connect(langCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); connect(toggleallCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); -} - - -void GuiCharacterDialog::change_adaptor() -{ - form_->changed(); - - if (!autoapplyCB->isChecked()) - return; - - // to be really good here, we should set the combos to the values of - // the current text, and make it appear as "no change" if the values - // stay the same between applys. Might be difficult though wrt to a - // moved cursor - jbl - form_->slotApply(); - familyCO->setCurrentIndex(0); - seriesCO->setCurrentIndex(0); - sizeCO->setCurrentIndex(0); - shapeCO->setCurrentIndex(0); - miscCO->setCurrentIndex(0); - langCO->setCurrentIndex(0); - colorCO->setCurrentIndex(0); -} - - -void GuiCharacterDialog::closeEvent(QCloseEvent * e) -{ - form_->slotWMHide(); - e->accept(); -} - - -///////////////////////////////////////////////////////////////////// -// -// GuiCharacter -// -///////////////////////////////////////////////////////////////////// - - -GuiCharacter::GuiCharacter(GuiDialog & parent) - : GuiView(parent, _("Text Style")) -{ -} - - -void GuiCharacter::build_dialog() -{ - dialog_.reset(new GuiCharacterDialog(this)); family = getFamilyData(); series = getSeriesData(); @@ -104,60 +55,94 @@ void GuiCharacter::build_dialog() for (vector::const_iterator cit = family.begin(); cit != family.end(); ++cit) { - dialog_->familyCO->addItem(toqstr(cit->first)); + familyCO->addItem(toqstr(cit->first)); } for (vector::const_iterator cit = series.begin(); cit != series.end(); ++cit) { - dialog_->seriesCO->addItem(toqstr(cit->first)); + seriesCO->addItem(toqstr(cit->first)); } for (vector::const_iterator cit = shape.begin(); cit != shape.end(); ++cit) { - dialog_->shapeCO->addItem(toqstr(cit->first)); + shapeCO->addItem(toqstr(cit->first)); } for (vector::const_iterator cit = size.begin(); cit != size.end(); ++cit) { - dialog_->sizeCO->addItem(toqstr(cit->first)); + sizeCO->addItem(toqstr(cit->first)); } for (vector::const_iterator cit = bar.begin(); cit != bar.end(); ++cit) { - dialog_->miscCO->addItem(toqstr(cit->first)); + miscCO->addItem(toqstr(cit->first)); } for (vector::const_iterator cit = color.begin(); cit != color.end(); ++cit) { - dialog_->colorCO->addItem(toqstr(cit->first)); + colorCO->addItem(toqstr(cit->first)); } for (vector::const_iterator cit = language.begin(); cit != language.end(); ++cit) { - dialog_->langCO->addItem(toqstr(cit->first)); + langCO->addItem(toqstr(cit->first)); } - bc().setOK(dialog_->okPB); - bc().setApply(dialog_->applyPB); - bc().setCancel(dialog_->closePB); - bc().addReadOnly(dialog_->familyCO); - bc().addReadOnly(dialog_->seriesCO); - bc().addReadOnly(dialog_->sizeCO); - bc().addReadOnly(dialog_->shapeCO); - bc().addReadOnly(dialog_->miscCO); - bc().addReadOnly(dialog_->langCO); - bc().addReadOnly(dialog_->colorCO); - bc().addReadOnly(dialog_->toggleallCB); - bc().addReadOnly(dialog_->autoapplyCB); + bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); + bc().setOK(okPB); + bc().setApply(applyPB); + bc().setCancel(closePB); + bc().addReadOnly(familyCO); + bc().addReadOnly(seriesCO); + bc().addReadOnly(sizeCO); + bc().addReadOnly(shapeCO); + bc().addReadOnly(miscCO); + bc().addReadOnly(langCO); + bc().addReadOnly(colorCO); + bc().addReadOnly(toggleallCB); + bc().addReadOnly(autoapplyCB); // FIXME: hack to work around resizing bug in Qt >= 4.2 // bug verified with Qt 4.2.{0-3} (JSpitzm) #if QT_VERSION >= 0x040200 // qt resizes the comboboxes only after show(), so ... - dialog_->show(); + QDialog::show(); #endif } -namespace { +ControlCharacter & GuiCharacterDialog::controller() const +{ + return static_cast(Dialog::controller()); +} + + +void GuiCharacterDialog::change_adaptor() +{ + changed(); + + if (!autoapplyCB->isChecked()) + return; + + // to be really good here, we should set the combos to the values of + // the current text, and make it appear as "no change" if the values + // stay the same between applys. Might be difficult though wrt to a + // moved cursor - jbl + slotApply(); + familyCO->setCurrentIndex(0); + seriesCO->setCurrentIndex(0); + sizeCO->setCurrentIndex(0); + shapeCO->setCurrentIndex(0); + miscCO->setCurrentIndex(0); + langCO->setCurrentIndex(0); + colorCO->setCurrentIndex(0); +} + + +void GuiCharacterDialog::closeEvent(QCloseEvent * e) +{ + slotWMHide(); + e->accept(); +} + template -int findPos2nd(vector > const & vec, B const & val) +static int findPos2nd(vector > const & vec, B const & val) { typedef typename vector >::const_iterator const_iterator; @@ -170,41 +155,39 @@ int findPos2nd(vector > const & vec, B const & val) return 0; } -} // namespace anon - -void GuiCharacter::update_contents() +void GuiCharacterDialog::update_contents() { ControlCharacter const & ctrl = controller(); - dialog_->familyCO->setCurrentIndex(findPos2nd(family, + familyCO->setCurrentIndex(findPos2nd(family, ctrl.getFamily())); - dialog_->seriesCO->setCurrentIndex(findPos2nd(series, + seriesCO->setCurrentIndex(findPos2nd(series, ctrl.getSeries())); - dialog_->shapeCO->setCurrentIndex(findPos2nd(shape, ctrl.getShape())); - dialog_->sizeCO->setCurrentIndex(findPos2nd(size, ctrl.getSize())); - dialog_->miscCO->setCurrentIndex(findPos2nd(bar, ctrl.getBar())); - dialog_->colorCO->setCurrentIndex(findPos2nd(color, ctrl.getColor())); - dialog_->langCO->setCurrentIndex(findPos2nd(language, + shapeCO->setCurrentIndex(findPos2nd(shape, ctrl.getShape())); + sizeCO->setCurrentIndex(findPos2nd(size, ctrl.getSize())); + miscCO->setCurrentIndex(findPos2nd(bar, ctrl.getBar())); + colorCO->setCurrentIndex(findPos2nd(color, ctrl.getColor())); + langCO->setCurrentIndex(findPos2nd(language, ctrl.getLanguage())); - dialog_->toggleallCB->setChecked(ctrl.getToggleAll()); + toggleallCB->setChecked(ctrl.getToggleAll()); } -void GuiCharacter::applyView() +void GuiCharacterDialog::applyView() { ControlCharacter & ctrl = controller(); - ctrl.setFamily(family[dialog_->familyCO->currentIndex()].second); - ctrl.setSeries(series[dialog_->seriesCO->currentIndex()].second); - ctrl.setShape(shape[dialog_->shapeCO->currentIndex()].second); - ctrl.setSize(size[dialog_->sizeCO->currentIndex()].second); - ctrl.setBar(bar[dialog_->miscCO->currentIndex()].second); - ctrl.setColor(color[dialog_->colorCO->currentIndex()].second); - ctrl.setLanguage(language[dialog_->langCO->currentIndex()].second); + ctrl.setFamily(family[familyCO->currentIndex()].second); + ctrl.setSeries(series[seriesCO->currentIndex()].second); + ctrl.setShape(shape[shapeCO->currentIndex()].second); + ctrl.setSize(size[sizeCO->currentIndex()].second); + ctrl.setBar(bar[miscCO->currentIndex()].second); + ctrl.setColor(color[colorCO->currentIndex()].second); + ctrl.setLanguage(language[langCO->currentIndex()].second); - ctrl.setToggleAll(dialog_->toggleallCB->isChecked()); + ctrl.setToggleAll(toggleallCB->isChecked()); } } // namespace frontend diff --git a/src/frontends/qt4/GuiCharacter.h b/src/frontends/qt4/GuiCharacter.h index 5f0145c066..512a3e331e 100644 --- a/src/frontends/qt4/GuiCharacter.h +++ b/src/frontends/qt4/GuiCharacter.h @@ -13,51 +13,33 @@ #ifndef GUICHARACTER_H #define GUICHARACTER_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlCharacter.h" #include "ui_CharacterUi.h" -#include - #include namespace lyx { namespace frontend { -class GuiCharacter; - -class GuiCharacterDialog : public QDialog, public Ui::CharacterUi { +class GuiCharacterDialog : public GuiDialog, public Ui::CharacterUi +{ Q_OBJECT + public: - GuiCharacterDialog(GuiCharacter * form); -protected: - void closeEvent(QCloseEvent * e); -private: - GuiCharacter * form_; + GuiCharacterDialog(LyXView & lv); + protected Q_SLOTS: void change_adaptor(); -}; - -class GuiCharacter : public GuiView -{ -public: - friend class GuiCharacterDialog; - - GuiCharacter(GuiDialog &); - /// parent controller - ControlCharacter & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlCharacter const & controller() const - { return static_cast(this->getController()); } private: + void closeEvent(QCloseEvent * e); + /// parent controller + ControlCharacter & controller() const; /// Apply changes - virtual void applyView(); + void applyView(); /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); + void update_contents(); std::vector family; std::vector series; diff --git a/src/frontends/qt4/GuiCitation.cpp b/src/frontends/qt4/GuiCitation.cpp index f932d1efac..d8835c56ec 100644 --- a/src/frontends/qt4/GuiCitation.cpp +++ b/src/frontends/qt4/GuiCitation.cpp @@ -38,6 +38,9 @@ using std::vector; using std::string; +namespace lyx { +namespace frontend { + template static QStringList to_qstring_list(vector const & v) { @@ -64,20 +67,12 @@ static vector to_docstring_vector(QStringList const & qlist) } -namespace lyx { -namespace frontend { - -/////////////////////////////////////////////////////////////////////// -// -// GuiCitationDialog -// -/////////////////////////////////////////////////////////////////////// - - -GuiCitationDialog::GuiCitationDialog(Dialog & dialog, GuiCitation * form) - : Dialog::View(dialog, _("Citation")), form_(form) +GuiCitationDialog::GuiCitationDialog(LyXView & lv) + : GuiDialog(lv, "citation") { setupUi(this); + setViewTitle(_("Citation")); + setController(new ControlCitation(*this)); setWindowTitle(toqstr("LyX: " + getViewTitle())); @@ -97,8 +92,7 @@ GuiCitationDialog::GuiCitationDialog(Dialog & dialog, GuiCitation * form) selectionManager = new GuiSelectionManager(availableLV, selectedLV, - addPB, deletePB, upPB, downPB, - form_->available(), form_->selected()); + addPB, deletePB, upPB, downPB, available(), selected()); connect(selectionManager, SIGNAL(selectionChanged()), this, SLOT(setCitedKeys())); connect(selectionManager, SIGNAL(updateHook()), @@ -106,25 +100,28 @@ GuiCitationDialog::GuiCitationDialog(Dialog & dialog, GuiCitation * form) connect(selectionManager, SIGNAL(okHook()), this, SLOT(on_okPB_clicked())); + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); } -GuiCitationDialog::~GuiCitationDialog() -{} +ControlCitation & GuiCitationDialog::controller() const +{ + return static_cast(Dialog::controller()); +} void GuiCitationDialog::cleanUp() { - form_->clearSelection(); - form_->clearParams(); + clearSelection(); + controller().clearParams(); close(); } void GuiCitationDialog::closeEvent(QCloseEvent * e) { - form_->clearSelection(); - form_->clearParams(); + clearSelection(); + controller().clearParams(); e->accept(); } @@ -139,13 +136,13 @@ void GuiCitationDialog::applyView() QString const before = textBeforeED->text(); QString const after = textAfterED->text(); - form_->apply(choice, full, force, before, after); + apply(choice, full, force, before, after); } void GuiCitationDialog::hideView() { - form_->clearParams(); + controller().clearParams(); accept(); } @@ -169,15 +166,15 @@ bool GuiCitationDialog::isVisibleView() const void GuiCitationDialog::on_okPB_clicked() { applyView(); - form_->clearSelection(); + clearSelection(); hideView(); } void GuiCitationDialog::on_cancelPB_clicked() { - form_->clearSelection(); - hide(); + clearSelection(); + hideView(); } @@ -189,8 +186,8 @@ void GuiCitationDialog::on_applyPB_clicked() void GuiCitationDialog::on_restorePB_clicked() { - form_->init(); - update(); + init(); + updateView(); } @@ -202,12 +199,12 @@ void GuiCitationDialog::updateView() } -//The main point of separating this out is that the fill*() methods -//called in update() do not need to be called for INTERNAL updates, -//such as when addPB is pressed, as the list of fields, entries, etc, -//will not have changed. At the moment, however, the division between -//fillStyles() and updateStyles() doesn't lend itself to dividing the -//two methods, though they should be divisible. +// The main point of separating this out is that the fill*() methods +// called in update() do not need to be called for INTERNAL updates, +// such as when addPB is pressed, as the list of fields, entries, etc, +// will not have changed. At the moment, however, the division between +// fillStyles() and updateStyles() doesn't lend itself to dividing the +// two methods, though they should be divisible. void GuiCitationDialog::updateDialog() { if (selectionManager->selectedFocused()) { @@ -223,8 +220,8 @@ void GuiCitationDialog::updateDialog() } setButtons(); - textBeforeED->setText(form_->textBefore()); - textAfterED->setText(form_->textAfter()); + textBeforeED->setText(textBefore()); + textAfterED->setText(textAfter()); fillStyles(); updateStyle(); } @@ -232,7 +229,7 @@ void GuiCitationDialog::updateDialog() void GuiCitationDialog::updateStyle() { - biblio::CiteEngine const engine = form_->getEngine(); + biblio::CiteEngine const engine = controller().getEngine(); bool const natbib_engine = engine == biblio::ENGINE_NATBIB_AUTHORYEAR || engine == biblio::ENGINE_NATBIB_NUMERICAL; @@ -249,7 +246,7 @@ void GuiCitationDialog::updateStyle() citationStyleCO->setEnabled(!basic_engine && haveSelection); citationStyleLA->setEnabled(!basic_engine && haveSelection); - string const & command = form_->params().getCmdName(); + string const & command = controller().params().getCmdName(); // Find the style of the citekeys vector const & styles = @@ -286,7 +283,7 @@ void GuiCitationDialog::fillStyles() citationStyleCO->clear(); - QStringList selected_keys = form_->selected()->stringList(); + QStringList selected_keys = selected()->stringList(); if (selected_keys.empty()) { citationStyleCO->setEnabled(false); citationStyleLA->setEnabled(false); @@ -300,10 +297,10 @@ void GuiCitationDialog::fillStyles() if (!selectedLV->selectionModel()->selectedIndexes().empty()) curr = selectedLV->selectionModel()->selectedIndexes()[0].row(); - QStringList sty = form_->citationStyles(curr); + QStringList sty = citationStyles(curr); bool const basic_engine = - (form_->getEngine() == biblio::ENGINE_BASIC); + (controller().getEngine() == biblio::ENGINE_BASIC); citationStyleCO->setEnabled(!sty.isEmpty() && !basic_engine); citationStyleLA->setEnabled(!sty.isEmpty() && !basic_engine); @@ -323,7 +320,7 @@ void GuiCitationDialog::fillFields() fieldsCO->blockSignals(true); int const oldIndex = fieldsCO->currentIndex(); fieldsCO->clear(); - QStringList const & fields = form_->getFieldsAsQStringList(); + QStringList const & fields = getFieldsAsQStringList(); fieldsCO->insertItem(0, qt_("All Fields")); fieldsCO->insertItem(1, qt_("Keys")); fieldsCO->insertItems(2, fields); @@ -338,7 +335,7 @@ void GuiCitationDialog::fillEntries() entriesCO->blockSignals(true); int const oldIndex = entriesCO->currentIndex(); entriesCO->clear(); - QStringList const & entries = form_->getEntriesAsQStringList(); + QStringList const & entries = getEntriesAsQStringList(); entriesCO->insertItem(0, qt_("All Entry Types")); entriesCO->insertItems(1, entries); if (oldIndex != -1 && oldIndex < entriesCO->count()) @@ -350,7 +347,7 @@ void GuiCitationDialog::fillEntries() bool GuiCitationDialog::isSelected(const QModelIndex & idx) { QString const str = idx.data().toString(); - return form_->selected()->stringList().contains(str); + return selected()->stringList().contains(str); } @@ -366,24 +363,18 @@ void GuiCitationDialog::setButtons() void GuiCitationDialog::updateInfo(QModelIndex const & idx) { if (idx.isValid()) { - QString const keytxt = form_->getKeyInfo(idx.data().toString()); + QString const keytxt = getKeyInfo(idx.data().toString()); infoML->document()->setPlainText(keytxt); } else infoML->document()->clear(); } -void GuiCitationDialog::setCitedKeys() -{ - form_->setCitedKeys(); -} - - void GuiCitationDialog::findText(QString const & text, bool reset) { //"All Fields" and "Keys" are the first two int index = fieldsCO->currentIndex() - 2; - vector const & fields = form_->availableFields(); + vector const & fields = controller().availableFields(); docstring field; if (index <= -1 || index >= int(fields.size())) @@ -397,7 +388,7 @@ void GuiCitationDialog::findText(QString const & text, bool reset) //"All Entry Types" is first. index = entriesCO->currentIndex() - 1; - vector const & entries = form_->availableEntries(); + vector const & entries = controller().availableEntries(); docstring entryType; if (index < 0 || index >= int(entries.size())) entryType = from_ascii(""); @@ -406,7 +397,7 @@ void GuiCitationDialog::findText(QString const & text, bool reset) bool const case_sentitive = caseCB->checkState(); bool const reg_exp = regexCB->checkState(); - form_->findKey(text, onlyKeys, field, entryType, + findKey(text, onlyKeys, field, entryType, case_sentitive, reg_exp, reset); //FIXME //It'd be nice to save and restore the current selection in @@ -456,20 +447,10 @@ void GuiCitationDialog::changed() setButtons(); } -/////////////////////////////////////////////////////////////////////// -// -// GuiCitation -// -/////////////////////////////////////////////////////////////////////// -GuiCitation::GuiCitation(GuiDialog & parent) - : ControlCitation(parent) -{ -} - - -void GuiCitation::apply(int const choice, bool const full, bool const force, - QString before, QString after) +void GuiCitationDialog::apply(int const choice, + bool const full, bool const force, + QString before, QString after) { if (cited_keys_.isEmpty()) return; @@ -481,50 +462,50 @@ void GuiCitation::apply(int const choice, bool const full, bool const force, biblio::CitationStyle(styles[choice], full, force) .asLatexStr(); - params().setCmdName(command); - params()["key"] = qstring_to_ucs4(cited_keys_.join(",")); - params()["before"] = qstring_to_ucs4(before); - params()["after"] = qstring_to_ucs4(after); - dispatchParams(); + controller().params().setCmdName(command); + controller().params()["key"] = qstring_to_ucs4(cited_keys_.join(",")); + controller().params()["before"] = qstring_to_ucs4(before); + controller().params()["after"] = qstring_to_ucs4(after); + controller().dispatchParams(); } -void GuiCitation::clearSelection() +void GuiCitationDialog::clearSelection() { cited_keys_.clear(); selected_model_.setStringList(cited_keys_); } -QString GuiCitation::textBefore() +QString GuiCitationDialog::textBefore() { - return toqstr(params()["before"]); + return toqstr(controller().params()["before"]); } -QString GuiCitation::textAfter() +QString GuiCitationDialog::textAfter() { - return toqstr(params()["after"]); + return toqstr(controller().params()["after"]); } -bool GuiCitation::initialiseParams(std::string const & data) +bool GuiCitationDialog::initialiseParams(std::string const & data) { - if (!ControlCitation::initialiseParams(data)) + if (!controller().initialiseParams(data)) return false; init(); return true; } -void GuiCitation::init() +void GuiCitationDialog::init() { // Make the list of all available bibliography keys - all_keys_ = to_qstring_list(availableKeys()); + all_keys_ = to_qstring_list(controller().availableKeys()); available_model_.setStringList(all_keys_); // Ditto for the keys cited in this inset - QString str = toqstr(params()["key"]); + QString str = toqstr(controller().params()["key"]); if (str.isEmpty()) cited_keys_.clear(); else @@ -533,7 +514,7 @@ void GuiCitation::init() } -void GuiCitation::findKey(QString const & str, bool only_keys, +void GuiCitationDialog::findKey(QString const & str, bool only_keys, docstring field, docstring entryType, bool case_sensitive, bool reg_exp, bool reset) { @@ -573,43 +554,44 @@ void GuiCitation::findKey(QString const & str, bool only_keys, // First, filter by entryType, which will be faster than // what follows, so we may get to do that on less. vector keyVector = to_docstring_vector(keys); - filterByEntryType(keyVector, entryType); + controller().filterByEntryType(keyVector, entryType); if (str.isEmpty()) result = to_qstring_list(keyVector); else - result = to_qstring_list(searchKeys(keyVector, only_keys, + result = to_qstring_list(controller().searchKeys(keyVector, only_keys, qstring_to_ucs4(str), field, case_sensitive, reg_exp)); available_model_.setStringList(result); } -QStringList GuiCitation::getFieldsAsQStringList() +QStringList GuiCitationDialog::getFieldsAsQStringList() { - return to_qstring_list(availableFields()); + return to_qstring_list(controller().availableFields()); } -QStringList GuiCitation::getEntriesAsQStringList() +QStringList GuiCitationDialog::getEntriesAsQStringList() { - return to_qstring_list(availableEntries()); + return to_qstring_list(controller().availableEntries()); } -QStringList GuiCitation::citationStyles(int sel) +QStringList GuiCitationDialog::citationStyles(int sel) { docstring const key = qstring_to_ucs4(cited_keys_[sel]); - return to_qstring_list(getCiteStrings(key)); + return to_qstring_list(controller().getCiteStrings(key)); } -QString GuiCitation::getKeyInfo(QString const & sel) +QString GuiCitationDialog::getKeyInfo(QString const & sel) { - return toqstr(getInfo(qstring_to_ucs4(sel))); + return toqstr(controller().getInfo(qstring_to_ucs4(sel))); } -void GuiCitation::setCitedKeys() + +void GuiCitationDialog::setCitedKeys() { cited_keys_ = selected_model_.stringList(); } diff --git a/src/frontends/qt4/GuiCitation.h b/src/frontends/qt4/GuiCitation.h index c2ba5ebd0d..339da17822 100644 --- a/src/frontends/qt4/GuiCitation.h +++ b/src/frontends/qt4/GuiCitation.h @@ -16,9 +16,9 @@ #define GUICITATION_H #include "GuiDialog.h" +#include "ControlCitation.h" #include "GuiSelectionManager.h" #include "ui_CitationUi.h" -#include "ControlCitation.h" #include "support/docstring.h" #include @@ -28,29 +28,22 @@ namespace lyx { namespace frontend { -class GuiCitation; - -class GuiCitationDialog : public QDialog, - public Ui::CitationUi, public Dialog::View +class GuiCitationDialog : public GuiDialog, public Ui::CitationUi { Q_OBJECT public: - GuiCitationDialog(Dialog &, GuiCitation * form ); - - virtual ~GuiCitationDialog(); - - virtual void applyView(); + /// + GuiCitationDialog(LyXView & lv); + /// + void applyView(); /// Hide the dialog from sight void hideView(); - /// Redraw the dialog (e.g. if the colors have been remapped). void redrawView() {} - /// Create the dialog if necessary, update it and display it. void showView(); - /// \return true if the dialog is visible. bool isVisibleView() const; @@ -58,7 +51,10 @@ public Q_SLOTS: /// Update the display of the dialog whilst it is still visible. void updateView(); -protected: +private: + /// + ControlCitation & controller() const; + /// void closeEvent(QCloseEvent * e); /// prepares a call to GuiCitation::searchKeys when we /// are ready to search the BibTeX entries @@ -68,7 +64,7 @@ protected: /// update the display of BibTeX information void updateInfo(QModelIndex const &); -protected Q_SLOTS: +private Q_SLOTS: void cleanUp(); void on_okPB_clicked(); void on_cancelPB_clicked(); @@ -79,7 +75,7 @@ protected Q_SLOTS: void on_entriesCO_currentIndexChanged(int index); void on_caseCB_stateChanged(int); void on_regexCB_stateChanged(int); - virtual void changed(); + void changed(); /// void setCitedKeys(); /// performs a limited update, suitable for internal call @@ -99,19 +95,10 @@ private: /// last used citation style int style_; - GuiCitation * form_; - GuiSelectionManager * selectionManager; -}; - -class GuiCitation : public ControlCitation -{ -public: /// - GuiCitation(GuiDialog &); - virtual ~GuiCitation() {} - virtual bool initialiseParams(std::string const & data); + bool initialiseParams(std::string const & data); /// void init(); @@ -155,10 +142,8 @@ public: QStringList citationStyles(int); /// Set the Params variable for the Controller. - virtual void apply(int const choice, bool const full, bool const force, + void apply(int const choice, bool const full, bool const force, QString before, QString after); - - void setCitedKeys(); private: /// available keys. diff --git a/src/frontends/qt4/GuiCommandBuffer.h b/src/frontends/qt4/GuiCommandBuffer.h index 6ed08f6cbe..fddb3f58b7 100644 --- a/src/frontends/qt4/GuiCommandBuffer.h +++ b/src/frontends/qt4/GuiCommandBuffer.h @@ -23,8 +23,10 @@ namespace frontend { class GuiCommandEdit; -class GuiCommandBuffer : public QWidget { +class GuiCommandBuffer : public QWidget +{ Q_OBJECT + public: GuiCommandBuffer(GuiViewBase * view); diff --git a/src/frontends/qt4/GuiCommandEdit.h b/src/frontends/qt4/GuiCommandEdit.h index f3587744a0..5968b6fbd0 100644 --- a/src/frontends/qt4/GuiCommandEdit.h +++ b/src/frontends/qt4/GuiCommandEdit.h @@ -19,7 +19,8 @@ namespace lyx { namespace frontend { -class GuiCommandEdit : public QLineEdit { +class GuiCommandEdit : public QLineEdit +{ Q_OBJECT public: diff --git a/src/frontends/qt4/GuiDelimiter.cpp b/src/frontends/qt4/GuiDelimiter.cpp index e93682b81f..6e50782e1d 100644 --- a/src/frontends/qt4/GuiDelimiter.cpp +++ b/src/frontends/qt4/GuiDelimiter.cpp @@ -30,21 +30,22 @@ using std::string; namespace lyx { namespace frontend { -namespace { +static QString const bigleft[] = {"", "bigl", "Bigl", "biggl", "Biggl"}; -QString const bigleft[] = {"", "bigl", "Bigl", "biggl", "Biggl"}; +static QString const bigright[] = {"", "bigr", "Bigr", "biggr", "Biggr"}; - -QString const bigright[] = {"", "bigr", "Bigr", "biggr", "Biggr"}; - - -char const * const biggui[] = {N_("big[[delimiter size]]"), N_("Big[[delimiter size]]"), - N_("bigg[[delimiter size]]"), N_("Bigg[[delimiter size]]"), ""}; +static char const * const biggui[] = { + N_("big[[delimiter size]]"), + N_("Big[[delimiter size]]"), + N_("bigg[[delimiter size]]"), + N_("Bigg[[delimiter size]]"), + "" +}; // FIXME: It might be better to fix the big delim LFUN to not require // additional '\' prefix. -QString fix_name(QString const & str, bool big) +static QString fix_name(QString const & str, bool big) { if (str.isEmpty()) return "."; @@ -55,50 +56,13 @@ QString fix_name(QString const & str, bool big) return "\\" + str; } -} // namespace anon - - -GuiDelimiter::GuiDelimiter(GuiDialog & parent) - : GuiView(parent, _("Math Delimiter")) -{} - - -void GuiDelimiter::build_dialog() -{ - dialog_.reset(new GuiDelimiterDialog(this, - static_cast(controller().view()))); -} - - -char_type GuiDelimiterDialog::doMatch(char_type const symbol) const -{ - string const & str = form_->controller().texName(symbol); - string match; - if (str == "(") match = ")"; - else if (str == ")") match = "("; - else if (str == "[") match = "]"; - else if (str == "]") match = "["; - else if (str == "{") match = "}"; - else if (str == "}") match = "{"; - else if (str == "l") match = "r"; - else if (str == "rceil") match = "lceil"; - else if (str == "lceil") match = "rceil"; - else if (str == "rfloor") match = "lfloor"; - else if (str == "lfloor") match = "rfloor"; - else if (str == "rangle") match = "langle"; - else if (str == "langle") match = "rangle"; - else if (str == "backslash") match = "/"; - else if (str == "/") match = "backslash"; - else return symbol; - - return form_->controller().mathSymbol(match).unicode; -} - -GuiDelimiterDialog::GuiDelimiterDialog(GuiDelimiter * form, QWidget * parent) - : QDialog(parent), form_(form) +GuiDelimiterDialog::GuiDelimiterDialog(LyXView & lv) + : GuiDialog(lv, "mathdelimiter") { setupUi(this); + setViewTitle(_("Math Delimiter")); + setController(new ControlMath(*this)); connect(closePB, SIGNAL(clicked()), this, SLOT(accept())); @@ -114,7 +78,7 @@ GuiDelimiterDialog::GuiDelimiterDialog(GuiDelimiter * form, QWidget * parent) int const end = nr_latex_delimiters - 1; for (int i = 0; i < end; ++i) { string const delim = latex_delimiters[i]; - MathSymbol const & ms = form_->controller().mathSymbol(delim); + MathSymbol const & ms = controller().mathSymbol(delim); QString symbol(ms.fontcode? QChar(ms.fontcode) : toqstr(docstring(1, ms.unicode))); QListWidgetItem * lwi = new QListWidgetItem(symbol); @@ -128,7 +92,7 @@ GuiDelimiterDialog::GuiDelimiterDialog(GuiDelimiter * form, QWidget * parent) } for (int i = 0; i != leftLW->count(); ++i) { - MathSymbol const & ms = form_->controller().mathSymbol( + MathSymbol const & ms = controller().mathSymbol( fromqstr(leftLW->item(i)->toolTip())); rightLW->addItem(list_items[doMatch(ms.unicode)]->clone()); } @@ -143,6 +107,38 @@ GuiDelimiterDialog::GuiDelimiterDialog(GuiDelimiter * form, QWidget * parent) sizeCO->addItem(qt_(biggui[i])); on_leftLW_currentRowChanged(0); + bc().setPolicy(ButtonPolicy::IgnorantPolicy); +} + + +ControlMath & GuiDelimiterDialog::controller() const +{ + return static_cast(GuiDialog::controller()); +} + + +char_type GuiDelimiterDialog::doMatch(char_type const symbol) const +{ + string const & str = controller().texName(symbol); + string match; + if (str == "(") match = ")"; + else if (str == ")") match = "("; + else if (str == "[") match = "]"; + else if (str == "]") match = "["; + else if (str == "{") match = "}"; + else if (str == "}") match = "{"; + else if (str == "l") match = "r"; + else if (str == "rceil") match = "lceil"; + else if (str == "lceil") match = "rceil"; + else if (str == "rfloor") match = "lfloor"; + else if (str == "lfloor") match = "rfloor"; + else if (str == "rangle") match = "langle"; + else if (str == "langle") match = "rangle"; + else if (str == "backslash") match = "/"; + else if (str == "/") match = "backslash"; + else return symbol; + + return controller().mathSymbol(match).unicode; } @@ -187,11 +183,11 @@ void GuiDelimiterDialog::updateTeXCode(int size) void GuiDelimiterDialog::on_insertPB_clicked() { if (sizeCO->currentIndex() == 0) - form_->controller().dispatchDelim(fromqstr(tex_code_)); + controller().dispatchDelim(fromqstr(tex_code_)); else { QString command = '"' + tex_code_ + '"'; command.replace(' ', "\" \""); - form_->controller().dispatchBigDelim(fromqstr(command)); + controller().dispatchBigDelim(fromqstr(command)); } } diff --git a/src/frontends/qt4/GuiDelimiter.h b/src/frontends/qt4/GuiDelimiter.h index 67ffdb7165..e3724500b1 100644 --- a/src/frontends/qt4/GuiDelimiter.h +++ b/src/frontends/qt4/GuiDelimiter.h @@ -12,7 +12,7 @@ #ifndef GUIDELIMITERDIALOG_H #define GUIDELIMITERDIALOG_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlMath.h" #include "ui_DelimiterUi.h" @@ -21,14 +21,13 @@ class QListWidgetItem; namespace lyx { namespace frontend { -class ControlMath; -class GuiDelimiter; - -class GuiDelimiterDialog : public QDialog, public Ui::DelimiterUi +class GuiDelimiterDialog : public GuiDialog, public Ui::DelimiterUi { Q_OBJECT + public: - GuiDelimiterDialog(GuiDelimiter * form, QWidget * parent); + GuiDelimiterDialog(LyXView & lv); + public Q_SLOTS: void on_leftLW_itemActivated(QListWidgetItem *); void on_rightLW_itemActivated(QListWidgetItem *); @@ -37,38 +36,19 @@ public Q_SLOTS: void on_matchCB_stateChanged(int); void on_insertPB_clicked(); void on_sizeCO_activated(int); + private: /// char_type doMatch(char_type const symbol) const; /// void updateTeXCode(int size); - /// owning form - GuiDelimiter * form_; + /// parent controller + ControlMath & controller() const; + /// TeX code that will be inserted. QString tex_code_; }; - -class GuiDelimiter : public GuiView -{ -public: - friend class GuiDelimiterDialog; - /// - GuiDelimiter(GuiDialog &); - /// parent controller - ControlMath & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlMath const & controller() const - { return static_cast(this->getController()); } -private: - virtual void applyView() {} - virtual void update_contents() {} - /// Build the dialog. - virtual void build_dialog(); -}; - - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiDialog.cpp b/src/frontends/qt4/GuiDialog.cpp index a46c9ce1ea..dad989fcae 100644 --- a/src/frontends/qt4/GuiDialog.cpp +++ b/src/frontends/qt4/GuiDialog.cpp @@ -12,7 +12,7 @@ #include "GuiDialog.h" #include "debug.h" - +#include "qt_helpers.h" namespace lyx { namespace frontend { @@ -40,14 +40,14 @@ void GuiDialog::OKButton() is_closing_ = true; apply(); is_closing_ = false; - hide(); + QDialog::hide(); bc().ok(); } void GuiDialog::CancelButton() { - hide(); + QDialog::hide(); bc().cancel(); } @@ -117,5 +117,104 @@ void GuiDialog::checkStatus() } } + +bool GuiDialog::isVisibleView() const +{ + return QDialog::isVisible(); +} + + +bool GuiDialog::readOnly() const +{ + return kernel().isBufferReadonly(); +} + + +void GuiDialog::showView() +{ + QSize const hint = sizeHint(); + if (hint.height() >= 0 && hint.width() >= 0) + setMinimumSize(hint); + + updateView(); // make sure its up-to-date + if (controller().exitEarly()) + return; + + setWindowTitle(toqstr("LyX: " + getViewTitle())); + + if (QWidget::isVisible()) { + raise(); + activateWindow(); + } else { + QWidget::show(); + } + setFocus(); +} + + +void GuiDialog::hideView() +{ + QDialog::hide(); +} + + +bool GuiDialog::isValid() +{ + return true; +} + + +void GuiDialog::changed() +{ + if (updating_) + return; + bc().setValid(isValid()); +} + + +void GuiDialog::slotWMHide() +{ + CancelButton(); +} + + +void GuiDialog::slotApply() +{ + ApplyButton(); +} + + +void GuiDialog::slotOK() +{ + OKButton(); +} + + +void GuiDialog::slotClose() +{ + CancelButton(); +} + + +void GuiDialog::slotRestore() +{ + RestoreButton(); +} + +void GuiDialog::updateView() +{ + setUpdatesEnabled(false); + + // protect the BC from unwarranted state transitions + updating_ = true; + update_contents(); + updating_ = false; + + setUpdatesEnabled(true); + QDialog::update(); +} + } // namespace frontend } // namespace lyx + +#include "GuiDialog_moc.cpp" diff --git a/src/frontends/qt4/GuiDialog.h b/src/frontends/qt4/GuiDialog.h index db52058e65..dbc32e1a27 100644 --- a/src/frontends/qt4/GuiDialog.h +++ b/src/frontends/qt4/GuiDialog.h @@ -15,20 +15,39 @@ #include "Dialog.h" #include "ButtonController.h" +#include +#include + namespace lyx { namespace frontend { /** \c Dialog collects the different parts of a Model-Controller-View * split of a generic dialog together. */ -class GuiDialog : public Dialog +class GuiDialog : public QDialog, public Dialog { + Q_OBJECT + public: /// \param lv is the access point for the dialog to the LyX kernel. /// \param name is the identifier given to the dialog by its parent /// container. GuiDialog(LyXView & lv, std::string const & name); + //GuiDialog(GuiDialog &, docstring const &); + +public Q_SLOTS: + // dialog closed from WM + void slotWMHide(); + // Restore button clicked + void slotRestore(); + // OK button clicked + void slotOK(); + // Apply button clicked + void slotApply(); + // Close button clicked + void slotClose(); +public: /** \name Buttons * These methods are publicly accessible because they are invoked * by the View when the user presses... guess what ;-) @@ -47,7 +66,6 @@ public: void checkStatus(); void setButtonsValid(bool valid); - /** \name Dialog Components * Methods to access the various components making up a dialog. */ @@ -61,8 +79,34 @@ public: void preUpdate(); void postUpdate(); + /// + bool readOnly() const; + + /// the dialog has changed contents + virtual void changed(); + + /// default: do nothing + virtual void applyView() {} + /// default: do nothing + virtual void update_contents() {} + +protected: + /// Hide the dialog. + virtual void hideView(); + /// Create the dialog if necessary, update it and display it. + virtual void showView(); + /// + virtual bool isVisibleView() const; + /// is the dialog currently valid ? + virtual bool isValid(); + private: + /// update the dialog + virtual void updateView(); + ButtonController bc_; + /// are we updating ? + bool updating_; }; } // namespace frontend diff --git a/src/frontends/qt4/GuiDialogView.cpp b/src/frontends/qt4/GuiDialogView.cpp deleted file mode 100644 index b9e16c4778..0000000000 --- a/src/frontends/qt4/GuiDialogView.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/** - * \file GuiDialogView.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Angus Leeming - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "GuiDialogView.h" -#include "qt_helpers.h" - - -namespace lyx { -namespace frontend { - -GuiDialogView::GuiDialogView(GuiDialog & parent, docstring const & t) - : Dialog::View(parent, t), updating_(false), parent_(parent) -{} - - -ButtonController & GuiDialogView::bc() -{ - return parent_.bc(); -} - - -bool GuiDialogView::isVisibleView() const -{ - return form() && form()->isVisible(); -} - - -bool GuiDialogView::readOnly() const -{ - return kernel().isBufferReadonly(); -} - - -void GuiDialogView::showView() -{ - if (!form()) - build(); - - QSize const sizeHint = form()->sizeHint(); - if (sizeHint.height() >= 0 && sizeHint.width() >= 0) - form()->setMinimumSize(sizeHint); - - updateView(); // make sure its up-to-date - if (dialog().controller().exitEarly()) - return; - - form()->setWindowTitle(toqstr("LyX: " + getViewTitle())); - - if (form()->isVisible()) { - form()->raise(); - form()->activateWindow(); - form()->setFocus(); - } else { - form()->show(); - form()->setFocus(); - } -} - - -void GuiDialogView::hideView() -{ - if (form() && form()->isVisible()) - form()->hide(); -} - - -void GuiDialogView::build() -{ - // protect the BC from unwarranted state transitions - updating_ = true; - build_dialog(); - updating_ = false; -} - - -bool GuiDialogView::isValid() -{ - return true; -} - - -void GuiDialogView::changed() -{ - if (updating_) - return; - parent_.bc().setValid(isValid()); -} - - -void GuiDialogView::slotWMHide() -{ - parent_.CancelButton(); -} - - -void GuiDialogView::slotApply() -{ - parent_.ApplyButton(); -} - - -void GuiDialogView::slotOK() -{ - parent_.OKButton(); -} - - -void GuiDialogView::slotClose() -{ - parent_.CancelButton(); -} - - -void GuiDialogView::slotRestore() -{ - parent_.RestoreButton(); -} - -} // namespace frontend -} // namespace lyx - -#include "GuiDialogView_moc.cpp" diff --git a/src/frontends/qt4/GuiDialogView.h b/src/frontends/qt4/GuiDialogView.h deleted file mode 100644 index 73b5b0627d..0000000000 --- a/src/frontends/qt4/GuiDialogView.h +++ /dev/null @@ -1,116 +0,0 @@ -// -*- C++ -*- -/** - * \file GuiDialogView.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Angus Leeming - * - * Full author contact details are available in file CREDITS. - */ - -#ifndef GUIDIALOGVIEW_H -#define GUIDIALOGVIEW_H - -#include "GuiDialog.h" - -#include - -#include -#include -#include - -namespace lyx { -namespace frontend { - -/** This class is an Qt2 GUI base class. - */ -class GuiDialogView : public QObject, public Dialog::View -{ - Q_OBJECT -public: - /// - GuiDialogView(GuiDialog &, docstring const &); - /// - virtual ~GuiDialogView() {} - /// - bool readOnly() const; - - /// the dialog has changed contents - virtual void changed(); - - /// - ButtonController & bc(); - -protected: - /// build the actual dialog - virtual void build_dialog() = 0; - /// Build the dialog - virtual void build(); - /// Hide the dialog. - virtual void hideView(); - /// Create the dialog if necessary, update it and display it. - virtual void showView(); - /// update the dialog's contents - virtual void update_contents() = 0; - /// - virtual bool isVisibleView() const; - /// is the dialog currently valid ? - virtual bool isValid(); - - /// are we updating ? - bool updating_; - /// - GuiDialog & parent_; - -public Q_SLOTS: - // dialog closed from WM - void slotWMHide(); - // Restore button clicked - void slotRestore(); - // OK button clicked - void slotOK(); - // Apply button clicked - void slotApply(); - // Close button clicked - void slotClose(); - -private: - /// Pointer to the actual instantiation of the Qt dialog - virtual QWidget * form() const = 0; -}; - - -template -class GuiView : public GuiDialogView { -protected: - GuiView(GuiDialog & p, docstring const & t) - : GuiDialogView(p, t) - {} - - virtual ~GuiView() {} - - /// update the dialog - virtual void updateView() { - dialog_->setUpdatesEnabled(false); - - // protect the BC from unwarranted state transitions - updating_ = true; - update_contents(); - updating_ = false; - - dialog_->setUpdatesEnabled(true); - dialog_->update(); - } - - /// Pointer to the actual instantiation of the Qt dialog - virtual GUIDialog * form() const { return dialog_.get(); } - - /// Real GUI implementation. - boost::scoped_ptr dialog_; -}; - -} // namespace frontend -} // namespace lyx - -#endif // GUIDIALOGVIEW_H diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 3abbc52a37..305dc6cf7e 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -54,45 +54,62 @@ using std::vector; using std::string; -char const * const tex_graphics[] = {"default", "dvips", "dvitops", "emtex", - "ln", "oztex", "textures", "none", "" +char const * const tex_graphics[] = +{ + "default", "dvips", "dvitops", "emtex", + "ln", "oztex", "textures", "none", "" }; -char const * const tex_graphics_gui[] = {N_("Default"), "Dvips", "DVItoPS", "EmTeX", - "LN", "OzTeX", "Textures", N_("None"), "" +char const * const tex_graphics_gui[] = +{ + N_("Default"), "Dvips", "DVItoPS", "EmTeX", + "LN", "OzTeX", "Textures", N_("None"), "" }; -char const * const tex_fonts_roman[] = {"default", "cmr", "lmodern", "ae", "times", "palatino", - "charter", "newcent", "bookman", "utopia", "beraserif", "ccfonts", "chancery", "" +char const * const tex_fonts_roman[] = +{ + "default", "cmr", "lmodern", "ae", "times", "palatino", + "charter", "newcent", "bookman", "utopia", "beraserif", + "ccfonts", "chancery", "" }; -char const * tex_fonts_roman_gui[] = { N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"), - N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"), N_("Bitstream Charter"), - N_("New Century Schoolbook"), N_("Bookman"), N_("Utopia"), N_("Bera Serif"), - N_("Concrete Roman"), N_("Zapf Chancery"), "" +char const * tex_fonts_roman_gui[] = +{ + N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"), + N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"), + N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"), + N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"), + "" }; -char const * const tex_fonts_sans[] = {"default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", "" +char const * const tex_fonts_sans[] = +{ + "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", "" }; -char const * tex_fonts_sans_gui[] = { N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"), - N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), "" +char const * tex_fonts_sans_gui[] = +{ + N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"), + N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), "" }; -char const * const tex_fonts_monospaced[] = {"default", "cmtt", "lmtt", "courier", "beramono", - "luximono", "cmtl", "" +char const * const tex_fonts_monospaced[] = +{ + "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", "" }; -char const * tex_fonts_monospaced_gui[] = { N_("Default"), N_("Computer Modern Typewriter"), - N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"), N_("LuxiMono"), - N_("CM Typewriter Light"), "" +char const * tex_fonts_monospaced_gui[] = +{ + N_("Default"), N_("Computer Modern Typewriter"), + N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"), + N_("LuxiMono"), N_("CM Typewriter Light"), "" }; @@ -171,25 +188,30 @@ void PreambleModule::closeEvent(QCloseEvent * e) ///////////////////////////////////////////////////////////////////// -GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form) - : form_(form), lang_(getSecond(getLanguageData(false))) + +GuiDocumentDialog::GuiDocumentDialog(LyXView & lv) + : GuiDialog(lv, "document") { setupUi(this); + setController(new ControlDocument(*this)); + setViewTitle(_("Document Settings")); - connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); - connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore())); + lang_ = getSecond(getLanguageData(false)); + + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); + connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore())); connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked())); connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked())); // Manage the restore, ok, apply, restore and cancel/close buttons - form_->bc().setOK(okPB); - form_->bc().setApply(applyPB); - form_->bc().setCancel(closePB); - form_->bc().setRestore(restorePB); - + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + bc().setOK(okPB); + bc().setApply(applyPB); + bc().setCancel(closePB); + bc().setRestore(restorePB); textLayoutModule = new UiWidget; // text layout @@ -246,7 +268,7 @@ GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form) Spacing::Other, qt_("Custom")); // initialize the length validator - form_->bc().addCheckedLineEdit(textLayoutModule->skipLE); + bc().addCheckedLineEdit(textLayoutModule->skipLE); fontModule = new UiWidget; // fonts @@ -277,19 +299,19 @@ GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form) for (int n = 0; tex_fonts_roman[n][0]; ++n) { QString font = qt_(tex_fonts_roman_gui[n]); - if (!form_->controller().isFontAvailable(tex_fonts_roman[n])) + if (!controller().isFontAvailable(tex_fonts_roman[n])) font += qt_(" (not installed)"); fontModule->fontsRomanCO->addItem(font); } for (int n = 0; tex_fonts_sans[n][0]; ++n) { QString font = qt_(tex_fonts_sans_gui[n]); - if (!form_->controller().isFontAvailable(tex_fonts_sans[n])) + if (!controller().isFontAvailable(tex_fonts_sans[n])) font += qt_(" (not installed)"); fontModule->fontsSansCO->addItem(font); } for (int n = 0; tex_fonts_monospaced[n][0]; ++n) { QString font = qt_(tex_fonts_monospaced_gui[n]); - if (!form_->controller().isFontAvailable(tex_fonts_monospaced[n])) + if (!controller().isFontAvailable(tex_fonts_monospaced[n])) font += qt_(" (not installed)"); fontModule->fontsTypewriterCO->addItem(font); } @@ -336,9 +358,9 @@ GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form) pageLayoutModule->pagestyleCO->addItem(qt_("plain")); pageLayoutModule->pagestyleCO->addItem(qt_("headings")); pageLayoutModule->pagestyleCO->addItem(qt_("fancy")); - form_->bc().addCheckedLineEdit(pageLayoutModule->paperheightLE, + bc().addCheckedLineEdit(pageLayoutModule->paperheightLE, pageLayoutModule->paperheightL); - form_->bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE, + bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE, pageLayoutModule->paperwidthL); // paper @@ -363,8 +385,6 @@ GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form) pageLayoutModule->paperwidthLE)); - - marginsModule = new UiWidget; // margins connect(marginsModule->marginCB, SIGNAL(toggled(bool)), @@ -414,19 +434,19 @@ GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form) marginsModule->footskipLE->setValidator(unsignedLengthValidator( marginsModule->footskipLE)); - form_->bc().addCheckedLineEdit(marginsModule->topLE, + bc().addCheckedLineEdit(marginsModule->topLE, marginsModule->topL); - form_->bc().addCheckedLineEdit(marginsModule->bottomLE, + bc().addCheckedLineEdit(marginsModule->bottomLE, marginsModule->bottomL); - form_->bc().addCheckedLineEdit(marginsModule->innerLE, + bc().addCheckedLineEdit(marginsModule->innerLE, marginsModule->innerL); - form_->bc().addCheckedLineEdit(marginsModule->outerLE, + bc().addCheckedLineEdit(marginsModule->outerLE, marginsModule->outerL); - form_->bc().addCheckedLineEdit(marginsModule->headsepLE, + bc().addCheckedLineEdit(marginsModule->headsepLE, marginsModule->headsepL); - form_->bc().addCheckedLineEdit(marginsModule->headheightLE, + bc().addCheckedLineEdit(marginsModule->headheightLE, marginsModule->headheightL); - form_->bc().addCheckedLineEdit(marginsModule->footskipLE, + bc().addCheckedLineEdit(marginsModule->footskipLE, marginsModule->footskipL); @@ -449,8 +469,7 @@ GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form) vector::const_iterator lit = langs.begin(); vector::const_iterator lend = langs.end(); for (; lit != lend; ++lit) { - langModule->languageCO->addItem( - toqstr(lit->first)); + langModule->languageCO->addItem(toqstr(lit->first)); } // Always put the default encoding in the first position. @@ -593,6 +612,12 @@ GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form) } +ControlDocument & GuiDocumentDialog::controller() const +{ + return static_cast(Dialog::controller()); +} + + void GuiDocumentDialog::showPreamble() { docPS->setCurrentPanel(_("LaTeX Preamble")); @@ -601,19 +626,19 @@ void GuiDocumentDialog::showPreamble() void GuiDocumentDialog::saveDefaultClicked() { - form_->saveDocDefault(); + saveDocDefault(); } void GuiDocumentDialog::useDefaultsClicked() { - form_->useClassDefaults(); + useClassDefaults(); } void GuiDocumentDialog::change_adaptor() { - form_->changed(); + changed(); } @@ -657,7 +682,7 @@ void GuiDocumentDialog::set_listings_msg() void GuiDocumentDialog::closeEvent(QCloseEvent * e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } @@ -764,18 +789,15 @@ void GuiDocumentDialog::updateFontsize(string const & items, string const & sel) void GuiDocumentDialog::romanChanged(int item) { string const font = tex_fonts_roman[item]; - - fontModule->fontScCB->setEnabled( - form_->controller().providesSC(font)); - fontModule->fontOsfCB->setEnabled( - form_->controller().providesOSF(font)); + fontModule->fontScCB->setEnabled(controller().providesSC(font)); + fontModule->fontOsfCB->setEnabled(controller().providesOSF(font)); } void GuiDocumentDialog::sansChanged(int item) { string const font = tex_fonts_sans[item]; - bool scaleable = form_->controller().providesScale(font); + bool scaleable = controller().providesScale(font); fontModule->scaleSansSB->setEnabled(scaleable); fontModule->scaleSansLA->setEnabled(scaleable); } @@ -784,7 +806,7 @@ void GuiDocumentDialog::sansChanged(int item) void GuiDocumentDialog::ttChanged(int item) { string const font = tex_fonts_monospaced[item]; - bool scaleable = form_->controller().providesScale(font); + bool scaleable = controller().providesScale(font); fontModule->scaleTypewriterSB->setEnabled(scaleable); fontModule->scaleTypewriterLA->setEnabled(scaleable); } @@ -822,19 +844,18 @@ void GuiDocumentDialog::updatePagestyle(string const & items, string const & sel void GuiDocumentDialog::classChanged() { - BufferParams & params = form_->controller().params(); + BufferParams & params = controller().params(); textclass_type const tc = latexModule->classCO->currentIndex(); params.setJustBaseClass(tc); if (lyxrc.auto_reset_options) params.useClassDefaults(); - form_->update_contents(); + update_contents(); } void GuiDocumentDialog::updateNumbering() { - TextClass const & tclass = - form_->controller().params().getTextClass(); + TextClass const & tclass = controller().params().getTextClass(); numberingModule->tocTW->setUpdatesEnabled(false); numberingModule->tocTW->clear(); @@ -1104,14 +1125,12 @@ void GuiDocumentDialog::apply(BufferParams & params) branchesModule->apply(params); } -namespace { /** Return the position of val in the vector if found. If not found, return 0. */ template -typename std::vector::size_type -findPos(std::vector const & vec, A const & val) +static size_t findPos(std::vector const & vec, A const & val) { typename std::vector::const_iterator it = std::find(vec.begin(), vec.end(), val); @@ -1120,8 +1139,6 @@ findPos(std::vector const & vec, A const & val) return distance(vec.begin(), it); } -} // namespace anom - void GuiDocumentDialog::updateParams(BufferParams const & params) { @@ -1150,7 +1167,7 @@ void GuiDocumentDialog::updateParams(BufferParams const & params) } // preamble - preambleModule->update(params, form_->controller().id()); + preambleModule->update(params, controller().id()); // biblio biblioModule->citeDefaultRB->setChecked( @@ -1195,9 +1212,9 @@ void GuiDocumentDialog::updateParams(BufferParams const & params) } // numbering - int const min_toclevel = form_->controller().textClass().min_toclevel(); - int const max_toclevel = form_->controller().textClass().max_toclevel(); - if (form_->controller().textClass().hasTocLevels()) { + int const min_toclevel = controller().textClass().min_toclevel(); + int const max_toclevel = controller().textClass().max_toclevel(); + if (controller().textClass().hasTocLevels()) { numberingModule->setEnabled(true); numberingModule->depthSL->setMinimum(min_toclevel - 1); numberingModule->depthSL->setMaximum(max_toclevel); @@ -1243,7 +1260,7 @@ void GuiDocumentDialog::updateParams(BufferParams const & params) // text layout latexModule->classCO->setCurrentIndex(params.getBaseClass()); - updatePagestyle(form_->controller().textClass().opt_pagestyle(), + updatePagestyle(controller().textClass().opt_pagestyle(), params.pagestyle); textLayoutModule->lspacingCO->setCurrentIndex(nitem); @@ -1299,13 +1316,13 @@ void GuiDocumentDialog::updateParams(BufferParams const & params) latexModule->optionsLE->setText( toqstr(params.options)); } else { - latexModule->optionsLE->setText(""); + latexModule->optionsLE->setText(QString()); } floatModule->set(params.float_placement); - //fonts - updateFontsize(form_->controller().textClass().opt_fontsize(), + // Fonts + updateFontsize(controller().textClass().opt_fontsize(), params.fontsize); int n = findToken(tex_fonts_roman, params.fontsRoman); @@ -1384,48 +1401,19 @@ void GuiDocumentDialog::updateParams(BufferParams const & params) } -///////////////////////////////////////////////////////////////////// -// -// GuiDocument -// -///////////////////////////////////////////////////////////////////// - - -GuiDocument::GuiDocument(GuiDialog & parent) - : GuiView(parent, _("Document Settings")) -{} - - -void GuiDocument::build_dialog() -{ - dialog_.reset(new GuiDocumentDialog(this)); -} - - -void GuiDocument::showPreamble() +void GuiDocumentDialog::applyView() { - dialog_->showPreamble(); + apply(controller().params()); } -void GuiDocument::applyView() +void GuiDocumentDialog::update_contents() { - if (!dialog_.get()) - return; - - dialog_->apply(controller().params()); + updateParams(controller().params()); } -void GuiDocument::update_contents() -{ - if (!dialog_.get()) - return; - - dialog_->updateParams(controller().params()); -} - -void GuiDocument::saveDocDefault() +void GuiDocumentDialog::saveDocDefault() { // we have to apply the params first applyView(); @@ -1433,20 +1421,20 @@ void GuiDocument::saveDocDefault() } -void GuiDocument::useClassDefaults() +void GuiDocumentDialog::useClassDefaults() { BufferParams & params = controller().params(); - params.setJustBaseClass(dialog_->latexModule->classCO->currentIndex()); + params.setJustBaseClass(latexModule->classCO->currentIndex()); params.useClassDefaults(); update_contents(); } -bool GuiDocument::isValid() +bool GuiDocumentDialog::isValid() { - return dialog_->validate_listings_params().empty(); + return validate_listings_params().empty(); } diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index 3607b8fc45..dff7bdccd9 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -12,7 +12,7 @@ #ifndef GUIDOCUMENT_H #define GUIDOCUMENT_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "BulletsModule.h" #include "ControlDocument.h" @@ -52,12 +52,13 @@ class GuiBranches; class GuiDocument; class PreambleModule; -class GuiDocumentDialog : public QDialog, public Ui::DocumentUi { +class GuiDocumentDialog : public GuiDialog, public Ui::DocumentUi +{ Q_OBJECT public: friend class GuiDocument; - GuiDocumentDialog(GuiDocument *); + GuiDocumentDialog(LyXView & lv); void updateParams(BufferParams const & params); void apply(BufferParams & params); @@ -76,7 +77,7 @@ public Q_SLOTS: void saveDefaultClicked(); void useDefaultsClicked(); -protected Q_SLOTS: +private Q_SLOTS: void setLSpacing(int); void setMargins(bool); void setCustomPapersize(int); @@ -89,11 +90,10 @@ protected Q_SLOTS: void portraitChanged(); void classChanged(); -protected: +private: void closeEvent(QCloseEvent * e); private: - UiWidget *textLayoutModule; UiWidget *fontModule; UiWidget *pageLayoutModule; @@ -110,42 +110,22 @@ private: BulletsModule * bulletsModule; FloatPlacement * floatModule; - GuiDocument * form_; - /// FIXME std::vector lang_; -}; - - -class GuiDocument : public GuiView -{ -public: - - friend class GuiDocumentDialog; - - GuiDocument(GuiDialog &); - void showPreamble(); - /// parent controller - ControlDocument & controller() - { return static_cast(this->getController()); } /// parent controller - ControlDocument const & controller() const - { return static_cast(this->getController()); } + ControlDocument & controller() const; private: /// Apply changes void applyView(); /// update void update_contents(); - /// build the dialog - void build_dialog(); /// save as default template void saveDocDefault(); /// reset to default params void useClassDefaults(); -protected: /// return false if validate_listings_params returns error - virtual bool isValid(); + bool isValid(); }; @@ -164,7 +144,7 @@ Q_SIGNALS: /// signal that something's changed in the Widget. void changed(); -protected: +private: void closeEvent(QCloseEvent *); void on_preambleTE_textChanged() { changed(); } diff --git a/src/frontends/qt4/GuiERT.cpp b/src/frontends/qt4/GuiERT.cpp index 394a4fc7a6..fcbc6dfd7a 100644 --- a/src/frontends/qt4/GuiERT.cpp +++ b/src/frontends/qt4/GuiERT.cpp @@ -11,6 +11,7 @@ #include #include "GuiERT.h" +#include "ControlERT.h" #include "gettext.h" #include @@ -21,77 +22,58 @@ namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiERTDialog -// -///////////////////////////////////////////////////////////////////// - - -GuiERTDialog::GuiERTDialog(GuiERT * form) - : form_(form) +GuiERTDialog::GuiERTDialog(LyXView & lv) + : GuiDialog(lv, "ert") { setupUi(this); - connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK())); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + setViewTitle(_("TeX Code Settings")); + setController(new ControlERT(*this)); + + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(collapsedRB, SIGNAL(clicked()), this, SLOT(change_adaptor())); connect(openRB, SIGNAL(clicked()), this, SLOT(change_adaptor())); -} - -void GuiERTDialog::closeEvent(QCloseEvent * e) -{ - form_->slotWMHide(); - e->accept(); + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + bc().setOK(okPB); + bc().setCancel(closePB); } -void GuiERTDialog::change_adaptor() +ControlERT & GuiERTDialog::controller() const { - form_->changed(); + return static_cast(Dialog::controller()); } -///////////////////////////////////////////////////////////////////// -// -// GuiERT -// -///////////////////////////////////////////////////////////////////// - -GuiERT::GuiERT(GuiDialog & parent) - : GuiView(parent, _("TeX Code Settings")) +void GuiERTDialog::closeEvent(QCloseEvent * e) { + slotWMHide(); + e->accept(); } -void GuiERT::build_dialog() +void GuiERTDialog::change_adaptor() { - dialog_.reset(new GuiERTDialog(this)); - - bc().setOK(dialog_->okPB); - bc().setCancel(dialog_->closePB); + changed(); } -void GuiERT::applyView() +void GuiERTDialog::applyView() { - if (dialog_->openRB->isChecked()) + if (openRB->isChecked()) controller().setStatus(Inset::Open); else controller().setStatus(Inset::Collapsed); } -void GuiERT::update_contents() +void GuiERTDialog::update_contents() { - QRadioButton * rb = 0; - switch (controller().status()) { - case InsetERT::Open: rb = dialog_->openRB; break; - case InsetERT::Collapsed: rb = dialog_->collapsedRB; break; + case InsetERT::Open: openRB->setChecked(true); break; + case InsetERT::Collapsed: collapsedRB->setChecked(true); break; } - - rb->setChecked(true); } } // namespace frontend diff --git a/src/frontends/qt4/GuiEmbeddedFiles.cpp b/src/frontends/qt4/GuiEmbeddedFiles.cpp index 0b88b4200f..594611c510 100644 --- a/src/frontends/qt4/GuiEmbeddedFiles.cpp +++ b/src/frontends/qt4/GuiEmbeddedFiles.cpp @@ -13,33 +13,41 @@ #include "GuiEmbeddedFiles.h" #include "debug.h" + namespace lyx { namespace frontend { - -///////////////////////////////////////////////////////////////////// -// -// GuiEmbeddedFilesDialog -// -///////////////////////////////////////////////////////////////////// - static QString const INVALID_COLOR = "gray"; static QString const AUTO_COLOR = "green"; static QString const EMBEDDED_COLOR = "black"; static QString const EXTERNAL_COLOR = "blue"; -GuiEmbeddedFilesDialog::GuiEmbeddedFilesDialog(GuiEmbeddedFiles * form) - : form_(form) + +GuiEmbeddedFilesDialog::GuiEmbeddedFilesDialog(LyXView & lv) + : GuiDialog(lv, "embedding") { setupUi(this); - // - update(); + setController(new ControlEmbeddedFiles(*this)); + setViewTitle(_("Embedded Files")); + + //setView(new DockView( + // *dialog, qef, &gui_view, _("Embedded Files"), Qt::RightDockWidgetArea)); + + bc().setPolicy(ButtonPolicy::OkCancelPolicy); + + updateView(); +} + + +ControlEmbeddedFiles & GuiEmbeddedFilesDialog::controller() const +{ + return static_cast(Dialog::controller()); } void GuiEmbeddedFilesDialog::on_filesLW_itemSelectionChanged() { - EmbeddedFiles & files = form_->embeddedFiles(); + EmbeddedFiles & files = controller().embeddedFiles(); QList selection = filesLW->selectedItems(); @@ -53,7 +61,7 @@ void GuiEmbeddedFilesDialog::on_filesLW_itemSelectionChanged() int idx = filesLW->row(*it); fullpathLE->setText(toqstr(files[idx].absFilename())); // go to the first selected item - form_->goTo(files[idx]); + controller().goTo(files[idx]); } EmbeddedFile::STATUS mode = EmbeddedFile::NONE; @@ -77,9 +85,9 @@ void GuiEmbeddedFilesDialog::on_filesLW_itemSelectionChanged() void GuiEmbeddedFilesDialog::on_filesLW_itemDoubleClicked() { - EmbeddedFiles & files = form_->embeddedFiles(); + EmbeddedFiles & files = controller().embeddedFiles(); QList selection = filesLW->selectedItems(); - form_->view(files[filesLW->row(*selection.begin())]); + controller().view(files[filesLW->row(*selection.begin())]); } @@ -88,7 +96,7 @@ void GuiEmbeddedFilesDialog::updateView() filesLW->clear(); // - EmbeddedFiles const & files = form_->embeddedFiles(); + EmbeddedFiles const & files = controller().embeddedFiles(); EmbeddedFiles::EmbeddedFileList::const_iterator it = files.begin(); EmbeddedFiles::EmbeddedFileList::const_iterator it_end = files.end(); for (; it != it_end; ++it) { @@ -113,9 +121,9 @@ void GuiEmbeddedFilesDialog::updateView() void GuiEmbeddedFilesDialog::on_addPB_clicked() { - docstring const file = form_->browseFile(); + docstring const file = controller().browseFile(); if (!file.empty()) { - EmbeddedFiles & files = form_->embeddedFiles(); + EmbeddedFiles & files = controller().embeddedFiles(); files.registerFile(to_utf8(file), EmbeddedFile::EMBEDDED); } } @@ -123,11 +131,11 @@ void GuiEmbeddedFilesDialog::on_addPB_clicked() void GuiEmbeddedFilesDialog::on_extractPB_clicked() { - EmbeddedFiles const & files = form_->embeddedFiles(); + EmbeddedFiles const & files = controller().embeddedFiles(); QList selection = filesLW->selectedItems(); for (QList::iterator it = selection.begin(); it != selection.end(); ++it) - form_->extract(files[filesLW->row(*it)]); + controller().extract(files[filesLW->row(*it)]); } @@ -138,20 +146,20 @@ void GuiEmbeddedFilesDialog::on_enableCB_toggled(bool enable) // When a embedded file is turned to disabled, it should save its // embedded files. Otherwise, embedded files will be lost!!! // - form_->embeddedFiles().enable(enable); + controller().embeddedFiles().enable(enable); // immediately post the change to buffer (and bufferView) if (enable) - form_->setMessage("Enable file embedding"); + controller().setMessage("Enable file embedding"); else - form_->setMessage("Disable file embedding"); + controller().setMessage("Disable file embedding"); // update bufferView - form_->dispatchParams(); + controller().dispatchParams(); } void GuiEmbeddedFilesDialog::set_embedding_status(EmbeddedFile::STATUS status) { - EmbeddedFiles & files = form_->embeddedFiles(); + EmbeddedFiles & files = controller().embeddedFiles(); QList selection = filesLW->selectedItems(); for (QList::iterator it = selection.begin(); it != selection.end(); ++it) { @@ -167,16 +175,16 @@ void GuiEmbeddedFilesDialog::set_embedding_status(EmbeddedFile::STATUS status) (*it)->setTextColor(EXTERNAL_COLOR); } if (status == EmbeddedFile::AUTO) - form_->setMessage("Switch to auto embedding"); + controller().setMessage("Switch to auto embedding"); else if (status == EmbeddedFile::EMBEDDED) - form_->setMessage("Switch to always embedding"); + controller().setMessage("Switch to always embedding"); else - form_->setMessage("Switch to never embedding"); + controller().setMessage("Switch to never embedding"); autoRB->setChecked(status == EmbeddedFile::AUTO); embeddedRB->setChecked(status == EmbeddedFile::EMBEDDED); externalRB->setChecked(status == EmbeddedFile::EXTERNAL); // update bufferView - form_->dispatchParams(); + controller().dispatchParams(); } diff --git a/src/frontends/qt4/GuiEmbeddedFiles.h b/src/frontends/qt4/GuiEmbeddedFiles.h index e5c5c0615a..7dcbf4f2f7 100644 --- a/src/frontends/qt4/GuiEmbeddedFiles.h +++ b/src/frontends/qt4/GuiEmbeddedFiles.h @@ -12,6 +12,7 @@ #ifndef GUIEMBEDDEDFILES_H #define GUIEMBEDDEDFILES_H +#include "GuiDialog.h" #include "EmbeddedFiles.h" #include "ControlEmbeddedFiles.h" #include "ui_EmbeddedFilesUi.h" @@ -19,12 +20,12 @@ namespace lyx { namespace frontend { -class GuiEmbeddedFiles; - -class GuiEmbeddedFilesDialog : public QWidget, public Ui::GuiEmbeddedFilesUi { +class GuiEmbeddedFilesDialog : public GuiDialog, public Ui::GuiEmbeddedFilesUi +{ Q_OBJECT + public: - GuiEmbeddedFilesDialog(GuiEmbeddedFiles * form); + GuiEmbeddedFilesDialog(LyXView & lv); public Q_SLOTS: /// @@ -43,22 +44,10 @@ public Q_SLOTS: void on_addPB_clicked(); // void on_extractPB_clicked(); + private: + ControlEmbeddedFiles & controller() const; void set_embedding_status(EmbeddedFile::STATUS); - /// - GuiEmbeddedFiles * form_; -}; - - -class GuiEmbeddedFiles : public QObject, public ControlEmbeddedFiles -{ - Q_OBJECT -public: - /// Constructor - GuiEmbeddedFiles(Dialog & dialog) - : ControlEmbeddedFiles(dialog) {} - /// - virtual ~GuiEmbeddedFiles() {} }; } // namespace frontend diff --git a/src/frontends/qt4/GuiErrorList.cpp b/src/frontends/qt4/GuiErrorList.cpp index 8630ffd8ef..f42c2f5308 100644 --- a/src/frontends/qt4/GuiErrorList.cpp +++ b/src/frontends/qt4/GuiErrorList.cpp @@ -11,6 +11,8 @@ #include #include "GuiErrorList.h" +#include "ControlErrorList.h" + #include "qt_helpers.h" #include @@ -18,37 +20,44 @@ #include #include + namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiErrorListDialog -// -///////////////////////////////////////////////////////////////////// -GuiErrorListDialog::GuiErrorListDialog(GuiErrorList * form) - : form_(form) +GuiErrorListDialog::GuiErrorListDialog(LyXView & lv) + : GuiDialog(lv, "errorlist") { setupUi(this); + setController(new ControlErrorList(*this)); + connect(closePB, SIGNAL(clicked()), - form, SLOT(slotClose())); - connect(errorsLW, SIGNAL( itemActivated(QListWidgetItem *)), - form, SLOT(slotClose())); - connect( errorsLW, SIGNAL( itemClicked(QListWidgetItem *)), + this, SLOT(slotClose())); + connect(errorsLW, SIGNAL(itemActivated(QListWidgetItem *)), + this, SLOT(slotClose())); + connect( errorsLW, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(select_adaptor(QListWidgetItem *))); + + bc().setPolicy(ButtonPolicy::OkCancelPolicy); + bc().setCancel(closePB); +} + + +ControlErrorList & GuiErrorListDialog::controller() const +{ + return static_cast(Dialog::controller()); } void GuiErrorListDialog::select_adaptor(QListWidgetItem * item) { - form_->select(item); + select(item); } void GuiErrorListDialog::closeEvent(QCloseEvent * e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } @@ -56,49 +65,29 @@ void GuiErrorListDialog::closeEvent(QCloseEvent * e) void GuiErrorListDialog::showEvent(QShowEvent *e) { errorsLW->setCurrentRow(0); - form_->select(errorsLW->item(0)); + select(errorsLW->item(0)); e->accept(); } -///////////////////////////////////////////////////////////////////// -// -// GuiErrorList -// -///////////////////////////////////////////////////////////////////// - - -GuiErrorList::GuiErrorList(GuiDialog & parent) - : GuiView(parent, docstring()) -{} - - -void GuiErrorList::build_dialog() -{ - dialog_.reset(new GuiErrorListDialog(this)); - bc().setCancel(dialog_->closePB); -} - - -void GuiErrorList::select(QListWidgetItem * wi) +void GuiErrorListDialog::select(QListWidgetItem * wi) { - int const item = dialog_->errorsLW->row(wi); + int const item = errorsLW->row(wi); controller().goTo(item); - dialog_->descriptionTB->setPlainText(toqstr(controller().errorList()[item].description)); + descriptionTB->setPlainText(toqstr(controller().errorList()[item].description)); } -void GuiErrorList::update_contents() +void GuiErrorListDialog::update_contents() { setViewTitle(from_utf8(controller().name())); - dialog_->errorsLW->clear(); - dialog_->descriptionTB->setPlainText(QString()); + errorsLW->clear(); + descriptionTB->setPlainText(QString()); ErrorList::const_iterator it = controller().errorList().begin(); ErrorList::const_iterator end = controller().errorList().end(); - for(; it != end; ++it) { - dialog_->errorsLW->addItem(toqstr(it->error)); - } + for (; it != end; ++it) + errorsLW->addItem(toqstr(it->error)); } } // namespace frontend diff --git a/src/frontends/qt4/GuiErrorList.h b/src/frontends/qt4/GuiErrorList.h index 8f64962f72..4687debf71 100644 --- a/src/frontends/qt4/GuiErrorList.h +++ b/src/frontends/qt4/GuiErrorList.h @@ -12,55 +12,34 @@ #ifndef GUIERRORLIST_H #define GUIERRORLIST_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlErrorList.h" #include "ui_ErrorListUi.h" -#include - class QListWidgetItem; namespace lyx { namespace frontend { -class GuiErrorList; - -class GuiErrorListDialog : public QDialog, public Ui::ErrorListUi { +class GuiErrorListDialog : public GuiDialog, public Ui::ErrorListUi +{ Q_OBJECT + public: - GuiErrorListDialog(GuiErrorList * form); + GuiErrorListDialog(LyXView & lv); public Q_SLOTS: void select_adaptor(QListWidgetItem *); -protected: + +private: void closeEvent(QCloseEvent *); void showEvent(QShowEvent *); -private: - GuiErrorList * form_; -}; - - -class GuiErrorList : public GuiView -{ -public: - friend class GuiErrorListDialog; - - GuiErrorList(GuiDialog &); - /// parent controller - ControlErrorList & controller() - { return static_cast(this->getController()); } /// parent controller - ControlErrorList const & controller() const - { return static_cast(this->getController()); } -private: + ControlErrorList & controller() const; /// select an entry void select(QListWidgetItem *); - /// required apply - virtual void applyView() {} - /// build dialog - virtual void build_dialog(); /// update contents - virtual void update_contents(); + void update_contents(); }; } // namespace frontend diff --git a/src/frontends/qt4/GuiExternal.cpp b/src/frontends/qt4/GuiExternal.cpp index 0def0d943c..5dbc5d659c 100644 --- a/src/frontends/qt4/GuiExternal.cpp +++ b/src/frontends/qt4/GuiExternal.cpp @@ -11,6 +11,9 @@ #include +#include "GuiExternal.h" + +#include "ControlExternal.h" #include "lengthcommon.h" #include "LyXRC.h" @@ -22,15 +25,14 @@ #include "support/os.h" #include "support/lyxlib.h" -#include "GuiExternal.h" - #include "LengthCombo.h" #include "qt_helpers.h" #include "Validator.h" +#include +#include #include #include -#include #include #include @@ -45,26 +47,21 @@ using lyx::support::os::internal_path; using std::string; using std::vector; -using std::find; namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiExternalDialog -// -///////////////////////////////////////////////////////////////////// - - -GuiExternalDialog::GuiExternalDialog(GuiExternal * form) - : form_(form) +GuiExternalDialog::GuiExternalDialog(LyXView & lv) + : GuiDialog(lv, "external") { setupUi(this); - connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + setViewTitle(_("External Material")); + setController(new ControlExternal(*this)); + + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(displayCB, SIGNAL(toggled(bool)), showCO, SLOT(setEnabled(bool))); @@ -126,6 +123,70 @@ GuiExternalDialog::GuiExternalDialog(GuiExternal * form) heightED->setValidator(unsignedLengthValidator(heightED)); setFocusProxy(fileED); + + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + + bc().setOK(okPB); + bc().setApply(applyPB); + bc().setCancel(closePB); + + bc().addReadOnly(fileED); + bc().addReadOnly(browsePB); + bc().addReadOnly(editPB); + bc().addReadOnly(externalCO); + bc().addReadOnly(draftCB); + bc().addReadOnly(displayscaleED); + bc().addReadOnly(showCO); + bc().addReadOnly(displayCB); + bc().addReadOnly(angleED); + bc().addReadOnly(originCO); + bc().addReadOnly(heightUnitCO); + bc().addReadOnly(heightED); + bc().addReadOnly(aspectratioCB); + bc().addReadOnly(widthUnitCO); + bc().addReadOnly(widthED); + bc().addReadOnly(clipCB); + bc().addReadOnly(getbbPB); + bc().addReadOnly(ytED); + bc().addReadOnly(xlED); + bc().addReadOnly(xrED); + bc().addReadOnly(ybED); + bc().addReadOnly(extraFormatCO); + bc().addReadOnly(extraED); + + bc().addCheckedLineEdit(angleED, angleLA); + bc().addCheckedLineEdit(displayscaleED, scaleLA); + bc().addCheckedLineEdit(heightED, heightLA); + bc().addCheckedLineEdit(widthED, widthLA); + bc().addCheckedLineEdit(xlED, lbLA); + bc().addCheckedLineEdit(ybED, lbLA); + bc().addCheckedLineEdit(xrED, rtLA); + bc().addCheckedLineEdit(ytED, rtLA); + bc().addCheckedLineEdit(fileED, fileLA); + + std::vector templates(controller().getTemplates()); + + for (std::vector::const_iterator cit = templates.begin(); + cit != templates.end(); ++cit) { + externalCO->addItem(qt_(*cit)); + } + + // Fill the origins combo + typedef vector Origins; + Origins const & all_origins = external::all_origins(); + for (Origins::size_type i = 0; i != all_origins.size(); ++i) + originCO->addItem(toqstr(external::origin_gui_str(i))); + + // Fill the width combo + widthUnitCO->addItem(qt_("Scale%")); + for (int i = 0; i < num_units; i++) + widthUnitCO->addItem(qt_(unit_name_gui[i])); +} + + +ControlExternal & GuiExternalDialog::controller() const +{ + return static_cast(Dialog::controller()); } @@ -165,8 +226,8 @@ bool GuiExternalDialog::activateAspectratio() const void GuiExternalDialog::bbChanged() { - form_->controller().bbChanged(true); - form_->changed(); + controller().bbChanged(true); + changed(); } @@ -174,33 +235,33 @@ void GuiExternalDialog::browseClicked() { int const choice = externalCO->currentIndex(); docstring const template_name = - from_utf8(form_->controller().getTemplate(choice).lyxName); + from_utf8(controller().getTemplate(choice).lyxName); docstring const str = - form_->controller().browse(qstring_to_ucs4(fileED->text()), + controller().browse(qstring_to_ucs4(fileED->text()), template_name); if (!str.empty()) { fileED->setText(toqstr(str)); - form_->changed(); + changed(); } } void GuiExternalDialog::change_adaptor() { - form_->changed(); + changed(); } void GuiExternalDialog::closeEvent(QCloseEvent * e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } void GuiExternalDialog::editClicked() { - form_->controller().editExternal(); + controller().editExternal(); } @@ -208,34 +269,34 @@ void GuiExternalDialog::editClicked() void GuiExternalDialog::extraChanged(const QString& text) { std::string const format = fromqstr(extraFormatCO->currentText()); - form_->extra_[format] = text; - form_->changed(); + extra_[format] = text; + changed(); } void GuiExternalDialog::formatChanged(const QString& format) { - extraED->setText(form_->extra_[fromqstr(format)]); + extraED->setText(extra_[fromqstr(format)]); } void GuiExternalDialog::getbbClicked() { - form_->getBB(); + getBB(); } void GuiExternalDialog::sizeChanged() { aspectratioCB->setEnabled(activateAspectratio()); - form_->changed(); + changed(); } void GuiExternalDialog::templateChanged() { - form_->updateTemplate(); - form_->changed(); + updateTemplate(); + changed(); } @@ -250,15 +311,10 @@ void GuiExternalDialog::widthUnitChanged() heightED->setEnabled(useHeight); heightUnitCO->setEnabled(useHeight); - form_->changed(); + changed(); } -///////////////////////////////////////////////////////////////////// -// -// GuiExternal -// -///////////////////////////////////////////////////////////////////// namespace { @@ -469,9 +525,9 @@ void getCrop(external::ClipData & data, void getExtra(external::ExtraData & data, - GuiExternal::MapType const & extra) + GuiExternalDialog::MapType const & extra) { - typedef GuiExternal::MapType MapType; + typedef GuiExternalDialog::MapType MapType; MapType::const_iterator it = extra.begin(); MapType::const_iterator const end = extra.end(); for (; it != end; ++it) @@ -481,102 +537,36 @@ void getExtra(external::ExtraData & data, } // namespace anon -GuiExternal::GuiExternal(GuiDialog & parent) - : GuiView(parent, _("External Material")) -{} - - -void GuiExternal::build_dialog() -{ - dialog_.reset(new GuiExternalDialog(this)); - - bc().setOK(dialog_->okPB); - bc().setApply(dialog_->applyPB); - bc().setCancel(dialog_->closePB); - - bc().addReadOnly(dialog_->fileED); - bc().addReadOnly(dialog_->browsePB); - bc().addReadOnly(dialog_->editPB); - bc().addReadOnly(dialog_->externalCO); - bc().addReadOnly(dialog_->draftCB); - bc().addReadOnly(dialog_->displayscaleED); - bc().addReadOnly(dialog_->showCO); - bc().addReadOnly(dialog_->displayCB); - bc().addReadOnly(dialog_->angleED); - bc().addReadOnly(dialog_->originCO); - bc().addReadOnly(dialog_->heightUnitCO); - bc().addReadOnly(dialog_->heightED); - bc().addReadOnly(dialog_->aspectratioCB); - bc().addReadOnly(dialog_->widthUnitCO); - bc().addReadOnly(dialog_->widthED); - bc().addReadOnly(dialog_->clipCB); - bc().addReadOnly(dialog_->getbbPB); - bc().addReadOnly(dialog_->ytED); - bc().addReadOnly(dialog_->xlED); - bc().addReadOnly(dialog_->xrED); - bc().addReadOnly(dialog_->ybED); - bc().addReadOnly(dialog_->extraFormatCO); - bc().addReadOnly(dialog_->extraED); - - bc().addCheckedLineEdit(dialog_->angleED, dialog_->angleLA); - bc().addCheckedLineEdit(dialog_->displayscaleED, dialog_->scaleLA); - bc().addCheckedLineEdit(dialog_->heightED, dialog_->heightLA); - bc().addCheckedLineEdit(dialog_->widthED, dialog_->widthLA); - bc().addCheckedLineEdit(dialog_->xlED, dialog_->lbLA); - bc().addCheckedLineEdit(dialog_->ybED, dialog_->lbLA); - bc().addCheckedLineEdit(dialog_->xrED, dialog_->rtLA); - bc().addCheckedLineEdit(dialog_->ytED, dialog_->rtLA); - bc().addCheckedLineEdit(dialog_->fileED, dialog_->fileLA); - - std::vector templates(controller().getTemplates()); - - for (std::vector::const_iterator cit = templates.begin(); - cit != templates.end(); ++cit) { - dialog_->externalCO->addItem(qt_(*cit)); - } - - // Fill the origins combo - typedef vector Origins; - Origins const & all_origins = external::all_origins(); - for (Origins::size_type i = 0; i != all_origins.size(); ++i) - dialog_->originCO->addItem(toqstr(external::origin_gui_str(i))); - - // Fill the width combo - dialog_->widthUnitCO->addItem(qt_("Scale%")); - for (int i = 0; i < num_units; i++) - dialog_->widthUnitCO->addItem(qt_(unit_name_gui[i])); -} - -void GuiExternal::update_contents() +void GuiExternalDialog::update_contents() { - dialog_->tab->setCurrentIndex(0); + tab->setCurrentIndex(0); InsetExternalParams const & params = controller().params(); string const name = params.filename.outputFilename(kernel().bufferFilepath()); - dialog_->fileED->setText(toqstr(name)); + fileED->setText(toqstr(name)); - dialog_->externalCO->setCurrentIndex( + externalCO->setCurrentIndex( controller().getTemplateNumber(params.templatename())); updateTemplate(); - dialog_->draftCB->setChecked(params.draft); + draftCB->setChecked(params.draft); - setDisplay(*dialog_->displayCB, *dialog_->showCO, - *dialog_->displayscaleED, + setDisplay(*displayCB, *showCO, + *displayscaleED, params.display, params.lyxscale, readOnly()); - setRotation(*dialog_->angleED, *dialog_->originCO, params.rotationdata); + setRotation(*angleED, *originCO, params.rotationdata); - setSize(*dialog_->widthED, *dialog_->widthUnitCO, - *dialog_->heightED, *dialog_->heightUnitCO, - *dialog_->aspectratioCB, + setSize(*widthED, *widthUnitCO, + *heightED, *heightUnitCO, + *aspectratioCB, params.resizedata); - setCrop(*dialog_->clipCB, - *dialog_->xlED, *dialog_->ybED, - *dialog_->xrED, *dialog_->ytED, + setCrop(*clipCB, + *xlED, *ybED, + *xrED, *ytED, params.clipdata); controller().bbChanged(!params.clipdata.bbox.empty()); @@ -584,11 +574,11 @@ void GuiExternal::update_contents() } -void GuiExternal::updateTemplate() +void GuiExternalDialog::updateTemplate() { external::Template templ = - controller().getTemplate(dialog_->externalCO->currentIndex()); - dialog_->externalTB->setPlainText(qt_(templ.helpText)); + controller().getTemplate(externalCO->currentIndex()); + externalTB->setPlainText(qt_(templ.helpText)); // Ascertain which (if any) transformations the template supports // and disable tabs hosting unsupported transforms. @@ -597,32 +587,25 @@ void GuiExternal::updateTemplate() TransformIDs::const_iterator tr_begin = transformIds.begin(); TransformIDs::const_iterator const tr_end = transformIds.end(); - bool found = find(tr_begin, tr_end, external::Rotate) != tr_end; - dialog_->tab->setTabEnabled( - dialog_->tab->indexOf(dialog_->rotatetab), found); - found = find(tr_begin, tr_end, external::Resize) != tr_end; - dialog_->tab->setTabEnabled( - dialog_->tab->indexOf(dialog_->scaletab), found); + bool found = std::find(tr_begin, tr_end, external::Rotate) != tr_end; + tab->setTabEnabled(tab->indexOf(rotatetab), found); + found = std::find(tr_begin, tr_end, external::Resize) != tr_end; + tab->setTabEnabled(tab->indexOf(scaletab), found); - found = find(tr_begin, tr_end, external::Clip) != tr_end; - dialog_->tab->setTabEnabled( - dialog_->tab->indexOf(dialog_->croptab), found); + found = std::find(tr_begin, tr_end, external::Clip) != tr_end; + tab->setTabEnabled(tab->indexOf(croptab), found); - found = find(tr_begin, tr_end, external::Extra) != tr_end; - dialog_->tab->setTabEnabled( - dialog_->tab->indexOf(dialog_->optionstab), found); + found = std::find(tr_begin, tr_end, external::Extra) != tr_end; + tab->setTabEnabled(tab->indexOf(optionstab), found); if (!found) return; // Ascertain whether the template has any formats supporting // the 'Extra' option - QLineEdit * const extraED = dialog_->extraED; - QComboBox * const extraCB = dialog_->extraFormatCO; - extra_.clear(); extraED->clear(); - extraCB->clear(); + extraFormatCO->clear(); external::Template::Formats::const_iterator it = templ.formats.begin(); external::Template::Formats::const_iterator end = templ.formats.end(); @@ -632,76 +615,66 @@ void GuiExternal::updateTemplate() continue; string const format = it->first; string const opt = controller().params().extradata.get(format); - extraCB->addItem(toqstr(format)); + extraFormatCO->addItem(toqstr(format)); extra_[format] = toqstr(opt); } - bool const enabled = extraCB->count() > 0; + bool const enabled = extraFormatCO->count() > 0; - dialog_->tab->setTabEnabled( - dialog_->tab->indexOf(dialog_->optionstab), enabled); + tab->setTabEnabled( + tab->indexOf(optionstab), enabled); extraED->setEnabled(enabled && !kernel().isBufferReadonly()); - extraCB->setEnabled(enabled); + extraFormatCO->setEnabled(enabled); if (enabled) { - extraCB->setCurrentIndex(0); - extraED->setText(extra_[fromqstr(extraCB->currentText())]); + extraFormatCO->setCurrentIndex(0); + extraED->setText(extra_[fromqstr(extraFormatCO->currentText())]); } } -void GuiExternal::applyView() +void GuiExternalDialog::applyView() { InsetExternalParams params = controller().params(); - params.filename.set(internal_path(fromqstr(dialog_->fileED->text())), + params.filename.set(internal_path(fromqstr(fileED->text())), kernel().bufferFilepath()); params.settemplate(controller().getTemplate( - dialog_->externalCO->currentIndex()).lyxName); + externalCO->currentIndex()).lyxName); - params.draft = dialog_->draftCB->isChecked(); + params.draft = draftCB->isChecked(); getDisplay(params.display, params.lyxscale, - *dialog_->displayCB, *dialog_->showCO, - *dialog_->displayscaleED); - - if (dialog_->tab->isTabEnabled( - dialog_->tab->indexOf(dialog_->rotatetab))) - getRotation(params.rotationdata, - *dialog_->angleED, *dialog_->originCO); - - if (dialog_->tab->isTabEnabled( - dialog_->tab->indexOf(dialog_->scaletab))) - getSize(params.resizedata, - *dialog_->widthED, *dialog_->widthUnitCO, - *dialog_->heightED, *dialog_->heightUnitCO, - *dialog_->aspectratioCB); - - if (dialog_->tab->isTabEnabled( - dialog_->tab->indexOf(dialog_->croptab))) - getCrop(params.clipdata, - *dialog_->clipCB, - *dialog_->xlED, *dialog_->ybED, - *dialog_->xrED, *dialog_->ytED, - controller().bbChanged()); - - if (dialog_->tab->isTabEnabled( - dialog_->tab->indexOf(dialog_->optionstab))) + *displayCB, *showCO, + *displayscaleED); + + if (tab->isTabEnabled(tab->indexOf(rotatetab))) + getRotation(params.rotationdata, *angleED, *originCO); + + if (tab->isTabEnabled(tab->indexOf(scaletab))) + getSize(params.resizedata, *widthED, *widthUnitCO, + *heightED, *heightUnitCO, *aspectratioCB); + + if (tab->isTabEnabled(tab->indexOf(croptab))) + getCrop(params.clipdata, *clipCB, *xlED, *ybED, + *xrED, *ytED, controller().bbChanged()); + + if (tab->isTabEnabled(tab->indexOf(optionstab))) getExtra(params.extradata, extra_); controller().setParams(params); } -void GuiExternal::getBB() +void GuiExternalDialog::getBB() { - dialog_->xlED->setText("0"); - dialog_->ybED->setText("0"); - dialog_->xrED->setText("0"); - dialog_->ytED->setText("0"); + xlED->setText("0"); + ybED->setText("0"); + xrED->setText("0"); + ytED->setText("0"); - string const filename = fromqstr(dialog_->fileED->text()); + string const filename = fromqstr(fileED->text()); if (filename.empty()) return; @@ -709,10 +682,10 @@ void GuiExternal::getBB() if (bb.empty()) return; - dialog_->xlED->setText(toqstr(token(bb, ' ', 0))); - dialog_->ybED->setText(toqstr(token(bb, ' ', 1))); - dialog_->xrED->setText(toqstr(token(bb, ' ', 2))); - dialog_->ytED->setText(toqstr(token(bb, ' ', 3))); + xlED->setText(toqstr(token(bb, ' ', 0))); + ybED->setText(toqstr(token(bb, ' ', 1))); + xrED->setText(toqstr(token(bb, ' ', 2))); + ytED->setText(toqstr(token(bb, ' ', 3))); controller().bbChanged(false); } diff --git a/src/frontends/qt4/GuiExternal.h b/src/frontends/qt4/GuiExternal.h index 63168d599a..13ad241f8c 100644 --- a/src/frontends/qt4/GuiExternal.h +++ b/src/frontends/qt4/GuiExternal.h @@ -12,74 +12,54 @@ #ifndef GUIEXTERNAL_H #define GUIEXTERNAL_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlExternal.h" #include "ui_ExternalUi.h" -#include -#include - #include namespace lyx { namespace frontend { -class GuiExternal; - -class GuiExternalDialog : public QDialog, public Ui::ExternalUi +class GuiExternalDialog : public GuiDialog, public Ui::ExternalUi { Q_OBJECT -public: - GuiExternalDialog(GuiExternal * form); - virtual void showView(); -protected Q_SLOTS: - virtual void bbChanged(); - virtual void browseClicked(); - virtual void change_adaptor(); - virtual void editClicked(); - virtual void extraChanged(const QString&); - virtual void formatChanged(const QString&); - virtual void getbbClicked(); - virtual void sizeChanged(); - virtual void templateChanged(); - virtual void widthUnitChanged(); +public: + GuiExternalDialog(LyXView & lv); + +private Q_SLOTS: + void bbChanged(); + void browseClicked(); + void change_adaptor(); + void editClicked(); + void extraChanged(const QString&); + void formatChanged(const QString&); + void getbbClicked(); + void sizeChanged(); + void templateChanged(); + void widthUnitChanged(); -protected: - virtual void closeEvent(QCloseEvent * e); private: - bool activateAspectratio() const; - GuiExternal * form_; -}; - - -class GuiExternal : public GuiView -{ public: - friend class GuiExternalDialog; - - GuiExternal(GuiDialog &); - /// parent controller - ControlExternal & controller() - { return static_cast(this->getController()); } + void showView(); + void closeEvent(QCloseEvent * e); + // + bool activateAspectratio() const; /// parent controller - ControlExternal const & controller() const - { return static_cast(this->getController()); } - /// - typedef std::map MapType; -private: + ControlExternal & controller() const; /// Apply changes - virtual void applyView(); + void applyView(); /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); - + void update_contents(); /// Helper function called when the template is changed. void updateTemplate(); /// get bounding box from file void getBB(); + /// + typedef std::map MapType; + /// MapType extra_; }; diff --git a/src/frontends/qt4/GuiFloat.cpp b/src/frontends/qt4/GuiFloat.cpp index c107bf09a7..263af7eab0 100644 --- a/src/frontends/qt4/GuiFloat.cpp +++ b/src/frontends/qt4/GuiFloat.cpp @@ -11,6 +11,8 @@ #include #include "GuiFloat.h" + +#include "ControlFloat.h" #include "FloatPlacement.h" #include "insets/InsetFloat.h" @@ -18,76 +20,69 @@ #include #include + namespace lyx { namespace frontend { -GuiFloatDialog::GuiFloatDialog(GuiFloat * form) - : form_(form) +GuiFloatDialog::GuiFloatDialog(LyXView & lv) + : GuiDialog(lv, "float") { + setController(new ControlFloat(*this)); + setViewTitle(_("Float Settings")); + setupUi(this); - connect(restorePB, SIGNAL(clicked()), - form, SLOT(slotRestore())); - connect(okPB, SIGNAL(clicked()), - form, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), - form, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), - form, SLOT(slotClose())); + connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore())); + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); // enable span columns checkbox floatFP->useWide(); - // enable sideways checkbox floatFP->useSideways(); - connect(floatFP, SIGNAL(changed()), - this, SLOT(change_adaptor())); -} + connect(floatFP, SIGNAL(changed()), this, SLOT(change_adaptor())); + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); -void GuiFloatDialog::change_adaptor() -{ - form_->changed(); + bc().setCancel(closePB); + bc().setApply(applyPB); + bc().setOK(okPB); + bc().setRestore(restorePB); + + bc().addReadOnly(floatFP); } -void GuiFloatDialog::closeEvent(QCloseEvent * e) +ControlFloat & GuiFloatDialog::controller() const { - form_->slotWMHide(); - e->accept(); + return static_cast(Dialog::controller()); } -GuiFloat::GuiFloat(GuiDialog & parent) - : GuiView(parent, _("Float Settings")) +void GuiFloatDialog::change_adaptor() { + changed(); } -void GuiFloat::build_dialog() +void GuiFloatDialog::closeEvent(QCloseEvent * e) { - dialog_.reset(new GuiFloatDialog(this)); - - bc().setCancel(dialog_->closePB); - bc().setApply(dialog_->applyPB); - bc().setOK(dialog_->okPB); - bc().setRestore(dialog_->restorePB); - - bc().addReadOnly(dialog_->floatFP); + slotWMHide(); + e->accept(); } -void GuiFloat::update_contents() +void GuiFloatDialog::update_contents() { - dialog_->floatFP->set(controller().params()); + floatFP->set(controller().params()); } -void GuiFloat::applyView() +void GuiFloatDialog::applyView() { InsetFloatParams & params = controller().params(); - - params.placement = dialog_->floatFP->get(params.wide, params.sideways); + params.placement = floatFP->get(params.wide, params.sideways); } } // namespace frontend diff --git a/src/frontends/qt4/GuiFloat.h b/src/frontends/qt4/GuiFloat.h index b5915bbe24..645ca5bb88 100644 --- a/src/frontends/qt4/GuiFloat.h +++ b/src/frontends/qt4/GuiFloat.h @@ -12,53 +12,31 @@ #ifndef GUIFLOAT_H #define GUIFLOAT_H -#include "GuiDialogView.h" -#include "ui_FloatUi.h" +#include "GuiDialog.h" #include "ControlFloat.h" - -#include +#include "ui_FloatUi.h" namespace lyx { namespace frontend { -class GuiFloat; - -class GuiFloatDialog : public QDialog, public Ui::FloatUi { +class GuiFloatDialog : public GuiDialog, public Ui::FloatUi +{ Q_OBJECT -public: - GuiFloatDialog(GuiFloat * form); -protected Q_SLOTS: - virtual void change_adaptor(); +public: + GuiFloatDialog(LyXView & lv); -protected: - virtual void closeEvent(QCloseEvent * e); +private Q_SLOTS: + void change_adaptor(); private: - GuiFloat * form_; -}; - - -/// -class GuiFloat : public GuiView { -public: - /// - friend class GuiFloatDialog; - /// - GuiFloat(GuiDialog &); - /// parent controller - ControlFloat & controller() - { return static_cast(this->getController()); } + void closeEvent(QCloseEvent * e); /// parent controller - ControlFloat const & controller() const - { return static_cast(this->getController()); } -private: + ControlFloat & controller() const; /// Apply changes - virtual void applyView(); + void applyView(); /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); + void update_contents(); }; } // namespace frontend diff --git a/src/frontends/qt4/GuiFontExample.h b/src/frontends/qt4/GuiFontExample.h index c56a566d7d..f0592fd9cf 100644 --- a/src/frontends/qt4/GuiFontExample.h +++ b/src/frontends/qt4/GuiFontExample.h @@ -18,14 +18,12 @@ class QPaintEvent; - //namespace lyx { -class GuiFontExample : public QWidget { - +class GuiFontExample : public QWidget +{ public: - GuiFontExample(QWidget * parent) - : QWidget(parent) {} + GuiFontExample(QWidget * parent) : QWidget(parent) {} void set(QFont const & font, QString const & text); diff --git a/src/frontends/qt4/GuiFontLoader.h b/src/frontends/qt4/GuiFontLoader.h index 8cd017e580..5fc718fbbf 100644 --- a/src/frontends/qt4/GuiFontLoader.h +++ b/src/frontends/qt4/GuiFontLoader.h @@ -28,7 +28,8 @@ namespace frontend { * Qt font loader for LyX. Matches Fonts against * actual QFont instances, and also caches metrics. */ -class QLFontInfo { +class QLFontInfo +{ public: QLFontInfo(Font const & f); diff --git a/src/frontends/qt4/GuiFontMetrics.h b/src/frontends/qt4/GuiFontMetrics.h index 707b5f336e..4f83c3807a 100644 --- a/src/frontends/qt4/GuiFontMetrics.h +++ b/src/frontends/qt4/GuiFontMetrics.h @@ -19,7 +19,6 @@ #include #include - namespace lyx { namespace frontend { diff --git a/src/frontends/qt4/GuiGraphics.cpp b/src/frontends/qt4/GuiGraphics.cpp index b63d2462f5..684dbbdf15 100644 --- a/src/frontends/qt4/GuiGraphics.cpp +++ b/src/frontends/qt4/GuiGraphics.cpp @@ -15,6 +15,7 @@ #include "GuiGraphics.h" +#include "ControlGraphics.h" #include "debug.h" #include "LengthCombo.h" #include "lengthcommon.h" @@ -68,19 +69,18 @@ getFirst(std::vector const & pr) return tmp; } -GuiGraphicsDialog::GuiGraphicsDialog(GuiGraphics * form) - : form_(form) +GuiGraphicsDialog::GuiGraphicsDialog(LyXView & lv) + : GuiDialog(lv, "graphics") { setupUi(this); + setViewTitle(_("Graphics")); + setController(new ControlGraphics(*this)); + //main buttons - connect(okPB, SIGNAL(clicked()), - form, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), - form, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), - form, SLOT(slotClose())); - connect(restorePB, SIGNAL(clicked()), - form, SLOT(slotRestore())); + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); + connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore())); //graphics pane connect(filename, SIGNAL(textChanged(const QString &)), @@ -173,6 +173,47 @@ GuiGraphicsDialog::GuiGraphicsDialog(GuiGraphics * form) connect(displayscale, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); displayscale->setValidator(new QIntValidator(displayscale)); + + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + bc().setOK(okPB); + bc().setApply(applyPB); + bc().setRestore(restorePB); + bc().setCancel(closePB); + + bc().addReadOnly(latexoptions); + bc().addReadOnly(subfigure); + bc().addReadOnly(filenameL); + bc().addReadOnly(filename); + bc().addReadOnly(browsePB); + bc().addReadOnly(unzipCB); + bc().addReadOnly(bbFrame); + bc().addReadOnly(draftCB); + bc().addReadOnly(clip); + bc().addReadOnly(unzipCB); + bc().addReadOnly(displayGB); + bc().addReadOnly(sizeGB); + bc().addReadOnly(rotationGB); + bc().addReadOnly(latexoptions); + bc().addReadOnly(getPB); + bc().addReadOnly(rotateOrderCB); + + // initialize the length validator + bc().addCheckedLineEdit(Scale, scaleCB); + bc().addCheckedLineEdit(Width, WidthCB); + bc().addCheckedLineEdit(Height, HeightCB); + bc().addCheckedLineEdit(displayscale, scaleLA); + bc().addCheckedLineEdit(angle, angleL); + bc().addCheckedLineEdit(lbX, xL); + bc().addCheckedLineEdit(lbY, yL); + bc().addCheckedLineEdit(rtX, xL_2); + bc().addCheckedLineEdit(rtY, yL_2); + bc().addCheckedLineEdit(filename, filenameL); +} + + +ControlGraphics & GuiGraphicsDialog::controller() const +{ + return static_cast(GuiDialog::controller()); } @@ -184,22 +225,22 @@ void GuiGraphicsDialog::showView() void GuiGraphicsDialog::change_adaptor() { - form_->changed(); + changed(); } void GuiGraphicsDialog::change_bb() { - form_->controller().bbChanged = true; + controller().bbChanged = true; LYXERR(Debug::GRAPHICS) << "[controller().bb_Changed set to true]\n"; - form_->changed(); + changed(); } void GuiGraphicsDialog::closeEvent(QCloseEvent * e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } @@ -207,23 +248,23 @@ void GuiGraphicsDialog::closeEvent(QCloseEvent * e) void GuiGraphicsDialog::on_browsePB_clicked() { docstring const str = - form_->controller().browse(qstring_to_ucs4(filename->text())); + controller().browse(qstring_to_ucs4(filename->text())); if(!str.empty()){ filename->setText(toqstr(str)); - form_->changed(); + changed(); } } void GuiGraphicsDialog::on_getPB_clicked() { - form_->getBB(); + getBB(); } void GuiGraphicsDialog::on_editPB_clicked() { - form_->controller().editGraphics(); + controller().editGraphics(); } @@ -235,7 +276,8 @@ void GuiGraphicsDialog::on_filename_textChanged(const QString & filename) void GuiGraphicsDialog::setAutoText() { - if (scaleCB->isChecked()) return; + if (scaleCB->isChecked()) + return; if (!Scale->isEnabled() && Scale->text() != "100") Scale->setText(QString("auto")); @@ -277,6 +319,7 @@ void GuiGraphicsDialog::on_scaleCB_toggled(bool setScale) setAutoText(); } + void GuiGraphicsDialog::on_WidthCB_toggled(bool setWidth) { Width->setEnabled(setWidth); @@ -335,53 +378,6 @@ void GuiGraphicsDialog::on_angle_textChanged(const QString & filename) (filename != "0")); } - -GuiGraphics::GuiGraphics(GuiDialog & parent) - : GuiView(parent, _("Graphics")) -{ -} - - -void GuiGraphics::build_dialog() -{ - dialog_.reset(new GuiGraphicsDialog(this)); - - bc().setOK(dialog_->okPB); - bc().setApply(dialog_->applyPB); - bc().setRestore(dialog_->restorePB); - bc().setCancel(dialog_->closePB); - - bc().addReadOnly(dialog_->latexoptions); - bc().addReadOnly(dialog_->subfigure); - bc().addReadOnly(dialog_->filenameL); - bc().addReadOnly(dialog_->filename); - bc().addReadOnly(dialog_->browsePB); - bc().addReadOnly(dialog_->unzipCB); - bc().addReadOnly(dialog_->bbFrame); - bc().addReadOnly(dialog_->draftCB); - bc().addReadOnly(dialog_->clip); - bc().addReadOnly(dialog_->unzipCB); - bc().addReadOnly(dialog_->displayGB); - bc().addReadOnly(dialog_->sizeGB); - bc().addReadOnly(dialog_->rotationGB); - bc().addReadOnly(dialog_->latexoptions); - bc().addReadOnly(dialog_->getPB); - bc().addReadOnly(dialog_->rotateOrderCB); - - // initialize the length validator - bc().addCheckedLineEdit(dialog_->Scale, dialog_->scaleCB); - bc().addCheckedLineEdit(dialog_->Width, dialog_->WidthCB); - bc().addCheckedLineEdit(dialog_->Height, dialog_->HeightCB); - bc().addCheckedLineEdit(dialog_->displayscale, dialog_->scaleLA); - bc().addCheckedLineEdit(dialog_->angle, dialog_->angleL); - bc().addCheckedLineEdit(dialog_->lbX, dialog_->xL); - bc().addCheckedLineEdit(dialog_->lbY, dialog_->yL); - bc().addCheckedLineEdit(dialog_->rtX, dialog_->xL_2); - bc().addCheckedLineEdit(dialog_->rtY, dialog_->yL_2); - bc().addCheckedLineEdit(dialog_->filename, dialog_->filenameL); -} - - // returns the number of the string s in the vector v static int getItemNo(const vector & v, string const & s) { @@ -391,20 +387,20 @@ static int getItemNo(const vector & v, string const & s) } -void GuiGraphics::update_contents() +void GuiGraphicsDialog::update_contents() { // clear and fill in the comboboxes vector const bb_units = frontend::getBBUnits(); - dialog_->lbXunit->clear(); - dialog_->lbYunit->clear(); - dialog_->rtXunit->clear(); - dialog_->rtYunit->clear(); + lbXunit->clear(); + lbYunit->clear(); + rtXunit->clear(); + rtYunit->clear(); for (vector::const_iterator it = bb_units.begin(); it != bb_units.end(); ++it) { - dialog_->lbXunit->addItem(toqstr(*it)); - dialog_->lbYunit->addItem(toqstr(*it)); - dialog_->rtXunit->addItem(toqstr(*it)); - dialog_->rtYunit->addItem(toqstr(*it)); + lbXunit->addItem(toqstr(*it)); + lbYunit->addItem(toqstr(*it)); + rtXunit->addItem(toqstr(*it)); + rtYunit->addItem(toqstr(*it)); } InsetGraphicsParams & igp = controller().params(); @@ -423,20 +419,20 @@ void GuiGraphics::update_contents() string const name = igp.filename.outputFilename(kernel().bufferFilepath()); - dialog_->filename->setText(toqstr(name)); + filename->setText(toqstr(name)); // set the bounding box values if (igp.bb.empty()) { string const bb = controller().readBB(igp.filename.absFilename()); // the values from the file always have the bigpoint-unit bp - dialog_->lbX->setText(toqstr(token(bb, ' ', 0))); - dialog_->lbY->setText(toqstr(token(bb, ' ', 1))); - dialog_->rtX->setText(toqstr(token(bb, ' ', 2))); - dialog_->rtY->setText(toqstr(token(bb, ' ', 3))); - dialog_->lbXunit->setCurrentIndex(0); - dialog_->lbYunit->setCurrentIndex(0); - dialog_->rtXunit->setCurrentIndex(0); - dialog_->rtYunit->setCurrentIndex(0); + lbX->setText(toqstr(token(bb, ' ', 0))); + lbY->setText(toqstr(token(bb, ' ', 1))); + rtX->setText(toqstr(token(bb, ' ', 2))); + rtY->setText(toqstr(token(bb, ' ', 3))); + lbXunit->setCurrentIndex(0); + lbYunit->setCurrentIndex(0); + rtXunit->setCurrentIndex(0); + rtYunit->setCurrentIndex(0); controller().bbChanged = false; } else { // get the values from the inset @@ -446,44 +442,44 @@ void GuiGraphics::update_contents() string const xr(token(igp.bb, ' ', 2)); string const yr(token(igp.bb, ' ', 3)); if (isValidLength(xl, &anyLength)) { - dialog_->lbX->setText(toqstr(convert(anyLength.value()))); + lbX->setText(toqstr(convert(anyLength.value()))); string const unit(unit_name[anyLength.unit()]); - dialog_->lbXunit->setCurrentIndex(getItemNo(bb_units, unit)); + lbXunit->setCurrentIndex(getItemNo(bb_units, unit)); } else { - dialog_->lbX->setText(toqstr(xl)); + lbX->setText(toqstr(xl)); } if (isValidLength(yl, &anyLength)) { - dialog_->lbY->setText(toqstr(convert(anyLength.value()))); + lbY->setText(toqstr(convert(anyLength.value()))); string const unit(unit_name[anyLength.unit()]); - dialog_->lbYunit->setCurrentIndex(getItemNo(bb_units, unit)); + lbYunit->setCurrentIndex(getItemNo(bb_units, unit)); } else { - dialog_->lbY->setText(toqstr(xl)); + lbY->setText(toqstr(xl)); } if (isValidLength(xr, &anyLength)) { - dialog_->rtX->setText(toqstr(convert(anyLength.value()))); + rtX->setText(toqstr(convert(anyLength.value()))); string const unit(unit_name[anyLength.unit()]); - dialog_->rtXunit->setCurrentIndex(getItemNo(bb_units, unit)); + rtXunit->setCurrentIndex(getItemNo(bb_units, unit)); } else { - dialog_->rtX->setText(toqstr(xl)); + rtX->setText(toqstr(xl)); } if (isValidLength(yr, &anyLength)) { - dialog_->rtY->setText(toqstr(convert(anyLength.value()))); + rtY->setText(toqstr(convert(anyLength.value()))); string const unit(unit_name[anyLength.unit()]); - dialog_->rtYunit->setCurrentIndex(getItemNo(bb_units, unit)); + rtYunit->setCurrentIndex(getItemNo(bb_units, unit)); } else { - dialog_->rtY->setText(toqstr(xl)); + rtY->setText(toqstr(xl)); } controller().bbChanged = true; } // Update the draft and clip mode - dialog_->draftCB->setChecked(igp.draft); - dialog_->clip->setChecked(igp.clip); - dialog_->unzipCB->setChecked(igp.noUnzip); + draftCB->setChecked(igp.draft); + clip->setChecked(igp.clip); + unzipCB->setChecked(igp.noUnzip); // Update the subcaption check button and input field - dialog_->subfigure->setChecked(igp.subcaption); - dialog_->subcaption->setText(toqstr(igp.subcaptionText)); + subfigure->setChecked(igp.subcaption); + subcaption->setText(toqstr(igp.subcaptionText)); int item = 0; switch (igp.display) { @@ -493,124 +489,122 @@ void GuiGraphics::update_contents() case graphics::ColorDisplay: item = 3; break; case graphics::NoDisplay: item = 0; break; } - dialog_->showCB->setCurrentIndex(item); - dialog_->displayscale->setText(toqstr(convert(igp.lyxscale))); - dialog_->displayGB->setChecked(igp.display != graphics::NoDisplay); + showCB->setCurrentIndex(item); + displayscale->setText(toqstr(convert(igp.lyxscale))); + displayGB->setChecked(igp.display != graphics::NoDisplay); // the output section (width/height) - dialog_->Scale->setText(toqstr(igp.scale)); + Scale->setText(toqstr(igp.scale)); //igp.scale defaults to 100, so we treat it as empty bool const scaleChecked = !igp.scale.empty() && igp.scale != "100"; - dialog_->scaleCB->blockSignals(true); - dialog_->scaleCB->setChecked(scaleChecked); - dialog_->scaleCB->blockSignals(false); - dialog_->Scale->setEnabled(scaleChecked); + scaleCB->blockSignals(true); + scaleCB->setChecked(scaleChecked); + scaleCB->blockSignals(false); + Scale->setEnabled(scaleChecked); - lengthAutoToWidgets(dialog_->Width, dialog_->widthUnit, igp.width, + lengthAutoToWidgets(Width, widthUnit, igp.width, unitDefault); - bool const widthChecked = !dialog_->Width->text().isEmpty() && - dialog_->Width->text() != "auto"; - dialog_->WidthCB->blockSignals(true); - dialog_->WidthCB->setChecked(widthChecked); - dialog_->WidthCB->blockSignals(false); - dialog_->Width->setEnabled(widthChecked); - dialog_->widthUnit->setEnabled(widthChecked); - - lengthAutoToWidgets(dialog_->Height, dialog_->heightUnit, igp.height, + bool const widthChecked = !Width->text().isEmpty() && + Width->text() != "auto"; + WidthCB->blockSignals(true); + WidthCB->setChecked(widthChecked); + WidthCB->blockSignals(false); + Width->setEnabled(widthChecked); + widthUnit->setEnabled(widthChecked); + + lengthAutoToWidgets(Height, heightUnit, igp.height, unitDefault); - bool const heightChecked = !dialog_->Height->text().isEmpty() - && dialog_->Height->text() != "auto"; - dialog_->HeightCB->blockSignals(true); - dialog_->HeightCB->setChecked(heightChecked); - dialog_->HeightCB->blockSignals(false); - dialog_->Height->setEnabled(heightChecked); - dialog_->heightUnit->setEnabled(heightChecked); + bool const heightChecked = !Height->text().isEmpty() + && Height->text() != "auto"; + HeightCB->blockSignals(true); + HeightCB->setChecked(heightChecked); + HeightCB->blockSignals(false); + Height->setEnabled(heightChecked); + heightUnit->setEnabled(heightChecked); - dialog_->scaleCB->setEnabled(!widthChecked && !heightChecked); - dialog_->WidthCB->setEnabled(!scaleChecked); - dialog_->HeightCB->setEnabled(!scaleChecked); - dialog_->aspectratio->setEnabled(widthChecked && heightChecked); + scaleCB->setEnabled(!widthChecked && !heightChecked); + WidthCB->setEnabled(!scaleChecked); + HeightCB->setEnabled(!scaleChecked); + aspectratio->setEnabled(widthChecked && heightChecked); - dialog_->setAutoText(); + setAutoText(); - dialog_->angle->setText(toqstr(igp.rotateAngle)); - dialog_->rotateOrderCB->setChecked(igp.scaleBeforeRotation); + angle->setText(toqstr(igp.rotateAngle)); + rotateOrderCB->setChecked(igp.scaleBeforeRotation); - dialog_->rotateOrderCB->setEnabled((widthChecked || - heightChecked || - scaleChecked) && - (igp.rotateAngle != "0")); + rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked) + && igp.rotateAngle != "0"); - dialog_->origin->clear(); + origin->clear(); vector origindata = getRotationOriginData(); vector const origin_lang = getFirst(origindata); - GuiGraphics::origin_ltx = getSecond(origindata); + origin_ltx = getSecond(origindata); for (vector::const_iterator it = origin_lang.begin(); it != origin_lang.end(); ++it) - dialog_->origin->addItem(toqstr(*it)); + origin->addItem(toqstr(*it)); if (!igp.rotateOrigin.empty()) - dialog_->origin->setCurrentIndex( + origin->setCurrentIndex( getItemNo(origin_ltx, igp.rotateOrigin)); else - dialog_->origin->setCurrentIndex(0); + origin->setCurrentIndex(0); // disable edit button when no filename is present - dialog_->editPB->setDisabled(dialog_->filename->text().isEmpty()); + editPB->setDisabled(filename->text().isEmpty()); //// latex section - dialog_->latexoptions->setText(toqstr(igp.special)); + latexoptions->setText(toqstr(igp.special)); } -void GuiGraphics::applyView() +void GuiGraphicsDialog::applyView() { InsetGraphicsParams & igp = controller().params(); - igp.filename.set(internal_path(fromqstr(dialog_->filename->text())), + igp.filename.set(internal_path(fromqstr(filename->text())), kernel().bufferFilepath()); // the bb section igp.bb.erase(); if (controller().bbChanged) { string bb; - string lbX(fromqstr(dialog_->lbX->text())); - string lbY(fromqstr(dialog_->lbY->text())); - string rtX(fromqstr(dialog_->rtX->text())); - string rtY(fromqstr(dialog_->rtY->text())); + string lbXs = fromqstr(lbX->text()); + string lbYs = fromqstr(lbY->text()); + string rtXs = fromqstr(rtX->text()); + string rtYs = fromqstr(rtY->text()); int bb_sum = - convert(lbX) + convert(lbY) + - convert(rtX) + convert(rtX); + convert(lbXs) + convert(lbYs) + + convert(rtXs) + convert(rtXs); if (bb_sum) { - if (lbX.empty()) + if (lbXs.empty()) bb = "0 "; else - bb = lbX + fromqstr(dialog_->lbXunit->currentText()) + ' '; - if (lbY.empty()) + bb = lbXs + fromqstr(lbXunit->currentText()) + ' '; + if (lbYs.empty()) bb += "0 "; else - bb += (lbY + fromqstr(dialog_->lbYunit->currentText()) + ' '); - if (rtX.empty()) + bb += (lbYs + fromqstr(lbYunit->currentText()) + ' '); + if (rtXs.empty()) bb += "0 "; else - bb += (rtX + fromqstr(dialog_->rtXunit->currentText()) + ' '); - if (rtY.empty()) + bb += (rtXs + fromqstr(rtXunit->currentText()) + ' '); + if (rtYs.empty()) bb += '0'; else - bb += (rtY + fromqstr(dialog_->rtYunit->currentText())); + bb += (rtYs + fromqstr(rtYunit->currentText())); igp.bb = bb; } } - igp.draft = dialog_->draftCB->isChecked(); - igp.clip = dialog_->clip->isChecked(); - igp.subcaption = dialog_->subfigure->isChecked(); - igp.subcaptionText = fromqstr(dialog_->subcaption->text()); + igp.draft = draftCB->isChecked(); + igp.clip = clip->isChecked(); + igp.subcaption = subfigure->isChecked(); + igp.subcaptionText = fromqstr(subcaption->text()); - switch (dialog_->showCB->currentIndex()) { + switch (showCB->currentIndex()) { case 0: igp.display = graphics::DefaultDisplay; break; case 1: igp.display = graphics::MonochromeDisplay; break; case 2: igp.display = graphics::GrayscaleDisplay; break; @@ -618,35 +612,33 @@ void GuiGraphics::applyView() default:; } - if (!dialog_->displayGB->isChecked()) + if (!displayGB->isChecked()) igp.display = graphics::NoDisplay; //the graphics section - if (dialog_->scaleCB->isChecked() && !dialog_->Scale->text().isEmpty()) { - igp.scale = fromqstr(dialog_->Scale->text()); + if (scaleCB->isChecked() && !Scale->text().isEmpty()) { + igp.scale = fromqstr(Scale->text()); igp.width = Length("0pt"); igp.height = Length("0pt"); igp.keepAspectRatio = false; } else { igp.scale = string(); - igp.width = dialog_->WidthCB->isChecked() ? - //Note that this works even if dialog_->Width is "auto", since in + igp.width = WidthCB->isChecked() ? + //Note that this works even if Width is "auto", since in //that case we get "0pt". - Length(widgetsToLength(dialog_->Width, dialog_->widthUnit)): + Length(widgetsToLength(Width, widthUnit)): Length("0pt"); - igp.height = dialog_->HeightCB->isChecked() ? - Length(widgetsToLength(dialog_->Height, dialog_->heightUnit)) : + igp.height = HeightCB->isChecked() ? + Length(widgetsToLength(Height, heightUnit)) : Length("0pt"); - igp.keepAspectRatio = dialog_->aspectratio->isEnabled() && - dialog_->aspectratio->isChecked() && + igp.keepAspectRatio = aspectratio->isEnabled() && + aspectratio->isChecked() && igp.width.value() > 0 && igp.height.value() > 0; } - igp.noUnzip = dialog_->unzipCB->isChecked(); - - igp.lyxscale = convert(fromqstr(dialog_->displayscale->text())); - - igp.rotateAngle = fromqstr(dialog_->angle->text()); + igp.noUnzip = unzipCB->isChecked(); + igp.lyxscale = displayscale->text().toInt(); + igp.rotateAngle = fromqstr(angle->text()); double rotAngle = convert(igp.rotateAngle); if (std::abs(rotAngle) > 360.0) { @@ -656,41 +648,39 @@ void GuiGraphics::applyView() // save the latex name for the origin. If it is the default // then origin_ltx returns "" - igp.rotateOrigin = - GuiGraphics::origin_ltx[dialog_->origin->currentIndex()]; - - igp.scaleBeforeRotation = dialog_->rotateOrderCB->isChecked(); + igp.rotateOrigin = origin_ltx[origin->currentIndex()]; + igp.scaleBeforeRotation = rotateOrderCB->isChecked(); // more latex options - igp.special = fromqstr(dialog_->latexoptions->text()); + igp.special = fromqstr(latexoptions->text()); } -void GuiGraphics::getBB() +void GuiGraphicsDialog::getBB() { - string const filename(fromqstr(dialog_->filename->text())); - if (!filename.empty()) { - string const bb(controller().readBB(filename)); + string const fn = fromqstr(filename->text()); + if (!fn.empty()) { + string const bb = controller().readBB(fn); if (!bb.empty()) { - dialog_->lbX->setText(toqstr(token(bb, ' ', 0))); - dialog_->lbY->setText(toqstr(token(bb, ' ', 1))); - dialog_->rtX->setText(toqstr(token(bb, ' ', 2))); - dialog_->rtY->setText(toqstr(token(bb, ' ', 3))); + lbX->setText(toqstr(token(bb, ' ', 0))); + lbY->setText(toqstr(token(bb, ' ', 1))); + rtX->setText(toqstr(token(bb, ' ', 2))); + rtY->setText(toqstr(token(bb, ' ', 3))); // the default units for the bb values when reading // it from the file - dialog_->lbXunit->setCurrentIndex(0); - dialog_->lbYunit->setCurrentIndex(0); - dialog_->rtXunit->setCurrentIndex(0); - dialog_->rtYunit->setCurrentIndex(0); + lbXunit->setCurrentIndex(0); + lbYunit->setCurrentIndex(0); + rtXunit->setCurrentIndex(0); + rtYunit->setCurrentIndex(0); } controller().bbChanged = false; } } -bool GuiGraphics::isValid() +bool GuiGraphicsDialog::isValid() { - return !dialog_->filename->text().isEmpty(); + return !filename->text().isEmpty(); } } // namespace frontend diff --git a/src/frontends/qt4/GuiGraphics.h b/src/frontends/qt4/GuiGraphics.h index b77defde42..100b31c316 100644 --- a/src/frontends/qt4/GuiGraphics.h +++ b/src/frontends/qt4/GuiGraphics.h @@ -13,11 +13,9 @@ #ifndef GUIGRAPHICS_H #define GUIGRAPHICS_H -#include "GuiDialogView.h" -#include "ui_GraphicsUi.h" +#include "GuiDialog.h" #include "ControlGraphics.h" - -#include +#include "ui_GraphicsUi.h" #include @@ -26,61 +24,38 @@ class QString; namespace lyx { namespace frontend { -class GuiGraphics; - -class GuiGraphicsDialog : public QDialog, public Ui::GraphicsUi +class GuiGraphicsDialog : public GuiDialog, public Ui::GraphicsUi { Q_OBJECT public: - GuiGraphicsDialog(GuiGraphics * form); - virtual void setAutoText(); - virtual void showView(); -protected Q_SLOTS: - virtual void change_adaptor(); - virtual void change_bb(); - virtual void on_browsePB_clicked(); - virtual void on_getPB_clicked(); - virtual void on_editPB_clicked(); - virtual void on_filename_textChanged(const QString &); - virtual void on_scaleCB_toggled(bool); - virtual void on_WidthCB_toggled(bool); - virtual void on_HeightCB_toggled(bool); - virtual void on_angle_textChanged(const QString &); -protected: - virtual void closeEvent(QCloseEvent * e); + GuiGraphicsDialog(LyXView & lv); + void setAutoText(); + void showView(); +private Q_SLOTS: + void change_adaptor(); + void change_bb(); + void on_browsePB_clicked(); + void on_getPB_clicked(); + void on_editPB_clicked(); + void on_filename_textChanged(const QString &); + void on_scaleCB_toggled(bool); + void on_WidthCB_toggled(bool); + void on_HeightCB_toggled(bool); + void on_angle_textChanged(const QString &); private: - GuiGraphics * form_; -}; - - -class GuiGraphics : public GuiView -{ -public: - /// - friend class GuiGraphicsDialog; - /// - GuiGraphics(GuiDialog &); + void closeEvent(QCloseEvent * e); /// parent controller - ControlGraphics & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlGraphics const & controller() const - { return static_cast(this->getController()); } -protected: - virtual bool isValid(); -private: + ControlGraphics & controller() const; + bool isValid(); /// Apply changes - virtual void applyView(); + void applyView(); /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); + void update_contents(); /// get bounding box from file void getBB(); /// Store the LaTeX names for the rotation origins. std::vector origin_ltx; - }; } // namespace frontend diff --git a/src/frontends/qt4/GuiImage.h b/src/frontends/qt4/GuiImage.h index 55529471bd..03c83f1574 100644 --- a/src/frontends/qt4/GuiImage.h +++ b/src/frontends/qt4/GuiImage.h @@ -21,7 +21,8 @@ namespace lyx { namespace graphics { -class GuiImage : public Image { +class GuiImage : public Image +{ public: /// Access to this class is through this static method. static ImagePtr newImage(); diff --git a/src/frontends/qt4/GuiInclude.cpp b/src/frontends/qt4/GuiInclude.cpp index 60f2d4e4e7..991c04e764 100644 --- a/src/frontends/qt4/GuiInclude.cpp +++ b/src/frontends/qt4/GuiInclude.cpp @@ -10,11 +10,12 @@ #include +#include "GuiInclude.h" +#include "ControlInclude.h" + #include "support/os.h" #include "support/lstrings.h" -#include "GuiInclude.h" - #include "qt_helpers.h" #include "LyXRC.h" @@ -33,21 +34,19 @@ using lyx::support::prefixIs; using lyx::support::getStringFromVector; using lyx::support::getVectorFromString; + namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiIncludeDialog -// -///////////////////////////////////////////////////////////////////// - -GuiIncludeDialog::GuiIncludeDialog(GuiInclude * form) - : form_(form) +GuiIncludeDialog::GuiIncludeDialog(LyXView & lv) + : GuiDialog(lv, "include") { setupUi(this); - connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK())); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + setViewTitle(_("Child Document")); + setController(new ControlInclude(*this)); + + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(visiblespaceCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); connect(filenameED, SIGNAL(textChanged(const QString &)), @@ -65,6 +64,23 @@ GuiIncludeDialog::GuiIncludeDialog(GuiInclude * form) connect(bypassCB, SIGNAL(clicked()), this, SLOT(set_listings_msg())); setFocusProxy(filenameED); + + bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); + bc().setOK(okPB); + bc().setCancel(closePB); + bc().addReadOnly(filenameED); + bc().addReadOnly(browsePB); + bc().addReadOnly(visiblespaceCB); + bc().addReadOnly(typeCO); + bc().addReadOnly(listingsED); + + bc().addCheckedLineEdit(filenameED, filenameLA); +} + + +ControlInclude & GuiIncludeDialog::controller() const +{ + return static_cast(Dialog::controller()); } @@ -76,7 +92,7 @@ void GuiIncludeDialog::showView() void GuiIncludeDialog::change_adaptor() { - form_->changed(); + changed(); } @@ -118,7 +134,7 @@ void GuiIncludeDialog::set_listings_msg() void GuiIncludeDialog::closeEvent(QCloseEvent * e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } @@ -166,59 +182,31 @@ void GuiIncludeDialog::typeChanged(int v) void GuiIncludeDialog::editClicked() { - form_->edit(); + edit(); } void GuiIncludeDialog::browseClicked() { - form_->browse(); -} - - -///////////////////////////////////////////////////////////////////// -// -// GuiInclude -// -///////////////////////////////////////////////////////////////////// - - -GuiInclude::GuiInclude(GuiDialog & parent) - : GuiView(parent, _("Child Document")) -{} - - -void GuiInclude::build_dialog() -{ - dialog_.reset(new GuiIncludeDialog(this)); - - bc().setOK(dialog_->okPB); - bc().setCancel(dialog_->closePB); - bc().addReadOnly(dialog_->filenameED); - bc().addReadOnly(dialog_->browsePB); - bc().addReadOnly(dialog_->visiblespaceCB); - bc().addReadOnly(dialog_->typeCO); - bc().addReadOnly(dialog_->listingsED); - - bc().addCheckedLineEdit(dialog_->filenameED, dialog_->filenameLA); + browse(); } -void GuiInclude::update_contents() +void GuiIncludeDialog::update_contents() { InsetCommandParams const & params = controller().params(); - dialog_->filenameED->setText(toqstr(params["filename"])); - - dialog_->visiblespaceCB->setChecked(false); - dialog_->visiblespaceCB->setEnabled(false); - dialog_->previewCB->setChecked(false); - dialog_->previewCB->setEnabled(false); - dialog_->listingsGB->setEnabled(false); - dialog_->captionLE->clear(); - dialog_->labelLE->clear(); - dialog_->listingsED->clear(); - dialog_->listingsTB->setPlainText( + filenameED->setText(toqstr(params["filename"])); + + visiblespaceCB->setChecked(false); + visiblespaceCB->setEnabled(false); + previewCB->setChecked(false); + previewCB->setEnabled(false); + listingsGB->setEnabled(false); + captionLE->clear(); + labelLE->clear(); + listingsED->clear(); + listingsTB->setPlainText( qt_("Input listing parameters on the right. Enter ? for a list of parameters.")); string cmdname = controller().params().getCmdName(); @@ -229,26 +217,26 @@ void GuiInclude::update_contents() cmdname = "input"; if (cmdname == "include") { - dialog_->typeCO->setCurrentIndex(0); + typeCO->setCurrentIndex(0); } else if (cmdname == "input") { - dialog_->typeCO->setCurrentIndex(1); - dialog_->previewCB->setEnabled(true); - dialog_->previewCB->setChecked(params.preview()); + typeCO->setCurrentIndex(1); + previewCB->setEnabled(true); + previewCB->setChecked(params.preview()); } else if (cmdname == "verbatiminput*") { - dialog_->typeCO->setCurrentIndex(2); - dialog_->visiblespaceCB->setEnabled(true); - dialog_->visiblespaceCB->setChecked(true); + typeCO->setCurrentIndex(2); + visiblespaceCB->setEnabled(true); + visiblespaceCB->setChecked(true); } else if (cmdname == "verbatiminput") { - dialog_->typeCO->setCurrentIndex(2); - dialog_->visiblespaceCB->setEnabled(true); + typeCO->setCurrentIndex(2); + visiblespaceCB->setEnabled(true); } else if (cmdname == "lstinputlisting") { - dialog_->typeCO->setCurrentIndex(3); - dialog_->listingsGB->setEnabled(true); - dialog_->listingsED->setEnabled(true); + typeCO->setCurrentIndex(3); + listingsGB->setEnabled(true); + listingsED->setEnabled(true); InsetListingsParams par(params.getOptions()); // extract caption and label and put them into their respective editboxes vector pars = getVectorFromString(par.separatedParams(), "\n"); @@ -257,32 +245,32 @@ void GuiInclude::update_contents() if (prefixIs(*it, "caption=")) { string cap = it->substr(8); if (cap[0] == '{' && cap[cap.size()-1] == '}') { - dialog_->captionLE->setText(toqstr(cap.substr(1, cap.size()-2))); + captionLE->setText(toqstr(cap.substr(1, cap.size()-2))); *it = ""; } } else if (prefixIs(*it, "label=")) { string lbl = it->substr(6); if (lbl[0] == '{' && lbl[lbl.size()-1] == '}') { - dialog_->labelLE->setText(toqstr(lbl.substr(1, lbl.size()-2))); + labelLE->setText(toqstr(lbl.substr(1, lbl.size()-2))); *it = ""; } } } // the rest is put to the extra edit box. string extra = getStringFromVector(pars); - dialog_->listingsED->setPlainText(toqstr(InsetListingsParams(extra).separatedParams())); + listingsED->setPlainText(toqstr(InsetListingsParams(extra).separatedParams())); } } -void GuiInclude::applyView() +void GuiIncludeDialog::applyView() { InsetCommandParams params = controller().params(); - params["filename"] = from_utf8(internal_path(fromqstr(dialog_->filenameED->text()))); - params.preview(dialog_->previewCB->isChecked()); + params["filename"] = from_utf8(internal_path(fromqstr(filenameED->text()))); + params.preview(previewCB->isChecked()); - int const item = dialog_->typeCO->currentIndex(); + int const item = typeCO->currentIndex(); if (item == 0) { params.setCmdName("include"); } else if (item == 1) { @@ -290,16 +278,16 @@ void GuiInclude::applyView() } else if (item == 3) { params.setCmdName("lstinputlisting"); // the parameter string should have passed validation - InsetListingsParams par(fromqstr(dialog_->listingsED->toPlainText())); - string caption = fromqstr(dialog_->captionLE->text()); - string label = fromqstr(dialog_->labelLE->text()); + InsetListingsParams par(fromqstr(listingsED->toPlainText())); + string caption = fromqstr(captionLE->text()); + string label = fromqstr(labelLE->text()); if (!caption.empty()) par.addParam("caption", "{" + caption + "}"); if (!label.empty()) par.addParam("label", "{" + label + "}"); params.setOptions(par.params()); } else { - if (dialog_->visiblespaceCB->isChecked()) + if (visiblespaceCB->isChecked()) params.setCmdName("verbatiminput*"); else params.setCmdName("verbatiminput"); @@ -308,11 +296,11 @@ void GuiInclude::applyView() } -void GuiInclude::browse() +void GuiIncludeDialog::browse() { ControlInclude::Type type; - int const item = dialog_->typeCO->currentIndex(); + int const item = typeCO->currentIndex(); if (item == 0) type = ControlInclude::INCLUDE; else if (item == 1) @@ -323,26 +311,26 @@ void GuiInclude::browse() type = ControlInclude::LISTINGS; docstring const & name = - controller().browse(qstring_to_ucs4(dialog_->filenameED->text()), type); + controller().browse(qstring_to_ucs4(filenameED->text()), type); if (!name.empty()) - dialog_->filenameED->setText(toqstr(name)); + filenameED->setText(toqstr(name)); } -void GuiInclude::edit() +void GuiIncludeDialog::edit() { if (isValid()) { - string const file = fromqstr(dialog_->filenameED->text()); + string const file = fromqstr(filenameED->text()); slotOK(); controller().edit(file); } } -bool GuiInclude::isValid() +bool GuiIncludeDialog::isValid() { - return !dialog_->filenameED->text().isEmpty() && - dialog_->validate_listings_params().empty(); + return !filenameED->text().isEmpty() && + validate_listings_params().empty(); } } // namespace frontend diff --git a/src/frontends/qt4/GuiInclude.h b/src/frontends/qt4/GuiInclude.h index dbed834854..a69c299236 100644 --- a/src/frontends/qt4/GuiInclude.h +++ b/src/frontends/qt4/GuiInclude.h @@ -12,71 +12,51 @@ #ifndef GUIINCLUDE_H #define GUIINCLUDE_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlInclude.h" #include "ui_IncludeUi.h" -#include - namespace lyx { namespace frontend { -class GuiInclude; - -class GuiIncludeDialog : public QDialog, public Ui::IncludeUi { +class GuiIncludeDialog : public GuiDialog, public Ui::IncludeUi +{ Q_OBJECT -public: - GuiIncludeDialog(GuiInclude * form); - void updateLists(); +public: + GuiIncludeDialog(LyXView & lv); - virtual void showView(); - /// validate listings parameters and return an error message, if any - docstring validate_listings_params(); -protected Q_SLOTS: - virtual void change_adaptor(); - virtual void editClicked(); - virtual void browseClicked(); - virtual void typeChanged(int v); +private Q_SLOTS: + void change_adaptor(); + void editClicked(); + void browseClicked(); + void typeChanged(int v); /// AFAIK, QValidator only works for QLineEdit so /// I have to validate listingsED (QTextEdit) manually. /// This function displays a hint or error message returned by /// validate_listings_params void set_listings_msg(); -protected: - virtual void closeEvent(QCloseEvent * e); -private: - GuiInclude * form_; -}; - -class GuiInclude : public GuiView -{ -public: +private: + void closeEvent(QCloseEvent * e); + /// parent controller + ControlInclude & controller() const; /// - friend class GuiIncludeDialog; + void updateLists(); /// - GuiInclude(GuiDialog &); - /// parent controller - ControlInclude & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlInclude const & controller() const - { return static_cast(this->getController()); } -protected: - virtual bool isValid(); -private: + void showView(); + /// validate listings parameters and return an error message, if any + docstring validate_listings_params(); + + /// + bool isValid(); /// Apply changes - virtual void applyView(); + void applyView(); /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); - + void update_contents(); /// edit the child document, .lyx file will be opened in lyx /// other formats will be edited by external applications. void edit(); - /// browse for a file void browse(); }; diff --git a/src/frontends/qt4/GuiIndex.cpp b/src/frontends/qt4/GuiIndex.cpp index c7e3409239..2fcbbe5711 100644 --- a/src/frontends/qt4/GuiIndex.cpp +++ b/src/frontends/qt4/GuiIndex.cpp @@ -12,6 +12,8 @@ #include "GuiIndex.h" +#include "ControlCommand.h" + #include "debug.h" #include "qt_helpers.h" @@ -20,30 +22,30 @@ #include #include - using std::string; -///////////////////////////////////////////////////////////////////// -// -// GuiIndexDialog -// -///////////////////////////////////////////////////////////////////// namespace lyx { namespace frontend { -GuiIndexDialog::GuiIndexDialog(GuiIndex * form) - : form_(form) +GuiIndexDialogBase::GuiIndexDialogBase(LyXView & lv, + docstring const & title, QString const & label) + : GuiDialog(lv, "index") { + label_ = label; setupUi(this); + setViewTitle(title); + setController(new ControlCommand(*this, "index", "index")); - connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK())); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(keywordED, SIGNAL(textChanged(const QString &)), this, SLOT(change_adaptor())); setFocusProxy(keywordED); + keywordLA->setText(label_); + keywordED->setWhatsThis( qt_( "The format of the entry in the index.\n" "\n" @@ -59,72 +61,56 @@ GuiIndexDialog::GuiIndexDialog(GuiIndex * form) "For further details refer to the local LaTeX\n" "documentation.\n") ); -} - -void GuiIndexDialog::change_adaptor() -{ - form_->changed(); + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + bc().setOK(okPB); + bc().setCancel(closePB); + bc().addReadOnly(keywordED); } -void GuiIndexDialog::reject() +ControlCommand & GuiIndexDialogBase::controller() const { - form_->slotClose(); + return static_cast(Dialog::controller()); } -void GuiIndexDialog::closeEvent(QCloseEvent * e) +void GuiIndexDialogBase::change_adaptor() { - form_->slotWMHide(); - e->accept(); + changed(); } -///////////////////////////////////////////////////////////////////// -// -// GuiIndex -// -///////////////////////////////////////////////////////////////////// - - -GuiIndex::GuiIndex(GuiDialog & parent, docstring const & title, - QString const & label) - : GuiView(parent, title), label_(label) +void GuiIndexDialogBase::reject() { + slotClose(); } -void GuiIndex::build_dialog() +void GuiIndexDialogBase::closeEvent(QCloseEvent * e) { - dialog_.reset(new GuiIndexDialog(this)); - - dialog_->keywordLA->setText(label_); - - bc().setOK(dialog_->okPB); - bc().setCancel(dialog_->closePB); - bc().addReadOnly(dialog_->keywordED); + slotWMHide(); + e->accept(); } -void GuiIndex::update_contents() +void GuiIndexDialogBase::update_contents() { docstring const contents = controller().params()["name"]; - dialog_->keywordED->setText(toqstr(contents)); - + keywordED->setText(toqstr(contents)); bc().setValid(!contents.empty()); } -void GuiIndex::applyView() +void GuiIndexDialogBase::applyView() { - controller().params()["name"] = qstring_to_ucs4(dialog_->keywordED->text()); + controller().params()["name"] = qstring_to_ucs4(keywordED->text()); } -bool GuiIndex::isValid() +bool GuiIndexDialogBase::isValid() { - return !dialog_->keywordED->text().isEmpty(); + return !keywordED->text().isEmpty(); } } // namespace frontend diff --git a/src/frontends/qt4/GuiIndex.h b/src/frontends/qt4/GuiIndex.h index a149750588..bbfb4ebbd5 100644 --- a/src/frontends/qt4/GuiIndex.h +++ b/src/frontends/qt4/GuiIndex.h @@ -13,56 +13,57 @@ #ifndef GUIINDEX_H #define GUIINDEX_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlCommand.h" #include "ui_IndexUi.h" -#include - namespace lyx { namespace frontend { -class GuiIndex; - -class GuiIndexDialog : public QDialog, public Ui::IndexUi { +class GuiIndexDialogBase : public GuiDialog, public Ui::IndexUi +{ Q_OBJECT + public: - GuiIndexDialog(GuiIndex * form); + GuiIndexDialogBase(LyXView & lv, docstring const & title, + QString const & label); + +private Q_SLOTS: + void change_adaptor(); + void reject(); -protected Q_SLOTS: - virtual void change_adaptor(); - virtual void reject(); -protected: - virtual void closeEvent(QCloseEvent * e); private: - GuiIndex * form_; + /// + void closeEvent(QCloseEvent * e); + /// parent controller + ControlCommand & controller() const; + /// + bool isValid(); + /// Apply changes + void applyView(); + /// update + void update_contents(); + + /// + QString label_; }; -class GuiIndex : public GuiView +class GuiIndexDialog : public GuiIndexDialogBase { public: - friend class GuiIndexDialog; + GuiIndexDialog(LyXView & lv) + : GuiIndexDialogBase(lv, _("Index Entry"), qt_("&Keyword:")) + {} +}; - GuiIndex(GuiDialog &, docstring const & title, QString const & label); - /// parent controller - ControlCommand & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlCommand const & controller() const - { return static_cast(this->getController()); } -protected: - virtual bool isValid(); -private: - /// Apply changes - virtual void applyView(); - /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); - /// - QString const label_; +class GuiLabelDialog : public GuiIndexDialogBase +{ +public: + GuiLabelDialog(LyXView & lv) + : GuiIndexDialogBase(lv, _("Label"), qt_("&Label:")) + {} }; } // namespace frontend diff --git a/src/frontends/qt4/GuiKeySymbol.h b/src/frontends/qt4/GuiKeySymbol.h index d172552175..89c4e53ac2 100644 --- a/src/frontends/qt4/GuiKeySymbol.h +++ b/src/frontends/qt4/GuiKeySymbol.h @@ -26,7 +26,8 @@ namespace lyx { * * This is some really sick stuff. */ -class GuiKeySymbol : public KeySymbol { +class GuiKeySymbol : public KeySymbol +{ public: GuiKeySymbol(); diff --git a/src/frontends/qt4/GuiListings.cpp b/src/frontends/qt4/GuiListings.cpp index 993fd676bf..dba31748cd 100644 --- a/src/frontends/qt4/GuiListings.cpp +++ b/src/frontends/qt4/GuiListings.cpp @@ -12,6 +12,8 @@ #include #include "GuiListings.h" + +#include "ControlListings.h" #include "qt_helpers.h" #include "insets/InsetListingsParams.h" #include "debug.h" @@ -161,36 +163,58 @@ char const * font_styles_gui[] = -GuiListingsDialog::GuiListingsDialog(GuiListings * form) - : form_(form) +GuiListingsDialog::GuiListingsDialog(LyXView & lv) + : GuiDialog(lv, "listings") { setupUi(this); - - connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); - - connect(languageCO, SIGNAL(currentIndexChanged(int)), this, SLOT(change_adaptor())); - connect(dialectCO, SIGNAL(currentIndexChanged(int)), this, SLOT(change_adaptor())); - connect(inlineCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); - connect(floatCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); - connect(placementLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); - connect(numberSideCO, SIGNAL(currentIndexChanged(int)), this, SLOT(change_adaptor())); - connect(numberStepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); - connect(numberFontSizeCO, SIGNAL(currentIndexChanged(int)), this, SLOT(change_adaptor())); - connect(firstlineLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); - connect(lastlineLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); - connect(fontsizeCO, SIGNAL(currentIndexChanged(int)), this, SLOT(change_adaptor())); - connect(fontstyleCO, SIGNAL(currentIndexChanged(int)), this, SLOT(change_adaptor())); - connect(breaklinesCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); - connect(spaceCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); - connect(spaceInStringCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); - connect(extendedcharsCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); - - connect(listingsED, SIGNAL(textChanged()), this, SLOT(change_adaptor())); - connect(listingsED, SIGNAL(textChanged()), this, SLOT(set_listings_msg())); - connect(bypassCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); - connect(bypassCB, SIGNAL(clicked()), this, SLOT(set_listings_msg())); + setViewTitle(_("Program Listing Settings")); + setController(new ControlListings(*this)); + + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); + + connect(languageCO, SIGNAL(currentIndexChanged(int)), + this, SLOT(change_adaptor())); + connect(dialectCO, SIGNAL(currentIndexChanged(int)), + this, SLOT(change_adaptor())); + connect(inlineCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(floatCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(placementLE, SIGNAL(textChanged(const QString&)), + this, SLOT(change_adaptor())); + connect(numberSideCO, SIGNAL(currentIndexChanged(int)), + this, SLOT(change_adaptor())); + connect(numberStepLE, SIGNAL(textChanged(const QString&)), + this, SLOT(change_adaptor())); + connect(numberFontSizeCO, SIGNAL(currentIndexChanged(int)), + this, SLOT(change_adaptor())); + connect(firstlineLE, SIGNAL(textChanged(const QString&)), + this, SLOT(change_adaptor())); + connect(lastlineLE, SIGNAL(textChanged(const QString&)), + this, SLOT(change_adaptor())); + connect(fontsizeCO, SIGNAL(currentIndexChanged(int)), + this, SLOT(change_adaptor())); + connect(fontstyleCO, SIGNAL(currentIndexChanged(int)), + this, SLOT(change_adaptor())); + connect(breaklinesCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(spaceCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(spaceInStringCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(extendedcharsCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + + connect(listingsED, SIGNAL(textChanged()), + this, SLOT(change_adaptor())); + connect(listingsED, SIGNAL(textChanged()), + this, SLOT(set_listings_msg())); + connect(bypassCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(bypassCB, SIGNAL(clicked()), + this, SLOT(set_listings_msg())); for (int n = 0; languages[n][0]; ++n) languageCO->addItem(qt_(languages_gui[n])); @@ -209,19 +233,34 @@ GuiListingsDialog::GuiListingsDialog(GuiListings * form) firstlineLE->setValidator(new QIntValidator(0, 1000000, this)); lastlineLE->setValidator(new QIntValidator(0, 1000000, this)); placementLE->setValidator(new QRegExpValidator(QRegExp("[\\*tbph]*"), this)); + + bc().setOK(okPB); + bc().setApply(applyPB); + bc().setCancel(closePB); + listingsTB->setPlainText( + qt_("Input listing parameters on the right. Enter ? for a list of parameters.")); + + update_contents(); + +} + + +ControlListings & GuiListingsDialog::controller() const +{ + return static_cast(Dialog::controller()); } void GuiListingsDialog::closeEvent(QCloseEvent * e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } void GuiListingsDialog::change_adaptor() { - form_->changed(); + changed(); } @@ -400,45 +439,16 @@ void GuiListingsDialog::on_languageCO_currentIndexChanged(int index) } -///////////////////////////////////////////////////////////////////// -// -// GuiListings -// -///////////////////////////////////////////////////////////////////// - - -GuiListings::GuiListings(GuiDialog & parent) - : GuiView(parent, _("Program Listing Settings")) -{ -} - - -void GuiListings::build_dialog() -{ - dialog_.reset(new GuiListingsDialog(this)); - - bc().setOK(dialog_->okPB); - bc().setApply(dialog_->applyPB); - bc().setCancel(dialog_->closePB); - dialog_->listingsTB->setPlainText( - qt_("Input listing parameters on the right. Enter ? for a list of parameters.")); - - update_contents(); -} - - -void GuiListings::applyView() +void GuiListingsDialog::applyView() { InsetListingsParams & params = controller().params(); - params.setInline(dialog_->inlineCB->isChecked()); - params.setParams(dialog_->construct_params()); + params.setInline(inlineCB->isChecked()); + params.setParams(construct_params()); controller().setParams(params); } -namespace { - -string plainParam(std::string const & par) +static string plainParam(std::string const & par) { // remove enclosing braces if (prefixIs(par, "{") && suffixIs(par, "}")) @@ -446,36 +456,34 @@ string plainParam(std::string const & par) return par; } -} //namespace anon - -void GuiListings::update_contents() +void GuiListingsDialog::update_contents() { // set default values - dialog_->listingsTB->setPlainText( + listingsTB->setPlainText( qt_("Input listing parameters on the right. Enter ? for a list of parameters.")); - dialog_->languageCO->setCurrentIndex(findToken(languages, "no language")); - dialog_->dialectCO->setCurrentIndex(0); - dialog_->floatCB->setChecked(false); - dialog_->placementLE->clear(); - dialog_->numberSideCO->setCurrentIndex(0); - dialog_->numberStepLE->clear(); - dialog_->numberFontSizeCO->setCurrentIndex(findToken(font_sizes, "default")); - dialog_->firstlineLE->clear(); - dialog_->lastlineLE->clear(); - dialog_->fontstyleCO->setCurrentIndex(findToken(font_styles, "default")); - dialog_->fontsizeCO->setCurrentIndex(findToken(font_sizes, "default")); - dialog_->breaklinesCB->setChecked(false); - dialog_->spaceCB->setChecked(false); - dialog_->spaceInStringCB->setChecked(true); - dialog_->extendedcharsCB->setChecked(false); + languageCO->setCurrentIndex(findToken(languages, "no language")); + dialectCO->setCurrentIndex(0); + floatCB->setChecked(false); + placementLE->clear(); + numberSideCO->setCurrentIndex(0); + numberStepLE->clear(); + numberFontSizeCO->setCurrentIndex(findToken(font_sizes, "default")); + firstlineLE->clear(); + lastlineLE->clear(); + fontstyleCO->setCurrentIndex(findToken(font_styles, "default")); + fontsizeCO->setCurrentIndex(findToken(font_sizes, "default")); + breaklinesCB->setChecked(false); + spaceCB->setChecked(false); + spaceInStringCB->setChecked(true); + extendedcharsCB->setChecked(false); // set values from param string InsetListingsParams & params = controller().params(); - dialog_->inlineCB->setChecked(params.isInline()); + inlineCB->setChecked(params.isInline()); if (params.isInline()) { - dialog_->floatCB->setChecked(false); - dialog_->placementLE->setEnabled(false); + floatCB->setChecked(false); + placementLE->setEnabled(false); } // break other parameters and set values vector pars = getVectorFromString(params.separatedParams(), "\n"); @@ -496,7 +504,7 @@ void GuiListings::update_contents() language = arg; int n = findToken(languages, language); if (n >= 0) { - dialog_->languageCO->setCurrentIndex(n); + languageCO->setCurrentIndex(n); in_gui = true; } // on_languageCO_currentIndexChanged should have set dialects @@ -509,23 +517,23 @@ void GuiListings::update_contents() break; } } - n = dialog_->dialectCO->findText(qt_(dialect_gui)); + n = dialectCO->findText(qt_(dialect_gui)); if (n >= 0) - dialog_->dialectCO->setCurrentIndex(n); + dialectCO->setCurrentIndex(n); else in_gui = false; } if (in_gui) *it = ""; - dialog_->languageCO->setEnabled(in_gui); - dialog_->dialectCO->setEnabled( - in_gui && dialog_->dialectCO->count() > 1); + languageCO->setEnabled(in_gui); + dialectCO->setEnabled( + in_gui && dialectCO->count() > 1); } else if (prefixIs(*it, "float")) { - dialog_->floatCB->setChecked(true); - dialog_->inlineCB->setChecked(false); - dialog_->placementLE->setEnabled(true); + floatCB->setChecked(true); + inlineCB->setChecked(false); + placementLE->setEnabled(true); if (prefixIs(*it, "float=")) - dialog_->placementLE->setText( + placementLE->setText( toqstr(plainParam(it->substr(6)))); *it = ""; } else if (prefixIs(*it, "numbers=")) { @@ -535,24 +543,24 @@ void GuiListings::update_contents() n = 1; else if (s == "right") n = 2; - dialog_->numberSideCO->setCurrentIndex(n); + numberSideCO->setCurrentIndex(n); *it = ""; } else if (prefixIs(*it, "stepnumber=")) { - dialog_->numberStepLE->setText( + numberStepLE->setText( toqstr(plainParam(it->substr(11)))); *it = ""; } else if (prefixIs(*it, "numberstyle=")) { string par = plainParam(it->substr(12)); int n = findToken(font_sizes, par.substr(1)); if (n >= 0) - dialog_->numberFontSizeCO->setCurrentIndex(n); + numberFontSizeCO->setCurrentIndex(n); *it = ""; } else if (prefixIs(*it, "firstline=")) { - dialog_->firstlineLE->setText( + firstlineLE->setText( toqstr(plainParam(it->substr(10)))); *it = ""; } else if (prefixIs(*it, "lastline=")) { - dialog_->lastlineLE->setText( + lastlineLE->setText( toqstr(plainParam(it->substr(9)))); *it = ""; } else if (prefixIs(*it, "basicstyle=")) { @@ -577,42 +585,42 @@ void GuiListings::update_contents() if (!style.empty()) { int n = findToken(font_styles, style.substr(1)); if (n >= 0) - dialog_->fontstyleCO->setCurrentIndex(n); + fontstyleCO->setCurrentIndex(n); } if (!size.empty()) { int n = findToken(font_sizes, size.substr(1)); if (n >= 0) - dialog_->fontsizeCO->setCurrentIndex(n); + fontsizeCO->setCurrentIndex(n); } *it = ""; } } else if (prefixIs(*it, "breaklines=")) { - dialog_->breaklinesCB->setChecked(contains(*it, "true")); + breaklinesCB->setChecked(contains(*it, "true")); *it = ""; } else if (prefixIs(*it, "showspaces=")) { - dialog_->spaceCB->setChecked(contains(*it, "true")); + spaceCB->setChecked(contains(*it, "true")); *it = ""; } else if (prefixIs(*it, "showstringspaces=")) { - dialog_->spaceInStringCB->setChecked(contains(*it, "true")); + spaceInStringCB->setChecked(contains(*it, "true")); *it = ""; } else if (prefixIs(*it, "extendedchars=")) { - dialog_->extendedcharsCB->setChecked(contains(*it, "true")); + extendedcharsCB->setChecked(contains(*it, "true")); *it = ""; } } - dialog_->numberStepLE->setEnabled(dialog_->numberSideCO->currentIndex() > 0); - dialog_->numberFontSizeCO->setEnabled(dialog_->numberSideCO->currentIndex() > 0); + numberStepLE->setEnabled(numberSideCO->currentIndex() > 0); + numberFontSizeCO->setEnabled(numberSideCO->currentIndex() > 0); // parameters that can be handled by widgets are cleared // the rest is put to the extra edit box. string extra = getStringFromVector(pars); - dialog_->listingsED->setPlainText(toqstr(InsetListingsParams(extra).separatedParams())); + listingsED->setPlainText(toqstr(InsetListingsParams(extra).separatedParams())); } -bool GuiListings::isValid() +bool GuiListingsDialog::isValid() { - return dialog_->validate_listings_params().empty(); + return validate_listings_params().empty(); } diff --git a/src/frontends/qt4/GuiListings.h b/src/frontends/qt4/GuiListings.h index f3a41328b4..6ffee237a3 100644 --- a/src/frontends/qt4/GuiListings.h +++ b/src/frontends/qt4/GuiListings.h @@ -12,27 +12,24 @@ #ifndef GUILISTINGS_H #define GUILISTINGS_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlListings.h" #include "ui_ListingsUi.h" -#include - namespace lyx { namespace frontend { -class GuiListings; - -class GuiListingsDialog : public QDialog, public Ui::ListingsUi { +class GuiListingsDialog : public GuiDialog, public Ui::ListingsUi +{ Q_OBJECT public: - GuiListingsDialog(GuiListings * form); + GuiListingsDialog(LyXView & lv); /// get values from all the widgets and form a string std::string construct_params(); /// validate listings parameters and return an error message, if any docstring validate_listings_params(); -protected Q_SLOTS: - virtual void change_adaptor(); +private Q_SLOTS: + void change_adaptor(); /// AFAIK, QValidator only works for QLineEdit so /// I have to validate listingsED (QTextEdit) manually. /// This function displays a hint or error message returned by @@ -46,34 +43,16 @@ protected Q_SLOTS: void on_numberSideCO_currentIndexChanged(int); /// show dialect when language is chosen void on_languageCO_currentIndexChanged(int); -protected: - virtual void closeEvent(QCloseEvent * e); private: - GuiListings * form_; -}; - - -class GuiListings : public GuiView { -public: - friend class GuiListingsDialog; - - GuiListings(GuiDialog &); - /// parent controller - ControlListings & controller() - { return static_cast(this->getController()); } + void closeEvent(QCloseEvent * e); /// parent controller - ControlListings const & controller() const - { return static_cast(this->getController()); } -private: + ControlListings & controller() const; + /// return false if validate_listings_params returns error + bool isValid(); /// Apply changes - virtual void applyView(); + void applyView(); /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); -protected: - /// return false if validate_listings_params returns error - virtual bool isValid(); + void update_contents(); }; } // namespace frontend diff --git a/src/frontends/qt4/GuiLog.cpp b/src/frontends/qt4/GuiLog.cpp index eb56985b40..0a678982e1 100644 --- a/src/frontends/qt4/GuiLog.cpp +++ b/src/frontends/qt4/GuiLog.cpp @@ -10,58 +10,46 @@ #include -#include - #include "GuiLog.h" + +#include "ControlLog.h" #include "qt_helpers.h" #include "frontends/Application.h" #include #include -#include +#include + +#include + namespace lyx { namespace frontend { + ///////////////////////////////////////////////////////////////////// // -// GuiLogDialog +// LogHighlighter // -///////////////////////////////////////////////////////////////////// - +//////////////////////////////////////////////////////////////////// -GuiLogDialog::GuiLogDialog(GuiLog * form) - : form_(form) +class LogHighlighter : public QSyntaxHighlighter { - setupUi(this); +public: + LogHighlighter(QTextDocument * parent); - connect(closePB, SIGNAL(clicked()), - form, SLOT(slotClose())); - connect( updatePB, SIGNAL( clicked() ), - this, SLOT( updateClicked() ) ); -} - - -void GuiLogDialog::closeEvent(QCloseEvent * e) -{ - form_->slotWMHide(); - e->accept(); -} +private: + void highlightBlock(QString const & text); +private: + QTextCharFormat infoFormat; + QTextCharFormat warningFormat; + QTextCharFormat errorFormat; +}; -void GuiLogDialog::updateClicked() -{ - form_->update_contents(); -} -///////////////////////////////////////////////////////////////////// -// -// LogHighlighter -// -///////////////////////////////////////////////////////////////////// - LogHighlighter::LogHighlighter(QTextDocument * parent) : QSyntaxHighlighter(parent) { @@ -106,35 +94,56 @@ void LogHighlighter::highlightBlock(QString const & text) // ///////////////////////////////////////////////////////////////////// +GuiLogDialog::GuiLogDialog(LyXView & lv) + : GuiDialog(lv, "log") +{ + setupUi(this); + setController(new ControlLog(*this)); -GuiLog::GuiLog(GuiDialog & parent) - : GuiView(parent, docstring()) -{} + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); + connect(updatePB, SIGNAL(clicked()), this, SLOT(updateClicked())); + bc().setPolicy(ButtonPolicy::OkCancelPolicy); -void GuiLog::build_dialog() -{ - dialog_.reset(new GuiLogDialog(this)); // set syntax highlighting - highlighter = new LogHighlighter(dialog_->logTB->document()); - // - dialog_->logTB->setReadOnly(true); + highlighter = new LogHighlighter(logTB->document()); + + logTB->setReadOnly(true); QFont font(toqstr(theApp()->typewriterFontName())); font.setKerning(false); font.setFixedPitch(true); font.setStyleHint(QFont::TypeWriter); - dialog_->logTB->setFont(font); + logTB->setFont(font); +} + + +ControlLog & GuiLogDialog::controller() const +{ + return static_cast(Dialog::controller()); +} + + +void GuiLogDialog::closeEvent(QCloseEvent * e) +{ + slotWMHide(); + e->accept(); +} + + +void GuiLogDialog::updateClicked() +{ + update_contents(); } -void GuiLog::update_contents() +void GuiLogDialog::update_contents() { setViewTitle(controller().title()); std::ostringstream ss; controller().getContents(ss); - dialog_->logTB->setPlainText(toqstr(ss.str())); + logTB->setPlainText(toqstr(ss.str())); } } // namespace frontend diff --git a/src/frontends/qt4/GuiLog.h b/src/frontends/qt4/GuiLog.h index efdddde7e6..ad6fe49e1b 100644 --- a/src/frontends/qt4/GuiLog.h +++ b/src/frontends/qt4/GuiLog.h @@ -12,76 +12,36 @@ #ifndef GUILOG_H #define GUILOG_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlLog.h" #include "ui_LogUi.h" -#include -#include - namespace lyx { namespace frontend { -class GuiLog; - -class GuiLogDialog : public QDialog, public Ui::LogUi { - Q_OBJECT -public: - GuiLogDialog(GuiLog * form); -protected Q_SLOTS: - virtual void updateClicked(); -protected: - virtual void closeEvent(QCloseEvent * e); -private: - GuiLog * form_; -}; - - -class ControlLog; class LogHighlighter; -/// -class GuiLog : public GuiView +class GuiLogDialog : public GuiDialog, public Ui::LogUi { + Q_OBJECT public: - /// - friend class GuiLogDialog; - /// - GuiLog(GuiDialog &); - /// parent controller - ControlLog & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlLog const & controller() const - { return static_cast(this->getController()); } + GuiLogDialog(LyXView & lv); +private Q_SLOTS: + void updateClicked(); private: + void closeEvent(QCloseEvent * e); + /// parent controller + ControlLog & controller() const; /// Apply changes - virtual void applyView() {} + void applyView() {} /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); + void update_contents(); + /// log syntax highlighter LogHighlighter * highlighter; }; -/// -class LogHighlighter : public QSyntaxHighlighter -{ -public: - LogHighlighter(QTextDocument * parent); - -protected: - void highlightBlock(QString const & text); - -private: - QTextCharFormat infoFormat; - QTextCharFormat warningFormat; - QTextCharFormat errorFormat; -}; - - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiMathMatrix.cpp b/src/frontends/qt4/GuiMathMatrix.cpp index 5d43963413..f4ba1b142b 100644 --- a/src/frontends/qt4/GuiMathMatrix.cpp +++ b/src/frontends/qt4/GuiMathMatrix.cpp @@ -12,6 +12,7 @@ #include "GuiMathMatrix.h" +#include "ControlMath.h" #include "EmptyTable.h" #include "qt_helpers.h" #include "gettext.h" @@ -28,21 +29,12 @@ using std::string; namespace lyx { namespace frontend { -GuiMathMatrix::GuiMathMatrix(GuiDialog & parent) - : GuiView(parent, _("Math Matrix")) -{} - - -void GuiMathMatrix::build_dialog() -{ - dialog_.reset(new GuiMathMatrixDialog(this)); -} - - -GuiMathMatrixDialog::GuiMathMatrixDialog(GuiMathMatrix * form) - : form_(form) +GuiMathMatrixDialog::GuiMathMatrixDialog(LyXView & lv) + : GuiDialog(lv, "mathmatrix") { setupUi(this); + setViewTitle(_("Math Matrix")); + setController(new ControlMath(*this)); setWindowTitle(qt_("LyX: Insert Matrix")); @@ -70,6 +62,14 @@ GuiMathMatrixDialog::GuiMathMatrixDialog(GuiMathMatrix * form) this, SLOT(change_adaptor())); connect(halignED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); + + bc().setPolicy(ButtonPolicy::IgnorantPolicy); +} + + +ControlMath & GuiMathMatrixDialog::controller() const +{ + return static_cast(Dialog::controller()); } @@ -106,7 +106,7 @@ void GuiMathMatrixDialog::slotOK() ostringstream os; os << nx << ' ' << ny << ' ' << c << ' ' << sh; - form_->controller().dispatchMatrix(os.str().c_str()); + controller().dispatchMatrix(os.str().c_str()); // close the dialog close(); diff --git a/src/frontends/qt4/GuiMathMatrix.h b/src/frontends/qt4/GuiMathMatrix.h index ac1448c194..7eae605d0b 100644 --- a/src/frontends/qt4/GuiMathMatrix.h +++ b/src/frontends/qt4/GuiMathMatrix.h @@ -14,7 +14,7 @@ #ifndef GUIMATHMATRIXDIALOG_H #define GUIMATHMATRIXDIALOG_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlMath.h" #include "ui_MathMatrixUi.h" @@ -23,45 +23,24 @@ namespace lyx { namespace frontend { -class GuiMathMatrix; -class ControlMath; - - -class GuiMathMatrixDialog : public QDialog, public Ui::MathMatrixUi { +class GuiMathMatrixDialog : public GuiDialog, public Ui::MathMatrixUi +{ Q_OBJECT + public: - GuiMathMatrixDialog(GuiMathMatrix * form); + GuiMathMatrixDialog(LyXView & lv); + public Q_SLOTS: void slotOK(); void slotClose(); -protected Q_SLOTS: - virtual void columnsChanged(int); - virtual void rowsChanged(int); - virtual void change_adaptor(); -private: - GuiMathMatrix * form_; -}; + void columnsChanged(int); + void rowsChanged(int); + void change_adaptor(); - -class GuiMathMatrix : public GuiView { -public: - friend class GuiMathMatrixDialog; - - GuiMathMatrix(GuiDialog &); /// parent controller - ControlMath & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlMath const & controller() const - { return static_cast(this->getController()); } -private: - virtual void applyView() {} - virtual void update_contents() {} - /// Build the dialog. - virtual void build_dialog(); + ControlMath & controller() const; }; - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiMenubar.h b/src/frontends/qt4/GuiMenubar.h index 959668ab7d..2ccacc322a 100644 --- a/src/frontends/qt4/GuiMenubar.h +++ b/src/frontends/qt4/GuiMenubar.h @@ -32,7 +32,8 @@ namespace frontend { class GuiViewBase; class LyXView; -class GuiMenubar : public QObject { +class GuiMenubar : public QObject +{ Q_OBJECT public: GuiMenubar(LyXView *, MenuBackend &); diff --git a/src/frontends/qt4/GuiNomencl.cpp b/src/frontends/qt4/GuiNomencl.cpp index 13abbeaa77..c244354e8c 100644 --- a/src/frontends/qt4/GuiNomencl.cpp +++ b/src/frontends/qt4/GuiNomencl.cpp @@ -29,25 +29,33 @@ using std::string; namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiNomenclDialog -// -///////////////////////////////////////////////////////////////////// - -GuiNomenclDialog::GuiNomenclDialog(GuiNomencl * form) - : form_(form) +GuiNomenclDialog::GuiNomenclDialog(LyXView & lv) + : GuiDialog(lv, "nomenclature") { setupUi(this); + setController(new ControlCommand(*this, "nomenclature", "nomenclature")); - connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK())); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(symbolED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); connect(descriptionTE, SIGNAL(textChanged()), this, SLOT(change_adaptor())); setFocusProxy(descriptionTE); + + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + bc().setOK(okPB); + bc().setCancel(closePB); + bc().addReadOnly(symbolED); + bc().addReadOnly(descriptionTE); + bc().addReadOnly(prefixED); +} + + +ControlCommand & GuiNomenclDialog::controller() const +{ + return static_cast(Dialog::controller()); } @@ -59,74 +67,49 @@ void GuiNomenclDialog::showView() void GuiNomenclDialog::change_adaptor() { - form_->changed(); + changed(); } void GuiNomenclDialog::reject() { - form_->slotClose(); + slotClose(); } void GuiNomenclDialog::closeEvent(QCloseEvent * e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } -///////////////////////////////////////////////////////////////////// -// -// GuiNomencl -// -///////////////////////////////////////////////////////////////////// - - -GuiNomencl::GuiNomencl(GuiDialog & parent, docstring const & title) - : GuiView(parent, title) -{ -} - - -void GuiNomencl::build_dialog() -{ - dialog_.reset(new GuiNomenclDialog(this)); - - bc().setOK(dialog_->okPB); - bc().setCancel(dialog_->closePB); - bc().addReadOnly(dialog_->symbolED); - bc().addReadOnly(dialog_->descriptionTE); - bc().addReadOnly(dialog_->prefixED); -} - - -void GuiNomencl::update_contents() +void GuiNomenclDialog::update_contents() { - dialog_->prefixED->setText(toqstr(controller().params()["prefix"])); - dialog_->symbolED->setText(toqstr(controller().params()["symbol"])); + prefixED->setText(toqstr(controller().params()["prefix"])); + symbolED->setText(toqstr(controller().params()["symbol"])); QString description = toqstr(controller().params()["description"]); description.replace("\\\\","\n"); - dialog_->descriptionTE->setPlainText(description); + descriptionTE->setPlainText(description); bc().setValid(isValid()); } -void GuiNomencl::applyView() +void GuiNomenclDialog::applyView() { - controller().params()["prefix"] = qstring_to_ucs4(dialog_->prefixED->text()); - controller().params()["symbol"] = qstring_to_ucs4(dialog_->symbolED->text()); - QString description = dialog_->descriptionTE->toPlainText(); + controller().params()["prefix"] = qstring_to_ucs4(prefixED->text()); + controller().params()["symbol"] = qstring_to_ucs4(symbolED->text()); + QString description = descriptionTE->toPlainText(); description.replace('\n',"\\\\"); controller().params()["description"] = qstring_to_ucs4(description); } -bool GuiNomencl::isValid() +bool GuiNomenclDialog::isValid() { - QString const description = dialog_->descriptionTE->toPlainText(); - return !dialog_->symbolED->text().isEmpty() && !description.isEmpty(); + QString const description = descriptionTE->toPlainText(); + return !symbolED->text().isEmpty() && !description.isEmpty(); } } // namespace frontend diff --git a/src/frontends/qt4/GuiNomencl.h b/src/frontends/qt4/GuiNomencl.h index 3e78c943fe..4a4dfcb2bc 100644 --- a/src/frontends/qt4/GuiNomencl.h +++ b/src/frontends/qt4/GuiNomencl.h @@ -14,55 +14,37 @@ #ifndef GUINOMENCL_H #define GUINOMENCL_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlCommand.h" #include "ui_NomenclUi.h" -#include - - namespace lyx { namespace frontend { -class GuiNomencl; - -class GuiNomenclDialog : public QDialog, public Ui::NomenclUi +class GuiNomenclDialog : public GuiDialog, public Ui::NomenclUi { Q_OBJECT -public: - GuiNomenclDialog(GuiNomencl * form); - virtual void showView(); -protected Q_SLOTS: - virtual void change_adaptor(); - virtual void reject(); -protected: - virtual void closeEvent(QCloseEvent * e); -private: - GuiNomencl * form_; -}; - -class GuiNomencl : public GuiView -{ public: - friend class GuiNomenclDialog; + GuiNomenclDialog(LyXView & lv); + +private Q_SLOTS: + void change_adaptor(); + void reject(); - GuiNomencl(GuiDialog &, docstring const & title); - /// parent controller - ControlCommand & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlCommand const & controller() const - { return static_cast(this->getController()); } -protected: - virtual bool isValid(); private: + /// + void showView(); + /// + void closeEvent(QCloseEvent * e); + /// parent controller + ControlCommand & controller() const; + /// + bool isValid(); /// Apply changes - virtual void applyView(); + void applyView(); /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); + void update_contents(); }; } // namespace frontend diff --git a/src/frontends/qt4/GuiNote.cpp b/src/frontends/qt4/GuiNote.cpp index 12b34458c6..007c1758e6 100644 --- a/src/frontends/qt4/GuiNote.cpp +++ b/src/frontends/qt4/GuiNote.cpp @@ -12,6 +12,7 @@ #include "GuiNote.h" +#include "ControlNote.h" #include "insets/InsetNote.h" #include @@ -19,81 +20,66 @@ namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiNoteDialog -// -///////////////////////////////////////////////////////////////////// - -GuiNoteDialog::GuiNoteDialog(GuiNote * form) - : form_(form) +GuiNoteDialog::GuiNoteDialog(LyXView & lv) + : GuiDialog(lv, "note") { setupUi(this); + setController(new ControlNote(*this)); + setViewTitle(_("Note Settings")); - connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK())); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(noteRB, SIGNAL(clicked()), this, SLOT(change_adaptor())); connect(greyedoutRB, SIGNAL(clicked()), this, SLOT(change_adaptor())); connect(commentRB, SIGNAL(clicked()), this, SLOT(change_adaptor())); connect(framedRB, SIGNAL(clicked()), this, SLOT(change_adaptor())); connect(shadedRB, SIGNAL(clicked()), this, SLOT(change_adaptor())); + + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + bc().setOK(okPB); + bc().setCancel(closePB); } -void GuiNoteDialog::closeEvent(QCloseEvent * e) +ControlNote & GuiNoteDialog::controller() const { - form_->slotWMHide(); - e->accept(); + return static_cast(Dialog::controller()); } -void GuiNoteDialog::change_adaptor() +void GuiNoteDialog::closeEvent(QCloseEvent * e) { - form_->changed(); + slotWMHide(); + e->accept(); } -///////////////////////////////////////////////////////////////////// -// -// GuiNote -// -///////////////////////////////////////////////////////////////////// - - -GuiNote::GuiNote(GuiDialog & parent) - : GuiView(parent, _("Note Settings")) -{} - - -void GuiNote::build_dialog() +void GuiNoteDialog::change_adaptor() { - dialog_.reset(new GuiNoteDialog(this)); - - bc().setOK(dialog_->okPB); - bc().setCancel(dialog_->closePB); + changed(); } -void GuiNote::update_contents() +void GuiNoteDialog::update_contents() { QRadioButton * rb = 0; switch (controller().params().type) { case InsetNoteParams::Note: - rb = dialog_->noteRB; + rb = noteRB; break; case InsetNoteParams::Comment: - rb = dialog_->commentRB; + rb = commentRB; break; case InsetNoteParams::Greyedout: - rb = dialog_->greyedoutRB; + rb = greyedoutRB; break; case InsetNoteParams::Framed: - rb = dialog_->framedRB; + rb = framedRB; break; case InsetNoteParams::Shaded: - rb = dialog_->shadedRB; + rb = shadedRB; break; } @@ -101,17 +87,17 @@ void GuiNote::update_contents() } -void GuiNote::applyView() +void GuiNoteDialog::applyView() { InsetNoteParams::Type type; - if (dialog_->greyedoutRB->isChecked()) + if (greyedoutRB->isChecked()) type = InsetNoteParams::Greyedout; - else if (dialog_->commentRB->isChecked()) + else if (commentRB->isChecked()) type = InsetNoteParams::Comment; - else if (dialog_->framedRB->isChecked()) + else if (framedRB->isChecked()) type = InsetNoteParams::Framed; - else if (dialog_->shadedRB->isChecked()) + else if (shadedRB->isChecked()) type = InsetNoteParams::Shaded; else type = InsetNoteParams::Note; diff --git a/src/frontends/qt4/GuiNote.h b/src/frontends/qt4/GuiNote.h index 649b37bb9f..e1f6e57f5f 100644 --- a/src/frontends/qt4/GuiNote.h +++ b/src/frontends/qt4/GuiNote.h @@ -12,53 +12,28 @@ #ifndef GUINOTE_H #define GUINOTE_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlNote.h" #include "ui_NoteUi.h" -#include - - namespace lyx { namespace frontend { -class GuiNote; - -class GuiNoteDialog : public QDialog, public Ui::NoteUi { +class GuiNoteDialog : public GuiDialog, public Ui::NoteUi +{ Q_OBJECT public: - GuiNoteDialog(GuiNote * form); -protected Q_SLOTS: - virtual void change_adaptor(); -protected: - virtual void closeEvent(QCloseEvent * e); + GuiNoteDialog(LyXView & lv); +private Q_SLOTS: + void change_adaptor(); private: - GuiNote * form_; -}; - - -/** This class provides a QT implementation of the Note Dialog. - */ -class GuiNote : public GuiView -{ -public: - friend class GuiNoteDialog; - - /// Constructor - GuiNote(GuiDialog &); - /// parent controller - ControlNote & controller() - { return static_cast(this->getController()); } + void closeEvent(QCloseEvent * e); /// parent controller - ControlNote const & controller() const - { return static_cast(this->getController()); } -private: - /// Apply changes - virtual void applyView(); - /// Build the dialog - virtual void build_dialog(); + ControlNote & controller() const; + /// Apply changes + void applyView(); /// Update dialog before showing it - virtual void update_contents(); + void update_contents(); }; } // namespace frontend diff --git a/src/frontends/qt4/GuiParagraph.cpp b/src/frontends/qt4/GuiParagraph.cpp index 8cc07ab250..dd6fc22418 100644 --- a/src/frontends/qt4/GuiParagraph.cpp +++ b/src/frontends/qt4/GuiParagraph.cpp @@ -13,6 +13,8 @@ #include "GuiParagraph.h" +#include "ControlParagraph.h" + #include "debug.h" #include "frontend_helpers.h" #include "ParagraphParameters.h" @@ -24,30 +26,25 @@ #include #include +#include + using std::string; using std::endl; -///////////////////////////////////////////////////////////////////// -// -// GuiParagraphDialog -// -///////////////////////////////////////////////////////////////////// - - -#include - namespace lyx { namespace frontend { -GuiParagraphDialog::GuiParagraphDialog(GuiParagraph * form) - : form_(form) +GuiParagraphDialog::GuiParagraphDialog(LyXView & lv) + : GuiDialog(lv, "paragraph") { setupUi(this); + setViewTitle(_("Paragraph Settings")); + setController(new ControlParagraph(*this)); - connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose())); - connect(restorePB, SIGNAL(clicked()), form_, SLOT(slotRestore())); + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); + connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore())); connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(change_adaptor())); connect(alignJustRB, SIGNAL(clicked()), this, SLOT(change_adaptor())); connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(change_adaptor())); @@ -86,19 +83,31 @@ GuiParagraphDialog::GuiParagraphDialog(GuiParagraph * form) labelMap[LYX_ALIGN_LEFT] = _("Left"); labelMap[LYX_ALIGN_RIGHT] = _("Right"); labelMap[LYX_ALIGN_CENTER] = _("Center"); + + bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); + bc().setOK(okPB); + bc().setApply(applyPB); + bc().setCancel(closePB); + bc().setRestore(restorePB); +} + + +ControlParagraph & GuiParagraphDialog::controller() const +{ + return static_cast(Dialog::controller()); } void GuiParagraphDialog::closeEvent(QCloseEvent * e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } void GuiParagraphDialog::change_adaptor() { - form_->changed(); + changed(); } @@ -110,23 +119,23 @@ void GuiParagraphDialog::enableLinespacingValue(int) void GuiParagraphDialog::checkAlignmentRadioButtons() { - LyXAlignment const alignPossible = form_->controller().alignPossible(); + LyXAlignment const alignPossible = controller().alignPossible(); - QPRadioMap::iterator it = radioMap.begin(); + RadioMap::iterator it = radioMap.begin(); for (; it != radioMap.end(); ++it) { LyXAlignment const align = it->first; it->second->setEnabled(align & alignPossible); } docstring label = labelMap[LYX_ALIGN_LAYOUT]; - if (!form_->controller().haveMulitParSelection()) - label += (" (" + labelMap[form_->controller().alignDefault()] + ")"); + if (!controller().haveMulitParSelection()) + label += (" (" + labelMap[controller().alignDefault()] + ")"); alignDefaultRB->setText(toqstr(label)); } void GuiParagraphDialog::alignmentToRadioButtons(LyXAlignment align) { - QPRadioMap::const_iterator it = radioMap.begin(); + RadioMap::const_iterator it = radioMap.begin(); for (;it != radioMap.end(); ++it) { if (align == it->first) { it->second->blockSignals(true); @@ -144,7 +153,7 @@ void GuiParagraphDialog::alignmentToRadioButtons(LyXAlignment align) LyXAlignment GuiParagraphDialog::getAlignmentFromDialog() { LyXAlignment alignment = LYX_ALIGN_NONE; - QPRadioMap::const_iterator it = radioMap.begin(); + RadioMap::const_iterator it = radioMap.begin(); for (; it != radioMap.end(); ++it) { if (it->second->isChecked()) { alignment = it->first; @@ -155,70 +164,45 @@ LyXAlignment GuiParagraphDialog::getAlignmentFromDialog() } -///////////////////////////////////////////////////////////////////// -// -// GuiParagraph -// -///////////////////////////////////////////////////////////////////// - - -GuiParagraph::GuiParagraph(GuiDialog & parent) - : GuiView(parent, _("Paragraph Settings")) -{} - - -void GuiParagraph::build_dialog() -{ - // the dialog - dialog_.reset(new GuiParagraphDialog(this)); - - // Manage the ok, apply, restore and cancel/close buttons - bc().setOK(dialog_->okPB); - bc().setApply(dialog_->applyPB); - bc().setCancel(dialog_->closePB); - bc().setRestore(dialog_->restorePB); -} - - -void GuiParagraph::applyView() +void GuiParagraphDialog::applyView() { ParagraphParameters & params = controller().params(); - params.align(dialog_->getAlignmentFromDialog()); + params.align(getAlignmentFromDialog()); // get spacing - Spacing::Space linespacing = Spacing::Default; + Spacing::Space ls = Spacing::Default; string other; - switch (dialog_->linespacing->currentIndex()) { + switch (linespacing->currentIndex()) { case 0: - linespacing = Spacing::Default; + ls = Spacing::Default; break; case 1: - linespacing = Spacing::Single; + ls = Spacing::Single; break; case 2: - linespacing = Spacing::Onehalf; + ls = Spacing::Onehalf; break; case 3: - linespacing = Spacing::Double; + ls = Spacing::Double; break; case 4: - linespacing = Spacing::Other; - other = fromqstr(dialog_->linespacingValue->text()); + ls = Spacing::Other; + other = fromqstr(linespacingValue->text()); break; } - Spacing const spacing(linespacing, other); + Spacing const spacing(ls, other); params.spacing(spacing); // label width - params.labelWidthString(qstring_to_ucs4(dialog_->labelWidth->text())); + params.labelWidthString(qstring_to_ucs4(labelWidth->text())); // indendation - params.noindent(!dialog_->indentCB->isChecked()); + params.noindent(!indentCB->isChecked()); } -void GuiParagraph::update_contents() +void GuiParagraphDialog::update_contents() { ParagraphParameters const & params = controller().params(); @@ -226,49 +210,49 @@ void GuiParagraph::update_contents() docstring const & labelwidth = params.labelWidthString(); // FIXME We should not compare translated strings if (labelwidth != _("Senseless with this layout!")) { - dialog_->labelwidthGB->setEnabled(true); - dialog_->labelWidth->setText(toqstr(labelwidth)); + labelwidthGB->setEnabled(true); + labelWidth->setText(toqstr(labelwidth)); } else { - dialog_->labelwidthGB->setEnabled(false); - dialog_->labelWidth->setText(""); + labelwidthGB->setEnabled(false); + labelWidth->setText(""); } // alignment - dialog_->checkAlignmentRadioButtons(); - dialog_->alignmentToRadioButtons(params.align()); + checkAlignmentRadioButtons(); + alignmentToRadioButtons(params.align()); //indentation bool const canindent = controller().canIndent(); - dialog_->indentCB->setEnabled(canindent); - dialog_->indentCB->setChecked(canindent && !params.noindent()); + indentCB->setEnabled(canindent); + indentCB->setChecked(canindent && !params.noindent()); // linespacing - int linespacing; + int ls; Spacing const & space = params.spacing(); switch (space.getSpace()) { case Spacing::Single: - linespacing = 1; + ls = 1; break; case Spacing::Onehalf: - linespacing = 2; + ls = 2; break; case Spacing::Double: - linespacing = 3; + ls = 3; break; case Spacing::Other: - linespacing = 4; + ls = 4; break; default: - linespacing = 0; + ls = 0; break; } - dialog_->linespacing->setCurrentIndex(linespacing); + linespacing->setCurrentIndex(ls); if (space.getSpace() == Spacing::Other) { - dialog_->linespacingValue->setText(toqstr(space.getValueAsString())); - dialog_->linespacingValue->setEnabled(true); + linespacingValue->setText(toqstr(space.getValueAsString())); + linespacingValue->setEnabled(true); } else { - dialog_->linespacingValue->setText(""); - dialog_->linespacingValue->setEnabled(false); + linespacingValue->setText(QString()); + linespacingValue->setEnabled(false); } } diff --git a/src/frontends/qt4/GuiParagraph.h b/src/frontends/qt4/GuiParagraph.h index 7255241faf..18f1180ce8 100644 --- a/src/frontends/qt4/GuiParagraph.h +++ b/src/frontends/qt4/GuiParagraph.h @@ -13,66 +13,48 @@ #ifndef GUIPARAGRAPH_H #define GUIPARAGRAPH_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlParagraph.h" #include "Layout.h" #include "ui_ParagraphUi.h" -#include - #include namespace lyx { namespace frontend { -class GuiParagraph; - -class GuiParagraphDialog : public QDialog, public Ui::ParagraphUi { +class GuiParagraphDialog : public GuiDialog, public Ui::ParagraphUi +{ Q_OBJECT public: - GuiParagraphDialog(GuiParagraph * form); + GuiParagraphDialog(LyXView & lv); /// void checkAlignmentRadioButtons(); /// void alignmentToRadioButtons(LyXAlignment align = LYX_ALIGN_LAYOUT); /// LyXAlignment getAlignmentFromDialog(); -protected: - void closeEvent (QCloseEvent * e); private: - GuiParagraph * form_; - typedef std::map QPRadioMap; - QPRadioMap radioMap; - typedef std::map QPAlignmentLabels; - QPAlignmentLabels labelMap; + /// + void closeEvent(QCloseEvent * e); + /// + typedef std::map RadioMap; + RadioMap radioMap; + /// + typedef std::map AlignmentLabels; + AlignmentLabels labelMap; -protected Q_SLOTS: +private Q_SLOTS: /// void change_adaptor(); /// void enableLinespacingValue(int); -}; - - -class GuiParagraph : public GuiView -{ -public: - friend class GuiParagraphDialog; - - GuiParagraph(GuiDialog &); - /// parent controller - ControlParagraph & controller() - { return static_cast(this->getController()); } /// parent controller - ControlParagraph const & controller() const - { return static_cast(this->getController()); } -private: + ControlParagraph & controller() const; /// Apply changes - virtual void applyView(); + void applyView(); /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); + void update_contents(); }; } // namespace frontend diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index c86e31c329..9c30830572 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -11,6 +11,7 @@ #include #include "GuiPrefs.h" +#include "ControlPrefs.h" #include "qt_helpers.h" #include "GuiApplication.h" @@ -27,8 +28,7 @@ #include "support/lstrings.h" #include "support/os.h" -#include "controllers/ControlPrefs.h" -#include "controllers/frontend_helpers.h" +#include "frontend_helpers.h" #include "frontends/alert.h" #include "frontends/Application.h" @@ -225,7 +225,7 @@ void PrefDate::update(LyXRC const & rc) // ///////////////////////////////////////////////////////////////////// -PrefKeyboard::PrefKeyboard(GuiPrefs * form, QWidget * parent) +PrefKeyboard::PrefKeyboard(GuiPrefsDialog * form, QWidget * parent) : PrefModule(_("Keyboard"), form, parent) { setupUi(this); @@ -296,7 +296,7 @@ void PrefKeyboard::on_keymapCB_toggled(bool keymap) // ///////////////////////////////////////////////////////////////////// -PrefLatex::PrefLatex(GuiPrefs * form, QWidget * parent) +PrefLatex::PrefLatex(GuiPrefsDialog * form, QWidget * parent) : PrefModule(_("LaTeX"), form, parent) { setupUi(this); @@ -364,7 +364,7 @@ void PrefLatex::update(LyXRC const & rc) // ///////////////////////////////////////////////////////////////////// -PrefScreenFonts::PrefScreenFonts(GuiPrefs * form, QWidget * parent) +PrefScreenFonts::PrefScreenFonts(GuiPrefsDialog * form, QWidget * parent) : PrefModule(_("Screen fonts"), form, parent) { setupUi(this); @@ -522,7 +522,7 @@ void PrefScreenFonts::select_typewriter(const QString& name) // ///////////////////////////////////////////////////////////////////// -PrefColors::PrefColors(GuiPrefs * form, QWidget * parent) +PrefColors::PrefColors(GuiPrefsDialog * form, QWidget * parent) : PrefModule( _("Colors"), form, parent) { setupUi(this); @@ -694,7 +694,7 @@ void PrefDisplay::update(LyXRC const & rc) // ///////////////////////////////////////////////////////////////////// -PrefPaths::PrefPaths(GuiPrefs * form, QWidget * parent) +PrefPaths::PrefPaths(GuiPrefsDialog * form, QWidget * parent) : PrefModule(_("Paths"), form, parent) { setupUi(this); @@ -798,7 +798,7 @@ void PrefPaths::select_lyxpipe() // ///////////////////////////////////////////////////////////////////// -PrefSpellchecker::PrefSpellchecker(GuiPrefs * form, QWidget * parent) +PrefSpellchecker::PrefSpellchecker(GuiPrefsDialog * form, QWidget * parent) : PrefModule(_("Spellchecker"), form, parent) { setupUi(this); @@ -908,7 +908,7 @@ void PrefSpellchecker::select_dict() ///////////////////////////////////////////////////////////////////// -PrefConverters::PrefConverters(GuiPrefs * form, QWidget * parent) +PrefConverters::PrefConverters(GuiPrefsDialog * form, QWidget * parent) : PrefModule(_("Converters"), form, parent) { setupUi(this); @@ -1106,7 +1106,7 @@ void PrefConverters::on_cacheCB_stateChanged(int state) // ///////////////////////////////////////////////////////////////////// -PrefCopiers::PrefCopiers(GuiPrefs * form, QWidget * parent) +PrefCopiers::PrefCopiers(GuiPrefsDialog * form, QWidget * parent) : PrefModule(_("Copiers"), form, parent) { setupUi(this); @@ -1359,7 +1359,7 @@ void PrefCopiers::remove_copier() // ///////////////////////////////////////////////////////////////////// -PrefFileformats::PrefFileformats(GuiPrefs * form, QWidget * parent) +PrefFileformats::PrefFileformats(GuiPrefsDialog * form, QWidget * parent) : PrefModule(_("File formats"), form, parent) { setupUi(this); @@ -1751,7 +1751,7 @@ void PrefPrinter::update(LyXRC const & rc) // ///////////////////////////////////////////////////////////////////// -PrefUserInterface::PrefUserInterface(GuiPrefs * form, QWidget * parent) +PrefUserInterface::PrefUserInterface(GuiPrefsDialog * form, QWidget * parent) : PrefModule(_("User interface"), form, parent) { setupUi(this); @@ -1902,43 +1902,46 @@ void PrefIdentity::update(LyXRC const & rc) // ///////////////////////////////////////////////////////////////////// -GuiPrefsDialog::GuiPrefsDialog(GuiPrefs * form) - : form_(form) +GuiPrefsDialog::GuiPrefsDialog(LyXView & lv) + : GuiDialog(lv, "prefs") { setupUi(this); + setViewTitle(_("Preferences")); + setController(new ControlPrefs(*this)); + QDialog::setModal(false); - connect(savePB, SIGNAL(clicked()), form, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); - connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore())); + connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); + connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore())); - add(new PrefUserInterface(form_)); - add(new PrefScreenFonts(form_)); - add(new PrefColors(form_)); + add(new PrefUserInterface(this)); + add(new PrefScreenFonts(this)); + add(new PrefColors(this)); add(new PrefDisplay); - add(new PrefKeyboard(form_)); + add(new PrefKeyboard(this)); - add(new PrefPaths(form_)); + add(new PrefPaths(this)); add(new PrefIdentity); add(new PrefLanguage); - add(new PrefSpellchecker(form_)); + add(new PrefSpellchecker(this)); add(new PrefPrinter); add(new PrefDate); add(new PrefPlaintext); - add(new PrefLatex(form_)); + add(new PrefLatex(this)); - PrefConverters * converters = new PrefConverters(form_); - PrefFileformats * formats = new PrefFileformats(form_); + PrefConverters * converters = new PrefConverters(this); + PrefFileformats * formats = new PrefFileformats(this); connect(formats, SIGNAL(formatsChanged()), converters, SLOT(updateGui())); add(converters); add(formats); - add(new PrefCopiers(form_)); + add(new PrefCopiers(this)); prefsPS->setCurrentPanel(_("User interface")); @@ -1948,34 +1951,39 @@ GuiPrefsDialog::GuiPrefsDialog(GuiPrefs * form) prefsPS->updateGeometry(); #endif - form_->bc().setOK(savePB); - form_->bc().setApply(applyPB); - form_->bc().setCancel(closePB); - form_->bc().setRestore(restorePB); + bc().setPolicy(ButtonPolicy::PreferencesPolicy); + bc().setOK(savePB); + bc().setApply(applyPB); + bc().setCancel(closePB); + bc().setRestore(restorePB); +} + + +ControlPrefs & GuiPrefsDialog::controller() const +{ + return static_cast(Dialog::controller()); } void GuiPrefsDialog::add(PrefModule * module) { BOOST_ASSERT(module); - prefsPS->addPanel(module, module->title()); - connect(module, SIGNAL(changed()), this, SLOT(change_adaptor())); - modules_.push_back(module); } + void GuiPrefsDialog::closeEvent(QCloseEvent * e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } void GuiPrefsDialog::change_adaptor() { - form_->changed(); + changed(); } @@ -1995,46 +2003,29 @@ void GuiPrefsDialog::updateRc(LyXRC const & rc) } -///////////////////////////////////////////////////////////////////// -// -// GuiPrefs -// -///////////////////////////////////////////////////////////////////// - - -GuiPrefs::GuiPrefs(GuiDialog & parent) - : GuiView(parent, _("Preferences")) -{ -} - -Converters & GuiPrefs::converters() +Converters & GuiPrefsDialog::converters() { return controller().converters(); } -Formats & GuiPrefs::formats() +Formats & GuiPrefsDialog::formats() { return controller().formats(); } -Movers & GuiPrefs::movers() +Movers & GuiPrefsDialog::movers() { return controller().movers(); } -void GuiPrefs::build_dialog() -{ - dialog_.reset(new GuiPrefsDialog(this)); -} - -void GuiPrefs::applyView() +void GuiPrefsDialog::applyView() { - dialog_->apply(controller().rc()); + apply(controller().rc()); } -void GuiPrefs::update_contents() +void GuiPrefsDialog::update_contents() { - dialog_->updateRc(controller().rc()); + updateRc(controller().rc()); } } // namespace frontend diff --git a/src/frontends/qt4/GuiPrefs.h b/src/frontends/qt4/GuiPrefs.h index 774442e0f6..72b8d22dfd 100644 --- a/src/frontends/qt4/GuiPrefs.h +++ b/src/frontends/qt4/GuiPrefs.h @@ -12,7 +12,7 @@ #ifndef GUIPREFS_H #define GUIPREFS_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlPrefs.h" #include "Color.h" #include "LyXRC.h" @@ -48,14 +48,14 @@ class Movers; namespace frontend { -class GuiPrefs; +class GuiPrefsDialog; class PrefModule : public QWidget { Q_OBJECT public: PrefModule(docstring const & t, - GuiPrefs * form = 0, QWidget * parent = 0) + GuiPrefsDialog * form = 0, QWidget * parent = 0) : QWidget(parent), title_(t), form_(form) {} @@ -66,14 +66,14 @@ public: protected: docstring title_; - GuiPrefs * form_; + GuiPrefsDialog * form_; Q_SIGNALS: void changed(); }; -class PrefPlaintext : public PrefModule, public Ui::PrefPlaintextUi +class PrefPlaintext : public PrefModule, public Ui::PrefPlaintextUi { Q_OBJECT public: @@ -84,7 +84,7 @@ public: }; -class PrefDate : public PrefModule, public Ui::PrefDateUi +class PrefDate : public PrefModule, public Ui::PrefDateUi { Q_OBJECT public: @@ -95,11 +95,11 @@ public: }; -class PrefKeyboard : public PrefModule, public Ui::PrefKeyboardUi +class PrefKeyboard : public PrefModule, public Ui::PrefKeyboardUi { Q_OBJECT public: - PrefKeyboard(GuiPrefs * form, QWidget * parent = 0); + PrefKeyboard(GuiPrefsDialog * form, QWidget * parent = 0); virtual void apply(LyXRC & rc) const; virtual void update(LyXRC const & rc); @@ -114,22 +114,22 @@ private: }; -class PrefLatex : public PrefModule, public Ui::PrefLatexUi +class PrefLatex : public PrefModule, public Ui::PrefLatexUi { Q_OBJECT public: - PrefLatex(GuiPrefs * form, QWidget * parent = 0); + PrefLatex(GuiPrefsDialog * form, QWidget * parent = 0); virtual void apply(LyXRC & rc) const; virtual void update(LyXRC const & rc); }; -class PrefScreenFonts : public PrefModule, public Ui::PrefScreenFontsUi +class PrefScreenFonts : public PrefModule, public Ui::PrefScreenFontsUi { Q_OBJECT public: - PrefScreenFonts(GuiPrefs * form, QWidget * parent = 0); + PrefScreenFonts(GuiPrefsDialog * form, QWidget * parent = 0); virtual void apply(LyXRC & rc) const; virtual void update(LyXRC const & rc); @@ -141,11 +141,11 @@ private Q_SLOTS: }; -class PrefColors : public PrefModule, public Ui::PrefColorsUi +class PrefColors : public PrefModule, public Ui::PrefColorsUi { Q_OBJECT public: - PrefColors(GuiPrefs * form, QWidget * parent = 0); + PrefColors(GuiPrefsDialog * form, QWidget * parent = 0); void apply(LyXRC & rc) const; void update(LyXRC const & rc); @@ -165,7 +165,7 @@ private: }; -class PrefDisplay : public PrefModule, public Ui::PrefDisplayUi +class PrefDisplay : public PrefModule, public Ui::PrefDisplayUi { Q_OBJECT public: @@ -176,11 +176,11 @@ public: }; -class PrefPaths : public PrefModule, public Ui::PrefPathsUi +class PrefPaths : public PrefModule, public Ui::PrefPathsUi { Q_OBJECT public: - PrefPaths(GuiPrefs * form, QWidget * parent = 0); + PrefPaths(GuiPrefsDialog * form, QWidget * parent = 0); void apply(LyXRC & rc) const; void update(LyXRC const & rc); @@ -195,11 +195,11 @@ private Q_SLOTS: }; -class PrefSpellchecker : public PrefModule, public Ui::PrefSpellcheckerUi +class PrefSpellchecker : public PrefModule, public Ui::PrefSpellcheckerUi { Q_OBJECT public: - PrefSpellchecker(GuiPrefs * form, QWidget * parent = 0); + PrefSpellchecker(GuiPrefsDialog * form, QWidget * parent = 0); void apply(LyXRC & rc) const; void update(LyXRC const & rc); @@ -209,11 +209,11 @@ private Q_SLOTS: }; -class PrefConverters : public PrefModule, public Ui::PrefConvertersUi +class PrefConverters : public PrefModule, public Ui::PrefConvertersUi { Q_OBJECT public: - PrefConverters(GuiPrefs * form, QWidget * parent = 0); + PrefConverters(GuiPrefsDialog * form, QWidget * parent = 0); void apply(LyXRC & rc) const; void update(LyXRC const & rc); @@ -233,11 +233,11 @@ private: }; -class PrefCopiers : public PrefModule, public Ui::PrefCopiersUi +class PrefCopiers : public PrefModule, public Ui::PrefCopiersUi { Q_OBJECT public: - PrefCopiers(GuiPrefs * form, QWidget * parent = 0); + PrefCopiers(GuiPrefsDialog * form, QWidget * parent = 0); void apply(LyXRC & rc) const; void update(LyXRC const & rc); @@ -257,11 +257,11 @@ private: }; -class PrefFileformats : public PrefModule, public Ui::PrefFileformatsUi +class PrefFileformats : public PrefModule, public Ui::PrefFileformatsUi { Q_OBJECT public: - PrefFileformats(GuiPrefs * form, QWidget * parent = 0); + PrefFileformats(GuiPrefsDialog * form, QWidget * parent = 0); void apply(LyXRC & rc) const; void update(LyXRC const & rc); @@ -281,7 +281,7 @@ private Q_SLOTS: }; -class PrefLanguage : public PrefModule, public Ui::PrefLanguageUi +class PrefLanguage : public PrefModule, public Ui::PrefLanguageUi { Q_OBJECT public: @@ -295,7 +295,7 @@ private: }; -class PrefPrinter : public PrefModule, public Ui::PrefPrinterUi +class PrefPrinter : public PrefModule, public Ui::PrefPrinterUi { Q_OBJECT public: @@ -306,11 +306,11 @@ public: }; -class PrefUserInterface : public PrefModule, public Ui::PrefUi +class PrefUserInterface : public PrefModule, public Ui::PrefUi { Q_OBJECT public: - PrefUserInterface(GuiPrefs * form, QWidget * parent = 0); + PrefUserInterface(GuiPrefsDialog * form, QWidget * parent = 0); void apply(LyXRC & rc) const; void update(LyXRC const & rc); @@ -323,7 +323,7 @@ public Q_SLOTS: }; -class PrefIdentity : public PrefModule, public Ui::PrefIdentityUi +class PrefIdentity : public PrefModule, public Ui::PrefIdentityUi { Q_OBJECT public: @@ -334,11 +334,11 @@ public: }; /// -class GuiPrefsDialog : public QDialog, public Ui::PrefsUi +class GuiPrefsDialog : public GuiDialog, public Ui::PrefsUi { Q_OBJECT public: - GuiPrefsDialog(GuiPrefs *); + GuiPrefsDialog(LyXView & lv); void apply(LyXRC & rc) const; void updateRc(LyXRC const & rc); @@ -346,44 +346,28 @@ public: public Q_SLOTS: void change_adaptor(); -protected: +public: + // void closeEvent(QCloseEvent * e); - -private: + /// void add(PrefModule * module); - -private: - GuiPrefs * form_; - std::vector modules_; -}; - - -class GuiPrefs : public GuiView -{ -public: - GuiPrefs(GuiDialog &); - + /// Converters & converters(); + /// Formats & formats(); + /// Movers & movers(); /// parent controller - ControlPrefs & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlPrefs const & controller() const - { return static_cast(this->getController()); } -private: + ControlPrefs & controller() const; /// Apply changes - virtual void applyView(); - + void applyView(); /// update (do we need this?) - virtual void update_contents(); - - /// build the dialog - virtual void build_dialog(); + void update_contents(); + std::vector modules_; }; + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiPrint.cpp b/src/frontends/qt4/GuiPrint.cpp index ee23476be9..1b5dd919d2 100644 --- a/src/frontends/qt4/GuiPrint.cpp +++ b/src/frontends/qt4/GuiPrint.cpp @@ -13,6 +13,7 @@ #include "GuiPrint.h" +#include "ControlPrint.h" #include "qt_helpers.h" #include "PrinterParams.h" @@ -24,16 +25,19 @@ #include #include + namespace lyx { namespace frontend { -GuiPrintDialog::GuiPrintDialog(GuiPrint * f) - : form_(f) +GuiPrintDialog::GuiPrintDialog(LyXView & lv) + : GuiDialog(lv, "print") { setupUi(this); + setController(new ControlPrint(*this)); + setViewTitle(_("Print Document")); - connect(printPB, SIGNAL(clicked()), form_, SLOT(slotOK())); - connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose())); + connect(printPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(copiesSB, SIGNAL(valueChanged(int)), this, SLOT(copiesChanged(int))); connect(printerED, SIGNAL(textChanged(const QString&)), @@ -56,21 +60,31 @@ GuiPrintDialog::GuiPrintDialog(GuiPrint * f) connect(printerRB, SIGNAL(clicked()), this, SLOT(change_adaptor())); connect(rangeRB, SIGNAL(toggled(bool)), fromED, SLOT(setEnabled(bool))); connect(rangeRB, SIGNAL(toggled(bool)), toED, SLOT(setEnabled(bool))); + + bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy); + bc().setOK(printPB); + bc().setCancel(closePB); +} + + +ControlPrint & GuiPrintDialog::controller() const +{ + return static_cast(Dialog::controller()); } void GuiPrintDialog::change_adaptor() { - form_->changed(); + changed(); } void GuiPrintDialog::browseClicked() { - QString file = toqstr(form_->controller().browse(docstring())); + QString file = toqstr(controller().browse(docstring())); if (!file.isNull()) { fileED->setText(file); - form_->changed(); + changed(); } } @@ -79,101 +93,81 @@ void GuiPrintDialog::fileChanged() { if (!fileED->text().isEmpty()) fileRB->setChecked(true); - form_->changed(); + changed(); } void GuiPrintDialog::copiesChanged(int i) { collateCB->setEnabled(i != 1); - form_->changed(); + changed(); } void GuiPrintDialog::printerChanged() { printerRB->setChecked(true); - form_->changed(); + changed(); } void GuiPrintDialog::pagerangeChanged() { - form_->changed(); -} - - -GuiPrint::GuiPrint(GuiDialog & parent) - : GuiView(parent, _("Print Document")) -{ + changed(); } -void GuiPrint::build_dialog() -{ - dialog_.reset(new GuiPrintDialog(this)); - - bc().setOK(dialog_->printPB); - bc().setCancel(dialog_->closePB); -} - - -void GuiPrint::update_contents() +void GuiPrintDialog::update_contents() { PrinterParams & pp = controller().params(); // only reset params if a different buffer - if (!pp.file_name.empty() && pp.file_name == fromqstr(dialog_->fileED->text())) + if (!pp.file_name.empty() && pp.file_name == fromqstr(fileED->text())) return; - dialog_->printerED->setText(toqstr(pp.printer_name)); - dialog_->fileED->setText(toqstr(pp.file_name)); + printerED->setText(toqstr(pp.printer_name)); + fileED->setText(toqstr(pp.file_name)); - dialog_->printerRB->setChecked(true); + printerRB->setChecked(true); if (pp.target == PrinterParams::FILE) - dialog_->fileRB->setChecked(true); + fileRB->setChecked(true); - dialog_->reverseCB->setChecked(pp.reverse_order); + reverseCB->setChecked(pp.reverse_order); - dialog_->copiesSB->setValue(pp.count_copies); + copiesSB->setValue(pp.count_copies); - dialog_->oddCB->setChecked(pp.odd_pages); - dialog_->evenCB->setChecked(pp.even_pages); + oddCB->setChecked(pp.odd_pages); + evenCB->setChecked(pp.even_pages); - dialog_->collateCB->setChecked(pp.sorted_copies); + collateCB->setChecked(pp.sorted_copies); if (pp.all_pages) { - dialog_->allRB->setChecked(true); - return; + allRB->setChecked(true); + } else { + rangeRB->setChecked(true); + fromED->setText(QString::number(pp.from_page)); + toED->setText(QString::number(pp.to_page)); } - - dialog_->rangeRB->setChecked(true); - - QString s; - s.setNum(pp.from_page); - dialog_->fromED->setText(s); - s.setNum(pp.to_page); - dialog_->toED->setText(s); } -void GuiPrint::applyView() +void GuiPrintDialog::applyView() { PrinterParams::Target t = PrinterParams::PRINTER; - if (dialog_->fileRB->isChecked()) + if (fileRB->isChecked()) t = PrinterParams::FILE; PrinterParams const pp(t, - fromqstr(dialog_->printerED->text()), - support::os::internal_path(fromqstr(dialog_->fileED->text())), - dialog_->allRB->isChecked(), - dialog_->fromED->text().toUInt(), - dialog_->toED->text().toUInt(), - dialog_->oddCB->isChecked(), - dialog_->evenCB->isChecked(), - dialog_->copiesSB->text().toUInt(), - dialog_->collateCB->isChecked(), - dialog_->reverseCB->isChecked()); + fromqstr(printerED->text()), + support::os::internal_path(fromqstr(fileED->text())), + allRB->isChecked(), + fromED->text().toUInt(), + toED->text().toUInt(), + oddCB->isChecked(), + evenCB->isChecked(), + copiesSB->text().toUInt(), + collateCB->isChecked(), + reverseCB->isChecked()); controller().params() = pp; } diff --git a/src/frontends/qt4/GuiPrint.h b/src/frontends/qt4/GuiPrint.h index e66ec29b1a..52abe81960 100644 --- a/src/frontends/qt4/GuiPrint.h +++ b/src/frontends/qt4/GuiPrint.h @@ -13,53 +13,35 @@ #ifndef GUIPRINT_H #define GUIPRINT_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlPrint.h" #include "ui_PrintUi.h" -#include - namespace lyx { namespace frontend { -class GuiPrint; - -class GuiPrintDialog : public QDialog, public Ui::PrintUi { +class GuiPrintDialog : public GuiDialog, public Ui::PrintUi +{ Q_OBJECT -public: - GuiPrintDialog(GuiPrint * f); -protected Q_SLOTS: - virtual void change_adaptor(); - virtual void browseClicked(); - virtual void fileChanged(); - virtual void copiesChanged(int); - virtual void printerChanged(); - virtual void pagerangeChanged(); -private: - GuiPrint * form_; -}; - -class GuiPrint : public GuiView -{ public: - /// - friend class GuiPrintDialog; - /// - GuiPrint(GuiDialog &); + GuiPrintDialog(LyXView & lv); + +private Q_SLOTS: + void change_adaptor(); + void browseClicked(); + void fileChanged(); + void copiesChanged(int); + void printerChanged(); + void pagerangeChanged(); /// parent controller - ControlPrint & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlPrint const & controller() const - { return static_cast(this->getController()); } + ControlPrint & controller() const; + private: /// Apply changes - virtual void applyView(); + void applyView(); /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); + void update_contents(); }; } // namespace frontend diff --git a/src/frontends/qt4/GuiRef.cpp b/src/frontends/qt4/GuiRef.cpp index 1367fa997b..53db6e2df6 100644 --- a/src/frontends/qt4/GuiRef.cpp +++ b/src/frontends/qt4/GuiRef.cpp @@ -12,6 +12,8 @@ #include #include "GuiRef.h" + +#include "ControlRef.h" #include "qt_helpers.h" #include "insets/InsetRef.h" @@ -32,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())); @@ -71,8 +72,28 @@ 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; +} + + +ControlRef & GuiRefDialog::controller() const +{ + return static_cast(Dialog::controller()); } + void GuiRefDialog::showView() { QDialog::show(); @@ -81,18 +102,18 @@ void GuiRefDialog::showView() void GuiRefDialog::changed_adaptor() { - form_->changed(); + changed(); } void GuiRefDialog::gotoClicked() { - form_->gotoRef(); + gotoRef(); } void GuiRefDialog::selectionChanged() { - if (form_->readOnly()) + if (readOnly()) return; QList selections = refsLW->selectedItems(); @@ -106,7 +127,7 @@ void GuiRefDialog::selectionChanged() void GuiRefDialog::refHighlighted(QListWidgetItem * sel) { - if (form_->readOnly()) + if (readOnly()) return; /* int const cur_item = refsLW->currentRow(); @@ -117,19 +138,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 (readOnly()) return; /* int const cur_item = refsLW->currentRow(); @@ -140,125 +161,94 @@ void GuiRefDialog::refSelected(QListWidgetItem * sel) if (cur_item_selected) referenceED->setText(sel->text()); // 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(); + slotWMHide(); reset_dialog(); e->accept(); } -///////////////////////////////////////////////////////////////////// -// -// GuiRef -// -///////////////////////////////////////////////////////////////////// - - -GuiRef::GuiRef(GuiDialog & parent) - : GuiView(parent, _("Cross-reference")), - sort_(false), at_ref_(false) -{ -} - - -void GuiRef::build_dialog() -{ - dialog_.reset(new GuiRefDialog(this)); - - bc().setOK(dialog_->okPB); - bc().setApply(dialog_->applyPB); - bc().setCancel(dialog_->closePB); - bc().addReadOnly(dialog_->refsLW); - bc().addReadOnly(dialog_->sortCB); - bc().addReadOnly(dialog_->nameED); - bc().addReadOnly(dialog_->referenceED); - bc().addReadOnly(dialog_->typeCO); - bc().addReadOnly(dialog_->bufferCO); - - restored_buffer_ = -1; -} - - -void GuiRef::update_contents() +void GuiRefDialog::update_contents() { 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() && !readOnly()); // 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() && !readOnly()); 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 const buffers = controller().getBufferList(); for (vector::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().setValid(false); } -void GuiRef::applyView() +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 && @@ -266,32 +256,32 @@ bool GuiRef::nameAllowed() } -bool GuiRef::typeAllowed() +bool GuiRefDialog::typeAllowed() { Kernel::DocType const doc_type = kernel().docType(); return doc_type != Kernel::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 @@ -306,29 +296,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::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 @@ -336,13 +326,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; } } @@ -350,29 +340,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 diff --git a/src/frontends/qt4/GuiRef.h b/src/frontends/qt4/GuiRef.h index 9fc20136b5..f918cfe711 100644 --- a/src/frontends/qt4/GuiRef.h +++ b/src/frontends/qt4/GuiRef.h @@ -12,12 +12,10 @@ #ifndef GUIREF_H #define GUIREF_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlRef.h" #include "ui_RefUi.h" -#include - #include class QListWidgetItem; @@ -25,16 +23,14 @@ class QListWidgetItem; namespace lyx { namespace frontend { -class GuiRef; - -class GuiRefDialog : public QDialog, public Ui::RefUi { +class GuiRefDialog : public GuiDialog, public Ui::RefUi +{ Q_OBJECT -public: - GuiRefDialog(GuiRef * form); - virtual void showView(); +public: + GuiRefDialog(LyXView & lv); -public Q_SLOTS: +private Q_SLOTS: void changed_adaptor(); void gotoClicked(); void refHighlighted(QListWidgetItem *); @@ -42,39 +38,21 @@ public Q_SLOTS: void refSelected(QListWidgetItem *); void sortToggled(bool); void updateClicked(); - -protected Q_SLOTS: void reset_dialog(); -protected: - void closeEvent(QCloseEvent * e); -private: - GuiRef * form_; -}; - - -class GuiRef : public GuiView -{ -public: - friend class GuiRefDialog; - - GuiRef(GuiDialog &); - - /// parent controller - ControlRef & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlRef const & controller() const - { return static_cast(this->getController()); } -protected: - virtual bool isValid(); private: + /// + void showView(); + /// + void closeEvent(QCloseEvent * e); + /// parent controller + ControlRef & controller() const; + /// + bool isValid(); /// apply changes - virtual void applyView(); - /// build dialog - virtual void build_dialog(); + void applyView(); /// update dialog - virtual void update_contents(); + void update_contents(); /// is name allowed for this ? bool nameAllowed(); diff --git a/src/frontends/qt4/GuiSearch.cpp b/src/frontends/qt4/GuiSearch.cpp index 1e59cd793d..efde8aaa79 100644 --- a/src/frontends/qt4/GuiSearch.cpp +++ b/src/frontends/qt4/GuiSearch.cpp @@ -12,6 +12,8 @@ #include #include "GuiSearch.h" + +#include "ControlSearch.h" #include "qt_helpers.h" #include @@ -19,17 +21,10 @@ using std::string; + namespace lyx { namespace frontend { - -///////////////////////////////////////////////////////////////////// -// -// GuiSearchDialog -// -///////////////////////////////////////////////////////////////////// - - static void uniqueInsert(QComboBox * box, QString const & text) { for (int i = 0; i < box->count(); ++i) { @@ -41,12 +36,14 @@ static void uniqueInsert(QComboBox * box, QString const & text) } -GuiSearchDialog::GuiSearchDialog(GuiSearch * form) - : form_(form) +GuiSearchDialog::GuiSearchDialog(LyXView & lv) + : GuiDialog(lv, "findreplace") { setupUi(this); + setController(new ControlSearch(*this)); + setViewTitle(_("Find and Replace")); - connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(findPB, SIGNAL(clicked()), this, SLOT(findClicked())); connect(replacePB, SIGNAL(clicked()), this, SLOT(replaceClicked())); connect(replaceallPB, SIGNAL(clicked()), this, SLOT(replaceallClicked())); @@ -54,6 +51,21 @@ GuiSearchDialog::GuiSearchDialog(GuiSearch * form) this, SLOT(findChanged())); setFocusProxy(findCO); + + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + bc().setCancel(closePB); + bc().addReadOnly(replaceCO); + bc().addReadOnly(replacePB); + bc().addReadOnly(replaceallPB); + + replacePB->setEnabled(false); + replaceallPB->setEnabled(false); +} + + +ControlSearch & GuiSearchDialog::controller() const +{ + return static_cast(Dialog::controller()); } @@ -66,7 +78,7 @@ void GuiSearchDialog::showView() void GuiSearchDialog::closeEvent(QCloseEvent * e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } @@ -79,18 +91,16 @@ void GuiSearchDialog::findChanged() replaceallPB->setEnabled(false); } else { findPB->setEnabled(true); - replacePB->setEnabled(!form_->readOnly()); - replaceallPB->setEnabled(!form_->readOnly()); + replacePB->setEnabled(!readOnly()); + replaceallPB->setEnabled(!readOnly()); } } void GuiSearchDialog::findClicked() { - docstring const find = qstring_to_ucs4(findCO->currentText()); - form_->find(find, - caseCB->isChecked(), - wordsCB->isChecked(), + docstring const needle = qstring_to_ucs4(findCO->currentText()); + find(needle, caseCB->isChecked(), wordsCB->isChecked(), backwardsCB->isChecked()); uniqueInsert(findCO, findCO->currentText()); findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length()); @@ -99,11 +109,9 @@ void GuiSearchDialog::findClicked() void GuiSearchDialog::replaceClicked() { - docstring const find = qstring_to_ucs4(findCO->currentText()); - docstring const replace = qstring_to_ucs4(replaceCO->currentText()); - form_->replace(find, replace, - caseCB->isChecked(), - wordsCB->isChecked(), + docstring const needle = qstring_to_ucs4(findCO->currentText()); + docstring const repl = qstring_to_ucs4(replaceCO->currentText()); + replace(needle, repl, caseCB->isChecked(), wordsCB->isChecked(), backwardsCB->isChecked(), false); uniqueInsert(findCO, findCO->currentText()); uniqueInsert(replaceCO, replaceCO->currentText()); @@ -112,51 +120,23 @@ void GuiSearchDialog::replaceClicked() void GuiSearchDialog::replaceallClicked() { - form_->replace(qstring_to_ucs4(findCO->currentText()), + replace(qstring_to_ucs4(findCO->currentText()), qstring_to_ucs4(replaceCO->currentText()), - caseCB->isChecked(), - wordsCB->isChecked(), - false, true); + caseCB->isChecked(), wordsCB->isChecked(), false, true); uniqueInsert(findCO, findCO->currentText()); uniqueInsert(replaceCO, replaceCO->currentText()); } -///////////////////////////////////////////////////////////////////// -// -// GuiSearch -// -///////////////////////////////////////////////////////////////////// - - -GuiSearch::GuiSearch(GuiDialog & parent) - : GuiView(parent, _("Find and Replace")) -{ -} - - -void GuiSearch::build_dialog() -{ - dialog_.reset(new GuiSearchDialog(this)); - - bc().setCancel(dialog_->closePB); - bc().addReadOnly(dialog_->replaceCO); - bc().addReadOnly(dialog_->replacePB); - bc().addReadOnly(dialog_->replaceallPB); - - dialog_->replacePB->setEnabled(false); - dialog_->replaceallPB->setEnabled(false); -} - - -void GuiSearch::find(docstring const & str, bool casesens, - bool words, bool backwards) +void GuiSearchDialog::find(docstring const & str, bool casesens, + bool words, bool backwards) { controller().find(str, casesens, words, !backwards); } -void GuiSearch::replace(docstring const & findstr, docstring const & replacestr, +void GuiSearchDialog::replace(docstring const & findstr, + docstring const & replacestr, bool casesens, bool words, bool backwards, bool all) { controller().replace(findstr, replacestr, casesens, words, diff --git a/src/frontends/qt4/GuiSearch.h b/src/frontends/qt4/GuiSearch.h index 25e5663b8c..3e5c8d147f 100644 --- a/src/frontends/qt4/GuiSearch.h +++ b/src/frontends/qt4/GuiSearch.h @@ -12,65 +12,40 @@ #ifndef GUISEARCH_H #define GUISEARCH_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlSearch.h" #include "ui_SearchUi.h" -#include - -#include - namespace lyx { namespace frontend { -class GuiSearch; +class ControlSearch; -class GuiSearchDialog : public QDialog, public Ui::SearchUi { +class GuiSearchDialog : public GuiDialog, public Ui::SearchUi +{ Q_OBJECT + public: - GuiSearchDialog(GuiSearch * form); + GuiSearchDialog(LyXView & lv); - virtual void showView(); -protected Q_SLOTS: +private Q_SLOTS: void findChanged(); void findClicked(); void replaceClicked(); void replaceallClicked(); -protected: - virtual void closeEvent(QCloseEvent * e); private: - GuiSearch * form_; -}; - - -class GuiSearch : public GuiView -{ -public: - /// - friend class GuiSearchDialog; - /// - GuiSearch(GuiDialog &); + void showView(); + void closeEvent(QCloseEvent * e); /// parent controller - ControlSearch & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlSearch const & controller() const - { return static_cast(this->getController()); } -private: - /// Apply changes - virtual void applyView() {} - /// update - virtual void update_contents() {} - /// build the dialog - virtual void build_dialog(); - + ControlSearch & controller() const; + /// void find(docstring const & str, bool casesens, - bool words, bool backwards); - + bool words, bool backwards); + /// void replace(docstring const & findstr, - docstring const & replacestr, - bool casesens, bool words, bool backwards, bool all); + docstring const & replacestr, + bool casesens, bool words, bool backwards, bool all); }; } // namespace frontend diff --git a/src/frontends/qt4/GuiSelectionManager.cpp b/src/frontends/qt4/GuiSelectionManager.cpp index 72ba407c3e..130d3f85c4 100644 --- a/src/frontends/qt4/GuiSelectionManager.cpp +++ b/src/frontends/qt4/GuiSelectionManager.cpp @@ -20,181 +20,181 @@ namespace lyx { namespace frontend { GuiSelectionManager::GuiSelectionManager( - QListView * avail, - QListView * sel, - QPushButton * add, - QPushButton * del, - QPushButton * up, - QPushButton * down, - QStringListModel * amod, - QStringListModel * smod) + QListView * avail, + QListView * sel, + QPushButton * add, + QPushButton * del, + QPushButton * up, + QPushButton * down, + QStringListModel * amod, + QStringListModel * smod) { - availableLV = avail; - selectedLV = sel; - addPB = add; - deletePB = del; - upPB = up; - downPB = down; - availableModel = amod; - selectedModel = smod; - - selectedLV->setModel(smod); - availableLV->setModel(amod); - - connect(availableLV->selectionModel(), - SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), - this, SLOT(availableChanged(const QModelIndex &, const QModelIndex &))); - connect(selectedLV->selectionModel(), - SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), - this, SLOT(selectedChanged(const QModelIndex &, const QModelIndex &))); - connect(addPB, SIGNAL(clicked()), - this, SLOT(addPB_clicked())); - connect(deletePB, SIGNAL(clicked()), - this, SLOT(deletePB_clicked())); - connect(upPB, SIGNAL(clicked()), - this, SLOT(upPB_clicked())); - connect(downPB, SIGNAL(clicked()), - this, SLOT(downPB_clicked())); - connect(availableLV, SIGNAL(clicked(const QModelIndex &)), - this, SLOT(availableLV_clicked(const QModelIndex &))); - connect(availableLV, SIGNAL(doubleClicked(const QModelIndex &)), - this, SLOT(availableLV_doubleClicked(const QModelIndex &))); - connect(selectedLV, SIGNAL(clicked(const QModelIndex &)), - this, SLOT(selectedLV_clicked(const QModelIndex &))); - - availableLV->installEventFilter(this); - selectedLV->installEventFilter(this); +availableLV = avail; +selectedLV = sel; +addPB = add; +deletePB = del; +upPB = up; +downPB = down; +availableModel = amod; +selectedModel = smod; + +selectedLV->setModel(smod); +availableLV->setModel(amod); + +connect(availableLV->selectionModel(), + SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), + this, SLOT(availableChanged(const QModelIndex &, const QModelIndex &))); +connect(selectedLV->selectionModel(), + SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), + this, SLOT(selectedChanged(const QModelIndex &, const QModelIndex &))); +connect(addPB, SIGNAL(clicked()), + this, SLOT(addPB_clicked())); +connect(deletePB, SIGNAL(clicked()), + this, SLOT(deletePB_clicked())); +connect(upPB, SIGNAL(clicked()), + this, SLOT(upPB_clicked())); +connect(downPB, SIGNAL(clicked()), + this, SLOT(downPB_clicked())); +connect(availableLV, SIGNAL(clicked(const QModelIndex &)), + this, SLOT(availableLV_clicked(const QModelIndex &))); +connect(availableLV, SIGNAL(doubleClicked(const QModelIndex &)), + this, SLOT(availableLV_doubleClicked(const QModelIndex &))); +connect(selectedLV, SIGNAL(clicked(const QModelIndex &)), + this, SLOT(selectedLV_clicked(const QModelIndex &))); + +availableLV->installEventFilter(this); +selectedLV->installEventFilter(this); } void GuiSelectionManager::updateView() { - int const arows = availableLV->model()->rowCount(); - QModelIndexList const availSels = - availableLV->selectionModel()->selectedIndexes(); - addPB->setEnabled(arows > 0 && - !availSels.isEmpty() && - !isSelected(availSels.first())); - - int const srows = selectedLV->model()->rowCount(); - QModelIndexList const selSels = - selectedLV->selectionModel()->selectedIndexes(); - int const sel_nr = selSels.empty() ? -1 : selSels.first().row(); - deletePB->setEnabled(sel_nr >= 0); - upPB->setEnabled(sel_nr > 0); - downPB->setEnabled(sel_nr >= 0 && sel_nr < srows - 1); +int const arows = availableLV->model()->rowCount(); +QModelIndexList const availSels = + availableLV->selectionModel()->selectedIndexes(); +addPB->setEnabled(arows > 0 && + !availSels.isEmpty() && + !isSelected(availSels.first())); + +int const srows = selectedLV->model()->rowCount(); +QModelIndexList const selSels = + selectedLV->selectionModel()->selectedIndexes(); +int const sel_nr = selSels.empty() ? -1 : selSels.first().row(); +deletePB->setEnabled(sel_nr >= 0); +upPB->setEnabled(sel_nr > 0); +downPB->setEnabled(sel_nr >= 0 && sel_nr < srows - 1); } bool GuiSelectionManager::isSelected(const QModelIndex & idx) { - QString const str = idx.data().toString(); - return selectedModel->stringList().contains(str); +QString const str = idx.data().toString(); +return selectedModel->stringList().contains(str); } void GuiSelectionManager::availableChanged(const QModelIndex & idx, const QModelIndex &) { - if (!idx.isValid()) - return; +if (!idx.isValid()) + return; - selectedHasFocus_ = false; - updateHook(); +selectedHasFocus_ = false; +updateHook(); } void GuiSelectionManager::selectedChanged(const QModelIndex & idx, const QModelIndex &) { - if (!idx.isValid()) - return; +if (!idx.isValid()) + return; - selectedHasFocus_ = true; - updateHook(); +selectedHasFocus_ = true; +updateHook(); } static QModelIndex getSelectedIndex(QListView * lv) { - QModelIndex retval = QModelIndex(); - QModelIndexList selIdx = - lv->selectionModel()->selectedIndexes(); - if (!selIdx.empty()) - retval = selIdx.first(); - return retval; +QModelIndex retval = QModelIndex(); +QModelIndexList selIdx = + lv->selectionModel()->selectedIndexes(); +if (!selIdx.empty()) + retval = selIdx.first(); +return retval; } void GuiSelectionManager::addPB_clicked() { - QModelIndex const idxToAdd = getSelectedIndex(availableLV); - if (!idxToAdd.isValid()) - return; - QModelIndex idx = selectedLV->currentIndex(); - - QStringList keys = selectedModel->stringList(); - keys.append(idxToAdd.data().toString()); - selectedModel->setStringList(keys); - selectionChanged(); //signal - - if (idx.isValid()) - selectedLV->setCurrentIndex(idx); - updateHook(); +QModelIndex const idxToAdd = getSelectedIndex(availableLV); +if (!idxToAdd.isValid()) + return; +QModelIndex idx = selectedLV->currentIndex(); + +QStringList keys = selectedModel->stringList(); +keys.append(idxToAdd.data().toString()); +selectedModel->setStringList(keys); +selectionChanged(); //signal + +if (idx.isValid()) + selectedLV->setCurrentIndex(idx); +updateHook(); } void GuiSelectionManager::deletePB_clicked() { - QModelIndex idx = getSelectedIndex(selectedLV); - if (!idx.isValid()) - return; - - QStringList keys = selectedModel->stringList(); - keys.removeAt(idx.row()); - selectedModel->setStringList(keys); - selectionChanged(); //signal - - int nrows = selectedLV->model()->rowCount(); - if (idx.row() == nrows) //was last item on list - idx = idx.sibling(idx.row() - 1, idx.column()); - - if (nrows > 1) - selectedLV->setCurrentIndex(idx); - else if (nrows == 1) - selectedLV->setCurrentIndex(selectedLV->model()->index(0,0)); - selectedHasFocus_ = (nrows > 0); - updateHook(); +QModelIndex idx = getSelectedIndex(selectedLV); +if (!idx.isValid()) + return; + +QStringList keys = selectedModel->stringList(); +keys.removeAt(idx.row()); +selectedModel->setStringList(keys); +selectionChanged(); //signal + +int nrows = selectedLV->model()->rowCount(); +if (idx.row() == nrows) //was last item on list + idx = idx.sibling(idx.row() - 1, idx.column()); + +if (nrows > 1) + selectedLV->setCurrentIndex(idx); +else if (nrows == 1) + selectedLV->setCurrentIndex(selectedLV->model()->index(0,0)); +selectedHasFocus_ = (nrows > 0); +updateHook(); } void GuiSelectionManager::upPB_clicked() { - QModelIndex idx = selectedLV->currentIndex(); - - int const pos = idx.row(); - QStringList keys = selectedModel->stringList(); - keys.swap(pos, pos - 1); - selectedModel->setStringList(keys); - selectionChanged(); //signal - - selectedLV->setCurrentIndex(idx.sibling(idx.row() - 1, idx.column())); - selectedHasFocus_ = true; - updateHook(); +QModelIndex idx = selectedLV->currentIndex(); + +int const pos = idx.row(); +QStringList keys = selectedModel->stringList(); +keys.swap(pos, pos - 1); +selectedModel->setStringList(keys); +selectionChanged(); //signal + +selectedLV->setCurrentIndex(idx.sibling(idx.row() - 1, idx.column())); +selectedHasFocus_ = true; +updateHook(); } void GuiSelectionManager::downPB_clicked() { - QModelIndex idx = selectedLV->currentIndex(); - - int const pos = idx.row(); - QStringList keys = selectedModel->stringList(); - keys.swap(pos, pos + 1); - selectedModel->setStringList(keys); - selectionChanged(); //signal - - selectedLV->setCurrentIndex(idx.sibling(idx.row() + 1, idx.column())); - selectedHasFocus_ = true; - updateHook(); +QModelIndex idx = selectedLV->currentIndex(); + +int const pos = idx.row(); +QStringList keys = selectedModel->stringList(); +keys.swap(pos, pos + 1); +selectedModel->setStringList(keys); +selectionChanged(); //signal + +selectedLV->setCurrentIndex(idx.sibling(idx.row() + 1, idx.column())); +selectedHasFocus_ = true; +updateHook(); } @@ -204,40 +204,40 @@ void GuiSelectionManager::downPB_clicked() //which means subclassing QListView. (rgh) void GuiSelectionManager::availableLV_clicked(const QModelIndex &) { - selectedHasFocus_ = false; - updateHook(); +selectedHasFocus_ = false; +updateHook(); } void GuiSelectionManager::availableLV_doubleClicked(const QModelIndex & idx) { - if (isSelected(idx)) - return; +if (isSelected(idx)) + return; - if (idx.isValid()) - selectedHasFocus_ = false; - addPB_clicked(); - //updateHook() will be emitted there +if (idx.isValid()) + selectedHasFocus_ = false; +addPB_clicked(); +//updateHook() will be emitted there } void GuiSelectionManager::selectedLV_clicked(const QModelIndex &) { - selectedHasFocus_ = true; - updateHook(); +selectedHasFocus_ = true; +updateHook(); } bool GuiSelectionManager::eventFilter(QObject * obj, QEvent * event) { - if (obj == availableLV) { - if (event->type() != QEvent::KeyPress) - return QObject::eventFilter(obj, event); - QKeyEvent * keyEvent = static_cast(event); - int const keyPressed = keyEvent->key(); - Qt::KeyboardModifiers const keyModifiers = keyEvent->modifiers(); - //Enter key without modifier will add current item. - //Ctrl-Enter will add it and close the dialog. +if (obj == availableLV) { + if (event->type() != QEvent::KeyPress) + return QObject::eventFilter(obj, event); + QKeyEvent * keyEvent = static_cast(event); + int const keyPressed = keyEvent->key(); + Qt::KeyboardModifiers const keyModifiers = keyEvent->modifiers(); + //Enter key without modifier will add current item. + //Ctrl-Enter will add it and close the dialog. //This is designed to work both with the main enter key //and the one on the numeric keypad. if ((keyPressed == Qt::Key_Enter || keyPressed == Qt::Key_Return) && @@ -283,7 +283,7 @@ bool GuiSelectionManager::eventFilter(QObject * obj, QEvent * event) return QObject::eventFilter(obj, event); } -}//namespace frontend -}//namespace lyx +} // namespace frontend +} // namespace lyx #include "GuiSelectionManager_moc.cpp" diff --git a/src/frontends/qt4/GuiSelectionManager.h b/src/frontends/qt4/GuiSelectionManager.h index f97dba29bb..a9d1f72bf8 100644 --- a/src/frontends/qt4/GuiSelectionManager.h +++ b/src/frontends/qt4/GuiSelectionManager.h @@ -9,10 +9,11 @@ * Full author contact details are available in file CREDITS. */ -#ifndef QSELECTIONMANAGER_H -#define QSELECTIONMANAGER_H +#ifndef GUISELECTIONMANAGER_H +#define GUISELECTIONMANAGER_H #include "Dialog.h" + #include #include #include @@ -20,7 +21,6 @@ #include #include - namespace lyx { namespace frontend { @@ -32,90 +32,91 @@ namespace frontend { * of them---should be created independently, and then passed to the * constructor. */ -class GuiSelectionManager : public QObject { - Q_OBJECT +class GuiSelectionManager : public QObject +{ +Q_OBJECT + +public: + /// + GuiSelectionManager( + QListView * availableLV, + QListView * selectedLV, + QPushButton * addPB, + QPushButton * delPB, + QPushButton * upPB, + QPushButton * downPB, + QStringListModel * availableModel, + QStringListModel * selectedModel); + /// Sets the state of the various push buttons, depending upon the + /// state of the widgets. (E.g., "delete" is enabled only if the + /// selection is non-empty.) + virtual void updateView(); + + /// Not strictly a matter of focus, which may be elsewhere, but + /// whether selectedLV is `more focused' than availableLV. Intended + /// to be used, for example, in displaying information about a + /// highlighted item: should it be the highlighted available item + /// or the highlighted selected item that is displayed? + bool selectedFocused() { return selectedHasFocus_; }; - public: - /// - GuiSelectionManager( - QListView * availableLV, - QListView * selectedLV, - QPushButton * addPB, - QPushButton * delPB, - QPushButton * upPB, - QPushButton * downPB, - QStringListModel * availableModel, - QStringListModel * selectedModel); - /// Sets the state of the various push buttons, depending upon the - /// state of the widgets. (E.g., "delete" is enabled only if the - /// selection is non-empty.) - virtual void updateView(); - - /// Not strictly a matter of focus, which may be elsewhere, but - /// whether selectedLV is `more focused' than availableLV. Intended - /// to be used, for example, in displaying information about a - /// highlighted item: should it be the highlighted available item - /// or the highlighted selected item that is displayed? - bool selectedFocused() { return selectedHasFocus_; }; +Q_SIGNALS: + ///Emitted when the list of selected items has changed. + void selectionChanged(); + ///Emitted when something has changed that might lead the containing + ///dialog to want to update---the focused subwidget or selected item. + ///(Specifically, it is emitted by *_PB_clicked() and *_LV_clicked.) + ///NOTE: No automatic update of the button state is done here. If you + ///just want to do that, connect updateHook() to updateView(). Much of the + ///time, though, you will want to do a bit more processing first, so + ///you can connect to some other function that itself calls updateView(). + void updateHook(); + ///Emitted on Ctrl-Enter in the availableLV. Intended to be connected + ///to an "OK" event in the parent dialog. + void okHook(); - Q_SIGNALS: - ///Emitted when the list of selected items has changed. - void selectionChanged(); - ///Emitted when something has changed that might lead the containing - ///dialog to want to update---the focused subwidget or selected item. - ///(Specifically, it is emitted by *_PB_clicked() and *_LV_clicked.) - ///NOTE: No automatic update of the button state is done here. If you - ///just want to do that, connect updateHook() to updateView(). Much of the - ///time, though, you will want to do a bit more processing first, so - ///you can connect to some other function that itself calls updateView(). - void updateHook(); - ///Emitted on Ctrl-Enter in the availableLV. Intended to be connected - ///to an "OK" event in the parent dialog. - void okHook(); - - protected: - ///Given a QModelIndex from availableLV, determines whether it has - ///been selected (i.e., is also in selectedLV). - bool isSelected(const QModelIndex & idx); +protected: + ///Given a QModelIndex from availableLV, determines whether it has + ///been selected (i.e., is also in selectedLV). + bool isSelected(const QModelIndex & idx); - protected Q_SLOTS: - /// - void availableChanged(const QModelIndex & idx, const QModelIndex &); - /// - void selectedChanged(const QModelIndex & idx, const QModelIndex &); - /// - void addPB_clicked(); - /// - void deletePB_clicked(); - /// - void upPB_clicked(); - /// - void downPB_clicked(); - /// - void availableLV_clicked(const QModelIndex &); - /// - void availableLV_doubleClicked(const QModelIndex &); - /// - void selectedLV_clicked(const QModelIndex &); - /// - bool eventFilter(QObject *, QEvent *); +protected Q_SLOTS: + /// + void availableChanged(const QModelIndex & idx, const QModelIndex &); + /// + void selectedChanged(const QModelIndex & idx, const QModelIndex &); + /// + void addPB_clicked(); + /// + void deletePB_clicked(); + /// + void upPB_clicked(); + /// + void downPB_clicked(); + /// + void availableLV_clicked(const QModelIndex &); + /// + void availableLV_doubleClicked(const QModelIndex &); + /// + void selectedLV_clicked(const QModelIndex &); + /// + bool eventFilter(QObject *, QEvent *); - private: - QListView * availableLV; - QListView * selectedLV; - QPushButton * addPB; - QPushButton * deletePB; - QPushButton * upPB; - QPushButton * downPB; - QStringListModel * availableModel; - QStringListModel * selectedModel; - Dialog::View * dialog; - - bool selectedHasFocus_; +private: + QListView * availableLV; + QListView * selectedLV; + QPushButton * addPB; + QPushButton * deletePB; + QPushButton * upPB; + QPushButton * downPB; + QStringListModel * availableModel; + QStringListModel * selectedModel; + //Dialog::View * dialog; + + bool selectedHasFocus_; }; } // namespace frontend } // namespace lyx -#endif +#endif // GUISELECTIONMANAGER diff --git a/src/frontends/qt4/GuiSendto.cpp b/src/frontends/qt4/GuiSendto.cpp index c466505710..a6b8aeb11d 100644 --- a/src/frontends/qt4/GuiSendto.cpp +++ b/src/frontends/qt4/GuiSendto.cpp @@ -11,6 +11,8 @@ #include #include "GuiSendto.h" + +#include "ControlSendto.h" #include "qt_helpers.h" #include "Format.h" @@ -26,73 +28,53 @@ using std::string; namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiSendtoDialog -// -///////////////////////////////////////////////////////////////////// - -GuiSendtoDialog::GuiSendtoDialog(GuiSendto * form) - : form_(form) +GuiSendtoDialog::GuiSendtoDialog(LyXView & lv) + : GuiDialog(lv, "sendto") { setupUi(this); - - connect(okPB, SIGNAL(clicked()), - form, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), - form, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), - form, SLOT(slotClose())); - - connect( formatLW, SIGNAL( itemClicked(QListWidgetItem *) ), - this, SLOT( slotFormatHighlighted(QListWidgetItem *) ) ); - connect( formatLW, SIGNAL( itemActivated(QListWidgetItem *) ), - this, SLOT( slotFormatSelected(QListWidgetItem *) ) ); - connect( formatLW, SIGNAL( itemClicked(QListWidgetItem *) ), - this, SLOT( changed_adaptor() ) ); - connect( commandCO, SIGNAL( textChanged(const QString&) ), - this, SLOT( changed_adaptor() ) ); + setViewTitle(_("Send Document to Command")); + setController(new ControlSendto(*this)); + + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); + + connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)), + this, SLOT(slotFormatHighlighted(QListWidgetItem *))); + connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)), + this, SLOT(slotFormatSelected(QListWidgetItem *))); + connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)), + this, SLOT(changed_adaptor())); + connect(commandCO, SIGNAL(textChanged(const QString&)), + this, SLOT(changed_adaptor())); + + bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy); + bc().setOK(okPB); + bc().setApply(applyPB); + bc().setCancel(closePB); } -void GuiSendtoDialog::changed_adaptor() -{ - form_->changed(); -} - - -void GuiSendtoDialog::closeEvent(QCloseEvent * e) +ControlSendto & GuiSendtoDialog::controller() const { - form_->slotWMHide(); - e->accept(); + return static_cast(Dialog::controller()); } -///////////////////////////////////////////////////////////////////// -// -// GuiSendto -// -///////////////////////////////////////////////////////////////////// - - -GuiSendto::GuiSendto(GuiDialog & parent) - : GuiView(parent, _("Send Document to Command")) +void GuiSendtoDialog::changed_adaptor() { + changed(); } -void GuiSendto::build_dialog() +void GuiSendtoDialog::closeEvent(QCloseEvent * e) { - dialog_.reset(new GuiSendtoDialog(this)); - - // Manage the ok, apply, restore and cancel/close buttons - bc().setOK(dialog_->okPB); - bc().setApply(dialog_->applyPB); - bc().setCancel(dialog_->closePB); + slotWMHide(); + e->accept(); } -void GuiSendto::update_contents() +void GuiSendtoDialog::update_contents() { all_formats_ = controller().allFormats(); @@ -104,45 +86,42 @@ void GuiSendto::update_contents() vector::iterator result = keys.begin(); vector::const_iterator it = all_formats_.begin(); vector::const_iterator end = all_formats_.end(); - for (; it != end; ++it, ++result) { + for (; it != end; ++it, ++result) *result = (*it)->prettyname(); - } // Reload the browser - dialog_->formatLW->clear(); + formatLW->clear(); for (vector::const_iterator it = keys.begin(); - it < keys.end(); ++it) { - dialog_->formatLW->addItem(toqstr(*it)); + it != keys.end(); ++it) { + formatLW->addItem(toqstr(*it)); } - dialog_->commandCO->addItem(toqstr(controller().getCommand())); + commandCO->addItem(toqstr(controller().getCommand())); } -void GuiSendto::applyView() +void GuiSendtoDialog::applyView() { - int const line(dialog_->formatLW->currentRow()); + int const line = formatLW->currentRow(); - if (line < 0 || line > int(dialog_->formatLW->count())) + if (line < 0 || line > int(formatLW->count())) return; - string const cmd(fromqstr(dialog_->commandCO->currentText())); - controller().setFormat(all_formats_[line]); - controller().setCommand(cmd); + controller().setCommand(fromqstr(commandCO->currentText())); } -bool GuiSendto::isValid() +bool GuiSendtoDialog::isValid() { - int const line(dialog_->formatLW->currentRow()); + int const line = formatLW->currentRow(); - if (line < 0 || line > int(dialog_->formatLW->count())) + if (line < 0 || line > int(formatLW->count())) return false; - else return dialog_->formatLW->count() != 0 && - !dialog_->commandCO->currentText().isEmpty(); + return formatLW->count() != 0 && + !commandCO->currentText().isEmpty(); } } // namespace frontend diff --git a/src/frontends/qt4/GuiSendto.h b/src/frontends/qt4/GuiSendto.h index bbba5e6b44..92aaf0a97f 100644 --- a/src/frontends/qt4/GuiSendto.h +++ b/src/frontends/qt4/GuiSendto.h @@ -12,12 +12,10 @@ #ifndef GUISENDTO_H #define GUISENDTO_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlSendto.h" #include "ui_SendtoUi.h" -#include - #include class QListWidgetItem; @@ -28,47 +26,29 @@ class Format; namespace frontend { -class GuiSendto; - -class GuiSendtoDialog : public QDialog, public Ui::SendtoUi { +class GuiSendtoDialog : public GuiDialog, public Ui::SendtoUi +{ Q_OBJECT + public: - GuiSendtoDialog(GuiSendto * form); -protected Q_SLOTS: - virtual void changed_adaptor(); - virtual void slotFormatHighlighted(QListWidgetItem *) {} - virtual void slotFormatSelected(QListWidgetItem *) {} -protected: - virtual void closeEvent(QCloseEvent * e); -private: - GuiSendto * form_; -}; + GuiSendtoDialog(LyXView & lv); +private Q_SLOTS: + void changed_adaptor(); + void slotFormatHighlighted(QListWidgetItem *) {} + void slotFormatSelected(QListWidgetItem *) {} -/** This class provides a Qt implementation of the Custom Export Dialog. - */ -class GuiSendto : public GuiView -{ -public: - /// - friend class GuiSendtoDialog; - /// - GuiSendto(GuiDialog &); - /// parent controller - ControlSendto & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlSendto const & controller() const - { return static_cast(this->getController()); } -protected: - virtual bool isValid(); private: + void closeEvent(QCloseEvent * e); + /// parent controller + ControlSendto & controller() const; + /// + bool isValid(); /// Apply from dialog - virtual void applyView(); + void applyView(); /// Update the dialog - virtual void update_contents(); - /// Build the dialog - virtual void build_dialog(); + void update_contents(); + /// std::vector all_formats_; }; diff --git a/src/frontends/qt4/GuiSetBorder.h b/src/frontends/qt4/GuiSetBorder.h index 2da560cc27..d67358b6d3 100644 --- a/src/frontends/qt4/GuiSetBorder.h +++ b/src/frontends/qt4/GuiSetBorder.h @@ -9,8 +9,9 @@ * * Full author contact details are available in file CREDITS. */ -#ifndef QSETBORDER_H -#define QSETBORDER_H + +#ifndef GUISETBORDER_H +#define GUISETBORDER_H #include #include @@ -87,4 +88,4 @@ private: //} // namespace lyx -#endif // QSETBORDER_H +#endif // GUISETBORDER_H diff --git a/src/frontends/qt4/GuiShowFile.cpp b/src/frontends/qt4/GuiShowFile.cpp index ab89573a43..f49ab8986e 100644 --- a/src/frontends/qt4/GuiShowFile.cpp +++ b/src/frontends/qt4/GuiShowFile.cpp @@ -11,67 +11,55 @@ #include #include "GuiShowFile.h" + +#include "ControlShowFile.h" #include "qt_helpers.h" #include #include #include + namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiShowFileDialog -// -///////////////////////////////////////////////////////////////////// - -GuiShowFileDialog::GuiShowFileDialog(GuiShowFile * form) - : form_(form) +GuiShowFileDialog::GuiShowFileDialog(LyXView & lv) + : GuiDialog(lv, "file") { setupUi(this); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); -} + setViewTitle(_("Show File")); + setController(new ControlShowFile(*this)); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); -void GuiShowFileDialog::closeEvent(QCloseEvent * e) -{ - form_->slotWMHide(); - e->accept(); + bc().setPolicy(ButtonPolicy::OkCancelPolicy); + bc().setCancel(closePB); } -///////////////////////////////////////////////////////////////////// -// -// GuiShowFile -// -///////////////////////////////////////////////////////////////////// - - -GuiShowFile::GuiShowFile(GuiDialog & parent) - : GuiView(parent, _("Show File")) +ControlShowFile & GuiShowFileDialog::controller() const { + return static_cast(Dialog::controller()); } -void GuiShowFile::build_dialog() +void GuiShowFileDialog::closeEvent(QCloseEvent * e) { - dialog_.reset(new GuiShowFileDialog(this)); - - bc().setCancel(dialog_->closePB); + slotWMHide(); + e->accept(); } -void GuiShowFile::update_contents() +void GuiShowFileDialog::update_contents() { - dialog_->setWindowTitle(toqstr(controller().getFileName())); + setWindowTitle(toqstr(controller().getFileName())); std::string contents = controller().getFileContents(); if (contents.empty()) { contents = "Error -> Cannot load file!"; } - dialog_->textTB->setPlainText(toqstr(contents)); + textTB->setPlainText(toqstr(contents)); } } // namespace frontend diff --git a/src/frontends/qt4/GuiShowFile.h b/src/frontends/qt4/GuiShowFile.h index 7e2fadadfe..bc7f4e6b3b 100644 --- a/src/frontends/qt4/GuiShowFile.h +++ b/src/frontends/qt4/GuiShowFile.h @@ -9,55 +9,33 @@ * Full author contact details are available in file CREDITS. */ -#ifndef QSHOWFILE_H -#define QSHOWFILE_H +#ifndef GUISHOWFILE_H +#define GUISHOWFILE_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlShowFile.h" #include "ui_ShowFileUi.h" -#include - - namespace lyx { namespace frontend { -class GuiShowFile; - -class GuiShowFileDialog : public QDialog, public Ui::ShowFileUi +class GuiShowFileDialog : public GuiDialog, public Ui::ShowFileUi { Q_OBJECT -public: - GuiShowFileDialog(GuiShowFile * form); -protected: - virtual void closeEvent(QCloseEvent * e); -private: - GuiShowFile * form_; -}; - -class GuiShowFile : public GuiView -{ public: - friend class GuiShowFileDialog; + GuiShowFileDialog(LyXView & lv); - GuiShowFile(GuiDialog &); - /// parent controller - ControlShowFile & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlShowFile const & controller() const - { return static_cast(this->getController()); } private: - /// Apply changes - virtual void applyView() {} + /// + void closeEvent(QCloseEvent * e); + /// parent controller + ControlShowFile & controller() const; /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); + void update_contents(); }; } // namespace frontend } // namespace lyx -#endif // QSHOWFILE_H +#endif // GUISHOWFILE_H diff --git a/src/frontends/qt4/GuiSpellchecker.cpp b/src/frontends/qt4/GuiSpellchecker.cpp index 2e83dba9d0..25391400a7 100644 --- a/src/frontends/qt4/GuiSpellchecker.cpp +++ b/src/frontends/qt4/GuiSpellchecker.cpp @@ -11,6 +11,8 @@ #include #include "GuiSpellchecker.h" + +#include "ControlSpellchecker.h" #include "qt_helpers.h" #include @@ -29,19 +31,14 @@ using std::string; namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiSpellCheckerDialog -// -///////////////////////////////////////////////////////////////////// - - -GuiSpellcheckerDialog::GuiSpellcheckerDialog(GuiSpellchecker * form) - : form_(form) +GuiSpellcheckerDialog::GuiSpellcheckerDialog(LyXView & lv) + : GuiDialog(lv, "spellchecker") { setupUi(this); + setViewTitle(_("Spellchecker")); + setController(new ControlSpellchecker(*this)); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(replaceCO, SIGNAL(highlighted(const QString &)), this, SLOT(replaceChanged(const QString &))); @@ -57,29 +54,44 @@ GuiSpellcheckerDialog::GuiSpellcheckerDialog(GuiSpellchecker * form) this, SLOT(replaceClicked() ) ); connect(suggestionsLW, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(suggestionChanged(QListWidgetItem*))); + + wordED->setReadOnly(true); + + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + bc().setCancel(closePB); +} + + +ControlSpellchecker & GuiSpellcheckerDialog::controller() const +{ + return static_cast(Dialog::controller()); } void GuiSpellcheckerDialog::acceptClicked() { - form_->accept(); + accept(); } + void GuiSpellcheckerDialog::addClicked() { - form_->add(); + add(); } + void GuiSpellcheckerDialog::replaceClicked() { - form_->replace(); + replace(); } + void GuiSpellcheckerDialog::ignoreClicked() { - form_->ignore(); + ignore(); } + void GuiSpellcheckerDialog::suggestionChanged(QListWidgetItem * item) { if (replaceCO->count() != 0) @@ -90,6 +102,7 @@ void GuiSpellcheckerDialog::suggestionChanged(QListWidgetItem * item) replaceCO->setCurrentIndex(0); } + void GuiSpellcheckerDialog::replaceChanged(const QString & str) { if (suggestionsLW->currentItem()->text() == str) @@ -106,101 +119,72 @@ void GuiSpellcheckerDialog::replaceChanged(const QString & str) void GuiSpellcheckerDialog::closeEvent(QCloseEvent * e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } void GuiSpellcheckerDialog::reject() { - form_->slotWMHide(); + slotWMHide(); QDialog::reject(); } - -///////////////////////////////////////////////////////////////////// -// -// GuiSpellChecker -// -///////////////////////////////////////////////////////////////////// - - -GuiSpellchecker::GuiSpellchecker(GuiDialog & parent) - : GuiView(parent, _("Spellchecker")) -{} - - -void GuiSpellchecker::build_dialog() -{ - dialog_.reset(new GuiSpellcheckerDialog(this)); - - bc().setCancel(dialog_->closePB); - dialog_->wordED->setReadOnly(true); -} - - -void GuiSpellchecker::update_contents() +void GuiSpellcheckerDialog::update_contents() { if (isVisibleView() || controller().exitEarly()) controller().check(); } -void GuiSpellchecker::accept() +void GuiSpellcheckerDialog::accept() { controller().ignoreAll(); } -void GuiSpellchecker::add() +void GuiSpellcheckerDialog::add() { controller().insert(); } -void GuiSpellchecker::ignore() +void GuiSpellcheckerDialog::ignore() { controller().check(); } -void GuiSpellchecker::replace() +void GuiSpellcheckerDialog::replace() { - controller().replace(qstring_to_ucs4(dialog_->replaceCO->currentText())); + controller().replace(qstring_to_ucs4(replaceCO->currentText())); } -void GuiSpellchecker::partialUpdate(int s) +void GuiSpellcheckerDialog::partialUpdate(int state) { - ControlSpellchecker::State const state = - static_cast(s); - switch (state) { + case ControlSpellchecker::SPELL_PROGRESSED: + spellcheckPR->setValue(controller().getProgress()); + break; - case ControlSpellchecker::SPELL_PROGRESSED: - dialog_->spellcheckPR->setValue(controller().getProgress()); - break; + case ControlSpellchecker::SPELL_FOUND_WORD: { + wordED->setText(toqstr(controller().getWord())); + suggestionsLW->clear(); - case ControlSpellchecker::SPELL_FOUND_WORD: { - dialog_->wordED->setText(toqstr(controller().getWord())); - dialog_->suggestionsLW->clear(); + docstring w; + while (!(w = controller().getSuggestion()).empty()) + suggestionsLW->addItem(toqstr(w)); - docstring w; - while (!(w = controller().getSuggestion()).empty()) { - dialog_->suggestionsLW->addItem(toqstr(w)); - } + if (suggestionsLW->count() == 0) + suggestionChanged(new QListWidgetItem(wordED->text())); + else + suggestionChanged(suggestionsLW->item(0)); - if (dialog_->suggestionsLW->count() == 0) { - dialog_->suggestionChanged(new QListWidgetItem(dialog_->wordED->text())); - } else { - dialog_->suggestionChanged(dialog_->suggestionsLW->item(0)); + suggestionsLW->setCurrentRow(0); + break; } - - dialog_->suggestionsLW->setCurrentRow(0); - } - break; - } } diff --git a/src/frontends/qt4/GuiSpellchecker.h b/src/frontends/qt4/GuiSpellchecker.h index e0e9e5e647..668821c5e7 100644 --- a/src/frontends/qt4/GuiSpellchecker.h +++ b/src/frontends/qt4/GuiSpellchecker.h @@ -13,70 +13,47 @@ #ifndef GUISPELLCHECKER_H #define GUISPELLCHECKER_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlSpellchecker.h" #include "ui_SpellcheckerUi.h" -#include - class QListWidgetItem; - namespace lyx { namespace frontend { -class GuiSpellchecker; - -class GuiSpellcheckerDialog: public QDialog, public Ui::SpellcheckerUi { +class GuiSpellcheckerDialog : public GuiDialog, public Ui::SpellcheckerUi +{ Q_OBJECT + public: - GuiSpellcheckerDialog(GuiSpellchecker * form); -public Q_SLOTS: - virtual void suggestionChanged(QListWidgetItem *); + GuiSpellcheckerDialog(LyXView & lv); -protected Q_SLOTS: - virtual void acceptClicked(); - virtual void addClicked(); - virtual void replaceClicked(); - virtual void ignoreClicked(); - virtual void replaceChanged(const QString &); - virtual void reject(); +public Q_SLOTS: + void suggestionChanged(QListWidgetItem *); -protected: - virtual void closeEvent(QCloseEvent * e); +private Q_SLOTS: + void acceptClicked(); + void addClicked(); + void replaceClicked(); + void ignoreClicked(); + void replaceChanged(const QString &); + void reject(); private: - GuiSpellchecker * form_; -}; - - -class GuiSpellchecker : public GuiView -{ -public: - friend class GuiSpellcheckerDialog; - - GuiSpellchecker(GuiDialog &); - + /// + void closeEvent(QCloseEvent * e); /// update from controller void partialUpdate(int id); /// parent controller - ControlSpellchecker & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlSpellchecker const & controller() const - { return static_cast(this->getController()); } -private: + ControlSpellchecker & controller() const; + //// void accept(); void add(); void ignore(); void replace(); - - /// Apply changes - virtual void applyView() {} /// - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); + void update_contents(); }; } // namespace frontend diff --git a/src/frontends/qt4/GuiTabular.cpp b/src/frontends/qt4/GuiTabular.cpp index 9a6650b3ef..71ecc009b4 100644 --- a/src/frontends/qt4/GuiTabular.cpp +++ b/src/frontends/qt4/GuiTabular.cpp @@ -14,6 +14,7 @@ #include "GuiTabular.h" +#include "ControlTabular.h" #include "GuiSetBorder.h" #include "LengthCombo.h" #include "Validator.h" @@ -29,19 +30,16 @@ using std::string; + namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiTabularDialog -// -///////////////////////////////////////////////////////////////////// - -GuiTabularDialog::GuiTabularDialog(GuiTabular * form) - : form_(form) +GuiTabularDialog::GuiTabularDialog(LyXView & lv) + : GuiDialog(lv, "tabular") { setupUi(this); + setViewTitle(_("Table Settings")); + setController(new ControlTabular(*this)); widthED->setValidator(unsignedLengthValidator(widthED)); topspaceED->setValidator(new LengthValidator(topspaceED)); @@ -98,27 +96,82 @@ GuiTabularDialog::GuiTabularDialog(GuiTabular * form) connect(rotateTabularCB, SIGNAL(clicked()), this, SLOT(rotateTabular())); connect(rotateCellCB, SIGNAL(clicked()), this, SLOT(rotateCell())); connect(longTabularCB, SIGNAL(clicked()), this, SLOT(longTabular())); + + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + bc().setCancel(closePB); + + bc().addReadOnly(topspaceED); + bc().addReadOnly(topspaceUnit); + bc().addReadOnly(topspaceCO); + bc().addReadOnly(bottomspaceED); + bc().addReadOnly(bottomspaceUnit); + bc().addReadOnly(bottomspaceCO); + bc().addReadOnly(interlinespaceED); + bc().addReadOnly(interlinespaceUnit); + bc().addReadOnly(interlinespaceCO); + bc().addReadOnly(borderDefaultRB); + bc().addReadOnly(booktabsRB); + + bc().addReadOnly(multicolumnCB); + bc().addReadOnly(rotateCellCB); + bc().addReadOnly(rotateTabularCB); + bc().addReadOnly(specialAlignmentED); + bc().addReadOnly(widthED); + bc().addReadOnly(widthUnit); + bc().addReadOnly(hAlignCB); + bc().addReadOnly(vAlignCB); + bc().addReadOnly(borderSetPB); + bc().addReadOnly(borderUnsetPB); + bc().addReadOnly(borders); + bc().addReadOnly(longTabularCB); + bc().addReadOnly(headerStatusCB); + bc().addReadOnly(headerBorderAboveCB); + bc().addReadOnly(headerBorderBelowCB); + bc().addReadOnly(firstheaderStatusCB); + bc().addReadOnly(firstheaderBorderAboveCB); + bc().addReadOnly(firstheaderBorderBelowCB); + bc().addReadOnly(firstheaderNoContentsCB); + bc().addReadOnly(footerStatusCB); + bc().addReadOnly(footerBorderAboveCB); + bc().addReadOnly(footerBorderBelowCB); + bc().addReadOnly(lastfooterStatusCB); + bc().addReadOnly(lastfooterBorderAboveCB); + bc().addReadOnly(lastfooterBorderBelowCB); + bc().addReadOnly(lastfooterNoContentsCB); + bc().addReadOnly(newpageCB); + + // initialize the length validator + bc().addCheckedLineEdit(widthED, fixedWidthColLA); + bc().addCheckedLineEdit(topspaceED, topspaceLA); + bc().addCheckedLineEdit(bottomspaceED, bottomspaceLA); + bc().addCheckedLineEdit(interlinespaceED, interlinespaceLA); +} + + +ControlTabular & GuiTabularDialog::controller() const +{ + return static_cast(Dialog::controller()); } void GuiTabularDialog::change_adaptor() { - form_->changed(); + changed(); } void GuiTabularDialog::closeEvent(QCloseEvent * e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } void GuiTabularDialog::booktabsChanged(bool) { - form_->changed(); - form_->controller().booktabs(booktabsRB->isChecked()); - form_->update_borders(); + changed(); + controller().booktabs(booktabsRB->isChecked()); + update_borders(); } @@ -126,29 +179,29 @@ void GuiTabularDialog::topspace_changed() { switch(topspaceCO->currentIndex()) { case 0: { - form_->controller().set(Tabular::SET_TOP_SPACE, ""); + controller().set(Tabular::SET_TOP_SPACE, ""); topspaceED->setEnabled(false); topspaceUnit->setEnabled(false); break; } case 1: { - form_->controller().set(Tabular::SET_TOP_SPACE, "default"); + controller().set(Tabular::SET_TOP_SPACE, "default"); topspaceED->setEnabled(false); topspaceUnit->setEnabled(false); break; } case 2: { if (!topspaceED->text().isEmpty()) - form_->controller().set(Tabular::SET_TOP_SPACE, + controller().set(Tabular::SET_TOP_SPACE, widgetsToLength(topspaceED, topspaceUnit)); - if (!form_->bc().policy().isReadOnly()) { + if (!bc().policy().isReadOnly()) { topspaceED->setEnabled(true); topspaceUnit->setEnabled(true); } break; } } - form_->changed(); + changed(); } @@ -156,29 +209,29 @@ void GuiTabularDialog::bottomspace_changed() { switch(bottomspaceCO->currentIndex()) { case 0: { - form_->controller().set(Tabular::SET_BOTTOM_SPACE, ""); + controller().set(Tabular::SET_BOTTOM_SPACE, ""); bottomspaceED->setEnabled(false); bottomspaceUnit->setEnabled(false); break; } case 1: { - form_->controller().set(Tabular::SET_BOTTOM_SPACE, "default"); + controller().set(Tabular::SET_BOTTOM_SPACE, "default"); bottomspaceED->setEnabled(false); bottomspaceUnit->setEnabled(false); break; } case 2: { if (!bottomspaceED->text().isEmpty()) - form_->controller().set(Tabular::SET_BOTTOM_SPACE, + controller().set(Tabular::SET_BOTTOM_SPACE, widgetsToLength(bottomspaceED, bottomspaceUnit)); - if (!form_->bc().policy().isReadOnly()) { + if (!bc().policy().isReadOnly()) { bottomspaceED->setEnabled(true); bottomspaceUnit->setEnabled(true); } break; } } - form_->changed(); + changed(); } @@ -186,117 +239,117 @@ void GuiTabularDialog::interlinespace_changed() { switch(interlinespaceCO->currentIndex()) { case 0: { - form_->controller().set(Tabular::SET_INTERLINE_SPACE, ""); + controller().set(Tabular::SET_INTERLINE_SPACE, ""); interlinespaceED->setEnabled(false); interlinespaceUnit->setEnabled(false); break; } case 1: { - form_->controller().set(Tabular::SET_INTERLINE_SPACE, "default"); + controller().set(Tabular::SET_INTERLINE_SPACE, "default"); interlinespaceED->setEnabled(false); interlinespaceUnit->setEnabled(false); break; } case 2: { if (!interlinespaceED->text().isEmpty()) - form_->controller().set(Tabular::SET_INTERLINE_SPACE, + controller().set(Tabular::SET_INTERLINE_SPACE, widgetsToLength(interlinespaceED, interlinespaceUnit)); - if (!form_->bc().policy().isReadOnly()) { + if (!bc().policy().isReadOnly()) { interlinespaceED->setEnabled(true); interlinespaceUnit->setEnabled(true); } break; } } - form_->changed(); + changed(); } void GuiTabularDialog::close_clicked() { - form_->closeGUI(); - form_->slotClose(); + closeGUI(); + slotClose(); } void GuiTabularDialog::borderSet_clicked() { - form_->controller().set(Tabular::SET_ALL_LINES); - form_->update_borders(); - form_->changed(); + controller().set(Tabular::SET_ALL_LINES); + update_borders(); + changed(); } void GuiTabularDialog::borderUnset_clicked() { - form_->controller().set(Tabular::UNSET_ALL_LINES); - form_->update_borders(); - form_->changed(); + controller().set(Tabular::UNSET_ALL_LINES); + update_borders(); + changed(); } void GuiTabularDialog::leftBorder_changed() { - form_->controller().toggleLeftLine(); - form_->changed(); + controller().toggleLeftLine(); + changed(); } void GuiTabularDialog::rightBorder_changed() { - form_->controller().toggleRightLine(); - form_->changed(); + controller().toggleRightLine(); + changed(); } void GuiTabularDialog::topBorder_changed() { - form_->controller().toggleTopLine(); - form_->changed(); + controller().toggleTopLine(); + changed(); } void GuiTabularDialog::bottomBorder_changed() { - form_->controller().toggleBottomLine(); - form_->changed(); + controller().toggleBottomLine(); + changed(); } void GuiTabularDialog::specialAlignment_changed() { string special = fromqstr(specialAlignmentED->text()); - form_->controller().setSpecial(special); - form_->changed(); + controller().setSpecial(special); + changed(); } void GuiTabularDialog::width_changed() { - form_->changed(); + changed(); string const width = widgetsToLength(widthED, widthUnit); - form_->controller().setWidth(width); + controller().setWidth(width); } void GuiTabularDialog::multicolumn_clicked() { - form_->controller().toggleMultiColumn(); - form_->changed(); + controller().toggleMultiColumn(); + changed(); } void GuiTabularDialog::rotateTabular() { - form_->controller().rotateTabular(rotateTabularCB->isChecked()); - form_->changed(); + controller().rotateTabular(rotateTabularCB->isChecked()); + changed(); } void GuiTabularDialog::rotateCell() { - form_->controller().rotateCell(rotateCellCB->isChecked()); - form_->changed(); + controller().rotateCell(rotateCellCB->isChecked()); + changed(); } @@ -311,7 +364,7 @@ void GuiTabularDialog::hAlign_changed(int align) case 3: h = ControlTabular::BLOCK; break; } - form_->controller().halign(h); + controller().halign(h); } @@ -325,21 +378,21 @@ void GuiTabularDialog::vAlign_changed(int align) case 2: v = ControlTabular::BOTTOM; break; } - form_->controller().valign(v); + controller().valign(v); } void GuiTabularDialog::longTabular() { - form_->controller().longTabular(longTabularCB->isChecked()); - form_->changed(); + controller().longTabular(longTabularCB->isChecked()); + changed(); } void GuiTabularDialog::ltNewpage_clicked() { - form_->controller().set(Tabular::SET_LTNEWPAGE); - form_->changed(); + controller().set(Tabular::SET_LTNEWPAGE); + changed(); } @@ -347,53 +400,53 @@ void GuiTabularDialog::ltHeaderStatus_clicked() { bool enable(headerStatusCB->isChecked()); if (enable) - form_->controller().set(Tabular::SET_LTHEAD, ""); + controller().set(Tabular::SET_LTHEAD, ""); else - form_->controller().set(Tabular::UNSET_LTHEAD, ""); + controller().set(Tabular::UNSET_LTHEAD, ""); headerBorderAboveCB->setEnabled(enable); headerBorderBelowCB->setEnabled(enable); firstheaderNoContentsCB->setEnabled(enable); - form_->changed(); + changed(); } void GuiTabularDialog::ltHeaderBorderAbove_clicked() { if (headerBorderAboveCB->isChecked()) - form_->controller().set(Tabular::SET_LTHEAD, "dl_above"); + controller().set(Tabular::SET_LTHEAD, "dl_above"); else - form_->controller().set(Tabular::UNSET_LTHEAD, "dl_above"); - form_->changed(); + controller().set(Tabular::UNSET_LTHEAD, "dl_above"); + changed(); } void GuiTabularDialog::ltHeaderBorderBelow_clicked() { if (headerBorderBelowCB->isChecked()) - form_->controller().set(Tabular::SET_LTHEAD, "dl_below"); + controller().set(Tabular::SET_LTHEAD, "dl_below"); else - form_->controller().set(Tabular::UNSET_LTHEAD, "dl_below"); - form_->changed(); + controller().set(Tabular::UNSET_LTHEAD, "dl_below"); + changed(); } void GuiTabularDialog::ltFirstHeaderBorderAbove_clicked() { if (firstheaderBorderAboveCB->isChecked()) - form_->controller().set(Tabular::SET_LTFIRSTHEAD, "dl_above"); + controller().set(Tabular::SET_LTFIRSTHEAD, "dl_above"); else - form_->controller().set(Tabular::UNSET_LTFIRSTHEAD, "dl_above"); - form_->changed(); + controller().set(Tabular::UNSET_LTFIRSTHEAD, "dl_above"); + changed(); } void GuiTabularDialog::ltFirstHeaderBorderBelow_clicked() { if (firstheaderBorderBelowCB->isChecked()) - form_->controller().set(Tabular::SET_LTFIRSTHEAD, "dl_below"); + controller().set(Tabular::SET_LTFIRSTHEAD, "dl_below"); else - form_->controller().set(Tabular::UNSET_LTFIRSTHEAD, "dl_below"); - form_->changed(); + controller().set(Tabular::UNSET_LTFIRSTHEAD, "dl_below"); + changed(); } @@ -401,12 +454,12 @@ void GuiTabularDialog::ltFirstHeaderStatus_clicked() { bool enable(firstheaderStatusCB->isChecked()); if (enable) - form_->controller().set(Tabular::SET_LTFIRSTHEAD, ""); + controller().set(Tabular::SET_LTFIRSTHEAD, ""); else - form_->controller().set(Tabular::UNSET_LTFIRSTHEAD, ""); + controller().set(Tabular::UNSET_LTFIRSTHEAD, ""); firstheaderBorderAboveCB->setEnabled(enable); firstheaderBorderBelowCB->setEnabled(enable); - form_->changed(); + changed(); } @@ -414,13 +467,13 @@ void GuiTabularDialog::ltFirstHeaderEmpty_clicked() { bool enable(firstheaderNoContentsCB->isChecked()); if (enable) - form_->controller().set(Tabular::SET_LTFIRSTHEAD, "empty"); + controller().set(Tabular::SET_LTFIRSTHEAD, "empty"); else - form_->controller().set(Tabular::UNSET_LTFIRSTHEAD, "empty"); + controller().set(Tabular::UNSET_LTFIRSTHEAD, "empty"); firstheaderStatusCB->setEnabled(!enable); firstheaderBorderAboveCB->setEnabled(!enable); firstheaderBorderBelowCB->setEnabled(!enable); - form_->changed(); + changed(); } @@ -428,33 +481,33 @@ void GuiTabularDialog::ltFooterStatus_clicked() { bool enable(footerStatusCB->isChecked()); if (enable) - form_->controller().set(Tabular::SET_LTFOOT, ""); + controller().set(Tabular::SET_LTFOOT, ""); else - form_->controller().set(Tabular::UNSET_LTFOOT, ""); + controller().set(Tabular::UNSET_LTFOOT, ""); footerBorderAboveCB->setEnabled(enable); footerBorderBelowCB->setEnabled(enable); lastfooterNoContentsCB->setEnabled(enable); - form_->changed(); + changed(); } void GuiTabularDialog::ltFooterBorderAbove_clicked() { if (footerBorderAboveCB->isChecked()) - form_->controller().set(Tabular::SET_LTFOOT, "dl_above"); + controller().set(Tabular::SET_LTFOOT, "dl_above"); else - form_->controller().set(Tabular::UNSET_LTFOOT, "dl_above"); - form_->changed(); + controller().set(Tabular::UNSET_LTFOOT, "dl_above"); + changed(); } void GuiTabularDialog::ltFooterBorderBelow_clicked() { if (footerBorderBelowCB->isChecked()) - form_->controller().set(Tabular::SET_LTFOOT, "dl_below"); + controller().set(Tabular::SET_LTFOOT, "dl_below"); else - form_->controller().set(Tabular::UNSET_LTFOOT, "dl_below"); - form_->changed(); + controller().set(Tabular::UNSET_LTFOOT, "dl_below"); + changed(); } @@ -462,32 +515,32 @@ void GuiTabularDialog::ltLastFooterStatus_clicked() { bool enable(lastfooterStatusCB->isChecked()); if (enable) - form_->controller().set(Tabular::SET_LTLASTFOOT, ""); + controller().set(Tabular::SET_LTLASTFOOT, ""); else - form_->controller().set(Tabular::UNSET_LTLASTFOOT, ""); + controller().set(Tabular::UNSET_LTLASTFOOT, ""); lastfooterBorderAboveCB->setEnabled(enable); lastfooterBorderBelowCB->setEnabled(enable); - form_->changed(); + changed(); } void GuiTabularDialog::ltLastFooterBorderAbove_clicked() { if (lastfooterBorderAboveCB->isChecked()) - form_->controller().set(Tabular::SET_LTLASTFOOT, "dl_above"); + controller().set(Tabular::SET_LTLASTFOOT, "dl_above"); else - form_->controller().set(Tabular::UNSET_LTLASTFOOT, "dl_above"); - form_->changed(); + controller().set(Tabular::UNSET_LTLASTFOOT, "dl_above"); + changed(); } void GuiTabularDialog::ltLastFooterBorderBelow_clicked() { if (lastfooterBorderBelowCB->isChecked()) - form_->controller().set(Tabular::SET_LTLASTFOOT, "dl_below"); + controller().set(Tabular::SET_LTLASTFOOT, "dl_below"); else - form_->controller().set(Tabular::UNSET_LTLASTFOOT, "dl_below"); - form_->changed(); + controller().set(Tabular::UNSET_LTLASTFOOT, "dl_below"); + changed(); } @@ -495,132 +548,59 @@ void GuiTabularDialog::ltLastFooterEmpty_clicked() { bool enable(lastfooterNoContentsCB->isChecked()); if (enable) - form_->controller().set(Tabular::SET_LTLASTFOOT, "empty"); + controller().set(Tabular::SET_LTLASTFOOT, "empty"); else - form_->controller().set(Tabular::UNSET_LTLASTFOOT, "empty"); + controller().set(Tabular::UNSET_LTLASTFOOT, "empty"); lastfooterStatusCB->setEnabled(!enable); lastfooterBorderAboveCB->setEnabled(!enable); lastfooterBorderBelowCB->setEnabled(!enable); - form_->changed(); -} - - -///////////////////////////////////////////////////////////////////// -// -// GuiTabular -// -///////////////////////////////////////////////////////////////////// - - -GuiTabular::GuiTabular(GuiDialog & parent) - : GuiView(parent, _("Table Settings")) -{ -} - - -void GuiTabular::build_dialog() -{ - dialog_.reset(new GuiTabularDialog(this)); - - bc().setCancel(dialog_->closePB); - - bc().addReadOnly(dialog_->topspaceED); - bc().addReadOnly(dialog_->topspaceUnit); - bc().addReadOnly(dialog_->topspaceCO); - bc().addReadOnly(dialog_->bottomspaceED); - bc().addReadOnly(dialog_->bottomspaceUnit); - bc().addReadOnly(dialog_->bottomspaceCO); - bc().addReadOnly(dialog_->interlinespaceED); - bc().addReadOnly(dialog_->interlinespaceUnit); - bc().addReadOnly(dialog_->interlinespaceCO); - bc().addReadOnly(dialog_->borderDefaultRB); - bc().addReadOnly(dialog_->booktabsRB); - - bc().addReadOnly(dialog_->multicolumnCB); - bc().addReadOnly(dialog_->rotateCellCB); - bc().addReadOnly(dialog_->rotateTabularCB); - bc().addReadOnly(dialog_->specialAlignmentED); - bc().addReadOnly(dialog_->widthED); - bc().addReadOnly(dialog_->widthUnit); - bc().addReadOnly(dialog_->hAlignCB); - bc().addReadOnly(dialog_->vAlignCB); - bc().addReadOnly(dialog_->borderSetPB); - bc().addReadOnly(dialog_->borderUnsetPB); - bc().addReadOnly(dialog_->borders); - bc().addReadOnly(dialog_->longTabularCB); - bc().addReadOnly(dialog_->headerStatusCB); - bc().addReadOnly(dialog_->headerBorderAboveCB); - bc().addReadOnly(dialog_->headerBorderBelowCB); - bc().addReadOnly(dialog_->firstheaderStatusCB); - bc().addReadOnly(dialog_->firstheaderBorderAboveCB); - bc().addReadOnly(dialog_->firstheaderBorderBelowCB); - bc().addReadOnly(dialog_->firstheaderNoContentsCB); - bc().addReadOnly(dialog_->footerStatusCB); - bc().addReadOnly(dialog_->footerBorderAboveCB); - bc().addReadOnly(dialog_->footerBorderBelowCB); - bc().addReadOnly(dialog_->lastfooterStatusCB); - bc().addReadOnly(dialog_->lastfooterBorderAboveCB); - bc().addReadOnly(dialog_->lastfooterBorderBelowCB); - bc().addReadOnly(dialog_->lastfooterNoContentsCB); - bc().addReadOnly(dialog_->newpageCB); - - // initialize the length validator - bc().addCheckedLineEdit(dialog_->widthED, dialog_->fixedWidthColLA); - bc().addCheckedLineEdit(dialog_->topspaceED, dialog_->topspaceLA); - bc().addCheckedLineEdit(dialog_->bottomspaceED, dialog_->bottomspaceLA); - bc().addCheckedLineEdit(dialog_->interlinespaceED, dialog_->interlinespaceLA); -} - - -bool GuiTabular::isValid() -{ - return true; + changed(); } -void GuiTabular::update_borders() +void GuiTabularDialog::update_borders() { Tabular const & tabular = controller().tabular(); Tabular::idx_type const cell = controller().getActiveCell(); bool const isMulticolumnCell = tabular.isMultiColumn(cell); if (!isMulticolumnCell) { - dialog_->borders->setLeftEnabled(true); - dialog_->borders->setRightEnabled(true); - dialog_->borders->setTop(tabular.topLine(cell, true)); - dialog_->borders->setBottom(tabular.bottomLine(cell, true)); - dialog_->borders->setLeft(tabular.leftLine(cell, true)); - dialog_->borders->setRight(tabular.rightLine(cell, true)); + borders->setLeftEnabled(true); + borders->setRightEnabled(true); + borders->setTop(tabular.topLine(cell, true)); + borders->setBottom(tabular.bottomLine(cell, true)); + borders->setLeft(tabular.leftLine(cell, true)); + borders->setRight(tabular.rightLine(cell, true)); // repaint the setborder widget - dialog_->borders->update(); + borders->update(); return; } - dialog_->borders->setTop(tabular.topLine(cell)); - dialog_->borders->setBottom(tabular.bottomLine(cell)); + borders->setTop(tabular.topLine(cell)); + borders->setBottom(tabular.bottomLine(cell)); // pay attention to left/right lines: they are only allowed // to set if we are in first/last cell of row or if the left/right // cell is also a multicolumn. if (tabular.isFirstCellInRow(cell) || tabular.isMultiColumn(cell - 1)) { - dialog_->borders->setLeftEnabled(true); - dialog_->borders->setLeft(tabular.leftLine(cell)); + borders->setLeftEnabled(true); + borders->setLeft(tabular.leftLine(cell)); } else { - dialog_->borders->setLeft(false); - dialog_->borders->setLeftEnabled(false); + borders->setLeft(false); + borders->setLeftEnabled(false); } if (tabular.isLastCellInRow(cell) || tabular.isMultiColumn(cell + 1)) { - dialog_->borders->setRightEnabled(true); - dialog_->borders->setRight(tabular.rightLine(cell)); + borders->setRightEnabled(true); + borders->setRight(tabular.rightLine(cell)); } else { - dialog_->borders->setRight(false); - dialog_->borders->setRightEnabled(false); + borders->setRight(false); + borders->setRightEnabled(false); } // repaint the setborder widget - dialog_->borders->update(); + borders->update(); } -void GuiTabular::update_contents() +void GuiTabularDialog::update_contents() { controller().initialiseParams(string()); @@ -630,17 +610,17 @@ void GuiTabular::update_contents() Tabular::row_type const row = tabular.cellRow(cell); Tabular::col_type const col = tabular.cellColumn(cell); - dialog_->tabularRowED->setText(toqstr(convert(row + 1))); - dialog_->tabularColumnED->setText(toqstr(convert(col + 1))); + tabularRowED->setText(toqstr(convert(row + 1))); + tabularColumnED->setText(toqstr(convert(col + 1))); bool const multicol(tabular.isMultiColumn(cell)); - dialog_->multicolumnCB->setChecked(multicol); + multicolumnCB->setChecked(multicol); - dialog_->rotateCellCB->setChecked(tabular.getRotateCell(cell)); - dialog_->rotateTabularCB->setChecked(tabular.getRotateTabular()); + rotateCellCB->setChecked(tabular.getRotateCell(cell)); + rotateTabularCB->setChecked(tabular.getRotateTabular()); - dialog_->longTabularCB->setChecked(tabular.isLongTabular()); + longTabularCB->setChecked(tabular.isLongTabular()); update_borders(); @@ -655,86 +635,86 @@ void GuiTabular::update_contents() pwidth = tabular.getColumnPWidth(cell); } - dialog_->specialAlignmentED->setText(toqstr(special)); + specialAlignmentED->setText(toqstr(special)); bool const isReadonly = bc().policy().isReadOnly(); - dialog_->specialAlignmentED->setEnabled(!isReadonly); + specialAlignmentED->setEnabled(!isReadonly); Length::UNIT default_unit = controller().useMetricUnits() ? Length::CM : Length::IN; - dialog_->borderDefaultRB->setChecked(!tabular.useBookTabs()); - dialog_->booktabsRB->setChecked(tabular.useBookTabs()); + borderDefaultRB->setChecked(!tabular.useBookTabs()); + booktabsRB->setChecked(tabular.useBookTabs()); if (tabular.row_info[row].top_space.empty() && !tabular.row_info[row].top_space_default) { - dialog_->topspaceCO->setCurrentIndex(0); + topspaceCO->setCurrentIndex(0); } else if (tabular.row_info[row].top_space_default) { - dialog_->topspaceCO->setCurrentIndex(1); + topspaceCO->setCurrentIndex(1); } else { - dialog_->topspaceCO->setCurrentIndex(2); - lengthToWidgets(dialog_->topspaceED, - dialog_->topspaceUnit, + topspaceCO->setCurrentIndex(2); + lengthToWidgets(topspaceED, + topspaceUnit, tabular.row_info[row].top_space.asString(), default_unit); } - dialog_->topspaceED->setEnabled(!isReadonly - && (dialog_->topspaceCO->currentIndex() == 2)); - dialog_->topspaceUnit->setEnabled(!isReadonly - && (dialog_->topspaceCO->currentIndex() == 2)); - dialog_->topspaceCO->setEnabled(!isReadonly); + topspaceED->setEnabled(!isReadonly + && (topspaceCO->currentIndex() == 2)); + topspaceUnit->setEnabled(!isReadonly + && (topspaceCO->currentIndex() == 2)); + topspaceCO->setEnabled(!isReadonly); if (tabular.row_info[row].bottom_space.empty() && !tabular.row_info[row].bottom_space_default) { - dialog_->bottomspaceCO->setCurrentIndex(0); + bottomspaceCO->setCurrentIndex(0); } else if (tabular.row_info[row].bottom_space_default) { - dialog_->bottomspaceCO->setCurrentIndex(1); + bottomspaceCO->setCurrentIndex(1); } else { - dialog_->bottomspaceCO->setCurrentIndex(2); - lengthToWidgets(dialog_->bottomspaceED, - dialog_->bottomspaceUnit, + bottomspaceCO->setCurrentIndex(2); + lengthToWidgets(bottomspaceED, + bottomspaceUnit, tabular.row_info[row].bottom_space.asString(), default_unit); } - dialog_->bottomspaceED->setEnabled(!isReadonly - && (dialog_->bottomspaceCO->currentIndex() == 2)); - dialog_->bottomspaceUnit->setEnabled(!isReadonly - && (dialog_->bottomspaceCO->currentIndex() == 2)); - dialog_->bottomspaceCO->setEnabled(!isReadonly); + bottomspaceED->setEnabled(!isReadonly + && (bottomspaceCO->currentIndex() == 2)); + bottomspaceUnit->setEnabled(!isReadonly + && (bottomspaceCO->currentIndex() == 2)); + bottomspaceCO->setEnabled(!isReadonly); if (tabular.row_info[row].interline_space.empty() && !tabular.row_info[row].interline_space_default) { - dialog_->interlinespaceCO->setCurrentIndex(0); + interlinespaceCO->setCurrentIndex(0); } else if (tabular.row_info[row].interline_space_default) { - dialog_->interlinespaceCO->setCurrentIndex(1); + interlinespaceCO->setCurrentIndex(1); } else { - dialog_->interlinespaceCO->setCurrentIndex(2); - lengthToWidgets(dialog_->interlinespaceED, - dialog_->interlinespaceUnit, + interlinespaceCO->setCurrentIndex(2); + lengthToWidgets(interlinespaceED, + interlinespaceUnit, tabular.row_info[row].interline_space.asString(), default_unit); } - dialog_->interlinespaceED->setEnabled(!isReadonly - && (dialog_->interlinespaceCO->currentIndex() == 2)); - dialog_->interlinespaceUnit->setEnabled(!isReadonly - && (dialog_->interlinespaceCO->currentIndex() == 2)); - dialog_->interlinespaceCO->setEnabled(!isReadonly); + interlinespaceED->setEnabled(!isReadonly + && (interlinespaceCO->currentIndex() == 2)); + interlinespaceUnit->setEnabled(!isReadonly + && (interlinespaceCO->currentIndex() == 2)); + interlinespaceCO->setEnabled(!isReadonly); string colwidth; if (!pwidth.zero()) colwidth = pwidth.asString(); - lengthToWidgets(dialog_->widthED, dialog_->widthUnit, + lengthToWidgets(widthED, widthUnit, colwidth, default_unit); - dialog_->widthED->setEnabled(!isReadonly); - dialog_->widthUnit->setEnabled(!isReadonly); + widthED->setEnabled(!isReadonly); + widthUnit->setEnabled(!isReadonly); - dialog_->hAlignCB->clear(); - dialog_->hAlignCB->addItem(qt_("Left")); - dialog_->hAlignCB->addItem(qt_("Center")); - dialog_->hAlignCB->addItem(qt_("Right")); + hAlignCB->clear(); + hAlignCB->addItem(qt_("Left")); + hAlignCB->addItem(qt_("Center")); + hAlignCB->addItem(qt_("Right")); if (!multicol && !pwidth.zero()) - dialog_->hAlignCB->addItem(qt_("Justified")); + hAlignCB->addItem(qt_("Justified")); int align = 0; switch (tabular.getAlignment(cell)) { @@ -757,7 +737,7 @@ void GuiTabular::update_contents() align = 0; break; } - dialog_->hAlignCB->setCurrentIndex(align); + hAlignCB->setCurrentIndex(align); int valign = 0; switch (tabular.getVAlignment(cell)) { @@ -776,103 +756,103 @@ void GuiTabular::update_contents() } if (pwidth.zero()) valign = 1; - dialog_->vAlignCB->setCurrentIndex(valign); + vAlignCB->setCurrentIndex(valign); - dialog_->hAlignCB->setEnabled(true); - dialog_->vAlignCB->setEnabled(!pwidth.zero()); + hAlignCB->setEnabled(true); + vAlignCB->setEnabled(!pwidth.zero()); if (!tabular.isLongTabular()) { - dialog_->headerStatusCB->setChecked(false); - dialog_->headerBorderAboveCB->setChecked(false); - dialog_->headerBorderBelowCB->setChecked(false); - dialog_->firstheaderStatusCB->setChecked(false); - dialog_->firstheaderBorderAboveCB->setChecked(false); - dialog_->firstheaderBorderBelowCB->setChecked(false); - dialog_->firstheaderNoContentsCB->setChecked(false); - dialog_->footerStatusCB->setChecked(false); - dialog_->footerBorderAboveCB->setChecked(false); - dialog_->footerBorderBelowCB->setChecked(false); - dialog_->lastfooterStatusCB->setChecked(false); - dialog_->lastfooterBorderAboveCB->setChecked(false); - dialog_->lastfooterBorderBelowCB->setChecked(false); - dialog_->lastfooterNoContentsCB->setChecked(false); - dialog_->newpageCB->setChecked(false); - dialog_->newpageCB->setEnabled(false); + headerStatusCB->setChecked(false); + headerBorderAboveCB->setChecked(false); + headerBorderBelowCB->setChecked(false); + firstheaderStatusCB->setChecked(false); + firstheaderBorderAboveCB->setChecked(false); + firstheaderBorderBelowCB->setChecked(false); + firstheaderNoContentsCB->setChecked(false); + footerStatusCB->setChecked(false); + footerBorderAboveCB->setChecked(false); + footerBorderBelowCB->setChecked(false); + lastfooterStatusCB->setChecked(false); + lastfooterBorderAboveCB->setChecked(false); + lastfooterBorderBelowCB->setChecked(false); + lastfooterNoContentsCB->setChecked(false); + newpageCB->setChecked(false); + newpageCB->setEnabled(false); return; } Tabular::ltType ltt; bool use_empty; bool row_set = tabular.getRowOfLTHead(row, ltt); - dialog_->headerStatusCB->setChecked(row_set); + headerStatusCB->setChecked(row_set); if (ltt.set) { - dialog_->headerBorderAboveCB->setChecked(ltt.topDL); - dialog_->headerBorderBelowCB->setChecked(ltt.bottomDL); + headerBorderAboveCB->setChecked(ltt.topDL); + headerBorderBelowCB->setChecked(ltt.bottomDL); use_empty = true; } else { - dialog_->headerBorderAboveCB->setChecked(false); - dialog_->headerBorderBelowCB->setChecked(false); - dialog_->headerBorderAboveCB->setEnabled(false); - dialog_->headerBorderBelowCB->setEnabled(false); - dialog_->firstheaderNoContentsCB->setChecked(false); - dialog_->firstheaderNoContentsCB->setEnabled(false); + headerBorderAboveCB->setChecked(false); + headerBorderBelowCB->setChecked(false); + headerBorderAboveCB->setEnabled(false); + headerBorderBelowCB->setEnabled(false); + firstheaderNoContentsCB->setChecked(false); + firstheaderNoContentsCB->setEnabled(false); use_empty = false; } row_set = tabular.getRowOfLTFirstHead(row, ltt); - dialog_->firstheaderStatusCB->setChecked(row_set); + firstheaderStatusCB->setChecked(row_set); if (ltt.set && (!ltt.empty || !use_empty)) { - dialog_->firstheaderBorderAboveCB->setChecked(ltt.topDL); - dialog_->firstheaderBorderBelowCB->setChecked(ltt.bottomDL); + firstheaderBorderAboveCB->setChecked(ltt.topDL); + firstheaderBorderBelowCB->setChecked(ltt.bottomDL); } else { - dialog_->firstheaderBorderAboveCB->setEnabled(false); - dialog_->firstheaderBorderBelowCB->setEnabled(false); - dialog_->firstheaderBorderAboveCB->setChecked(false); - dialog_->firstheaderBorderBelowCB->setChecked(false); + firstheaderBorderAboveCB->setEnabled(false); + firstheaderBorderBelowCB->setEnabled(false); + firstheaderBorderAboveCB->setChecked(false); + firstheaderBorderBelowCB->setChecked(false); if (use_empty) { - dialog_->firstheaderNoContentsCB->setChecked(ltt.empty); + firstheaderNoContentsCB->setChecked(ltt.empty); if (ltt.empty) - dialog_->firstheaderStatusCB->setEnabled(false); + firstheaderStatusCB->setEnabled(false); } } row_set = tabular.getRowOfLTFoot(row, ltt); - dialog_->footerStatusCB->setChecked(row_set); + footerStatusCB->setChecked(row_set); if (ltt.set) { - dialog_->footerBorderAboveCB->setChecked(ltt.topDL); - dialog_->footerBorderBelowCB->setChecked(ltt.bottomDL); + footerBorderAboveCB->setChecked(ltt.topDL); + footerBorderBelowCB->setChecked(ltt.bottomDL); use_empty = true; } else { - dialog_->footerBorderAboveCB->setChecked(false); - dialog_->footerBorderBelowCB->setChecked(false); - dialog_->footerBorderAboveCB->setEnabled(false); - dialog_->footerBorderBelowCB->setEnabled(false); - dialog_->lastfooterNoContentsCB->setChecked(false); - dialog_->lastfooterNoContentsCB->setEnabled(false); + footerBorderAboveCB->setChecked(false); + footerBorderBelowCB->setChecked(false); + footerBorderAboveCB->setEnabled(false); + footerBorderBelowCB->setEnabled(false); + lastfooterNoContentsCB->setChecked(false); + lastfooterNoContentsCB->setEnabled(false); use_empty = false; } row_set = tabular.getRowOfLTLastFoot(row, ltt); - dialog_->lastfooterStatusCB->setChecked(row_set); + lastfooterStatusCB->setChecked(row_set); if (ltt.set && (!ltt.empty || !use_empty)) { - dialog_->lastfooterBorderAboveCB->setChecked(ltt.topDL); - dialog_->lastfooterBorderBelowCB->setChecked(ltt.bottomDL); + lastfooterBorderAboveCB->setChecked(ltt.topDL); + lastfooterBorderBelowCB->setChecked(ltt.bottomDL); } else { - dialog_->lastfooterBorderAboveCB->setEnabled(false); - dialog_->lastfooterBorderBelowCB->setEnabled(false); - dialog_->lastfooterBorderAboveCB->setChecked(false); - dialog_->lastfooterBorderBelowCB->setChecked(false); + lastfooterBorderAboveCB->setEnabled(false); + lastfooterBorderBelowCB->setEnabled(false); + lastfooterBorderAboveCB->setChecked(false); + lastfooterBorderBelowCB->setChecked(false); if (use_empty) { - dialog_->lastfooterNoContentsCB->setChecked(ltt.empty); + lastfooterNoContentsCB->setChecked(ltt.empty); if (ltt.empty) - dialog_->lastfooterStatusCB->setEnabled(false); + lastfooterStatusCB->setEnabled(false); } } - dialog_->newpageCB->setChecked(tabular.getLTNewPage(row)); + newpageCB->setChecked(tabular.getLTNewPage(row)); } -void GuiTabular::closeGUI() +void GuiTabularDialog::closeGUI() { // ugly hack to auto-apply the stuff that hasn't been // yet. don't let this continue to exist ... @@ -885,7 +865,7 @@ void GuiTabular::closeGUI() // apply the fixed width values Tabular::idx_type const cell = controller().getActiveCell(); bool const multicol = tabular.isMultiColumn(cell); - string width = widgetsToLength(dialog_->widthED, dialog_->widthUnit); + string width = widgetsToLength(widthED, widthUnit); string width2; Length llen = tabular.getColumnPWidth(cell); @@ -897,7 +877,7 @@ void GuiTabular::closeGUI() width2 = llen.asString(); // apply the special alignment - docstring const sa1 = qstring_to_ucs4(dialog_->specialAlignmentED->text()); + docstring const sa1 = qstring_to_ucs4(specialAlignmentED->text()); docstring sa2; if (multicol) @@ -920,7 +900,7 @@ void GuiTabular::closeGUI() } /* DO WE NEED THIS? - switch (dialog_->topspaceCO->currentIndex()) { + switch (topspaceCO->currentIndex()) { case 0: controller().set(Tabular::SET_TOP_SPACE, ""); break; @@ -929,12 +909,12 @@ void GuiTabular::closeGUI() break; case 2: controller().set(Tabular::SET_TOP_SPACE, - widgetsToLength(dialog_->topspaceED, - dialog_->topspaceUnit)); + widgetsToLength(topspaceED, + topspaceUnit)); break; } - switch (dialog_->bottomspaceCO->currentIndex()) { + switch (bottomspaceCO->currentIndex()) { case 0: controller().set(Tabular::SET_BOTTOM_SPACE, ""); break; @@ -943,12 +923,12 @@ void GuiTabular::closeGUI() break; case 2: controller().set(Tabular::SET_BOTTOM_SPACE, - widgetsToLength(dialog_->bottomspaceED, - dialog_->bottomspaceUnit)); + widgetsToLength(bottomspaceED, + bottomspaceUnit)); break; } - switch (dialog_->interlinespaceCO->currentIndex()) { + switch (interlinespaceCO->currentIndex()) { case 0: controller().set(Tabular::SET_INTERLINE_SPACE, ""); break; @@ -957,8 +937,8 @@ void GuiTabular::closeGUI() break; case 2: controller().set(Tabular::SET_INTERLINE_SPACE, - widgetsToLength(dialog_->interlinespaceED, - dialog_->interlinespaceUnit)); + widgetsToLength(interlinespaceED, + interlinespaceUnit)); break; } */ diff --git a/src/frontends/qt4/GuiTabular.h b/src/frontends/qt4/GuiTabular.h index b27f5d2380..41893feda3 100644 --- a/src/frontends/qt4/GuiTabular.h +++ b/src/frontends/qt4/GuiTabular.h @@ -15,96 +15,71 @@ #ifndef GUITABULAR_H #define GUITABULAR_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlTabular.h" #include "ui_TabularUi.h" -#include - namespace lyx { namespace frontend { -class GuiTabular; - -class GuiTabularDialog : public QDialog, public Ui::TabularUi +class GuiTabularDialog : public GuiDialog, public Ui::TabularUi { Q_OBJECT -public: - GuiTabularDialog(GuiTabular * form); - -protected Q_SLOTS: - virtual void change_adaptor(); - - virtual void topspace_changed(); - virtual void bottomspace_changed(); - virtual void interlinespace_changed(); - virtual void booktabsChanged(bool); - virtual void close_clicked(); - virtual void borderSet_clicked(); - virtual void borderUnset_clicked(); - virtual void leftBorder_changed(); - virtual void rightBorder_changed(); - virtual void topBorder_changed(); - virtual void bottomBorder_changed(); - virtual void multicolumn_clicked(); - virtual void rotateTabular(); - virtual void rotateCell(); - virtual void hAlign_changed(int align); - virtual void vAlign_changed(int align); - virtual void specialAlignment_changed(); - virtual void width_changed(); - virtual void longTabular(); - virtual void ltNewpage_clicked(); - virtual void ltHeaderStatus_clicked(); - virtual void ltHeaderBorderAbove_clicked(); - virtual void ltHeaderBorderBelow_clicked(); - virtual void ltFirstHeaderStatus_clicked(); - virtual void ltFirstHeaderBorderAbove_clicked(); - virtual void ltFirstHeaderBorderBelow_clicked(); - virtual void ltFirstHeaderEmpty_clicked(); - virtual void ltFooterStatus_clicked(); - virtual void ltFooterBorderAbove_clicked(); - virtual void ltFooterBorderBelow_clicked(); - virtual void ltLastFooterStatus_clicked(); - virtual void ltLastFooterBorderAbove_clicked(); - virtual void ltLastFooterBorderBelow_clicked(); - virtual void ltLastFooterEmpty_clicked(); - -protected: - virtual void closeEvent(QCloseEvent * e); - -private: - GuiTabular * form_; -}; - -class GuiTabular : public GuiView -{ public: - friend class GuiTabularDialog; - - GuiTabular(GuiDialog &); - - /// parent controller - ControlTabular & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlTabular const & controller() const - { return static_cast(this->getController()); } -protected: - virtual bool isValid(); + GuiTabularDialog(LyXView & lv); + +private Q_SLOTS: + void change_adaptor(); + + void topspace_changed(); + void bottomspace_changed(); + void interlinespace_changed(); + void booktabsChanged(bool); + void close_clicked(); + void borderSet_clicked(); + void borderUnset_clicked(); + void leftBorder_changed(); + void rightBorder_changed(); + void topBorder_changed(); + void bottomBorder_changed(); + void multicolumn_clicked(); + void rotateTabular(); + void rotateCell(); + void hAlign_changed(int align); + void vAlign_changed(int align); + void specialAlignment_changed(); + void width_changed(); + void longTabular(); + void ltNewpage_clicked(); + void ltHeaderStatus_clicked(); + void ltHeaderBorderAbove_clicked(); + void ltHeaderBorderBelow_clicked(); + void ltFirstHeaderStatus_clicked(); + void ltFirstHeaderBorderAbove_clicked(); + void ltFirstHeaderBorderBelow_clicked(); + void ltFirstHeaderEmpty_clicked(); + void ltFooterStatus_clicked(); + void ltFooterBorderAbove_clicked(); + void ltFooterBorderBelow_clicked(); + void ltLastFooterStatus_clicked(); + void ltLastFooterBorderAbove_clicked(); + void ltLastFooterBorderBelow_clicked(); + void ltLastFooterEmpty_clicked(); private: - /// We can't use this ... - virtual void applyView() {} + /// + void closeEvent(QCloseEvent * e); + /// parent controller + ControlTabular & controller() const; + /// + bool isValid() { return true; } /// update borders - virtual void update_borders(); + void update_borders(); /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); + void update_contents(); /// save some values before closing the gui - virtual void closeGUI(); + void closeGUI(); }; } // namespace frontend diff --git a/src/frontends/qt4/GuiTabularCreate.cpp b/src/frontends/qt4/GuiTabularCreate.cpp index bde12658bd..c40c24fa95 100644 --- a/src/frontends/qt4/GuiTabularCreate.cpp +++ b/src/frontends/qt4/GuiTabularCreate.cpp @@ -11,77 +11,64 @@ #include #include "GuiTabularCreate.h" + +#include "ControlTabularCreate.h" #include "EmptyTable.h" #include #include #include + namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiTabularCreateDialog -// -///////////////////////////////////////////////////////////////////// - -GuiTabularCreateDialog::GuiTabularCreateDialog(GuiTabularCreate * form) - : form_(form) +GuiTabularCreateDialog::GuiTabularCreateDialog(LyXView & lv) + : GuiDialog(lv, "tabularcreate") { setupUi(this); + setViewTitle(_("Insert Table")); + setController(new ControlTabularCreate(*this)); rowsSB->setValue(5); columnsSB->setValue(5); - connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK())); - connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose())); + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(rowsSB, SIGNAL(valueChanged(int)), this, SLOT(rowsChanged(int))); connect(columnsSB, SIGNAL(valueChanged(int)), this, SLOT(columnsChanged(int))); -} - -void GuiTabularCreateDialog::columnsChanged(int) -{ - form_->changed(); + bc().setPolicy(ButtonPolicy::IgnorantPolicy); + bc().setOK(okPB); + bc().setCancel(closePB); } -void GuiTabularCreateDialog::rowsChanged(int) +ControlTabularCreate & GuiTabularCreateDialog::controller() const { - form_->changed(); + return static_cast(Dialog::controller()); } -///////////////////////////////////////////////////////////////////// -// -// GuiTabularCreate -// -///////////////////////////////////////////////////////////////////// - - -GuiTabularCreate::GuiTabularCreate(GuiDialog & parent) - : GuiView(parent, _("Insert Table")) +void GuiTabularCreateDialog::columnsChanged(int) { + changed(); } -void GuiTabularCreate::build_dialog() +void GuiTabularCreateDialog::rowsChanged(int) { - dialog_.reset(new GuiTabularCreateDialog(this)); - - bc().setOK(dialog_->okPB); - bc().setCancel(dialog_->closePB); + changed(); } -void GuiTabularCreate::applyView() +void GuiTabularCreateDialog::applyView() { - controller().params().first = dialog_->rowsSB->value(); - controller().params().second = dialog_->columnsSB->value(); + controller().params().first = rowsSB->value(); + controller().params().second = columnsSB->value(); } } // namespace frontend diff --git a/src/frontends/qt4/GuiTabularCreate.h b/src/frontends/qt4/GuiTabularCreate.h index d946f9f543..8387b43bef 100644 --- a/src/frontends/qt4/GuiTabularCreate.h +++ b/src/frontends/qt4/GuiTabularCreate.h @@ -12,50 +12,30 @@ #ifndef GUITABULARCREATE_H #define GUITABULARCREATE_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlTabularCreate.h" #include "ui_TabularCreateUi.h" -#include - namespace lyx { namespace frontend { -class GuiTabularCreate; - -class GuiTabularCreateDialog : public QDialog, public Ui::TabularCreateUi +class GuiTabularCreateDialog : public GuiDialog, public Ui::TabularCreateUi { Q_OBJECT + public: - GuiTabularCreateDialog(GuiTabularCreate * form); -protected Q_SLOTS: - virtual void columnsChanged(int); - virtual void rowsChanged(int); -private: - GuiTabularCreate * form_; -}; + GuiTabularCreateDialog(LyXView & lv); +private Q_SLOTS: + void columnsChanged(int); + void rowsChanged(int); -class GuiTabularCreate : public GuiView -{ -public: - /// - friend class GuiTabularCreateDialog; - /// - GuiTabularCreate(GuiDialog &); /// parent controller - ControlTabularCreate & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlTabularCreate const & controller() const - { return static_cast(this->getController()); } + ControlTabularCreate & controller() const; + private: /// Apply changes - virtual void applyView(); - /// update - virtual void update_contents() {} - /// build the dialog - virtual void build_dialog(); + void applyView(); }; } // namespace frontend diff --git a/src/frontends/qt4/GuiTexinfo.cpp b/src/frontends/qt4/GuiTexinfo.cpp index 8fe2a443b5..21decc7ce2 100644 --- a/src/frontends/qt4/GuiTexinfo.cpp +++ b/src/frontends/qt4/GuiTexinfo.cpp @@ -11,6 +11,8 @@ #include #include "GuiTexinfo.h" + +#include "ControlTexinfo.h" #include "qt_helpers.h" #include "support/filetools.h" @@ -23,22 +25,21 @@ using std::string; using std::vector; + namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiTexinfoDialog -// -///////////////////////////////////////////////////////////////////// - - -GuiTexinfoDialog::GuiTexinfoDialog(GuiTexinfo * form) - : form_(form) +GuiTexinfoDialog::GuiTexinfoDialog(LyXView & lv) + : GuiDialog(lv, "texinfo") { setupUi(this); + setViewTitle(_("TeX Information")); + setController(new ControlTexinfo(*this)); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + warningPosted = false; + activeStyle = ControlTexinfo::cls; + + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(viewPB, SIGNAL(clicked()), this, SLOT(viewClicked())); connect(whatStyleCO, SIGNAL(activated(const QString &)), @@ -48,21 +49,32 @@ GuiTexinfoDialog::GuiTexinfoDialog(GuiTexinfo * form) connect(rescanPB, SIGNAL(clicked()), this, SLOT(enableViewPB())); connect(rescanPB, SIGNAL(clicked()), this, SLOT(rescanClicked())); connect(fileListLW, SIGNAL(itemClicked(QListWidgetItem *)), - this, SLOT( enableViewPB() ) ); + this, SLOT(enableViewPB())); connect(fileListLW, SIGNAL(itemSelectionChanged()), this, SLOT(enableViewPB())); + + updateStyles(ControlTexinfo::cls); + + bc().setPolicy(ButtonPolicy::OkCancelPolicy); + bc().setCancel(closePB); +} + + +ControlTexinfo & GuiTexinfoDialog::controller() const +{ + return static_cast(Dialog::controller()); } void GuiTexinfoDialog::change_adaptor() { - form_->changed(); + changed(); } void GuiTexinfoDialog::closeEvent(QCloseEvent * e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } @@ -71,7 +83,7 @@ void GuiTexinfoDialog::rescanClicked() { // build new *Files.lst rescanTexStyles(); - form_->updateStyles(); + updateStyles(); enableViewPB(); } @@ -79,29 +91,29 @@ void GuiTexinfoDialog::rescanClicked() void GuiTexinfoDialog::viewClicked() { size_t const fitem = fileListLW->currentRow(); - vector const & data = form_->texdata_[form_->activeStyle]; + vector const & data = texdata_[activeStyle]; string file = data[fitem]; if (!pathCB->isChecked()) file = getTexFileFromList(data[fitem], - form_->controller().getFileType(form_->activeStyle)); - form_->controller().viewFile(file); + controller().getFileType(activeStyle)); + controller().viewFile(file); } void GuiTexinfoDialog::updateView() { switch (whatStyleCO->currentIndex()) { - case 0: - form_->updateStyles(ControlTexinfo::cls); - break; - case 1: - form_->updateStyles(ControlTexinfo::sty); - break; - case 2: - form_->updateStyles(ControlTexinfo::bst); - break; - default: - break; + case 0: + updateStyles(ControlTexinfo::cls); + break; + case 1: + updateStyles(ControlTexinfo::sty); + break; + case 2: + updateStyles(ControlTexinfo::bst); + break; + default: + break; } enableViewPB(); @@ -114,48 +126,24 @@ void GuiTexinfoDialog::enableViewPB() } -///////////////////////////////////////////////////////////////////// -// -// GuiTexinfo -// -///////////////////////////////////////////////////////////////////// - - -GuiTexinfo::GuiTexinfo(GuiDialog & parent) - : GuiView(parent, _("TeX Information")), - warningPosted(false), activeStyle(ControlTexinfo::cls) -{ -} - - -void GuiTexinfo::build_dialog() -{ - dialog_.reset(new GuiTexinfoDialog(this)); - - updateStyles(ControlTexinfo::cls); - - bc().setCancel(dialog_->closePB); -} - - -void GuiTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle) +void GuiTexinfoDialog::updateStyles(ControlTexinfo::texFileSuffix whichStyle) { ContentsType & data = texdata_[whichStyle]; - bool const withFullPath = dialog_->pathCB->isChecked(); + bool const withFullPath = pathCB->isChecked(); getTexFileList(whichStyle, data, withFullPath); - dialog_->fileListLW->clear(); + fileListLW->clear(); ContentsType::const_iterator it = data.begin(); ContentsType::const_iterator end = data.end(); for (; it != end; ++it) - dialog_->fileListLW->addItem(toqstr(*it)); + fileListLW->addItem(toqstr(*it)); activeStyle = whichStyle; } -void GuiTexinfo::updateStyles() +void GuiTexinfoDialog::updateStyles() { updateStyles(activeStyle); } diff --git a/src/frontends/qt4/GuiTexinfo.h b/src/frontends/qt4/GuiTexinfo.h index 08e46ee9fe..34de13dab0 100644 --- a/src/frontends/qt4/GuiTexinfo.h +++ b/src/frontends/qt4/GuiTexinfo.h @@ -9,63 +9,40 @@ * Full author contact details are available in file CREDITS. */ -#ifndef QTEXINFO_H -#define QTEXINFO_H +#ifndef GUITEXINFO_H +#define GUITEXINFO_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlTexinfo.h" #include "ui_TexinfoUi.h" -#include - #include #include namespace lyx { namespace frontend { -class GuiTexinfo; - -class GuiTexinfoDialog : public QDialog, public Ui::TexinfoUi +class GuiTexinfoDialog : public GuiDialog, public Ui::TexinfoUi { Q_OBJECT + public: - GuiTexinfoDialog(GuiTexinfo * form); + GuiTexinfoDialog(LyXView & lv); + public Q_SLOTS: - virtual void updateView(); -protected Q_SLOTS: - virtual void change_adaptor(); - virtual void rescanClicked(); - virtual void viewClicked(); - virtual void enableViewPB(); -protected: - virtual void closeEvent(QCloseEvent * e); -private: - GuiTexinfo * form_; -}; + void updateView(); +private Q_SLOTS: + void change_adaptor(); + void rescanClicked(); + void viewClicked(); + void enableViewPB(); -/// -class GuiTexinfo : public GuiView -{ -public: +private: /// - friend class GuiTexinfoDialog; + void closeEvent(QCloseEvent * e); /// - GuiTexinfo(GuiDialog &); - /// parent controller - ControlTexinfo & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlTexinfo const & controller() const - { return static_cast(this->getController()); } -private: - /// Apply changes - virtual void applyView() {} - /// update (do we need this?) - virtual void update_contents() {} - /// build the dialog - virtual void build_dialog(); + ControlTexinfo & controller() const; /// void updateStyles(ControlTexinfo::texFileSuffix); /// @@ -82,4 +59,4 @@ private: } // namespace frontend } // namespace lyx -#endif // QTEXINFO_H +#endif // GUITEXINFO_H diff --git a/src/frontends/qt4/GuiThesaurus.cpp b/src/frontends/qt4/GuiThesaurus.cpp index 6d1490ca47..8db27077dd 100644 --- a/src/frontends/qt4/GuiThesaurus.cpp +++ b/src/frontends/qt4/GuiThesaurus.cpp @@ -11,6 +11,8 @@ #include #include "GuiThesaurus.h" + +#include "ControlThesaurus.h" #include "qt_helpers.h" #include "debug.h" @@ -23,25 +25,22 @@ using std::string; + namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// QTheasurusDialog -// -///////////////////////////////////////////////////////////////////// - -GuiThesaurusDialog::GuiThesaurusDialog(GuiThesaurus * form) - : form_(form) +GuiThesaurusDialog::GuiThesaurusDialog(LyXView & lv) + : GuiDialog(lv, "thesaurus") { setupUi(this); + setViewTitle(_("Thesaurus")); + setController(new ControlThesaurus(*this)); meaningsTV->setColumnCount(1); meaningsTV->header()->hide(); connect(closePB, SIGNAL(clicked()), - form, SLOT(slotClose())); + this, SLOT(slotClose())); connect(replaceED, SIGNAL(returnPressed()), this, SLOT(replaceClicked())); connect(replaceED, SIGNAL(textChanged(const QString &)), @@ -56,18 +55,29 @@ GuiThesaurusDialog::GuiThesaurusDialog(GuiThesaurus * form) this, SLOT(selectionChanged())); connect(meaningsTV, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this, SLOT(selectionClicked(QTreeWidgetItem *, int))); + + bc().setCancel(closePB); + bc().setApply(replacePB); + bc().addReadOnly(replaceED); + bc().addReadOnly(replacePB); + bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); } +ControlThesaurus & GuiThesaurusDialog::controller() const +{ + return static_cast(Dialog::controller()); +} + void GuiThesaurusDialog::change_adaptor() { - form_->changed(); + changed(); } void GuiThesaurusDialog::closeEvent(QCloseEvent * e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } @@ -78,21 +88,15 @@ void GuiThesaurusDialog::entryChanged() } -void GuiThesaurusDialog::replaceClicked() -{ - form_->replace(); -} - - void GuiThesaurusDialog::selectionChanged() { int const col = meaningsTV->currentColumn(); - if (col<0 || form_->readOnly()) + if (col<0 || readOnly()) return; replaceED->setText(meaningsTV->currentItem()->text(col)); replacePB->setEnabled(true); - form_->changed(); + changed(); } @@ -115,7 +119,7 @@ void GuiThesaurusDialog::updateLists() meaningsTV->clear(); meaningsTV->setUpdatesEnabled(false); - Thesaurus::Meanings meanings = form_->controller().getMeanings(qstring_to_ucs4(entryED->text())); + Thesaurus::Meanings meanings = controller().getMeanings(qstring_to_ucs4(entryED->text())); for (Thesaurus::Meanings::const_iterator cit = meanings.begin(); cit != meanings.end(); ++cit) { @@ -134,40 +138,17 @@ void GuiThesaurusDialog::updateLists() } -///////////////////////////////////////////////////////////////////// -// -// GuiThesaurus -// -///////////////////////////////////////////////////////////////////// - -GuiThesaurus::GuiThesaurus(GuiDialog & parent) - : GuiView(parent, _("Thesaurus")) -{ -} - - -void GuiThesaurus::build_dialog() -{ - dialog_.reset(new GuiThesaurusDialog(this)); - - bc().setCancel(dialog_->closePB); - bc().setApply(dialog_->replacePB); - bc().addReadOnly(dialog_->replaceED); - bc().addReadOnly(dialog_->replacePB); -} - - -void GuiThesaurus::update_contents() +void GuiThesaurusDialog::update_contents() { - dialog_->entryED->setText(toqstr(controller().text())); - dialog_->replaceED->setText(""); - dialog_->updateLists(); + entryED->setText(toqstr(controller().text())); + replaceED->setText(""); + updateLists(); } -void GuiThesaurus::replace() +void GuiThesaurusDialog::replaceClicked() { - controller().replace(qstring_to_ucs4(dialog_->replaceED->text())); + controller().replace(qstring_to_ucs4(replaceED->text())); } } // namespace frontend diff --git a/src/frontends/qt4/GuiThesaurus.h b/src/frontends/qt4/GuiThesaurus.h index 48bbce8bcf..e21bab5a2a 100644 --- a/src/frontends/qt4/GuiThesaurus.h +++ b/src/frontends/qt4/GuiThesaurus.h @@ -12,67 +12,38 @@ #ifndef GUITHESAURUS_H #define GUITHESAURUS_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlThesaurus.h" #include "ui_ThesaurusUi.h" -#include - - class QTreeWidgetItem; namespace lyx { namespace frontend { -class ControlThesaurus; - -class GuiThesaurus; - -class GuiThesaurusDialog : public QDialog, public Ui::ThesaurusUi +class GuiThesaurusDialog : public GuiDialog, public Ui::ThesaurusUi { Q_OBJECT -public: - GuiThesaurusDialog(GuiThesaurus * form); - void updateLists(); -protected Q_SLOTS: - virtual void change_adaptor(); - virtual void entryChanged(); - virtual void replaceClicked(); - virtual void selectionChanged(); - virtual void selectionClicked(QTreeWidgetItem *, int); - virtual void itemClicked(QTreeWidgetItem *, int); -protected: - virtual void closeEvent(QCloseEvent * e); -private: - GuiThesaurus * form_; -}; +public: + GuiThesaurusDialog(LyXView & lv); +private Q_SLOTS: + void change_adaptor(); + void entryChanged(); + void replaceClicked(); + void selectionChanged(); + void selectionClicked(QTreeWidgetItem *, int); + void itemClicked(QTreeWidgetItem *, int); -/// -class GuiThesaurus : public GuiView -{ -public: - /// - friend class GuiThesaurusDialog; - /// - GuiThesaurus(GuiDialog &); - /// parent controller - ControlThesaurus & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlThesaurus const & controller() const - { return static_cast(this->getController()); } private: - /// Apply changes - virtual void applyView() {} + void closeEvent(QCloseEvent * e); + /// parent controller + ControlThesaurus & controller() const; /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); - - /// replace the word - void replace(); + void update_contents(); + /// + void updateLists(); }; } // namespace frontend diff --git a/src/frontends/qt4/GuiToc.cpp b/src/frontends/qt4/GuiToc.cpp index 3f524f91d4..8715d1bcad 100644 --- a/src/frontends/qt4/GuiToc.cpp +++ b/src/frontends/qt4/GuiToc.cpp @@ -32,9 +32,26 @@ namespace lyx { namespace frontend { -GuiToc::GuiToc(Dialog & dialog, QObject * parent) - : QObject(parent), ControlToc(dialog) +GuiToc::GuiToc(LyXView & lv) + : GuiDialog(lv, "toc") { + setViewTitle(_("Outline")); + setController(new ControlToc(*this)); +#ifdef Q_WS_MACX + // On Mac show as a drawer at the right + //setView(new DockView( + // *dialog, qtoc, &gui_view, _("Outline"), Qt::RightDockWidgetArea, Qt::Drawer)); +#else + //setView(new DockView( +// *dialog, qtoc, &gui_view, _("Outline"))); +#endif + bc().setPolicy(ButtonPolicy::OkCancelPolicy); +} + + +ControlToc & GuiToc::controller() const +{ + return static_cast(Dialog::controller()); } @@ -43,7 +60,7 @@ bool GuiToc::canOutline(int type) const if (type < 0) return false; - return ControlToc::canOutline(type); + return controller().canOutline(type); } @@ -86,7 +103,7 @@ QModelIndex const GuiToc::getCurrentIndex(int type) const if(!canOutline(type)) return QModelIndex(); - return toc_models_[type]->modelIndex(getCurrentTocItem(type)); + return toc_models_[type]->modelIndex(controller().getCurrentTocItem(type)); } @@ -106,13 +123,13 @@ void GuiToc::goTo(int type, QModelIndex const & index) LYXERR(Debug::GUI) << "GuiToc::goTo " << to_utf8(it->str()) << endl; - ControlToc::goTo(*it); + controller().goTo(*it); } bool GuiToc::initialiseParams(std::string const & data) { - if (!ControlToc::initialiseParams(data)) + if (!controller().initialiseParams(data)) return false; updateView(); modelReset(); @@ -123,8 +140,8 @@ bool GuiToc::initialiseParams(std::string const & data) void GuiToc::updateView() { toc_models_.clear(); - TocList::const_iterator it = tocs().begin(); - TocList::const_iterator end = tocs().end(); + TocList::const_iterator it = controller().tocs().begin(); + TocList::const_iterator end = controller().tocs().end(); for (; it != end; ++it) toc_models_.push_back(new TocModel(it->second)); } diff --git a/src/frontends/qt4/GuiToc.h b/src/frontends/qt4/GuiToc.h index 0b2dbe54bd..027910e574 100644 --- a/src/frontends/qt4/GuiToc.h +++ b/src/frontends/qt4/GuiToc.h @@ -14,6 +14,7 @@ #ifndef GUITOC_H #define GUITOC_H +#include "GuiDialog.h" #include "ControlToc.h" #include @@ -23,16 +24,15 @@ namespace lyx { namespace frontend { -class ControlToc; class TocModel; -class GuiToc : public QObject, public ControlToc +class GuiToc : public GuiDialog { Q_OBJECT -public: - GuiToc(Dialog &, QObject * parent = 0); - virtual ~GuiToc() {} +public: + /// + GuiToc(LyXView & lv); /// \c ControlToc inherited method. virtual bool initialiseParams(std::string const & data); @@ -51,6 +51,8 @@ public: /// int getTocDepth(int type); + ControlToc & controller() const; + Q_SIGNALS: /// Signal that the internal toc_models_ has been reset. void modelReset(); diff --git a/src/frontends/qt4/GuiToolbar.h b/src/frontends/qt4/GuiToolbar.h index 22fa093014..0d903a8065 100644 --- a/src/frontends/qt4/GuiToolbar.h +++ b/src/frontends/qt4/GuiToolbar.h @@ -39,7 +39,8 @@ class GuiViewBase; class Action; -class GuiLayoutBox : public QObject, public LayoutBox { +class GuiLayoutBox : public QObject, public LayoutBox +{ Q_OBJECT public: GuiLayoutBox(QToolBar *, GuiViewBase &); @@ -64,7 +65,8 @@ private: }; -class GuiToolbar : public QToolBar, public Toolbar { +class GuiToolbar : public QToolBar, public Toolbar +{ Q_OBJECT public: GuiToolbar(ToolbarInfo const &, GuiViewBase &); diff --git a/src/frontends/qt4/GuiURL.cpp b/src/frontends/qt4/GuiURL.cpp index 5351f0fb65..204e1e83c1 100644 --- a/src/frontends/qt4/GuiURL.cpp +++ b/src/frontends/qt4/GuiURL.cpp @@ -11,6 +11,8 @@ #include #include "GuiURL.h" + +#include "ControlCommand.h" #include "qt_helpers.h" #include @@ -22,13 +24,15 @@ namespace lyx { namespace frontend { -GuiURLDialog::GuiURLDialog(UrlView * form) - : form_(form) +GuiURLDialog::GuiURLDialog(LyXView & lv) + : GuiDialog(lv, "url") { setupUi(this); + setViewTitle( _("URL")); + setController(new ControlCommand(*this, "url", "url")); - connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK())); - connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose())); + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(urlED, SIGNAL(textChanged(const QString &)), this, SLOT(changed_adaptor())); connect(hyperlinkCB, SIGNAL(clicked()), @@ -37,71 +41,66 @@ GuiURLDialog::GuiURLDialog(UrlView * form) this, SLOT(changed_adaptor())); setFocusProxy(urlED); -} - -void GuiURLDialog::changed_adaptor() -{ - form_->changed(); + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + bc().setOK(okPB); + bc().setCancel(closePB); + bc().addReadOnly(urlED); + bc().addReadOnly(nameED); + bc().addReadOnly(hyperlinkCB); } -void GuiURLDialog::closeEvent(QCloseEvent * e) +ControlCommand & GuiURLDialog::controller() const { - form_->slotWMHide(); - e->accept(); + return static_cast(Dialog::controller()); } - -UrlView::UrlView(GuiDialog & parent) - : GuiView(parent, _("URL")) +void GuiURLDialog::changed_adaptor() { + changed(); } -void UrlView::build_dialog() +void GuiURLDialog::closeEvent(QCloseEvent * e) { - dialog_.reset(new GuiURLDialog(this)); - - bc().setOK(dialog_->okPB); - bc().setCancel(dialog_->closePB); - bc().addReadOnly(dialog_->urlED); - bc().addReadOnly(dialog_->nameED); - bc().addReadOnly(dialog_->hyperlinkCB); + slotWMHide(); + e->accept(); } -void UrlView::update_contents() + +void GuiURLDialog::update_contents() { InsetCommandParams const & params = controller().params(); - dialog_->urlED->setText(toqstr(params["target"])); - dialog_->nameED->setText(toqstr(params["name"])); - dialog_->hyperlinkCB->setChecked(params.getCmdName() != "url"); + urlED->setText(toqstr(params["target"])); + nameED->setText(toqstr(params["name"])); + hyperlinkCB->setChecked(params.getCmdName() != "url"); bc().setValid(isValid()); } -void UrlView::applyView() +void GuiURLDialog::applyView() { InsetCommandParams & params = controller().params(); - params["target"] = qstring_to_ucs4(dialog_->urlED->text()); - params["name"] = qstring_to_ucs4(dialog_->nameED->text()); + params["target"] = qstring_to_ucs4(urlED->text()); + params["name"] = qstring_to_ucs4(nameED->text()); - if (dialog_->hyperlinkCB->isChecked()) + if (hyperlinkCB->isChecked()) params.setCmdName("htmlurl"); else params.setCmdName("url"); } -bool UrlView::isValid() +bool GuiURLDialog::isValid() { - QString const u = dialog_->urlED->text(); - QString const n = dialog_->nameED->text(); + QString const u = urlED->text(); + QString const n = nameED->text(); return !u.isEmpty() || !n.isEmpty(); } diff --git a/src/frontends/qt4/GuiURL.h b/src/frontends/qt4/GuiURL.h index 042a1c6630..c9159dbfac 100644 --- a/src/frontends/qt4/GuiURL.h +++ b/src/frontends/qt4/GuiURL.h @@ -12,51 +12,33 @@ #ifndef GUIURLDIALOG_H #define GUIURLDIALOG_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlCommand.h" #include "ui_URLUi.h" -#include - namespace lyx { namespace frontend { -class UrlView; - -class GuiURLDialog : public QDialog, public Ui::URLUi +class GuiURLDialog : public GuiDialog, public Ui::URLUi { Q_OBJECT + public: - GuiURLDialog(UrlView * form); + GuiURLDialog(LyXView & lv); + public Q_SLOTS: void changed_adaptor(); -protected: - void closeEvent(QCloseEvent *); -private: - UrlView * form_; -}; - -class UrlView : public GuiView -{ -public: - friend class QURLDialog; - UrlView(GuiDialog &); - /// parent controller - ControlCommand & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlCommand const & controller() const - { return static_cast(this->getController()); } -protected: - virtual bool isValid(); private: + void closeEvent(QCloseEvent *); + /// parent controller + ControlCommand & controller() const; + /// + bool isValid(); /// apply dialog - virtual void applyView(); - /// build dialog - virtual void build_dialog(); + void applyView(); /// update dialog - virtual void update_contents(); + void update_contents(); }; } // namespace frontend diff --git a/src/frontends/qt4/GuiVSpace.cpp b/src/frontends/qt4/GuiVSpace.cpp index 568fc50709..ebbb347de4 100644 --- a/src/frontends/qt4/GuiVSpace.cpp +++ b/src/frontends/qt4/GuiVSpace.cpp @@ -17,6 +17,7 @@ #include "GuiVSpace.h" +#include "ControlVSpace.h" #include "LengthCombo.h" #include "qt_helpers.h" #include "Validator.h" @@ -36,28 +37,22 @@ #include #include - using std::string; + namespace lyx { namespace frontend { - -///////////////////////////////////////////////////////////////////// -// -// GuiVSpaceDialog -// -///////////////////////////////////////////////////////////////////// - - -GuiVSpaceDialog::GuiVSpaceDialog(GuiVSpace * form) - : form_(form) +GuiVSpaceDialog::GuiVSpaceDialog(LyXView & lv) + : GuiDialog(lv, "vspace") { setupUi(this); + setViewTitle(_("Vertical Space Settings")); + setController(new ControlVSpace(*this)); - connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose())); + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(spacingCO, SIGNAL(highlighted(const QString &)), this, SLOT(change_adaptor())); @@ -71,19 +66,43 @@ GuiVSpaceDialog::GuiVSpaceDialog(GuiVSpace * form) this, SLOT(change_adaptor())); valueLE->setValidator(unsignedLengthValidator(valueLE)); + + // Manage the ok, apply, restore and cancel/close buttons + bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); + bc().setOK(okPB); + bc().setApply(applyPB); + bc().setCancel(closePB); + + // disable for read-only documents + bc().addReadOnly(spacingCO); + bc().addReadOnly(valueLE); + bc().addReadOnly(unitCO); + bc().addReadOnly(keepCB); + + // initialize the length validator + bc().addCheckedLineEdit(valueLE, valueL); + + // remove the %-items from the unit choice + unitCO->noPercents(); +} + + +ControlVSpace & GuiVSpaceDialog::controller() const +{ + return static_cast(Dialog::controller()); } void GuiVSpaceDialog::closeEvent(QCloseEvent * e) { - form_->slotWMHide(); + slotWMHide(); e->accept(); } void GuiVSpaceDialog::change_adaptor() { - form_->changed(); + changed(); } @@ -95,12 +114,6 @@ void GuiVSpaceDialog::enableCustom(int selection) } -///////////////////////////////////////////////////////////////////// -// -// GuiVSpace -// -///////////////////////////////////////////////////////////////////// - static void setWidgetsFromVSpace(VSpace const & space, QComboBox * spacing, QLineEdit * value, @@ -109,24 +122,12 @@ static void setWidgetsFromVSpace(VSpace const & space, { int item = 0; switch (space.kind()) { - case VSpace::DEFSKIP: - item = 0; - break; - case VSpace::SMALLSKIP: - item = 1; - break; - case VSpace::MEDSKIP: - item = 2; - break; - case VSpace::BIGSKIP: - item = 3; - break; - case VSpace::VFILL: - item = 4; - break; - case VSpace::LENGTH: - item = 5; - break; + case VSpace::DEFSKIP: item = 0; break; + case VSpace::SMALLSKIP: item = 1; break; + case VSpace::MEDSKIP: item = 2; break; + case VSpace::BIGSKIP: item = 3; break; + case VSpace::VFILL: item = 4; break; + case VSpace::LENGTH: item = 5; break; } spacing->setCurrentIndex(item); keep->setChecked(space.keep()); @@ -148,31 +149,17 @@ static void setWidgetsFromVSpace(VSpace const & space, static VSpace setVSpaceFromWidgets(int spacing, - QLineEdit * value, - LengthCombo * unit, - bool keep) + QLineEdit * value, LengthCombo * unit, bool keep) { VSpace space; switch (spacing) { - case 0: - space = VSpace(VSpace::DEFSKIP); - break; - case 1: - space = VSpace(VSpace::SMALLSKIP); - break; - case 2: - space = VSpace(VSpace::MEDSKIP); - break; - case 3: - space = VSpace(VSpace::BIGSKIP); - break; - case 4: - space = VSpace(VSpace::VFILL); - break; - case 5: - space = VSpace(GlueLength(widgetsToLength(value, unit))); - break; + case 0: space = VSpace(VSpace::DEFSKIP); break; + case 1: space = VSpace(VSpace::SMALLSKIP); break; + case 2: space = VSpace(VSpace::MEDSKIP); break; + case 3: space = VSpace(VSpace::BIGSKIP); break; + case 4: space = VSpace(VSpace::VFILL); break; + case 5: space = VSpace(GlueLength(widgetsToLength(value, unit))); break; } space.setKeep(keep); @@ -180,61 +167,24 @@ static VSpace setVSpaceFromWidgets(int spacing, } -GuiVSpace::GuiVSpace(GuiDialog & parent) - : GuiView(parent, _("Vertical Space Settings")) -{} - - -void GuiVSpace::build_dialog() -{ - // the tabbed folder - dialog_.reset(new GuiVSpaceDialog(this)); - - // Manage the ok, apply, restore and cancel/close buttons - bc().setOK(dialog_->okPB); - bc().setApply(dialog_->applyPB); - bc().setCancel(dialog_->closePB); - - // disable for read-only documents - bc().addReadOnly(dialog_->spacingCO); - bc().addReadOnly(dialog_->valueLE); - bc().addReadOnly(dialog_->unitCO); - bc().addReadOnly(dialog_->keepCB); - - // initialize the length validator - bc().addCheckedLineEdit(dialog_->valueLE, dialog_->valueL); - - // remove the %-items from the unit choice - dialog_->unitCO->noPercents(); -} - - -void GuiVSpace::applyView() +void GuiVSpaceDialog::applyView() { - // spacing // If a vspace choice is "Length" but there's no text in // the input field, do not insert a vspace at all. - if (dialog_->spacingCO->currentIndex() == 5 - && dialog_->valueLE->text().isEmpty()) + if (spacingCO->currentIndex() == 5 && valueLE->text().isEmpty()) return; - VSpace const space = - setVSpaceFromWidgets(dialog_->spacingCO->currentIndex(), - dialog_->valueLE, - dialog_->unitCO, - dialog_->keepCB->isChecked()); + VSpace const space = setVSpaceFromWidgets(spacingCO->currentIndex(), + valueLE, unitCO, keepCB->isChecked()); controller().params() = space; } -void GuiVSpace::update_contents() +void GuiVSpaceDialog::update_contents() { setWidgetsFromVSpace(controller().params(), - dialog_->spacingCO, - dialog_->valueLE, - dialog_->unitCO, - dialog_->keepCB); + spacingCO, valueLE, unitCO, keepCB); } } // namespace frontend diff --git a/src/frontends/qt4/GuiVSpace.h b/src/frontends/qt4/GuiVSpace.h index 163ee1eb78..12c2978b82 100644 --- a/src/frontends/qt4/GuiVSpace.h +++ b/src/frontends/qt4/GuiVSpace.h @@ -11,62 +11,38 @@ * Full author contact details are available in file CREDITS. */ -#ifndef QVSPACE_H -#define QVSPACE_H +#ifndef GUIVSPACE_H +#define GUIVSPACE_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlVSpace.h" #include "ui_VSpaceUi.h" -#include - namespace lyx { namespace frontend { -class GuiVSpace; - -class GuiVSpaceDialog : public QDialog, public Ui::VSpaceUi +class GuiVSpaceDialog : public GuiDialog, public Ui::VSpaceUi { Q_OBJECT public: - GuiVSpaceDialog(GuiVSpace * form); + GuiVSpaceDialog(LyXView & lv); -public Q_SLOTS: +private Q_SLOTS: void change_adaptor(); - -protected Q_SLOTS: void closeEvent(QCloseEvent *); void enableCustom(int); private: - GuiVSpace * form_; -}; - - -class GuiVSpace : public GuiView -{ -public: - /// - friend class GuiVSpaceDialog; - /// - GuiVSpace(GuiDialog &); /// parent controller - ControlVSpace & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlVSpace const & controller() const - { return static_cast(this->getController()); } -private: - /// Build the dialog - virtual void build_dialog(); + ControlVSpace & controller() const; /// Apply from dialog - virtual void applyView(); + void applyView(); /// Update the dialog - virtual void update_contents(); + void update_contents(); }; } // namespace frontend } // namespace lyx -#endif //QVSPACE_H +#endif // GUIVSPACE_H diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 98e499ce5f..428f9325f1 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -28,11 +28,10 @@ class QDropEvent; class QMenu; class QToolBar; - namespace lyx { namespace frontend { -QWidget* mainWindow(); +QWidget * mainWindow(); /** * GuiView - Qt4 implementation of LyXView @@ -43,7 +42,8 @@ QWidget* mainWindow(); * is deleted. This might be useful for closing other dialogs * depending on a given GuiView. */ -class GuiViewBase : public QMainWindow, public LyXView { +class GuiViewBase : public QMainWindow, public LyXView +{ Q_OBJECT public: /// create a main window of the given dimensions @@ -98,10 +98,8 @@ public Q_SLOTS: protected: /// make sure we quit cleanly virtual void closeEvent(QCloseEvent * e); - /// virtual void resizeEvent(QResizeEvent * e); - /// virtual void moveEvent(QMoveEvent * e); diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp index 0a6d13544f..8b67fe23d1 100644 --- a/src/frontends/qt4/GuiViewSource.cpp +++ b/src/frontends/qt4/GuiViewSource.cpp @@ -20,19 +20,20 @@ #include #include + namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiViewSourceDialog -// -///////////////////////////////////////////////////////////////////// - -GuiViewSourceDialog::GuiViewSourceDialog(GuiViewSource * form) - : form_(form) +GuiViewSourceDialog::GuiViewSourceDialog(LyXView & lv) + : GuiDialog(lv, "view-source"), + document_(new QTextDocument(this)), + highlighter_(new LaTeXHighlighter(document_)) { setupUi(this); + setController(new ControlViewSource(*this)); + + // GuiViewBase & gui_view = static_cast(lyxview_); + // *dialog, qvs, &gui_view, _("LaTeX Source"), Qt::BottomDockWidgetArea)); connect(viewFullSourceCB, SIGNAL(clicked()), this, SLOT(update())); @@ -43,9 +44,9 @@ GuiViewSourceDialog::GuiViewSourceDialog(GuiViewSource * form) // setting a document at this point trigger an assertion in Qt // so we disable the signals here: - form_->document()->blockSignals(true); - viewSourceTV->setDocument(form_->document()); - form_->document()->blockSignals(false); + document()->blockSignals(true); + viewSourceTV->setDocument(document()); + document()->blockSignals(false); viewSourceTV->setReadOnly(true); ///dialog_->viewSourceTV->setAcceptRichText(false); // this is personal. I think source code should be in fixed-size font @@ -56,16 +57,24 @@ GuiViewSourceDialog::GuiViewSourceDialog(GuiViewSource * form) viewSourceTV->setFont(font); // again, personal taste viewSourceTV->setWordWrapMode(QTextOption::NoWrap); + + bc().setPolicy(ButtonPolicy::OkCancelPolicy); +} + + +ControlViewSource & GuiViewSourceDialog::controller() const +{ + return static_cast(Dialog::controller()); } void GuiViewSourceDialog::updateView() { if (autoUpdateCB->isChecked()) - form_->update(viewFullSourceCB->isChecked()); + update(viewFullSourceCB->isChecked()); int beg, end; - boost::tie(beg, end) = form_->getRows(); + boost::tie(beg, end) = controller().getRows(); QTextCursor c = QTextCursor(viewSourceTV->document()); c.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor, beg); c.select(QTextCursor::BlockUnderCursor); @@ -75,6 +84,13 @@ void GuiViewSourceDialog::updateView() } +void GuiViewSourceDialog::update(bool full_source) +{ + document_->setPlainText(toqstr(controller().updateContent(full_source))); +} + + + ///////////////////////////////////////////////////////////////////// // // LaTeXHighlighter @@ -160,26 +176,6 @@ void LaTeXHighlighter::highlightBlock(QString const & text) } -GuiViewSource::GuiViewSource(GuiDialog & parent) - : ControlViewSource(parent) -{ - document_ = new QTextDocument(this); - highlighter_ = new LaTeXHighlighter(document_); -} - - -///////////////////////////////////////////////////////////////////// -// -// GuiViewSource -// -///////////////////////////////////////////////////////////////////// - -void GuiViewSource::update(bool full_source) -{ - document_->setPlainText(toqstr(updateContent(full_source))); -} - - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiViewSource.h b/src/frontends/qt4/GuiViewSource.h index a1fe2ff826..404020b183 100644 --- a/src/frontends/qt4/GuiViewSource.h +++ b/src/frontends/qt4/GuiViewSource.h @@ -14,8 +14,8 @@ #ifndef GUIVIEWSOURCE_H #define GUIVIEWSOURCE_H -#include "ControlViewSource.h" #include "GuiDialog.h" +#include "ControlViewSource.h" #include "Application.h" #include "ui_ViewSourceUi.h" @@ -44,33 +44,24 @@ private: }; -class GuiViewSource; - -class GuiViewSourceDialog : public QWidget, public Ui::ViewSourceUi { +class GuiViewSourceDialog : public GuiDialog, public Ui::ViewSourceUi +{ Q_OBJECT + public: - GuiViewSourceDialog(GuiViewSource * form); + GuiViewSourceDialog(LyXView & lv); public Q_SLOTS: // update content void updateView(); - -private: - GuiViewSource * form_; -}; - - -/// -class GuiViewSource : public QObject, public ControlViewSource { -public: - /// - GuiViewSource(GuiDialog &); /// QTextDocument * document() { return document_; } /// void update(bool full_source); private: + /// + ControlViewSource & controller() const; /// QTextDocument * document_; /// LaTeX syntax highlighter diff --git a/src/frontends/qt4/GuiWrap.cpp b/src/frontends/qt4/GuiWrap.cpp index 313be7f093..943c7c5aac 100644 --- a/src/frontends/qt4/GuiWrap.cpp +++ b/src/frontends/qt4/GuiWrap.cpp @@ -12,6 +12,7 @@ #include "GuiWrap.h" +#include "ControlWrap.h" #include "LengthCombo.h" #include "qt_helpers.h" @@ -24,28 +25,23 @@ #include #include - using std::string; + namespace lyx { namespace frontend { -///////////////////////////////////////////////////////////////////// -// -// GuiWrapDialog -// -///////////////////////////////////////////////////////////////////// - - -GuiWrapDialog::GuiWrapDialog(GuiWrap * form) - : form_(form) +GuiWrapDialog::GuiWrapDialog(LyXView & lv) + : GuiDialog(lv, "wrap") { setupUi(this); + setViewTitle(_("Text Wrap Settings")); + setController(new ControlWrap(*this)); - connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore())); - connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore())); + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(widthED, SIGNAL(textChanged(const QString &)), this, SLOT(change_adaptor())); @@ -53,60 +49,50 @@ GuiWrapDialog::GuiWrapDialog(GuiWrap * form) this, SLOT(change_adaptor())); connect(valignCO, SIGNAL(highlighted(const QString &)), this, SLOT(change_adaptor())); -} + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + bc().setRestore(restorePB); + bc().setOK(okPB); + bc().setApply(applyPB); + bc().setCancel(closePB); -void GuiWrapDialog::closeEvent(QCloseEvent * e) -{ - form_->slotWMHide(); - e->accept(); + bc().addReadOnly(widthED); + bc().addReadOnly(unitsLC); + bc().addReadOnly(valignCO); } -void GuiWrapDialog::change_adaptor() +ControlWrap & GuiWrapDialog::controller() const { - form_->changed(); + return static_cast(Dialog::controller()); } -///////////////////////////////////////////////////////////////////// -// -// GuiWrap -// -///////////////////////////////////////////////////////////////////// -GuiWrap::GuiWrap(GuiDialog & parent) - : GuiView(parent, _("Text Wrap Settings")) +void GuiWrapDialog::closeEvent(QCloseEvent * e) { + slotWMHide(); + e->accept(); } -void GuiWrap::build_dialog() +void GuiWrapDialog::change_adaptor() { - dialog_.reset(new GuiWrapDialog(this)); - - bc().setRestore(dialog_->restorePB); - bc().setOK(dialog_->okPB); - bc().setApply(dialog_->applyPB); - bc().setCancel(dialog_->closePB); - - bc().addReadOnly(dialog_->widthED); - bc().addReadOnly(dialog_->unitsLC); - bc().addReadOnly(dialog_->valignCO); + changed(); } -void GuiWrap::applyView() +void GuiWrapDialog::applyView() { - double const value = convert(fromqstr(dialog_->widthED->text())); - Length::UNIT unit = dialog_->unitsLC->currentLengthItem(); - if (dialog_->widthED->text().isEmpty()) + double const value = widthED->text().toDouble(); + Length::UNIT unit = unitsLC->currentLengthItem(); + if (widthED->text().isEmpty()) unit = Length::UNIT_NONE; InsetWrapParams & params = controller().params(); params.width = Length(value, unit); - switch (dialog_->valignCO->currentIndex()) { + switch (valignCO->currentIndex()) { case 0: params.placement.erase(); break; @@ -133,13 +119,13 @@ static string const numtostr(double val) } -void GuiWrap::update_contents() +void GuiWrapDialog::update_contents() { InsetWrapParams & params = controller().params(); Length len(params.width); - dialog_->widthED->setText(toqstr(numtostr(len.value()))); - dialog_->unitsLC->setCurrentItem(len.unit()); + widthED->setText(toqstr(numtostr(len.value()))); + unitsLC->setCurrentItem(len.unit()); int item = 0; if (params.placement == "l") @@ -149,7 +135,7 @@ void GuiWrap::update_contents() else if (params.placement == "p") item = 3; - dialog_->valignCO->setCurrentIndex(item); + valignCO->setCurrentIndex(item); } } // namespace frontend diff --git a/src/frontends/qt4/GuiWrap.h b/src/frontends/qt4/GuiWrap.h index 20510448a2..b06b686b74 100644 --- a/src/frontends/qt4/GuiWrap.h +++ b/src/frontends/qt4/GuiWrap.h @@ -12,50 +12,31 @@ #ifndef GUIWRAP_H #define GUIWRAP_H -#include "GuiDialogView.h" +#include "GuiDialog.h" #include "ControlWrap.h" #include "ui_WrapUi.h" -#include - namespace lyx { namespace frontend { -class GuiWrap; - -class GuiWrapDialog : public QDialog, public Ui::WrapUi +class GuiWrapDialog : public GuiDialog, public Ui::WrapUi { Q_OBJECT -public: - GuiWrapDialog(GuiWrap * form); -protected Q_SLOTS: - virtual void change_adaptor(); -protected: - virtual void closeEvent(QCloseEvent * e); -private: - GuiWrap * form_; -}; - -class GuiWrap : public GuiView -{ public: - friend class GuiWrapDialog; + GuiWrapDialog(LyXView & lv); + +private Q_SLOTS: + void change_adaptor(); - GuiWrap(GuiDialog &); - /// parent controller - ControlWrap & controller() - { return static_cast(this->getController()); } - /// parent controller - ControlWrap const & controller() const - { return static_cast(this->getController()); } private: + void closeEvent(QCloseEvent * e); + /// parent controller + ControlWrap & controller() const; /// Apply changes - virtual void applyView(); + void applyView(); /// update - virtual void update_contents(); - /// build the dialog - virtual void build_dialog(); + void update_contents(); }; } // namespace frontend diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index ff01af670c..b1e439dc8e 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -59,7 +59,6 @@ SOURCEFILES = \ GuiCommandEdit.cpp \ GuiDelimiter.cpp \ GuiDialog.cpp \ - GuiDialogView.cpp \ GuiDocument.cpp \ GuiEmbeddedFiles.cpp \ GuiErrorList.cpp \ @@ -149,7 +148,6 @@ MOCHEADER = \ GuiCommandEdit.h \ GuiDelimiter.h \ GuiDialog.h \ - GuiDialogView.h \ GuiDocument.h \ GuiEmbeddedFiles.h \ GuiErrorList.h \ diff --git a/src/frontends/qt4/README b/src/frontends/qt4/README index 2c28190694..5e017a0914 100644 --- a/src/frontends/qt4/README +++ b/src/frontends/qt4/README @@ -6,8 +6,8 @@ General rules Every editable field that affects the state of the dialog contents from LyX's point of view should connect its xxxChanged() signal to a the dialog's changed_adaptor() slot, which in turn should call -form_->changed(). If you are using a more complicated thing anyway, -then remember to call form_->changed() at the end (if it has changed !) +changed(). If you are using a more complicated thing anyway, +then remember to call changed() at the end (if it has changed!) Every non-trivial widget should have a tooltip. If you don't know what to write, write "FIXME", and it can fixed later. Don't be afraid @@ -15,39 +15,43 @@ to use QWhatsThis too, but this must be done in the derived class's constructor, and use _("..."). Non-trivial means that things like "OK" /must not/ have a tooltip. -moc is incredibly stupid and sometimes you need a fully qualified -"std::string" for .connect() statements to work. Be very, very careful. +moc needs a fully qualified "std::string" for .connect() statements +to work. Be very, very careful. -Remember to check tab order on a dialog (third icon, with blue bars in designer). +Remember to check tab order on a dialog (third icon, with blue bars in +designer). -Remember to check sensible resizing behaviour on a dialog. +Remember to check sensible resizing behaviour on a dialog. This is +usually done by adding a top-level layout to the dialog in Designer. Remember to use Edit->Check Accelerators -If necessary, you should override Qt2Base::isValid() for determining the validity -of the current dialog's contents. +If necessary, you should override Qt2Base::isValid() for determining the +validity 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. +OK/Apply/Restore/Close should be connected in the derived class's +constructor to call slotOK() etc. Refer to close/cancel as close in the +source. -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. +Override update_contents() to update the dialog, not update(). 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 -the buttoncontroller, make sure to respect Qt2Base::updating_ +Never call buttoncontroller functions directly from dialogs. In general, +you should use Qt2Base::changed() in all circumstances. However, if you +must call the buttoncontroller, make sure to respect Qt2Base::updating_ Naming conventions ------------------ -QFoo.[Ch] The file that interacts with the controller -QFooDialog.[Ch] The implementation of the dialog, derived from the generated files -ui/FooDialog.ui The designer file -ui/FooDialogBase.[Ch] Generated files from FooDialog.ui +QFoo.{cpp,h} The file that interacts with the controller _and_ +the implementation of the dialog, derived from the generated files +ui/FooDialog.ui The designer file +ui_FooDialog.h Generated files from FooDialog.ui -slots should be named e.g. slotFooClicked(), slotFooSelected(), where foo is the name -of the widget. +slots should be named e.g. slotFooClicked(), slotFooSelected(), where +foo is the name of the widget. Widgets should be named like "fooXX", where XX is one of the following widget types : @@ -68,30 +72,11 @@ TE - text edit TW - tree widget (FIXME: also TV in some files) -Stuff to be aware of --------------------- - -The connect statement in Qt is a macro and its arguments does not follow -the C++ standard as it should. Using the construct "Type const &" as -argument will lead to runtime-errors, use "const Type &" instead. - -ex. - ---right-- - - connect(list, SIGNAL(selected(const QString &)), - this, SLOT(complete_selected(const QString &))); - ---wrong-- - - connect(list, SIGNAL(selected(QString const &)), - this, SLOT(complete_selected(QString const &))); - Qt, Unicode, and LyX -------------------- LyX uses a different encoding (UCS4) than Qt (UTF16), therefore there are a -number of conversion functions in qt_helpers.[Ch]. Read the doxygen +number of conversion functions in qt_helpers.{cpp,h}. Read the doxygen documentation for details when to use which function. Additionally, you should follow these simple rules : diff --git a/src/frontends/qt4/TocWidget.cpp b/src/frontends/qt4/TocWidget.cpp index f21d0fbbd4..1fa781058b 100644 --- a/src/frontends/qt4/TocWidget.cpp +++ b/src/frontends/qt4/TocWidget.cpp @@ -43,12 +43,12 @@ using support::libFileSearch; namespace frontend { TocWidget::TocWidget(GuiToc * form, QWidget * parent) - : QWidget(parent), form_(form), depth_(0) + : QWidget(parent), depth_(0) { setupUi(this); + form_ = form; - connect(form, SIGNAL(modelReset()), - SLOT(updateGui())); + connect(form_, SIGNAL(modelReset()), SLOT(updateGui())); FileName icon_path = libFileSearch("images", "promote.png"); moveOutTB->setIcon(QIcon(toqstr(icon_path.absFilename()))); @@ -94,7 +94,7 @@ void TocWidget::on_updateTB_clicked() // The backend update can take some time so we disable // the controls while waiting. enableControls(false); - form_->updateBackend(); + form_->controller().updateBackend(); } /* FIXME (Ugras 17/11/06): @@ -106,8 +106,8 @@ depth calculation. int TocWidget::getIndexDepth(QModelIndex const & index, int depth) { ++depth; - return (index.parent() == - QModelIndex())? depth : getIndexDepth(index.parent(),depth); + return (index.parent() == QModelIndex()) + ? depth : getIndexDepth(index.parent(),depth); } @@ -154,7 +154,7 @@ void TocWidget::on_moveUpTB_clicked() if (!list.isEmpty()) { enableControls(false); form_->goTo(typeCO->currentIndex(), list[0]); - form_->outlineUp(); + form_->controller().outlineUp(); enableControls(true); } } @@ -167,7 +167,7 @@ void TocWidget::on_moveDownTB_clicked() if (!list.isEmpty()) { enableControls(false); form_->goTo(typeCO->currentIndex(), list[0]); - form_->outlineDown(); + form_->controller().outlineDown(); enableControls(true); } } @@ -180,7 +180,7 @@ void TocWidget::on_moveInTB_clicked() if (!list.isEmpty()) { enableControls(false); form_->goTo(typeCO->currentIndex(), list[0]); - form_->outlineIn(); + form_->controller().outlineIn(); enableControls(true); } } @@ -192,7 +192,7 @@ void TocWidget::on_moveOutTB_clicked() if (!list.isEmpty()) { enableControls(false); form_->goTo(typeCO->currentIndex(), list[0]); - form_->outlineOut(); + form_->controller().outlineOut(); enableControls(true); } } @@ -239,7 +239,7 @@ void TocWidget::update() void TocWidget::updateGui() { - vector const & type_names = form_->typeNames(); + vector const & type_names = form_->controller().typeNames(); if (type_names.empty()) { enableControls(false); typeCO->clear(); @@ -262,7 +262,7 @@ void TocWidget::updateGui() if (current_type != -1) typeCO->setCurrentIndex(current_type); else - typeCO->setCurrentIndex(form_->selectedType()); + typeCO->setCurrentIndex(form_->controller().selectedType()); typeCO->blockSignals(false); setTocModel(typeCO->currentIndex()); @@ -294,7 +294,7 @@ void TocWidget::setTocModel(size_t type) if (toc_model) { LYXERR(Debug::GUI) - << "form_->tocModel()->rowCount " + << "tocModel()->rowCount " << toc_model->rowCount() << "\nform_->tocModel()->columnCount " << toc_model->columnCount() diff --git a/src/frontends/qt4/TocWidget.h b/src/frontends/qt4/TocWidget.h index cb38ee70af..c426534de0 100644 --- a/src/frontends/qt4/TocWidget.h +++ b/src/frontends/qt4/TocWidget.h @@ -13,9 +13,10 @@ #ifndef TOC_WIDGET_H #define TOC_WIDGET_H +#include "GuiDialog.h" +#include "ControlToc.h" #include "ui_TocUi.h" -#include namespace lyx { namespace frontend { @@ -26,7 +27,7 @@ class TocWidget : public QWidget, public Ui::TocUi { Q_OBJECT public: - TocWidget(GuiToc * form, QWidget * parent = 0); + TocWidget(GuiToc * form, QWidget * parent); /// Update the display of the dialog whilst it is still visible. void update(); @@ -65,10 +66,10 @@ private: //This is a workaround for a problem of signals blocking. void disconnectSelectionModel(); - GuiToc * form_; - /// depth of list shown int depth_; + /// + GuiToc * form_; }; } // namespace frontend -- 2.39.5