]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QDelimiterDialog.C
rename LFUN enum values according to their command (as used in th minibuffer/bind...
[lyx.git] / src / frontends / qt4 / QDelimiterDialog.C
1 /**
2  * \file QDelimiterDialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "QDelimiterDialog.h"
14
15 #include "iconpalette.h"
16 #include "QMath.h"
17 #include "qt_helpers.h"
18
19 #include "controllers/ControlMath.h"
20
21 #include <qlabel.h>
22 #include <qpixmap.h>
23 #include <qcheckbox.h>
24
25
26 using std::string;
27
28 namespace lyx {
29 namespace frontend {
30
31 namespace {
32
33 char const * delim[] = {
34         "(", ")", "{", "}", "[", "]",
35         "lceil", "rceil", "lfloor", "rfloor", "langle", "rangle",
36         "uparrow", "Uparrow", "downarrow", "Downarrow",
37         "|", "Vert", "slash", "backslash", ""
38 };
39
40
41 string do_match(const string & str)
42 {
43         if (str == "(") return ")";
44         if (str == ")") return "(";
45         if (str == "[") return "]";
46         if (str == "]") return "[";
47         if (str == "{") return "}";
48         if (str == "}") return "{";
49         if (str == "l") return "r";
50         if (str == "rceil") return "lceil";
51         if (str == "lceil") return "rceil";
52         if (str == "rfloor") return "lfloor";
53         if (str == "lfloor") return "rfloor";
54         if (str == "rangle") return "langle";
55         if (str == "langle") return "rangle";
56         if (str == "backslash") return "slash";
57         if (str == "slash") return "backslash";
58         return str;
59 }
60
61
62 string fix_name(const string & str)
63 {
64         if (str == "slash")
65                 return "/";
66         if (str == "backslash")
67                 return "\\";
68         if (str == "empty")
69                 return ".";
70         return str;
71 }
72
73 } // namespace anon
74
75
76 QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form)
77         : form_(form)
78 {
79         setupUi(this);
80
81     connect( closePB, SIGNAL( clicked() ), this, SLOT( accept() ) );
82     connect( insertPB, SIGNAL( clicked() ), this, SLOT( insertClicked() ) );
83
84         setCaption(qt_("LyX: Delimiters"));
85
86         for (int i = 0; *delim[i]; ++i) {
87                 string xpm(find_xpm(delim[i]));
88                 leftIP->add(QPixmap(toqstr(xpm)), delim[i], delim[i]);
89                 rightIP->add(QPixmap(toqstr(xpm)), delim[i], delim[i]);
90         }
91
92         string empty_xpm(find_xpm("empty"));
93
94         leftIP->add(QPixmap(toqstr(empty_xpm)), "empty", "empty");
95         rightIP->add(QPixmap(toqstr(empty_xpm)), "empty", "empty");
96         // Leave these std:: qualifications alone !
97         connect(leftIP, SIGNAL(button_clicked(const std::string &)),
98                 this, SLOT(ldelim_clicked(const std::string &)));
99         connect(rightIP, SIGNAL(button_clicked(const std::string &)),
100                 this, SLOT(rdelim_clicked(const std::string &)));
101         ldelim_clicked("(");
102         rdelim_clicked(")");
103 }
104
105
106 void QDelimiterDialog::insertClicked()
107 {
108         form_->controller().dispatchDelim(fix_name(left_) + ' ' + fix_name(right_));
109 }
110
111
112 void QDelimiterDialog::set_label(QLabel * label, const string & str)
113 {
114         label->setUpdatesEnabled(false);
115         label->setPixmap(QPixmap(toqstr(find_xpm(str))));
116         label->setUpdatesEnabled(true);
117         label->update();
118 }
119
120
121 void QDelimiterDialog::ldelim_clicked(const string & str)
122 {
123         left_ = str;
124
125         set_label(leftPI, left_);
126         if (matchCB->isChecked()) {
127                 right_ = do_match(left_);
128                 set_label(rightPI, right_);
129         }
130 }
131
132
133 void QDelimiterDialog::rdelim_clicked(const string & str)
134 {
135         right_ = str;
136
137         set_label(rightPI, right_);
138         if (matchCB->isChecked()) {
139                 left_ = do_match(right_);
140                 set_label(leftPI, left_);
141         }
142 }
143
144 } // namespace frontend
145 } // namespace lyx