From af8621ea73e84f809323f42ff559db5408a08bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sat, 1 Sep 2007 20:44:14 +0000 Subject: [PATCH] merge GuiBC<.,.> into Qt2BC git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19979 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/BCView.h | 53 ------------ src/frontends/controllers/BCView.tmpl | 80 ------------------- .../controllers/ButtonController.cpp | 1 + src/frontends/controllers/ButtonPolicy.cpp | 49 ++++-------- src/frontends/controllers/ButtonPolicy.h | 37 ++------- src/frontends/controllers/Dialog.cpp | 1 + src/frontends/controllers/Makefile.am | 4 +- src/frontends/qt4/Dialogs.cpp | 32 -------- src/frontends/qt4/Qt2BC.cpp | 60 +++++++++++--- src/frontends/qt4/Qt2BC.h | 41 +++++++--- 10 files changed, 105 insertions(+), 253 deletions(-) delete mode 100644 src/frontends/controllers/BCView.tmpl diff --git a/src/frontends/controllers/BCView.h b/src/frontends/controllers/BCView.h index 6b35f7137d..a089976126 100644 --- a/src/frontends/controllers/BCView.h +++ b/src/frontends/controllers/BCView.h @@ -87,60 +87,7 @@ private: }; -/** A templatised instantiation of the ButtonController's View requiring the - * gui-frontend widgets. - */ -template -class GuiBC : public BCView { -public: - /// - GuiBC(ButtonController const & parent, - docstring const & cancel, docstring const & close); - - //@{ - /** Store pointers to these widgets. The pointers are _not_ - * owned by GuiBC. - */ - void setOK(Button * obj) { okay_ = obj; } - void setApply(Button * obj) { apply_ = obj; } - void setCancel(Button * obj) { cancel_ = obj; } - void setRestore(Button * obj) { restore_ = obj; } - //@} - - /** Add a pointer to the list of widgets whose activation - * state is dependent upon the read-only status of the - * underlying buffer. - */ - void addReadOnly(Widget * obj) { read_only_.push_back(obj); } - - /// Refresh the status of the Ok, Apply, Restore, Cancel buttons. - virtual void refresh() const; - /// Refresh the status of any widgets in the read_only list - virtual void refreshReadOnly() const; - -private: - /// Enable/Disable a widget - virtual void setWidgetEnabled(Widget * obj, bool enable) const = 0; - /// Enable/Disable a button - virtual void setButtonEnabled(Button * obj, bool enable) const = 0; - /// Set the Label on the button - virtual void setButtonLabel(Button * obj, docstring const & label) const = 0; - - docstring const cancel_label_; - docstring const close_label_; - - Button * okay_; - Button * apply_; - Button * cancel_; - Button * restore_; - - typedef std::list Widgets; - Widgets read_only_; -}; - } // namespace frontend } // namespace lyx -#include "BCView.tmpl" - #endif // BCVIEW_H diff --git a/src/frontends/controllers/BCView.tmpl b/src/frontends/controllers/BCView.tmpl deleted file mode 100644 index 0e1aa800c7..0000000000 --- a/src/frontends/controllers/BCView.tmpl +++ /dev/null @@ -1,80 +0,0 @@ -// -*- C++ -*- -/** - * \file ButtonController.tmpl - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Allan Rae - * \author Angus Leeming - * \author Baruch Even - * - * Full author contact details are available in file CREDITS - * - * GuiBC is a base class and so these templatised methods will be - * instantiated if this file is #included in the derived classes' .C file. - */ - -#include "BCView.h" -#include "ButtonPolicy.h" -#include "debug.h" - -namespace lyx { -namespace frontend { - -template -GuiBC::GuiBC(ButtonController const & parent, - lyx::docstring const & cancel, lyx::docstring const & close) - : BCView(parent), - cancel_label_(cancel), close_label_(close), - okay_(0), apply_(0), cancel_(0), restore_(0) -{} - - -template -void GuiBC::refresh() const -{ - lyxerr[Debug::GUI] << "Calling BC refresh()" << std::endl; - - bool const all_valid = checkWidgets(); - - if (okay_) { - bool const enabled = - all_valid && bp().buttonStatus(ButtonPolicy::OKAY); - setButtonEnabled(okay_, enabled); - } - if (apply_) { - bool const enabled = - all_valid && bp().buttonStatus(ButtonPolicy::APPLY); - setButtonEnabled(apply_, enabled); - } - if (restore_) { - bool const enabled = - all_valid && bp().buttonStatus(ButtonPolicy::RESTORE); - setButtonEnabled(restore_, enabled); - } - if (cancel_) { - bool const enabled = bp().buttonStatus(ButtonPolicy::CANCEL); - if (enabled) - setButtonLabel(cancel_, cancel_label_); - else - setButtonLabel(cancel_, close_label_); - } -} - - -template -void GuiBC::refreshReadOnly() const -{ - if (read_only_.empty()) return; - - bool const enable = !bp().isReadOnly(); - - typename Widgets::const_iterator end = read_only_.end(); - typename Widgets::const_iterator iter = read_only_.begin(); - for (; iter != end; ++iter) { - setWidgetEnabled(*iter, enable); - } -} - -} // namespace frontend -} // namespace lyx diff --git a/src/frontends/controllers/ButtonController.cpp b/src/frontends/controllers/ButtonController.cpp index 5c7d625664..8f8ded96be 100644 --- a/src/frontends/controllers/ButtonController.cpp +++ b/src/frontends/controllers/ButtonController.cpp @@ -12,6 +12,7 @@ #include "ButtonController.h" #include "BCView.h" +#include "debug.h" namespace lyx { namespace frontend { diff --git a/src/frontends/controllers/ButtonPolicy.cpp b/src/frontends/controllers/ButtonPolicy.cpp index b76d636081..8dbedac506 100644 --- a/src/frontends/controllers/ButtonPolicy.cpp +++ b/src/frontends/controllers/ButtonPolicy.cpp @@ -110,7 +110,8 @@ void nextState(ButtonPolicy::State & state, ButtonPolicy::StateMachine const & s_m, char const * function_name = "nextState") { - if (ButtonPolicy::SMI_NOOP == in) return; + if (ButtonPolicy::SMI_NOOP == in) + return; ButtonPolicy::State tmp = s_m[state][in]; @@ -191,15 +192,11 @@ void PreferencesPolicy::input(SMInput input) { // The APPLIED state is persistent. Next time the dialog is opened, // the user will be able to press 'Save'. - if (SMI_CANCEL == input - || SMI_HIDE == input) { + if (SMI_CANCEL == input || SMI_HIDE == input) { if (state_ != APPLIED) state_ = INITIAL; } else { - nextState(state_, - input, - state_machine_, - "PreferencesPolicy"); + nextState(state_, input, state_machine_, "PreferencesPolicy"); } } @@ -250,8 +247,7 @@ void OkCancelPolicy::input(SMInput input) //lyxerr << "OkCancelPolicy::input" << endl; // CANCEL and HIDE always take us to INITIAL for all cases - if (SMI_CANCEL == input - || SMI_HIDE == input) { + if (SMI_CANCEL == input || SMI_HIDE == input) { state_ = INITIAL; } else { nextState(state_, input, state_machine_, "OkCancelPolicy"); @@ -324,13 +320,10 @@ void OkCancelReadOnlyPolicy::input(SMInput input) //lyxerr << "OkCancelReadOnlyPolicy::input" << endl; // CANCEL and HIDE always take us to INITIAL for all cases - if (SMI_CANCEL == input - || SMI_HIDE == input) { + if (SMI_CANCEL == input || SMI_HIDE == input) { state_ = INITIAL; } else { - nextState(state_, - input, - state_machine_, + nextState(state_, input, state_machine_, "OkCancelReadOnlyPolicy"); } } @@ -402,13 +395,10 @@ void NoRepeatedApplyReadOnlyPolicy::input(SMInput input) //lyxerr << "NoReapeatedApplyReadOnlyPolicy::input" << endl; // CANCEL and HIDE always take us to INITIAL for all cases - if (SMI_CANCEL == input - || SMI_HIDE == input) { + if (SMI_CANCEL == input || SMI_HIDE == input) { state_ = INITIAL; } else { - nextState(state_, - input, - state_machine_, + nextState(state_, input, state_machine_, "NoRepeatedApplyReadOnlyPolicy"); } } @@ -494,13 +484,10 @@ void OkApplyCancelReadOnlyPolicy::input(SMInput input) //lyxerr << "OkApplyCancelReadOnlyPolicy::input" << endl; // CANCEL and HIDE always take us to INITIAL for all cases - if (SMI_CANCEL == input - || SMI_HIDE == input) { + if (SMI_CANCEL == input || SMI_HIDE == input) { state_ = INITIAL; } else { - nextState(state_, - input, - state_machine_, + nextState(state_, input, state_machine_, "OkApplyCancelReadOnlyPolicy"); } } @@ -560,13 +547,10 @@ void OkApplyCancelPolicy::input(SMInput input) //lyxerr << "OkApplyCancelPolicy::input" << endl; // CANCEL and HIDE always take us to INITIAL for all cases - if (SMI_CANCEL == input - || SMI_HIDE == input) { + if (SMI_CANCEL == input || SMI_HIDE == input) { state_ = INITIAL; } else { - nextState(state_, - input, - state_machine_, + nextState(state_, input, state_machine_, "OkApplyCancelPolicy"); } } @@ -618,13 +602,10 @@ void NoRepeatedApplyPolicy::input(SMInput input) //lyxerr << "NoRepeatedApplyPolicy::input" << endl; // CANCEL and HIDE always take us to INITIAL for all cases - if (SMI_CANCEL == input - || SMI_HIDE == input) { + if (SMI_CANCEL == input || SMI_HIDE == input) { state_ = INITIAL; } else { - nextState(state_, - input, - state_machine_, + nextState(state_, input, state_machine_, "NoRepeatedApplyPolicy"); } } diff --git a/src/frontends/controllers/ButtonPolicy.h b/src/frontends/controllers/ButtonPolicy.h index 2a9e00cc79..66b5566f18 100644 --- a/src/frontends/controllers/ButtonPolicy.h +++ b/src/frontends/controllers/ButtonPolicy.h @@ -15,7 +15,6 @@ #ifndef BUTTONPOLICY_H #define BUTTONPOLICY_H - #include #include @@ -60,7 +59,7 @@ namespace frontend { without requiring a change of the dialog contents. If no repeating is allowed the Ok+Apply buttons are deactivated. The Preferences dialog has its own special version of repeated apply handling because its Ok - button is actually a Save button -- its always reasonable to Save the + button is actually a Save button -- it is always reasonable to Save the preferences if the dialog has changed since the last save. The IgnorantPolicy is a special case that allows anything. @@ -205,9 +204,7 @@ public: return button & outputs_[state_]; } /// Are we in a read-only state? - virtual bool isReadOnly() const { - return false; - } + virtual bool isReadOnly() const { return false; } private: /// Current state. State state_; @@ -320,8 +317,6 @@ class OkApplyCancelReadOnlyPolicy : public ButtonPolicy { public: /// OkApplyCancelReadOnlyPolicy(); - /// - //virtual ~OkApplyCancelReadOnlyPolicy() {} /// Trigger a transition with this input. virtual void input(SMInput); @@ -356,8 +351,6 @@ class OkApplyCancelPolicy : public ButtonPolicy { public: /// OkApplyCancelPolicy(); - /// - //virtual ~OkApplyCancelPolicy() {} /// Trigger a transition with this input. virtual void input(SMInput); @@ -366,9 +359,7 @@ public: return button & outputs_[state_]; } /// Are we in a read-only state? - virtual bool isReadOnly() const { - return false; - } + virtual bool isReadOnly() const { return false; } private: /// Current state. State state_; @@ -389,8 +380,6 @@ class NoRepeatedApplyPolicy : public ButtonPolicy { public: /// NoRepeatedApplyPolicy(); - /// - //virtual ~NoRepeatedApplyPolicy() {} /// Trigger a transition with this input. virtual void input(SMInput); @@ -399,9 +388,7 @@ public: return button & outputs_[state_]; } /// Are we in a read-only state? - virtual bool isReadOnly() const { - return false; - } + virtual bool isReadOnly() const { return false; } private: /// Current state. State state_; @@ -423,8 +410,6 @@ class PreferencesPolicy : public ButtonPolicy { public: /// PreferencesPolicy(); - /// - //virtual ~PreferencesPolicy() {} /// Trigger a transition with this input. virtual void input(SMInput); @@ -433,9 +418,7 @@ public: return button & outputs_[state_]; } /// Are we in a read-only state? - virtual bool isReadOnly() const { - return false; - } + virtual bool isReadOnly() const { return false; } private: /// Current state. State state_; @@ -454,18 +437,12 @@ private: */ class IgnorantPolicy : public ButtonPolicy { public: - //virtual ~IgnorantPolicy() {} - /// Trigger a transition with this input. virtual void input(SMInput) {} /// Activation status of a button. - virtual bool buttonStatus(Button) const { - return true; - } + virtual bool buttonStatus(Button) const { return true; } /// Are we in a read-only state? - virtual bool isReadOnly() const { - return false; - } + virtual bool isReadOnly() const { return false; } }; } // namespace frontend diff --git a/src/frontends/controllers/Dialog.cpp b/src/frontends/controllers/Dialog.cpp index a46f1b84a3..1c8cd2e97a 100644 --- a/src/frontends/controllers/Dialog.cpp +++ b/src/frontends/controllers/Dialog.cpp @@ -17,6 +17,7 @@ #include "frontends/LyXView.h" +#include "debug.h" #include "FuncRequest.h" #include "FuncStatus.h" #include "LyXFunc.h" diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index 8c1ad66e9c..4834bbf9e3 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -1,9 +1,9 @@ include $(top_srcdir)/config/common.am -EXTRA_DIST = BCView.tmpl - AM_CPPFLAGS += -I$(top_srcdir)/src $(BOOST_INCLUDES) +EXTRA_DIST = + pkglib_LTLIBRARIES = liblyxcontrollers.la SOURCEFILES = \ diff --git a/src/frontends/qt4/Dialogs.cpp b/src/frontends/qt4/Dialogs.cpp index 918cd1e636..eaef50d5eb 100644 --- a/src/frontends/qt4/Dialogs.cpp +++ b/src/frontends/qt4/Dialogs.cpp @@ -12,38 +12,6 @@ #include "Dialogs.h" -#include "ControlAboutlyx.h" -#include "ControlBibtex.h" -#include "ControlBox.h" -#include "ControlBranch.h" -#include "ControlChanges.h" -#include "ControlCharacter.h" -#include "ControlDocument.h" -#include "ControlEmbeddedFiles.h" -#include "ControlErrorList.h" -#include "ControlERT.h" -#include "ControlExternal.h" -#include "ControlFloat.h" -#include "ControlGraphics.h" -#include "ControlInclude.h" -#include "ControlListings.h" -#include "ControlLog.h" -#include "ControlViewSource.h" -#include "ControlMath.h" -#include "ControlNote.h" -#include "ControlParagraph.h" -#include "ControlPrefs.h" -#include "ControlPrint.h" -#include "ControlRef.h" -#include "ControlSearch.h" -#include "ControlSendto.h" -#include "ControlShowFile.h" -#include "ControlSpellchecker.h" -#include "ControlTabular.h" -#include "ControlTabularCreate.h" -#include "ControlVSpace.h" -#include "ControlWrap.h" - #include "Qt2BC.h" #include "ButtonController.h" #include "DockView.h" diff --git a/src/frontends/qt4/Qt2BC.cpp b/src/frontends/qt4/Qt2BC.cpp index e6b42ad3c6..0506d7036e 100644 --- a/src/frontends/qt4/Qt2BC.cpp +++ b/src/frontends/qt4/Qt2BC.cpp @@ -12,7 +12,9 @@ #include #include "Qt2BC.h" -#include "qt_helpers.h" +#include "BCView.h" +#include "ButtonPolicy.h" +#include "debug.h" #include #include @@ -20,21 +22,59 @@ namespace lyx { namespace frontend { -Qt2BC::Qt2BC(ButtonController const & parent, - docstring const & cancel, docstring const & close) - : GuiBC(parent, cancel, close) + +Qt2BC::Qt2BC(ButtonController const & parent) + : BCView(parent), okay_(0), apply_(0), cancel_(0), restore_(0) {} -void Qt2BC::setButtonEnabled(QPushButton * obj, bool enabled) const +void Qt2BC::refresh() const { - obj->setEnabled(enabled); + lyxerr[Debug::GUI] << "Calling BC refresh()" << std::endl; + + bool const all_valid = checkWidgets(); + + if (okay_) { + bool const enabled = + all_valid && bp().buttonStatus(ButtonPolicy::OKAY); + okay_->setEnabled(enabled); + } + if (apply_) { + bool const enabled = + all_valid && bp().buttonStatus(ButtonPolicy::APPLY); + apply_->setEnabled(enabled); + } + if (restore_) { + bool const enabled = + all_valid && bp().buttonStatus(ButtonPolicy::RESTORE); + restore_->setEnabled(enabled); + } + if (cancel_) { + bool const enabled = bp().buttonStatus(ButtonPolicy::CANCEL); + if (enabled) + cancel_->setText(toqstr(_("Cancel"))); + else + cancel_->setText(toqstr(_("Close"))); + } +} + + +void Qt2BC::refreshReadOnly() const +{ + if (read_only_.empty()) return; + + bool const enable = !bp().isReadOnly(); + + Widgets::const_iterator end = read_only_.end(); + Widgets::const_iterator iter = read_only_.begin(); + for (; iter != end; ++iter) { + setWidgetEnabled(*iter, enable); + } } void Qt2BC::setWidgetEnabled(QWidget * obj, bool enabled) const { - // yuck, rtti, but the user comes first if (QLineEdit * le = qobject_cast(obj)) le->setReadOnly(!enabled); else @@ -43,11 +83,5 @@ void Qt2BC::setWidgetEnabled(QWidget * obj, bool enabled) const obj->setFocusPolicy(enabled ? Qt::StrongFocus : Qt::NoFocus); } - -void Qt2BC::setButtonLabel(QPushButton * obj, docstring const & label) const -{ - obj->setText(toqstr(label)); -} - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/Qt2BC.h b/src/frontends/qt4/Qt2BC.h index 9ba55e2685..f630050d24 100644 --- a/src/frontends/qt4/Qt2BC.h +++ b/src/frontends/qt4/Qt2BC.h @@ -29,21 +29,44 @@ namespace frontend { the activation policy and which buttons correspond to which output of the state machine. */ -class Qt2BC : public GuiBC { + +class Qt2BC : public BCView +{ public: /// - Qt2BC(ButtonController const &, - docstring const & = _("Cancel"), - docstring const & = _("Close")); -private: - /// Updates the button sensitivity (enabled/disabled) - void setButtonEnabled(QPushButton *, bool enabled) const; + Qt2BC(ButtonController const & parent); + //@{ + /** Store pointers to these widgets. + */ + void setOK(QPushButton * obj) { okay_ = obj; } + void setApply(QPushButton * obj) { apply_ = obj; } + void setCancel(QPushButton * obj) { cancel_ = obj; } + void setRestore(QPushButton * obj) { restore_ = obj; } + //@} + + /** Add a pointer to the list of widgets whose activation + * state is dependent upon the read-only status of the + * underlying buffer. + */ + void addReadOnly(QWidget * obj) { read_only_.push_back(obj); } + + /// Refresh the status of the Ok, Apply, Restore, Cancel buttons. + virtual void refresh() const; + /// Refresh the status of any widgets in the read_only list + virtual void refreshReadOnly() const; + +private: /// Updates the widget sensitivity (enabled/disabled) void setWidgetEnabled(QWidget *, bool enabled) const; - /// Set the label on the button - void setButtonLabel(QPushButton *, docstring const & label) const; + QPushButton * okay_; + QPushButton * apply_; + QPushButton * cancel_; + QPushButton * restore_; + + typedef std::list Widgets; + Widgets read_only_; }; } // namespace frontend