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"
34 char const * delim[] = {
35 "(", ")", "{", "}", "[", "]",
36 "lceil", "rceil", "lfloor", "rfloor", "langle", "rangle",
37 "uparrow", "Uparrow", "downarrow", "Downarrow",
38 "|", "Vert", "slash", "backslash", ""
42 char const * const bigleft[] = {"bigl", "Bigl", "biggl", "Biggl", ""};
45 char const * const bigright[] = {"bigr", "Bigr", "biggr", "Biggr", ""};
48 char const * const biggui[] = {N_("big[[delimiter size]]"), N_("Big[[delimiter size]]"),
49 N_("bigg[[delimiter size]]"), N_("Bigg[[delimiter size]]"), ""};
52 string do_match(const string & str)
54 if (str == "(") return ")";
55 if (str == ")") return "(";
56 if (str == "[") return "]";
57 if (str == "]") return "[";
58 if (str == "{") return "}";
59 if (str == "}") return "{";
60 if (str == "l") return "r";
61 if (str == "rceil") return "lceil";
62 if (str == "lceil") return "rceil";
63 if (str == "rfloor") return "lfloor";
64 if (str == "lfloor") return "rfloor";
65 if (str == "rangle") return "langle";
66 if (str == "langle") return "rangle";
67 if (str == "backslash") return "slash";
68 if (str == "slash") return "backslash";
73 string fix_name(const string & str, bool big)
77 if (str == "backslash")
81 if (!big || str == "(" || str == ")" || str == "[" || str == "]")
90 QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form)
95 connect(closePB, SIGNAL(clicked()), this, SLOT(accept()));
96 connect(insertPB, SIGNAL(clicked()), this, SLOT(insertClicked()));
98 setWindowTitle(qt_("LyX: Delimiters"));
100 for (int i = 0; *delim[i]; ++i) {
101 QPixmap pm = QPixmap(toqstr(find_xpm(delim[i])));
102 leftCO->addItem(QIcon(pm), "");
103 rightCO->addItem(QIcon(pm), "");
106 string empty_xpm(find_xpm("empty"));
107 leftCO->addItem(QIcon(QPixmap(toqstr(empty_xpm))), qt_("(None)"));
108 rightCO->addItem(QIcon(QPixmap(toqstr(empty_xpm))), qt_("(None)"));
110 sizeCO->addItem(qt_("Variable size"));
112 for (int i = 0; *biggui[i]; ++i)
113 sizeCO->addItem(qt_(biggui[i]));
115 on_leftCO_activated(0);
119 void QDelimiterDialog::insertClicked()
121 string const left_ = delim[leftCO->currentIndex()];
122 string const right_ = delim[rightCO->currentIndex()];
123 int const size_ = sizeCO->currentIndex();
126 form_->controller().dispatchDelim(
127 fix_name(left_, false) + ' ' +
128 fix_name(right_, false));
130 std::ostringstream os;
131 os << '"' << bigleft[size_ - 1] << "\" \""
132 << fix_name(left_, true) << "\" \""
133 << bigright[size_ - 1] << "\" \""
134 << fix_name(right_, true) << '"';
135 form_->controller().dispatchBigDelim(os.str());
141 void QDelimiterDialog::on_leftCO_activated(int item)
143 if (matchCB->isChecked()) {
144 string const match = do_match(delim[item]);
146 while (delim[k] && delim[k] != match)
148 rightCO->setCurrentIndex(k);
153 void QDelimiterDialog::on_rightCO_activated(int item)
155 if (matchCB->isChecked()) {
156 string const match = do_match(delim[item]);
158 while (delim[k] && delim[k] != match)
160 leftCO->setCurrentIndex(k);
165 void QDelimiterDialog::on_matchCB_stateChanged(int state)
167 if (state == Qt::Checked)
168 on_leftCO_activated(leftCO->currentIndex());
172 } // namespace frontend
175 #include "QDelimiterDialog_moc.cpp"