git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20804 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-10-06 22:16:14 +00:00
parent 868cb241a2
commit ff2356f7e6
6 changed files with 259 additions and 338 deletions

View File

@ -1,194 +0,0 @@
/**
* \file ControlGraphics.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
* \author Herbert Voß
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "ControlGraphics.h"
#include "frontend_helpers.h"
#include "FuncRequest.h"
#include "gettext.h"
#include "LyXRC.h"
#include "graphics/GraphicsCache.h"
#include "graphics/GraphicsCacheItem.h"
#include "graphics/GraphicsImage.h"
#include "support/convert.h"
#include "support/FileFilterList.h"
#include "support/filetools.h"
#include "support/Package.h"
#include "support/types.h"
#include <boost/filesystem/operations.hpp>
using std::make_pair;
using std::string;
using std::pair;
using std::vector;
namespace fs = boost::filesystem;
namespace lyx {
using support::addName;
using support::FileFilterList;
using support::FileName;
using support::isFileReadable;
using support::makeAbsPath;
using support::package;
using support::readBB_from_PSFile;
namespace frontend {
ControlGraphics::ControlGraphics(Dialog & parent)
: Controller(parent)
{}
bool ControlGraphics::initialiseParams(string const & data)
{
InsetGraphicsMailer::string2params(data, buffer(), params_);
return true;
}
void ControlGraphics::clearParams()
{
params_ = InsetGraphicsParams();
}
void ControlGraphics::dispatchParams()
{
InsetGraphicsParams tmp_params(params());
string const lfun =
InsetGraphicsMailer::params2string(tmp_params, buffer());
dispatch(FuncRequest(getLfun(), lfun));
}
docstring const ControlGraphics::browse(docstring const & in_name) const
{
docstring const title = _("Select graphics file");
// Does user clipart directory exist?
string clipdir = addName(package().user_support().absFilename(), "clipart");
string const encoded_clipdir = FileName(clipdir).toFilesystemEncoding();
if (!(fs::exists(encoded_clipdir) && fs::is_directory(encoded_clipdir)))
// No - bail out to system clipart directory
clipdir = addName(package().system_support().absFilename(), "clipart");
pair<docstring, docstring> dir1(_("Clipart|#C#c"), from_utf8(clipdir));
pair<docstring, docstring> dir2(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
// Show the file browser dialog
return browseRelFile(in_name, from_utf8(bufferFilepath()),
title, FileFilterList(), false, dir1, dir2);
}
string const ControlGraphics::readBB(string const & file)
{
FileName const abs_file(makeAbsPath(file, bufferFilepath()));
// try to get it from the file, if possible. Zipped files are
// unzipped in the readBB_from_PSFile-Function
string const bb = readBB_from_PSFile(abs_file);
if (!bb.empty())
return bb;
// we don't, so ask the Graphics Cache if it has loaded the file
int width = 0;
int height = 0;
graphics::Cache & gc = graphics::Cache::get();
if (gc.inCache(abs_file)) {
graphics::Image const * image = gc.item(abs_file)->image();
if (image) {
width = image->getWidth();
height = image->getHeight();
}
}
return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
}
bool ControlGraphics::isFilenameValid(string const & fname) const
{
// It may be that the filename is relative.
FileName const name(makeAbsPath(fname, bufferFilepath()));
return isFileReadable(name);
}
void ControlGraphics::editGraphics()
{
dialog().applyView();
string const lfun =
InsetGraphicsMailer::params2string(params(), buffer());
dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
}
namespace {
char const * const bb_units[] = { "bp", "cm", "mm", "in" };
size_t const bb_size = sizeof(bb_units) / sizeof(char *);
// These are the strings that are stored in the LyX file and which
// correspond to the LaTeX identifiers shown in the comments at the
// end of each line.
char const * const rorigin_lyx_strs[] = {
// the LaTeX default is leftBaseline
"",
"leftTop", "leftBottom", "leftBaseline", // lt lb lB
"center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
"rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
// These are the strings, corresponding to the above, that the GUI should
// use. Note that they can/should be translated.
char const * const rorigin_gui_strs[] = {
N_("Default"),
N_("Top left"), N_("Bottom left"), N_("Baseline left"),
N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
N_("Top right"), N_("Bottom right"), N_("Baseline right") };
size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
} // namespace anon
vector<string> const getBBUnits()
{
return vector<string>(bb_units, bb_units + bb_size);
}
vector<RotationOriginPair> getRotationOriginData()
{
static vector<RotationOriginPair> data;
if (!data.empty())
return data;
data.resize(rorigin_size);
for (size_type i = 0; i < rorigin_size; ++i) {
data[i] = make_pair(_(rorigin_gui_strs[i]),
rorigin_lyx_strs[i]);
}
return data;
}
} // namespace frontend
} // namespace lyx

View File

@ -1,81 +0,0 @@
// -*- C++ -*-
/**
* \file ControlGraphics.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Baruch Even
* \author Angus Leeming
* \author Herbert Voß
*
* Full author contact details are available in file CREDITS.
*/
#ifndef CONTROLGRAPHICS_H
#define CONTROLGRAPHICS_H
#include "Dialog.h"
#include "support/docstring.h"
#include "insets/InsetGraphics.h"
#include <utility>
#include <vector>
namespace lyx {
class InsetGraphics;
class InsetGraphicsParams;
namespace frontend {
class LyXView;
/** A controller for Graphics dialogs.
*/
class ControlGraphics : public Controller
{
public:
///
ControlGraphics(Dialog &);
///
virtual bool initialiseParams(std::string const & data);
/// clean-up on hide.
virtual void clearParams();
/// clean-up on hide.
virtual void dispatchParams();
///
virtual bool isBufferDependent() const { return true; }
///
InsetGraphicsParams & params() { return params_; }
///
InsetGraphicsParams const & params() const { return params_; }
/// Browse for a file
docstring const browse(docstring const &) const;
/// Read the Bounding Box from a eps or ps-file
std::string const readBB(std::string const & file);
/// Control the bb
bool bbChanged;
/// test if file exist
bool isFilenameValid(std::string const & fname) const;
/// edit file
void editGraphics();
private:
///
InsetGraphicsParams params_;
};
/// get the units for the bounding box
std::vector<std::string> const getBBUnits();
/// The (tranlated) GUI std::string and it's LaTeX equivalent.
typedef std::pair<docstring, std::string> RotationOriginPair;
///
std::vector<RotationOriginPair> getRotationOriginData();
} // namespace frontend
} // namespace lyx
#endif // CONTROLGRAPHICS_H

View File

@ -13,7 +13,6 @@ SOURCEFILES = \
ControlCommandBuffer.cpp \ ControlCommandBuffer.cpp \
ControlDocument.cpp \ ControlDocument.cpp \
ControlExternal.cpp \ ControlExternal.cpp \
ControlGraphics.cpp \
ControlMath.cpp \ ControlMath.cpp \
ControlParagraph.cpp \ ControlParagraph.cpp \
ControlPrefs.cpp \ ControlPrefs.cpp \
@ -25,7 +24,6 @@ HEADERFILES = \
ControlCommandBuffer.h \ ControlCommandBuffer.h \
ControlDocument.h \ ControlDocument.h \
ControlExternal.h \ ControlExternal.h \
ControlGraphics.h \
ControlMath.h \ ControlMath.h \
ControlParagraph.h \ ControlParagraph.h \
ControlPrefs.h \ ControlPrefs.h \

View File

@ -20,7 +20,6 @@
#include "GuiDelimiter.h" #include "GuiDelimiter.h"
#include "GuiDocument.h" #include "GuiDocument.h"
#include "GuiExternal.h" #include "GuiExternal.h"
#include "GuiGraphics.h"
#include "GuiIndex.h" #include "GuiIndex.h"
#include "GuiMathMatrix.h" #include "GuiMathMatrix.h"
#include "GuiNomencl.h" #include "GuiNomencl.h"
@ -165,7 +164,7 @@ Dialog * Dialogs::build(string const & name)
if (name == "float") if (name == "float")
return createGuiFloat(lyxview_); return createGuiFloat(lyxview_);
if (name == "graphics") if (name == "graphics")
return new GuiGraphicsDialog(lyxview_); return createGuiGraphics(lyxview_);
if (name == "include") if (name == "include")
return createGuiInclude(lyxview_); return createGuiInclude(lyxview_);
if (name == "index") if (name == "index")

View File

@ -3,6 +3,7 @@
* This file is part of LyX, the document processor. * This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
* \author Angus Leeming
* \author John Levon * \author John Levon
* \author Edwin Leuven * \author Edwin Leuven
* \author Herbert Voß * \author Herbert Voß
@ -15,22 +16,35 @@
#include "GuiGraphics.h" #include "GuiGraphics.h"
#include "ControlGraphics.h" #include "GuiGraphics.h"
#include "debug.h" #include "debug.h"
#include "LengthCombo.h" #include "LengthCombo.h"
#include "lengthcommon.h" #include "lengthcommon.h"
#include "LyXRC.h" #include "LyXRC.h"
#include "qt_helpers.h" #include "qt_helpers.h"
#include "Validator.h" #include "Validator.h"
#include "frontend_helpers.h"
#include "FuncRequest.h"
#include "gettext.h"
#include "graphics/GraphicsCache.h"
#include "graphics/GraphicsCacheItem.h"
#include "graphics/GraphicsImage.h"
#include "insets/InsetGraphicsParams.h" #include "insets/InsetGraphicsParams.h"
#include "support/convert.h" #include "support/convert.h"
#include "support/FileFilterList.h"
#include "support/filetools.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/lyxlib.h" #include "support/lyxlib.h"
#include "support/os.h" #include "support/os.h"
#include "support/Package.h"
#include "support/types.h"
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/filesystem/operations.hpp>
#include <QCheckBox> #include <QCheckBox>
#include <QCloseEvent> #include <QCloseEvent>
@ -43,24 +57,33 @@
#include <cmath> #include <cmath>
#include <utility> #include <utility>
using lyx::support::float_equal;
using lyx::support::token;
using lyx::support::os::internal_path;
using std::find;
#ifndef CXX_GLOBAL_CSTD #ifndef CXX_GLOBAL_CSTD
using std::floor; using std::floor;
#endif #endif
using std::find;
using std::vector; using std::vector;
using std::string; using std::string;
using std::transform; using std::transform;
using std::make_pair;
using std::pair;
using std::vector;
namespace fs = boost::filesystem;
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
using support::addName;
using support::FileFilterList;
using support::FileName;
using support::float_equal;
using support::isFileReadable;
using support::makeAbsPath;
using support::os::internal_path;
using support::package;
using support::readBB_from_PSFile;
using support::token;
//FIXME setAutoTextCB should really take an argument, as indicated, that //FIXME setAutoTextCB should really take an argument, as indicated, that
//determines what text is to be written for "auto". But making //determines what text is to be written for "auto". But making
@ -111,12 +134,12 @@ getSecond(vector<Pair> const & pr)
return tmp; return tmp;
} }
GuiGraphicsDialog::GuiGraphicsDialog(LyXView & lv) GuiGraphics::GuiGraphics(LyXView & lv)
: GuiDialog(lv, "graphics") : GuiDialog(lv, "graphics"), Controller(this)
{ {
setupUi(this); setupUi(this);
setViewTitle(_("Graphics")); setViewTitle(_("Graphics"));
setController(new ControlGraphics(*this)); setController(this, false);
//main buttons //main buttons
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
@ -253,38 +276,30 @@ GuiGraphicsDialog::GuiGraphicsDialog(LyXView & lv)
} }
ControlGraphics & GuiGraphicsDialog::controller() void GuiGraphics::change_adaptor()
{
return static_cast<ControlGraphics &>(GuiDialog::controller());
}
void GuiGraphicsDialog::change_adaptor()
{ {
changed(); changed();
} }
void GuiGraphicsDialog::change_bb() void GuiGraphics::change_bb()
{ {
controller().bbChanged = true; bbChanged = true;
LYXERR(Debug::GRAPHICS) LYXERR(Debug::GRAPHICS) << "[bb_Changed set to true]\n";
<< "[controller().bb_Changed set to true]\n";
changed(); changed();
} }
void GuiGraphicsDialog::closeEvent(QCloseEvent * e) void GuiGraphics::closeEvent(QCloseEvent * e)
{ {
slotClose(); slotClose();
GuiDialog::closeEvent(e); GuiDialog::closeEvent(e);
} }
void GuiGraphicsDialog::on_browsePB_clicked() void GuiGraphics::on_browsePB_clicked()
{ {
docstring const str = docstring const str = browse(qstring_to_ucs4(filename->text()));
controller().browse(qstring_to_ucs4(filename->text()));
if (!str.empty()) { if (!str.empty()) {
filename->setText(toqstr(str)); filename->setText(toqstr(str));
embedCB->setCheckState(Qt::Unchecked); embedCB->setCheckState(Qt::Unchecked);
@ -293,25 +308,25 @@ void GuiGraphicsDialog::on_browsePB_clicked()
} }
void GuiGraphicsDialog::on_getPB_clicked() void GuiGraphics::on_getPB_clicked()
{ {
getBB(); getBB();
} }
void GuiGraphicsDialog::on_editPB_clicked() void GuiGraphics::on_editPB_clicked()
{ {
controller().editGraphics(); editGraphics();
} }
void GuiGraphicsDialog::on_filename_textChanged(const QString & filename) void GuiGraphics::on_filename_textChanged(const QString & filename)
{ {
editPB->setDisabled(filename.isEmpty()); editPB->setDisabled(filename.isEmpty());
} }
void GuiGraphicsDialog::setAutoText() void GuiGraphics::setAutoText()
{ {
if (scaleCB->isChecked()) if (scaleCB->isChecked())
return; return;
@ -323,7 +338,7 @@ void GuiGraphicsDialog::setAutoText()
} }
void GuiGraphicsDialog::on_scaleCB_toggled(bool setScale) void GuiGraphics::on_scaleCB_toggled(bool setScale)
{ {
Scale->setEnabled(setScale); Scale->setEnabled(setScale);
if (setScale) { if (setScale) {
@ -357,7 +372,7 @@ void GuiGraphicsDialog::on_scaleCB_toggled(bool setScale)
} }
void GuiGraphicsDialog::on_WidthCB_toggled(bool setWidth) void GuiGraphics::on_WidthCB_toggled(bool setWidth)
{ {
Width->setEnabled(setWidth); Width->setEnabled(setWidth);
widthUnit->setEnabled(setWidth); widthUnit->setEnabled(setWidth);
@ -382,7 +397,7 @@ void GuiGraphicsDialog::on_WidthCB_toggled(bool setWidth)
} }
void GuiGraphicsDialog::on_HeightCB_toggled(bool setHeight) void GuiGraphics::on_HeightCB_toggled(bool setHeight)
{ {
Height->setEnabled(setHeight); Height->setEnabled(setHeight);
heightUnit->setEnabled(setHeight); heightUnit->setEnabled(setHeight);
@ -407,7 +422,7 @@ void GuiGraphicsDialog::on_HeightCB_toggled(bool setHeight)
} }
void GuiGraphicsDialog::on_angle_textChanged(const QString & filename) void GuiGraphics::on_angle_textChanged(const QString & filename)
{ {
rotateOrderCB->setEnabled((WidthCB->isChecked() || rotateOrderCB->setEnabled((WidthCB->isChecked() ||
HeightCB->isChecked() || HeightCB->isChecked() ||
@ -424,7 +439,7 @@ static int getItemNo(const vector<string> & v, string const & s)
} }
void GuiGraphicsDialog::updateContents() void GuiGraphics::updateContents()
{ {
// clear and fill in the comboboxes // clear and fill in the comboboxes
vector<string> const bb_units = frontend::getBBUnits(); vector<string> const bb_units = frontend::getBBUnits();
@ -440,7 +455,7 @@ void GuiGraphicsDialog::updateContents()
rtYunit->addItem(toqstr(*it)); rtYunit->addItem(toqstr(*it));
} }
InsetGraphicsParams & igp = controller().params(); InsetGraphicsParams & igp = params_;
// set the right default unit // set the right default unit
Length::UNIT unitDefault = Length::CM; Length::UNIT unitDefault = Length::CM;
@ -455,13 +470,13 @@ void GuiGraphicsDialog::updateContents()
} }
string const name = string const name =
igp.filename.outputFilename(controller().bufferFilepath()); igp.filename.outputFilename(bufferFilepath());
filename->setText(toqstr(name)); filename->setText(toqstr(name));
embedCB->setCheckState(igp.filename.embedded() ? Qt::Checked : Qt::Unchecked); embedCB->setCheckState(igp.filename.embedded() ? Qt::Checked : Qt::Unchecked);
// set the bounding box values // set the bounding box values
if (igp.bb.empty()) { if (igp.bb.empty()) {
string const bb = controller().readBB(igp.filename.absFilename()); string const bb = readBB(igp.filename.absFilename());
// the values from the file always have the bigpoint-unit bp // the values from the file always have the bigpoint-unit bp
lbX->setText(toqstr(token(bb, ' ', 0))); lbX->setText(toqstr(token(bb, ' ', 0)));
lbY->setText(toqstr(token(bb, ' ', 1))); lbY->setText(toqstr(token(bb, ' ', 1)));
@ -471,14 +486,14 @@ void GuiGraphicsDialog::updateContents()
lbYunit->setCurrentIndex(0); lbYunit->setCurrentIndex(0);
rtXunit->setCurrentIndex(0); rtXunit->setCurrentIndex(0);
rtYunit->setCurrentIndex(0); rtYunit->setCurrentIndex(0);
controller().bbChanged = false; bbChanged = false;
} else { } else {
// get the values from the inset // get the values from the inset
Length anyLength; Length anyLength;
string const xl(token(igp.bb, ' ', 0)); string const xl = token(igp.bb, ' ', 0);
string const yl(token(igp.bb, ' ', 1)); string const yl = token(igp.bb, ' ', 1);
string const xr(token(igp.bb, ' ', 2)); string const xr = token(igp.bb, ' ', 2);
string const yr(token(igp.bb, ' ', 3)); string const yr = token(igp.bb, ' ', 3);
if (isValidLength(xl, &anyLength)) { if (isValidLength(xl, &anyLength)) {
lbX->setText(toqstr(convert<string>(anyLength.value()))); lbX->setText(toqstr(convert<string>(anyLength.value())));
string const unit(unit_name[anyLength.unit()]); string const unit(unit_name[anyLength.unit()]);
@ -507,7 +522,7 @@ void GuiGraphicsDialog::updateContents()
} else { } else {
rtY->setText(toqstr(xl)); rtY->setText(toqstr(xl));
} }
controller().bbChanged = true; bbChanged = true;
} }
// Update the draft and clip mode // Update the draft and clip mode
@ -598,17 +613,17 @@ void GuiGraphicsDialog::updateContents()
} }
void GuiGraphicsDialog::applyView() void GuiGraphics::applyView()
{ {
InsetGraphicsParams & igp = controller().params(); InsetGraphicsParams & igp = params_;
igp.filename.set(internal_path(fromqstr(filename->text())), igp.filename.set(internal_path(fromqstr(filename->text())),
controller().bufferFilepath()); bufferFilepath());
igp.filename.setEmbed(embedCB->checkState() == Qt::Checked); igp.filename.setEmbed(embedCB->checkState() == Qt::Checked);
// the bb section // the bb section
igp.bb.erase(); igp.bb.erase();
if (controller().bbChanged) { if (bbChanged) {
string bb; string bb;
string lbXs = fromqstr(lbX->text()); string lbXs = fromqstr(lbX->text());
string lbYs = fromqstr(lbY->text()); string lbYs = fromqstr(lbY->text());
@ -695,11 +710,11 @@ void GuiGraphicsDialog::applyView()
} }
void GuiGraphicsDialog::getBB() void GuiGraphics::getBB()
{ {
string const fn = fromqstr(filename->text()); string const fn = fromqstr(filename->text());
if (!fn.empty()) { if (!fn.empty()) {
string const bb = controller().readBB(fn); string const bb = readBB(fn);
if (!bb.empty()) { if (!bb.empty()) {
lbX->setText(toqstr(token(bb, ' ', 0))); lbX->setText(toqstr(token(bb, ' ', 0)));
lbY->setText(toqstr(token(bb, ' ', 1))); lbY->setText(toqstr(token(bb, ' ', 1)));
@ -712,18 +727,156 @@ void GuiGraphicsDialog::getBB()
rtXunit->setCurrentIndex(0); rtXunit->setCurrentIndex(0);
rtYunit->setCurrentIndex(0); rtYunit->setCurrentIndex(0);
} }
controller().bbChanged = false; bbChanged = false;
} }
} }
bool GuiGraphicsDialog::isValid() bool GuiGraphics::isValid()
{ {
return !filename->text().isEmpty(); return !filename->text().isEmpty();
} }
bool GuiGraphics::initialiseParams(string const & data)
{
InsetGraphicsMailer::string2params(data, buffer(), params_);
return true;
}
void GuiGraphics::clearParams()
{
params_ = InsetGraphicsParams();
}
void GuiGraphics::dispatchParams()
{
InsetGraphicsParams tmp_params(params_);
string const lfun =
InsetGraphicsMailer::params2string(tmp_params, buffer());
dispatch(FuncRequest(getLfun(), lfun));
}
docstring const GuiGraphics::browse(docstring const & in_name) const
{
docstring const title = _("Select graphics file");
// Does user clipart directory exist?
string clipdir = addName(package().user_support().absFilename(), "clipart");
string const encoded_clipdir = FileName(clipdir).toFilesystemEncoding();
if (!(fs::exists(encoded_clipdir) && fs::is_directory(encoded_clipdir)))
// No - bail out to system clipart directory
clipdir = addName(package().system_support().absFilename(), "clipart");
pair<docstring, docstring> dir1(_("Clipart|#C#c"), from_utf8(clipdir));
pair<docstring, docstring> dir2(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
// Show the file browser dialog
return browseRelFile(in_name, from_utf8(bufferFilepath()),
title, FileFilterList(), false, dir1, dir2);
}
string const GuiGraphics::readBB(string const & file)
{
FileName const abs_file(makeAbsPath(file, bufferFilepath()));
// try to get it from the file, if possible. Zipped files are
// unzipped in the readBB_from_PSFile-Function
string const bb = readBB_from_PSFile(abs_file);
if (!bb.empty())
return bb;
// we don't, so ask the Graphics Cache if it has loaded the file
int width = 0;
int height = 0;
graphics::Cache & gc = graphics::Cache::get();
if (gc.inCache(abs_file)) {
graphics::Image const * image = gc.item(abs_file)->image();
if (image) {
width = image->getWidth();
height = image->getHeight();
}
}
return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
}
bool GuiGraphics::isFilenameValid(string const & fname) const
{
// It may be that the filename is relative.
FileName const name(makeAbsPath(fname, bufferFilepath()));
return isFileReadable(name);
}
void GuiGraphics::editGraphics()
{
dialog().applyView();
string const lfun =
InsetGraphicsMailer::params2string(params_, buffer());
dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
}
namespace {
char const * const bb_units[] = { "bp", "cm", "mm", "in" };
size_t const bb_size = sizeof(bb_units) / sizeof(char *);
// These are the strings that are stored in the LyX file and which
// correspond to the LaTeX identifiers shown in the comments at the
// end of each line.
char const * const rorigin_lyx_strs[] = {
// the LaTeX default is leftBaseline
"",
"leftTop", "leftBottom", "leftBaseline", // lt lb lB
"center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
"rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
// These are the strings, corresponding to the above, that the GUI should
// use. Note that they can/should be translated.
char const * const rorigin_gui_strs[] = {
N_("Default"),
N_("Top left"), N_("Bottom left"), N_("Baseline left"),
N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
N_("Top right"), N_("Bottom right"), N_("Baseline right") };
size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
} // namespace anon
vector<string> const getBBUnits()
{
return vector<string>(bb_units, bb_units + bb_size);
}
vector<RotationOriginPair> getRotationOriginData()
{
static vector<RotationOriginPair> data;
if (!data.empty())
return data;
data.resize(rorigin_size);
for (size_type i = 0; i < rorigin_size; ++i) {
data[i] = make_pair(_(rorigin_gui_strs[i]),
rorigin_lyx_strs[i]);
}
return data;
}
Dialog * createGuiGraphics(LyXView & lv) { return new GuiGraphics(lv); }
} // namespace frontend } // namespace frontend
} // namespace lyx } // namespace lyx
#include "GuiGraphics_moc.cpp" #include "GuiGraphics_moc.cpp"

View File

@ -6,6 +6,8 @@
* *
* \author John Levon * \author John Levon
* \author Herbert Voß * \author Herbert Voß
* \author Baruch Even
* \author Angus Leeming
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -14,22 +16,33 @@
#define GUIGRAPHICS_H #define GUIGRAPHICS_H
#include "GuiDialog.h" #include "GuiDialog.h"
#include "ControlGraphics.h"
#include "ui_GraphicsUi.h" #include "ui_GraphicsUi.h"
#include "support/docstring.h"
#include "insets/InsetGraphics.h"
#include <utility>
#include <vector> #include <vector>
class QString; class QString;
namespace lyx { namespace lyx {
class InsetGraphics;
class InsetGraphicsParams;
namespace frontend { namespace frontend {
class GuiGraphicsDialog : public GuiDialog, public Ui::GraphicsUi class LyXView;
class GuiGraphics : public GuiDialog, public Ui::GraphicsUi, public Controller
{ {
Q_OBJECT Q_OBJECT
public: public:
GuiGraphicsDialog(LyXView & lv); GuiGraphics(LyXView & lv);
void setAutoText(); void setAutoText();
private Q_SLOTS: private Q_SLOTS:
void change_adaptor(); void change_adaptor();
void change_bb(); void change_bb();
@ -41,10 +54,11 @@ private Q_SLOTS:
void on_WidthCB_toggled(bool); void on_WidthCB_toggled(bool);
void on_HeightCB_toggled(bool); void on_HeightCB_toggled(bool);
void on_angle_textChanged(const QString &); void on_angle_textChanged(const QString &);
private: private:
void closeEvent(QCloseEvent * e); void closeEvent(QCloseEvent * e);
/// parent controller /// parent controller
ControlGraphics & controller(); Controller & controller() { return *this; }
bool isValid(); bool isValid();
/// Apply changes /// Apply changes
void applyView(); void applyView();
@ -55,8 +69,40 @@ private:
/// Store the LaTeX names for the rotation origins. /// Store the LaTeX names for the rotation origins.
std::vector<std::string> origin_ltx; std::vector<std::string> origin_ltx;
///
bool initialiseParams(std::string const & data);
/// clean-up on hide.
void clearParams();
/// clean-up on hide.
void dispatchParams();
///
bool isBufferDependent() const { return true; }
/// Browse for a file
docstring const browse(docstring const &) const;
/// Read the Bounding Box from a eps or ps-file
std::string const readBB(std::string const & file);
/// Control the bb
bool bbChanged;
/// test if file exist
bool isFilenameValid(std::string const & fname) const;
/// edit file
void editGraphics();
private:
///
InsetGraphicsParams params_;
}; };
/// get the units for the bounding box
std::vector<std::string> const getBBUnits();
/// The (tranlated) GUI std::string and it's LaTeX equivalent.
typedef std::pair<docstring, std::string> RotationOriginPair;
///
std::vector<RotationOriginPair> getRotationOriginData();
} // namespace frontend } // namespace frontend
} // namespace lyx } // namespace lyx