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