]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QDelimiterDialog.C
Lots and lots of little trivial bits.
[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 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "support/filetools.h"
18 #include "gettext.h"
19 #include "debug.h"
20  
21 #include "QMath.h"
22 #include "QDelimiterDialog.h"
23
24 #include "iconpalette.h"
25  
26 #include <qlabel.h>
27 #include <qpixmap.h>
28 #include <qpushbutton.h>
29 #include <qcheckbox.h>
30  
31 namespace {
32         char const * delim[] = {
33                 "(", ")", "{", "}", "[", "]",
34                 "lceil", "rceil", "lfloor", "rfloor", "langle", "rangle",
35                 "uparrow", "Uparrow", "downarrow", "Downarrow", 
36                 "|", "Vert", "slash", "backslash", ""
37         };
38
39         string do_match(string str) {
40                 if (str == "(") return ")";
41                 if (str == ")") return "(";
42                 if (str == "[") return "]";
43                 if (str == "]") return "[";
44                 if (str == "{") return "}";
45                 if (str == "}") return "{";
46                 if (str == "l") return "r";
47                 if (str == "rceil") return "lceil";
48                 if (str == "lceil") return "rceil";
49                 if (str == "rfloor") return "lfloor";
50                 if (str == "lfloor") return "rfloor";
51                 if (str == "rangle") return "langle";
52                 if (str == "langle") return "rangle";
53                 if (str == "backslash") return "slash";
54                 if (str == "slash") return "backslash";
55                 return str;
56         }
57  
58 }
59
60 QDelimiterDialog::QDelimiterDialog(QMath * form)
61         : QDelimiterDialogBase(0, 0, false, 0),
62         form_(form)
63 {
64         setCaption(_("LyX: Delimiters"));
65  
66         for (int i = 0; *delim[i]; ++i) {
67                 string xpm_name = LibFileSearch("images/math/", delim[i], "xpm");
68                 leftIP->add(QPixmap(xpm_name.c_str()), delim[i], delim[i]);
69         }
70         leftIP->add(QPixmap(LibFileSearch("images/math/", "empty", "xpm").c_str()), "empty", "empty");
71         connect(leftIP, SIGNAL(button_clicked(string)), this, SLOT(ldelim_clicked(string)));
72         ldelim_clicked("(");
73
74         for (int i = 0; *delim[i]; ++i) {
75                 string xpm_name = LibFileSearch("images/math/", delim[i], "xpm");
76                 rightIP->add(QPixmap(xpm_name.c_str()), delim[i], delim[i]);
77         }
78         rightIP->add(QPixmap(LibFileSearch("images/math/", "empty", "xpm").c_str()), "empty", "empty");
79         connect(rightIP, SIGNAL(button_clicked(string)), this, SLOT(rdelim_clicked(string)));
80         rdelim_clicked(")");
81 }
82
83  
84 namespace {
85         string fix_name(string const & str) {
86                 if (str == "slash")
87                         return "/";
88                 if (str == "backslash")
89                         return "\\";
90                 if (str == "empty")
91                         return ".";
92                 return str;
93         }
94 }
95  
96 void QDelimiterDialog::insertClicked()
97 {
98         form_->insertDelim(fix_name(left_) + " " + fix_name(right_));
99 }
100
101  
102 void QDelimiterDialog::set_label(QLabel * label, string const & str)
103 {
104         string xpm_name = LibFileSearch("images/math/", str, "xpm");
105         label->setUpdatesEnabled(false);
106         label->setPixmap(QPixmap(xpm_name.c_str()));
107         label->setUpdatesEnabled(true);
108         label->update();
109 }
110
111  
112 void QDelimiterDialog::ldelim_clicked(string 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 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 }