]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QDelimiterDialog.C
Strip trailing whitespace.
[lyx.git] / src / frontends / qt2 / 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
14 #include "support/filetools.h"
15 #include "qt_helpers.h"
16 #include "debug.h"
17
18 #include "QMath.h"
19 #include "ControlMath.h"
20 #include "QDelimiterDialog.h"
21
22 #include "iconpalette.h"
23
24 #include <qlabel.h>
25 #include <qpixmap.h>
26 #include <qpushbutton.h>
27 #include <qcheckbox.h>
28
29 namespace {
30
31 char const * delim[] = {
32         "(", ")", "{", "}", "[", "]",
33         "lceil", "rceil", "lfloor", "rfloor", "langle", "rangle",
34         "uparrow", "Uparrow", "downarrow", "Downarrow",
35         "|", "Vert", "slash", "backslash", ""
36 };
37
38
39 string do_match(string const & str)
40 {
41         if (str == "(") return ")";
42         if (str == ")") return "(";
43         if (str == "[") return "]";
44         if (str == "]") return "[";
45         if (str == "{") return "}";
46         if (str == "}") return "{";
47         if (str == "l") return "r";
48         if (str == "rceil") return "lceil";
49         if (str == "lceil") return "rceil";
50         if (str == "rfloor") return "lfloor";
51         if (str == "lfloor") return "rfloor";
52         if (str == "rangle") return "langle";
53         if (str == "langle") return "rangle";
54         if (str == "backslash") return "slash";
55         if (str == "slash") return "backslash";
56         return str;
57 }
58
59
60 string fix_name(string const & str)
61 {
62         if (str == "slash")
63                 return "/";
64         if (str == "backslash")
65                 return "\\";
66         if (str == "empty")
67                 return ".";
68         return str;
69 }
70
71 } // namespace anon
72
73
74 QDelimiterDialog::QDelimiterDialog(QMath * form)
75         : QDelimiterDialogBase(0, 0, false, 0),
76         form_(form)
77 {
78         setCaption(qt_("LyX: Delimiters"));
79
80         for (int i = 0; *delim[i]; ++i) {
81                 string xpm(find_xpm(delim[i]));
82                 leftIP->add(QPixmap(toqstr(xpm)), delim[i], delim[i]);
83                 rightIP->add(QPixmap(toqstr(xpm)), delim[i], delim[i]);
84         }
85
86         string empty_xpm(find_xpm("empty"));
87
88         leftIP->add(QPixmap(toqstr(empty_xpm)), "empty", "empty");
89         rightIP->add(QPixmap(toqstr(empty_xpm)), "empty", "empty");
90         connect(leftIP, SIGNAL(button_clicked(const string &)), this, SLOT(ldelim_clicked(const string &)));
91         connect(rightIP, SIGNAL(button_clicked(const string &)), this, SLOT(rdelim_clicked(const string &)));
92         ldelim_clicked("(");
93         rdelim_clicked(")");
94 }
95
96
97 void QDelimiterDialog::insertClicked()
98 {
99         form_->insertDelim(fix_name(left_) + ' ' + fix_name(right_));
100 }
101
102
103 void QDelimiterDialog::set_label(QLabel * label, string const & str)
104 {
105         label->setUpdatesEnabled(false);
106         label->setPixmap(QPixmap(toqstr(find_xpm(str))));
107         label->setUpdatesEnabled(true);
108         label->update();
109 }
110
111
112 void QDelimiterDialog::ldelim_clicked(string const & str)
113 {
114         left_ = str;
115
116         set_label(leftPI, left_);
117         if (matchCB->isChecked()) {
118                 right_ = do_match(left_);
119                 set_label(rightPI, right_);
120         }
121 }
122
123
124 void QDelimiterDialog::rdelim_clicked(string const & str)
125 {
126         right_ = str;
127
128         set_label(rightPI, right_);
129         if (matchCB->isChecked()) {
130                 left_ = do_match(right_);
131                 set_label(leftPI, left_);
132         }
133 }