2001-08-29 02:08:04 +00:00
|
|
|
/**
|
|
|
|
* \file QMinipage.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-29 02:08:04 +00:00
|
|
|
*
|
2002-10-20 01:48:28 +00:00
|
|
|
* \author John Levon
|
2002-09-24 13:57:09 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2001-08-29 02:08:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "debug.h"
|
2002-12-17 20:37:13 +00:00
|
|
|
#include "qt_helpers.h"
|
2001-08-29 02:08:04 +00:00
|
|
|
#include "support/lstrings.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "LyXView.h"
|
2001-08-29 02:08:04 +00:00
|
|
|
#include "ControlMinipage.h"
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "QMinipage.h"
|
|
|
|
#include "QMinipageDialog.h"
|
|
|
|
#include "Qt2BC.h"
|
|
|
|
#include "lengthcombo.h"
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
#include <qpushbutton.h>
|
|
|
|
#include <qcombobox.h>
|
|
|
|
#include <qlineedit.h>
|
|
|
|
|
2001-08-29 02:08:04 +00:00
|
|
|
typedef Qt2CB<ControlMinipage, Qt2DB<QMinipageDialog> > base_class;
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-08-12 14:28:43 +00:00
|
|
|
QMinipage::QMinipage()
|
2002-12-17 20:37:13 +00:00
|
|
|
: base_class(qt_("Minipage"))
|
2001-08-29 02:08:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMinipage::build_dialog()
|
|
|
|
{
|
|
|
|
dialog_.reset(new QMinipageDialog(this));
|
|
|
|
|
|
|
|
bc().setRestore(dialog_->restorePB);
|
|
|
|
bc().setOK(dialog_->okPB);
|
|
|
|
bc().setApply(dialog_->applyPB);
|
|
|
|
bc().setCancel(dialog_->closePB);
|
|
|
|
|
|
|
|
bc().addReadOnly(dialog_->widthED);
|
|
|
|
bc().addReadOnly(dialog_->unitsLC);
|
2002-03-21 21:21:28 +00:00
|
|
|
bc().addReadOnly(dialog_->valignCO);
|
2001-08-29 02:08:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMinipage::apply()
|
|
|
|
{
|
2002-12-17 20:37:13 +00:00
|
|
|
double const value = strToDbl(fromqstr(dialog_->widthED->text()));
|
2001-08-29 02:08:04 +00:00
|
|
|
LyXLength::UNIT unit = dialog_->unitsLC->currentLengthItem();
|
2002-12-17 20:37:13 +00:00
|
|
|
if (dialog_->widthED->text().isEmpty())
|
2001-08-29 02:08:04 +00:00
|
|
|
unit = LyXLength::UNIT_NONE;
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
MinipageParams & params = controller().params();
|
|
|
|
|
|
|
|
params.pageWidth = LyXLength(value, unit);
|
2001-08-29 02:08:04 +00:00
|
|
|
|
2001-09-02 18:10:50 +00:00
|
|
|
switch (dialog_->valignCO->currentItem()) {
|
|
|
|
case 0:
|
2002-10-20 01:48:28 +00:00
|
|
|
params.pos = InsetMinipage::top;
|
2001-09-02 18:10:50 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2002-10-20 01:48:28 +00:00
|
|
|
params.pos = InsetMinipage::center;
|
2001-09-02 18:10:50 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2002-10-20 01:48:28 +00:00
|
|
|
params.pos = InsetMinipage::bottom;
|
2001-09-02 18:10:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-08-29 02:08:04 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-29 02:08:04 +00:00
|
|
|
namespace {
|
2002-10-20 01:48:28 +00:00
|
|
|
|
|
|
|
string const numtostr(double val)
|
|
|
|
{
|
|
|
|
string a(tostr(val));
|
|
|
|
if (a == "0")
|
|
|
|
a.erase();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2001-08-29 02:08:04 +00:00
|
|
|
} // namespace anon
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
|
|
|
2001-08-29 02:08:04 +00:00
|
|
|
void QMinipage::update_contents()
|
|
|
|
{
|
2002-10-20 01:48:28 +00:00
|
|
|
MinipageParams const & params = controller().params();
|
|
|
|
|
|
|
|
LyXLength len(params.pageWidth);
|
2002-12-17 20:37:13 +00:00
|
|
|
dialog_->widthED->setText(toqstr(numtostr(len.value())));
|
2001-08-29 02:08:04 +00:00
|
|
|
dialog_->unitsLC->setCurrentItem(len.unit());
|
2002-10-20 01:48:28 +00:00
|
|
|
lyxerr << "width " << numtostr(len.value())
|
|
|
|
<< " units " << len.unit() << std::endl;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-09-02 18:10:50 +00:00
|
|
|
int item = 0;
|
2002-10-20 01:48:28 +00:00
|
|
|
switch (params.pos) {
|
|
|
|
case InsetMinipage::top:
|
|
|
|
item = 0;
|
|
|
|
break;
|
|
|
|
case InsetMinipage::center:
|
|
|
|
item = 1;
|
|
|
|
break;
|
|
|
|
case InsetMinipage::bottom:
|
|
|
|
item = 2;
|
|
|
|
break;
|
2001-08-29 02:08:04 +00:00
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
dialog_->valignCO->setCurrentItem(item);
|
2001-08-29 02:08:04 +00:00
|
|
|
}
|