]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QDelimiterDialog.C
qtabular skeleton
[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
33 char const * delim[] = {
34         "(", ")", "{", "}", "[", "]",
35         "lceil", "rceil", "lfloor", "rfloor", "langle", "rangle",
36         "uparrow", "Uparrow", "downarrow", "Downarrow",
37         "|", "Vert", "slash", "backslash", ""
38 };
39
40
41 string do_match(string const & str)
42 {
43         if (str == "(") return ")";
44         if (str == ")") return "(";
45         if (str == "[") return "]";
46         if (str == "]") return "[";
47         if (str == "{") return "}";
48         if (str == "}") return "{";
49         if (str == "l") return "r";
50         if (str == "rceil") return "lceil";
51         if (str == "lceil") return "rceil";
52         if (str == "rfloor") return "lfloor";
53         if (str == "lfloor") return "rfloor";
54         if (str == "rangle") return "langle";
55         if (str == "langle") return "rangle";
56         if (str == "backslash") return "slash";
57         if (str == "slash") return "backslash";
58         return str;
59 }
60
61
62 string fix_name(string const & str)
63 {
64         if (str == "slash")
65                 return "/";
66         if (str == "backslash")
67                 return "\\";
68         if (str == "empty")
69                 return ".";
70         return str;
71 }
72
73 } // namespace anon
74
75
76 QDelimiterDialog::QDelimiterDialog(QMath * form)
77         : QDelimiterDialogBase(0, 0, false, 0),
78         form_(form)
79 {
80         setCaption(_("LyX: Delimiters"));
81
82         for (int i = 0; *delim[i]; ++i) {
83                 string xpm_name = LibFileSearch("images/math/", delim[i], "xpm");
84                 leftIP->add(QPixmap(xpm_name.c_str()), delim[i], delim[i]);
85         }
86         leftIP->add(QPixmap(LibFileSearch("images/math/", "empty", "xpm").c_str()), "empty", "empty");
87         connect(leftIP, SIGNAL(button_clicked(string)), this, SLOT(ldelim_clicked(string)));
88         ldelim_clicked("(");
89
90         for (int i = 0; *delim[i]; ++i) {
91                 string xpm_name = LibFileSearch("images/math/", delim[i], "xpm");
92                 rightIP->add(QPixmap(xpm_name.c_str()), delim[i], delim[i]);
93         }
94         rightIP->add(QPixmap(LibFileSearch("images/math/", "empty", "xpm").c_str()), "empty", "empty");
95         connect(rightIP, SIGNAL(button_clicked(string)), this, SLOT(rdelim_clicked(string)));
96         rdelim_clicked(")");
97 }
98
99
100 void QDelimiterDialog::insertClicked()
101 {
102         form_->insertDelim(fix_name(left_) + " " + fix_name(right_));
103 }
104
105
106 void QDelimiterDialog::set_label(QLabel * label, string const & str)
107 {
108         string xpm_name = LibFileSearch("images/math/", str, "xpm");
109         label->setUpdatesEnabled(false);
110         label->setPixmap(QPixmap(xpm_name.c_str()));
111         label->setUpdatesEnabled(true);
112         label->update();
113 }
114
115
116 void QDelimiterDialog::ldelim_clicked(string str)
117 {
118         left_ = str;
119
120         set_label(leftPI, left_);
121         if (matchCB->isChecked()) {
122                 right_ = do_match(left_);
123                 set_label(rightPI, right_);
124         }
125 }
126
127
128 void QDelimiterDialog::rdelim_clicked(string str)
129 {
130         right_ = str;
131
132         set_label(rightPI, right_);
133         if (matchCB->isChecked()) {
134                 left_ = do_match(right_);
135                 set_label(leftPI, left_);
136         }
137 }