]> git.lyx.org Git - lyx.git/commitdiff
From c7899a30a0b5975bf599a69ecd11ab25e1cdf1a4 Mon Sep 17 00:00:00 2001
authorJuergen Spitzmueller <spitz@lyx.org>
Wed, 28 Dec 2016 15:34:44 +0000 (16:34 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Wed, 28 Dec 2016 15:34:44 +0000 (16:34 +0100)
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

src/frontends/qt4/GuiDelimiter.cpp
src/frontends/qt4/GuiDelimiter.h
src/frontends/qt4/ui/DelimiterUi.ui

index 18937d017ace7723112a73bc6b1d1bd3e8365309..104cb761bd62a9f833ea5ff26eee991c926eff62 100644 (file)
@@ -211,7 +211,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);
@@ -236,7 +236,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());
        }
 
@@ -324,6 +324,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);
 }
 
 
@@ -405,6 +411,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); }
 
index 655d805efb4f5e5c7dba28caa88b35d8e07cbb4a..7bd6ee610be5775e1dfde3f62ed8d36c85e17fcd 100644 (file)
@@ -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:
index 21c6ad1299e5d8c6dfad4d02a4e17e97d8bf03a6..96cdc4968ca65824210a93ff6827177f3d62b023 100644 (file)
@@ -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>
     <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>
-           <horstretch>0</horstretch>
-           <verstretch>0</verstretch>
-          </sizepolicy>
-         </property>
-         <property name="minimumSize" >
-          <size>
-           <width>60</width>
-           <height>0</height>
-          </size>
+        <spacer>
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
          </property>
-         <property name="maximumSize" >
-          <size>
-           <width>140</width>
-           <height>16777215</height>
-          </size>
+         <property name="sizeType">
+          <enum>QSizePolicy::Expanding</enum>
          </property>
-         <property name="iconSize" >
+         <property name="sizeHint" stdset="0">
           <size>
-           <width>16</width>
-           <height>16</height>
+           <width>50</width>
+           <height>28</height>
           </size>
          </property>
-         <property name="resizeMode" >
-          <enum>QListView::Adjust</enum>
+        </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="spacing" >
-          <number>2</number>
+         <property name="toolTip">
+          <string>Insert the delimiters</string>
          </property>
-         <property name="currentRow" >
-          <number>-1</number>
+         <property name="text">
+          <string>&amp;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>&amp;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>&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 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>&amp;Size:</string>
+         <property name="text">
+          <string>Si&amp;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>
        </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>
        </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>
+        <widget class="QListWidget" name="leftLW">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
          </property>
-         <property name="sizeType" >
-          <enum>QSizePolicy::Expanding</enum>
+         <property name="minimumSize">
+          <size>
+           <width>60</width>
+           <height>0</height>
+          </size>
          </property>
-         <property name="sizeHint" stdset="0" >
+         <property name="maximumSize">
           <size>
-           <width>50</width>
-           <height>28</height>
+           <width>140</width>
+           <height>16777215</height>
           </size>
          </property>
-        </spacer>
+         <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="insertPB" >
-         <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="toolTip" >
-          <string>Insert the delimiters</string>
+         <property name="minimumSize">
+          <size>
+           <width>60</width>
+           <height>0</height>
+          </size>
          </property>
-         <property name="text" >
-          <string>&amp;Insert</string>
+         <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="QPushButton" name="closePB" >
-         <property name="sizePolicy" >
-          <sizepolicy>
-           <hsizetype>5</hsizetype>
-           <vsizetype>0</vsizetype>
+        <widget class="QCheckBox" name="matchCB">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
            <horstretch>0</horstretch>
            <verstretch>0</verstretch>
           </sizepolicy>
          </property>
-         <property name="text" >
-          <string>&amp;Close</string>
+         <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>
         </widget>
        </item>
     </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/>