2001-08-27 01:19:32 +00:00
|
|
|
/**
|
|
|
|
* \file QExternalDialog.C
|
2002-09-24 13:57:09 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-08-27 01:19:32 +00:00
|
|
|
*
|
2002-10-20 01:48:28 +00:00
|
|
|
* \author John Levon
|
2003-12-05 02:49:22 +00:00
|
|
|
* \author Angus Leeming
|
2002-09-24 13:57:09 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-08-27 01:19:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2004-05-20 09:36:28 +00:00
|
|
|
// Qt defines a macro 'signals' that clashes with a boost namespace.
|
|
|
|
// All is well if the namespace is visible first.
|
2004-01-08 10:59:51 +00:00
|
|
|
#include "insets/ExternalTemplate.h"
|
|
|
|
|
2003-12-05 02:49:22 +00:00
|
|
|
#include "controllers/ButtonController.h"
|
|
|
|
#include "controllers/ControlExternal.h"
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "support/lyxlib.h"
|
|
|
|
|
|
|
|
#include "QExternalDialog.h"
|
|
|
|
|
|
|
|
#include "lengthcombo.h"
|
|
|
|
#include "lengthvalidator.h"
|
2002-12-17 20:37:13 +00:00
|
|
|
#include "qt_helpers.h"
|
2003-12-05 02:49:22 +00:00
|
|
|
#include "QExternal.h"
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2003-12-05 02:49:22 +00:00
|
|
|
#include <qcheckbox.h>
|
2003-10-07 22:59:58 +00:00
|
|
|
#include <qcombobox.h>
|
2001-08-27 01:19:32 +00:00
|
|
|
#include <qpushbutton.h>
|
|
|
|
#include <qfiledialog.h>
|
|
|
|
#include <qtextview.h>
|
2002-03-21 21:21:28 +00:00
|
|
|
#include <qlineedit.h>
|
2003-06-04 09:16:29 +00:00
|
|
|
#include <qvalidator.h>
|
2001-08-27 01:19:32 +00:00
|
|
|
|
2003-12-05 02:49:22 +00:00
|
|
|
using lyx::support::float_equal;
|
|
|
|
using lyx::support::isStrDbl;
|
|
|
|
using lyx::support::strToDbl;
|
|
|
|
using std::string;
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
2003-12-05 02:49:22 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
LengthValidator * unsignedLengthValidator(QLineEdit * ed)
|
|
|
|
{
|
|
|
|
LengthValidator * v = new LengthValidator(ed);
|
|
|
|
v->setBottom(LyXLength());
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
2001-08-27 01:19:32 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2001-08-27 01:19:32 +00:00
|
|
|
QExternalDialog::QExternalDialog(QExternal * form)
|
2004-06-01 22:16:28 +00:00
|
|
|
: QExternalDialogBase(qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget(), 0, false, 0),
|
2003-12-05 02:49:22 +00:00
|
|
|
form_(form)
|
2001-08-27 01:19:32 +00:00
|
|
|
{
|
|
|
|
connect(okPB, SIGNAL(clicked()),
|
|
|
|
form, SLOT(slotOK()));
|
2003-03-06 05:52:13 +00:00
|
|
|
connect(applyPB, SIGNAL(clicked()),
|
|
|
|
form, SLOT(slotApply()));
|
2001-08-27 01:19:32 +00:00
|
|
|
connect(closePB, SIGNAL(clicked()),
|
|
|
|
form, SLOT(slotClose()));
|
2003-06-04 09:16:29 +00:00
|
|
|
|
2003-12-05 02:49:22 +00:00
|
|
|
QIntValidator * validator = new QIntValidator(displayscaleED);
|
2003-06-04 09:16:29 +00:00
|
|
|
validator->setBottom(1);
|
2003-12-05 02:49:22 +00:00
|
|
|
displayscaleED->setValidator(validator);
|
|
|
|
|
|
|
|
angleED->setValidator(new QDoubleValidator(-360, 360, 2, angleED));
|
|
|
|
|
|
|
|
xlED->setValidator(new QIntValidator(xlED));
|
|
|
|
ybED->setValidator(new QIntValidator(ybED));
|
|
|
|
xrED->setValidator(new QIntValidator(xrED));
|
|
|
|
ytED->setValidator(new QIntValidator(ytED));
|
|
|
|
|
|
|
|
// The width is initially set to 'scale' and so should accept
|
|
|
|
// a pure number only.
|
|
|
|
widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
|
|
|
|
heightED->setValidator(unsignedLengthValidator(heightED));
|
2001-08-27 01:19:32 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-09-11 17:42:45 +00:00
|
|
|
void QExternalDialog::show()
|
|
|
|
{
|
|
|
|
QExternalDialogBase::show();
|
|
|
|
fileED->setFocus();
|
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2003-12-05 02:49:22 +00:00
|
|
|
|
|
|
|
bool QExternalDialog::activateAspectratio() const
|
|
|
|
{
|
|
|
|
if (widthUnitCO->currentItem() == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
string const wstr = fromqstr(widthED->text());
|
|
|
|
if (wstr.empty())
|
|
|
|
return false;
|
|
|
|
bool const wIsDbl = isStrDbl(wstr);
|
|
|
|
if (wIsDbl && float_equal(strToDbl(wstr), 0.0, 0.05))
|
|
|
|
return false;
|
|
|
|
LyXLength l;
|
|
|
|
if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
string const hstr = fromqstr(heightED->text());
|
|
|
|
if (hstr.empty())
|
|
|
|
return false;
|
|
|
|
bool const hIsDbl = isStrDbl(hstr);
|
|
|
|
if (hIsDbl && float_equal(strToDbl(hstr), 0.0, 0.05))
|
|
|
|
return false;
|
|
|
|
if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QExternalDialog::bbChanged()
|
|
|
|
{
|
|
|
|
form_->controller().bbChanged(true);
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QExternalDialog::browseClicked()
|
|
|
|
{
|
2004-01-08 10:59:51 +00:00
|
|
|
int const choice = externalCO->currentItem();
|
|
|
|
string const template_name =
|
|
|
|
form_->controller().getTemplate(choice).lyxName;
|
2003-12-05 02:49:22 +00:00
|
|
|
string const str =
|
2004-01-08 10:59:51 +00:00
|
|
|
form_->controller().browse(fromqstr(fileED->text()),
|
|
|
|
template_name);
|
2003-12-05 02:49:22 +00:00
|
|
|
fileED->setText(toqstr(str));
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-27 01:19:32 +00:00
|
|
|
void QExternalDialog::change_adaptor()
|
|
|
|
{
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-27 01:19:32 +00:00
|
|
|
void QExternalDialog::closeEvent(QCloseEvent * e)
|
|
|
|
{
|
|
|
|
form_->slotWMHide();
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-27 01:19:32 +00:00
|
|
|
void QExternalDialog::editClicked()
|
|
|
|
{
|
|
|
|
form_->controller().editExternal();
|
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
|
|
|
2003-12-05 02:49:22 +00:00
|
|
|
void QExternalDialog::extraChanged(const QString& text)
|
2001-08-27 01:19:32 +00:00
|
|
|
{
|
2003-12-05 02:49:22 +00:00
|
|
|
std::string const format = fromqstr(extraFormatCO->currentText());
|
|
|
|
form_->extra_[format] = text;
|
2001-08-27 01:19:32 +00:00
|
|
|
form_->changed();
|
|
|
|
}
|
2003-10-07 22:59:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
void QExternalDialog::formatChanged(const QString& format)
|
|
|
|
{
|
|
|
|
extraED->setText(form_->extra_[fromqstr(format)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-05 02:49:22 +00:00
|
|
|
void QExternalDialog::getbbClicked()
|
2003-10-07 22:59:58 +00:00
|
|
|
{
|
2003-12-05 02:49:22 +00:00
|
|
|
form_->getBB();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QExternalDialog::sizeChanged()
|
|
|
|
{
|
|
|
|
aspectratioCB->setEnabled(activateAspectratio());
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QExternalDialog::templateChanged()
|
|
|
|
{
|
|
|
|
form_->updateTemplate();
|
2003-10-07 22:59:58 +00:00
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
2003-12-05 02:49:22 +00:00
|
|
|
|
|
|
|
void QExternalDialog::widthUnitChanged()
|
|
|
|
{
|
|
|
|
bool useHeight = (widthUnitCO->currentItem() > 0);
|
|
|
|
|
|
|
|
if (useHeight)
|
|
|
|
widthED->setValidator(unsignedLengthValidator(widthED));
|
|
|
|
else
|
|
|
|
widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
|
|
|
|
|
|
|
|
heightED->setEnabled(useHeight);
|
|
|
|
heightUnitCO->setEnabled(useHeight);
|
|
|
|
form_->changed();
|
|
|
|
}
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|