Uwe Stöhr schrieb:

OK, I'll implement this and send a new patch.

Here is the patch.
To be able to set a default value, I introduced a new unit for Length. I cannot think of another solution because using a real length to mark that the user wants the default is not possible, since every set width might be desired by the user.

> When I switch to Length, should I also change the other width from
> VSpace to Length?

I left these untouched to make the patch not unnecessary large. I can do this 
later.

regards Uwe
Index: BufferParams.cpp
===================================================================
--- BufferParams.cpp	(revision 30595)
+++ BufferParams.cpp	(working copy)
@@ -289,6 +289,7 @@
 	/** This is the amount of space used for paragraph_separation "skip",
 	 * and for detached paragraphs in "indented" documents.
 	 */
+	Length indentation;
 	VSpace defskip;
 	PDFOptions pdfoptions;
 	LayoutFileIndex baseClass_;
@@ -468,6 +469,18 @@
 }
 
 
+Length const & BufferParams::getIndentation() const
+{
+	return pimpl_->indentation;
+}
+
+
+void BufferParams::setIndentation(Length const & indent)
+{
+	pimpl_->indentation = indent;
+}
+
+
 VSpace const & BufferParams::getDefSkip() const
 {
 	return pimpl_->defskip;
@@ -566,6 +579,13 @@
 		string parsep;
 		lex >> parsep;
 		paragraph_separation = parseptranslator().find(parsep);
+	} else if (token == "\\paragraph_indentation") {
+		lex.next();
+		string indentation = lex.getString();
+		if (indentation == "default")
+			pimpl_->indentation = Length(Length::DEFAULT);
+		else
+			pimpl_->indentation = Length(indentation);
 	} else if (token == "\\defskip") {
 		lex.next();
 		string defskip = lex.getString();
@@ -903,9 +923,12 @@
 	os << "\\secnumdepth " << secnumdepth
 	   << "\n\\tocdepth " << tocdepth
 	   << "\n\\paragraph_separation "
-	   << string_paragraph_separation[paragraph_separation]
-	   << "\n\\defskip " << getDefSkip().asLyXCommand()
-	   << "\n\\quotes_language "
+	   << string_paragraph_separation[paragraph_separation];
+	if (!paragraph_separation)
+		os << "\n\\paragraph_indentation " << getIndentation().asString();
+	else
+		os << "\n\\defskip " << getDefSkip().asLyXCommand();
+	os << "\n\\quotes_language "
 	   << string_quotes_language[quotes_language]
 	   << "\n\\papercolumns " << columns
 	   << "\n\\papersides " << sides
@@ -1370,6 +1393,7 @@
 	}
 
 	if (paragraph_separation) {
+		// when skip separation
 		switch (getDefSkip().kind()) {
 		case VSpace::SMALLSKIP:
 			os << "\\setlength{\\parskip}{\\smallskipamount}\n";
@@ -1390,9 +1414,17 @@
 			break;
 		}
 		texrow.newline();
-
 		os << "\\setlength{\\parindent}{0pt}\n";
 		texrow.newline();
+	} else {
+		// when separation by indentation
+		// only output something when a indetn width is given
+		if (getIndentation().value() > 0) {
+			os << "\\setlength{\\parindent}{"
+			   << from_utf8(getIndentation().asString())
+			   << "}\n";
+			texrow.newline();
+		}
 	}
 
 	// Now insert the LyX specific LaTeX commands...
Index: BufferParams.h
===================================================================
--- BufferParams.h	(revision 30595)
+++ BufferParams.h	(working copy)
@@ -41,6 +41,7 @@
 class LatexFeatures;
 class LayoutFile;
 class LayoutFileIndex;
+class Length;
 class Lexer;
 class PDFOptions;
 class Spacing;
@@ -90,6 +91,10 @@
 	bool hasClassDefaults() const;
 
 	///
+	Length const & getIndentation() const;
+	///
+	void setIndentation(Length const & indent);
+	///
 	VSpace const & getDefSkip() const;
 	///
 	void setDefSkip(VSpace const & vs);
Index: frontends/qt4/GuiDocument.cpp
===================================================================
--- frontends/qt4/GuiDocument.cpp	(revision 30595)
+++ frontends/qt4/GuiDocument.cpp	(working copy)
@@ -553,20 +553,38 @@
 		this, SLOT(setLSpacing(int)));
 	connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
 		this, SLOT(change_adaptor()));
+
+	connect(textLayoutModule->indentRB, SIGNAL(clicked()),
+		this, SLOT(change_adaptor()));
+	connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
+		textLayoutModule->indentCO, SLOT(setEnabled(bool)));
+	connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
+		this, SLOT(change_adaptor()));
+	connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
+		this, SLOT(setIndent(int)));
+	connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
+		this, SLOT(change_adaptor()));
+	connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
+		this, SLOT(change_adaptor()));
+
 	connect(textLayoutModule->skipRB, SIGNAL(clicked()),
 		this, SLOT(change_adaptor()));
-	connect(textLayoutModule->indentRB, SIGNAL(clicked()),
+	connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
+		textLayoutModule->skipCO, SLOT(setEnabled(bool)));
+	connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
 		this, SLOT(change_adaptor()));
 	connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
-		this, SLOT(change_adaptor()));
+		this, SLOT(setSkip(int)));
 	connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
 		this, SLOT(change_adaptor()));
 	connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
 		this, SLOT(change_adaptor()));
-	connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
-		this, SLOT(setSkip(int)));
+
+	connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
+		this, SLOT(enableIndent(bool)));
 	connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
 		this, SLOT(enableSkip(bool)));
+
 	connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
 		this, SLOT(change_adaptor()));
 	connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
@@ -583,15 +601,17 @@
 		qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
 	textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
 		textLayoutModule->lspacingLE));
+	textLayoutModule->indentLE->setValidator(unsignedLengthValidator(
+		textLayoutModule->indentLE));
 	textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
 		textLayoutModule->skipLE));
 
+	textLayoutModule->indentCO->addItem(qt_("Default"));
+	textLayoutModule->indentCO->addItem(qt_("Length"));
 	textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
 	textLayoutModule->skipCO->addItem(qt_("MedSkip"));
 	textLayoutModule->skipCO->addItem(qt_("BigSkip"));
 	textLayoutModule->skipCO->addItem(qt_("Length"));
-	// remove the %-items from the unit choice
-	textLayoutModule->skipLengthCO->noPercents();
 	textLayoutModule->lspacingCO->insertItem(
 		Spacing::Single, qt_("Single"));
 	textLayoutModule->lspacingCO->insertItem(
@@ -600,8 +620,11 @@
 		Spacing::Double, qt_("Double"));
 	textLayoutModule->lspacingCO->insertItem(
 		Spacing::Other, qt_("Custom"));
-
+	// remove the %-items from the unit choices
+	textLayoutModule->indentLengthCO->noPercents();
+	textLayoutModule->skipLengthCO->noPercents();
 	// initialize the length validator
+	bc().addCheckedLineEdit(textLayoutModule->indentLE);
 	bc().addCheckedLineEdit(textLayoutModule->skipLE);
 
 	// output
@@ -1115,19 +1138,45 @@
 }
 
 
+void GuiDocument::setIndent(int item)
+{
+	bool const enable = (item == 1);
+	textLayoutModule->indentLE->setEnabled(enable);
+	textLayoutModule->indentLengthCO->setEnabled(enable);
+	textLayoutModule->skipLE->setEnabled(false);
+	textLayoutModule->skipLengthCO->setEnabled(false);
+	// clear values, otherwise one would get for a new document the
+	// same settings as default as for a currently opened document
+	textLayoutModule->skipLE->clear();
+	isValid();
+}
+
+
+void GuiDocument::enableIndent(bool indent)
+{
+	textLayoutModule->skipLE->setEnabled(!indent);
+	textLayoutModule->skipLengthCO->setEnabled(!indent);
+	if (indent)
+		setIndent(textLayoutModule->indentCO->currentIndex());
+}
+
+
 void GuiDocument::setSkip(int item)
 {
 	bool const enable = (item == 3);
 	textLayoutModule->skipLE->setEnabled(enable);
 	textLayoutModule->skipLengthCO->setEnabled(enable);
+	// clear values, otherwise one would get for a new document the
+	// same settings as default as for a currently opened document
+	textLayoutModule->indentLE->clear();
+	isValid();
 }
 
 
 void GuiDocument::enableSkip(bool skip)
 {
-	textLayoutModule->skipCO->setEnabled(skip);
-	textLayoutModule->skipLE->setEnabled(skip);
-	textLayoutModule->skipLengthCO->setEnabled(skip);
+	textLayoutModule->indentLE->setEnabled(!skip);
+	textLayoutModule->indentLengthCO->setEnabled(!skip);
 	if (skip)
 		setSkip(textLayoutModule->skipCO->currentIndex());
 }
@@ -1890,36 +1939,55 @@
 	bp_.listings_params =
 		InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
 
-	if (textLayoutModule->indentRB->isChecked())
+	if (textLayoutModule->indentRB->isChecked()) {
+		// if paragraphs are separated by an indentation
 		bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
-	else
+		switch (textLayoutModule->indentCO->currentIndex()) {
+		case 0:
+			bp_.setIndentation(Length(Length::DEFAULT));
+			break;
+		case 1:
+			{
+			Length indent = Length(
+				widgetsToLength(textLayoutModule->indentLE,
+				textLayoutModule->indentLengthCO)
+				);
+			bp_.setIndentation(indent);
+			break;
+			}
+		default:
+			// this should never happen
+			bp_.setIndentation(Length());
+			break;
+		}
+	} else {
+		// if paragraphs are separated by a skip
 		bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
-
-	switch (textLayoutModule->skipCO->currentIndex()) {
-	case 0:
-		bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
-		break;
-	case 1:
-		bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
-		break;
-	case 2:
-		bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
-		break;
-	case 3:
-	{
-		VSpace vs = VSpace(
-			widgetsToLength(textLayoutModule->skipLE,
+		switch (textLayoutModule->skipCO->currentIndex()) {
+		case 0:
+			bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
+			break;
+		case 1:
+			bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
+			break;
+		case 2:
+			bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
+			break;
+		case 3:
+			{
+			VSpace vs = VSpace(
+				widgetsToLength(textLayoutModule->skipLE,
 				textLayoutModule->skipLengthCO)
-			);
-		bp_.setDefSkip(vs);
-		break;
+				);
+			bp_.setDefSkip(vs);
+			break;
+			}
+		default:
+			// this should never happen
+			bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
+			break;
+		}
 	}
-	default:
-		// DocumentDefskipCB assures that this never happens
-		// so Assert then !!!  - jbl
-		bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
-		break;
-	}
 
 	bp_.options =
 		fromqstr(latexModule->optionsLE->text());
@@ -2206,37 +2274,50 @@
 	}
 	setLSpacing(nitem);
 
-	if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation)
+	if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
 		textLayoutModule->indentRB->setChecked(true);
-	else
+		string indentation = bp_.getIndentation().asString();
+		int indent = 0;
+		// "0" is the case for a new document
+		if (indentation == "default" || indentation == "0")
+			indent = 0;
+		else {
+			lengthToWidgets(textLayoutModule->indentLE,
+			textLayoutModule->indentLengthCO,
+			indentation, defaultUnit);
+			indent = 1;
+		}
+		textLayoutModule->indentCO->setCurrentIndex(indent);
+		setIndent(indent);
+	} else {
 		textLayoutModule->skipRB->setChecked(true);
-
-	int skip = 0;
-	switch (bp_.getDefSkip().kind()) {
-	case VSpace::SMALLSKIP:
-		skip = 0;
-		break;
-	case VSpace::MEDSKIP:
-		skip = 1;
-		break;
-	case VSpace::BIGSKIP:
-		skip = 2;
-		break;
-	case VSpace::LENGTH:
-	{
-		skip = 3;
-		string const length = bp_.getDefSkip().asLyXCommand();
-		lengthToWidgets(textLayoutModule->skipLE,
-			textLayoutModule->skipLengthCO,
-			length, defaultUnit);
-		break;
+		int skip = 0;
+		switch (bp_.getDefSkip().kind()) {
+		case VSpace::SMALLSKIP:
+			skip = 0;
+			break;
+		case VSpace::MEDSKIP:
+			skip = 1;
+			break;
+		case VSpace::BIGSKIP:
+			skip = 2;
+			break;
+		case VSpace::LENGTH:
+			{
+			skip = 3;
+			string const length = bp_.getDefSkip().asLyXCommand();
+			lengthToWidgets(textLayoutModule->skipLE,
+				textLayoutModule->skipLengthCO,
+				length, defaultUnit);
+			break;
+			}
+		default:
+			skip = 0;
+			break;
+		}
+		textLayoutModule->skipCO->setCurrentIndex(skip);
+		setSkip(skip);
 	}
-	default:
-		skip = 0;
-		break;
-	}
-	textLayoutModule->skipCO->setCurrentIndex(skip);
-	setSkip(skip);
 
 	textLayoutModule->twoColumnCB->setChecked(
 		bp_.columns == 2);
@@ -2535,7 +2616,11 @@
 {
 	return validateListingsParameters().isEmpty()
 		&& (textLayoutModule->skipCO->currentIndex() != 3
-			|| !textLayoutModule->skipLE->text().isEmpty());
+			|| !textLayoutModule->skipLE->text().isEmpty()
+			|| textLayoutModule->indentRB->isChecked())
+		&& (textLayoutModule->indentCO->currentIndex() != 1
+			|| !textLayoutModule->indentLE->text().isEmpty()
+			|| textLayoutModule->skipRB->isChecked());
 }
 
 
Index: frontends/qt4/GuiDocument.h
===================================================================
--- frontends/qt4/GuiDocument.h	(revision 30595)
+++ frontends/qt4/GuiDocument.h	(working copy)
@@ -93,6 +93,8 @@
 	void romanChanged(int);
 	void sansChanged(int);
 	void ttChanged(int);
+	void setIndent(int);
+	void enableIndent(bool);
 	void setSkip(int);
 	void enableSkip(bool);
 	void portraitChanged();
Index: frontends/qt4/ui/TextLayoutUi.ui
===================================================================
--- frontends/qt4/ui/TextLayoutUi.ui	(revision 30595)
+++ frontends/qt4/ui/TextLayoutUi.ui	(working copy)
@@ -6,7 +6,7 @@
     <x>0</x>
     <y>0</y>
     <width>400</width>
-    <height>366</height>
+    <height>424</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -50,7 +50,114 @@
         </property>
        </widget>
       </item>
-      <item row="1" column="0">
+      <item row="0" column="1">
+       <widget class="QComboBox" name="indentCO">
+        <property name="enabled">
+         <bool>false</bool>
+        </property>
+        <property name="minimumSize">
+         <size>
+          <width>120</width>
+          <height>20</height>
+         </size>
+        </property>
+        <property name="maximumSize">
+         <size>
+          <width>121</width>
+          <height>21</height>
+         </size>
+        </property>
+        <property name="toolTip">
+         <string>size of the vertical space</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="2" colspan="2">
+       <spacer name="spacer_3">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeType">
+         <enum>QSizePolicy::Expanding</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>135</width>
+          <height>26</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="1" column="1">
+       <widget class="QLineEdit" name="indentLE">
+        <property name="enabled">
+         <bool>false</bool>
+        </property>
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="minimumSize">
+         <size>
+          <width>120</width>
+          <height>20</height>
+         </size>
+        </property>
+        <property name="maximumSize">
+         <size>
+          <width>121</width>
+          <height>21</height>
+         </size>
+        </property>
+        <property name="toolTip">
+         <string>value</string>
+        </property>
+        <property name="text">
+         <string/>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="2">
+       <widget class="LengthCombo" name="indentLengthCO">
+        <property name="enabled">
+         <bool>false</bool>
+        </property>
+        <property name="minimumSize">
+         <size>
+          <width>69</width>
+          <height>20</height>
+         </size>
+        </property>
+        <property name="maximumSize">
+         <size>
+          <width>70</width>
+          <height>21</height>
+         </size>
+        </property>
+        <property name="toolTip">
+         <string>unit</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="3">
+       <spacer name="spacer">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeType">
+         <enum>QSizePolicy::Expanding</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>62</width>
+          <height>26</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="2" column="0">
        <widget class="QRadioButton" name="skipRB">
         <property name="minimumSize">
          <size>
@@ -66,7 +173,7 @@
         </property>
        </widget>
       </item>
-      <item row="1" column="1">
+      <item row="2" column="1">
        <widget class="QComboBox" name="skipCO">
         <property name="enabled">
          <bool>false</bool>
@@ -88,7 +195,7 @@
         </property>
        </widget>
       </item>
-      <item row="1" column="2" colspan="2">
+      <item row="2" column="2" colspan="2">
        <spacer name="spacer_2">
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
@@ -104,7 +211,7 @@
         </property>
        </spacer>
       </item>
-      <item row="2" column="1">
+      <item row="3" column="1">
        <widget class="QLineEdit" name="skipLE">
         <property name="enabled">
          <bool>false</bool>
@@ -132,7 +239,7 @@
         </property>
        </widget>
       </item>
-      <item row="2" column="2">
+      <item row="3" column="2">
        <widget class="LengthCombo" name="skipLengthCO">
         <property name="enabled">
          <bool>false</bool>
@@ -154,7 +261,7 @@
         </property>
        </widget>
       </item>
-      <item row="2" column="3">
+      <item row="3" column="3">
        <spacer>
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
Index: Length.cpp
===================================================================
--- Length.cpp	(revision 30595)
+++ Length.cpp	(working copy)
@@ -39,6 +39,11 @@
 {}
 
 
+Length::Length(Length::UNIT u)
+	: val_(0), unit_(u)
+{}
+
+
 Length::Length(double v, Length::UNIT u)
 	: val_(v), unit_(u)
 {}
@@ -67,7 +72,10 @@
 string const Length::asString() const
 {
 	ostringstream os;
-	os << val_ << unit_name[unit_]; // setw?
+	if (unit_ != Length::DEFAULT)
+		os << val_ << unit_name[unit_]; // setw?
+	else
+		os << "default";
 	return os.str();
 }
 
@@ -75,7 +83,10 @@
 docstring const Length::asDocstring() const
 {
 	odocstringstream os;
-	os << val_ << unit_name[unit_]; // setw?
+	if (unit_ != Length::DEFAULT)
+		os << val_ << unit_name[unit_]; // setw?
+	else
+		os << from_ascii("default");
 	return os.str();
 }
 
@@ -102,6 +113,8 @@
 	case PTH:
 		os << val_ / 100.0 << "\\textheight";
 		break;
+	case DEFAULT:
+		break;
 	default:
 		os << val_ << unit_name[unit_];
 	  break;
@@ -146,6 +159,7 @@
 		break;
 	case SP:
 	case UNIT_NONE:
+	case DEFAULT:
 		break;
 	}
 	return os.str();
@@ -283,6 +297,7 @@
 	case Length::PPH:
 		result = val_ * text_width * 2.2 / 100;
 		break;
+	case DEFAULT:
 	case Length::UNIT_NONE:
 		result = 0;  // this cannot happen
 		break;
Index: Length.h
===================================================================
--- Length.h	(revision 30595)
+++ Length.h	(working copy)
@@ -56,12 +56,15 @@
 		PPW, //< Percent of PageWidth
 		PTH, //< Percent of TextHeight		// Herbert 2002-05-16
 		PTW, //< Percent of TextWidth
-		UNIT_NONE ///< no unit
+		UNIT_NONE, ///< no unit
+		DEFAULT ///< when the document class or LaTeX default should be used
 	};
 
 	///
 	Length();
 	///
+	Length(Length::UNIT u);
+	///
 	Length(double v, Length::UNIT u);
 
 	/// "data" must be a decimal number, followed by a unit

Reply via email to