Herbert's bb units fix

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5567 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2002-10-31 20:05:55 +00:00
parent 23c5fe9f30
commit 1690d45d92
8 changed files with 155 additions and 28 deletions

View File

@ -1,3 +1,8 @@
2002-10-31 John Levon <levon@movementarian.org>
* ControlGraphics.h:
* ControlGraphics.C: bb units from Herbert
2002-10-29 Rob Lahaye <lahaye@snu.ac.kr>
* ControlParagraph.[Ch] (alignDefault): new method, returning the

View File

@ -133,6 +133,28 @@ bool ControlGraphics::isFilenameValid(string const & fname) const
}
namespace {
static char const * bb_units[] = { "bp", "cm", "mm", "in"};
size_t const bb_size = sizeof(bb_units) / sizeof(char *);
}
vector<string> const ControlGraphics::getUnits()
{
static vector<string> data;
if (!data.empty())
return data;
data.resize(bb_size);
for (lyx::size_type i = 0; i < bb_size; ++i) {
data[i] = bb_units[i];
}
return data;
}
namespace frnt {
namespace {

View File

@ -32,6 +32,7 @@ class LyXView;
/** A controller for Graphics dialogs.
*/
class ControlGraphics
: public ControlInset<InsetGraphics, InsetGraphicsParams> {
public:
@ -46,6 +47,8 @@ public:
bool bbChanged;
/// test if file exist
bool isFilenameValid(string const & fname) const;
/// get the units for the bb
std::vector<string> const getUnits();
private:
/// Dispatch the changed parameters to the kernel.

View File

@ -1,3 +1,10 @@
2002-10-31 John Levon <levon@movementarian.org>
* qt2/QGraphics.C:
* qt2/QGraphicsDialog.C:
* qt2/QGraphicsDialog.h:
* qt2/ui/QGraphicsDialog.ui: bb unit fixes
2002-10-30 John Levon <levon@movementarian.org>
* QPrintDialog.[hC]: move to ...

View File

@ -5,6 +5,7 @@
*
* \author John Levon
* \author Edwin Leuven
* \author Herbert Voss
*
* Full author contact details are available in file CREDITS
*/
@ -25,6 +26,8 @@
#include "lyxrc.h"
#include "lengthcombo.h"
#include "gettext.h"
#include "lengthcommon.h"
#include "lyxlength.h"
#include "debug.h"
#include <qlineedit.h>
@ -40,6 +43,7 @@
#include "QGraphics.h"
#include "Qt2BC.h"
using std::vector;
typedef Qt2CB<ControlGraphics, Qt2DB<QGraphicsDialog> > base_class;
@ -96,8 +100,33 @@ void QGraphics::build_dialog()
}
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;
}
}
void QGraphics::update_contents()
{
// 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);
}
InsetGraphicsParams & igp = controller().params();
// set the right default unit
@ -121,24 +150,51 @@ void QGraphics::update_contents()
dialog_->filename->setText(igp.filename.c_str());
controller().bbChanged = false;
// set the bounding box values
if (igp.bb.empty()) {
string const bb(controller().readBB(igp.filename));
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());
}
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());
} 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());
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());
}
}
// Update the draft and clip mode
@ -188,7 +244,9 @@ void QGraphics::apply()
igp.filename = dialog_->filename->text();
// the bb section
if (!controller().bbChanged) {
// don't write anything
igp.bb.erase();
} else {
string bb;
@ -200,20 +258,19 @@ void QGraphics::apply()
if (lbX.empty())
bb = "0 ";
else
bb = lbX + " ";
bb = lbX + dialog_->lbXunit->currentText().latin1() + ' ';
if (lbY.empty())
bb += "0 ";
else
bb += (lbY + " ");
else
bb += (lbY + dialog_->lbYunit->currentText().latin1() + ' ');
if (rtX.empty())
bb += "0 ";
else
bb += (rtX + " ");
else
bb += (rtX + dialog_->rtXunit->currentText().latin1() + ' ');
if (rtY.empty())
bb += "0 ";
else
bb += (rtY + " ");
bb += "0";
else
bb += (rtY + dialog_->rtYunit->currentText().latin1());
igp.bb = bb;
}
@ -277,6 +334,12 @@ void QGraphics::get()
dialog_->lbY->setText(token(bb, ' ', 1).c_str());
dialog_->rtX->setText(token(bb, ' ', 2).c_str());
dialog_->rtY->setText(token(bb, ' ', 3).c_str());
// 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);
}
controller().bbChanged = false;
}

View File

@ -57,6 +57,13 @@ void QGraphicsDialog::change_adaptor()
}
void QGraphicsDialog::change_bb()
{
form_->controller().bbChanged = true;
form_->changed();
}
void QGraphicsDialog::closeEvent(QCloseEvent * e)
{
form_->slotWMHide();

View File

@ -28,6 +28,7 @@ public:
virtual void show();
protected slots:
virtual void change_adaptor();
virtual void change_bb();
virtual void browse_clicked();
virtual void get_clicked();
protected:

View File

@ -1377,31 +1377,49 @@
<sender>lbX</sender>
<signal>textChanged(const QString&amp;)</signal>
<receiver>QGraphicsDialogBase</receiver>
<slot>change_adaptor()</slot>
<slot>change_bb()</slot>
</connection>
<connection>
<sender>lbY</sender>
<signal>textChanged(const QString&amp;)</signal>
<receiver>QGraphicsDialogBase</receiver>
<slot>change_bb()</slot>
</connection>
<connection>
<sender>rtX</sender>
<signal>textChanged(const QString&amp;)</signal>
<receiver>QGraphicsDialogBase</receiver>
<slot>change_bb()</slot>
</connection>
<connection>
<sender>rtY</sender>
<signal>textChanged(const QString&amp;)</signal>
<receiver>QGraphicsDialogBase</receiver>
<slot>change_bb()</slot>
</connection>
<connection>
<sender>lbXunit</sender>
<signal>activated(int)</signal>
<receiver>QGraphicsDialogBase</receiver>
<slot>change_adaptor()</slot>
<slot>change_bb()</slot>
</connection>
<connection>
<sender>lbYunit</sender>
<signal>activated(int)</signal>
<receiver>QGraphicsDialogBase</receiver>
<slot>change_adaptor()</slot>
<slot>change_bb()</slot>
</connection>
<connection>
<sender>rtXunit</sender>
<signal>activated(int)</signal>
<receiver>QGraphicsDialogBase</receiver>
<slot>change_adaptor()</slot>
<slot>change_bb()</slot>
</connection>
<connection>
<sender>rtYunit</sender>
<signal>activated(int)</signal>
<receiver>QGraphicsDialogBase</receiver>
<slot>change_adaptor()</slot>
<slot>change_bb()</slot>
</connection>
<connection>
<sender>showCB</sender>
@ -1526,6 +1544,7 @@
<slot access="protected">browse_clicked()</slot>
<slot access="protected">get_clicked()</slot>
<slot access="protected">change_adaptor()</slot>
<slot access="protected">change_bb()</slot>
</connections>
<tabstops>
<tabstop>TabWidget</tabstop>