Ich schrieb:
>> OK, I'll provide an improved version of my patch that also shows
the code for \big etc.
>
> Hum... then why not just take my patch?
because you display LFUNS ;-).
Just joking. Your patch is good as it cleans up the whole code. I take it and built in what I like
to have.
In your patch was a bug:
if (leftLW->currentRow() < leftLW->count() - 1)
left_str = fix_name(leftLW->currentItem()->toolTip(), bigsize);
In this case when the user selects "None" as delimiter, the "." is not set in the LaTeX-output and
causes therefore LaTeX-errors.
In my patch is also a bug I cannot fix. This line causes Lyx to crash when
calling the dialog:
bigl = bigleft[size - 1];
I don't understand why it compiles fine but the a crash occurs.
If you could fix this issue please test.
I also widened the dialog a bit because it was too small to display the maximal TeX-code (also too
small for your LFUN output).
thanks and regards
Uwe
Index: QDelimiterDialog.C
===================================================================
--- QDelimiterDialog.C (revision 17833)
+++ QDelimiterDialog.C (working copy)
@@ -36,19 +36,19 @@
namespace {
-char const * const bigleft[] = {"bigl", "Bigl", "biggl", "Biggl", ""};
+QString const bigleft[] = {"bigl", "Bigl", "biggl", "Biggl", ""};
-char const * const bigright[] = {"bigr", "Bigr", "biggr", "Biggr", ""};
+QString const bigright[] = {"bigr", "Bigr", "biggr", "Biggr", ""};
char const * const biggui[] = {N_("big[[delimiter size]]"), N_("Big[[delimiter size]]"),
N_("bigg[[delimiter size]]"), N_("Bigg[[delimiter size]]"), ""};
-string fix_name(string const & str, bool big)
+QString fix_name(QString const & str, bool big)
{
- if (str.empty())
+ if (str.isEmpty())
return ".";
if (!big || str == "(" || str == ")" || str == "[" || str == "]"
|| str == "|" || str == "/")
@@ -91,7 +91,6 @@
setupUi(this);
connect(closePB, SIGNAL(clicked()), this, SLOT(accept()));
- connect(insertPB, SIGNAL(clicked()), this, SLOT(insertClicked()));
setWindowTitle(qt_("LyX: Delimiters"));
setFocusProxy(leftLW);
@@ -133,41 +132,78 @@
}
-void QDelimiterDialog::insertClicked()
+void QDelimiterDialog::updateTeXCode(int size)
{
- string left_str;
- string right_str;
+ QString left_str;
+ QString right_str;
+ QString l_str;
+ QString r_str;
+ QString bigl;
+ QString bigr;
+ QString code_str;
+ bool bigsize = size != 0;
+
+ // Omit the \big commands when there is no delimiter for the TeX-code
if (leftLW->currentRow() < leftLW->count() - 1)
- left_str = fromqstr(leftLW->currentItem()->toolTip());
+ bigl = bigleft[size - 1];
+ else
+ bigl = "";
if (rightLW->currentRow() < rightLW->count() - 1)
- right_str = fromqstr(rightLW->currentItem()->toolTip());
+ bigr = bigright[size - 1];
+ else
+ bigr = "";
- int const size_ = sizeCO->currentIndex();
- if (size_ == 0) {
- form_->controller().dispatchDelim(
- fix_name(left_str, false) + ' ' +
- fix_name(right_str, false));
+ left_str = fix_name(leftLW->currentItem()->toolTip(), bigsize);
+ right_str = fix_name(rightLW->currentItem()->toolTip(), bigsize);
+
+ if (!bigsize)
+ {
+ tex_code_ = left_str + ' ' + right_str;
+ left_str = fix_name(leftLW->currentItem()->toolTip(), true);
+ right_str = fix_name(rightLW->currentItem()->toolTip(), true);
+ code_str = "TeX-Code: \\left" + left_str + ' ' + "\\right" + right_str;
} else {
- std::ostringstream os;
- os << '"' << bigleft[size_ - 1] << "\" \""
- << fix_name(left_str, true) << "\" \""
- << bigright[size_ - 1] << "\" \""
- << fix_name(right_str, true) << '"';
- form_->controller().dispatchBigDelim(os.str());
+ tex_code_ = bigleft[size - 1] + ' '
+ + left_str + ' '
+ + bigright[size - 1] + ' '
+ + right_str;
+ code_str = "TeX-Code: \\" + bigl
+ + left_str + ' '
+ + "\\" + bigr
+ + right_str;
}
+
+ texCodeL->setText(code_str);
}
+void QDelimiterDialog::on_insertPB_clicked()
+{
+ if (sizeCO->currentIndex() == 0)
+ form_->controller().dispatchDelim(fromqstr(tex_code_));
+ else {
+ QString command = '"' + tex_code_ + '"';
+ command.replace(' ', "\" \"");
+ form_->controller().dispatchBigDelim(fromqstr(command));
+ }
+ }
+
+void QDelimiterDialog::on_sizeCO_activated(int index)
+{
+ updateTeXCode(index);
+}
+
+
void QDelimiterDialog::on_leftLW_itemActivated(QListWidgetItem *)
{
- insertClicked();
+ on_insertPB_clicked();
accept();
}
void QDelimiterDialog::on_rightLW_itemActivated(QListWidgetItem *)
{
- insertClicked();
+ on_insertPB_clicked();
accept();
}
@@ -177,11 +213,7 @@
if (matchCB->isChecked())
rightLW->setCurrentRow(item);
- // Display the associated TeX name.
- if (leftLW->currentRow() == leftLW->count() - 1)
- texCodeL->clear();
- else
- texCodeL->setText("TeX code: \\" + leftLW->currentItem()->toolTip());
+ updateTeXCode(sizeCO->currentIndex());
}
@@ -190,11 +222,7 @@
if (matchCB->isChecked())
leftLW->setCurrentRow(item);
- // Display the associated TeX name.
- if (rightLW->currentRow() == leftLW->count() - 1)
- texCodeL->clear();
- else
- texCodeL->setText("TeX code: \\" + rightLW->currentItem()->toolTip());
+ updateTeXCode(sizeCO->currentIndex());
}
Index: QDelimiterDialog.h
===================================================================
--- QDelimiterDialog.h (revision 17833)
+++ QDelimiterDialog.h (working copy)
@@ -33,12 +33,17 @@
void on_leftLW_currentRowChanged(int);
void on_rightLW_currentRowChanged(int);
void on_matchCB_stateChanged(int);
- void insertClicked();
+ void on_insertPB_clicked();
+ void on_sizeCO_activated(int);
private:
///
char_type doMatch(char_type const symbol) const;
+ ///
+ void updateTeXCode(int size);
/// owning form
QMathDelimiter * form_;
+ /// TeX code that will be inserted.
+ QString tex_code_;
};
} // namespace frontend
Index: ui/QDelimiterUi.ui
===================================================================
--- ui/QDelimiterUi.ui (revision 17833)
+++ ui/QDelimiterUi.ui (working copy)
@@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>200</width>
- <height>447</height>
+ <width>286</width>
+ <height>537</height>
</rect>
</property>
<property name="sizePolicy" >
@@ -35,13 +35,13 @@
<property name="sizeGripEnabled" >
<bool>true</bool>
</property>
- <widget class="QWidget" name="" >
+ <widget class="QWidget" name="verticalLayout" >
<property name="geometry" >
<rect>
- <x>9</x>
- <y>9</y>
- <width>176</width>
- <height>431</height>
+ <x>10</x>
+ <y>10</y>
+ <width>261</width>
+ <height>511</height>
</rect>
</property>
<layout class="QVBoxLayout" >
@@ -144,8 +144,17 @@
</sizepolicy>
</property>
<property name="text" >
- <string>TeX Code</string>
+ <string>TeX Code: \Biggl\Updownarrow \Biggr\Updownarrow</string>
</property>
+ <property name="textFormat" >
+ <enum>Qt::AutoText</enum>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+ </property>
+ <property name="wordWrap" >
+ <bool>false</bool>
+ </property>
</widget>
</item>
<item>
@@ -190,6 +199,9 @@
<property name="text" >
<string>&Size:</string>
</property>
+ <property name="alignment" >
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
<property name="buddy" >
<cstring>sizeCO</cstring>
</property>