]> git.lyx.org Git - features.git/blob - src/frontends/qt3/QDelimiterDialog.C
* Rename src/frontends/qt2 to src/frontends/qt3,
[features.git] / src / frontends / qt3 / 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         : QDelimiterDialogBase(0, 0, false, 0),
78         form_(form)
79 {
80         setCaption(qt_("LyX: Delimiters"));
81
82         for (int i = 0; *delim[i]; ++i) {
83                 string xpm(find_xpm(delim[i]));
84                 leftIP->add(QPixmap(toqstr(xpm)), delim[i], delim[i]);
85                 rightIP->add(QPixmap(toqstr(xpm)), delim[i], delim[i]);
86         }
87
88         string empty_xpm(find_xpm("empty"));
89
90         leftIP->add(QPixmap(toqstr(empty_xpm)), "empty", "empty");
91         rightIP->add(QPixmap(toqstr(empty_xpm)), "empty", "empty");
92         // Leave these std:: qualifications alone !
93         connect(leftIP, SIGNAL(button_clicked(const std::string &)),
94                 this, SLOT(ldelim_clicked(const std::string &)));
95         connect(rightIP, SIGNAL(button_clicked(const std::string &)),
96                 this, SLOT(rdelim_clicked(const std::string &)));
97         ldelim_clicked("(");
98         rdelim_clicked(")");
99 }
100
101
102 void QDelimiterDialog::insertClicked()
103 {
104         form_->controller().dispatchDelim(fix_name(left_) + ' ' + fix_name(right_));
105 }
106
107
108 void QDelimiterDialog::set_label(QLabel * label, const string & str)
109 {
110         label->setUpdatesEnabled(false);
111         label->setPixmap(QPixmap(toqstr(find_xpm(str))));
112         label->setUpdatesEnabled(true);
113         label->update();
114 }
115
116
117 void QDelimiterDialog::ldelim_clicked(const string & str)
118 {
119         left_ = str;
120
121         set_label(leftPI, left_);
122         if (matchCB->isChecked()) {
123                 right_ = do_match(left_);
124                 set_label(rightPI, right_);
125         }
126 }
127
128
129 void QDelimiterDialog::rdelim_clicked(const string & str)
130 {
131         right_ = str;
132
133         set_label(rightPI, right_);
134         if (matchCB->isChecked()) {
135                 left_ = do_match(right_);
136                 set_label(leftPI, left_);
137         }
138 }
139
140 } // namespace frontend
141 } // namespace lyx