2001-08-28 03:35:17 +00:00
|
|
|
/**
|
|
|
|
* \file QGraphics.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-28 03:35:17 +00:00
|
|
|
*
|
2002-10-20 01:48:28 +00:00
|
|
|
* \author John Levon
|
|
|
|
* \author Edwin Leuven
|
2002-10-31 20:05:55 +00:00
|
|
|
* \author Herbert Voss
|
2002-09-24 13:57:09 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2001-08-28 03:35:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "QtLyXView.h"
|
|
|
|
#include "ControlGraphics.h"
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "support/FileInfo.h"
|
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "insets/insetgraphicsParams.h"
|
|
|
|
#include "lyxrc.h"
|
|
|
|
#include "lengthcombo.h"
|
|
|
|
#include "gettext.h"
|
2002-10-31 20:05:55 +00:00
|
|
|
#include "lengthcommon.h"
|
|
|
|
#include "lyxlength.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
#include <qlineedit.h>
|
|
|
|
#include <qpushbutton.h>
|
|
|
|
#include <qcheckbox.h>
|
|
|
|
#include <qradiobutton.h>
|
|
|
|
#include <qcombobox.h>
|
|
|
|
#include <qgroupbox.h>
|
|
|
|
#include <qbuttongroup.h>
|
|
|
|
#include <qlabel.h>
|
|
|
|
|
2001-08-28 03:35:17 +00:00
|
|
|
#include "QGraphicsDialog.h"
|
|
|
|
#include "QGraphics.h"
|
|
|
|
#include "Qt2BC.h"
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-10-31 20:05:55 +00:00
|
|
|
using std::vector;
|
2001-08-28 03:35:17 +00:00
|
|
|
|
|
|
|
typedef Qt2CB<ControlGraphics, Qt2DB<QGraphicsDialog> > base_class;
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-08-12 14:28:43 +00:00
|
|
|
QGraphics::QGraphics()
|
|
|
|
: base_class(_("Graphics"))
|
2001-08-28 03:35:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QGraphics::build_dialog()
|
|
|
|
{
|
|
|
|
dialog_.reset(new QGraphicsDialog(this));
|
|
|
|
|
|
|
|
bc().setOK(dialog_->okPB);
|
|
|
|
bc().setApply(dialog_->applyPB);
|
2002-01-31 13:15:33 +00:00
|
|
|
bc().setRestore(dialog_->restorePB);
|
2002-08-08 03:50:54 +00:00
|
|
|
bc().setCancel(dialog_->closePB);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
bc().addReadOnly(dialog_->rotateGB);
|
2002-08-25 04:06:06 +00:00
|
|
|
bc().addReadOnly(dialog_->latexoptions);
|
2002-01-31 13:15:33 +00:00
|
|
|
bc().addReadOnly(dialog_->subfigure);
|
|
|
|
bc().addReadOnly(dialog_->subcaption);
|
|
|
|
bc().addReadOnly(dialog_->filenameL);
|
|
|
|
bc().addReadOnly(dialog_->filename);
|
2001-08-28 03:35:17 +00:00
|
|
|
bc().addReadOnly(dialog_->browsePB);
|
2002-08-25 04:06:06 +00:00
|
|
|
bc().addReadOnly(dialog_->unzipCB);
|
|
|
|
bc().addReadOnly(dialog_->filename);
|
|
|
|
bc().addReadOnly(dialog_->lbX);
|
|
|
|
bc().addReadOnly(dialog_->lbY);
|
|
|
|
bc().addReadOnly(dialog_->rtX);
|
|
|
|
bc().addReadOnly(dialog_->rtY);
|
|
|
|
bc().addReadOnly(dialog_->lbXunit);
|
|
|
|
bc().addReadOnly(dialog_->lbYunit);
|
|
|
|
bc().addReadOnly(dialog_->rtXunit);
|
|
|
|
bc().addReadOnly(dialog_->rtYunit);
|
|
|
|
bc().addReadOnly(dialog_->draftCB);
|
|
|
|
bc().addReadOnly(dialog_->clip);
|
|
|
|
bc().addReadOnly(dialog_->unzipCB);
|
|
|
|
bc().addReadOnly(dialog_->subfigure);
|
|
|
|
bc().addReadOnly(dialog_->subcaption);
|
|
|
|
bc().addReadOnly(dialog_->showCB);
|
|
|
|
bc().addReadOnly(dialog_->width);
|
|
|
|
bc().addReadOnly(dialog_->height);
|
|
|
|
bc().addReadOnly(dialog_->displayCB);
|
|
|
|
bc().addReadOnly(dialog_->displayscale);
|
|
|
|
bc().addReadOnly(dialog_->widthUnit);
|
|
|
|
bc().addReadOnly(dialog_->heightUnit);
|
|
|
|
bc().addReadOnly(dialog_->aspectratio);
|
|
|
|
bc().addReadOnly(dialog_->angle);
|
|
|
|
bc().addReadOnly(dialog_->origin);
|
|
|
|
bc().addReadOnly(dialog_->latexoptions);
|
|
|
|
bc().addReadOnly(dialog_->getPB);
|
2001-08-28 03:35:17 +00:00
|
|
|
}
|
|
|
|
|
2002-08-25 04:06:06 +00:00
|
|
|
|
2002-10-31 20:05:55 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
int getItemNo(vector<string> v, string const & s) {
|
|
|
|
vector<string>::const_iterator cit =
|
|
|
|
find(v.begin(), v.end(), s);
|
|
|
|
return (cit != v.end()) ? int(cit - v.begin()) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-28 03:35:17 +00:00
|
|
|
void QGraphics::update_contents()
|
|
|
|
{
|
2002-10-31 20:05:55 +00:00
|
|
|
// clear and fill in the comboboxes
|
|
|
|
vector<string> const bb_units = controller().getUnits();
|
|
|
|
dialog_->lbXunit->clear();
|
|
|
|
dialog_->lbYunit->clear();
|
|
|
|
dialog_->rtXunit->clear();
|
|
|
|
dialog_->rtYunit->clear();
|
|
|
|
for (vector<string>::const_iterator it = bb_units.begin();
|
|
|
|
it != bb_units.end(); ++it) {
|
|
|
|
dialog_->lbXunit->insertItem((*it).c_str(), -1);
|
|
|
|
dialog_->lbYunit->insertItem((*it).c_str(), -1);
|
|
|
|
dialog_->rtXunit->insertItem((*it).c_str(), -1);
|
|
|
|
dialog_->rtYunit->insertItem((*it).c_str(), -1);
|
|
|
|
}
|
|
|
|
|
2001-08-28 03:35:17 +00:00
|
|
|
InsetGraphicsParams & igp = controller().params();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
// set the right default unit
|
2002-01-31 13:15:33 +00:00
|
|
|
string unit = "cm";
|
2002-08-24 22:02:30 +00:00
|
|
|
switch (lyxrc.default_papersize) {
|
|
|
|
case BufferParams::PAPER_DEFAULT: break;
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
case BufferParams::PAPER_USLETTER:
|
|
|
|
case BufferParams::PAPER_LEGALPAPER:
|
2002-10-20 01:48:28 +00:00
|
|
|
case BufferParams::PAPER_EXECUTIVEPAPER:
|
|
|
|
unit = "in";
|
|
|
|
break;
|
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
case BufferParams::PAPER_A3PAPER:
|
|
|
|
case BufferParams::PAPER_A4PAPER:
|
|
|
|
case BufferParams::PAPER_A5PAPER:
|
2002-10-20 01:48:28 +00:00
|
|
|
case BufferParams::PAPER_B5PAPER:
|
|
|
|
unit = "cm";
|
|
|
|
break;
|
2002-08-24 22:02:30 +00:00
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
dialog_->filename->setText(igp.filename.c_str());
|
|
|
|
|
2002-10-31 20:05:55 +00:00
|
|
|
// set the bounding box values
|
2002-01-31 13:15:33 +00:00
|
|
|
if (igp.bb.empty()) {
|
2002-10-31 20:05:55 +00:00
|
|
|
controller().bbChanged = false;
|
|
|
|
string const bb = controller().readBB(igp.filename);
|
|
|
|
// the values from the file always have the point-unit
|
|
|
|
dialog_->lbX->setText(token(bb, ' ', 0).c_str());
|
|
|
|
dialog_->lbY->setText(token(bb, ' ', 1).c_str());
|
|
|
|
dialog_->rtX->setText(token(bb, ' ', 2).c_str());
|
|
|
|
dialog_->rtY->setText(token(bb, ' ', 3).c_str());
|
2002-01-31 13:15:33 +00:00
|
|
|
} else {
|
|
|
|
// get the values from the inset
|
|
|
|
controller().bbChanged = true;
|
2002-10-31 20:05:55 +00:00
|
|
|
LyXLength anyLength;
|
|
|
|
string const xl(token(igp.bb,' ',0));
|
|
|
|
string const yl(token(igp.bb,' ',1));
|
|
|
|
string const xr(token(igp.bb,' ',2));
|
|
|
|
string const yr(token(igp.bb,' ',3));
|
|
|
|
if (isValidLength(xl, &anyLength)) {
|
|
|
|
dialog_->lbX->setText(tostr(anyLength.value()).c_str());
|
|
|
|
string const unit(unit_name[anyLength.unit()]);
|
|
|
|
dialog_->lbXunit->setCurrentItem(getItemNo(bb_units, unit));
|
|
|
|
} else {
|
|
|
|
dialog_->lbX->setText(xl.c_str());
|
|
|
|
}
|
|
|
|
if (isValidLength(yl, &anyLength)) {
|
|
|
|
dialog_->lbY->setText(tostr(anyLength.value()).c_str());
|
|
|
|
string const unit(unit_name[anyLength.unit()]);
|
|
|
|
dialog_->lbYunit->setCurrentItem(getItemNo(bb_units, unit));
|
|
|
|
} else {
|
|
|
|
dialog_->lbY->setText(xl.c_str());
|
|
|
|
}
|
|
|
|
if (isValidLength(xr, &anyLength)) {
|
|
|
|
dialog_->rtX->setText(tostr(anyLength.value()).c_str());
|
|
|
|
string const unit(unit_name[anyLength.unit()]);
|
|
|
|
dialog_->rtXunit->setCurrentItem(getItemNo(bb_units, unit));
|
|
|
|
} else {
|
|
|
|
dialog_->rtX->setText(xl.c_str());
|
|
|
|
}
|
|
|
|
if (isValidLength(yr, &anyLength)) {
|
|
|
|
dialog_->rtY->setText(tostr(anyLength.value()).c_str());
|
|
|
|
string const unit(unit_name[anyLength.unit()]);
|
|
|
|
dialog_->rtYunit->setCurrentItem(getItemNo(bb_units, unit));
|
|
|
|
} else {
|
|
|
|
dialog_->rtY->setText(xl.c_str());
|
|
|
|
}
|
2002-01-31 13:15:33 +00:00
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
// Update the draft and clip mode
|
2002-08-25 04:06:06 +00:00
|
|
|
dialog_->draftCB->setChecked(igp.draft);
|
2002-01-31 13:15:33 +00:00
|
|
|
dialog_->clip->setChecked(igp.clip);
|
2002-08-25 04:06:06 +00:00
|
|
|
dialog_->unzipCB->setChecked(igp.noUnzip);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
// Update the subcaption check button and input field
|
|
|
|
dialog_->subfigure->setChecked(igp.subcaption);
|
|
|
|
dialog_->subcaption->setText(igp.subcaptionText.c_str());
|
2001-08-28 03:35:17 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
int item = 0;
|
2001-08-28 03:35:17 +00:00
|
|
|
switch (igp.display) {
|
2002-08-24 22:02:30 +00:00
|
|
|
case grfx::DefaultDisplay: item = 0; break;
|
|
|
|
case grfx::MonochromeDisplay: item = 1; break;
|
|
|
|
case grfx::GrayscaleDisplay: item = 2; break;
|
|
|
|
case grfx::ColorDisplay: item = 3; break;
|
2002-08-25 04:06:06 +00:00
|
|
|
case grfx::NoDisplay: item = 0; break;
|
2001-08-28 03:35:17 +00:00
|
|
|
}
|
2002-08-25 04:06:06 +00:00
|
|
|
dialog_->showCB->setCurrentItem(item);
|
|
|
|
dialog_->showCB->setEnabled(igp.display != grfx::NoDisplay && !readOnly());
|
|
|
|
dialog_->displayCB->setChecked(igp.display != grfx::NoDisplay);
|
|
|
|
dialog_->displayscale->setEnabled(igp.display != grfx::NoDisplay && !readOnly());
|
2002-08-08 03:50:54 +00:00
|
|
|
dialog_->displayscale->setText(tostr(igp.lyxscale).c_str());
|
|
|
|
|
|
|
|
dialog_->widthUnit->setCurrentItem(igp.width.unit());
|
|
|
|
dialog_->heightUnit->setCurrentItem(igp.height.unit());
|
|
|
|
dialog_->aspectratio->setChecked(igp.keepAspectRatio);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
// Update the rotate angle
|
|
|
|
dialog_->angle->setText(tostr(igp.rotateAngle).c_str());
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
if (igp.rotateOrigin.empty()) {
|
|
|
|
dialog_->origin->setCurrentItem(0);
|
|
|
|
} else {
|
2002-08-08 03:50:54 +00:00
|
|
|
// FIXME fl_set_choice_text(special_->choice_origin,igp.rotateOrigin.c_str());
|
2001-08-28 03:35:17 +00:00
|
|
|
}
|
2002-01-31 13:15:33 +00:00
|
|
|
|
|
|
|
// latex options
|
|
|
|
dialog_->latexoptions->setText(igp.special.c_str());
|
2001-08-28 03:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QGraphics::apply()
|
|
|
|
{
|
|
|
|
InsetGraphicsParams & igp = controller().params();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
igp.filename = dialog_->filename->text();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-10-31 20:05:55 +00:00
|
|
|
// the bb section
|
2002-08-08 03:50:54 +00:00
|
|
|
if (!controller().bbChanged) {
|
2002-10-31 20:05:55 +00:00
|
|
|
// don't write anything
|
2002-10-20 01:48:28 +00:00
|
|
|
igp.bb.erase();
|
2002-08-08 03:50:54 +00:00
|
|
|
} else {
|
2002-01-31 13:15:33 +00:00
|
|
|
string bb;
|
|
|
|
string lbX(dialog_->lbX->text());
|
|
|
|
string lbY(dialog_->lbY->text());
|
|
|
|
string rtX(dialog_->rtX->text());
|
|
|
|
string rtY(dialog_->rtY->text());
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
if (lbX.empty())
|
|
|
|
bb = "0 ";
|
|
|
|
else
|
2002-10-31 20:05:55 +00:00
|
|
|
bb = lbX + dialog_->lbXunit->currentText().latin1() + ' ';
|
2002-01-31 13:15:33 +00:00
|
|
|
if (lbY.empty())
|
|
|
|
bb += "0 ";
|
2002-10-31 20:05:55 +00:00
|
|
|
else
|
|
|
|
bb += (lbY + dialog_->lbYunit->currentText().latin1() + ' ');
|
2002-01-31 13:15:33 +00:00
|
|
|
if (rtX.empty())
|
|
|
|
bb += "0 ";
|
2002-10-31 20:05:55 +00:00
|
|
|
else
|
|
|
|
bb += (rtX + dialog_->rtXunit->currentText().latin1() + ' ');
|
2002-01-31 13:15:33 +00:00
|
|
|
if (rtY.empty())
|
2002-10-31 20:05:55 +00:00
|
|
|
bb += "0";
|
|
|
|
else
|
|
|
|
bb += (rtY + dialog_->rtYunit->currentText().latin1());
|
2002-01-31 13:15:33 +00:00
|
|
|
igp.bb = bb;
|
2001-08-28 03:35:17 +00:00
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-08-25 04:06:06 +00:00
|
|
|
igp.draft = dialog_->draftCB->isChecked();
|
2002-01-31 13:15:33 +00:00
|
|
|
igp.clip = dialog_->clip->isChecked();
|
|
|
|
igp.subcaption = dialog_->subfigure->isChecked();
|
|
|
|
igp.subcaptionText = dialog_->subcaption->text();
|
|
|
|
|
2002-08-25 04:06:06 +00:00
|
|
|
switch (dialog_->showCB->currentItem()) {
|
2002-08-24 22:02:30 +00:00
|
|
|
case 0: igp.display = grfx::DefaultDisplay; break;
|
|
|
|
case 1: igp.display = grfx::MonochromeDisplay; break;
|
|
|
|
case 2: igp.display = grfx::GrayscaleDisplay; break;
|
|
|
|
case 3: igp.display = grfx::ColorDisplay; break;
|
2001-08-28 03:35:17 +00:00
|
|
|
default:;
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-08-25 04:06:06 +00:00
|
|
|
if (!dialog_->displayCB->isChecked())
|
|
|
|
igp.display = grfx::NoDisplay;
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
string value(dialog_->width->text());
|
|
|
|
igp.width = LyXLength(strToDbl(value), dialog_->widthUnit->currentLengthItem());
|
|
|
|
value = string(dialog_->height->text());
|
|
|
|
igp.height = LyXLength(strToDbl(value), dialog_->heightUnit->currentLengthItem());
|
|
|
|
|
2002-08-08 03:50:54 +00:00
|
|
|
igp.keepAspectRatio = dialog_->aspectratio->isChecked();
|
2002-08-25 04:06:06 +00:00
|
|
|
|
|
|
|
igp.noUnzip = dialog_->unzipCB->isChecked();
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-08-08 03:50:54 +00:00
|
|
|
igp.lyxscale = strToInt(string(dialog_->displayscale->text()));
|
2002-01-31 13:15:33 +00:00
|
|
|
|
|
|
|
igp.rotateAngle = strToDbl(string(dialog_->angle->text()));
|
2002-08-25 04:06:06 +00:00
|
|
|
while (igp.rotateAngle < -360.0)
|
|
|
|
igp.rotateAngle += 360.0;
|
|
|
|
while (igp.rotateAngle > 360.0)
|
|
|
|
igp.rotateAngle -= 360.0;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
if ((dialog_->origin->currentItem()) > 0)
|
|
|
|
igp.rotateOrigin = dialog_->origin->currentText();
|
|
|
|
else
|
2002-10-20 01:48:28 +00:00
|
|
|
igp.rotateOrigin.erase();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
igp.special = dialog_->latexoptions->text();
|
2001-08-28 03:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QGraphics::browse()
|
|
|
|
{
|
2002-01-31 13:15:33 +00:00
|
|
|
string const & name = controller().Browse(dialog_->filename->text().latin1());
|
2001-08-28 03:35:17 +00:00
|
|
|
if (!name.empty())
|
2002-03-21 21:21:28 +00:00
|
|
|
dialog_->filename->setText(name.c_str());
|
2002-01-31 13:15:33 +00:00
|
|
|
}
|
|
|
|
|
2002-08-08 03:50:54 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
void QGraphics::get()
|
|
|
|
{
|
2002-08-08 03:50:54 +00:00
|
|
|
string const filename(dialog_->filename->text());
|
|
|
|
if (!filename.empty()) {
|
2002-10-30 17:13:09 +00:00
|
|
|
string const bb(controller().readBB(filename));
|
2002-08-08 03:50:54 +00:00
|
|
|
if (!bb.empty()) {
|
|
|
|
dialog_->lbX->setText(token(bb, ' ', 0).c_str());
|
|
|
|
dialog_->lbY->setText(token(bb, ' ', 1).c_str());
|
|
|
|
dialog_->rtX->setText(token(bb, ' ', 2).c_str());
|
|
|
|
dialog_->rtY->setText(token(bb, ' ', 3).c_str());
|
2002-10-31 20:05:55 +00:00
|
|
|
// the default units for the bb values when reading
|
|
|
|
// it from the file
|
|
|
|
dialog_->lbXunit->setCurrentItem(0);
|
|
|
|
dialog_->lbYunit->setCurrentItem(0);
|
|
|
|
dialog_->rtXunit->setCurrentItem(0);
|
|
|
|
dialog_->rtYunit->setCurrentItem(0);
|
2002-08-08 03:50:54 +00:00
|
|
|
}
|
|
|
|
controller().bbChanged = false;
|
2002-01-31 13:15:33 +00:00
|
|
|
}
|
2001-08-28 03:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool QGraphics::isValid()
|
|
|
|
{
|
2002-10-20 01:48:28 +00:00
|
|
|
// FIXME: we need more here.
|
2002-10-30 17:13:09 +00:00
|
|
|
// why?? LaTeX needs a filename, the rest is user-specific (Herbert)
|
2002-01-31 13:15:33 +00:00
|
|
|
return !string(dialog_->filename->text().latin1()).empty();
|
2001-08-28 03:35:17 +00:00
|
|
|
}
|