mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-12 22:14:35 +00:00
From c7899a30a0b5975bf599a69ecd11ab25e1cdf1a4 Mon Sep 17 00:00:00 2001
From: "Joel A. Kulesza" <jkulesza@gmail.com> Date: Mon, 24 Oct 2016 17:37:58 -0600 Subject: [PATCH] Add "Swap & Reverse" to math delimiter dialog When "Keep matched" is unchecked, a button becomes enabled to "Swap & Reverse" the left and right delimiters. This is expected to be of use with line-wrapped equations featuring one or more set of delimiters that break across the lines. When "Keep matched" is checked, the button is visible but disabled. The most common use case is expected to be the user entering a pair of unmatched delimiters on the first line of an equation (e.g., "(" and "(None)"), entering the inner text, going to the next line, and inserting the opposite set of delimiters (e.g., "(None)" and ")"). This button will negate the need to find the correct corresponding combination. However, it relies on the dialog's memory of the previous unmatched set. This change addresses Ticket #10457 ----------- Modifications by spitz to the original patch: * Only enable the button if an unmatched pair is selected * Consider l7n when locating the string "(None)" * Add an accelerator and a tooltip to the dialog * Simplify the code a bit
This commit is contained in:
parent
2a4538ad56
commit
5de448e132
@ -207,7 +207,7 @@ GuiDelimiter::GuiDelimiter(GuiView & lv)
|
||||
int const end = nr_latex_delimiters - 1;
|
||||
for (int i = 0; i < end; ++i) {
|
||||
string const delim = latex_delimiters[i];
|
||||
MathSymbol const & ms = mathSymbol(delim);
|
||||
MathSymbol const & ms = mathSymbol(delim);
|
||||
QString symbol(ms.fontcode?
|
||||
QChar(ms.fontcode) : toqstr(docstring(1, ms.unicode)));
|
||||
QListWidgetItem * lwi = new QListWidgetItem(symbol);
|
||||
@ -232,7 +232,7 @@ GuiDelimiter::GuiDelimiter(GuiView & lv)
|
||||
}
|
||||
|
||||
for (int i = 0; i != leftLW->count(); ++i) {
|
||||
MathSymbol const & ms = mathSymbol(getDelimiterName(leftLW->item(i)));
|
||||
MathSymbol const & ms = mathSymbol(getDelimiterName(leftLW->item(i)));
|
||||
rightLW->addItem(list_items[doMatch(ms.unicode)]->clone());
|
||||
}
|
||||
|
||||
@ -318,6 +318,12 @@ void GuiDelimiter::updateTeXCode(int size)
|
||||
}
|
||||
|
||||
texCodeL->setText(qt_("TeX Code: ") + toqstr(code_str));
|
||||
|
||||
// Enable the Swap button with non-matched pairs
|
||||
bool const allow_swap =
|
||||
(doMatch(mathSymbol(getDelimiterName(leftLW->currentItem())).unicode)
|
||||
!= mathSymbol(getDelimiterName(rightLW->currentItem())).unicode);
|
||||
swapPB->setEnabled(allow_swap);
|
||||
}
|
||||
|
||||
|
||||
@ -385,6 +391,43 @@ void GuiDelimiter::on_matchCB_stateChanged(int state)
|
||||
updateTeXCode(sizeCO->currentIndex());
|
||||
}
|
||||
|
||||
void GuiDelimiter::on_swapPB_clicked()
|
||||
{
|
||||
// Get current math symbol for each side.
|
||||
MathSymbol const & lms =
|
||||
mathSymbol(getDelimiterName(leftLW->currentItem()));
|
||||
MathSymbol const & rms =
|
||||
mathSymbol(getDelimiterName(rightLW->currentItem()));
|
||||
|
||||
// Swap and match.
|
||||
char_type const lc = doMatch(rms.unicode);
|
||||
char_type const rc = doMatch(lms.unicode);
|
||||
|
||||
// Convert back to QString to locate them in the widget.
|
||||
MathSymbol const & nlms = mathSymbol(texName(lc));
|
||||
MathSymbol const & nrms = mathSymbol(texName(rc));
|
||||
QString lqs(nlms.fontcode ?
|
||||
QChar(nlms.fontcode) : toqstr(docstring(1, nlms.unicode)));
|
||||
QString rqs(nrms.fontcode ?
|
||||
QChar(nrms.fontcode) : toqstr(docstring(1, nrms.unicode)));
|
||||
|
||||
// Handle unencoded "symbol" of "(None)".
|
||||
if (lqs.toStdString() == "?")
|
||||
lqs = qt_("(None)");
|
||||
if(rqs.toStdString() == "?")
|
||||
rqs = qt_("(None)");
|
||||
|
||||
// Locate matching QListWidgetItem.
|
||||
QList<QListWidgetItem *> lwi = leftLW->findItems(lqs, Qt::MatchExactly);
|
||||
QList<QListWidgetItem *> rwi = rightLW->findItems(rqs, Qt::MatchExactly);
|
||||
|
||||
// Select.
|
||||
leftLW->setCurrentItem(lwi.first());
|
||||
rightLW->setCurrentItem(rwi.first());
|
||||
|
||||
updateTeXCode(sizeCO->currentIndex());
|
||||
}
|
||||
|
||||
|
||||
Dialog * createGuiDelimiter(GuiView & lv) { return new GuiDelimiter(lv); }
|
||||
|
||||
|
@ -40,6 +40,7 @@ public Q_SLOTS:
|
||||
void on_rightLW_currentRowChanged(int);
|
||||
void on_matchCB_stateChanged(int);
|
||||
void on_insertPB_clicked();
|
||||
void on_swapPB_clicked();
|
||||
void on_sizeCO_activated(int);
|
||||
|
||||
private:
|
||||
|
@ -1,7 +1,8 @@
|
||||
<ui version="4.0" >
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DelimiterUi</class>
|
||||
<widget class="QDialog" name="DelimiterUi" >
|
||||
<property name="geometry" >
|
||||
<widget class="QDialog" name="DelimiterUi">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
@ -9,206 +10,107 @@
|
||||
<height>352</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy>
|
||||
<hsizetype>5</hsizetype>
|
||||
<vsizetype>5</vsizetype>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize" >
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<height>330</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize" >
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<property name="windowTitle">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="sizeGripEnabled" >
|
||||
<property name="sizeGripEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout" >
|
||||
<item row="0" column="0" >
|
||||
<layout class="QGridLayout" >
|
||||
<property name="margin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0" >
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout">
|
||||
<item row="5" column="0">
|
||||
<layout class="QHBoxLayout">
|
||||
<item>
|
||||
<widget class="QListWidget" name="leftLW" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy>
|
||||
<hsizetype>5</hsizetype>
|
||||
<vsizetype>5</vsizetype>
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>50</width>
|
||||
<height>28</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="insertPB">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize" >
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
<property name="toolTip">
|
||||
<string>Insert the delimiters</string>
|
||||
</property>
|
||||
<property name="maximumSize" >
|
||||
<size>
|
||||
<width>140</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="iconSize" >
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="resizeMode" >
|
||||
<enum>QListView::Adjust</enum>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="currentRow" >
|
||||
<number>-1</number>
|
||||
<property name="text">
|
||||
<string>&Insert</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="rightLW" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy>
|
||||
<hsizetype>5</hsizetype>
|
||||
<vsizetype>5</vsizetype>
|
||||
<widget class="QPushButton" name="closePB">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize" >
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize" >
|
||||
<size>
|
||||
<width>139</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="iconSize" >
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="resizeMode" >
|
||||
<enum>QListView::Adjust</enum>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<number>2</number>
|
||||
<property name="text">
|
||||
<string>&Close</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QLabel" name="texCodeL" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy>
|
||||
<hsizetype>3</hsizetype>
|
||||
<vsizetype>0</vsizetype>
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>TeX Code: </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 row="2" column="0" >
|
||||
<widget class="QCheckBox" name="matchCB" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy>
|
||||
<hsizetype>3</hsizetype>
|
||||
<vsizetype>0</vsizetype>
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip" >
|
||||
<string>Match delimiter types</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>&Keep matched</string>
|
||||
</property>
|
||||
<property name="checked" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" >
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="4" column="0">
|
||||
<layout class="QHBoxLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy>
|
||||
<hsizetype>5</hsizetype>
|
||||
<vsizetype>0</vsizetype>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>&Size:</string>
|
||||
<property name="text">
|
||||
<string>Si&ze:</string>
|
||||
</property>
|
||||
<property name="alignment" >
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<property name="buddy">
|
||||
<cstring>sizeCO</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="sizeCO" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy>
|
||||
<hsizetype>5</hsizetype>
|
||||
<vsizetype>0</vsizetype>
|
||||
<widget class="QComboBox" name="sizeCO">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@ -217,10 +119,10 @@
|
||||
</item>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0" >
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
@ -230,60 +132,137 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" column="0" >
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="texCodeL">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="margin" >
|
||||
<number>0</number>
|
||||
<property name="text">
|
||||
<string>TeX Code: </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 row="0" column="0">
|
||||
<layout class="QHBoxLayout">
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType" >
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0" >
|
||||
<size>
|
||||
<width>50</width>
|
||||
<height>28</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="insertPB" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy>
|
||||
<hsizetype>5</hsizetype>
|
||||
<vsizetype>0</vsizetype>
|
||||
<widget class="QListWidget" name="leftLW">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip" >
|
||||
<string>Insert the delimiters</string>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>&Insert</string>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>140</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="resizeMode">
|
||||
<enum>QListView::Adjust</enum>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="currentRow">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="closePB" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy>
|
||||
<hsizetype>5</hsizetype>
|
||||
<vsizetype>0</vsizetype>
|
||||
<widget class="QListWidget" name="rightLW">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>&Close</string>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>139</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="resizeMode">
|
||||
<enum>QListView::Adjust</enum>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="matchCB">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Match delimiter types</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Keep matched</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="swapPB">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Swap left and right delimiter type (while reversing to the appropriate direction)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>S&wap && Reverse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -292,17 +271,15 @@
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>leftLW</zorder>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="9" />
|
||||
<layoutdefault spacing="6" margin="9"/>
|
||||
<tabstops>
|
||||
<tabstop>matchCB</tabstop>
|
||||
<tabstop>sizeCO</tabstop>
|
||||
<tabstop>insertPB</tabstop>
|
||||
<tabstop>closePB</tabstop>
|
||||
</tabstops>
|
||||
<includes>
|
||||
<include location="local" >qt_i18n.h</include>
|
||||
<include location="local">qt_i18n.h</include>
|
||||
</includes>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
Loading…
Reference in New Issue
Block a user