File indexing completed on 2024-12-22 04:18:19
0001 /*************************************************************************** 0002 * * 0003 * copyright : (C) 2008 The University of Toronto * 0004 * netterfield@astro.utoronto.ca * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 ***************************************************************************/ 0012 0013 #include "labelbuilder.h" 0014 0015 #include "objectstore.h" 0016 0017 namespace Kst { 0018 0019 LabelBuilder::LabelBuilder(QWidget *parent, ObjectStore *store) 0020 : QWidget(parent), _store(store), _helpBox(0) { 0021 0022 setupUi(this); 0023 0024 _label->setWhatsThis(tr("<qt>The syntax for labels is a derivative of a subset of LaTeX. " 0025 "Supported syntax is: <b>\\[greeklettername]</b> and <b>\\[Greeklettername]</b>, " 0026 "<b>\\approx</b>, <b>\\cdot</b>, <b>\\ge</b>, <b>\\geq</b>, <b>\\inf</b> ," 0027 "<b>\\int</b>, <b>\\le</b>, <b>\\leq</b>, <b>\\ne</b>, <b>\\n</b>, " 0028 "<b>\\partial</b>, <b>\\prod</b>, <b>\\pm</b>, " 0029 "<b>\\textcolor{color name}{colored text}</b>, <b>\\textbf{bold text}</b>, " 0030 "<b>\\textit{italicized text}</b>, <b>\\t</b>, <b>\\sum</b>, <b>\\sqrt</b>, " 0031 "<b>\\underline{underlined text}</b>, <b>\\overline{overlined text}</b>, " 0032 "<b>x^y</b>, <b>x_y</b>. " 0033 "Scalars, equations, and vector elements can be embedded. " 0034 "Scalar: <i>[V1/Mean]</i>. Vector Element: <i>[V1[4]]</i>. " 0035 "Equation: <i>[=[V1/Mean]^2]</i>. A [ character can be inserted as <i>\\[</i>.")); 0036 0037 _label->setToolTip(tr("Label text. A subset of LaTeX is supported. Click 'Help' for help.")); 0038 0039 connect(_label, SIGNAL(textChanged()), this, SIGNAL(labelChanged())); 0040 connect(_help, SIGNAL(clicked()), this, SLOT(showHelp())); 0041 0042 _label->setFocus(); 0043 } 0044 0045 0046 LabelBuilder::~LabelBuilder() { 0047 if (_helpBox) { 0048 delete _helpBox; 0049 _helpBox = 0; 0050 } 0051 } 0052 0053 void LabelBuilder::showHelp() { 0054 if (!_helpBox) { 0055 _helpBox = new ModelessInfoBox(this); 0056 } 0057 0058 _helpBox->show(); 0059 _helpBox->setText(tr("<qt>" 0060 "<P ALIGN=LEFT STYLE=\"margin-bottom: 0in\"><FONT SIZE=4><B>Scalars & equations</B></FONT><br>" 0061 "Scalars and scalar equations can be displayed live in labels. When the scalar " 0062 "is updated, the label is updated. Scalar names are autocompleted. The format is:</P>" 0063 0064 "<P STYLE=\"margin-bottom: 0in\"><B>Scalar:</B> <FONT FACE=\"Courier New, monospace\">[</FONT><I>scalar" 0065 "name</I><FONT FACE=\"Courier New, monospace\">]</FONT>, e.g. <FONT FACE=\"Courier New, monospace\">[GYRO1:Mean" 0066 "(X4)]</FONT><br>" 0067 "<B>Vector Element:</B>" 0068 "<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\">, " 0069 "e.g., </FONT><FONT FACE=\"Courier New, monospace\">[GYRO1 (V2)[4]]</FONT>" 0070 "<br>" 0071 "<B>Equation:</B> <FONT FACE=\"Courier New, monospace\">[=</FONT><I>equation</I><FONT FACE=\"Courier New, monospace\">]</FONT>, " 0072 "e.g. <FONT FACE=\"Courier New, monospace\">[=[GYRO1:Mean" 0073 "(X4)]/[GYRO1:Sigma (X4)]]</FONT></P>" 0074 0075 "<P STYLE=\"margin-bottom: 0in\"><B>Formatting:</B><br> Numbers can be formatted using C printf formats. " 0076 "(eg, <FONT FACE=\"Courier New, monospace\">[GYRO1:Mean (X4)]{%4.2f}</FONT> )<br>" 0077 0078 "or as time using C strftime formats. (eg, " 0079 "<FONT FACE=\"Courier New, monospace\">[Time:Min (X4)]{T%a, %d %b %Y %T}</FONT>. )<br>For time, Note the {T...}." 0080 0081 "<P ALIGN=LEFT STYLE=\"margin-bottom: 0in\"><FONT SIZE=4><B>Supported LaTeX Subset</B></FONT><br>" 0082 "Labels in <i>kst</i> " 0083 "support a derivative subset of LaTeX. For example, to display the equation for the area of a " 0084 "circle, you could set the label to A=2\\pir^2. Unlike LaTeX, it is not necessary to enter math mode using '$'. Also, " 0085 "unlike LaTeX, variables are not automatically displayed in italic font. If desired, this must " 0086 "be done explicitly using \\textit{}. Supported sequences are:</P>" 0087 0088 "<P STYLE=\"margin-bottom: 0in\"><B>Greek letters:</B> \\<I>name</I> or " 0089 "\\<I>Name</I>. e.g.: <FONT FACE=\"Courier New, monospace\">\\alpha</FONT></P>" 0090 "<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\">" 0091 "\\cdot</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">" 0092 "\\ge</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">" 0093 "\\geq</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">" 0094 "\\inf</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">" 0095 "\\int</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">" 0096 "\\le</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">" 0097 "\\leq</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">" 0098 "\\ne</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">" 0099 "\\partial</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">" 0100 "\\prod</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">" 0101 "\\pm</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">" 0102 "\\sum</FONT><FONT FACE=\"Times New Roman, serif\">,</FONT><FONT FACE=\"Courier New, monospace\">" 0103 "\\sqrt</FONT></P>" 0104 "<P STYLE=\"margin-bottom: 0in\"><B>Font effects:</B> <FONT FACE=\"Courier New, monospace\">\\textcolor{</FONT><I>color" 0105 "name</I><FONT FACE=\"Courier New, monospace\">}{</FONT><I>colored " 0106 "text</I><FONT FACE=\"Courier New, monospace\">}</FONT>, <FONT FACE=\"Courier New, monospace\">\\textbf{</FONT><I>bold " 0107 "text</I><FONT FACE=\"Courier New, monospace\">}</FONT>," 0108 "<FONT FACE=\"Courier New, monospace\">\\textit{</FONT><I>italicized " 0109 "text</I><FONT FACE=\"Courier New, monospace\">}</FONT>," 0110 "<FONT FACE=\"Courier New, monospace\">\\underline{</FONT><I>underlined " 0111 "text</I><FONT FACE=\"Courier New, monospace\">}</FONT>," 0112 "<FONT FACE=\"Courier New, monospace\">\\overline{</FONT><I>overlined " 0113 "text</I><FONT FACE=\"Courier New, monospace\">}</FONT>." 0114 0115 "<P STYLE=\"margin-bottom: 0in\"><B>Other:</B><I>x</I><FONT FACE=\"Courier New, monospace\">^</FONT><I>y</I>," 0116 "<I>x</I><FONT FACE=\"Courier New, monospace\">_</FONT><I>y</I>, <FONT FACE=\"Courier New, monospace\">\\t</FONT>," 0117 "<FONT FACE=\"Courier New, monospace\">\\n</FONT>, <FONT FACE=\"Courier New, monospace\">\\[</FONT></P>" 0118 0119 )); 0120 _helpBox->setWidth(100); 0121 0122 } 0123 0124 0125 void LabelBuilder::setObjectStore(ObjectStore *store) { 0126 _store = store; 0127 _label->setObjectStore(store); 0128 } 0129 0130 0131 QString LabelBuilder::labelText() const { 0132 return _label->toPlainText(); 0133 } 0134 0135 0136 void LabelBuilder::setLabelText(const QString &label) { 0137 _label->setPlainText(label); 0138 } 0139 0140 0141 } 0142 0143 // vim: ts=2 sw=2 et