Author: leuven
Date: Sat Jun 5 09:44:44 2010
New Revision: 34598
URL: http://www.lyx.org/trac/changeset/34598
Log:
add support for decimal alignment in tables
Added:
lyx-devel/trunk/lib/images/tabular-feature_align-decimal.png (contents,
props changed)
Modified:
lyx-devel/trunk/lib/lyx2lyx/lyx_2_0.py
lyx-devel/trunk/lib/ui/stdtoolbars.inc
lyx-devel/trunk/src/Buffer.cpp
lyx-devel/trunk/src/LayoutEnums.h
lyx-devel/trunk/src/LyXRC.cpp
lyx-devel/trunk/src/LyXRC.h
lyx-devel/trunk/src/frontends/qt4/GuiPrefs.cpp
lyx-devel/trunk/src/frontends/qt4/GuiTabular.cpp
lyx-devel/trunk/src/frontends/qt4/ui/PrefLanguageUi.ui
lyx-devel/trunk/src/frontends/qt4/ui/TabularUi.ui
lyx-devel/trunk/src/insets/InsetTabular.cpp
lyx-devel/trunk/src/insets/InsetTabular.h
Added: lyx-devel/trunk/lib/images/tabular-feature_align-decimal.png
==============================================================================
Binary file. No diff available.
Modified: lyx-devel/trunk/lib/lyx2lyx/lyx_2_0.py
==============================================================================
--- lyx-devel/trunk/lib/lyx2lyx/lyx_2_0.py Sat Jun 5 00:53:44 2010
(r34597)
+++ lyx-devel/trunk/lib/lyx2lyx/lyx_2_0.py Sat Jun 5 09:44:44 2010
(r34598)
@@ -28,6 +28,13 @@
####################################################################
# Private helper functions
+def remove_option(document, m, option):
+ l = document.body[m].find(option)
+ if l != -1:
+ val = document.body[m][l:].split('"')[1]
+ document.body[m] = document.body[m][:l-1] +
document.body[m][l+len(option + '="' + val + '"'):]
+ return l
+
def find_end_of_inset(lines, i):
" Find end of inset, where lines[i] is included."
return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
@@ -1588,6 +1595,16 @@
del document.header[i]
+def revert_align_decimal(document):
+ l = 0
+ while True:
+ l = document.body[l].find('alignment=decimal')
+ if l == -1:
+ break
+ remove_option(document, l, 'decimal_point')
+ document.body[l].replace('decimal', 'center')
+
+
##
# Conversion hub
#
@@ -1637,10 +1654,12 @@
[387, []],
[388, []],
[389, [convert_html_quotes]],
- [390, []]
+ [390, []],
+ [391, []]
]
-revert = [[389, [revert_output_sync]],
+revert = [[390, [revert_align_decimal]],
+ [389, [revert_output_sync]],
[388, [revert_html_quotes]],
[387, [revert_pagesizes]],
[386, [revert_math_scale]],
Modified: lyx-devel/trunk/lib/ui/stdtoolbars.inc
==============================================================================
--- lyx-devel/trunk/lib/ui/stdtoolbars.inc Sat Jun 5 00:53:44 2010
(r34597)
+++ lyx-devel/trunk/lib/ui/stdtoolbars.inc Sat Jun 5 09:44:44 2010
(r34598)
@@ -154,6 +154,7 @@
Item "Align left" "command-alternatives inset-modify tabular
m-align-left;inset-modify tabular align-left"
Item "Align center" "command-alternatives inset-modify tabular
m-align-center;inset-modify tabular align-center"
Item "Align right" "command-alternatives inset-modify tabular
m-align-right;inset-modify tabular align-right"
+ Item "Align on decimal" "inset-modify tabular align-decimal"
Separator
Item "Align top" "command-alternatives inset-modify tabular
m-valign-top;inset-modify tabular valign-top"
Item "Align middle" "command-alternatives inset-modify tabular
m-valign-middle;inset-modify tabular valign-middle"
Modified: lyx-devel/trunk/src/Buffer.cpp
==============================================================================
--- lyx-devel/trunk/src/Buffer.cpp Sat Jun 5 00:53:44 2010 (r34597)
+++ lyx-devel/trunk/src/Buffer.cpp Sat Jun 5 09:44:44 2010 (r34598)
@@ -126,7 +126,7 @@
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
-int const LYX_FORMAT = 390; // ps: forward view
+int const LYX_FORMAT = 391; // edwin: decimal alignment in tables
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
Modified: lyx-devel/trunk/src/LayoutEnums.h
==============================================================================
--- lyx-devel/trunk/src/LayoutEnums.h Sat Jun 5 00:53:44 2010 (r34597)
+++ lyx-devel/trunk/src/LayoutEnums.h Sat Jun 5 09:44:44 2010 (r34598)
@@ -59,7 +59,9 @@
///
LYX_ALIGN_LAYOUT = 16,
///
- LYX_ALIGN_SPECIAL = 32
+ LYX_ALIGN_SPECIAL = 32,
+ ///
+ LYX_ALIGN_DECIMAL = 64
};
///
Modified: lyx-devel/trunk/src/LyXRC.cpp
==============================================================================
--- lyx-devel/trunk/src/LyXRC.cpp Sat Jun 5 00:53:44 2010 (r34597)
+++ lyx-devel/trunk/src/LyXRC.cpp Sat Jun 5 09:44:44 2010 (r34598)
@@ -84,6 +84,7 @@
{ "\\cursor_follows_scrollbar", LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR },
{ "\\date_insert_format", LyXRC::RC_DATE_INSERT_FORMAT },
{ "\\def_file", LyXRC::RC_DEFFILE },
+ { "\\default_decimal_point", LyXRC::RC_DEFAULT_DECIMAL_POINT },
{ "\\default_language", LyXRC::RC_DEFAULT_LANGUAGE },
{ "\\default_papersize", LyXRC::RC_DEFAULT_PAPERSIZE },
{ "\\default_view_format", LyXRC::RC_DEFAULT_VIEW_FORMAT },
@@ -352,6 +353,7 @@
completion_inline_text = false;
completion_inline_dots = -1;
completion_inline_delay = 0.2;
+ default_decimal_point = ".";
}
@@ -939,6 +941,9 @@
backupdir_path = expandPath(backupdir_path);
}
break;
+ case RC_DEFAULT_DECIMAL_POINT:
+ lexrc >> default_decimal_point;
+ break;
case RC_DATE_INSERT_FORMAT:
lexrc >> date_insert_format;
break;
@@ -2380,6 +2385,14 @@
if (tag != RC_LAST)
break;
+ case RC_DEFAULT_DECIMAL_POINT:
+ if (ignore_system_lyxrc ||
+ default_decimal_point !=
system_lyxrc.default_decimal_point) {
+ os << "\\default_decimal_point " <<
default_decimal_point << '\n';
+ }
+ if (tag != RC_LAST)
+ break;
+
case RC_SPELLCHECKER:
if (ignore_system_lyxrc ||
spellchecker != system_lyxrc.spellchecker) {
Modified: lyx-devel/trunk/src/LyXRC.h
==============================================================================
--- lyx-devel/trunk/src/LyXRC.h Sat Jun 5 00:53:44 2010 (r34597)
+++ lyx-devel/trunk/src/LyXRC.h Sat Jun 5 09:44:44 2010 (r34598)
@@ -66,6 +66,7 @@
RC_COPIER,
RC_CURSOR_FOLLOWS_SCROLLBAR,
RC_DATE_INSERT_FORMAT,
+ RC_DEFAULT_DECIMAL_POINT,
RC_DEFAULT_LANGUAGE,
RC_DEFAULT_VIEW_FORMAT,
RC_DEFAULT_PAPERSIZE,
@@ -499,6 +500,8 @@
std::string forward_search_pdf;
///
int export_overwrite;
+ /// Default decimal point when aligning table columns on decimal
+ std::string default_decimal_point;
};
Modified: lyx-devel/trunk/src/frontends/qt4/GuiPrefs.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiPrefs.cpp Sat Jun 5 00:53:44
2010 (r34597)
+++ lyx-devel/trunk/src/frontends/qt4/GuiPrefs.cpp Sat Jun 5 09:44:44
2010 (r34598)
@@ -2070,6 +2070,8 @@
this, SIGNAL(changed()));
connect(uiLanguageCO, SIGNAL(activated(int)),
this, SIGNAL(changed()));
+ connect(defaultDecimalPointLE, SIGNAL(textChanged(QString)),
+ this, SIGNAL(changed()));
uiLanguageCO->clear();
@@ -2113,6 +2115,7 @@
rc.language_command_end = fromqstr(endCommandED->text());
rc.gui_language = fromqstr(
uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
+ rc.default_decimal_point = fromqstr(defaultDecimalPointLE->text());
}
@@ -2132,6 +2135,7 @@
languagePackageED->setText(toqstr(rc.language_package));
startCommandED->setText(toqstr(rc.language_command_begin));
endCommandED->setText(toqstr(rc.language_command_end));
+ defaultDecimalPointLE->setText(toqstr(rc.default_decimal_point));
int pos = uiLanguageCO->findData(toqstr(rc.gui_language));
uiLanguageCO->blockSignals(true);
Modified: lyx-devel/trunk/src/frontends/qt4/GuiTabular.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiTabular.cpp Sat Jun 5 00:53:44
2010 (r34597)
+++ lyx-devel/trunk/src/frontends/qt4/GuiTabular.cpp Sat Jun 5 09:44:44
2010 (r34598)
@@ -27,6 +27,7 @@
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "LyX.h"
+#include "LyXRC.h"
#include "insets/InsetTabular.h"
@@ -159,6 +160,10 @@
void GuiTabular::checkEnabled()
{
hAlignCB->setEnabled(true);
+ bool dalign = hAlignCB->currentText() == QString("Decimal");
+ decimalPointLE->setEnabled(dalign);
+ decimalL->setEnabled(dalign);
+
vAlignCB->setEnabled(!multirowCB->isChecked()
&& !widgetsToLength(widthED, widthUnitCB).empty());
@@ -271,38 +276,24 @@
void GuiTabular::setHAlign(string & param_str) const
{
- int const align = hAlignCB->currentIndex();
-
- enum HALIGN { LEFT, RIGHT, CENTER, BLOCK };
- HALIGN h = LEFT;
-
- switch (align) {
- case 0: h = LEFT; break;
- case 1: h = CENTER; break;
- case 2: h = RIGHT; break;
- case 3: h = BLOCK; break;
- }
-
Tabular::Feature num = Tabular::ALIGN_LEFT;
Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
-
- switch (h) {
- case LEFT:
- num = Tabular::ALIGN_LEFT;
- multi_num = Tabular::M_ALIGN_LEFT;
- break;
- case CENTER:
- num = Tabular::ALIGN_CENTER;
- multi_num = Tabular::M_ALIGN_CENTER;
- break;
- case RIGHT:
- num = Tabular::ALIGN_RIGHT;
- multi_num = Tabular::M_ALIGN_RIGHT;
- break;
- case BLOCK:
- num = Tabular::ALIGN_BLOCK;
- //multi_num: no equivalent
- break;
+ QString const align = hAlignCB->currentText();
+ if (align == qt_("Left")) {
+ num = Tabular::ALIGN_LEFT;
+ multi_num = Tabular::M_ALIGN_LEFT;
+ } else if (align == qt_("Center")) {
+ num = Tabular::ALIGN_CENTER;
+ multi_num = Tabular::M_ALIGN_CENTER;
+ } else if (align == qt_("Right")) {
+ num = Tabular::ALIGN_RIGHT;
+ multi_num = Tabular::M_ALIGN_RIGHT;
+ } else if (align == qt_("Justified")) {
+ num = Tabular::ALIGN_BLOCK;
+ //multi_num: no equivalent
+ } else if (align == qt_("Decimal")) {
+ num = Tabular::ALIGN_DECIMAL;
+ //multi_num: no equivalent
}
if (multicolumnCB->isChecked())
@@ -367,6 +358,13 @@
// FIXME: We should use Tabular directly.
string param_str = "tabular";
setHAlign(param_str);
+
+ // SET_DECIMAL_POINT must come after setHAlign() (ALIGN_DECIMAL)
+ string decimal_point = fromqstr(decimalPointLE->text());
+ if (decimal_point.empty())
+ decimal_point = lyxrc.default_decimal_point;
+ setParam(param_str, Tabular::SET_DECIMAL_POINT, decimal_point);
+
setVAlign(param_str);
setTableAlignment(param_str);
//
@@ -693,29 +691,43 @@
hAlignCB->addItem(qt_("Right"));
if (!multicol && !pwidth.zero())
hAlignCB->addItem(qt_("Justified"));
+ if (!multicol)
+ hAlignCB->addItem(qt_("Decimal"));
- int align = 0;
+ QString align;
switch (tabular.getAlignment(cell)) {
- case LYX_ALIGN_LEFT:
- align = 0;
- break;
- case LYX_ALIGN_CENTER:
- align = 1;
- break;
- case LYX_ALIGN_RIGHT:
- align = 2;
- break;
- case LYX_ALIGN_BLOCK:
- {
- if (!multicol && !pwidth.zero())
- align = 3;
- break;
- }
- default:
- align = 0;
- break;
+ case LYX_ALIGN_LEFT:
+ align = qt_("Left");
+ break;
+ case LYX_ALIGN_CENTER:
+ align = qt_("Center");
+ break;
+ case LYX_ALIGN_RIGHT:
+ align = qt_("Right");
+ break;
+ case LYX_ALIGN_BLOCK:
+ {
+ if (!multicol && !pwidth.zero())
+ align = qt_("Justified");
+ break;
+ }
+ case LYX_ALIGN_DECIMAL:
+ {
+ if (!multicol)
+ align = qt_("Decimal");
+ break;
+ }
+ default:
+ // we should never end up here
+ break;
}
- hAlignCB->setCurrentIndex(align);
+ hAlignCB->setCurrentIndex(hAlignCB->findText(align));
+
+ //
+ QString decimal_point = toqstr(tabular.column_info[col].decimal_point);
+ if (decimal_point.isEmpty())
+ decimal_point = toqstr(from_utf8(lyxrc.default_decimal_point));
+ decimalPointLE->setText(decimal_point);
int valign = 0;
switch (tabular.getVAlignment(cell)) {
@@ -772,6 +784,7 @@
captionStatusCB->blockSignals(true);
captionStatusCB->setChecked(false);
captionStatusCB->blockSignals(false);
+ checkEnabled();
return;
} else {
// longtables cannot have a vertical alignment
Modified: lyx-devel/trunk/src/frontends/qt4/ui/PrefLanguageUi.ui
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/ui/PrefLanguageUi.ui Sat Jun 5
00:53:44 2010 (r34597)
+++ lyx-devel/trunk/src/frontends/qt4/ui/PrefLanguageUi.ui Sat Jun 5
09:44:44 2010 (r34598)
@@ -43,14 +43,31 @@
</property>
</widget>
</item>
- <item row="1" column="2" rowspan="2">
+ <item row="1" column="2">
<widget class="QLineEdit" name="languagePackageED">
<property name="toolTip">
<string>Enter the command to load the language package (default:
babel)</string>
</property>
</widget>
</item>
- <item row="2" column="3" rowspan="2">
+ <item row="2" column="0" colspan="2">
+ <widget class="QLabel" name="startCommandLA">
+ <property name="text">
+ <string>Command s&tart:</string>
+ </property>
+ <property name="buddy">
+ <cstring>startCommandED</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2">
+ <widget class="QLineEdit" name="startCommandED">
+ <property name="toolTip">
+ <string>The LaTeX command that starts a switch to a foreign
language</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -64,36 +81,45 @@
</spacer>
</item>
<item row="3" column="0" colspan="2">
- <widget class="QLabel" name="startCommandLA">
+ <widget class="QLabel" name="endCommandLA">
<property name="text">
- <string>Command s&tart:</string>
+ <string>Command e&nd:</string>
</property>
<property name="buddy">
- <cstring>startCommandED</cstring>
+ <cstring>endCommandED</cstring>
</property>
</widget>
</item>
<item row="3" column="2">
- <widget class="QLineEdit" name="startCommandED">
+ <widget class="QLineEdit" name="endCommandED">
<property name="toolTip">
- <string>The LaTeX command that starts a switch to a foreign
language</string>
+ <string>The LaTeX command that ends a switch to a foreign
language</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
- <widget class="QLabel" name="endCommandLA">
+ <widget class="QLabel" name="decimalPointL">
<property name="text">
- <string>Command e&nd:</string>
+ <string>Default Decimal &Point:</string>
</property>
<property name="buddy">
- <cstring>endCommandED</cstring>
+ <cstring>defaultDecimalPointLE</cstring>
</property>
</widget>
</item>
<item row="4" column="2">
- <widget class="QLineEdit" name="endCommandED">
- <property name="toolTip">
- <string>The LaTeX command that ends a switch to a foreign
language</string>
+ <widget class="QLineEdit" name="defaultDecimalPointLE">
+ <property name="maximumSize">
+ <size>
+ <width>20</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="inputMask">
+ <string>X; </string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
</property>
</widget>
</item>
@@ -244,14 +270,19 @@
</layout>
</widget>
<tabstops>
+ <tabstop>uiLanguageCO</tabstop>
<tabstop>languagePackageED</tabstop>
<tabstop>startCommandED</tabstop>
<tabstop>endCommandED</tabstop>
+ <tabstop>defaultDecimalPointLE</tabstop>
<tabstop>useBabelCB</tabstop>
<tabstop>globalCB</tabstop>
<tabstop>autoBeginCB</tabstop>
<tabstop>autoEndCB</tabstop>
<tabstop>markForeignCB</tabstop>
+ <tabstop>rtlGB</tabstop>
+ <tabstop>logicalCursorRB</tabstop>
+ <tabstop>visualCursorRB</tabstop>
</tabstops>
<includes>
<include location="local">qt_i18n.h</include>
Modified: lyx-devel/trunk/src/frontends/qt4/ui/TabularUi.ui
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/ui/TabularUi.ui Sat Jun 5 00:53:44
2010 (r34597)
+++ lyx-devel/trunk/src/frontends/qt4/ui/TabularUi.ui Sat Jun 5 09:44:44
2010 (r34598)
@@ -5,17 +5,20 @@
<rect>
<x>0</x>
<y>0</y>
- <width>374</width>
- <height>389</height>
+ <width>358</width>
+ <height>376</height>
</rect>
</property>
<property name="windowTitle">
<string/>
</property>
<property name="sizeGripEnabled" stdset="0">
- <bool>true</bool>
+ <bool>false</bool>
</property>
- <layout class="QGridLayout" name="_2">
+ <layout class="QGridLayout" name="gridLayout_9">
+ <property name="margin">
+ <number>0</number>
+ </property>
<item row="0" column="0">
<widget class="QTabWidget" name="TabWidget">
<property name="toolTip">
@@ -73,23 +76,76 @@
<string>Right</string>
</property>
</item>
+ <item>
+ <property name="text">
+ <string>Decimal</string>
+ </property>
+ </item>
</widget>
</item>
<item row="0" column="2" colspan="2">
- <spacer>
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeType">
- <enum>QSizePolicy::Expanding</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <spacer>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Expanding</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="decimalL">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Decimal point:</string>
+ </property>
+ <property name="buddy">
+ <cstring>decimalPointLE</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="decimalPointLE">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>20</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="inputMask">
+ <string>X; </string>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="maxLength">
+ <number>1</number>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="fixedWidthColLA">
@@ -149,7 +205,7 @@
</item>
</widget>
</item>
- <item row="2" column="2" colspan="2">
+ <item row="2" column="2">
<spacer name="spacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -309,19 +365,6 @@
</property>
</widget>
</item>
- <item row="4" column="1">
- <spacer name="verticalSpacer_3">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>4</height>
- </size>
- </property>
- </spacer>
- </item>
</layout>
</widget>
<widget class="QWidget" name="Borders">
@@ -1420,43 +1463,49 @@
<tabstops>
<tabstop>TabWidget</tabstop>
<tabstop>hAlignCB</tabstop>
+ <tabstop>decimalPointLE</tabstop>
<tabstop>widthED</tabstop>
<tabstop>widthUnitCB</tabstop>
<tabstop>vAlignCB</tabstop>
<tabstop>multicolumnCB</tabstop>
- <tabstop>rotateTabularCB</tabstop>
<tabstop>multirowCB</tabstop>
<tabstop>rotateCellCB</tabstop>
+ <tabstop>TableAlignCB</tabstop>
+ <tabstop>rotateTabularCB</tabstop>
<tabstop>specialAlignmentED</tabstop>
- <tabstop>borderSetPB</tabstop>
- <tabstop>borderUnsetPB</tabstop>
<tabstop>borderDefaultRB</tabstop>
<tabstop>booktabsRB</tabstop>
<tabstop>topspaceCO</tabstop>
- <tabstop>bottomspaceCO</tabstop>
- <tabstop>interlinespaceCO</tabstop>
+ <tabstop>bottomspaceUnit</tabstop>
<tabstop>topspaceED</tabstop>
+ <tabstop>topspaceUnit</tabstop>
+ <tabstop>bottomspaceCO</tabstop>
<tabstop>bottomspaceED</tabstop>
<tabstop>interlinespaceED</tabstop>
- <tabstop>topspaceUnit</tabstop>
- <tabstop>bottomspaceUnit</tabstop>
- <tabstop>interlinespaceUnit</tabstop>
+ <tabstop>interlinespaceCO</tabstop>
<tabstop>longTabularCB</tabstop>
+ <tabstop>interlinespaceUnit</tabstop>
<tabstop>headerStatusCB</tabstop>
+ <tabstop>firstheaderNoContentsCB</tabstop>
<tabstop>headerBorderAboveCB</tabstop>
<tabstop>headerBorderBelowCB</tabstop>
<tabstop>firstheaderStatusCB</tabstop>
<tabstop>firstheaderBorderAboveCB</tabstop>
<tabstop>firstheaderBorderBelowCB</tabstop>
- <tabstop>firstheaderNoContentsCB</tabstop>
- <tabstop>footerStatusCB</tabstop>
<tabstop>footerBorderAboveCB</tabstop>
+ <tabstop>footerStatusCB</tabstop>
+ <tabstop>newpageCB</tabstop>
<tabstop>footerBorderBelowCB</tabstop>
<tabstop>lastfooterStatusCB</tabstop>
<tabstop>lastfooterBorderAboveCB</tabstop>
<tabstop>lastfooterBorderBelowCB</tabstop>
<tabstop>lastfooterNoContentsCB</tabstop>
- <tabstop>newpageCB</tabstop>
+ <tabstop>captionStatusCB</tabstop>
+ <tabstop>leftRB</tabstop>
+ <tabstop>borderSetPB</tabstop>
+ <tabstop>centerRB</tabstop>
+ <tabstop>rightRB</tabstop>
+ <tabstop>borderUnsetPB</tabstop>
</tabstops>
<includes>
<include location="local">qt_i18n.h</include>
Modified: lyx-devel/trunk/src/insets/InsetTabular.cpp
==============================================================================
--- lyx-devel/trunk/src/insets/InsetTabular.cpp Sat Jun 5 00:53:44 2010
(r34597)
+++ lyx-devel/trunk/src/insets/InsetTabular.cpp Sat Jun 5 09:44:44 2010
(r34598)
@@ -125,6 +125,7 @@
{ Tabular::ALIGN_RIGHT, "align-right", false },
{ Tabular::ALIGN_CENTER, "align-center", false },
{ Tabular::ALIGN_BLOCK, "align-block", false },
+ { Tabular::ALIGN_DECIMAL, "align-decimal", false },
{ Tabular::VALIGN_TOP, "valign-top", false },
{ Tabular::VALIGN_BOTTOM, "valign-bottom", false },
{ Tabular::VALIGN_MIDDLE, "valign-middle", false },
@@ -174,6 +175,7 @@
{ Tabular::LONGTABULAR_ALIGN_LEFT, "longtabular-align-left", false },
{ Tabular::LONGTABULAR_ALIGN_CENTER, "longtabular-align-center", false
},
{ Tabular::LONGTABULAR_ALIGN_RIGHT, "longtabular-align-right", false },
+ { Tabular::SET_DECIMAL_POINT, "set-decimal-point", true },
{ Tabular::LAST_ACTION, "", false }
};
@@ -251,6 +253,8 @@
return "layout";
case LYX_ALIGN_SPECIAL:
return "special";
+ case LYX_ALIGN_DECIMAL:
+ return "decimal";
}
return string();
}
@@ -311,6 +315,8 @@
num = LYX_ALIGN_CENTER;
else if (str == "right")
num = LYX_ALIGN_RIGHT;
+ else if (str == "decimal")
+ num = LYX_ALIGN_DECIMAL;
else
return false;
return true;
@@ -502,6 +508,30 @@
}
+InsetTableCell splitCell(InsetTableCell & head, docstring const align_d, bool
& hassep)
+{
+ InsetTableCell tail = InsetTableCell(head);
+ tail.getText(0)->setMacrocontextPosition(
+ head.getText(0)->macrocontextPosition());
+ tail.setBuffer(head.buffer());
+
+ DocIterator dit = doc_iterator_begin(&head.buffer(), &head);
+ for (; dit; dit.forwardChar())
+ if (dit.inTexted() && dit.depth()==1
+ && dit.paragraph().find(align_d, false, false,
dit.pos()))
+ break;
+
+ pit_type const psize = head.paragraphs().front().size();
+ hassep = dit;
+ if (hassep)
+ head.paragraphs().front().eraseChars(dit.pos(), psize, false);
+
+ tail.paragraphs().front().eraseChars(0,
+ dit.pos() < psize ? dit.pos() + 1 : psize, false);
+
+ return tail;
+}
+
/////////////////////////////////////////////////////////////////////
//
@@ -517,6 +547,8 @@
multirow(Tabular::CELL_NORMAL),
alignment(LYX_ALIGN_CENTER),
valignment(LYX_VALIGN_TOP),
+ decimal_hoffset(0),
+ decimal_width(0),
voffset(0),
top_line(false),
bottom_line(false),
@@ -537,6 +569,8 @@
multirow(cs.multirow),
alignment(cs.alignment),
valignment(cs.valignment),
+ decimal_hoffset(cs.decimal_hoffset),
+ decimal_width(cs.decimal_width),
voffset(cs.voffset),
top_line(cs.top_line),
bottom_line(cs.bottom_line),
@@ -564,6 +598,8 @@
std::swap(multirow, rhs.multirow);
std::swap(alignment, rhs.alignment);
std::swap(valignment, rhs.valignment);
+ std::swap(decimal_hoffset, rhs.decimal_hoffset);
+ std::swap(decimal_width, rhs.decimal_width);
std::swap(voffset, rhs.voffset);
std::swap(top_line, rhs.top_line);
std::swap(bottom_line, rhs.bottom_line);
@@ -814,7 +850,8 @@
rowofcell[i] = row;
columnofcell[i] = column;
setFixedWidth(row, column);
- updateContentAlignment(row, column);
+ cell_info[row][column].inset->setContentAlignment(
+ getAlignment(cellIndex(row, column)));
++i;
}
}
@@ -910,6 +947,14 @@
bool Tabular::updateColumnWidths()
{
+ vector<int> max_dwidth(ncols(), 0);
+ for(col_type c = 0; c < ncols(); ++c)
+ for(row_type r = 0; r < nrows(); ++r) {
+ idx_type const i = cellIndex(r, c);
+ if (getAlignment(i) == LYX_ALIGN_DECIMAL)
+ max_dwidth[c] = max(max_dwidth[c],
cell_info[r][c].decimal_width);
+ }
+
bool update = false;
// for each col get max of single col cells
for(col_type c = 0; c < ncols(); ++c) {
@@ -917,7 +962,11 @@
for(row_type r = 0; r < nrows(); ++r) {
idx_type const i = cellIndex(r, c);
if (columnSpan(i) == 1)
- new_width = max(new_width, cellInfo(i).width);
+ if (getAlignment(i) == LYX_ALIGN_DECIMAL)
+ new_width = max(new_width,
cellInfo(i).width
+ + max_dwidth[c] -
cellInfo(i).decimal_width);
+ else
+ new_width = max(new_width,
cellInfo(i).width);
}
if (column_info[c].width != new_width) {
@@ -966,11 +1015,16 @@
void Tabular::setAlignment(idx_type cell, LyXAlignment align,
bool onlycolumn)
{
- if (!isMultiColumn(cell) || onlycolumn)
- column_info[cellColumn(cell)].alignment = align;
- if (!onlycolumn)
+ col_type const col = cellColumn(cell);
+ if (onlycolumn || !isMultiColumn(cell)) {
+ column_info[col].alignment = align;
+ docstring & dpoint = column_info[col].decimal_point;
+ if (align == LYX_ALIGN_DECIMAL && dpoint.empty())
+ dpoint = from_utf8(lyxrc.default_decimal_point);
+ } else {
cellInfo(cell).alignment = align;
- cellInset(cell).get()->setContentAlignment(align);
+ cellInset(cell).get()->setContentAlignment(align);
+ }
}
@@ -1050,13 +1104,6 @@
}
-void Tabular::updateContentAlignment(row_type r, col_type c)
-{
- cell_info[r][c].inset->setContentAlignment(
- getAlignment(cellIndex(r, c)));
-}
-
-
bool Tabular::setMColumnPWidth(Cursor & cur, idx_type cell,
Length const & width)
{
@@ -1170,8 +1217,9 @@
LyXAlignment Tabular::getAlignment(idx_type cell, bool onlycolumn) const
{
- if (!onlycolumn && isMultiColumn(cell))
+ if (!onlycolumn && (isMultiColumn(cell) || isMultiRow(cell)))
return cellInfo(cell).alignment;
+
return column_info[cellColumn(cell)].alignment;
}
@@ -1212,6 +1260,21 @@
x += columnWidth(cell) - cellWidth(cell);
// + interColumnSpace(cell);
break;
+ case LYX_ALIGN_DECIMAL: {
+ // we center when no decimal point
+ if (cellInfo(cell).decimal_width == 0) {
+ x += (columnWidth(cell) - cellWidth(cell)) / 2;
+ break;
+ }
+ col_type const c = cellColumn(cell);
+ int max_dhoffset = 0;
+ for(row_type r = 0; r < row_info.size() ; ++r) {
+ idx_type const i = cellIndex(r, c);
+ if (getAlignment(i) == LYX_ALIGN_DECIMAL)
+ max_dhoffset = max(max_dhoffset,
cellInfo(i).decimal_hoffset);
+ }
+ x += max_dhoffset - cellInfo(cell).decimal_hoffset;
+ }
default:
// LYX_ALIGN_LEFT: nothing :-)
break;
@@ -1303,8 +1366,10 @@
os << ">\n";
for (col_type c = 0; c < ncols(); ++c) {
os << "<column"
- << write_attribute("alignment", column_info[c].alignment)
- << write_attribute("valignment", column_info[c].valignment)
+ << write_attribute("alignment", column_info[c].alignment);
+ if (column_info[c].alignment == LYX_ALIGN_DECIMAL)
+ os << write_attribute("decimal_point",
column_info[c].decimal_point);
+ os << write_attribute("valignment", column_info[c].valignment)
<< write_attribute("width",
column_info[c].p_width.asString())
<< write_attribute("special", column_info[c].align_special)
<< ">\n";
@@ -1410,6 +1475,7 @@
return;
}
getTokenValue(line, "alignment", column_info[c].alignment);
+ getTokenValue(line, "decimal_point",
column_info[c].decimal_point);
getTokenValue(line, "valignment", column_info[c].valignment);
getTokenValue(line, "width", column_info[c].p_width);
getTokenValue(line, "special", column_info[c].align_special);
@@ -1504,7 +1570,8 @@
cell = cellIndex(row, col);
CellData & cs = cellInfo(cell);
cs.multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
- cs.alignment = column_info[col].alignment;
+ if (column_info[col].alignment != LYX_ALIGN_DECIMAL)
+ cs.alignment = column_info[col].alignment;
if (col > 0)
setRightLine(cell, rightLine(cellIndex(row, col - 1)));
@@ -1544,7 +1611,7 @@
// change (assigning this to uwestoehr)
// until LyX supports this, use the deault alignment of multirow
// cells: left
- cs.alignment = LYX_ALIGN_LEFT;
+ cs.alignment = LYX_ALIGN_CENTER;
// set the bottom row of the last selected cell
setBottomLine(cell, bottomLine(cell + (number - 1)*ncols()));
@@ -1563,11 +1630,12 @@
Tabular::idx_type Tabular::columnSpan(idx_type cell) const
{
row_type const row = cellRow(cell);
- col_type column = cellColumn(cell) + 1;
- while (column < ncols() && isPartOfMultiColumn(row, column))
- ++column;
+ col_type const col = cellColumn(cell);
+ int span = 1;
+ while (col + span < ncols() && isPartOfMultiColumn(row, col + span))
+ ++span;
- return column - cellColumn(cell);
+ return span;
}
@@ -1936,20 +2004,29 @@
}
} else if (row == 0) {
for (col_type c = 0; c < ncols(); ++c) {
- if (topline[c]) {
- //babel makes the "-" character an active one,
so we have to suppress this here
- //see
http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
- if (lang == "slovak" || lang == "czech")
- os << (use_booktabs ?
"\\expandafter\\cmidrule\\expandafter{\\expandafter" :
-
"\\expandafter\\cline\\expandafter{\\expandafter")
-
<< c + 1 << "\\string-";
- else
- os << (use_booktabs ? "\\cmidrule{" :
"\\cline{") << c + 1 << '-';
- // get to last column of line span
- while (c < ncols() && topline[c])
- ++c;
- os << c << "} ";
- }
+ for ( ; c < ncols() && !topline[c]; ++c) {}
+
+ col_type offset = 0;
+ for (col_type j = 0 ; j < c; ++j)
+ if (column_info[j].alignment ==
LYX_ALIGN_DECIMAL)
+ ++offset;
+
+ //babel makes the "-" character an active one, so we
have to suppress this here
+ //see
http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
+ if (lang == "slovak" || lang == "czech")
+ os << "\\expandafter" << (use_booktabs ?
"\\cmidrule" : "\\cline")
+ << "\\expandafter{\\expandafter" << c + 1 +
offset << "\\string-";
+ else
+ os << (use_booktabs ? "\\cmidrule{" :
"\\cline{") << c + 1 + offset << '-';
+
+ col_type cstart = c;
+ for ( ; c < ncols() && topline[c]; ++c) {}
+
+ for (col_type j = cstart ; j < c ; ++j)
+ if (column_info[j].alignment ==
LYX_ALIGN_DECIMAL)
+ ++offset;
+
+ os << c + offset << "} ";
}
}
os << "\n";
@@ -2000,20 +2077,29 @@
os << "\\hline ";
} else {
for (col_type c = 0; c < ncols(); ++c) {
- if (bottomline[c]) {
- //babel makes the "-" character an active one,
so we have to suppress this here
- //see
http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
- if (lang == "slovak" || lang == "czech")
- os << (use_booktabs ?
"\\expandafter\\cmidrule\\expandafter{\\expandafter" :
-
"\\expandafter\\cline\\expandafter{\\expandafter")
-
<< c + 1 << "\\string-";
- else
- os << (use_booktabs ? "\\cmidrule{" :
"\\cline{") << c + 1 << '-';
- // get to last column of line span
- while (c < ncols() && bottomline[c])
- ++c;
- os << c << "} ";
- }
+ for ( ; c < ncols() && !bottomline[c]; ++c) {}
+
+ col_type offset = 0;
+ for (col_type j = 0 ; j < c; ++j)
+ if (column_info[j].alignment ==
LYX_ALIGN_DECIMAL)
+ ++offset;
+
+ //babel makes the "-" character an active one, so we
have to suppress this here
+ //see
http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
+ if (lang == "slovak" || lang == "czech")
+ os << "\\expandafter" << (use_booktabs ?
"\\cmidrule" : "\\cline")
+ << "\\expandafter{\\expandafter" << c + 1 +
offset << "\\string-";
+ else
+ os << (use_booktabs ? "\\cmidrule{" :
"\\cline{") << c + 1 + offset << '-';
+
+ col_type cstart = c;
+ for ( ; c < ncols() && bottomline[c]; ++c) {}
+
+ for (col_type j = cstart ; j < c ; ++j)
+ if (column_info[j].alignment ==
LYX_ALIGN_DECIMAL)
+ ++offset;
+
+ os << c + offset << "} ";
}
}
os << "\n";
@@ -2048,8 +2134,19 @@
|| ((colright || nextcolleft) && !rightLine(cell) &&
!nextcellleft)
|| (!colright && !nextcolleft && (rightLine(cell) ||
nextcellleft))
|| (coldouble != celldouble);
+
+ // we center in multicol when no decimal point
+ ismulticol |= ((column_info[c].alignment == LYX_ALIGN_DECIMAL)
+ && (cellInfo(cell).decimal_width == 0) || isMultiRow(cell));
+
+ // up counter by 1 for each decimally aligned col since they use 2
latex cols
+ int latexcolspan = columnSpan(cell);
+ for(col_type col = c; col < c + columnSpan(cell); ++col)
+ if (column_info[col].alignment == LYX_ALIGN_DECIMAL)
+ ++latexcolspan;
+
if (ismulticol) {
- os << "\\multicolumn{" << columnSpan(cell) << "}{";
+ os << "\\multicolumn{" << latexcolspan << "}{";
if (c ==0 && leftLine(cell))
os << '|';
if (!cellInfo(cell).align_special.empty()) {
@@ -2103,7 +2200,7 @@
// add extra vertical line if we want a double one
os << '|';
os << "}{";
- } // end if ismulticol
+ } // end if ismulticol
// we only need code for the first multirow cell
ismultirow = isMultiRow(cell);
@@ -2116,7 +2213,7 @@
// needs to be discussed
os << "*";
os << "}{";
- } // end if ismultirow
+ } // end if ismultirow
if (getRotateCell(cell)) {
os << "\\begin{sideways}\n";
@@ -2177,9 +2274,11 @@
os << "%\n\\end{sideways}";
++ret;
}
- if (ismulticol || ismultirow) {
+ if (ismultirow)
os << '}';
- }
+ if (ismulticol)
+ os << '}';
+
return ret;
}
@@ -2328,10 +2427,15 @@
bool ismulticol = false;
bool ismultirow = false;
for (col_type c = 0; c < ncols(); ++c) {
- if (isPartOfMultiRow(row, c))
- os << " & "; // we need to add a further column
- if (isPartOfMultiColumn(row, c) || isPartOfMultiRow(row, c))
+ if (isPartOfMultiColumn(row, c))
+ continue;
+
+ if (isPartOfMultiRow(row, c) &&
+ column_info[c].alignment != LYX_ALIGN_DECIMAL) {
+ os << " & ";
continue;
+ }
+
cell = cellIndex(row, c);
ret += TeXCellPreamble(os, cell, ismulticol, ismultirow);
shared_ptr<InsetTableCell> inset = cellInset(cell);
@@ -2360,7 +2464,22 @@
newrp.inTableCell = (getAlignment(cell) == LYX_ALIGN_BLOCK)
? OutputParams::PLAIN
: OutputParams::ALIGNED;
- ret += inset->latex(os, newrp);
+
+ if (getAlignment(cell) == LYX_ALIGN_DECIMAL
+ && cellInfo(cell).decimal_width != 0 &&
!isMultiRow(cell)) {
+ // copy cell and split in 2
+ InsetTableCell head =
InsetTableCell(*cellInset(cell).get());
+ head.getText(0)->setMacrocontextPosition(
+
cellInset(cell)->getText(0)->macrocontextPosition());
+ head.setBuffer(buffer());
+ bool hassep = false;
+ InsetTableCell tail = splitCell(head,
column_info[c].decimal_point, hassep);
+ head.latex(os, newrp);
+ os << '&';
+ ret += tail.latex(os, newrp);
+ } else if (!isPartOfMultiRow(row, c))
+ ret += inset->latex(os, newrp);
+
runparams.encoding = newrp.encoding;
if (rtl)
os << '}';
@@ -2477,6 +2596,7 @@
case LYX_ALIGN_BLOCK:
case LYX_ALIGN_LAYOUT:
case LYX_ALIGN_SPECIAL:
+ case LYX_ALIGN_DECIMAL:
break;
}
@@ -2502,6 +2622,9 @@
case LYX_ALIGN_RIGHT:
os << 'r';
break;
+ case LYX_ALIGN_DECIMAL:
+ os << "r...@{\\extracolsep{0pt}" <<
column_info[c].decimal_point << "}l";
+ break;
default:
os << 'c';
break;
@@ -3235,6 +3358,33 @@
// FIXME(?): do we need a second metrics call?
TextMetrics const & tm =
mi.base.bv->textMetrics(tabular.cellInset(cell)->getText(0));
+
+ // determine horiz offset because of decimal align (if
necessary)
+ int decimal_hoffset = 0;
+ int decimal_width = 0;
+ if ((tabular.column_info[c].alignment ==
LYX_ALIGN_DECIMAL)
+ && !tabular.isMultiColumn(cell)
+ && !tabular.isMultiRow(cell)) {
+ // make a copy which we will split in 2
+ InsetTableCell head =
InsetTableCell(*tabular.cellInset(cell).get());
+ head.getText(0)->setMacrocontextPosition(
+
tabular.cellInset(cell)->getText(0)->macrocontextPosition());
+ head.setBuffer(tabular.buffer());
+ // split in 2 and calculate width of each part
+ bool hassep = false;
+ InsetTableCell tail =
+ splitCell(head,
tabular.column_info[c].decimal_point, hassep);
+ Dimension dim1;
+ head.metrics(m, dim1);
+ decimal_hoffset = dim1.width();
+ if (hassep) {
+ tail.metrics(m, dim1);
+ decimal_width = dim1.width();
+ }
+ }
+ tabular.cell_info[r][c].decimal_hoffset =
decimal_hoffset;
+ tabular.cell_info[r][c].decimal_width = decimal_width;
+
// with LYX_VALIGN_BOTTOM the descent is relative to
the last par
// = descent of text in last par + TEXT_TO_INSET_OFFSET:
int const lastpardes = tm.last().second->descent()
@@ -4040,6 +4190,11 @@
status.clear();
return true;
+ case Tabular::SET_DECIMAL_POINT:
+ status.setEnabled(
+ tabular.getAlignment(cur.idx()) ==
LYX_ALIGN_DECIMAL);
+ break;
+
case Tabular::MULTICOLUMN:
// If a row is set as longtable caption, it must not be
allowed
// to unset that this row is a multicolumn.
@@ -4116,6 +4271,12 @@
status.setOnOff(tabular.getAlignment(cur.idx(), flag)
== LYX_ALIGN_BLOCK);
break;
+ case Tabular::ALIGN_DECIMAL:
+ status.setEnabled(!tabular.isMultiRow(cur.idx())
+ && !tabular.isMultiColumn(cur.idx()));
+ status.setOnOff(tabular.getAlignment(cur.idx(), true)
== LYX_ALIGN_DECIMAL);
+ break;
+
case Tabular::M_VALIGN_TOP:
flag = false;
case Tabular::VALIGN_TOP:
@@ -4810,6 +4971,10 @@
setAlign = LYX_ALIGN_BLOCK;
break;
+ case Tabular::ALIGN_DECIMAL:
+ setAlign = LYX_ALIGN_DECIMAL;
+ break;
+
case Tabular::M_VALIGN_TOP:
case Tabular::VALIGN_TOP:
setVAlign = Tabular::LYX_VALIGN_TOP;
@@ -4954,6 +5119,7 @@
case Tabular::ALIGN_RIGHT:
case Tabular::ALIGN_CENTER:
case Tabular::ALIGN_BLOCK:
+ case Tabular::ALIGN_DECIMAL:
for (row_type r = sel_row_start; r <= sel_row_end; ++r)
for (col_type c = sel_col_start; c <= sel_col_end; ++c)
tabular.setAlignment(tabular.cellIndex(r, c),
setAlign, flag);
@@ -5245,6 +5411,11 @@
break;
}
+ case Tabular::SET_DECIMAL_POINT:
+ for (col_type c = sel_col_start; c <= sel_col_end; ++c)
+ tabular.column_info[c].decimal_point = from_utf8(value);
+ break;
+
// dummy stuff just to avoid warnings
case Tabular::LAST_ACTION:
break;
Modified: lyx-devel/trunk/src/insets/InsetTabular.h
==============================================================================
--- lyx-devel/trunk/src/insets/InsetTabular.h Sat Jun 5 00:53:44 2010
(r34597)
+++ lyx-devel/trunk/src/insets/InsetTabular.h Sat Jun 5 09:44:44 2010
(r34598)
@@ -96,6 +96,8 @@
///
ALIGN_BLOCK,
///
+ ALIGN_DECIMAL,
+ ///
VALIGN_TOP,
///
VALIGN_BOTTOM,
@@ -190,6 +192,8 @@
///
LONGTABULAR_ALIGN_RIGHT,
///
+ SET_DECIMAL_POINT,
+ ///
LAST_ACTION
};
///
@@ -490,6 +494,10 @@
LyXAlignment alignment;
///
VAlignment valignment;
+ /// width of the part before the decimal
+ int decimal_hoffset;
+ /// width of the decimal part
+ int decimal_width;
///
int voffset;
///
@@ -570,6 +578,8 @@
Length p_width;
///
docstring align_special;
+ ///
+ docstring decimal_point;
};
///
typedef std::vector<ColumnData> column_vector;
@@ -614,8 +624,6 @@
void updateIndexes();
///
bool setFixedWidth(row_type r, col_type c);
- ///
- void updateContentAlignment(row_type r, col_type c);
/// return true of update is needed
bool updateColumnWidths();
///
@@ -944,6 +952,9 @@
std::string const featureAsString(Tabular::Feature feature);
+/// Split cell on decimal symbol
+InsetTableCell splitCell(InsetTableCell & head, docstring const decimal_sym,
bool & hassep);
+
} // namespace lyx
#endif // INSET_TABULAR_H