1 /***************************************************************************
2  *                                                                         *
3  *   copyright : (C) 2008 The University of Toronto                        *
4  *                   netterfield@astro.utoronto.ca                         *
5  *                                                                         *
6  *   This program is free software; you can redistribute it and/or modify  *
7  *   it under the terms of the GNU General Public License as published by  *
8  *   the Free Software Foundation; either version 2 of the License, or     *
9  *   (at your option) any later version.                                   *
10  *                                                                         *
11  ***************************************************************************/
12 
13 #include "labelbuilder.h"
14 
15 #include "objectstore.h"
16 
17 namespace Kst {
18 
LabelBuilder(QWidget * parent,ObjectStore * store)19 LabelBuilder::LabelBuilder(QWidget *parent, ObjectStore *store)
20   : QWidget(parent), _store(store), _helpBox(0) {
21 
22   setupUi(this);
23 
24    _label->setWhatsThis(tr("<qt>The syntax for labels is a derivative of a subset of LaTeX.  "
25                              "Supported syntax is: <b>\\[greeklettername]</b> and <b>\\[Greeklettername]</b>, "
26                              "<b>\\approx</b>, <b>\\cdot</b>, <b>\\ge</b>, <b>\\geq</b>, <b>\\inf</b> ,"
27                              "<b>\\int</b>, <b>\\le</b>, <b>\\leq</b>, <b>\\ne</b>, <b>\\n</b>, "
28                              "<b>\\partial</b>, <b>\\prod</b>, <b>\\pm</b>, "
29                              "<b>\\textcolor{color name}{colored text}</b>, <b>\\textbf{bold text}</b>, "
30                              "<b>\\textit{italicized text}</b>, <b>\\t</b>, <b>\\sum</b>, <b>\\sqrt</b>, "
31                              "<b>\\underline{underlined text}</b>, <b>\\overline{overlined text}</b>, "
32                              "<b>x^y</b>, <b>x_y</b>.  "
33                              "Scalars, equations, and vector elements can be embedded.  "
34                              "Scalar: <i>[V1/Mean]</i>.  Vector Element: <i>[V1[4]]</i>.  "
35                              "Equation: <i>[=[V1/Mean]^2]</i>.  A [ character can be inserted as <i>\\[</i>."));
36 
37   _label->setToolTip(tr("Label text.  A subset of LaTeX is supported.  Click 'Help' for help."));
38 
39   connect(_label, SIGNAL(textChanged()), this, SIGNAL(labelChanged()));
40   connect(_help, SIGNAL(clicked()), this, SLOT(showHelp()));
41 
42   _label->setFocus();
43 }
44 
45 
~LabelBuilder()46 LabelBuilder::~LabelBuilder() {
47   if (_helpBox) {
48     delete _helpBox;
49     _helpBox = 0;
50   }
51 }
52 
showHelp()53 void LabelBuilder::showHelp() {
54   if (!_helpBox) {
55     _helpBox = new ModelessInfoBox(this);
56   }
57 
58   _helpBox->show();
59   _helpBox->setText(tr("<qt>"
60                     "<P ALIGN=LEFT STYLE=\"margin-bottom: 0in\"><FONT SIZE=4><B>Scalars &amp; equations</B></FONT><br>"
61                      "Scalars and scalar equations can be displayed live in labels.  When the scalar "
62                      "is updated, the label is updated.  Scalar names are autocompleted.  The format is:</P>"
63 
64                     "<P STYLE=\"margin-bottom: 0in\"><B>Scalar:</B> <FONT FACE=\"Courier New, monospace\">[</FONT><I>scalar"
65                     "name</I><FONT FACE=\"Courier New, monospace\">]</FONT>, e.g. <FONT FACE=\"Courier New, monospace\">[GYRO1:Mean"
66                     "(X4)]</FONT><br>"
67                     "<B>Vector Element:</B>"
68                     "<FONT FACE=\"Courier New, monospace\">[</FONT><I>vectorName</I><FONT FACE=\"Courier New, monospace\">[</FONT><I>index</I><FONT FACE=\"Courier New, monospace\">]]</FONT><FONT FACE=\"Times New Roman, serif\">, "
69                     "e.g., </FONT><FONT FACE=\"Courier New, monospace\">[GYRO1 (V2)[4]]</FONT>"
70                     "<br>"
71                     "<B>Equation:</B> <FONT FACE=\"Courier New, monospace\">[=</FONT><I>equation</I><FONT FACE=\"Courier New, monospace\">]</FONT>, "
72                     "e.g. <FONT FACE=\"Courier New, monospace\">[=[GYRO1:Mean"
73                     "(X4)]/[GYRO1:Sigma (X4)]]</FONT></P>"
74 
75                     "<P STYLE=\"margin-bottom: 0in\"><B>Formatting:</B><br> Numbers can be formatted using C printf formats. "
76                     "(eg, <FONT FACE=\"Courier New, monospace\">[GYRO1:Mean (X4)]{%4.2f}</FONT> )<br>"
77 
78                     "or as time using C strftime formats.  (eg, "
79                     "<FONT FACE=\"Courier New, monospace\">[Time:Min (X4)]{T%a, %d %b %Y %T}</FONT>. )<br>For time, Note the {T...}."
80 
81                     "<P ALIGN=LEFT STYLE=\"margin-bottom: 0in\"><FONT SIZE=4><B>Supported LaTeX Subset</B></FONT><br>"
82                     "Labels in <i>kst</i> "
83                     "support a derivative subset of LaTeX. For example, to display the equation for the area of a "
84                     "circle, you could set the label to A=2\\pir^2.  Unlike LaTeX, it is not necessary to enter math mode using '$'.  Also, "
85                     "unlike LaTeX, variables are not automatically displayed in italic font.  If desired, this must "
86                     "be done explicitly using \\textit{}.  Supported sequences are:</P>"
87 
88                     "<P STYLE=\"margin-bottom: 0in\"><B>Greek letters:</B>  \\<I>name</I> or "
89                     "\\<I>Name</I>.  e.g.: <FONT FACE=\"Courier New, monospace\">\\alpha</FONT></P>"
90                     "<P STYLE=\"margin-bottom: 0in\"><B>Other symbols:</B>  <FONT FACE=\"Courier New, monospace\">\\approx</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">"
91                     "\\cdot</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">"
92                     "\\ge</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">"
93                     "\\geq</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">"
94                     "\\inf</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">"
95                     "\\int</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">"
96                     "\\le</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">"
97                     "\\leq</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">"
98                     "\\ne</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">"
99                     "\\partial</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">"
100                     "\\prod</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">"
101                     "\\pm</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">"
102                     "\\sum</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">"
103                     "\\sqrt</FONT></P>"
104                    "<P STYLE=\"margin-bottom: 0in\"><B>Font effects:</B> <FONT FACE=\"Courier New, monospace\">\\textcolor{</FONT><I>color"
105                    "name</I><FONT FACE=\"Courier New, monospace\">}{</FONT><I>colored "
106                    "text</I><FONT FACE=\"Courier New, monospace\">}</FONT>, <FONT FACE=\"Courier New, monospace\">\\textbf{</FONT><I>bold "
107                    "text</I><FONT FACE=\"Courier New, monospace\">}</FONT>,"
108                    "<FONT FACE=\"Courier New, monospace\">\\textit{</FONT><I>italicized "
109                    "text</I><FONT FACE=\"Courier New, monospace\">}</FONT>,"
110                    "<FONT FACE=\"Courier New, monospace\">\\underline{</FONT><I>underlined "
111                    "text</I><FONT FACE=\"Courier New, monospace\">}</FONT>,"
112                    "<FONT FACE=\"Courier New, monospace\">\\overline{</FONT><I>overlined "
113                    "text</I><FONT FACE=\"Courier New, monospace\">}</FONT>."
114 
115                    "<P STYLE=\"margin-bottom: 0in\"><B>Other:</B><I>x</I><FONT FACE=\"Courier New, monospace\">^</FONT><I>y</I>,"
116                    "<I>x</I><FONT FACE=\"Courier New, monospace\">_</FONT><I>y</I>, <FONT FACE=\"Courier New, monospace\">\\t</FONT>,"
117                    "<FONT FACE=\"Courier New, monospace\">\\n</FONT>, <FONT FACE=\"Courier New, monospace\">\\[</FONT></P>"
118 
119                     ));
120   _helpBox->setWidth(100);
121 
122 }
123 
124 
setObjectStore(ObjectStore * store)125 void LabelBuilder::setObjectStore(ObjectStore *store) {
126   _store = store;
127   _label->setObjectStore(store);
128 }
129 
130 
labelText() const131 QString LabelBuilder::labelText() const {
132   return _label->toPlainText();
133 }
134 
135 
setLabelText(const QString & label)136 void LabelBuilder::setLabelText(const QString &label) {
137   _label->setPlainText(label);
138 }
139 
140 
141 }
142 
143 // vim: ts=2 sw=2 et
144