2 * \file QDelimiterDialog.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "QDelimiterDialog.h"
16 #include "qt_helpers.h"
17 #include "controllers/ControlMath.h"
23 #include <QListWidgetItem>
34 char const * const bigleft[] = {"bigl", "Bigl", "biggl", "Biggl", ""};
37 char const * const bigright[] = {"bigr", "Bigr", "biggr", "Biggr", ""};
40 char const * const biggui[] = {N_("big[[delimiter size]]"), N_("Big[[delimiter size]]"),
41 N_("bigg[[delimiter size]]"), N_("Bigg[[delimiter size]]"), ""};
44 string do_match(string const & str)
46 if (str == "(") return ")";
47 if (str == ")") return "(";
48 if (str == "[") return "]";
49 if (str == "]") return "[";
50 if (str == "{") return "}";
51 if (str == "}") return "{";
52 if (str == "l") return "r";
53 if (str == "rceil") return "lceil";
54 if (str == "lceil") return "rceil";
55 if (str == "rfloor") return "lfloor";
56 if (str == "lfloor") return "rfloor";
57 if (str == "rangle") return "langle";
58 if (str == "langle") return "rangle";
59 if (str == "\\") return "/";
60 if (str == "/") return "\\";
65 string fix_name(string const & str, bool big)
69 if (!big || str == "(" || str == ")" || str == "[" || str == "]"
70 || str == "|" || str == "/")
79 QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form)
84 connect(closePB, SIGNAL(clicked()), this, SLOT(accept()));
85 connect(insertPB, SIGNAL(clicked()), this, SLOT(insertClicked()));
87 setWindowTitle(qt_("LyX: Delimiters"));
88 setFocusProxy(leftLW);
90 // The last element is the empty one.
91 for (int i = 0; i < nr_latex_delimiters - 1; ++i) {
92 docstring const left_d(1,
93 form_->controller().mathSymbol(latex_delimiters[i]));
94 docstring const right_d(1,
95 form_->controller().mathSymbol(do_match(latex_delimiters[i])));
96 leftLW->addItem(toqstr(left_d));
97 rightLW->addItem(toqstr(right_d));
100 leftLW->addItem(qt_("(None)"));
101 rightLW->addItem(qt_("(None)"));
103 sizeCO->addItem(qt_("Variable"));
105 for (int i = 0; *biggui[i]; ++i)
106 sizeCO->addItem(qt_(biggui[i]));
108 on_leftLW_currentRowChanged(0);
112 void QDelimiterDialog::insertClicked()
116 if (leftLW->currentRow() < leftLW->count() - 1)
117 left_str = form_->controller().texName(qstring_to_ucs4(leftLW->currentItem()->text())[0]);
118 if (rightLW->currentRow() < rightLW->count() - 1)
119 right_str = form_->controller().texName(qstring_to_ucs4(rightLW->currentItem()->text())[0]);
121 int const size_ = sizeCO->currentIndex();
123 form_->controller().dispatchDelim(
124 fix_name(left_str, false) + ' ' +
125 fix_name(right_str, false));
127 std::ostringstream os;
128 os << '"' << bigleft[size_ - 1] << "\" \""
129 << fix_name(left_str, true) << "\" \""
130 << bigright[size_ - 1] << "\" \""
131 << fix_name(right_str, true) << '"';
132 form_->controller().dispatchBigDelim(os.str());
137 void QDelimiterDialog::on_leftLW_itemActivated(QListWidgetItem *)
144 void QDelimiterDialog::on_rightLW_itemActivated(QListWidgetItem *)
151 void QDelimiterDialog::on_leftLW_currentRowChanged(int item)
153 if (matchCB->isChecked())
154 rightLW->setCurrentRow(item);
156 // Display the associated TeX name.
157 if (leftLW->currentRow() == leftLW->count() - 1)
160 QString const str = toqstr(form_->controller().texName(
161 qstring_to_ucs4(leftLW->currentItem()->text())[0]));
162 texCodeL->setText("TeX code: \\" + str);
167 void QDelimiterDialog::on_rightLW_currentRowChanged(int item)
169 if (matchCB->isChecked())
170 leftLW->setCurrentRow(item);
172 // Display the associated TeX name.
173 if (rightLW->currentRow() == leftLW->count() - 1)
176 QString const str = toqstr(form_->controller().texName(
177 qstring_to_ucs4(rightLW->currentItem()->text())[0]));
178 texCodeL->setText("TeX code: \\" + str);
183 void QDelimiterDialog::on_matchCB_stateChanged(int state)
185 if (state == Qt::Checked)
186 on_leftLW_currentRowChanged(leftLW->currentRow());
190 } // namespace frontend
193 #include "QDelimiterDialog_moc.cpp"