2001-08-28 03:35:17 +00:00
|
|
|
/**
|
|
|
|
* \file QGraphics.C
|
|
|
|
* Copyright 2001 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author John Levon <moz@compsoc.man.ac.uk>
|
2002-01-31 13:15:33 +00:00
|
|
|
* \author Edwin Leuven <leuven@fee.uva.nl>
|
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"
|
|
|
|
#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
|
|
|
|
2001-08-28 03:35:17 +00:00
|
|
|
|
|
|
|
typedef Qt2CB<ControlGraphics, Qt2DB<QGraphicsDialog> > base_class;
|
|
|
|
|
2002-07-11 01:01:38 +00:00
|
|
|
QGraphics::QGraphics(ControlGraphics & c, Dialogs &)
|
2001-08-28 03:35:17 +00:00
|
|
|
: base_class(c, _("Graphics"))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QGraphics::build_dialog()
|
|
|
|
{
|
|
|
|
dialog_.reset(new QGraphicsDialog(this));
|
|
|
|
|
|
|
|
bc().setOK(dialog_->okPB);
|
|
|
|
bc().setApply(dialog_->applyPB);
|
|
|
|
bc().setCancel(dialog_->closePB);
|
2002-01-31 13:15:33 +00:00
|
|
|
bc().setRestore(dialog_->restorePB);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
bc().addReadOnly(dialog_->rotateGB);
|
|
|
|
bc().addReadOnly(dialog_->latexoptionsGB);
|
|
|
|
bc().addReadOnly(dialog_->bbGB);
|
|
|
|
bc().addReadOnly(dialog_->sizeBG);
|
|
|
|
bc().addReadOnly(dialog_->displayGB);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QGraphics::update_contents()
|
|
|
|
{
|
|
|
|
InsetGraphicsParams & igp = controller().params();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
string unit = "cm";
|
|
|
|
if (lyxrc.default_papersize < 3)
|
|
|
|
unit = "in";
|
|
|
|
string const defaultUnit = string(unit);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
// Update dialog with details from inset
|
|
|
|
dialog_->filename->setText(igp.filename.c_str());
|
|
|
|
|
|
|
|
// set the bounding box values, if exists. First we need the whole
|
|
|
|
// path, because the controller knows nothing about the doc-dir
|
|
|
|
controller().bbChanged = false;
|
|
|
|
if (igp.bb.empty()) {
|
2002-03-21 21:21:28 +00:00
|
|
|
string const fileWithAbsPath = MakeAbsPath(igp.filename, OnlyPath(igp.filename));
|
2002-01-31 13:15:33 +00:00
|
|
|
string bb = controller().readBB(fileWithAbsPath);
|
|
|
|
if (!bb.empty()) {
|
|
|
|
// get the values from the file
|
|
|
|
// in this case we 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());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// get the values from the inset
|
|
|
|
controller().bbChanged = true;
|
|
|
|
dialog_->lbX->setText(token(igp.bb,' ',0).c_str());
|
|
|
|
dialog_->lbY->setText(token(igp.bb,' ',1).c_str());
|
|
|
|
dialog_->rtX->setText(token(igp.bb,' ',2).c_str());
|
|
|
|
dialog_->rtY->setText(token(igp.bb,' ',3).c_str());
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
// Update the draft and clip mode
|
|
|
|
dialog_->draft->setChecked(igp.draft);
|
|
|
|
dialog_->clip->setChecked(igp.clip);
|
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
|
|
|
|
|
|
|
switch (igp.display) {
|
2002-01-31 13:15:33 +00:00
|
|
|
case InsetGraphicsParams::MONOCHROME: {
|
|
|
|
dialog_->show->setCurrentItem(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case InsetGraphicsParams::GRAYSCALE: {
|
|
|
|
dialog_->show->setCurrentItem(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case InsetGraphicsParams::COLOR: {
|
|
|
|
dialog_->show->setCurrentItem(2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case InsetGraphicsParams::NONE: {
|
|
|
|
dialog_->show->setCurrentItem(3);
|
|
|
|
break;
|
|
|
|
}
|
2001-08-28 03:35:17 +00:00
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
dialog_->widthUnit->setCurrentItem(igp.width.unit());
|
|
|
|
dialog_->heightUnit->setCurrentItem(igp.height.unit());
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
switch (igp.size_type) {
|
|
|
|
case InsetGraphicsParams::DEFAULT_SIZE: {
|
|
|
|
dialog_->defaultRB->setChecked(TRUE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case InsetGraphicsParams::WH: {
|
|
|
|
dialog_->customRB->setChecked(TRUE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case InsetGraphicsParams::SCALE: {
|
|
|
|
dialog_->scaleRB->setChecked(TRUE);
|
|
|
|
dialog_->scale->setText(tostr(igp.scale).c_str());
|
|
|
|
break;
|
|
|
|
}
|
2001-08-28 03:35:17 +00:00
|
|
|
}
|
2002-01-31 13:15:33 +00:00
|
|
|
|
|
|
|
// aspect ratio
|
|
|
|
dialog_->aspectratio->setChecked(igp.keepAspectRatio);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
// now the lyx-internally viewsize
|
|
|
|
dialog_->displaywidthUnit->setCurrentItem(igp.lyxwidth.unit());
|
|
|
|
dialog_->displayheightUnit->setCurrentItem(igp.lyxheight.unit());
|
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 {
|
|
|
|
//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()
|
|
|
|
{
|
2002-01-31 13:15:33 +00:00
|
|
|
// Create the parameters structure and fill the data from the dialog.
|
2001-08-28 03:35:17 +00:00
|
|
|
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-02-06 10:58:08 +00:00
|
|
|
if (!controller().bbChanged) // different to the original one?
|
2002-03-21 21:21:28 +00:00
|
|
|
igp.bb = string(); // don't write anything
|
2002-01-31 13:15:33 +00:00
|
|
|
else {
|
|
|
|
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
|
|
|
|
bb = lbX + " ";
|
|
|
|
if (lbY.empty())
|
|
|
|
bb += "0 ";
|
|
|
|
else
|
|
|
|
bb += (lbY + " ");
|
|
|
|
if (rtX.empty())
|
|
|
|
bb += "0 ";
|
|
|
|
else
|
|
|
|
bb += (rtX + " ");
|
|
|
|
if (rtY.empty())
|
|
|
|
bb += "0 ";
|
|
|
|
else
|
|
|
|
bb += (rtY + " ");
|
|
|
|
|
|
|
|
igp.bb = bb;
|
2001-08-28 03:35:17 +00:00
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
igp.draft = dialog_->draft->isChecked();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
igp.clip = dialog_->clip->isChecked();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
igp.subcaption = dialog_->subfigure->isChecked();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
igp.subcaptionText = dialog_->subcaption->text();
|
|
|
|
|
|
|
|
switch(dialog_->show->currentItem()) {
|
|
|
|
case 0: igp.display = InsetGraphicsParams::MONOCHROME; break;
|
|
|
|
case 1: igp.display = InsetGraphicsParams::GRAYSCALE; break;
|
|
|
|
case 2: igp.display = InsetGraphicsParams::COLOR; break;
|
|
|
|
case 3: igp.display = InsetGraphicsParams::NONE; break;
|
2001-08-28 03:35:17 +00:00
|
|
|
default:;
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
if (dialog_->defaultRB->isChecked())
|
|
|
|
igp.size_type = InsetGraphicsParams::DEFAULT_SIZE;
|
|
|
|
else if (dialog_->customRB->isChecked())
|
|
|
|
igp.size_type = InsetGraphicsParams::WH;
|
|
|
|
else
|
|
|
|
igp.size_type = InsetGraphicsParams::SCALE;
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
value = string(dialog_->displaywidth->text());
|
|
|
|
igp.lyxwidth = LyXLength(strToDbl(value), dialog_->displaywidthUnit->currentLengthItem());
|
2001-08-28 03:35:17 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
value = string(dialog_->displayheight->text());
|
|
|
|
igp.lyxheight = LyXLength(strToDbl(value), dialog_->displayheightUnit->currentLengthItem());
|
2001-08-28 03:35:17 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
igp.scale = strToInt(string(dialog_->scale->text()));
|
2001-08-28 03:35:17 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
igp.keepAspectRatio = dialog_->aspectratio->isChecked();
|
|
|
|
|
|
|
|
igp.rotateAngle = strToDbl(string(dialog_->angle->text()));
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
while (igp.rotateAngle < 0.0 || igp.rotateAngle > 360.0) {
|
|
|
|
if (igp.rotateAngle < 0.0) {
|
|
|
|
igp.rotateAngle += 360.0;
|
|
|
|
} else if (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
|
|
|
|
igp.rotateOrigin = string();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-31 13:15:33 +00:00
|
|
|
igp.special = dialog_->latexoptions->text();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void QGraphics::get()
|
|
|
|
{
|
|
|
|
string const filename(dialog_->filename->text());
|
|
|
|
if (!filename.empty()) {
|
2002-03-21 21:21:28 +00:00
|
|
|
string const fileWithAbsPath = MakeAbsPath(filename, OnlyPath(filename));
|
2002-01-31 13:15:33 +00:00
|
|
|
string bb = controller().readBB(fileWithAbsPath);
|
2002-03-21 21:21:28 +00:00
|
|
|
if (!bb.empty()) {
|
2002-01-31 13:15:33 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
controller().bbChanged = false;
|
|
|
|
}
|
2001-08-28 03:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool QGraphics::isValid()
|
|
|
|
{
|
2002-01-31 13:15:33 +00:00
|
|
|
return !string(dialog_->filename->text().latin1()).empty();
|
2001-08-28 03:35:17 +00:00
|
|
|
}
|