source: ntrip/trunk/GnssCenter/inpedit/panel.cpp@ 10206

Last change on this file since 10206 was 5097, checked in by mervart, 12 years ago
File size: 4.6 KB
RevLine 
[4823]1
2/* -------------------------------------------------------------------------
3 * RTNet GUI
4 * -------------------------------------------------------------------------
5 *
[4857]6 * Class: t_panel
[4823]7 *
8 * Purpose: Panel in RTNet Input File
9 *
10 * Author: L. Mervart
11 *
12 * Created: 05-Jan-2013
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
[4857]18#include "panel.h"
[4872]19#include "keyword.h"
[4881]20#include "uniline.h"
[4823]21
22using namespace std;
[5000]23using namespace GnssCenter;
[4823]24
25// Constructor
26////////////////////////////////////////////////////////////////////////////
[4872]27t_panel::t_panel(const QString& line, QTextStream& inStream,
[5097]28 QMap<QString, t_keyword*>* keywords,
29 QStringList& staticLines) : QScrollArea(0) {
[4872]30
31 _keywords = keywords;
32
[4824]33 _ok = true;
[4829]34
[4825]35 _layout = new QGridLayout();
[4829]36 _layout->setSpacing(0);
37 _layout->setSizeConstraint(QLayout::SetFixedSize);
38
39 _page = new QWidget();
40 _page->setLayout(_layout);
41
[4831]42 QFont font("Courier");
43 _page->setFont(font);
44
[4829]45 this->setWidget(_page);
46
[5097]47 read(line, inStream, staticLines);
[4829]48
[4830]49 setWidgetResizable(true);
[4825]50}
[4824]51
[4825]52// Destructor
53////////////////////////////////////////////////////////////////////////////
[4857]54t_panel::~t_panel() {
[4825]55}
56
57// Read Panel
58////////////////////////////////////////////////////////////////////////////
[5097]59void t_panel::read(QString line, QTextStream& inStream, QStringList& staticLines) {
60 staticLines << line;
[4825]61 int iRow = -1;
[4824]62 while (inStream.status() == QTextStream::Ok && !inStream.atEnd()) {
63 line = inStream.readLine().trimmed();
[5097]64 staticLines << line;
[4827]65 if (line.isEmpty() || line.indexOf("END_PANEL") != -1) {
[4824]66 break;
67 }
[4825]68 else {
69 ++iRow;
[4832]70
[4873]71 QStringList keyNames;
72 int lastInd = line.lastIndexOf('#');
73 if (lastInd != -1) {
74 keyNames = line.mid(lastInd+1).split(QRegExp("\\s+"),
75 QString::SkipEmptyParts);
76 line = line.left(lastInd).replace('#', " ");
77 }
[4832]78
[4834]79 // Empty Line
80 // ----------
[4832]81 if (line.trimmed().isEmpty()) {
82 QLabel* label = new QLabel(line, this);
83 addWidget(label, iRow, 0, 1, line.length());
84 continue;
85 }
[4834]86
87 // Non-Editable Text
88 // -----------------
[4832]89 QStringListIterator it(
90 line.split(QRegExp(">[^<]+<|\\s{2,}"),QString::SkipEmptyParts) );
91 int icLast = -1;
92 while (it.hasNext()) {
93 QString txt = it.next().trimmed();
94 if (!txt.isEmpty()) {
[4834]95 QLabel* label = new QLabel();
[4832]96 label->setScaledContents(true);
97 label->setAlignment(Qt::AlignLeft);
98 int ic = line.indexOf(txt, icLast+1);
99 icLast = ic + txt.length();
100 txt.replace(QRegExp("@")," ");
101 label->setText(txt);
102 addWidget(label, iRow, ic, 1, txt.length());
103 if (iRow == 0) {
104 QFont font = label->font();
105 font.setBold(true);
106 label->setFont(font);
107 }
108 }
109 }
110
[4834]111 // Editable Field
112 // --------------
[4873]113 int fld = -1;
[4869]114 int pos = 0;
[4834]115 while (true) {
[4882]116 QRegExp fldRx(">([^<]+)<");
[4870]117 pos = fldRx.indexIn(line, pos);
[4869]118 if (pos != -1) {
[4873]119 fld += 1;
[4834]120 int len = fldRx.matchedLength();
[4873]121 if (_keywords->contains(keyNames[fld])) {
122 t_keyword* keyword = (*_keywords)[ keyNames[fld] ];
[4882]123 QWidget* widget = keyword->createWidget(fldRx.cap(1).trimmed());
[4874]124 if (widget) {
125 addWidget(widget, iRow, pos, 1, len);
126 }
[4873]127 }
[4869]128 pos += len;
[4834]129 }
130 else {
131 break;
132 }
133 }
[4825]134 }
[4824]135 }
[4823]136}
137
[4832]138//
139////////////////////////////////////////////////////////////////////////////
[4857]140void t_panel::addWidget(QWidget* widget, int row, int col,
[4832]141 int rSpan, int cSpan, const QString& toolTip) {
142
[4834]143 const int fontW = QFontMetrics(_page->font()).width('W');
144 const int fontH = QFontMetrics(_page->font()).height();
145
146 for (int ii = row; ii < row+rSpan; ii++) {
147 _layout->setRowMinimumHeight(ii, fontH+6);
148 }
149 for (int ii = col; ii < col+cSpan; ii++) {
150 _layout->setColumnMinimumWidth(ii, fontW+1);
151 }
152
[4881]153 t_uniLine* uniline = dynamic_cast<t_uniLine*>(widget);
154 if (uniline) {
155 _layout->addWidget(widget, row, col, rSpan, cSpan);
156 }
157 else {
[4834]158 QSize size(cSpan*fontW+6, rSpan*fontH+4);
159 widget->setMinimumSize(size);
160 widget->setMaximumSize(size);
[4832]161 _layout->addWidget(widget, row, col, rSpan, cSpan,
162 Qt::AlignLeft | Qt::AlignTop);
[4881]163 }
[4832]164
165 // Tool Tip (keyword name)
166 // -----------------------
167 if (!toolTip.isEmpty()) {
168 widget->setToolTip(toolTip);
169 }
170}
Note: See TracBrowser for help on using the repository browser.