From 0e7ab29f49c899cb4fa3b9134cca238ff540a48f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20St=C3=B6hr?= Date: Tue, 7 Sep 2010 00:41:00 +0000 Subject: [PATCH] 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 --- development/FORMAT | 5 + development/scons/scons_manifest.py | 3 + lib/lyx2lyx/lyx_2_0.py | 90 ++++++++++++- src/Buffer.cpp | 2 +- src/BufferView.cpp | 1 + src/LaTeXFeatures.cpp | 8 -- src/LyXAction.cpp | 10 +- src/Text.cpp | 6 - src/Text3.cpp | 19 ++- src/factory.cpp | 12 +- src/frontends/qt4/GuiLine.cpp | 163 ++++++++++++++++++++++++ src/frontends/qt4/GuiLine.h | 57 +++++++++ src/frontends/qt4/GuiView.cpp | 18 +-- src/frontends/qt4/Makefile.am | 3 + src/frontends/qt4/ui/LineUi.ui | 188 ++++++++++++++++++++++++++++ src/insets/InsetCommand.cpp | 2 + src/insets/InsetCommand.h | 4 +- src/insets/InsetCommandParams.cpp | 7 ++ src/insets/InsetLine.cpp | 149 ++++++++++++++++++---- src/insets/InsetLine.h | 39 +++--- src/rowpainter.cpp | 5 + 21 files changed, 721 insertions(+), 70 deletions(-) create mode 100644 src/frontends/qt4/GuiLine.cpp create mode 100644 src/frontends/qt4/GuiLine.h create mode 100644 src/frontends/qt4/ui/LineUi.ui diff --git a/development/FORMAT b/development/FORMAT index 31df747f14..b662714efe 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -7,6 +7,11 @@ The good example would be 2010-01-10 entry. ----------------------- +2010-09-07 Uwe Stöhr + * Format incremented to 400: support for the LaTeX-command + \rule; + new CommandInset "line" + 2010-08-31 Uwe Stöhr * Format incremented to 399: support for the LaTeX-package mathdots; diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index 21492007e1..160898c5a4 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -742,6 +742,7 @@ src_frontends_qt4_header_files = Split(''' GuiInfo.h GuiKeySymbol.h GuiLabel.h + GuiLine.h GuiListings.h GuiLog.h GuiMathMatrix.h @@ -843,6 +844,7 @@ src_frontends_qt4_files = Split(''' GuiInfo.cpp GuiKeySymbol.cpp GuiLabel.cpp + GuiLine.cpp GuiListings.cpp GuiLog.cpp GuiMathMatrix.cpp @@ -938,6 +940,7 @@ src_frontends_qt4_ui_files = Split(''' LabelUi.ui LaTeXUi.ui LanguageUi.ui + LineUi.ui ListingsUi.ui ListingsSettingsUi.ui LocalLayoutUi.ui diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index bc4111cc03..9c0d7497df 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -2078,6 +2078,90 @@ def revert_mathdots(document): 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 # @@ -2136,10 +2220,12 @@ convert = [[346, []], [396, []], [397, [remove_Nameref]], [398, []], - [399, [convert_mathdots]] + [399, [convert_mathdots]], + [400, [convert_rule]] ] -revert = [[398, [revert_mathdots]], +revert = [[399, [revert_rule]], + [398, [revert_mathdots]], [397, [revert_mathrsfs]], [396, []], [395, [revert_nameref]], diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 3a17d014aa..3f36d6f3ed 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -127,7 +127,7 @@ namespace { // Do not remove the comment below, so we get merge conflict in // 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 DepClean; typedef map > RefCache; diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 357fd77845..1eae3b3a3f 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1027,6 +1027,7 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag) case LFUN_FONT_STATE: case LFUN_LABEL_INSERT: + case LFUN_LINE_INSERT: case LFUN_INFO_INSERT: case LFUN_PARAGRAPH_GOTO: case LFUN_NOTE_NEXT: diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index c9216c6042..c2b0a85e46 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -60,11 +60,6 @@ namespace lyx { static docstring const lyx_def = from_ascii( "\\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( "\\newcommand{\\noun}[1]{\\textsc{#1}}"); @@ -805,9 +800,6 @@ docstring const LaTeXFeatures::getMacros() const if (mustProvide("LyX")) macros << lyx_def << '\n'; - if (mustProvide("lyxline")) - macros << lyxline_def << '\n'; - if (mustProvide("noun")) macros << noun_def << '\n'; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index babc10f0cd..963cfd2b1a 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -2378,12 +2378,12 @@ void LyXAction::init() * \var lyx::FuncCode lyx::LFUN_INSET_SETTINGS * \li Action: Open the inset's properties dialog. * \li Notion: Used for bibitem, bibtex, box, branch, citation, ert, external, - float, graphics, href, include, index, index_print, label, listings, - note, phantom, ref, space, tabular, vspace, wrap insets. + float, graphics, href, include, index, index_print, label, line, + listings, note, phantom, ref, space, tabular, vspace, wrap insets. * \li Syntax: inset-settings * \li Params: : . + graphics|href|include|index|index_print|label|line| + listings|note|phantom|ref|space|tabular|vspace|wrap>. * \endvar */ { LFUN_INSET_SETTINGS, "inset-settings", ReadOnly | AtPoint, Edit }, @@ -2663,7 +2663,7 @@ void LyXAction::init() * \li Syntax: dialog-show [] * \li Params: : aboutlyx|bibitem|bibtex|box|branch|changes|character|citation|\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 print|ref|sendto|space|spellchecker|symbols|tabular|tabularcreate|\n thesaurus|texinfo|toc|view-source|vspace|wrap| \n diff --git a/src/Text.cpp b/src/Text.cpp index de977ffa8a..f392cee920 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -53,7 +53,6 @@ #include "insets/InsetText.h" #include "insets/InsetBibitem.h" #include "insets/InsetCaption.h" -#include "insets/InsetLine.h" #include "insets/InsetNewline.h" #include "insets/InsetNewpage.h" #include "insets/InsetArgument.h" @@ -452,11 +451,6 @@ void Text::readParToken(Paragraph & par, Lexer & lex, auto_ptr inset(new InsetTabular(buf)); inset->read(lex); par.insertInset(par.size(), inset.release(), font, change); - } else if (token == "\\lyxline") { - auto_ptr inset; - inset.reset(new InsetLine); - inset->setBuffer(*buf); - par.insertInset(par.size(), inset.release(), font, change); } else if (token == "\\change_unchanged") { change = Change(Change::UNCHANGED); } else if (token == "\\change_inserted" || token == "\\change_deleted") { diff --git a/src/Text3.cpp b/src/Text3.cpp index 40fff5dbe5..75ad2c0733 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -1548,6 +1548,22 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) 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: { Inset * inset; if (cmd.argument().empty() && cur.selection()) { @@ -1672,7 +1688,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) case LFUN_NOMENCL_PRINT: case LFUN_TOC_INSERT: - case LFUN_LINE_INSERT: case LFUN_NEWPAGE_INSERT: // do nothing fancy doInsertInset(cur, this, cmd, false, false); @@ -2229,6 +2244,8 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, code = NOMENCL_PRINT_CODE; else if (cmd.argument() == "label") code = LABEL_CODE; + else if (cmd.argument() == "line") + code = LINE_CODE; else if (cmd.argument() == "note") code = NOTE_CODE; else if (cmd.argument() == "phantom") diff --git a/src/factory.cpp b/src/factory.cpp index 6df3d268ca..a1a375f9b5 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -82,9 +82,6 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd) switch (cmd.action()) { - case LFUN_LINE_INSERT: - return new InsetLine; - case LFUN_NEWPAGE_INSERT: { string const name = cmd.getArg(0); InsetNewpageParams inp; @@ -292,6 +289,12 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd) 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: { InsetListingsParams par; InsetListings::string2params(to_utf8(cmd.argument()), par); @@ -490,6 +493,9 @@ Inset * readInset(Lexer & lex, Buffer * buf) case LABEL_CODE: inset.reset(new InsetLabel(buf, inscmd)); break; + case LINE_CODE: + inset.reset(new InsetLine(buf, inscmd)); + break; case NOMENCL_CODE: inset.reset(new InsetNomencl(buf, inscmd)); break; diff --git a/src/frontends/qt4/GuiLine.cpp b/src/frontends/qt4/GuiLine.cpp new file mode 100644 index 0000000000..bec4438d8c --- /dev/null +++ b/src/frontends/qt4/GuiLine.cpp @@ -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 + +#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 +#include +#include + +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" diff --git a/src/frontends/qt4/GuiLine.h b/src/frontends/qt4/GuiLine.h new file mode 100644 index 0000000000..46a8079e12 --- /dev/null +++ b/src/frontends/qt4/GuiLine.h @@ -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 diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index dc569ac049..0a1b4ba150 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -3457,13 +3457,14 @@ namespace { char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character", -"citation", "compare", "document", "errorlist", "ert", "external", "file", -"findreplace", "findreplaceadv", "float", "graphics", "href", "include", -"index", "index_print", "info", "listings", "label", "log", "mathdelimiter", -"mathmatrix", "mathspace", "nomenclature", "nomencl_print", "note", -"paragraph", "phantom", "prefs", "print", "ref", "sendto", "space", -"spellchecker", "symbols", "tabular", "tabularcreate", "thesaurus", "texinfo", -"toc", "view-source", "vspace", "wrap", "progress"}; +"citation", "compare", "document", "errorlist", "ert", "external", +"file", "findreplace", "findreplaceadv", "float", "graphics", "href", +"include", "index", "index_print", "info", "listings", "label", "line", +"log", "mathdelimiter", "mathmatrix", "mathspace", "nomenclature", +"nomencl_print", "note", "paragraph", "phantom", "prefs", "print", "ref", +"sendto", "space", "spellchecker", "symbols", "tabular", "tabularcreate", +"thesaurus", "texinfo", "toc", "view-source", "vspace", "wrap", +"progress"}; char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); @@ -3650,6 +3651,7 @@ Dialog * createGuiGraphics(GuiView & lv); Dialog * createGuiInclude(GuiView & lv); Dialog * createGuiIndex(GuiView & lv); Dialog * createGuiLabel(GuiView & lv); +Dialog * createGuiLine(GuiView & lv); Dialog * createGuiListings(GuiView & lv); Dialog * createGuiLog(GuiView & lv); Dialog * createGuiMathMatrix(GuiView & lv); @@ -3723,6 +3725,8 @@ Dialog * GuiView::build(string const & name) return createGuiPrintindex(*this); if (name == "label") return createGuiLabel(*this); + if (name == "line") + return createGuiLine(*this); if (name == "listings") return createGuiListings(*this); if (name == "log") diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index a2e4c23f82..12b3d0d4da 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -95,6 +95,7 @@ SOURCEFILES = \ GuiInfo.cpp \ GuiKeySymbol.cpp \ GuiLabel.cpp \ + GuiLine.cpp \ GuiListings.cpp \ GuiLog.cpp \ GuiMathMatrix.cpp \ @@ -199,6 +200,7 @@ MOCHEADER = \ GuiIndices.h \ GuiInfo.h \ GuiLabel.h \ + GuiLine.h \ GuiListings.h \ GuiLog.h \ GuiMathMatrix.h \ @@ -280,6 +282,7 @@ UIFILES = \ LabelUi.ui \ LanguageUi.ui \ LaTeXUi.ui \ + LineUi.ui \ ListingsUi.ui \ ListingsSettingsUi.ui \ LocalLayoutUi.ui \ diff --git a/src/frontends/qt4/ui/LineUi.ui b/src/frontends/qt4/ui/LineUi.ui new file mode 100644 index 0000000000..bdfd70f2c4 --- /dev/null +++ b/src/frontends/qt4/ui/LineUi.ui @@ -0,0 +1,188 @@ + + LineUi + + + + 0 + 0 + 325 + 126 + + + + + + + true + + + + + + Offset: + + + + + + + true + + + Value of the vertical line offset. + + + + + + + + 0 + 0 + + + + + 150 + 20 + + + + + + + + Width: + + + WidthLE + + + + + + + true + + + Value of the line width. + + + + + + + + 0 + 0 + + + + + 150 + 20 + + + + + + + + Height: + + + + + + + true + + + Value of the line height. + + + + + + + + 0 + 0 + + + + + 150 + 20 + + + + + + + + Qt::Horizontal + + + + 59 + 20 + + + + + + + + + + &OK + + + false + + + true + + + + + + + &Apply + + + false + + + + + + + &Close + + + false + + + + + + + + + + LengthCombo + QComboBox +
LengthCombo.h
+
+
+ + WidthLE + + + qt_i18n.h + + + +
diff --git a/src/insets/InsetCommand.cpp b/src/insets/InsetCommand.cpp index 357ec8628a..b53f08958c 100644 --- a/src/insets/InsetCommand.cpp +++ b/src/insets/InsetCommand.cpp @@ -29,6 +29,7 @@ #include "insets/InsetFloat.h" #include "insets/InsetGraphics.h" #include "insets/InsetInclude.h" +#include "insets/InsetLine.h" #include "insets/InsetListings.h" #include "insets/InsetNote.h" #include "insets/InsetPhantom.h" @@ -260,6 +261,7 @@ bool decodeInsetParam(string const & name, string & data, case BIBTEX_CODE: case INDEX_CODE: case LABEL_CODE: + case LINE_CODE: case NOMENCL_CODE: case NOMENCL_PRINT_CODE: case REF_CODE: diff --git a/src/insets/InsetCommand.h b/src/insets/InsetCommand.h index 6297cf723e..911ddf3042 100644 --- a/src/insets/InsetCommand.h +++ b/src/insets/InsetCommand.h @@ -55,6 +55,8 @@ public: /// 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; /// FIXME Remove docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); } @@ -87,8 +89,6 @@ private: /// void metrics(MetricsInfo &, Dimension &) const; /// - Dimension const dimension(BufferView const &) const { return button_.dimension(); } - /// void draw(PainterInfo & pi, int x, int y) const; /// int latex(odocstream &, OutputParams const &) const; diff --git a/src/insets/InsetCommandParams.cpp b/src/insets/InsetCommandParams.cpp index a0cbd6e785..87084c3ee9 100644 --- a/src/insets/InsetCommandParams.cpp +++ b/src/insets/InsetCommandParams.cpp @@ -23,6 +23,7 @@ #include "InsetInclude.h" #include "InsetIndex.h" #include "InsetLabel.h" +#include "InsetLine.h" #include "InsetNomencl.h" #include "InsetRef.h" #include "InsetTOC.h" @@ -70,6 +71,8 @@ static ParamInfo const & findInfo(InsetCode code, string const & cmdName) return InsetPrintIndex::findInfo(cmdName); case LABEL_CODE: return InsetLabel::findInfo(cmdName); + case LINE_CODE: + return InsetLine::findInfo(cmdName); case NOMENCL_CODE: return InsetNomencl::findInfo(cmdName); case NOMENCL_PRINT_CODE: @@ -200,6 +203,8 @@ string InsetCommandParams::getDefaultCmd(InsetCode code) return InsetPrintIndex::defaultCommand(); case LABEL_CODE: return InsetLabel::defaultCommand(); + case LINE_CODE: + return InsetLine::defaultCommand(); case NOMENCL_CODE: return InsetNomencl::defaultCommand(); case NOMENCL_PRINT_CODE: @@ -234,6 +239,8 @@ bool InsetCommandParams::isCompatibleCommand(InsetCode code, string const & s) return InsetPrintIndex::isCompatibleCommand(s); case LABEL_CODE: return InsetLabel::isCompatibleCommand(s); + case LINE_CODE: + return InsetLine::isCompatibleCommand(s); case NOMENCL_CODE: return InsetNomencl::isCompatibleCommand(s); case NOMENCL_PRINT_CODE: diff --git a/src/insets/InsetLine.cpp b/src/insets/InsetLine.cpp index 867f5fbb3a..ff76f28385 100644 --- a/src/insets/InsetLine.cpp +++ b/src/insets/InsetLine.cpp @@ -4,6 +4,7 @@ * Licence details can be found in the file COPYING. * * \author André Pönitz + * \author Uwe Stöhr * * Full author contact details are available in file CREDITS. */ @@ -12,20 +13,26 @@ #include "InsetLine.h" +#include "Buffer.h" #include "Dimension.h" -#include "Font.h" +#include "DispatchResult.h" +#include "FuncRequest.h" +#include "FuncStatus.h" #include "LaTeXFeatures.h" +#include "Length.h" #include "MetricsInfo.h" #include "OutputParams.h" #include "output_xhtml.h" #include "Text.h" +#include "frontends/FontMetrics.h" #include "frontends/Painter.h" +#include "support/convert.h" #include "support/debug.h" #include "support/docstream.h" - - +#include "support/gettext.h" +#include "support/lstrings.h" using namespace std; @@ -34,24 +41,88 @@ namespace lyx { 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 { - dim.asc = 3; - dim.des = 3; - dim.wid = mi.base.textwidth; - // Cache the inset dimension. + frontend::FontMetrics const & fm = theFontMetrics(mi.base.font); + dim.asc = fm.maxAscent(); + dim.des = fm.maxDescent(); + + 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); } @@ -60,18 +131,60 @@ void InsetLine::draw(PainterInfo & pi, int x, int y) const { 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; Color Line_color = f.realColor(); - pi.pain.line(x, y, x + dim.wid, y, Line_color, - Painter::line_solid, 1); + // assure that the drawn line is not outside of the window + // 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 { - os << "\\lyxline{\\" - << from_ascii(runparams.local_font->latexSize()) << '}'; + bool have_offset = true; + 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; } @@ -98,10 +211,4 @@ docstring InsetLine::xhtml(XHTMLStream & xs, OutputParams const &) const } -void InsetLine::validate(LaTeXFeatures & features) const -{ - features.require("lyxline"); -} - - } // namespace lyx diff --git a/src/insets/InsetLine.h b/src/insets/InsetLine.h index f9e289528c..87c1569769 100644 --- a/src/insets/InsetLine.h +++ b/src/insets/InsetLine.h @@ -5,6 +5,7 @@ * Licence details can be found in the file COPYING. * * \author André Pönitz + * \author Uwe Stöhr * * Full author contact details are available in file CREDITS. */ @@ -14,16 +15,36 @@ #include "Inset.h" +#include "InsetCommand.h" namespace lyx { -class InsetLine : public Inset { +class LaTeXFeatures; + +class InsetLine : public InsetCommand { 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; } + /// + 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; /// @@ -33,20 +54,10 @@ public: /// 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); } }; diff --git a/src/rowpainter.cpp b/src/rowpainter.cpp index cb48fb7f1a..ba3d476f42 100644 --- a/src/rowpainter.cpp +++ b/src/rowpainter.cpp @@ -103,6 +103,11 @@ void RowPainter::paintInset(Inset const * inset, pos_type const pos) // requires a 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 // noFontChange() in Inset.h. pi_.base.font = inset->noFontChange() ?