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:
Juergen Spitzmueller 2016-12-28 16:34:44 +01:00
parent 2a4538ad56
commit 5de448e132
3 changed files with 220 additions and 199 deletions

View File

@ -207,7 +207,7 @@ GuiDelimiter::GuiDelimiter(GuiView & lv)
int const end = nr_latex_delimiters - 1; int const end = nr_latex_delimiters - 1;
for (int i = 0; i < end; ++i) { for (int i = 0; i < end; ++i) {
string const delim = latex_delimiters[i]; string const delim = latex_delimiters[i];
MathSymbol const & ms = mathSymbol(delim); MathSymbol const & ms = mathSymbol(delim);
QString symbol(ms.fontcode? QString symbol(ms.fontcode?
QChar(ms.fontcode) : toqstr(docstring(1, ms.unicode))); QChar(ms.fontcode) : toqstr(docstring(1, ms.unicode)));
QListWidgetItem * lwi = new QListWidgetItem(symbol); QListWidgetItem * lwi = new QListWidgetItem(symbol);
@ -232,7 +232,7 @@ GuiDelimiter::GuiDelimiter(GuiView & lv)
} }
for (int i = 0; i != leftLW->count(); ++i) { 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()); 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)); 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()); 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); } Dialog * createGuiDelimiter(GuiView & lv) { return new GuiDelimiter(lv); }

View File

@ -40,6 +40,7 @@ public Q_SLOTS:
void on_rightLW_currentRowChanged(int); void on_rightLW_currentRowChanged(int);
void on_matchCB_stateChanged(int); void on_matchCB_stateChanged(int);
void on_insertPB_clicked(); void on_insertPB_clicked();
void on_swapPB_clicked();
void on_sizeCO_activated(int); void on_sizeCO_activated(int);
private: private:

View File

@ -1,7 +1,8 @@
<ui version="4.0" > <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DelimiterUi</class> <class>DelimiterUi</class>
<widget class="QDialog" name="DelimiterUi" > <widget class="QDialog" name="DelimiterUi">
<property name="geometry" > <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
@ -9,206 +10,107 @@
<height>352</height> <height>352</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy" > <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<hsizetype>5</hsizetype>
<vsizetype>5</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize" > <property name="minimumSize">
<size> <size>
<width>300</width> <width>300</width>
<height>330</height> <height>330</height>
</size> </size>
</property> </property>
<property name="maximumSize" > <property name="maximumSize">
<size> <size>
<width>16777215</width> <width>16777215</width>
<height>16777215</height> <height>16777215</height>
</size> </size>
</property> </property>
<property name="windowTitle" > <property name="windowTitle">
<string/> <string/>
</property> </property>
<property name="sizeGripEnabled" > <property name="sizeGripEnabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QGridLayout" name="gridLayout" > <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" > <item row="0" column="0">
<layout class="QGridLayout" > <layout class="QGridLayout">
<property name="margin" > <item row="5" column="0">
<number>0</number> <layout class="QHBoxLayout">
</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>
<item> <item>
<widget class="QListWidget" name="leftLW" > <spacer>
<property name="sizePolicy" > <property name="orientation">
<sizepolicy> <enum>Qt::Horizontal</enum>
<hsizetype>5</hsizetype> </property>
<vsizetype>5</vsizetype> <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> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize" > <property name="toolTip">
<size> <string>Insert the delimiters</string>
<width>60</width>
<height>0</height>
</size>
</property> </property>
<property name="maximumSize" > <property name="text">
<size> <string>&amp;Insert</string>
<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> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QListWidget" name="rightLW" > <widget class="QPushButton" name="closePB">
<property name="sizePolicy" > <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<hsizetype>5</hsizetype>
<vsizetype>5</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize" > <property name="text">
<size> <string>&amp;Close</string>
<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> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
<item row="1" column="0" > <item row="4" column="0">
<widget class="QLabel" name="texCodeL" > <layout class="QHBoxLayout">
<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>&amp;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> <item>
<widget class="QLabel" name="label" > <widget class="QLabel" name="label">
<property name="sizePolicy" > <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<hsizetype>5</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text" > <property name="text">
<string>&amp;Size:</string> <string>Si&amp;ze:</string>
</property> </property>
<property name="alignment" > <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
<property name="buddy" > <property name="buddy">
<cstring>sizeCO</cstring> <cstring>sizeCO</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="sizeCO" > <widget class="QComboBox" name="sizeCO">
<property name="sizePolicy" > <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<hsizetype>5</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -217,10 +119,10 @@
</item> </item>
<item> <item>
<spacer> <spacer>
<property name="orientation" > <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0" > <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -230,60 +132,137 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="4" column="0" > <item row="1" column="0">
<layout class="QHBoxLayout" > <widget class="QLabel" name="texCodeL">
<property name="spacing" > <property name="sizePolicy">
<number>6</number> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="margin" > <property name="text">
<number>0</number> <string>TeX Code: </string>
</property> </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> <item>
<spacer> <widget class="QListWidget" name="leftLW">
<property name="orientation" > <property name="sizePolicy">
<enum>Qt::Horizontal</enum> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
</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>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolTip" > <property name="minimumSize">
<string>Insert the delimiters</string> <size>
<width>60</width>
<height>0</height>
</size>
</property> </property>
<property name="text" > <property name="maximumSize">
<string>&amp;Insert</string> <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> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="closePB" > <widget class="QListWidget" name="rightLW">
<property name="sizePolicy" > <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<hsizetype>5</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text" > <property name="minimumSize">
<string>&amp;Close</string> <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>&amp;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&amp;wap &amp;&amp; Reverse</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -292,17 +271,15 @@
</layout> </layout>
</item> </item>
</layout> </layout>
<zorder>leftLW</zorder>
</widget> </widget>
<layoutdefault spacing="6" margin="9" /> <layoutdefault spacing="6" margin="9"/>
<tabstops> <tabstops>
<tabstop>matchCB</tabstop>
<tabstop>sizeCO</tabstop> <tabstop>sizeCO</tabstop>
<tabstop>insertPB</tabstop> <tabstop>insertPB</tabstop>
<tabstop>closePB</tabstop> <tabstop>closePB</tabstop>
</tabstops> </tabstops>
<includes> <includes>
<include location="local" >qt_i18n.h</include> <include location="local">qt_i18n.h</include>
</includes> </includes>
<resources/> <resources/>
<connections/> <connections/>