merge GuiBC<.,.> into Qt2BC

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19979 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-09-01 20:44:14 +00:00
parent 8906059a0a
commit af8621ea73
10 changed files with 105 additions and 253 deletions

View File

@ -87,60 +87,7 @@ private:
};
/** A templatised instantiation of the ButtonController's View requiring the
* gui-frontend widgets.
*/
template <class Button, class Widget>
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<Widget *> Widgets;
Widgets read_only_;
};
} // namespace frontend
} // namespace lyx
#include "BCView.tmpl"
#endif // BCVIEW_H

View File

@ -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 <class Button, class Widget>
GuiBC<Button, Widget>::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 <class Button, class Widget>
void GuiBC<Button, Widget>::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 <class Button, class Widget>
void GuiBC<Button, Widget>::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

View File

@ -12,6 +12,7 @@
#include "ButtonController.h"
#include "BCView.h"
#include "debug.h"
namespace lyx {
namespace frontend {

View File

@ -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");
}
}

View File

@ -15,7 +15,6 @@
#ifndef BUTTONPOLICY_H
#define BUTTONPOLICY_H
#include <vector>
#include <boost/utility.hpp>
@ -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

View File

@ -17,6 +17,7 @@
#include "frontends/LyXView.h"
#include "debug.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "LyXFunc.h"

View File

@ -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 = \

View File

@ -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"

View File

@ -12,7 +12,9 @@
#include <config.h>
#include "Qt2BC.h"
#include "qt_helpers.h"
#include "BCView.h"
#include "ButtonPolicy.h"
#include "debug.h"
#include <QPushButton>
#include <QLineEdit>
@ -20,21 +22,59 @@
namespace lyx {
namespace frontend {
Qt2BC::Qt2BC(ButtonController const & parent,
docstring const & cancel, docstring const & close)
: GuiBC<QPushButton, QWidget>(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<QLineEdit*>(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

View File

@ -29,21 +29,44 @@ namespace frontend {
the activation policy and which buttons correspond to which output of the
state machine.
*/
class Qt2BC : public GuiBC<QPushButton, QWidget> {
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<QWidget *> Widgets;
Widgets read_only_;
};
} // namespace frontend