2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiBox.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Vigna (Minipage stuff)
|
2006-03-05 17:24:44 +00:00
|
|
|
* \author Martin Vermeer
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Spitzmüller
|
2015-05-11 19:30:32 +00:00
|
|
|
* \author Uwe Stöhr
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiBox.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2015-05-16 01:22:37 +00:00
|
|
|
#include "GuiApplication.h"
|
|
|
|
#include "ColorCache.h"
|
2015-05-16 03:22:22 +00:00
|
|
|
#include "ColorSet.h"
|
2007-04-26 03:53:02 +00:00
|
|
|
#include "LengthCombo.h"
|
2007-10-24 22:55:02 +00:00
|
|
|
#include "Length.h"
|
2008-03-27 07:26:37 +00:00
|
|
|
#include "qt_helpers.h"
|
2007-04-26 03:53:02 +00:00
|
|
|
#include "Validator.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "insets/InsetBox.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-03-27 07:26:37 +00:00
|
|
|
#include "support/gettext.h"
|
2008-03-08 13:02:52 +00:00
|
|
|
#include "support/foreach.h"
|
2008-03-27 07:26:37 +00:00
|
|
|
#include "support/lstrings.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2015-05-16 01:22:37 +00:00
|
|
|
#include <QComboBox>
|
2006-05-04 07:31:46 +00:00
|
|
|
#include <QLineEdit>
|
2015-05-15 01:51:11 +00:00
|
|
|
#include <QPushButton>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-05-24 21:58:56 +00:00
|
|
|
#ifdef IN
|
|
|
|
#undef IN
|
|
|
|
#endif
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-03-08 13:02:52 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2008-03-08 13:02:52 +00:00
|
|
|
static QStringList boxGuiIds()
|
|
|
|
{
|
|
|
|
return QStringList()
|
|
|
|
<< "Frameless" << "Boxed"
|
|
|
|
<< "ovalbox" << "Ovalbox"
|
|
|
|
<< "Shadowbox" << "Shaded"
|
|
|
|
<< "Doublebox";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static QStringList boxGuiNames()
|
|
|
|
{
|
|
|
|
return QStringList()
|
|
|
|
<< qt_("No frame") << qt_("Simple rectangular frame")
|
|
|
|
<< qt_("Oval frame, thin") << qt_("Oval frame, thick")
|
|
|
|
<< qt_("Drop shadow") << qt_("Shaded background")
|
|
|
|
<< qt_("Double rectangular frame");
|
|
|
|
}
|
|
|
|
|
2007-10-06 10:23:51 +00:00
|
|
|
|
2008-03-08 13:02:52 +00:00
|
|
|
static QStringList boxGuiSpecialLengthIds()
|
2007-10-06 10:23:51 +00:00
|
|
|
{
|
2009-01-14 14:10:52 +00:00
|
|
|
return QStringList() << "height" << "depth"
|
2008-03-08 13:02:52 +00:00
|
|
|
<< "totalheight" << "width";
|
2007-10-06 10:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-08 13:02:52 +00:00
|
|
|
static QStringList boxGuiSpecialLengthNames()
|
2007-10-06 10:23:51 +00:00
|
|
|
{
|
2009-01-14 14:10:52 +00:00
|
|
|
return QStringList() << qt_("Height") << qt_("Depth")
|
2008-03-08 13:02:52 +00:00
|
|
|
<< qt_("Total Height") << qt_("Width");
|
2007-10-06 10:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-16 09:27:13 +00:00
|
|
|
static QList<ColorCode> colors()
|
2015-05-16 01:22:37 +00:00
|
|
|
{
|
2015-05-16 09:27:13 +00:00
|
|
|
QList<ColorCode> colors;
|
|
|
|
colors << Color_black;
|
|
|
|
colors << Color_white;
|
|
|
|
colors << Color_blue;
|
|
|
|
colors << Color_brown;
|
|
|
|
colors << Color_cyan;
|
|
|
|
colors << Color_darkgray;
|
|
|
|
colors << Color_gray;
|
|
|
|
colors << Color_green;
|
|
|
|
colors << Color_lightgray;
|
|
|
|
colors << Color_lime;
|
|
|
|
colors << Color_magenta;
|
|
|
|
colors << Color_olive;
|
|
|
|
colors << Color_orange;
|
|
|
|
colors << Color_pink;
|
|
|
|
colors << Color_purple;
|
|
|
|
colors << Color_red;
|
|
|
|
colors << Color_teal;
|
|
|
|
colors << Color_violet;
|
|
|
|
colors << Color_yellow;
|
2015-05-16 01:22:37 +00:00
|
|
|
return colors;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-15 23:17:45 +00:00
|
|
|
GuiBox::GuiBox(QWidget * parent) : InsetParamsWidget(parent)
|
2007-04-24 10:56:22 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
// fill the box type choice
|
2008-03-08 13:02:52 +00:00
|
|
|
ids_ = boxGuiIds();
|
|
|
|
gui_names_ = boxGuiNames();
|
2010-06-25 17:39:53 +00:00
|
|
|
for (int i = 0; i != ids_.size(); ++i)
|
|
|
|
typeCO->addItem(gui_names_[i], ids_[i]);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
// add the special units to the height choice
|
|
|
|
// width needs different handling
|
2008-03-08 13:02:52 +00:00
|
|
|
ids_spec_ = boxGuiSpecialLengthIds();
|
|
|
|
gui_names_spec_ = boxGuiSpecialLengthNames();
|
2009-01-14 12:57:23 +00:00
|
|
|
for (int i = 0; i != ids_spec_.size(); ++i)
|
|
|
|
heightUnitsLC->addItem(gui_names_spec_[i], ids_spec_[i]);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2010-02-15 23:17:45 +00:00
|
|
|
connect(widthED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
|
2007-04-28 12:58:49 +00:00
|
|
|
connect(widthUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
2010-02-15 23:17:45 +00:00
|
|
|
this, SIGNAL(changed()));
|
|
|
|
connect(valignCO, SIGNAL(highlighted(QString)), this, SIGNAL(changed()));
|
|
|
|
connect(heightED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
|
2008-03-08 13:02:52 +00:00
|
|
|
connect(heightUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
2010-02-15 23:17:45 +00:00
|
|
|
this, SIGNAL(changed()));
|
|
|
|
connect(halignCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
|
|
|
|
connect(ialignCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
|
2015-05-11 19:30:32 +00:00
|
|
|
connect(thicknessED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
|
|
|
|
connect(thicknessUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
|
|
|
this, SIGNAL(changed()));
|
|
|
|
connect(separationED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
|
|
|
|
connect(separationUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
|
|
|
this, SIGNAL(changed()));
|
|
|
|
connect(shadowsizeED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
|
|
|
|
connect(shadowsizeUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
|
|
|
this, SIGNAL(changed()));
|
2015-05-18 11:13:04 +00:00
|
|
|
connect(backgroundColorCO, SIGNAL(currentIndexChanged(int)),
|
|
|
|
this, SIGNAL(changed()));
|
2007-04-24 10:56:22 +00:00
|
|
|
|
|
|
|
heightED->setValidator(unsignedLengthValidator(heightED));
|
|
|
|
widthED->setValidator(unsignedLengthValidator(widthED));
|
2015-05-11 19:30:32 +00:00
|
|
|
thicknessED->setValidator(unsignedLengthValidator(thicknessED));
|
|
|
|
separationED->setValidator(unsignedLengthValidator(separationED));
|
|
|
|
shadowsizeED->setValidator(unsignedLengthValidator(shadowsizeED));
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
// initialize the length validator
|
2013-03-22 00:33:58 +00:00
|
|
|
addCheckedWidget(widthED, widthCB);
|
2010-02-07 20:28:41 +00:00
|
|
|
addCheckedWidget(heightED, heightCB);
|
2015-05-11 19:30:32 +00:00
|
|
|
addCheckedWidget(thicknessED, thicknessLA);
|
|
|
|
addCheckedWidget(separationED, separationLA);
|
|
|
|
addCheckedWidget(shadowsizeED, shadowsizeLA);
|
2010-02-07 20:28:41 +00:00
|
|
|
|
2015-05-16 01:22:37 +00:00
|
|
|
// the background can be uncolored while the frame cannot
|
2015-05-16 09:27:13 +00:00
|
|
|
color_codes_ = colors();
|
2015-05-19 10:56:31 +00:00
|
|
|
qSort(color_codes_.begin(), color_codes_.end(), ColorSorter);
|
2015-05-16 09:27:13 +00:00
|
|
|
fillComboColor(backgroundColorCO, true);
|
2015-05-18 11:07:00 +00:00
|
|
|
fillComboColor(frameColorCO, false);
|
2015-05-16 01:22:37 +00:00
|
|
|
|
2010-02-07 20:28:41 +00:00
|
|
|
initDialog();
|
2007-09-05 20:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-16 09:27:13 +00:00
|
|
|
void GuiBox::fillComboColor(QComboBox * combo, bool const is_none)
|
|
|
|
{
|
2015-05-18 11:09:07 +00:00
|
|
|
combo->clear();
|
2015-05-16 09:27:13 +00:00
|
|
|
QPixmap coloritem(32, 32);
|
|
|
|
QColor color;
|
|
|
|
// frameColorCO cannot be uncolored
|
|
|
|
if (is_none)
|
|
|
|
combo->addItem(toqstr(translateIfPossible(lcolor.getGUIName(Color_none))),
|
|
|
|
toqstr(lcolor.getLaTeXName(Color_none)));
|
2015-05-18 11:10:32 +00:00
|
|
|
QList<ColorCode>::const_iterator cit = color_codes_.begin();
|
2015-05-16 09:27:13 +00:00
|
|
|
for (; cit != color_codes_.end(); ++cit) {
|
|
|
|
QString const latexname = toqstr(lcolor.getLaTeXName(*cit));
|
|
|
|
QString const guiname = toqstr(translateIfPossible(lcolor.getGUIName(*cit)));
|
|
|
|
color = QColor(guiApp->colorCache().get(*cit, false));
|
|
|
|
coloritem.fill(color);
|
|
|
|
combo->addItem(QIcon(coloritem), guiname, latexname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-18 11:05:28 +00:00
|
|
|
void GuiBox::on_innerBoxCO_activated(int index)
|
2007-04-24 10:56:22 +00:00
|
|
|
{
|
2015-05-18 11:05:28 +00:00
|
|
|
QString itype = innerBoxCO->itemData(index).toString();
|
2010-07-03 13:14:15 +00:00
|
|
|
// handle parbox and minipage the same way
|
2015-05-10 11:02:00 +00:00
|
|
|
bool const ibox = (itype != "none" && itype != "makebox");
|
2010-07-03 13:14:15 +00:00
|
|
|
if (heightCB->isChecked() && !ibox)
|
|
|
|
heightCB->setChecked(false);
|
2013-05-25 13:07:17 +00:00
|
|
|
widthCB->setChecked(!widthED->text().isEmpty());
|
2007-09-05 20:33:29 +00:00
|
|
|
setSpecial(ibox);
|
2010-02-15 23:17:45 +00:00
|
|
|
changed();
|
2007-04-24 10:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-07 20:28:41 +00:00
|
|
|
void GuiBox::on_typeCO_activated(int index)
|
2007-04-24 10:56:22 +00:00
|
|
|
{
|
2010-06-25 17:39:53 +00:00
|
|
|
QString const type =
|
|
|
|
typeCO->itemData(index).toString();
|
|
|
|
bool const frameless = (type == "Frameless");
|
|
|
|
QString itype =
|
|
|
|
innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
|
2010-07-03 13:14:15 +00:00
|
|
|
setInnerType(frameless, itype);
|
|
|
|
// refresh itype because it might have been changed in setInnerType
|
|
|
|
itype =
|
|
|
|
innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
|
|
|
|
// handle parbox and minipage the same way
|
2015-05-10 11:02:00 +00:00
|
|
|
bool const ibox = (itype != "none" && itype != "makebox");
|
2010-07-03 13:14:15 +00:00
|
|
|
if (frameless && itype != "makebox") {
|
|
|
|
if (heightCB->isChecked() && !ibox)
|
|
|
|
heightCB->setChecked(false);
|
|
|
|
setSpecial(ibox);
|
|
|
|
}
|
2015-05-11 20:16:36 +00:00
|
|
|
if (type != "Boxed") {
|
2015-05-10 13:54:03 +00:00
|
|
|
if (type != "Frameless")
|
|
|
|
widthCB->setChecked(itype != "none");
|
2013-03-22 00:33:58 +00:00
|
|
|
pagebreakCB->setChecked(false);
|
2015-05-11 20:16:36 +00:00
|
|
|
}
|
2015-05-16 01:22:37 +00:00
|
|
|
// assure that the frame color is black for frameless boxes to
|
|
|
|
// provide the color "none"
|
2015-05-16 09:27:13 +00:00
|
|
|
int const b = frameColorCO->findData("black");
|
|
|
|
if (frameless && frameColorCO->currentIndex() != b)
|
|
|
|
frameColorCO->setCurrentIndex(b);
|
2015-05-16 01:22:37 +00:00
|
|
|
changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-16 09:27:13 +00:00
|
|
|
void GuiBox::on_frameColorCO_currentIndexChanged(int index)
|
2015-05-16 01:22:37 +00:00
|
|
|
{
|
2015-05-16 09:27:13 +00:00
|
|
|
// if there is a non-black frame color the background cannot be uncolored
|
2015-05-16 03:22:22 +00:00
|
|
|
// therefore remove the entry "none" in this case
|
2015-05-18 11:12:26 +00:00
|
|
|
int const n = backgroundColorCO->findData("none");
|
2015-05-16 09:27:13 +00:00
|
|
|
if (index != frameColorCO->findData("black")) {
|
|
|
|
if (n != -1) {
|
|
|
|
if (backgroundColorCO->currentIndex() == n)
|
|
|
|
backgroundColorCO->setCurrentIndex(
|
|
|
|
backgroundColorCO->findData("white"));
|
|
|
|
backgroundColorCO->removeItem(n);
|
2015-05-16 03:22:22 +00:00
|
|
|
}
|
2015-05-16 01:22:37 +00:00
|
|
|
} else {
|
2015-05-18 11:12:26 +00:00
|
|
|
if (n == -1)
|
2015-05-16 09:27:13 +00:00
|
|
|
backgroundColorCO->insertItem(0, toqstr(translateIfPossible((lcolor.getGUIName(Color_none)))),
|
|
|
|
toqstr(lcolor.getLaTeXName(Color_none)));
|
2015-05-16 01:22:37 +00:00
|
|
|
}
|
2010-02-15 23:17:45 +00:00
|
|
|
changed();
|
2007-04-24 10:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-07 20:28:41 +00:00
|
|
|
void GuiBox::initDialog()
|
2007-04-24 10:56:22 +00:00
|
|
|
{
|
2010-06-25 17:39:53 +00:00
|
|
|
setInnerType(true, toqstr("minipage"));
|
2007-04-24 10:56:22 +00:00
|
|
|
widthED->setText("100");
|
2013-05-05 23:31:04 +00:00
|
|
|
widthCB->setChecked(true);
|
|
|
|
widthCB->setEnabled(false);
|
2007-04-28 12:58:49 +00:00
|
|
|
widthUnitsLC->setCurrentItem(Length::PCW);
|
2007-04-24 10:56:22 +00:00
|
|
|
heightED->setText("1");
|
2009-01-14 12:57:23 +00:00
|
|
|
heightUnitsLC->setCurrentItem("totalheight");
|
2015-05-11 19:30:32 +00:00
|
|
|
// LaTeX's default for \fboxrule is 0.4 pt
|
|
|
|
thicknessED->setText("0.4");
|
|
|
|
thicknessUnitsLC->setCurrentItem(Length::PT);
|
|
|
|
// LaTeX's default for \fboxsep is 3 pt
|
|
|
|
separationED->setText("3");
|
|
|
|
separationUnitsLC->setCurrentItem(Length::PT);
|
|
|
|
// LaTeX's default for \shadowsize is 4 pt
|
|
|
|
shadowsizeED->setText("4");
|
|
|
|
shadowsizeUnitsLC->setCurrentItem(Length::PT);
|
2007-04-24 10:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-23 13:14:44 +00:00
|
|
|
void GuiBox::on_widthCB_stateChanged(int)
|
2013-03-22 00:33:58 +00:00
|
|
|
{
|
|
|
|
changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-10 11:02:00 +00:00
|
|
|
void GuiBox::on_heightCB_stateChanged(int /*state*/)
|
2010-02-07 20:28:41 +00:00
|
|
|
{
|
2010-02-15 23:17:45 +00:00
|
|
|
changed();
|
2010-02-07 20:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiBox::on_pagebreakCB_stateChanged()
|
2007-12-04 09:25:50 +00:00
|
|
|
{
|
|
|
|
bool pbreak = (pagebreakCB->checkState() == Qt::Checked);
|
2013-03-22 00:33:58 +00:00
|
|
|
if (pbreak)
|
|
|
|
widthCB->setChecked(!pbreak);
|
2010-02-07 21:12:46 +00:00
|
|
|
if (!pbreak) {
|
2010-02-07 20:28:41 +00:00
|
|
|
on_typeCO_activated(typeCO->currentIndex());
|
2010-02-07 21:12:46 +00:00
|
|
|
return;
|
2008-03-08 13:02:52 +00:00
|
|
|
}
|
2010-02-07 21:12:46 +00:00
|
|
|
setSpecial(false);
|
2010-02-15 23:17:45 +00:00
|
|
|
changed();
|
2007-12-04 09:25:50 +00:00
|
|
|
}
|
|
|
|
|
2008-03-08 13:02:52 +00:00
|
|
|
|
2010-02-07 20:28:41 +00:00
|
|
|
void GuiBox::paramsToDialog(Inset const * inset)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2010-02-07 20:28:41 +00:00
|
|
|
InsetBox const * box = static_cast<InsetBox const *>(inset);
|
|
|
|
InsetBoxParams const & params = box->params();
|
|
|
|
QString type = toqstr(params.type);
|
2007-12-04 09:25:50 +00:00
|
|
|
if (type == "Framed") {
|
|
|
|
pagebreakCB->setChecked(true);
|
|
|
|
type = "Boxed";
|
2008-03-08 13:02:52 +00:00
|
|
|
} else {
|
2007-12-04 09:25:50 +00:00
|
|
|
pagebreakCB->setChecked(false);
|
2008-03-08 13:02:52 +00:00
|
|
|
}
|
2007-12-04 09:25:50 +00:00
|
|
|
|
2010-06-25 17:39:53 +00:00
|
|
|
typeCO->setCurrentIndex(typeCO->findData(type));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// default: minipage
|
2010-06-25 17:39:53 +00:00
|
|
|
QString inner_type = "minipage";
|
2010-02-07 20:28:41 +00:00
|
|
|
if (!params.inner_box)
|
2010-06-25 17:39:53 +00:00
|
|
|
inner_type = "none";
|
2010-02-07 20:28:41 +00:00
|
|
|
if (params.use_parbox)
|
2010-06-25 17:39:53 +00:00
|
|
|
inner_type = "parbox";
|
2010-07-03 13:14:15 +00:00
|
|
|
if (params.use_makebox)
|
|
|
|
inner_type = "makebox";
|
2010-06-25 17:39:53 +00:00
|
|
|
bool const frameless = (params.type == "Frameless");
|
2006-03-05 17:24:44 +00:00
|
|
|
setInnerType(frameless, inner_type);
|
|
|
|
|
2010-02-07 20:28:41 +00:00
|
|
|
char c = params.pos;
|
2007-09-05 20:33:29 +00:00
|
|
|
valignCO->setCurrentIndex(string("tcb").find(c, 0));
|
2010-02-07 20:28:41 +00:00
|
|
|
c = params.inner_pos;
|
2007-09-05 20:33:29 +00:00
|
|
|
ialignCO->setCurrentIndex(string("tcbs").find(c, 0));
|
2010-02-07 20:28:41 +00:00
|
|
|
c = params.hor_pos;
|
2007-09-05 20:33:29 +00:00
|
|
|
halignCO->setCurrentIndex(string("lcrs").find(c, 0));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2010-07-03 13:14:15 +00:00
|
|
|
bool ibox = (params.inner_box && !params.use_makebox);
|
2007-09-05 20:33:29 +00:00
|
|
|
valignCO->setEnabled(ibox);
|
|
|
|
ialignCO->setEnabled(ibox);
|
2006-03-05 17:24:44 +00:00
|
|
|
setSpecial(ibox);
|
|
|
|
|
2015-10-23 20:08:38 +00:00
|
|
|
// halign is only allowed without inner box and if a width is used and if
|
|
|
|
// pagebreak is not used
|
|
|
|
halignCO->setEnabled(!pagebreakCB->isChecked() && widthCB->isChecked()
|
|
|
|
&& ((!ibox && type == "Boxed") || inner_type == "makebox"));
|
2015-05-11 19:30:32 +00:00
|
|
|
// add the entry "Stretch" if the box is \makebox or \framebox and if not already there
|
|
|
|
if ((inner_type == "makebox" || (type == "Boxed" && inner_type == "none"))
|
|
|
|
&& halignCO->count() < 4)
|
|
|
|
halignCO->addItem(toqstr("Stretch"));
|
|
|
|
else if (inner_type != "makebox" && (type != "Boxed" && inner_type != "none"))
|
|
|
|
halignCO->removeItem(3);
|
2010-07-03 13:14:15 +00:00
|
|
|
// pagebreak is only allowed for Boxed without inner box
|
2010-06-26 21:02:14 +00:00
|
|
|
pagebreakCB->setEnabled(!ibox && type == "Boxed");
|
|
|
|
|
2009-02-06 21:24:13 +00:00
|
|
|
Length::UNIT const default_unit = Length::defaultUnit();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2013-03-22 00:33:58 +00:00
|
|
|
// the width can only be selected for makebox or framebox
|
2013-04-17 09:30:25 +00:00
|
|
|
widthCB->setEnabled(inner_type == "makebox"
|
|
|
|
|| (type == "Boxed"
|
|
|
|
&& !ibox && !pagebreakCB->isChecked()));
|
|
|
|
if (params.width.empty()) {
|
|
|
|
widthCB->setChecked(false);
|
|
|
|
lengthToWidgets(widthED, widthUnitsLC,
|
|
|
|
params.width, default_unit);
|
|
|
|
} else {
|
2013-05-25 13:07:17 +00:00
|
|
|
widthCB->setChecked(true);
|
2013-03-22 00:33:58 +00:00
|
|
|
lengthToWidgets(widthED, widthUnitsLC,
|
2013-04-17 09:30:25 +00:00
|
|
|
params.width, default_unit);
|
2013-03-22 00:33:58 +00:00
|
|
|
QString const special = toqstr(params.special);
|
|
|
|
if (!special.isEmpty() && special != "none")
|
|
|
|
widthUnitsLC->setCurrentItem(special);
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2013-03-22 00:33:58 +00:00
|
|
|
widthED->setEnabled(widthCB->isChecked());
|
|
|
|
widthUnitsLC->setEnabled(widthCB->isChecked());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
lengthToWidgets(heightED, heightUnitsLC,
|
2010-02-07 20:28:41 +00:00
|
|
|
(params.height).asString(), default_unit);
|
2013-04-17 09:30:25 +00:00
|
|
|
|
2010-02-07 20:28:41 +00:00
|
|
|
QString const height_special = toqstr(params.height_special);
|
2009-01-14 12:57:23 +00:00
|
|
|
if (!height_special.isEmpty() && height_special != "none")
|
|
|
|
heightUnitsLC->setCurrentItem(height_special);
|
|
|
|
// set no optional height if the value is the default "1\height"
|
2007-10-05 00:36:38 +00:00
|
|
|
// (special units like \height are handled as "in",
|
2010-02-07 20:28:41 +00:00
|
|
|
// FIXME: this is a very bad UI, this check box should be disabled in
|
|
|
|
// this case, not forced to 'unchecked' state.
|
|
|
|
if (height_special == "totalheight" && params.height == Length("1in"))
|
2007-10-05 00:36:38 +00:00
|
|
|
heightCB->setCheckState(Qt::Unchecked);
|
|
|
|
else
|
|
|
|
heightCB->setCheckState(Qt::Checked);
|
|
|
|
|
2007-09-27 20:19:06 +00:00
|
|
|
heightCB->setEnabled(ibox);
|
2015-05-11 19:30:32 +00:00
|
|
|
|
|
|
|
// enable line thickness only for the rectangular frame types and drop shadow
|
|
|
|
thicknessED->setEnabled(type == "Boxed" || type == "Doublebox" || type == "Shadowbox");
|
|
|
|
thicknessUnitsLC->setEnabled(type == "Boxed" || type == "Doublebox" || type == "Shadowbox");
|
|
|
|
lengthToWidgets(thicknessED, thicknessUnitsLC,
|
|
|
|
(params.thickness).asString(), default_unit);
|
|
|
|
// enable line separation for the allowed frame types
|
|
|
|
separationED->setEnabled(type == "Boxed" || type == "ovalbox" || type == "Ovalbox"
|
|
|
|
|| type == "Doublebox" || type == "Shadowbox");
|
|
|
|
separationUnitsLC->setEnabled(type == "Boxed" || type == "ovalbox" || type == "Ovalbox"
|
|
|
|
|| type == "Doublebox" || type == "Shadowbox");
|
|
|
|
lengthToWidgets(separationED, separationUnitsLC,
|
|
|
|
(params.separation).asString(), default_unit);
|
|
|
|
// enable shadow size for drop shadow
|
|
|
|
shadowsizeED->setEnabled(type == "Shadowbox");
|
|
|
|
shadowsizeUnitsLC->setEnabled(type == "Shadowbox");
|
|
|
|
lengthToWidgets(shadowsizeED, shadowsizeUnitsLC,
|
|
|
|
(params.shadowsize).asString(), default_unit);
|
2015-05-16 01:22:37 +00:00
|
|
|
// set color
|
2015-05-16 09:27:13 +00:00
|
|
|
frameColorCO->setCurrentIndex(frameColorCO->findData(toqstr(params.framecolor)));
|
|
|
|
backgroundColorCO->setCurrentIndex(backgroundColorCO->findData(toqstr(params.backgroundcolor)));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-07 20:28:41 +00:00
|
|
|
docstring GuiBox::dialogToParams() const
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2010-02-07 20:28:41 +00:00
|
|
|
bool const pagebreak =
|
2009-01-14 12:57:23 +00:00
|
|
|
pagebreakCB->isEnabled() && pagebreakCB->isChecked();
|
2010-02-07 20:28:41 +00:00
|
|
|
string box_type;
|
2007-12-04 09:25:50 +00:00
|
|
|
if (pagebreak)
|
2010-02-07 20:28:41 +00:00
|
|
|
box_type = "Framed";
|
2007-12-04 09:25:50 +00:00
|
|
|
else
|
2010-06-25 17:39:53 +00:00
|
|
|
box_type = fromqstr(typeCO->itemData(
|
|
|
|
typeCO->currentIndex()).toString());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2010-02-07 20:28:41 +00:00
|
|
|
InsetBoxParams params(box_type);
|
|
|
|
params.inner_box =
|
2009-01-14 12:57:23 +00:00
|
|
|
(!pagebreak && innerBoxCO->currentText() != qt_("None"));
|
2010-02-07 20:28:41 +00:00
|
|
|
params.use_parbox =
|
2009-01-14 12:57:23 +00:00
|
|
|
(!pagebreak && innerBoxCO->currentText() == qt_("Parbox"));
|
2010-07-03 13:14:15 +00:00
|
|
|
params.use_makebox =
|
|
|
|
(!pagebreak && innerBoxCO->currentText() == qt_("Makebox"));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2010-02-07 20:28:41 +00:00
|
|
|
params.pos = "tcb"[valignCO->currentIndex()];
|
|
|
|
params.inner_pos = "tcbs"[ialignCO->currentIndex()];
|
|
|
|
params.hor_pos = "lcrs"[halignCO->currentIndex()];
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2009-01-14 12:57:23 +00:00
|
|
|
QString unit =
|
|
|
|
widthUnitsLC->itemData(widthUnitsLC->currentIndex()).toString();
|
2007-09-05 20:33:29 +00:00
|
|
|
QString value = widthED->text();
|
2013-03-22 00:33:58 +00:00
|
|
|
|
2013-04-17 09:30:25 +00:00
|
|
|
if (widthED->isEnabled()) {
|
|
|
|
if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
|
|
|
|
params.special = fromqstr(unit);
|
|
|
|
// Note: the unit is simply ignored in this case
|
|
|
|
params.width = Length(value.toDouble(), Length::IN);
|
|
|
|
} else {
|
2013-03-22 00:33:58 +00:00
|
|
|
params.special = "none";
|
2013-05-25 11:52:09 +00:00
|
|
|
// we must specify a valid length in this case
|
|
|
|
if (value.isEmpty())
|
|
|
|
widthED->setText("0");
|
2013-04-17 09:30:25 +00:00
|
|
|
params.width = Length(widgetsToLength(widthED, widthUnitsLC));
|
2013-03-22 00:33:58 +00:00
|
|
|
}
|
2013-04-17 09:30:25 +00:00
|
|
|
} else {
|
|
|
|
params.special = "none";
|
|
|
|
params.width = Length();
|
2007-10-06 10:23:51 +00:00
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2009-11-01 23:23:54 +00:00
|
|
|
// the height parameter is omitted if the value
|
2007-09-27 20:19:06 +00:00
|
|
|
// is "1in" and "Total Height" is used as unit.
|
2009-01-14 12:57:23 +00:00
|
|
|
// 1in + "Total Height" means "1\height" which is the LaTeX default
|
|
|
|
// if no height is given
|
|
|
|
if (heightCB->checkState() == Qt::Unchecked) {
|
2010-02-07 20:28:41 +00:00
|
|
|
params.height = Length("1in");
|
|
|
|
params.height_special = "totalheight";
|
2009-01-14 12:57:23 +00:00
|
|
|
} else {
|
|
|
|
unit = heightUnitsLC->itemData(heightUnitsLC->currentIndex()).toString();
|
|
|
|
value = heightED->text();
|
|
|
|
if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
|
2010-02-07 20:28:41 +00:00
|
|
|
params.height_special = fromqstr(unit);
|
2009-01-14 12:57:23 +00:00
|
|
|
// Note: the unit is simply ignored in this case
|
2010-02-07 20:28:41 +00:00
|
|
|
params.height = Length(value.toDouble(), Length::IN);
|
2009-01-14 12:57:23 +00:00
|
|
|
} else {
|
2010-02-07 20:28:41 +00:00
|
|
|
params.height_special = "none";
|
|
|
|
params.height =
|
2009-01-14 12:57:23 +00:00
|
|
|
Length(widgetsToLength(heightED, heightUnitsLC));
|
|
|
|
}
|
2007-09-27 20:19:06 +00:00
|
|
|
}
|
2015-05-11 19:30:32 +00:00
|
|
|
|
|
|
|
// handle the line thickness, line separation and shadow size
|
|
|
|
if (thicknessED->isEnabled())
|
|
|
|
params.thickness = Length(widgetsToLength(thicknessED, thicknessUnitsLC));
|
|
|
|
else
|
2015-05-15 01:51:11 +00:00
|
|
|
params.thickness = Length("0.4pt");
|
2015-05-11 19:30:32 +00:00
|
|
|
if (separationED->isEnabled())
|
|
|
|
params.separation = Length(widgetsToLength(separationED, separationUnitsLC));
|
|
|
|
else
|
2015-05-15 01:51:11 +00:00
|
|
|
params.separation = Length("3pt");
|
2015-05-11 19:30:32 +00:00
|
|
|
if (separationED->isEnabled())
|
|
|
|
params.shadowsize = Length(widgetsToLength(shadowsizeED, shadowsizeUnitsLC));
|
|
|
|
else
|
2015-05-15 01:51:11 +00:00
|
|
|
params.shadowsize = Length("4pt");
|
2015-05-16 01:22:37 +00:00
|
|
|
if (frameColorCO->isEnabled())
|
2015-05-16 09:27:13 +00:00
|
|
|
params.framecolor =
|
|
|
|
fromqstr(frameColorCO->itemData(frameColorCO->currentIndex()).toString());
|
2015-05-16 01:22:37 +00:00
|
|
|
else
|
|
|
|
params.framecolor = "black";
|
2015-05-16 09:27:13 +00:00
|
|
|
if (backgroundColorCO->isEnabled())
|
|
|
|
params.backgroundcolor =
|
|
|
|
fromqstr(backgroundColorCO->itemData(backgroundColorCO->currentIndex()).toString());
|
|
|
|
else
|
2015-05-16 01:22:37 +00:00
|
|
|
params.backgroundcolor = "none";
|
2015-05-11 19:30:32 +00:00
|
|
|
|
2010-02-07 20:28:41 +00:00
|
|
|
return from_ascii(InsetBox::params2string(params));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-02 15:03:08 +00:00
|
|
|
bool GuiBox::checkWidgets(bool readonly) const
|
|
|
|
{
|
|
|
|
typeCO->setEnabled(!readonly);
|
2015-05-10 11:02:00 +00:00
|
|
|
|
|
|
|
if (readonly) {
|
|
|
|
pagebreakCB->setEnabled(false);
|
|
|
|
innerBoxCO->setEnabled(false);
|
|
|
|
valignCO->setEnabled(false);
|
|
|
|
ialignCO->setEnabled(false);
|
|
|
|
halignCO->setEnabled(false);
|
|
|
|
widthCB->setEnabled(false);
|
|
|
|
widthED->setEnabled(false);
|
|
|
|
widthUnitsLC->setEnabled(false);
|
|
|
|
heightED->setEnabled(false);
|
|
|
|
heightUnitsLC->setEnabled(false);
|
|
|
|
heightCB->setEnabled(false);
|
2015-05-11 19:30:32 +00:00
|
|
|
thicknessED->setEnabled(false);
|
|
|
|
thicknessUnitsLC->setEnabled(false);
|
|
|
|
separationED->setEnabled(false);
|
|
|
|
separationUnitsLC->setEnabled(false);
|
|
|
|
shadowsizeED->setEnabled(false);
|
|
|
|
shadowsizeUnitsLC->setEnabled(false);
|
2015-05-10 11:02:00 +00:00
|
|
|
} else {
|
|
|
|
QString const outer =
|
|
|
|
typeCO->itemData(typeCO->currentIndex()).toString();
|
|
|
|
QString const itype =
|
|
|
|
innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
|
|
|
|
bool const ibox = (itype != "none" && itype != "makebox");
|
|
|
|
valignCO->setEnabled(ibox);
|
|
|
|
ialignCO->setEnabled(ibox);
|
2015-05-11 19:30:32 +00:00
|
|
|
if (heightCB->isChecked() && !ibox)
|
|
|
|
heightCB->setChecked(false);
|
|
|
|
heightCB->setEnabled(ibox);
|
2015-05-10 11:02:00 +00:00
|
|
|
// the width can only be selected for makebox or framebox
|
|
|
|
widthCB->setEnabled(itype == "makebox"
|
2015-05-12 23:16:35 +00:00
|
|
|
|| (outer == "Boxed" && itype == "none" && !pagebreakCB->isChecked()));
|
2015-05-11 19:30:32 +00:00
|
|
|
// except for Frameless and Boxed, the width cannot be specified if
|
2015-05-10 11:02:00 +00:00
|
|
|
// there is no inner box
|
|
|
|
bool const width_enabled =
|
2015-05-15 04:02:41 +00:00
|
|
|
ibox || outer == "Frameless" || (outer == "Boxed" && !pagebreakCB->isChecked());
|
2015-05-11 19:30:32 +00:00
|
|
|
// enable if width_enabled
|
|
|
|
widthED->setEnabled(width_enabled);
|
|
|
|
widthUnitsLC->setEnabled(width_enabled);
|
2015-05-10 11:02:00 +00:00
|
|
|
if (!widthCB->isChecked() && widthCB->isEnabled()) {
|
|
|
|
widthED->setEnabled(false);
|
|
|
|
widthUnitsLC->setEnabled(false);
|
|
|
|
}
|
2015-10-23 20:08:38 +00:00
|
|
|
// halign is only allowed without inner box and if a width is used and if
|
|
|
|
// pagebreak is not used
|
|
|
|
halignCO->setEnabled(!pagebreakCB->isChecked() && widthCB->isChecked()
|
|
|
|
&& ((!ibox && outer == "Boxed") || itype == "makebox"));
|
2015-05-11 19:30:32 +00:00
|
|
|
// add the entry "Stretch" if the box is \makebox or \framebox and if not already there
|
|
|
|
if ((itype == "makebox" || (outer == "Boxed" && itype == "none"))
|
|
|
|
&& halignCO->count() < 4)
|
|
|
|
halignCO->addItem(toqstr("Stretch"));
|
|
|
|
else if (itype != "makebox" && (outer != "Boxed" && itype != "none"))
|
|
|
|
halignCO->removeItem(3);
|
|
|
|
// pagebreak is only allowed for Boxed without inner box
|
|
|
|
pagebreakCB->setEnabled(!ibox && outer == "Boxed");
|
|
|
|
|
2015-05-10 11:02:00 +00:00
|
|
|
heightED->setEnabled(itype != "none" && heightCB->isChecked());
|
|
|
|
heightUnitsLC->setEnabled(itype != "none" && heightCB->isChecked());
|
|
|
|
heightCB->setEnabled(ibox);
|
2015-05-11 19:30:32 +00:00
|
|
|
|
|
|
|
// enable line thickness for the rectangular frame types and drop shadow
|
|
|
|
thicknessED->setEnabled(outer == "Boxed" || outer == "Doublebox" || outer == "Shadowbox");
|
|
|
|
thicknessUnitsLC->setEnabled(outer == "Boxed" || outer == "Doublebox" || outer == "Shadowbox");
|
|
|
|
// set default values if empty
|
|
|
|
if (thicknessED->text().isEmpty() && thicknessED->isEnabled()) {
|
|
|
|
thicknessED->setText("0.4");
|
|
|
|
thicknessUnitsLC->setCurrentItem(Length::PT);
|
|
|
|
}
|
|
|
|
// enable line separation for the allowed frame types
|
|
|
|
separationED->setEnabled(outer == "Boxed" || outer == "ovalbox" || outer == "Ovalbox"
|
|
|
|
|| outer == "Doublebox" || outer == "Shadowbox");
|
|
|
|
separationUnitsLC->setEnabled(outer == "Boxed" || outer == "ovalbox" || outer == "Ovalbox"
|
|
|
|
|| outer == "Doublebox" || outer == "Shadowbox");
|
|
|
|
// set default values if empty
|
|
|
|
if (separationED->text().isEmpty() && separationED->isEnabled()) {
|
|
|
|
separationED->setText("3");
|
|
|
|
separationUnitsLC->setCurrentItem(Length::PT);
|
|
|
|
}
|
|
|
|
// enable shadow size for drop shadow
|
|
|
|
shadowsizeED->setEnabled(outer == "Shadowbox");
|
|
|
|
shadowsizeUnitsLC->setEnabled(outer == "Shadowbox");
|
|
|
|
// set default values if empty
|
|
|
|
if (shadowsizeED->text().isEmpty() && shadowsizeED->isEnabled()) {
|
|
|
|
shadowsizeED->setText("4");
|
|
|
|
shadowsizeUnitsLC->setCurrentItem(Length::PT);
|
|
|
|
}
|
2015-05-16 01:22:37 +00:00
|
|
|
// \fboxcolor and \colorbox cannot be used for fancybox boxes
|
|
|
|
frameColorCO->setEnabled(!pagebreakCB->isChecked() && outer == "Boxed");
|
|
|
|
backgroundColorCO->setEnabled(!pagebreakCB->isChecked() && (frameColorCO->isEnabled() || outer == "Frameless"));
|
2015-05-10 11:02:00 +00:00
|
|
|
}
|
2015-04-02 15:03:08 +00:00
|
|
|
|
|
|
|
return InsetParamsWidget::checkWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 10:23:51 +00:00
|
|
|
void GuiBox::setSpecial(bool ibox)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2009-01-14 12:57:23 +00:00
|
|
|
QString const last_item =
|
|
|
|
widthUnitsLC->itemData(heightUnitsLC->currentIndex()).toString();
|
2008-10-04 09:24:40 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
// check if the widget contains the special units
|
2009-01-14 12:57:23 +00:00
|
|
|
bool const has_special = (widthUnitsLC->findData("totalheight") != -1);
|
2006-03-05 17:24:44 +00:00
|
|
|
// insert 'em if needed...
|
|
|
|
if (!ibox && !has_special) {
|
2009-01-14 12:57:23 +00:00
|
|
|
for (int i = 1; i < ids_spec_.size(); ++i)
|
|
|
|
widthUnitsLC->addItem(gui_names_spec_[i], ids_spec_[i]);
|
2006-03-05 17:24:44 +00:00
|
|
|
// ... or remove 'em if needed
|
|
|
|
} else if (ibox && has_special) {
|
2009-01-14 12:57:23 +00:00
|
|
|
for (int i = 1; i < ids_spec_.size(); ++i) {
|
|
|
|
int n = widthUnitsLC->findData(ids_spec_[i]);
|
|
|
|
if (n != -1)
|
|
|
|
widthUnitsLC->removeItem(n);
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2008-10-04 09:24:40 +00:00
|
|
|
// restore selected text, if possible
|
2009-01-14 12:57:23 +00:00
|
|
|
widthUnitsLC->setCurrentItem(last_item);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-25 17:39:53 +00:00
|
|
|
void GuiBox::setInnerType(bool frameless, QString const & type)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2010-06-25 17:39:53 +00:00
|
|
|
// with "frameless" boxes, inner box is mandatory
|
|
|
|
// (i.e. is the actual box)
|
2006-03-05 17:24:44 +00:00
|
|
|
// we have to remove "none" then and adjust the combo
|
2010-06-25 17:39:53 +00:00
|
|
|
innerBoxCO->clear();
|
|
|
|
if (!frameless)
|
|
|
|
innerBoxCO->addItem(qt_("None"), toqstr("none"));
|
2010-07-03 13:14:15 +00:00
|
|
|
else
|
|
|
|
innerBoxCO->addItem(qt_("Makebox"), toqstr("makebox"));
|
2010-06-25 17:39:53 +00:00
|
|
|
innerBoxCO->addItem(qt_("Parbox"), toqstr("parbox"));
|
|
|
|
innerBoxCO->addItem(qt_("Minipage"), toqstr("minipage"));
|
|
|
|
int i = (innerBoxCO->findData(type) != -1)
|
|
|
|
? innerBoxCO->findData(type) : 0;
|
|
|
|
innerBoxCO->setCurrentIndex(i);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-24 10:56:22 +00:00
|
|
|
|
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiBox.cpp"
|