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