From c49cd699986175a5a76490e2109332ce8919eb59 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Wed, 28 Dec 2016 16:34:44 +0100 Subject: [PATCH] From c7899a30a0b5975bf599a69ecd11ab25e1cdf1a4 Mon Sep 17 00:00:00 2001 From: "Joel A. Kulesza" 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 | 47 +++- src/frontends/qt4/GuiDelimiter.h | 1 + src/frontends/qt4/ui/DelimiterUi.ui | 371 +++++++++++++--------------- 3 files changed, 220 insertions(+), 199 deletions(-) diff --git a/src/frontends/qt4/GuiDelimiter.cpp b/src/frontends/qt4/GuiDelimiter.cpp index 18937d017a..104cb761bd 100644 --- a/src/frontends/qt4/GuiDelimiter.cpp +++ b/src/frontends/qt4/GuiDelimiter.cpp @@ -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 lwi = leftLW->findItems(lqs, Qt::MatchExactly); + QList 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); } diff --git a/src/frontends/qt4/GuiDelimiter.h b/src/frontends/qt4/GuiDelimiter.h index 655d805efb..7bd6ee610b 100644 --- a/src/frontends/qt4/GuiDelimiter.h +++ b/src/frontends/qt4/GuiDelimiter.h @@ -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: diff --git a/src/frontends/qt4/ui/DelimiterUi.ui b/src/frontends/qt4/ui/DelimiterUi.ui index 21c6ad1299..96cdc4968c 100644 --- a/src/frontends/qt4/ui/DelimiterUi.ui +++ b/src/frontends/qt4/ui/DelimiterUi.ui @@ -1,7 +1,8 @@ - + + DelimiterUi - - + + 0 0 @@ -9,206 +10,107 @@ 352 - - - 5 - 5 + + 0 0 - + 300 330 - + 16777215 16777215 - + - + true - - - - - 0 - - - 6 - - - - - 6 - - - 0 - + + + + + - - - - 5 - 5 + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 50 + 28 + + + + + + + + 0 0 - - - 60 - 0 - + + Insert the delimiters - - - 140 - 16777215 - - - - - 16 - 16 - - - - QListView::Adjust - - - 2 - - - -1 + + &Insert - - - - 5 - 5 + + + 0 0 - - - 60 - 0 - - - - - 139 - 16777215 - - - - - 16 - 16 - - - - QListView::Adjust - - - 2 + + &Close - - - - - 3 - 0 - 0 - 0 - - - - TeX Code: - - - Qt::AutoText - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - false - - - - - - - - 3 - 0 - 0 - 0 - - - - Match delimiter types - - - &Keep matched - - - true - - - - - - - 6 - - - 0 - + + - - - - 5 - 0 + + + 0 0 - - &Size: + + Si&ze: - + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + sizeCO - - - - 5 - 0 + + + 0 0 @@ -217,10 +119,10 @@ - + Qt::Horizontal - + 40 20 @@ -230,60 +132,137 @@ - - - - 6 + + + + + 0 + 0 + - - 0 + + TeX Code: + + Qt::AutoText + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + + + - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 50 - 28 - - - - - - - - - 5 - 0 + + + 0 0 - - Insert the delimiters + + + 60 + 0 + - - &Insert + + + 140 + 16777215 + + + + + 16 + 16 + + + + QListView::Adjust + + + 2 + + + -1 - - - - 5 - 0 + + + 0 0 - - &Close + + + 60 + 0 + + + + + 139 + 16777215 + + + + + 16 + 16 + + + + QListView::Adjust + + + 2 + + + + + + + + + + + + 0 + 0 + + + + Match delimiter types + + + &Keep matched + + + true + + + + + + + + 0 + 0 + + + + Swap left and right delimiter type (while reversing to the appropriate direction) + + + S&wap && Reverse @@ -292,17 +271,15 @@ - leftLW - + - matchCB sizeCO insertPB closePB - qt_i18n.h + qt_i18n.h