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
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-08-29 02:08:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2002-12-17 20:37:13 +00:00
|
|
|
#include "qt_helpers.h"
|
2003-05-13 17:01:28 +00:00
|
|
|
#include "support/tostr.h"
|
2001-08-29 02:08:04 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
#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 <qlineedit.h>
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
using lyx::support::strToDbl;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2001-08-29 02:08:04 +00:00
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
typedef QController<ControlMinipage, QView<QMinipageDialog> > base_class;
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2003-03-07 14:08:10 +00:00
|
|
|
QMinipage::QMinipage(Dialog & parent)
|
2003-05-22 15:42:50 +00:00
|
|
|
: base_class(parent, _("LyX: Minipage Settings"))
|
2001-08-29 02:08:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMinipage::build_dialog()
|
|
|
|
{
|
|
|
|
dialog_.reset(new QMinipageDialog(this));
|
|
|
|
|
2003-03-10 03:13:28 +00:00
|
|
|
bcview().setRestore(dialog_->restorePB);
|
|
|
|
bcview().setOK(dialog_->okPB);
|
|
|
|
bcview().setApply(dialog_->applyPB);
|
|
|
|
bcview().setCancel(dialog_->closePB);
|
|
|
|
|
|
|
|
bcview().addReadOnly(dialog_->widthED);
|
|
|
|
bcview().addReadOnly(dialog_->unitsLC);
|
|
|
|
bcview().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;
|
|
|
|
|
2003-03-07 14:08:10 +00:00
|
|
|
InsetMinipage::Params & params = controller().params();
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2003-03-07 14:08:10 +00:00
|
|
|
params.width = 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()
|
|
|
|
{
|
2003-03-07 14:08:10 +00:00
|
|
|
InsetMinipage::Params const & params = controller().params();
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2003-03-07 14:08:10 +00:00
|
|
|
LyXLength len(params.width);
|
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-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
|
|
|
}
|