]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QDelimiterDialog.C
fix empty delimiter
[lyx.git] / src / frontends / qt2 / QDelimiterDialog.C
1 /**
2  * \file QDelimiterDialog.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon <moz@compsoc.man.ac.uk>
7  */
8
9 #include <config.h>
10
11 #include "support/filetools.h"
12 #include "gettext.h"
13 #include "debug.h"
14  
15 #include "QMath.h"
16 #include "QDelimiterDialog.h"
17
18 #include "iconpalette.h"
19  
20 #include <qlabel.h>
21 #include <qpixmap.h>
22 #include <qpushbutton.h>
23 #include <qcheckbox.h>
24  
25 namespace {
26         char const * delim[] = {
27                 "(", ")", "{", "}", "[", "]",
28                 "lceil", "rceil", "lfloor", "rfloor", "langle", "rangle",
29                 "uparrow", "Uparrow", "downarrow", "Downarrow", 
30                 "|", "Vert", "slash", "backslash", ""
31         };
32
33         string do_match(string str) {
34                 if (str == "(") return ")";
35                 if (str == ")") return "(";
36                 if (str == "[") return "]";
37                 if (str == "]") return "[";
38                 if (str == "{") return "}";
39                 if (str == "}") return "{";
40                 if (str == "l") return "r";
41                 if (str == "rceil") return "lceil";
42                 if (str == "lceil") return "rceil";
43                 if (str == "rfloor") return "lfloor";
44                 if (str == "lfloor") return "rfloor";
45                 if (str == "rangle") return "langle";
46                 if (str == "langle") return "rangle";
47                 if (str == "backslash") return "slash";
48                 if (str == "slash") return "backslash";
49                 return str;
50         }
51  
52 }
53
54 QDelimiterDialog::QDelimiterDialog(QMath * form)
55         : QDelimiterDialogBase(0, 0, false, 0),
56         form_(form)
57 {
58         setCaption(_("LyX: Delimiters"));
59  
60         for (int i = 0; *delim[i]; ++i) {
61                 string xpm_name = LibFileSearch("images/math/", delim[i], "xpm");
62                 leftIP->add(QPixmap(xpm_name.c_str()), delim[i], delim[i]);
63         }
64         leftIP->add(QPixmap(LibFileSearch("images/math/", "empty", "xpm").c_str()), "empty", "empty");
65         connect(leftIP, SIGNAL(button_clicked(string)), this, SLOT(ldelim_clicked(string)));
66         ldelim_clicked("(");
67
68         for (int i = 0; *delim[i]; ++i) {
69                 string xpm_name = LibFileSearch("images/math/", delim[i], "xpm");
70                 rightIP->add(QPixmap(xpm_name.c_str()), delim[i], delim[i]);
71         }
72         rightIP->add(QPixmap(LibFileSearch("images/math/", "empty", "xpm").c_str()), "empty", "empty");
73         connect(rightIP, SIGNAL(button_clicked(string)), this, SLOT(rdelim_clicked(string)));
74         rdelim_clicked(")");
75 }
76
77  
78 namespace {
79         string fix_name(string const & str) {
80                 if (str == "slash")
81                         return "/";
82                 if (str == "backslash")
83                         return "\\";
84                 if (str == "empty")
85                         return ".";
86                 return str;
87         }
88 }
89  
90 void QDelimiterDialog::insertClicked()
91 {
92         form_->insertDelim(fix_name(left_) + " " + fix_name(right_));
93 }
94
95  
96 void QDelimiterDialog::set_label(QLabel * label, string const & str)
97 {
98         string xpm_name = LibFileSearch("images/math/", str, "xpm");
99         label->setUpdatesEnabled(false);
100         label->setPixmap(QPixmap(xpm_name.c_str()));
101         label->setUpdatesEnabled(true);
102         label->update();
103 }
104
105  
106 void QDelimiterDialog::ldelim_clicked(string str)
107 {
108         left_ = str;
109  
110         set_label(leftPI, left_);
111         if (matchCB->isChecked()) {
112                 right_ = do_match(left_);
113                 set_label(rightPI, right_);
114         }
115 }
116
117
118 void QDelimiterDialog::rdelim_clicked(string str)
119 {
120         right_ = str;
121  
122         set_label(rightPI, right_);
123         if (matchCB->isChecked()) {
124                 left_ = do_match(right_);
125                 set_label(leftPI, left_);
126         }
127 }