]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QDelimiterDialog.C
remove qPixmapFromMimeSource. This caused the inclusion of Qt3 support headers which...
[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 #include "QMath.h"
15
16 #include "qt_helpers.h"
17 #include "controllers/ControlMath.h"
18
19 #include "gettext.h"
20
21 #include <QPixmap>
22 #include <QCheckBox>
23
24
25 #include <sstream>
26
27 using std::string;
28
29 namespace lyx {
30 namespace frontend {
31
32 namespace {
33
34 char const * delim[] = {
35         "(", ")", "{", "}", "[", "]",
36         "lceil", "rceil", "lfloor", "rfloor", "langle", "rangle",
37         "uparrow", "Uparrow", "downarrow", "Downarrow",
38         "|", "Vert", "slash", "backslash", ""
39 };
40
41
42 char const * const bigleft[]  = {"bigl", "Bigl", "biggl", "Biggl", ""};
43
44
45 char const * const bigright[] = {"bigr", "Bigr", "biggr", "Biggr", ""};
46
47
48 char const * const biggui[]   = {N_("big size"), N_("Big size"),
49         N_("bigg size"), N_("Bigg size"), ""};
50
51
52 string do_match(const string & str)
53 {
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";
69         return str;
70 }
71
72
73 string fix_name(const string & str, bool big)
74 {
75         if (str == "slash")
76                 return "/";
77         if (str == "backslash")
78                 return "\\";
79         if (str == "empty")
80                 return ".";
81         if (!big || str == "(" || str == ")" || str == "[" || str == "]")
82                 return str;
83
84         return "\\" + str;
85 }
86
87 } // namespace anon
88
89
90 QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form)
91         : form_(form)
92 {
93         setupUi(this);
94
95         connect(closePB, SIGNAL(clicked()), this, SLOT(accept()));
96         connect(insertPB, SIGNAL(clicked()), this, SLOT(insertClicked()));
97
98         setWindowTitle(qt_("LyX: Delimiters"));
99
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), "");
104         }
105
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)"));
109
110         for (int i = 0; *biggui[i]; ++i)
111                 sizeCO->addItem(qt_(biggui[i]));
112
113         on_leftCO_activated(0);
114 }
115
116
117 void QDelimiterDialog::insertClicked()
118 {
119         string const left_ = delim[leftCO->currentIndex()];
120         string const right_ = delim[rightCO->currentIndex()];
121         int const size_ = sizeCO->currentIndex();
122
123         if (size_ == 0) {
124                 form_->controller().dispatchDelim(
125                         fix_name(left_, false) + ' ' +
126                         fix_name(right_, false));
127         } else {
128                 std::ostringstream os;
129                 os << '"' << bigleft[size_ - 1] << "\" \""
130                    << fix_name(left_, true) << "\" \""
131                    << bigright[size_ - 1] << "\" \""
132                    << fix_name(right_, true) << '"';
133                 form_->controller().dispatchBigDelim(os.str());
134         }
135
136 }
137
138
139 void QDelimiterDialog::on_leftCO_activated(int item)
140 {
141         if (matchCB->isChecked()) {
142                 string const match = do_match(delim[item]);
143                 int k = 0;
144                 while (delim[k] && delim[k] != match)
145                         ++k;
146                 rightCO->setCurrentIndex(k);
147         }
148 }
149
150
151 void QDelimiterDialog::on_rightCO_activated(int item)
152 {
153         if (matchCB->isChecked()) {
154                 string const match = do_match(delim[item]);
155                 int k = 0;
156                 while (delim[k] && delim[k] != match)
157                         ++k;
158                 leftCO->setCurrentIndex(k);
159         }
160 }
161
162
163 void QDelimiterDialog::on_matchCB_stateChanged(int state)
164 {
165         if (state == Qt::Checked)
166                 on_leftCO_activated(leftCO->currentIndex());
167 }
168
169
170 } // namespace frontend
171 } // namespace lyx
172
173 #include "QDelimiterDialog_moc.cpp"