Add support for global float alignment

It is now possible in the float settings (doc dialog) to specify a global
(inner) alignment for floats, and in the float settings, this can be
overridden (just as with float placement)

Fixes: #8665

File format change.
This commit is contained in:
Juergen Spitzmueller 2018-05-10 20:15:11 +02:00
parent 2389580c27
commit aa9543fa2b
12 changed files with 431 additions and 140 deletions

View File

@ -7,6 +7,14 @@ changes happened in particular if possible. A good example would be
----------------------- -----------------------
2018-05-10 Jürgen Spitzmüller <spitz@lyx.org>
* format incremented to 552: support for float alignment
- add buffer param \float_alignment [class|left|center|right]
- add buffer param \float_placement class
- add float param alignment [class|document|left|center|right]
- add float param placement class (=> new param)
- add float param placement document(=> like formerly empty param)
2018-05-06 Jürgen Spitzmüller <spitz@lyx.org> 2018-05-06 Jürgen Spitzmüller <spitz@lyx.org>
* format incremented to 551: add font info param \nospellcheck that prevents * format incremented to 551: add font info param \nospellcheck that prevents
text from being spellchecked. text from being spellchecked.

View File

@ -213,6 +213,74 @@ def revert_nospellcheck(document):
del document.body[i] del document.body[i]
def revert_floatpclass(document):
" Remove float placement params 'document' and 'class' "
i = 0
i = find_token(document.header, "\\float_placement class", 0)
if i != -1:
del document.header[i]
i = 0
while True:
i = find_token(document.body, '\\begin_inset Float', i)
if i == -1:
break
j = find_end_of_inset(document.body, i)
k = find_token(document.body, 'placement class', i, i + 2)
if k == -1:
k = find_token(document.body, 'placement document', i, i + 2)
if k != -1:
del document.body[k]
i = j
continue
del document.body[k]
def revert_floatalignment(document):
" Remove float alignment params "
i = 0
i = find_token(document.header, "\\float_alignment", 0)
galignment = ""
if i != -1:
galignment = get_value(document.header, "\\float_alignment", i)
del document.header[i]
i = 0
while True:
i = find_token(document.body, '\\begin_inset Float', i)
if i == -1:
break
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Malformed LyX document: Can't find end of inset at line " + str(i))
i += 1
k = find_token(document.body, 'alignment', i, i + 4)
if k == -1:
i = j
continue
alignment = get_value(document.body, "alignment", k)
if alignment == "document":
alignment = galignment
del document.body[k]
l = find_token(document.body, "\\begin_layout Plain Layout", i, j)
if l == -1:
document.warning("Can't find float layout!")
i = j
continue
alcmd = []
if alignment == "left":
alcmd = put_cmd_in_ert("\\raggedright{}")
elif alignment == "center":
alcmd = put_cmd_in_ert("\\centering{}")
elif alignment == "right":
alcmd = put_cmd_in_ert("\\raggedleft{}")
if len(alcmd) > 0:
document.body[l+1:l+1] = alcmd
i = j
## ##
# Conversion hub # Conversion hub
# #
@ -225,11 +293,13 @@ convert = [
[548, []], [548, []],
[549, []], [549, []],
[550, [convert_fontenc]], [550, [convert_fontenc]],
[551, []] [551, []],
[552, []]
] ]
revert = [ revert = [
[549, [revert_nospellcheck]], [551, [revert_floatpclass, revert_floatalignment]],
[550, [revert_nospellcheck]],
[549, [revert_fontenc]], [549, [revert_fontenc]],
[548, []],# dummy format change [548, []],# dummy format change
[547, [revert_lscape]], [547, [revert_lscape]],

View File

@ -888,6 +888,7 @@ int Buffer::readHeader(Lexer & lex)
params().options.erase(); params().options.erase();
params().master.erase(); params().master.erase();
params().float_placement.erase(); params().float_placement.erase();
params().float_alignment.erase();
params().paperwidth.erase(); params().paperwidth.erase();
params().paperheight.erase(); params().paperheight.erase();
params().leftmargin.erase(); params().leftmargin.erase();

View File

@ -1071,6 +1071,8 @@ string BufferParams::readToken(Lexer & lex, string const & token,
spacing().set(spacetranslator().find(nspacing), tmp_val); spacing().set(spacetranslator().find(nspacing), tmp_val);
} else if (token == "\\float_placement") { } else if (token == "\\float_placement") {
lex >> float_placement; lex >> float_placement;
} else if (token == "\\float_alignment") {
lex >> float_alignment;
} else if (prefixIs(token, "\\pdf_") || token == "\\use_hyperref") { } else if (prefixIs(token, "\\pdf_") || token == "\\use_hyperref") {
string toktmp = pdfoptions().readToken(lex, token); string toktmp = pdfoptions().readToken(lex, token);
@ -1261,9 +1263,10 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
os << "\\bibtex_command " << bibtex_command << '\n'; os << "\\bibtex_command " << bibtex_command << '\n';
os << "\\index_command " << index_command << '\n'; os << "\\index_command " << index_command << '\n';
if (!float_placement.empty()) { if (!float_placement.empty())
os << "\\float_placement " << float_placement << '\n'; os << "\\float_placement " << float_placement << '\n';
} if (!float_alignment.empty())
os << "\\float_alignment " << float_alignment << '\n';
os << "\\paperfontsize " << fontsize << '\n'; os << "\\paperfontsize " << fontsize << '\n';
spacing().writeFile(os); spacing().writeFile(os);

View File

@ -352,6 +352,8 @@ public:
/// ///
std::string float_placement; std::string float_placement;
/// ///
std::string float_alignment;
///
unsigned int columns; unsigned int columns;
/// ///
bool justification; bool justification;

View File

@ -5,6 +5,7 @@
* *
* \author Edwin Leuven * \author Edwin Leuven
* \author John Levon * \author John Levon
* \author Jürgen Spitzmüller
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -39,6 +40,7 @@ FloatPlacement::FloatPlacement(bool show_options, QWidget * parent)
setupUi(this); setupUi(this);
connect(floatTypeCO, SIGNAL(activated(int)), this, SLOT(changedSlot())); connect(floatTypeCO, SIGNAL(activated(int)), this, SLOT(changedSlot()));
connect(placementCO, SIGNAL(activated(int)), this, SLOT(changedSlot()));
connect(topCB, SIGNAL(clicked()), this, SLOT(changedSlot())); connect(topCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
connect(bottomCB, SIGNAL(clicked()), this, SLOT(changedSlot())); connect(bottomCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
connect(pageCB, SIGNAL(clicked()), this, SLOT(changedSlot())); connect(pageCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
@ -47,11 +49,19 @@ FloatPlacement::FloatPlacement(bool show_options, QWidget * parent)
connect(ignoreCB, SIGNAL(clicked()), this, SLOT(changedSlot())); connect(ignoreCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
connect(spanCB, SIGNAL(clicked()), this, SLOT(changedSlot())); connect(spanCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
connect(sidewaysCB, SIGNAL(clicked()), this, SLOT(changedSlot())); connect(sidewaysCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
connect(alignClassDefaultRB, SIGNAL(clicked()), this, SLOT(changedSlot()));
connect(alignDocDefaultRB, SIGNAL(clicked()), this, SLOT(changedSlot()));
connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(changedSlot()));
connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(changedSlot()));
connect(alignRightRB, SIGNAL(clicked()), this, SLOT(changedSlot()));
floatTypeTitle->setVisible(show_options); floatTypeTitle->setVisible(show_options);
floatTypeCO->setVisible(show_options); floatTypeCO->setVisible(show_options);
alignDocDefaultRB->setVisible(show_options);
spanCB->setVisible(show_options); spanCB->setVisible(show_options);
sidewaysCB->setVisible(show_options); sidewaysCB->setVisible(show_options);
optionsGB->setVisible(show_options);
initFloatPlacementCO(show_options);
} }
@ -59,7 +69,10 @@ docstring FloatPlacement::dialogToParams() const
{ {
InsetFloatParams params; InsetFloatParams params;
params.type = fromqstr(floatTypeCO->itemData(floatTypeCO->currentIndex()).toString()); params.type = fromqstr(floatTypeCO->itemData(floatTypeCO->currentIndex()).toString());
params.placement = get(params.wide, params.sideways); params.wide = spanCB->isChecked();
params.sideways = sidewaysCB->isChecked();
params.alignment = getAlignment();
params.placement = getPlacement();
return from_ascii(InsetFloat::params2string(params)); return from_ascii(InsetFloat::params2string(params));
} }
@ -82,9 +95,10 @@ bool FloatPlacement::possiblePlacement(char const & p) const
} }
void FloatPlacement::set(string const & placement) void FloatPlacement::setPlacement(string const & placement)
{ {
bool def_placement = false; bool def_placement = false;
bool doc_placement = false;
bool top = false; bool top = false;
bool bottom = false; bool bottom = false;
bool page = false; bool page = false;
@ -92,9 +106,11 @@ void FloatPlacement::set(string const & placement)
bool force = false; bool force = false;
bool here_definitely = false; bool here_definitely = false;
if (placement.empty()) { if (placement.empty() || placement == "class")
def_placement = true; def_placement = true;
} else if (contains(placement, 'H') && possiblePlacement('H')) { else if (placement == "document")
doc_placement = true;
else if (contains(placement, 'H') && possiblePlacement('H')) {
here_definitely = true; here_definitely = true;
} else { } else {
if (contains(placement, '!') && possiblePlacement('!')) { if (contains(placement, '!') && possiblePlacement('!')) {
@ -114,7 +130,12 @@ void FloatPlacement::set(string const & placement)
} }
} }
defaultsCB->setChecked(def_placement); if (def_placement)
placementCO->setCurrentIndex(placementCO->findData(toqstr("class")));
else if (doc_placement)
placementCO->setCurrentIndex(placementCO->findData(toqstr("document")));
else
placementCO->setCurrentIndex(placementCO->findData(toqstr("custom")));
topCB->setChecked(top); topCB->setChecked(top);
bottomCB->setChecked(bottom); bottomCB->setChecked(bottom);
pageCB->setChecked(page); pageCB->setChecked(page);
@ -125,6 +146,21 @@ void FloatPlacement::set(string const & placement)
} }
void FloatPlacement::setAlignment(string const & alignment)
{
if (alignment == "document")
alignDocDefaultRB->setChecked(true);
else if (alignment == "left")
alignLeftRB->setChecked(true);
else if (alignment == "center")
alignCenterRB->setChecked(true);
else if (alignment == "right")
alignRightRB->setChecked(true);
else
alignClassDefaultRB->setChecked(true);
}
void FloatPlacement::initFloatTypeCO(FloatList const & floats) void FloatPlacement::initFloatTypeCO(FloatList const & floats)
{ {
if (float_list_ == &floats) if (float_list_ == &floats)
@ -141,6 +177,15 @@ void FloatPlacement::initFloatTypeCO(FloatList const & floats)
} }
void FloatPlacement::initFloatPlacementCO(bool const local)
{
placementCO->addItem(qt_("Class Defaults"), "class");
if (local)
placementCO->addItem(qt_("Document Defaults"), "document");
placementCO->addItem(qt_("Custom"), "custom");
}
void FloatPlacement::paramsToDialog(Inset const * inset) void FloatPlacement::paramsToDialog(Inset const * inset)
{ {
InsetFloat const * fl = static_cast<InsetFloat const *>(inset); InsetFloat const * fl = static_cast<InsetFloat const *>(inset);
@ -157,7 +202,8 @@ void FloatPlacement::paramsToDialog(Inset const * inset)
allows_sideways_ = floats.allowsSideways(params.type); allows_sideways_ = floats.allowsSideways(params.type);
allows_wide_ = floats.allowsWide(params.type); allows_wide_ = floats.allowsWide(params.type);
set(params.placement); setPlacement(params.placement);
setAlignment(params.alignment);
standardfloat_ = (params.type == "figure" standardfloat_ = (params.type == "figure"
|| params.type == "table"); || params.type == "table");
@ -175,21 +221,16 @@ void FloatPlacement::paramsToDialog(Inset const * inset)
} }
string const FloatPlacement::get(bool & wide, bool & sideways) const string const FloatPlacement::getPlacement() const
{
wide = spanCB->isChecked();
sideways = sidewaysCB->isChecked();
return get();
}
string const FloatPlacement::get() const
{ {
string placement; string placement;
if (defaultsCB->isChecked()) QString const data =
return placement; placementCO->itemData(placementCO->currentIndex()).toString();
if (data == "class")
return "class";
if (data == "document")
return "document";
if (heredefinitelyCB->isChecked()) { if (heredefinitelyCB->isChecked()) {
placement += 'H'; placement += 'H';
@ -214,10 +255,24 @@ string const FloatPlacement::get() const
} }
void FloatPlacement::on_defaultsCB_stateChanged(int state) string const FloatPlacement::getAlignment() const
{
if (alignDocDefaultRB->isChecked())
return "document";
if (alignLeftRB->isChecked())
return "left";
if (alignCenterRB->isChecked())
return "center";
if (alignRightRB->isChecked())
return "right";
return "class";
}
void FloatPlacement::on_placementCO_currentIndexChanged(QString const & text)
{ {
checkAllowed(); checkAllowed();
if (state == Qt::Checked) if (text != "custom")
return; return;
if (topCB->isChecked() || bottomCB->isChecked() if (topCB->isChecked() || bottomCB->isChecked()
|| pageCB->isChecked() || herepossiblyCB->isChecked() || pageCB->isChecked() || herepossiblyCB->isChecked()
@ -235,7 +290,8 @@ void FloatPlacement::changedSlot()
void FloatPlacement::checkAllowed() const void FloatPlacement::checkAllowed() const
{ {
bool const defaults = defaultsCB->isChecked(); bool const defaults =
placementCO->itemData(placementCO->currentIndex()).toString() != "custom";
bool const ignore = topCB->isChecked() || bottomCB->isChecked() bool const ignore = topCB->isChecked() || bottomCB->isChecked()
|| pageCB->isChecked() || herepossiblyCB->isChecked(); || pageCB->isChecked() || herepossiblyCB->isChecked();
bool const heredefinitely = heredefinitelyCB->isChecked(); bool const heredefinitely = heredefinitelyCB->isChecked();
@ -273,7 +329,7 @@ void FloatPlacement::checkAllowed() const
bottomCB->setChecked(false); bottomCB->setChecked(false);
spanCB->setEnabled(allows_wide_ && (!sideways || standardfloat_)); spanCB->setEnabled(allows_wide_ && (!sideways || standardfloat_));
sidewaysCB->setEnabled(allows_sideways_); sidewaysCB->setEnabled(allows_sideways_);
defaultsCB->setEnabled(!(sideways && span)); placementCO->setEnabled(!(sideways && span));
} else { } else {
topCB->setEnabled(!defaults && !heredefinitely); topCB->setEnabled(!defaults && !heredefinitely);
bottomCB->setEnabled(!defaults && !heredefinitely); bottomCB->setEnabled(!defaults && !heredefinitely);
@ -289,8 +345,8 @@ bool FloatPlacement::checkWidgets(bool readonly) const
{ {
if (readonly) { if (readonly) {
floatTypeCO->setEnabled(false); floatTypeCO->setEnabled(false);
defaultsCB->setEnabled(false); placementCO->setEnabled(false);
options->setEnabled(false); aligmentGB->setEnabled(false);
spanCB->setEnabled(false); spanCB->setEnabled(false);
sidewaysCB->setEnabled(false); sidewaysCB->setEnabled(false);
} else } else

View File

@ -45,22 +45,26 @@ public:
/// ///
void useSideways(); void useSideways();
/// ///
void set(std::string const & placement); void setPlacement(std::string const & placement);
/// ///
std::string const get() const; void setAlignment(std::string const & placement);
///
std::string const getPlacement() const;
///
std::string const getAlignment() const;
private Q_SLOTS: private Q_SLOTS:
void on_defaultsCB_stateChanged(int state); void on_placementCO_currentIndexChanged(QString const &);
void changedSlot(); void changedSlot();
private: private:
/// ///
void checkAllowed() const; void checkAllowed() const;
/// ///
std::string const get(bool & wide, bool & sideways) const;
///
void initFloatTypeCO(FloatList const & floats); void initFloatTypeCO(FloatList const & floats);
/// ///
void initFloatPlacementCO(bool const);
///
bool possiblePlacement(char const & p) const; bool possiblePlacement(char const & p) const;
/// one of figure or table? /// one of figure or table?

View File

@ -1556,7 +1556,7 @@ GuiDocument::GuiDocument(GuiView & lv)
docPS->addPanel(indicesModule, N_("Indexes")); docPS->addPanel(indicesModule, N_("Indexes"));
docPS->addPanel(pdfSupportModule, N_("PDF Properties")); docPS->addPanel(pdfSupportModule, N_("PDF Properties"));
docPS->addPanel(mathsModule, N_("Math Options")); docPS->addPanel(mathsModule, N_("Math Options"));
docPS->addPanel(floatModule, N_("Float Placement")); docPS->addPanel(floatModule, N_("Float Settings"));
docPS->addPanel(listingsModule, N_("Listings[[inset]]")); docPS->addPanel(listingsModule, N_("Listings[[inset]]"));
docPS->addPanel(bulletsModule, N_("Bullets")); docPS->addPanel(bulletsModule, N_("Bullets"));
docPS->addPanel(branchesModule, N_("Branches")); docPS->addPanel(branchesModule, N_("Branches"));
@ -3216,8 +3216,9 @@ void GuiDocument::applyView()
bp_.maintain_unincluded_children = bp_.maintain_unincluded_children =
masterChildModule->maintainAuxCB->isChecked(); masterChildModule->maintainAuxCB->isChecked();
// Float Placement // Float Settings
bp_.float_placement = floatModule->get(); bp_.float_placement = floatModule->getPlacement();
bp_.float_alignment = floatModule->getAlignment();
// Listings // Listings
// text should have passed validation // text should have passed validation
@ -3747,7 +3748,8 @@ void GuiDocument::paramsToDialog()
bp_.maintain_unincluded_children); bp_.maintain_unincluded_children);
// Float Settings // Float Settings
floatModule->set(bp_.float_placement); floatModule->setPlacement(bp_.float_placement);
floatModule->setAlignment(bp_.float_alignment);
// ListingsSettings // ListingsSettings
// break listings_params to multiple lines // break listings_params to multiple lines

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>FloatPlacementUi</class> <class>FloatPlacementUi</class>
<widget class="QWidget" name="FloatPlacementUi"> <widget class="QWidget" name="FloatPlacementUi">
@ -5,110 +6,52 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>207</width> <width>530</width>
<height>382</height> <height>413</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout" > <layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0"> <item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="floatTypeTitle"> <widget class="QLabel" name="floatTypeTitle">
<property name="text"> <property name="text">
<string>Float Type:</string> <string>Float T&amp;ype:</string>
</property>
<property name="buddy">
<cstring>floatTypeCO</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1" colspan="2" > <item>
<widget class="QComboBox" name="floatTypeCO"> <widget class="QComboBox" name="floatTypeCO">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" > <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch> <horstretch>1</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="4" > </layout>
<widget class="QCheckBox" name="defaultsCB" >
<property name="text" >
<string>Use &amp;default placement</string>
</property>
</widget>
</item> </item>
<item row="2" column="0" colspan="4" > <item row="2" column="3" rowspan="3">
<widget class="QGroupBox" name="options" > <spacer name="verticalSpacer">
<property name="title" > <property name="orientation">
<string>Advanced Placement Options</string> <enum>Qt::Vertical</enum>
</property> </property>
<layout class="QGridLayout" > <property name="sizeHint" stdset="0">
<property name="margin" > <size>
<number>9</number> <width>20</width>
<height>154</height>
</size>
</property> </property>
<property name="spacing" > </spacer>
<number>6</number>
</property>
<item row="0" column="0" >
<widget class="QCheckBox" name="topCB" >
<property name="text" >
<string>&amp;Top of page</string>
</property>
</widget>
</item>
<item row="5" column="0" >
<widget class="QCheckBox" name="ignoreCB" >
<property name="text" >
<string>&amp;Ignore LaTeX rules</string>
</property>
</widget>
</item> </item>
<item row="4" column="0"> <item row="4" column="0">
<widget class="QCheckBox" name="heredefinitelyCB" >
<property name="text" >
<string>Here de&amp;finitely</string>
</property>
</widget>
</item>
<item row="3" column="0" >
<widget class="QCheckBox" name="herepossiblyCB" >
<property name="text" >
<string>&amp;Here if possible</string>
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QCheckBox" name="pageCB" >
<property name="text" >
<string>&amp;Page of floats</string>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QCheckBox" name="bottomCB" >
<property name="text" >
<string>&amp;Bottom of page</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0" colspan="2" >
<widget class="QCheckBox" name="spanCB" >
<property name="text" >
<string>&amp;Span columns</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2" >
<widget class="QCheckBox" name="sidewaysCB" >
<property name="text" >
<string>&amp;Rotate sideways</string>
</property>
</widget>
</item>
<item row="5" column="2" colspan="2" >
<spacer> <spacer>
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -121,10 +64,203 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="1" column="3">
<widget class="QGroupBox" name="aligmentGB">
<property name="title">
<string>Alignment of Contents</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="_2">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="1" column="0">
<widget class="QRadioButton" name="alignDocDefaultRB">
<property name="toolTip">
<string>Use the document's default alignment for floats, as specified in Document Settings.</string>
</property>
<property name="text">
<string>D&amp;ocument Defaults</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="alignLeftRB">
<property name="toolTip">
<string>Left-align float contents</string>
</property>
<property name="text">
<string>&amp;Left</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QRadioButton" name="alignCenterRB">
<property name="toolTip">
<string>Center float contents</string>
</property>
<property name="text">
<string>&amp;Center</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QRadioButton" name="alignRightRB">
<property name="toolTip">
<string>Right-align float contents</string>
</property>
<property name="text">
<string>&amp;Right</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QRadioButton" name="alignClassDefaultRB">
<property name="toolTip">
<string>Use the class' default alignment for floats, whatever it is.</string>
</property>
<property name="text">
<string>Class &amp;Defaults</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QGroupBox" name="optionsGB">
<property name="title">
<string>Further Options</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QCheckBox" name="spanCB">
<property name="text">
<string>&amp;Span columns</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="sidewaysCB">
<property name="text">
<string>Rotate side&amp;ways</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" rowspan="2" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Position on Page</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="placementLA">
<property name="text">
<string>Place&amp;ment Settings:</string>
</property>
<property name="buddy">
<cstring>placementCO</cstring>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="placementCO"/>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="topCB">
<property name="text">
<string>&amp;Top of page</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="bottomCB">
<property name="text">
<string>&amp;Bottom of page</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="pageCB">
<property name="text">
<string>&amp;Page of floats</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="herepossiblyCB">
<property name="text">
<string>&amp;Here if possible</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="heredefinitelyCB">
<property name="text">
<string>Here de&amp;finitely</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="ignoreCB">
<property name="text">
<string>&amp;Ignore LaTeX rules</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="1" colspan="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>303</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="4">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
<tabstops> <tabstops>
<tabstop>defaultsCB</tabstop>
<tabstop>topCB</tabstop> <tabstop>topCB</tabstop>
<tabstop>bottomCB</tabstop> <tabstop>bottomCB</tabstop>
<tabstop>pageCB</tabstop> <tabstop>pageCB</tabstop>
@ -136,22 +272,5 @@
<include location="local">qt_i18n.h</include> <include location="local">qt_i18n.h</include>
</includes> </includes>
<resources/> <resources/>
<connections> <connections/>
<connection>
<sender>defaultsCB</sender>
<signal>toggled(bool)</signal>
<receiver>options</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>51</x>
<y>20</y>
</hint>
<hint type="destinationlabel" >
<x>201</x>
<y>47</y>
</hint>
</hints>
</connection>
</connections>
</ui> </ui>

View File

@ -166,6 +166,7 @@ void InsetFloat::doDispatch(Cursor & cur, FuncRequest & cmd)
params_.wide = params.wide; params_.wide = params.wide;
params_.sideways = params.sideways; params_.sideways = params.sideways;
} }
params_.alignment = params.alignment;
setNewLabel(); setNewLabel();
if (params_.type != params.type) if (params_.type != params.type)
setCaptionType(params.type); setCaptionType(params.type);
@ -235,6 +236,8 @@ void InsetFloatParams::write(ostream & os) const
if (!placement.empty()) if (!placement.empty())
os << "placement " << placement << "\n"; os << "placement " << placement << "\n";
if (!alignment.empty())
os << "alignment " << alignment << "\n";
if (wide) if (wide)
os << "wide true\n"; os << "wide true\n";
@ -254,6 +257,8 @@ void InsetFloatParams::read(Lexer & lex)
lex >> type; lex >> type;
if (lex.checkFor("placement")) if (lex.checkFor("placement"))
lex >> placement; lex >> placement;
if (lex.checkFor("alignment"))
lex >> alignment;
lex >> "wide" >> wide; lex >> "wide" >> wide;
lex >> "sideways" >> sideways; lex >> "sideways" >> sideways;
} }
@ -366,13 +371,14 @@ void InsetFloat::latex(otexstream & os, OutputParams const & runparams_in) const
string tmpplacement; string tmpplacement;
string const buf_placement = buffer().params().float_placement; string const buf_placement = buffer().params().float_placement;
string const def_placement = floats.defaultPlacement(params_.type); string const def_placement = floats.defaultPlacement(params_.type);
if (!params_.placement.empty() if (params_.placement == "document"
&& params_.placement != def_placement) {
tmpplacement = params_.placement;
} else if (params_.placement.empty()
&& !buf_placement.empty() && !buf_placement.empty()
&& buf_placement != def_placement) { && buf_placement != def_placement) {
tmpplacement = buf_placement; tmpplacement = buf_placement;
} else if (!params_.placement.empty()
&& params_.placement != "document"
&& params_.placement != def_placement) {
tmpplacement = params_.placement;
} }
// Check if placement is allowed by this float // Check if placement is allowed by this float
@ -386,6 +392,17 @@ void InsetFloat::latex(otexstream & os, OutputParams const & runparams_in) const
placement += *lit; placement += *lit;
} }
string alignment;
string const buf_alignment = buffer().params().float_alignment;
if (params_.alignment == "document"
&& !buf_alignment.empty()) {
alignment = buf_alignment;
} else if (!params_.alignment.empty()
&& params_.alignment != "class"
&& params_.alignment != "document") {
alignment = params_.alignment;
}
// Force \begin{<floatname>} to appear in a new line. // Force \begin{<floatname>} to appear in a new line.
os << breakln << "\\begin{" << from_ascii(tmptype) << '}'; os << breakln << "\\begin{" << from_ascii(tmptype) << '}';
if (runparams.lastid != -1) if (runparams.lastid != -1)
@ -397,6 +414,12 @@ void InsetFloat::latex(otexstream & os, OutputParams const & runparams_in) const
&& (!params_.sideways || (params_.sideways && from_ascii(placement) != "p"))) && (!params_.sideways || (params_.sideways && from_ascii(placement) != "p")))
os << '[' << from_ascii(placement) << ']'; os << '[' << from_ascii(placement) << ']';
os << '\n'; os << '\n';
if (alignment == "left")
os << "\\raggedright" << breakln;
else if (alignment == "center")
os << "\\centering" << breakln;
else if (alignment == "right")
os << "\\raggedleft" << breakln;
InsetText::latex(os, runparams); InsetText::latex(os, runparams);

View File

@ -25,7 +25,8 @@ class InsetFloatParams
{ {
public: public:
/// ///
InsetFloatParams() : type("senseless"), wide(false), sideways(false), subfloat(false) {} InsetFloatParams() : type("senseless"), placement("document"), alignment("document"),
wide(false), sideways(false), subfloat(false) {}
/// ///
void write(std::ostream & os) const; void write(std::ostream & os) const;
/// ///
@ -34,6 +35,8 @@ public:
std::string type; std::string type;
/// ///
std::string placement; std::string placement;
///
std::string alignment;
/// span columns /// span columns
bool wide; bool wide;
/// ///

View File

@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
// Do not remove the comment below, so we get merge conflict in // Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own. // independent branches. Instead add your own.
#define LYX_FORMAT_LYX 551 // spitz: \nospellcheck font param #define LYX_FORMAT_LYX 552 // spitz: float alignment
#define LYX_FORMAT_TEX2LYX 551 #define LYX_FORMAT_TEX2LYX 552
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#ifndef _MSC_VER #ifndef _MSC_VER