2001-08-27 01:19:32 +00:00
|
|
|
/**
|
|
|
|
* \file QExternal.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
|
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-09-24 13:57:09 +00:00
|
|
|
|
2003-09-29 10:50:51 +00:00
|
|
|
#include "debug.h"
|
2001-08-27 01:19:32 +00:00
|
|
|
#include "ControlExternal.h"
|
2002-12-17 20:37:13 +00:00
|
|
|
#include "qt_helpers.h"
|
2003-06-11 14:30:04 +00:00
|
|
|
|
|
|
|
#include "insets/ExternalTemplate.h"
|
2003-10-07 20:25:10 +00:00
|
|
|
#include "insets/insetexternal.h"
|
2003-06-11 14:30:04 +00:00
|
|
|
|
2003-06-04 09:16:29 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "support/tostr.h"
|
2001-08-27 01:19:32 +00:00
|
|
|
|
|
|
|
#include <qlineedit.h>
|
|
|
|
#include <qpushbutton.h>
|
2003-06-04 09:16:29 +00:00
|
|
|
#include <qcheckbox.h>
|
2002-03-21 21:21:28 +00:00
|
|
|
#include <qcombobox.h>
|
2001-08-27 01:19:32 +00:00
|
|
|
#include <qtextview.h>
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "QExternalDialog.h"
|
|
|
|
#include "QExternal.h"
|
|
|
|
#include "Qt2BC.h"
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
using lyx::support::strToInt;
|
2003-10-07 22:59:58 +00:00
|
|
|
using lyx::support::trim;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
|
2003-03-05 11:30:35 +00:00
|
|
|
typedef QController<ControlExternal, QView<QExternalDialog> > base_class;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2003-03-05 11:30:35 +00:00
|
|
|
QExternal::QExternal(Dialog & parent)
|
2003-05-22 15:42:50 +00:00
|
|
|
: base_class(parent, _("LyX: External Material"))
|
2001-08-27 01:19:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QExternal::build_dialog()
|
|
|
|
{
|
|
|
|
dialog_.reset(new QExternalDialog(this));
|
|
|
|
|
2003-03-10 03:13:28 +00:00
|
|
|
bcview().setOK(dialog_->okPB);
|
|
|
|
bcview().setApply(dialog_->applyPB);
|
|
|
|
bcview().setCancel(dialog_->closePB);
|
|
|
|
bcview().addReadOnly(dialog_->externalCO);
|
|
|
|
bcview().addReadOnly(dialog_->fileED);
|
|
|
|
bcview().addReadOnly(dialog_->browsePB);
|
2003-10-07 22:59:58 +00:00
|
|
|
bcview().addReadOnly(dialog_->extraED);
|
2001-08-27 01:19:32 +00:00
|
|
|
|
|
|
|
std::vector<string> templates(controller().getTemplates());
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-27 01:19:32 +00:00
|
|
|
for (std::vector<string>::const_iterator cit = templates.begin();
|
|
|
|
cit != templates.end(); ++cit) {
|
2002-12-17 20:37:13 +00:00
|
|
|
dialog_->externalCO->insertItem(toqstr(*cit), -1);
|
2001-08-27 01:19:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-27 01:19:32 +00:00
|
|
|
void QExternal::update_contents()
|
|
|
|
{
|
2003-10-07 20:25:10 +00:00
|
|
|
InsetExternalParams const & params = controller().params();
|
2001-08-27 01:19:32 +00:00
|
|
|
|
2003-07-23 09:17:04 +00:00
|
|
|
string const name =
|
|
|
|
params.filename.outputFilename(kernel().bufferFilepath());
|
|
|
|
dialog_->fileED->setText(toqstr(name));
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2003-09-25 10:49:13 +00:00
|
|
|
dialog_->externalCO->setCurrentItem(controller()
|
|
|
|
.getTemplateNumber(params.templatename()));
|
2003-10-07 22:59:58 +00:00
|
|
|
updateTemplate();
|
2003-06-04 09:16:29 +00:00
|
|
|
|
|
|
|
int item = 0;
|
|
|
|
switch (params.display) {
|
2003-10-22 22:26:47 +00:00
|
|
|
case lyx::external::DefaultDisplay: item = 0; break;
|
|
|
|
case lyx::external::MonochromeDisplay: item = 1; break;
|
|
|
|
case lyx::external::GrayscaleDisplay: item = 2; break;
|
|
|
|
case lyx::external::ColorDisplay: item = 3; break;
|
|
|
|
case lyx::external::PreviewDisplay: item = 4; break;
|
|
|
|
case lyx::external::NoDisplay: item = 0; break;
|
2003-06-04 09:16:29 +00:00
|
|
|
}
|
|
|
|
dialog_->showCB->setCurrentItem(item);
|
2003-10-22 22:26:47 +00:00
|
|
|
dialog_->showCB->setEnabled(params.display != lyx::external::NoDisplay &&
|
2003-06-04 09:16:29 +00:00
|
|
|
!readOnly());
|
2003-10-22 22:26:47 +00:00
|
|
|
dialog_->displayCB->setChecked(params.display != lyx::external::NoDisplay);
|
|
|
|
dialog_->displayscale->setEnabled(params.display != lyx::external::NoDisplay &&
|
2003-06-04 09:16:29 +00:00
|
|
|
!readOnly());
|
|
|
|
dialog_->displayscale->setText(toqstr(tostr(params.lyxscale)));
|
|
|
|
|
2001-08-27 01:19:32 +00:00
|
|
|
isValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-07 22:59:58 +00:00
|
|
|
void QExternal::updateTemplate()
|
|
|
|
{
|
|
|
|
namespace external = lyx::external;
|
|
|
|
|
|
|
|
dialog_->externalTV->setText(toqstr(helpText()));
|
|
|
|
|
|
|
|
// Ascertain whether the template has any formats supporting
|
|
|
|
// the 'Extra' option
|
|
|
|
QLineEdit * const input = dialog_->extraED;
|
|
|
|
QComboBox * const combo = dialog_->extraFormatCB;
|
|
|
|
|
|
|
|
extra_.clear();
|
|
|
|
input->clear();
|
|
|
|
combo->clear();
|
|
|
|
|
|
|
|
external::Template templ =
|
|
|
|
controller().getTemplate(dialog_->externalCO->currentItem());
|
|
|
|
external::Template::Formats::const_iterator it = templ.formats.begin();
|
|
|
|
external::Template::Formats::const_iterator end = templ.formats.end();
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
if (it->second.option_transformers.find(external::Extra) ==
|
|
|
|
it->second.option_transformers.end())
|
|
|
|
continue;
|
|
|
|
string const format = it->first;
|
|
|
|
string const opt = controller().params().extradata.get(format);
|
|
|
|
combo->insertItem(toqstr(format));
|
|
|
|
extra_[format] = toqstr(opt);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool const enabled = combo->count() > 0;
|
|
|
|
|
|
|
|
input->setEnabled(enabled && !kernel().isBufferReadonly());
|
|
|
|
combo->setEnabled(enabled);
|
|
|
|
|
|
|
|
if (enabled) {
|
|
|
|
combo->setCurrentItem(0);
|
|
|
|
input->setText(extra_[fromqstr(combo->currentText())]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-05 11:30:35 +00:00
|
|
|
string const QExternal::helpText() const
|
2001-08-27 01:19:32 +00:00
|
|
|
{
|
2003-10-01 10:16:00 +00:00
|
|
|
lyx::external::Template templ =
|
2003-03-05 11:30:35 +00:00
|
|
|
controller().getTemplate(dialog_->externalCO->currentItem());
|
|
|
|
return templ.helpText;
|
2001-08-27 01:19:32 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-27 01:19:32 +00:00
|
|
|
void QExternal::apply()
|
|
|
|
{
|
2003-10-07 20:25:10 +00:00
|
|
|
InsetExternalParams params = controller().params();
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2003-07-23 09:17:04 +00:00
|
|
|
params.filename.set(fromqstr(dialog_->fileED->text()),
|
|
|
|
kernel().bufferFilepath());
|
2001-08-27 01:19:32 +00:00
|
|
|
|
2003-09-25 10:49:13 +00:00
|
|
|
params.settemplate(
|
|
|
|
controller().getTemplate(dialog_->externalCO->currentItem()).lyxName);
|
2003-03-05 11:30:35 +00:00
|
|
|
|
2003-06-04 09:16:29 +00:00
|
|
|
switch (dialog_->showCB->currentItem()) {
|
2003-10-22 22:26:47 +00:00
|
|
|
case 0: params.display = lyx::external::DefaultDisplay; break;
|
|
|
|
case 1: params.display = lyx::external::MonochromeDisplay; break;
|
|
|
|
case 2: params.display = lyx::external::GrayscaleDisplay; break;
|
|
|
|
case 3: params.display = lyx::external::ColorDisplay; break;
|
|
|
|
case 4: params.display = lyx::external::PreviewDisplay; break;
|
2003-06-04 09:16:29 +00:00
|
|
|
default:;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dialog_->displayCB->isChecked())
|
2003-10-22 22:26:47 +00:00
|
|
|
params.display = lyx::external::NoDisplay;
|
2003-06-04 09:16:29 +00:00
|
|
|
|
|
|
|
params.lyxscale = strToInt(fromqstr(dialog_->displayscale->text()));
|
|
|
|
|
2003-10-07 22:59:58 +00:00
|
|
|
std::map<string, QString>::const_iterator it = extra_.begin();
|
|
|
|
std::map<string, QString>::const_iterator end = extra_.end();
|
|
|
|
for (; it != end; ++it)
|
|
|
|
params.extradata.set(it->first, trim(fromqstr(it->second)));
|
|
|
|
|
2003-03-05 11:30:35 +00:00
|
|
|
controller().setParams(params);
|
2001-08-27 01:19:32 +00:00
|
|
|
}
|