InsetLine: support for the LaTeX command \rule; kick out the hardcoded \lyxline; fileformat change

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35299 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Uwe Stöhr 2010-09-07 00:41:00 +00:00
parent eac118ae98
commit 0e7ab29f49
21 changed files with 721 additions and 70 deletions

View File

@ -7,6 +7,11 @@ The good example would be 2010-01-10 entry.
----------------------- -----------------------
2010-09-07 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 400: support for the LaTeX-command
\rule;
new CommandInset "line"
2010-08-31 Uwe Stöhr <uwestoehr@web.de> 2010-08-31 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 399: support for the LaTeX-package * Format incremented to 399: support for the LaTeX-package
mathdots; mathdots;

View File

@ -742,6 +742,7 @@ src_frontends_qt4_header_files = Split('''
GuiInfo.h GuiInfo.h
GuiKeySymbol.h GuiKeySymbol.h
GuiLabel.h GuiLabel.h
GuiLine.h
GuiListings.h GuiListings.h
GuiLog.h GuiLog.h
GuiMathMatrix.h GuiMathMatrix.h
@ -843,6 +844,7 @@ src_frontends_qt4_files = Split('''
GuiInfo.cpp GuiInfo.cpp
GuiKeySymbol.cpp GuiKeySymbol.cpp
GuiLabel.cpp GuiLabel.cpp
GuiLine.cpp
GuiListings.cpp GuiListings.cpp
GuiLog.cpp GuiLog.cpp
GuiMathMatrix.cpp GuiMathMatrix.cpp
@ -938,6 +940,7 @@ src_frontends_qt4_ui_files = Split('''
LabelUi.ui LabelUi.ui
LaTeXUi.ui LaTeXUi.ui
LanguageUi.ui LanguageUi.ui
LineUi.ui
ListingsUi.ui ListingsUi.ui
ListingsSettingsUi.ui ListingsSettingsUi.ui
LocalLayoutUi.ui LocalLayoutUi.ui

View File

@ -2078,6 +2078,90 @@ def revert_mathdots(document):
break break
def convert_rule(document):
" Convert \\lyxline to CommandInset line "
i = 0
while True:
i = find_token(document.body, "\\lyxline" , i)
if i != -1:
j = find_token(document.body, "\\color" , i - 2)
if j == i - 2:
color = document.body[j] + '\n'
else:
color = ''
k = find_token(document.body, "\\begin_layout Standard" , i - 4)
# we need to handle the case that \lyxline is in a separate paragraph and that it is colored
# the result is then an extra empty paragraph which we get by adding an empty ERT inset
if k == i - 4 and j == i - 2 and document.body[i - 1] == '':
layout = '\\begin_inset ERT\nstatus collapsed\n\n\\begin_layout Plain Layout\n\n\n\\end_layout\n\n\\end_inset\n' \
+ '\\end_layout\n\n' \
+ '\\begin_layout Standard\n'
elif k == i - 2 and document.body[i - 1] == '':
layout = ''
else:
layout = '\\end_layout\n\n' \
+ '\\begin_layout Standard\n'
l = find_token(document.body, "\\begin_layout Standard" , i + 4)
if l == i + 4 and document.body[i + 1] == '':
layout2 = ''
else:
layout2 = '\\end_layout\n' \
+ '\n\\begin_layout Standard\n'
subst = layout \
+ '\\noindent\n\n' \
+ color \
+ '\\begin_inset CommandInset line\n' \
+ 'LatexCommand rule\n' \
+ 'offset "0.5ex"\n' \
+ 'width "100line%"\n' \
+ 'height "1pt"\n' \
+ '\n\\end_inset\n\n\n' \
+ layout2
document.body[i] = subst
i += 1
else:
return
def revert_rule(document):
" Revert line insets to Tex code "
i = 0
while 1:
i = find_token(document.body, "\\begin_inset CommandInset line" , i)
if i != -1:
# find end of inset
j = find_token(document.body, "\\end_inset" , i)
# assure we found the end_inset of the current inset
if j > i + 6 or j == -1:
document.warning("Malformed LyX document: Can't find end of line inset.")
return
# determine the optional offset
k = find_token(document.body, 'offset', i)
if k != -1 and k < j:
offset = document.body[k][8:]
else:
offset = '0"'
# determine the width
l = find_token(document.body, 'width', k + 1)
width = document.body[l][7:]
# determine the height
m = find_token(document.body, 'height', l + 1)
height = document.body[m][8:]
# remove trailing '"'
offset = offset[:-1]
width = width[:-1]
height = height[:-1]
# output the \rule command
if offset <> "0":
subst = "\\rule[" + offset + "]{" + width + "}{" + height + "}"
else:
subst = "\\rule{" + width + "}{" + height + "}"
document.body[i:j + 1] = put_cmd_in_ert(subst)
i += 1
else:
return
## ##
# Conversion hub # Conversion hub
# #
@ -2136,10 +2220,12 @@ convert = [[346, []],
[396, []], [396, []],
[397, [remove_Nameref]], [397, [remove_Nameref]],
[398, []], [398, []],
[399, [convert_mathdots]] [399, [convert_mathdots]],
[400, [convert_rule]]
] ]
revert = [[398, [revert_mathdots]], revert = [[399, [revert_rule]],
[398, [revert_mathdots]],
[397, [revert_mathrsfs]], [397, [revert_mathrsfs]],
[396, []], [396, []],
[395, [revert_nameref]], [395, [revert_nameref]],

View File

@ -127,7 +127,7 @@ namespace {
// 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.
int const LYX_FORMAT = 399; // uwestoehr: support for package mathdots int const LYX_FORMAT = 400; // uwestoehr: support for \rule
typedef map<string, bool> DepClean; typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache; typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;

View File

@ -1027,6 +1027,7 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
case LFUN_FONT_STATE: case LFUN_FONT_STATE:
case LFUN_LABEL_INSERT: case LFUN_LABEL_INSERT:
case LFUN_LINE_INSERT:
case LFUN_INFO_INSERT: case LFUN_INFO_INSERT:
case LFUN_PARAGRAPH_GOTO: case LFUN_PARAGRAPH_GOTO:
case LFUN_NOTE_NEXT: case LFUN_NOTE_NEXT:

View File

@ -60,11 +60,6 @@ namespace lyx {
static docstring const lyx_def = from_ascii( static docstring const lyx_def = from_ascii(
"\\providecommand{\\LyX}{L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}"); "\\providecommand{\\LyX}{L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}");
static docstring const lyxline_def = from_ascii(
"\\newcommand{\\lyxline}[1][1pt]{%\n"
" \\par\\noindent%\n"
" \\rule[.5ex]{\\linewidth}{#1}\\par}");
static docstring const noun_def = from_ascii( static docstring const noun_def = from_ascii(
"\\newcommand{\\noun}[1]{\\textsc{#1}}"); "\\newcommand{\\noun}[1]{\\textsc{#1}}");
@ -805,9 +800,6 @@ docstring const LaTeXFeatures::getMacros() const
if (mustProvide("LyX")) if (mustProvide("LyX"))
macros << lyx_def << '\n'; macros << lyx_def << '\n';
if (mustProvide("lyxline"))
macros << lyxline_def << '\n';
if (mustProvide("noun")) if (mustProvide("noun"))
macros << noun_def << '\n'; macros << noun_def << '\n';

View File

@ -2378,12 +2378,12 @@ void LyXAction::init()
* \var lyx::FuncCode lyx::LFUN_INSET_SETTINGS * \var lyx::FuncCode lyx::LFUN_INSET_SETTINGS
* \li Action: Open the inset's properties dialog. * \li Action: Open the inset's properties dialog.
* \li Notion: Used for bibitem, bibtex, box, branch, citation, ert, external, * \li Notion: Used for bibitem, bibtex, box, branch, citation, ert, external,
float, graphics, href, include, index, index_print, label, listings, float, graphics, href, include, index, index_print, label, line,
note, phantom, ref, space, tabular, vspace, wrap insets. listings, note, phantom, ref, space, tabular, vspace, wrap insets.
* \li Syntax: inset-settings <INSET> * \li Syntax: inset-settings <INSET>
* \li Params: <INSET>: <bibitem|bibtex|box|branch|citation|ert|external|float| * \li Params: <INSET>: <bibitem|bibtex|box|branch|citation|ert|external|float|
graphics|href|include|index|index_print|label|listings| graphics|href|include|index|index_print|label|line|
note|phantom|ref|space|tabular|vspace|wrap>. listings|note|phantom|ref|space|tabular|vspace|wrap>.
* \endvar * \endvar
*/ */
{ LFUN_INSET_SETTINGS, "inset-settings", ReadOnly | AtPoint, Edit }, { LFUN_INSET_SETTINGS, "inset-settings", ReadOnly | AtPoint, Edit },
@ -2663,7 +2663,7 @@ void LyXAction::init()
* \li Syntax: dialog-show <NAME> [<DATA>] * \li Syntax: dialog-show <NAME> [<DATA>]
* \li Params: <NAME>: aboutlyx|bibitem|bibtex|box|branch|changes|character|citation|\n * \li Params: <NAME>: aboutlyx|bibitem|bibtex|box|branch|changes|character|citation|\n
compare|document|errorlist|ert|external|file|findreplace|findreplaceadv|float|\n compare|document|errorlist|ert|external|file|findreplace|findreplaceadv|float|\n
graphics|href|include|index|index_print|info|label|listings|log|mathdelimiter|\n graphics|href|include|index|index_print|info|label|line|listings|log|mathdelimiter|\n
mathmatrix|mathspace|nomenclature|nomencl_print|note|paragraph|phantom|prefs|\n mathmatrix|mathspace|nomenclature|nomencl_print|note|paragraph|phantom|prefs|\n
print|ref|sendto|space|spellchecker|symbols|tabular|tabularcreate|\n print|ref|sendto|space|spellchecker|symbols|tabular|tabularcreate|\n
thesaurus|texinfo|toc|view-source|vspace|wrap|<SPECIAL> \n thesaurus|texinfo|toc|view-source|vspace|wrap|<SPECIAL> \n

View File

@ -53,7 +53,6 @@
#include "insets/InsetText.h" #include "insets/InsetText.h"
#include "insets/InsetBibitem.h" #include "insets/InsetBibitem.h"
#include "insets/InsetCaption.h" #include "insets/InsetCaption.h"
#include "insets/InsetLine.h"
#include "insets/InsetNewline.h" #include "insets/InsetNewline.h"
#include "insets/InsetNewpage.h" #include "insets/InsetNewpage.h"
#include "insets/InsetArgument.h" #include "insets/InsetArgument.h"
@ -452,11 +451,6 @@ void Text::readParToken(Paragraph & par, Lexer & lex,
auto_ptr<Inset> inset(new InsetTabular(buf)); auto_ptr<Inset> inset(new InsetTabular(buf));
inset->read(lex); inset->read(lex);
par.insertInset(par.size(), inset.release(), font, change); par.insertInset(par.size(), inset.release(), font, change);
} else if (token == "\\lyxline") {
auto_ptr<Inset> inset;
inset.reset(new InsetLine);
inset->setBuffer(*buf);
par.insertInset(par.size(), inset.release(), font, change);
} else if (token == "\\change_unchanged") { } else if (token == "\\change_unchanged") {
change = Change(Change::UNCHANGED); change = Change(Change::UNCHANGED);
} else if (token == "\\change_inserted" || token == "\\change_deleted") { } else if (token == "\\change_inserted" || token == "\\change_deleted") {

View File

@ -1548,6 +1548,22 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
break; break;
} }
case LFUN_LINE_INSERT: {
InsetCommandParams p(LINE_CODE);
p["offset"] = from_ascii(".5ex");
p["width"] = from_ascii("100col%");
p["height"] = from_ascii("1pt");
string const data = InsetCommand::params2string("line", p);
if (cmd.argument().empty()) {
bv->showDialog("line", data);
} else {
FuncRequest fr(LFUN_INSET_INSERT, data);
dispatch(cur, fr);
}
break;
}
case LFUN_INFO_INSERT: { case LFUN_INFO_INSERT: {
Inset * inset; Inset * inset;
if (cmd.argument().empty() && cur.selection()) { if (cmd.argument().empty() && cur.selection()) {
@ -1672,7 +1688,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_NOMENCL_PRINT: case LFUN_NOMENCL_PRINT:
case LFUN_TOC_INSERT: case LFUN_TOC_INSERT:
case LFUN_LINE_INSERT:
case LFUN_NEWPAGE_INSERT: case LFUN_NEWPAGE_INSERT:
// do nothing fancy // do nothing fancy
doInsertInset(cur, this, cmd, false, false); doInsertInset(cur, this, cmd, false, false);
@ -2229,6 +2244,8 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
code = NOMENCL_PRINT_CODE; code = NOMENCL_PRINT_CODE;
else if (cmd.argument() == "label") else if (cmd.argument() == "label")
code = LABEL_CODE; code = LABEL_CODE;
else if (cmd.argument() == "line")
code = LINE_CODE;
else if (cmd.argument() == "note") else if (cmd.argument() == "note")
code = NOTE_CODE; code = NOTE_CODE;
else if (cmd.argument() == "phantom") else if (cmd.argument() == "phantom")

View File

@ -82,9 +82,6 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
switch (cmd.action()) { switch (cmd.action()) {
case LFUN_LINE_INSERT:
return new InsetLine;
case LFUN_NEWPAGE_INSERT: { case LFUN_NEWPAGE_INSERT: {
string const name = cmd.getArg(0); string const name = cmd.getArg(0);
InsetNewpageParams inp; InsetNewpageParams inp;
@ -292,6 +289,12 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
return new InsetLabel(buf, icp); return new InsetLabel(buf, icp);
} }
case LINE_CODE: {
InsetCommandParams icp(code);
InsetCommand::string2params(name, to_utf8(cmd.argument()), icp);
return new InsetLine(buf, icp);
}
case LISTINGS_CODE: { case LISTINGS_CODE: {
InsetListingsParams par; InsetListingsParams par;
InsetListings::string2params(to_utf8(cmd.argument()), par); InsetListings::string2params(to_utf8(cmd.argument()), par);
@ -490,6 +493,9 @@ Inset * readInset(Lexer & lex, Buffer * buf)
case LABEL_CODE: case LABEL_CODE:
inset.reset(new InsetLabel(buf, inscmd)); inset.reset(new InsetLabel(buf, inscmd));
break; break;
case LINE_CODE:
inset.reset(new InsetLine(buf, inscmd));
break;
case NOMENCL_CODE: case NOMENCL_CODE:
inset.reset(new InsetNomencl(buf, inscmd)); inset.reset(new InsetNomencl(buf, inscmd));
break; break;

View File

@ -0,0 +1,163 @@
/**
* \file GuiLine.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Uwe Stöhr
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "GuiLine.h"
#include "LengthCombo.h"
#include "qt_helpers.h"
#include "Validator.h"
#include "FuncRequest.h"
#include "insets/InsetLine.h"
#include "support/debug.h"
#include "support/gettext.h"
#include "support/lstrings.h"
#include <QLineEdit>
#include <QPushButton>
#include <QValidator>
using namespace std;
namespace lyx {
namespace frontend {
GuiLine::GuiLine(GuiView & lv)
: GuiDialog(lv, "line", qt_("Horizontal line")),
params_(insetCode("line"))
{
setupUi(this);
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
connect(OffsetLE, SIGNAL(textChanged(QString)),
this, SLOT(change_adaptor()));
connect(OffsetUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
this, SLOT(change_adaptor()));
connect(WidthLE, SIGNAL(textChanged(QString)),
this, SLOT(change_adaptor()));
connect(WidthUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
this, SLOT(change_adaptor()));
connect(HeightLE, SIGNAL(textChanged(QString)),
this, SLOT(change_adaptor()));
connect(HeightUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
this, SLOT(change_adaptor()));
// Manage the ok, apply, restore and cancel/close buttons
bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
bc().setOK(okPB);
bc().setApply(applyPB);
bc().setCancel(closePB);
// disable for read-only documents
bc().addReadOnly(OffsetLE);
bc().addReadOnly(OffsetUnitCO);
bc().addReadOnly(WidthLE);
bc().addReadOnly(WidthUnitCO);
bc().addReadOnly(HeightLE);
bc().addReadOnly(HeightUnitCO);
// initialize the length validator
bc().addCheckedLineEdit(OffsetLE, OffsetValueL);
bc().addCheckedLineEdit(WidthLE, WidthValueL);
bc().addCheckedLineEdit(HeightLE, HeightValueL);
OffsetLE->setValidator(unsignedGlueLengthValidator(OffsetLE));
WidthLE->setValidator(unsignedGlueLengthValidator(WidthLE));
HeightLE->setValidator(unsignedGlueLengthValidator(HeightLE));
}
void GuiLine::change_adaptor()
{
changed();
}
void GuiLine::paramsToDialog(InsetCommandParams const & /*icp*/)
{
lengthToWidgets(OffsetLE,
OffsetUnitCO,
params_["offset"],
Length::defaultUnit());
lengthToWidgets(WidthLE,
WidthUnitCO,
params_["width"],
Length::defaultUnit());
lengthToWidgets(HeightLE,
HeightUnitCO,
params_["height"],
Length::defaultUnit());
bc().setValid(isValid());
}
void GuiLine::applyView()
{
docstring offset = from_utf8(widgetsToLength(OffsetLE, OffsetUnitCO));
params_["offset"] = offset;
// negative widths are senseless
string width_str = fromqstr(WidthLE->text());
if (width_str[0] == '-')
width_str.erase(0,1);
WidthLE->setText(toqstr(width_str));
docstring width = from_utf8(widgetsToLength(WidthLE, WidthUnitCO));
params_["width"] = width;
// negative heights are senseless
string height_str = fromqstr(HeightLE->text());
if (height_str[0] == '-')
height_str.erase(0,1);
HeightLE->setText(toqstr(height_str));
docstring height = from_utf8(widgetsToLength(HeightLE, HeightUnitCO));
params_["height"] = height;
params_.setCmdName("rule");
}
bool GuiLine::isValid() const
{
return true;
}
bool GuiLine::initialiseParams(std::string const & data)
{
InsetCommand::string2params("line", data, params_);
paramsToDialog(params_);
return true;
}
void GuiLine::dispatchParams()
{
std::string const lfun = InsetCommand::params2string("line", params_);
dispatch(FuncRequest(getLfun(), lfun));
}
Dialog * createGuiLine(GuiView & lv) { return new GuiLine(lv); }
} // namespace frontend
} // namespace lyx
#include "moc_GuiLine.cpp"

View File

@ -0,0 +1,57 @@
// -*- C++ -*-
/**
* \file GuiLine.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Uwe Stöhr
*
* Full author contact details are available in file CREDITS.
*/
#ifndef GUILINE_H
#define GUILINE_H
#include "GuiDialog.h"
#include "ui_LineUi.h"
#include "insets/InsetCommandParams.h"
namespace lyx {
namespace frontend {
class GuiLine : public GuiDialog, public Ui::LineUi
{
Q_OBJECT
public:
GuiLine(GuiView & lv);
private Q_SLOTS:
void change_adaptor();
private:
/// Apply changes
void applyView();
/// Update dialog before showing it
bool initialiseParams(std::string const & data);
///
void paramsToDialog(InsetCommandParams const & icp);
///
void clearParams() { params_.clear(); }
///
void dispatchParams();
///
bool isBufferDependent() const { return true; }
///
bool isValid() const;
///
InsetCommandParams params_;
};
} // namespace frontend
} // namespace lyx
#endif // GUILINE_H

View File

@ -3457,13 +3457,14 @@ namespace {
char const * const dialognames[] = { char const * const dialognames[] = {
"aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character", "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
"citation", "compare", "document", "errorlist", "ert", "external", "file", "citation", "compare", "document", "errorlist", "ert", "external",
"findreplace", "findreplaceadv", "float", "graphics", "href", "include", "file", "findreplace", "findreplaceadv", "float", "graphics", "href",
"index", "index_print", "info", "listings", "label", "log", "mathdelimiter", "include", "index", "index_print", "info", "listings", "label", "line",
"mathmatrix", "mathspace", "nomenclature", "nomencl_print", "note", "log", "mathdelimiter", "mathmatrix", "mathspace", "nomenclature",
"paragraph", "phantom", "prefs", "print", "ref", "sendto", "space", "nomencl_print", "note", "paragraph", "phantom", "prefs", "print", "ref",
"spellchecker", "symbols", "tabular", "tabularcreate", "thesaurus", "texinfo", "sendto", "space", "spellchecker", "symbols", "tabular", "tabularcreate",
"toc", "view-source", "vspace", "wrap", "progress"}; "thesaurus", "texinfo", "toc", "view-source", "vspace", "wrap",
"progress"};
char const * const * const end_dialognames = char const * const * const end_dialognames =
dialognames + (sizeof(dialognames) / sizeof(char *)); dialognames + (sizeof(dialognames) / sizeof(char *));
@ -3650,6 +3651,7 @@ Dialog * createGuiGraphics(GuiView & lv);
Dialog * createGuiInclude(GuiView & lv); Dialog * createGuiInclude(GuiView & lv);
Dialog * createGuiIndex(GuiView & lv); Dialog * createGuiIndex(GuiView & lv);
Dialog * createGuiLabel(GuiView & lv); Dialog * createGuiLabel(GuiView & lv);
Dialog * createGuiLine(GuiView & lv);
Dialog * createGuiListings(GuiView & lv); Dialog * createGuiListings(GuiView & lv);
Dialog * createGuiLog(GuiView & lv); Dialog * createGuiLog(GuiView & lv);
Dialog * createGuiMathMatrix(GuiView & lv); Dialog * createGuiMathMatrix(GuiView & lv);
@ -3723,6 +3725,8 @@ Dialog * GuiView::build(string const & name)
return createGuiPrintindex(*this); return createGuiPrintindex(*this);
if (name == "label") if (name == "label")
return createGuiLabel(*this); return createGuiLabel(*this);
if (name == "line")
return createGuiLine(*this);
if (name == "listings") if (name == "listings")
return createGuiListings(*this); return createGuiListings(*this);
if (name == "log") if (name == "log")

View File

@ -95,6 +95,7 @@ SOURCEFILES = \
GuiInfo.cpp \ GuiInfo.cpp \
GuiKeySymbol.cpp \ GuiKeySymbol.cpp \
GuiLabel.cpp \ GuiLabel.cpp \
GuiLine.cpp \
GuiListings.cpp \ GuiListings.cpp \
GuiLog.cpp \ GuiLog.cpp \
GuiMathMatrix.cpp \ GuiMathMatrix.cpp \
@ -199,6 +200,7 @@ MOCHEADER = \
GuiIndices.h \ GuiIndices.h \
GuiInfo.h \ GuiInfo.h \
GuiLabel.h \ GuiLabel.h \
GuiLine.h \
GuiListings.h \ GuiListings.h \
GuiLog.h \ GuiLog.h \
GuiMathMatrix.h \ GuiMathMatrix.h \
@ -280,6 +282,7 @@ UIFILES = \
LabelUi.ui \ LabelUi.ui \
LanguageUi.ui \ LanguageUi.ui \
LaTeXUi.ui \ LaTeXUi.ui \
LineUi.ui \
ListingsUi.ui \ ListingsUi.ui \
ListingsSettingsUi.ui \ ListingsSettingsUi.ui \
LocalLayoutUi.ui \ LocalLayoutUi.ui \

View File

@ -0,0 +1,188 @@
<ui version="4.0">
<class>LineUi</class>
<widget class="QWidget" name="LineUi">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>325</width>
<height>126</height>
</rect>
</property>
<property name="windowTitle">
<string/>
</property>
<property name="sizeGripEnabled" stdset="0">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="OffsetValueL">
<property name="text">
<string>Offset:</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="OffsetLE">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Value of the vertical line offset.</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="LengthCombo" name="OffsetUnitCO">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>20</height>
</size>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="WidthValueL">
<property name="text">
<string>Width:</string>
</property>
<property name="buddy">
<cstring>WidthLE</cstring>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="WidthLE">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Value of the line width.</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="LengthCombo" name="WidthUnitCO">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>20</height>
</size>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="HeightValueL">
<property name="text">
<string>Height:</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QLineEdit" name="HeightLE">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Value of the line height.</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="LengthCombo" name="HeightUnitCO">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>20</height>
</size>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>59</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="2" colspan="2">
<layout class="QHBoxLayout">
<item>
<widget class="QPushButton" name="okPB">
<property name="text">
<string>&amp;OK</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applyPB">
<property name="text">
<string>&amp;Apply</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB">
<property name="text">
<string>&amp;Close</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LengthCombo</class>
<extends>QComboBox</extends>
<header>LengthCombo.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>WidthLE</tabstop>
</tabstops>
<includes>
<include location="local">qt_i18n.h</include>
</includes>
<resources/>
<connections/>
</ui>

View File

@ -29,6 +29,7 @@
#include "insets/InsetFloat.h" #include "insets/InsetFloat.h"
#include "insets/InsetGraphics.h" #include "insets/InsetGraphics.h"
#include "insets/InsetInclude.h" #include "insets/InsetInclude.h"
#include "insets/InsetLine.h"
#include "insets/InsetListings.h" #include "insets/InsetListings.h"
#include "insets/InsetNote.h" #include "insets/InsetNote.h"
#include "insets/InsetPhantom.h" #include "insets/InsetPhantom.h"
@ -260,6 +261,7 @@ bool decodeInsetParam(string const & name, string & data,
case BIBTEX_CODE: case BIBTEX_CODE:
case INDEX_CODE: case INDEX_CODE:
case LABEL_CODE: case LABEL_CODE:
case LINE_CODE:
case NOMENCL_CODE: case NOMENCL_CODE:
case NOMENCL_PRINT_CODE: case NOMENCL_PRINT_CODE:
case REF_CODE: case REF_CODE:

View File

@ -55,6 +55,8 @@ public:
/// ///
void setParam(std::string const & name, docstring const & value); void setParam(std::string const & name, docstring const & value);
/// ///
Dimension const dimension(BufferView const &) const { return button_.dimension(); }
///
docstring const & getParam(std::string const & name) const; docstring const & getParam(std::string const & name) const;
/// FIXME Remove /// FIXME Remove
docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); } docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); }
@ -87,8 +89,6 @@ private:
/// ///
void metrics(MetricsInfo &, Dimension &) const; void metrics(MetricsInfo &, Dimension &) const;
/// ///
Dimension const dimension(BufferView const &) const { return button_.dimension(); }
///
void draw(PainterInfo & pi, int x, int y) const; void draw(PainterInfo & pi, int x, int y) const;
/// ///
int latex(odocstream &, OutputParams const &) const; int latex(odocstream &, OutputParams const &) const;

View File

@ -23,6 +23,7 @@
#include "InsetInclude.h" #include "InsetInclude.h"
#include "InsetIndex.h" #include "InsetIndex.h"
#include "InsetLabel.h" #include "InsetLabel.h"
#include "InsetLine.h"
#include "InsetNomencl.h" #include "InsetNomencl.h"
#include "InsetRef.h" #include "InsetRef.h"
#include "InsetTOC.h" #include "InsetTOC.h"
@ -70,6 +71,8 @@ static ParamInfo const & findInfo(InsetCode code, string const & cmdName)
return InsetPrintIndex::findInfo(cmdName); return InsetPrintIndex::findInfo(cmdName);
case LABEL_CODE: case LABEL_CODE:
return InsetLabel::findInfo(cmdName); return InsetLabel::findInfo(cmdName);
case LINE_CODE:
return InsetLine::findInfo(cmdName);
case NOMENCL_CODE: case NOMENCL_CODE:
return InsetNomencl::findInfo(cmdName); return InsetNomencl::findInfo(cmdName);
case NOMENCL_PRINT_CODE: case NOMENCL_PRINT_CODE:
@ -200,6 +203,8 @@ string InsetCommandParams::getDefaultCmd(InsetCode code)
return InsetPrintIndex::defaultCommand(); return InsetPrintIndex::defaultCommand();
case LABEL_CODE: case LABEL_CODE:
return InsetLabel::defaultCommand(); return InsetLabel::defaultCommand();
case LINE_CODE:
return InsetLine::defaultCommand();
case NOMENCL_CODE: case NOMENCL_CODE:
return InsetNomencl::defaultCommand(); return InsetNomencl::defaultCommand();
case NOMENCL_PRINT_CODE: case NOMENCL_PRINT_CODE:
@ -234,6 +239,8 @@ bool InsetCommandParams::isCompatibleCommand(InsetCode code, string const & s)
return InsetPrintIndex::isCompatibleCommand(s); return InsetPrintIndex::isCompatibleCommand(s);
case LABEL_CODE: case LABEL_CODE:
return InsetLabel::isCompatibleCommand(s); return InsetLabel::isCompatibleCommand(s);
case LINE_CODE:
return InsetLine::isCompatibleCommand(s);
case NOMENCL_CODE: case NOMENCL_CODE:
return InsetNomencl::isCompatibleCommand(s); return InsetNomencl::isCompatibleCommand(s);
case NOMENCL_PRINT_CODE: case NOMENCL_PRINT_CODE:

View File

@ -4,6 +4,7 @@
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
* \author André Pönitz * \author André Pönitz
* \author Uwe Stöhr
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -12,20 +13,26 @@
#include "InsetLine.h" #include "InsetLine.h"
#include "Buffer.h"
#include "Dimension.h" #include "Dimension.h"
#include "Font.h" #include "DispatchResult.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "LaTeXFeatures.h" #include "LaTeXFeatures.h"
#include "Length.h"
#include "MetricsInfo.h" #include "MetricsInfo.h"
#include "OutputParams.h" #include "OutputParams.h"
#include "output_xhtml.h" #include "output_xhtml.h"
#include "Text.h" #include "Text.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h" #include "frontends/Painter.h"
#include "support/convert.h"
#include "support/debug.h" #include "support/debug.h"
#include "support/docstream.h" #include "support/docstream.h"
#include "support/gettext.h"
#include "support/lstrings.h"
using namespace std; using namespace std;
@ -34,24 +41,88 @@ namespace lyx {
using frontend::Painter; using frontend::Painter;
void InsetLine::read(Lexer &) InsetLine::InsetLine(Buffer * buf, InsetCommandParams const & p)
: InsetCommand(buf, p, "line")
{}
ParamInfo const & InsetLine::findInfo(string const & /* cmdName */)
{ {
/* Nothing to read */ static ParamInfo param_info_;
if (param_info_.empty()) {
param_info_.add("offset", ParamInfo::LYX_INTERNAL);
param_info_.add("width", ParamInfo::LYX_INTERNAL);
param_info_.add("height", ParamInfo::LYX_INTERNAL);
}
return param_info_;
} }
void InsetLine::write(ostream & os) const docstring InsetLine::screenLabel() const
{ {
os << "\n\\lyxline\n"; return _("Horizontal line");
}
void InsetLine::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action()) {
case LFUN_INSET_MODIFY: {
InsetCommandParams p(LINE_CODE);
// FIXME UNICODE
InsetCommand::string2params("line",
to_utf8(cmd.argument()), p);
if (p.getCmdName().empty()) {
cur.noScreenUpdate();
break;
}
setParams(p);
break;
}
default:
InsetCommand::doDispatch(cur, cmd);
break;
}
}
bool InsetLine::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & status) const
{
switch (cmd.action()) {
case LFUN_INSET_DIALOG_UPDATE:
case LFUN_INSET_MODIFY:
status.setEnabled(true);
return true;
default:
return InsetCommand::getStatus(cur, cmd, status);
}
} }
void InsetLine::metrics(MetricsInfo & mi, Dimension & dim) const void InsetLine::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
dim.asc = 3; frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
dim.des = 3; dim.asc = fm.maxAscent();
dim.wid = mi.base.textwidth; dim.des = fm.maxDescent();
// Cache the inset dimension.
Length width = Length(to_ascii(getParam("width")));
int w =
width.inPixels(mi.base.textwidth,
fm.width(char_type('M')));
// assure that the line inset is not outside of the window
// check that it doesn't exceed the outer boundary
if (w > mi.base.textwidth)
w = mi.base.textwidth;
// set a minimal width
int const minw = (w < 0) ? 3 * 8 : 4;
dim.wid = max(minw, abs(w));
// Cache the inset dimension
setDimCache(mi, dim); setDimCache(mi, dim);
} }
@ -60,18 +131,60 @@ void InsetLine::draw(PainterInfo & pi, int x, int y) const
{ {
Dimension const dim = dimension(*pi.base.bv); Dimension const dim = dimension(*pi.base.bv);
frontend::FontMetrics const & fm = theFontMetrics(pi.base.font);
// get the length of the parameters in pixels
Length offset = Length(to_ascii(getParam("offset")));
int o =
offset.inPixels(pi.base.textwidth,
fm.width(char_type('M')));
Length width = Length(to_ascii(getParam("width")));
int w =
width.inPixels(pi.base.textwidth,
fm.width(char_type('M')));
Length height = Length(to_ascii(getParam("height")));
int h =
height.inPixels(pi.base.textwidth,
fm.width(char_type('M')));
// get the surrounding text color
FontInfo f = pi.base.font; FontInfo f = pi.base.font;
Color Line_color = f.realColor(); Color Line_color = f.realColor();
pi.pain.line(x, y, x + dim.wid, y, Line_color, // assure that the drawn line is not outside of the window
Painter::line_solid, 1); // check that it doesn't exceed the outer boundary
if (x + w - h/2 - 2 > pi.base.textwidth)
w = pi.base.textwidth - x + h/2 + 2;
// check that it doesn't exceed the upper boundary
if (y - o - h/2 < 0)
o = y - h/2 - 2;
// the offset is a vertical one
pi.pain.line(x + h/2 + 1, y - o - h/2, x + w - h/2 - 2, y - o - h/2,
Line_color, Painter::line_solid, float(h));
} }
int InsetLine::latex(odocstream & os, OutputParams const & runparams) const int InsetLine::latex(odocstream & os, OutputParams const & runparams) const
{ {
os << "\\lyxline{\\" bool have_offset = true;
<< from_ascii(runparams.local_font->latexSize()) << '}'; Length offset_len = Length(to_ascii(getParam("offset")));
if (offset_len.value() == 0)
have_offset = false;
string const offset =
Length(to_ascii(getParam("offset"))).asLatexString();
string const width =
Length(to_ascii(getParam("width"))).asLatexString();
string const height =
Length(to_ascii(getParam("height"))).asLatexString();
os << "\\rule";
// only output the optional parameter if the offset is not 0
if (have_offset)
os << "[" << from_ascii(offset) << "]";
os << "{" << from_ascii(width) << "}{" << from_ascii(height) << '}';
return 0; return 0;
} }
@ -98,10 +211,4 @@ docstring InsetLine::xhtml(XHTMLStream & xs, OutputParams const &) const
} }
void InsetLine::validate(LaTeXFeatures & features) const
{
features.require("lyxline");
}
} // namespace lyx } // namespace lyx

View File

@ -5,6 +5,7 @@
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
* \author André Pönitz * \author André Pönitz
* \author Uwe Stöhr
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -14,16 +15,36 @@
#include "Inset.h" #include "Inset.h"
#include "InsetCommand.h"
namespace lyx { namespace lyx {
class InsetLine : public Inset { class LaTeXFeatures;
class InsetLine : public InsetCommand {
public: public:
/// ///
InsetLine() : Inset(0) {} InsetLine(Buffer * buf, InsetCommandParams const &);
///
int docbook(odocstream &, OutputParams const &) const;
/// Does nothing at the moment.
docstring xhtml(XHTMLStream &, OutputParams const &) const;
/// ///
InsetCode lyxCode() const { return LINE_CODE; } InsetCode lyxCode() const { return LINE_CODE; }
///
bool hasSettings() const { return true; }
///
docstring screenLabel() const;
///
static ParamInfo const & findInfo(std::string const &);
///
static std::string defaultCommand() { return "rule"; };
///
static bool isCompatibleCommand(std::string const & s)
{ return s == "rule"; }
private:
/// ///
void metrics(MetricsInfo &, Dimension &) const; void metrics(MetricsInfo &, Dimension &) const;
/// ///
@ -33,20 +54,10 @@ public:
/// ///
int plaintext(odocstream &, OutputParams const &) const; int plaintext(odocstream &, OutputParams const &) const;
/// ///
int docbook(odocstream &, OutputParams const &) const; void doDispatch(Cursor & cur, FuncRequest & cmd);
/// ///
docstring xhtml(XHTMLStream &, OutputParams const &) const; bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
/// ///
void read(Lexer & lex);
///
void write(std::ostream & os) const;
/// We don't need \begin_inset and \end_inset
bool directWrite() const { return true; }
///
DisplayType display() const { return AlignCenter; }
///
void validate(LaTeXFeatures & features) const;
private:
Inset * clone() const { return new InsetLine(*this); } Inset * clone() const { return new InsetLine(*this); }
}; };

View File

@ -103,6 +103,11 @@ void RowPainter::paintInset(Inset const * inset, pos_type const pos)
// requires a full repaint // requires a full repaint
bool pi_full_repaint = pi_.full_repaint; bool pi_full_repaint = pi_.full_repaint;
// FIXME: this is a hack to get the mi.base.textwidth but
// text_metrics_.width() is 1.0857 * mi.base.textwidth
// ( 1.0857 = 684 / 630 )
pi_.base.textwidth = int(0.92 * text_metrics_.width());
// FIXME: We should always use font, see documentation of // FIXME: We should always use font, see documentation of
// noFontChange() in Inset.h. // noFontChange() in Inset.h.
pi_.base.font = inset->noFontChange() ? pi_.base.font = inset->noFontChange() ?