2007-09-03 05:59:32 +00:00
|
|
|
/**
|
|
|
|
* \file Dialog.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 <config.h>
|
|
|
|
|
|
|
|
#include "GuiDialog.h"
|
|
|
|
#include "debug.h"
|
2007-09-05 20:33:29 +00:00
|
|
|
#include "qt_helpers.h"
|
2007-09-10 22:32:59 +00:00
|
|
|
#include "frontends/LyXView.h"
|
|
|
|
|
|
|
|
using std::string;
|
2007-09-03 05:59:32 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
GuiDialog::GuiDialog(LyXView & lv, std::string const & name)
|
2007-09-10 22:32:59 +00:00
|
|
|
: is_closing_(false), name_(name), controller_(0)
|
|
|
|
{
|
|
|
|
lyxview_ = &lv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GuiDialog::~GuiDialog()
|
|
|
|
{
|
|
|
|
delete controller_;
|
|
|
|
}
|
2007-09-03 05:59:32 +00:00
|
|
|
|
|
|
|
|
2007-09-10 19:02:11 +00:00
|
|
|
void GuiDialog::setViewTitle(docstring const & title)
|
|
|
|
{
|
|
|
|
setWindowTitle("LyX: " + toqstr(title));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-03 05:59:32 +00:00
|
|
|
void GuiDialog::setButtonsValid(bool valid)
|
|
|
|
{
|
|
|
|
bc().setValid(valid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-11 17:06:15 +00:00
|
|
|
void GuiDialog::slotApply()
|
2007-09-03 05:59:32 +00:00
|
|
|
{
|
|
|
|
apply();
|
|
|
|
bc().apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-11 17:06:15 +00:00
|
|
|
void GuiDialog::slotOK()
|
2007-09-03 05:59:32 +00:00
|
|
|
{
|
|
|
|
is_closing_ = true;
|
|
|
|
apply();
|
|
|
|
is_closing_ = false;
|
2007-09-05 20:33:29 +00:00
|
|
|
QDialog::hide();
|
2007-09-03 05:59:32 +00:00
|
|
|
bc().ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-11 17:06:15 +00:00
|
|
|
void GuiDialog::slotClose()
|
2007-09-03 05:59:32 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
QDialog::hide();
|
2007-09-03 05:59:32 +00:00
|
|
|
bc().cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-11 17:06:15 +00:00
|
|
|
void GuiDialog::slotRestore()
|
2007-09-03 05:59:32 +00:00
|
|
|
{
|
2007-09-10 22:32:59 +00:00
|
|
|
// Tell the controller that a request to refresh the dialog's contents
|
|
|
|
// has been received. It's up to the controller to supply the necessary
|
2007-09-03 20:28:26 +00:00
|
|
|
// info by calling GuiDialog::updateView().
|
2007-09-10 22:32:59 +00:00
|
|
|
controller().updateDialog(name_);
|
2007-09-03 05:59:32 +00:00
|
|
|
bc().restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiDialog::checkStatus()
|
|
|
|
{
|
|
|
|
// buffer independant dialogs are always active.
|
|
|
|
// This check allows us leave canApply unimplemented for some dialogs.
|
|
|
|
if (!controller().isBufferDependent())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// deactivate the dialog if we have no buffer
|
2007-09-10 22:32:59 +00:00
|
|
|
if (!controller().isBufferAvailable()) {
|
2007-09-03 05:59:32 +00:00
|
|
|
bc().setReadOnly(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check whether this dialog may be active
|
|
|
|
if (controller().canApply()) {
|
2007-09-10 22:32:59 +00:00
|
|
|
bool const readonly = controller().isBufferReadonly();
|
2007-09-03 05:59:32 +00:00
|
|
|
bc().setReadOnly(readonly);
|
|
|
|
// refreshReadOnly() is too generous in _enabling_ widgets
|
|
|
|
// update dialog to disable disabled widgets again
|
2007-09-26 14:50:35 +00:00
|
|
|
|
2007-09-03 05:59:32 +00:00
|
|
|
if (!readonly || controller().canApplyToReadOnly())
|
2007-09-26 14:50:35 +00:00
|
|
|
updateView();
|
|
|
|
|
2007-09-03 05:59:32 +00:00
|
|
|
} else {
|
|
|
|
bc().setReadOnly(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
bool GuiDialog::isVisibleView() const
|
|
|
|
{
|
|
|
|
return QDialog::isVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (QWidget::isVisible()) {
|
|
|
|
raise();
|
|
|
|
activateWindow();
|
|
|
|
} else {
|
|
|
|
QWidget::show();
|
|
|
|
}
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiDialog::hideView()
|
|
|
|
{
|
|
|
|
QDialog::hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiDialog::changed()
|
|
|
|
{
|
|
|
|
if (updating_)
|
|
|
|
return;
|
|
|
|
bc().setValid(isValid());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiDialog::updateView()
|
|
|
|
{
|
|
|
|
setUpdatesEnabled(false);
|
|
|
|
|
|
|
|
// protect the BC from unwarranted state transitions
|
|
|
|
updating_ = true;
|
2007-09-11 18:33:42 +00:00
|
|
|
updateContents();
|
2007-09-05 20:33:29 +00:00
|
|
|
updating_ = false;
|
|
|
|
|
|
|
|
setUpdatesEnabled(true);
|
|
|
|
QDialog::update();
|
|
|
|
}
|
|
|
|
|
2007-09-10 22:32:59 +00:00
|
|
|
|
|
|
|
void GuiDialog::showData(string const & data)
|
|
|
|
{
|
|
|
|
if (controller().isBufferDependent() && !controller().isBufferAvailable())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!controller().initialiseParams(data)) {
|
|
|
|
lyxerr << "Dialog \"" << name_
|
|
|
|
<< "\" failed to translate the data "
|
|
|
|
"string passed to show()" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bc().setReadOnly(controller().isBufferReadonly());
|
|
|
|
showView();
|
|
|
|
// The widgets may not be valid, so refresh the button controller
|
|
|
|
bc().refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiDialog::updateData(string const & data)
|
|
|
|
{
|
|
|
|
if (controller().isBufferDependent() && !controller().isBufferAvailable())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!controller().initialiseParams(data)) {
|
|
|
|
lyxerr << "Dialog \"" << name_
|
|
|
|
<< "\" could not be initialized" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bc().setReadOnly(controller().isBufferReadonly());
|
|
|
|
updateView();
|
|
|
|
// The widgets may not be valid, so refresh the button controller
|
|
|
|
bc().refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiDialog::hide()
|
|
|
|
{
|
|
|
|
if (!isVisibleView())
|
|
|
|
return;
|
|
|
|
|
|
|
|
controller().clearParams();
|
|
|
|
hideView();
|
|
|
|
controller().disconnect(name_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiDialog::apply()
|
|
|
|
{
|
|
|
|
if (controller().isBufferDependent()) {
|
|
|
|
if (!controller().isBufferAvailable() ||
|
|
|
|
(controller().isBufferReadonly() && !controller().canApplyToReadOnly()))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
applyView();
|
|
|
|
controller().dispatchParams();
|
|
|
|
|
|
|
|
if (controller().disconnectOnApply() && !is_closing_) {
|
|
|
|
controller().disconnect(name_);
|
|
|
|
controller().initialiseParams(string());
|
|
|
|
updateView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiDialog::setController(Controller * controller)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(controller);
|
|
|
|
BOOST_ASSERT(!controller_);
|
|
|
|
controller_ = controller;
|
|
|
|
controller_->setLyXView(*lyxview_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-03 05:59:32 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
#include "GuiDialog_moc.cpp"
|