2002-10-07 16:41:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file QWrap.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
2003-09-07 01:45:40 +00:00
|
|
|
|
* \author J<EFBFBD>rgen Spitzm<EFBFBD>ller
|
2002-10-07 16:41:10 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-10-07 16:41:10 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "QWrap.h"
|
|
|
|
|
#include "QWrapDialog.h"
|
|
|
|
|
#include "Qt2BC.h"
|
2004-05-20 09:36:28 +00:00
|
|
|
|
|
2002-10-07 16:41:10 +00:00
|
|
|
|
#include "lengthcombo.h"
|
2004-05-20 09:36:28 +00:00
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
|
|
#include "controllers/ControlWrap.h"
|
2002-10-20 01:48:28 +00:00
|
|
|
|
|
2003-03-05 23:19:45 +00:00
|
|
|
|
#include "insets/insetwrap.h"
|
|
|
|
|
|
2005-01-06 16:44:04 +00:00
|
|
|
|
#include "support/convert.h"
|
2004-05-20 09:36:28 +00:00
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
2002-10-07 16:41:10 +00:00
|
|
|
|
#include <qlineedit.h>
|
2004-05-20 09:36:28 +00:00
|
|
|
|
#include <qpushbutton.h>
|
2002-10-07 16:41:10 +00:00
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::strToDbl;
|
2003-03-05 23:19:45 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
namespace frontend {
|
2002-10-07 16:41:10 +00:00
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
typedef QController<ControlWrap, QView<QWrapDialog> > base_class;
|
2002-10-20 01:48:28 +00:00
|
|
|
|
|
2003-03-05 23:19:45 +00:00
|
|
|
|
QWrap::QWrap(Dialog & parent)
|
2003-05-22 15:42:50 +00:00
|
|
|
|
: base_class(parent, _("LyX: Text Wrap Settings"))
|
2002-10-07 16:41:10 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QWrap::build_dialog()
|
|
|
|
|
{
|
|
|
|
|
dialog_.reset(new QWrapDialog(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);
|
2002-10-07 16:41:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QWrap::apply()
|
|
|
|
|
{
|
2002-12-17 20:37:13 +00:00
|
|
|
|
double const value = strToDbl(fromqstr(dialog_->widthED->text()));
|
2002-10-07 16:41:10 +00:00
|
|
|
|
LyXLength::UNIT unit = dialog_->unitsLC->currentLengthItem();
|
2002-12-17 20:37:13 +00:00
|
|
|
|
if (dialog_->widthED->text().isEmpty())
|
2002-10-07 16:41:10 +00:00
|
|
|
|
unit = LyXLength::UNIT_NONE;
|
|
|
|
|
|
2003-03-05 23:19:45 +00:00
|
|
|
|
InsetWrapParams & params = controller().params();
|
2002-10-20 01:48:28 +00:00
|
|
|
|
|
2003-03-05 23:19:45 +00:00
|
|
|
|
params.width = LyXLength(value, unit);
|
2002-10-07 16:41:10 +00:00
|
|
|
|
|
|
|
|
|
switch (dialog_->valignCO->currentItem()) {
|
|
|
|
|
case 0:
|
2002-10-20 01:48:28 +00:00
|
|
|
|
params.placement.erase();
|
2002-10-07 16:41:10 +00:00
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2002-10-20 01:48:28 +00:00
|
|
|
|
params.placement = "l";
|
2002-10-07 16:41:10 +00:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2002-10-20 01:48:28 +00:00
|
|
|
|
params.placement = "r";
|
2002-10-07 16:41:10 +00:00
|
|
|
|
break;
|
|
|
|
|
case 3:
|
2002-10-20 01:48:28 +00:00
|
|
|
|
params.placement = "p";
|
2002-10-07 16:41:10 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
2002-10-20 01:48:28 +00:00
|
|
|
|
|
|
|
|
|
string const numtostr(double val) {
|
2005-01-06 15:40:49 +00:00
|
|
|
|
string a(convert<string>(val));
|
|
|
|
|
#warning Will this test ever trigger? (Lgb)
|
2002-10-20 01:48:28 +00:00
|
|
|
|
if (a == "0")
|
|
|
|
|
a.erase();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-07 16:41:10 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QWrap::update_contents()
|
|
|
|
|
{
|
2003-03-05 23:19:45 +00:00
|
|
|
|
InsetWrapParams & params = controller().params();
|
2002-10-20 01:48:28 +00:00
|
|
|
|
|
2003-03-05 23:19:45 +00:00
|
|
|
|
LyXLength len(params.width);
|
2002-12-17 20:37:13 +00:00
|
|
|
|
dialog_->widthED->setText(toqstr(numtostr(len.value())));
|
2002-10-07 16:41:10 +00:00
|
|
|
|
dialog_->unitsLC->setCurrentItem(len.unit());
|
|
|
|
|
|
|
|
|
|
int item = 0;
|
2002-10-20 01:48:28 +00:00
|
|
|
|
if (params.placement == "l")
|
2002-10-07 16:41:10 +00:00
|
|
|
|
item = 1;
|
2002-10-20 01:48:28 +00:00
|
|
|
|
else if (params.placement == "r")
|
2002-10-07 16:41:10 +00:00
|
|
|
|
item = 2;
|
2002-10-20 01:48:28 +00:00
|
|
|
|
else if (params.placement == "p")
|
2002-10-07 16:41:10 +00:00
|
|
|
|
item = 3;
|
|
|
|
|
|
|
|
|
|
dialog_->valignCO->setCurrentItem(item);
|
|
|
|
|
}
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|