]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QDelimiterDialog.C
Remove quite a few compiler warnings:
[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 // FIXME: Implement fixed size delimiters (see qt3 frontend)
32
33 namespace {
34
35 char const * delim[] = {
36         "(", ")", "{", "}", "[", "]",
37         "lceil", "rceil", "lfloor", "rfloor", "langle", "rangle",
38         "uparrow", "Uparrow", "downarrow", "Downarrow",
39         "|", "Vert", "slash", "backslash", ""
40 };
41
42
43 string do_match(const string & str)
44 {
45         if (str == "(") return ")";
46         if (str == ")") return "(";
47         if (str == "[") return "]";
48         if (str == "]") return "[";
49         if (str == "{") return "}";
50         if (str == "}") return "{";
51         if (str == "l") return "r";
52         if (str == "rceil") return "lceil";
53         if (str == "lceil") return "rceil";
54         if (str == "rfloor") return "lfloor";
55         if (str == "lfloor") return "rfloor";
56         if (str == "rangle") return "langle";
57         if (str == "langle") return "rangle";
58         if (str == "backslash") return "slash";
59         if (str == "slash") return "backslash";
60         return str;
61 }
62
63
64 string fix_name(const string & str)
65 {
66         if (str == "slash")
67                 return "/";
68         if (str == "backslash")
69                 return "\\";
70         if (str == "empty")
71                 return ".";
72         return str;
73 }
74
75 } // namespace anon
76
77
78 QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form)
79         : form_(form)
80 {
81         setupUi(this);
82
83     connect( closePB, SIGNAL( clicked() ), this, SLOT( accept() ) );
84     connect( insertPB, SIGNAL( clicked() ), this, SLOT( insertClicked() ) );
85
86         setCaption(qt_("LyX: Delimiters"));
87
88         for (int i = 0; *delim[i]; ++i) {
89                 string xpm(find_xpm(delim[i]));
90                 leftIP->add(QPixmap(toqstr(xpm)), delim[i], delim[i]);
91                 rightIP->add(QPixmap(toqstr(xpm)), delim[i], delim[i]);
92         }
93
94         string empty_xpm(find_xpm("empty"));
95
96         leftIP->add(QPixmap(toqstr(empty_xpm)), "empty", "empty");
97         rightIP->add(QPixmap(toqstr(empty_xpm)), "empty", "empty");
98         // Leave these std:: qualifications alone !
99         connect(leftIP, SIGNAL(button_clicked(const std::string &)),
100                 this, SLOT(ldelim_clicked(const std::string &)));
101         connect(rightIP, SIGNAL(button_clicked(const std::string &)),
102                 this, SLOT(rdelim_clicked(const std::string &)));
103         ldelim_clicked("(");
104         rdelim_clicked(")");
105 }
106
107
108 void QDelimiterDialog::insertClicked()
109 {
110         form_->controller().dispatchDelim(fix_name(left_) + ' ' + fix_name(right_));
111 }
112
113
114 void QDelimiterDialog::set_label(QLabel * label, const string & str)
115 {
116         label->setUpdatesEnabled(false);
117         label->setPixmap(QPixmap(toqstr(find_xpm(str))));
118         label->setUpdatesEnabled(true);
119         label->update();
120 }
121
122
123 void QDelimiterDialog::ldelim_clicked(const string & str)
124 {
125         left_ = str;
126
127         set_label(leftPI, left_);
128         if (matchCB->isChecked()) {
129                 right_ = do_match(left_);
130                 set_label(rightPI, right_);
131         }
132 }
133
134
135 void QDelimiterDialog::rdelim_clicked(const string & str)
136 {
137         right_ = str;
138
139         set_label(rightPI, right_);
140         if (matchCB->isChecked()) {
141                 left_ = do_match(right_);
142                 set_label(leftPI, left_);
143         }
144 }
145
146 } // namespace frontend
147 } // namespace lyx
148
149 #include "QDelimiterDialog_moc.cpp"