]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDelimiter.cpp
do what the FIXME suggested
[lyx.git] / src / frontends / qt4 / GuiDelimiter.cpp
index e93682b81f75c13c4e4c2fff7196334fb4a1eb68..b164316a2eccc280373b31a5732037a418ddb2f3 100644 (file)
 #include "GuiView.h"
 
 #include "qt_helpers.h"
-#include "gettext.h"
+#include "support/gettext.h"
 
 #include <QPixmap>
 #include <QCheckBox>
 #include <QListWidgetItem>
 
-// Set to zero if unicode symbols are preferred.
-#define USE_PIXMAP 1
+using namespace std;
 
-using std::string;
+static char const *  latex_delimiters[] = {
+       "(", ")", "{", "}", "[", "]",
+       "lceil", "rceil", "lfloor", "rfloor", "langle", "rangle",
+       "uparrow", "updownarrow", "Uparrow", "Updownarrow", "downarrow", "Downarrow",
+       "|", "Vert", "/", "backslash", ""
+};
 
-namespace lyx {
-namespace frontend {
-
-namespace {
-
-QString const bigleft[]  = {"", "bigl", "Bigl", "biggl", "Biggl"};
 
+static int const nr_latex_delimiters =
+       sizeof(latex_delimiters) / sizeof(char const *);
 
-QString const bigright[] = {"", "bigr", "Bigr", "biggr", "Biggr"};
+static QString const bigleft[]  = {"", "bigl", "Bigl", "biggl", "Biggl"};
 
+static QString const bigright[] = {"", "bigr", "Bigr", "biggr", "Biggr"};
 
-char const * const biggui[]   = {N_("big[[delimiter size]]"), N_("Big[[delimiter size]]"),
-       N_("bigg[[delimiter size]]"), N_("Bigg[[delimiter size]]"), ""};
+static char const * const biggui[] = {
+       N_("big[[delimiter size]]"),
+       N_("Big[[delimiter size]]"),
+       N_("bigg[[delimiter size]]"),
+       N_("Bigg[[delimiter size]]"),
+       ""
+};
 
 
 // FIXME: It might be better to fix the big delim LFUN to not require
 // additional '\' prefix.
-QString fix_name(QString const & str, bool big)
+static QString fix_name(QString const & str, bool big)
 {
        if (str.isEmpty())
                return ".";
@@ -55,71 +61,35 @@ QString fix_name(QString const & str, bool big)
        return "\\" + str;
 }
 
-} // namespace anon
 
-
-GuiDelimiter::GuiDelimiter(GuiDialog & parent)
-       : GuiView<GuiDelimiterDialog>(parent, _("Math Delimiter"))
-{}
-
-
-void GuiDelimiter::build_dialog()
-{
-       dialog_.reset(new GuiDelimiterDialog(this,
-               static_cast<GuiViewBase *>(controller().view())));
-}
-
-
-char_type GuiDelimiterDialog::doMatch(char_type const symbol) const
-{
-       string const & str = form_->controller().texName(symbol);
-       string match;
-       if (str == "(") match = ")";
-       else if (str == ")") match = "(";
-       else if (str == "[") match = "]";
-       else if (str == "]") match = "[";
-       else if (str == "{") match = "}";
-       else if (str == "}") match = "{";
-       else if (str == "l") match = "r";
-       else if (str == "rceil") match = "lceil";
-       else if (str == "lceil") match = "rceil";
-       else if (str == "rfloor") match = "lfloor";
-       else if (str == "lfloor") match = "rfloor";
-       else if (str == "rangle") match = "langle";
-       else if (str == "langle") match = "rangle";
-       else if (str == "backslash") match = "/";
-       else if (str == "/") match = "backslash";
-       else return symbol;
-
-       return form_->controller().mathSymbol(match).unicode;
-}
+namespace lyx {
+namespace frontend {
 
 
-GuiDelimiterDialog::GuiDelimiterDialog(GuiDelimiter * form, QWidget * parent)
-       : QDialog(parent), form_(form)
+GuiDelimiter::GuiDelimiter(GuiView & lv)
+       : GuiMath(lv, "mathdelimiter", qt_("Math Delimiter"))
 {
        setupUi(this);
 
        connect(closePB, SIGNAL(clicked()), this, SLOT(accept()));
 
-       setWindowTitle(qt_("LyX: Delimiters"));
        setFocusProxy(leftLW);
 
        leftLW->setViewMode(QListView::IconMode);
        rightLW->setViewMode(QListView::IconMode);
 
-       typedef std::map<char_type, QListWidgetItem *> ListItems;
+       typedef map<char_type, QListWidgetItem *> ListItems;
        ListItems list_items;
        // The last element is the empty one.
        int const end = nr_latex_delimiters - 1;
        for (int i = 0; i < end; ++i) {
                string const delim = latex_delimiters[i];
-               MathSymbol const & ms = form_->controller().mathSymbol(delim);
+               MathSymbol const & ms = mathSymbol(delim);
                QString symbol(ms.fontcode?
                        QChar(ms.fontcode) : toqstr(docstring(1, ms.unicode)));
                QListWidgetItem * lwi = new QListWidgetItem(symbol);
                lwi->setToolTip(toqstr(delim));
-               Font lyxfont;
+               FontInfo lyxfont;
                lyxfont.setFamily(ms.fontfamily);
                QFont const & symbol_font = guiApp->guiFontLoader().get(lyxfont);
                lwi->setFont(symbol_font);
@@ -128,7 +98,7 @@ GuiDelimiterDialog::GuiDelimiterDialog(GuiDelimiter * form, QWidget * parent)
        }
 
        for (int i = 0; i != leftLW->count(); ++i) {
-               MathSymbol const & ms = form_->controller().mathSymbol(
+               MathSymbol const & ms = mathSymbol(
                        fromqstr(leftLW->item(i)->toolTip()));
                rightLW->addItem(list_items[doMatch(ms.unicode)]->clone());
        }
@@ -143,10 +113,36 @@ GuiDelimiterDialog::GuiDelimiterDialog(GuiDelimiter * form, QWidget * parent)
                sizeCO->addItem(qt_(biggui[i]));
 
        on_leftLW_currentRowChanged(0);
+       bc().setPolicy(ButtonPolicy::IgnorantPolicy);
+}
+
+
+char_type GuiDelimiter::doMatch(char_type const symbol)
+{
+       string const & str = texName(symbol);
+       string match;
+       if (str == "(") match = ")";
+       else if (str == ")") match = "(";
+       else if (str == "[") match = "]";
+       else if (str == "]") match = "[";
+       else if (str == "{") match = "}";
+       else if (str == "}") match = "{";
+       else if (str == "l") match = "r";
+       else if (str == "rceil") match = "lceil";
+       else if (str == "lceil") match = "rceil";
+       else if (str == "rfloor") match = "lfloor";
+       else if (str == "lfloor") match = "rfloor";
+       else if (str == "rangle") match = "langle";
+       else if (str == "langle") match = "rangle";
+       else if (str == "backslash") match = "/";
+       else if (str == "/") match = "backslash";
+       else return symbol;
+
+       return mathSymbol(match).unicode;
 }
 
 
-void GuiDelimiterDialog::updateTeXCode(int size)
+void GuiDelimiter::updateTeXCode(int size)
 {
        bool const bigsize = size != 0;
 
@@ -184,39 +180,39 @@ void GuiDelimiterDialog::updateTeXCode(int size)
 }
 
 
-void GuiDelimiterDialog::on_insertPB_clicked()
+void GuiDelimiter::on_insertPB_clicked()
 {
        if (sizeCO->currentIndex() == 0)
-               form_->controller().dispatchDelim(fromqstr(tex_code_));
+               dispatchDelim(fromqstr(tex_code_));
        else {
                QString command = '"' + tex_code_ + '"';
                command.replace(' ', "\" \"");
-               form_->controller().dispatchBigDelim(fromqstr(command));
+               dispatchBigDelim(fromqstr(command));
        }
  }
 
 
-void GuiDelimiterDialog::on_sizeCO_activated(int index)
+void GuiDelimiter::on_sizeCO_activated(int index)
 {
        updateTeXCode(index);
 }
 
 
-void GuiDelimiterDialog::on_leftLW_itemActivated(QListWidgetItem *)
+void GuiDelimiter::on_leftLW_itemActivated(QListWidgetItem *)
 {
        on_insertPB_clicked();
        accept();
 }
 
 
-void GuiDelimiterDialog::on_rightLW_itemActivated(QListWidgetItem *)
+void GuiDelimiter::on_rightLW_itemActivated(QListWidgetItem *)
 {
        on_insertPB_clicked();
        accept();
 }
 
 
-void GuiDelimiterDialog::on_leftLW_currentRowChanged(int item)
+void GuiDelimiter::on_leftLW_currentRowChanged(int item)
 {
        if (matchCB->isChecked())
                rightLW->setCurrentRow(item);
@@ -225,7 +221,7 @@ void GuiDelimiterDialog::on_leftLW_currentRowChanged(int item)
 }
 
 
-void GuiDelimiterDialog::on_rightLW_currentRowChanged(int item)
+void GuiDelimiter::on_rightLW_currentRowChanged(int item)
 {
        if (matchCB->isChecked())
                leftLW->setCurrentRow(item);
@@ -234,7 +230,7 @@ void GuiDelimiterDialog::on_rightLW_currentRowChanged(int item)
 }
 
 
-void GuiDelimiterDialog::on_matchCB_stateChanged(int state)
+void GuiDelimiter::on_matchCB_stateChanged(int state)
 {
        if (state == Qt::Checked)
                on_leftLW_currentRowChanged(leftLW->currentRow());
@@ -243,6 +239,9 @@ void GuiDelimiterDialog::on_matchCB_stateChanged(int state)
 }
 
 
+Dialog * createGuiDelimiter(GuiView & lv) { return new GuiDelimiter(lv); }
+
+
 } // namespace frontend
 } // namespace lyx