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

Last change on this file since 10503 was 5097, checked in by mervart, 12 years ago
File size: 4.6 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * RTNet GUI
4 * -------------------------------------------------------------------------
5 *
6 * Class: t_panel
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
18#include "panel.h"
19#include "keyword.h"
20#include "uniline.h"
21
22using namespace std;
23using namespace GnssCenter;
24
25// Constructor
26////////////////////////////////////////////////////////////////////////////
27t_panel::t_panel(const QString& line, QTextStream& inStream,
28 QMap<QString, t_keyword*>* keywords,
29 QStringList& staticLines) : QScrollArea(0) {
30
31 _keywords = keywords;
32
33 _ok = true;
34
35 _layout = new QGridLayout();
36 _layout->setSpacing(0);
37 _layout->setSizeConstraint(QLayout::SetFixedSize);
38
39 _page = new QWidget();
40 _page->setLayout(_layout);
41
42 QFont font("Courier");
43 _page->setFont(font);
44
45 this->setWidget(_page);
46
47 read(line, inStream, staticLines);
48
49 setWidgetResizable(true);
50}
51
52// Destructor
53////////////////////////////////////////////////////////////////////////////
54t_panel::~t_panel() {
55}
56
57// Read Panel
58////////////////////////////////////////////////////////////////////////////
59void t_panel::read(QString line, QTextStream& inStream, QStringList& staticLines) {
60 staticLines << line;
61 int iRow = -1;
62 while (inStream.status() == QTextStream::Ok && !inStream.atEnd()) {
63 line = inStream.readLine().trimmed();
64 staticLines << line;
65 if (line.isEmpty() || line.indexOf("END_PANEL") != -1) {
66 break;
67 }
68 else {
69 ++iRow;
70
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 }
78
79 // Empty Line
80 // ----------
81 if (line.trimmed().isEmpty()) {
82 QLabel* label = new QLabel(line, this);
83 addWidget(label, iRow, 0, 1, line.length());
84 continue;
85 }
86
87 // Non-Editable Text
88 // -----------------
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()) {
95 QLabel* label = new QLabel();
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
111 // Editable Field
112 // --------------
113 int fld = -1;
114 int pos = 0;
115 while (true) {
116 QRegExp fldRx(">([^<]+)<");
117 pos = fldRx.indexIn(line, pos);
118 if (pos != -1) {
119 fld += 1;
120 int len = fldRx.matchedLength();
121 if (_keywords->contains(keyNames[fld])) {
122 t_keyword* keyword = (*_keywords)[ keyNames[fld] ];
123 QWidget* widget = keyword->createWidget(fldRx.cap(1).trimmed());
124 if (widget) {
125 addWidget(widget, iRow, pos, 1, len);
126 }
127 }
128 pos += len;
129 }
130 else {
131 break;
132 }
133 }
134 }
135 }
136}
137
138//
139////////////////////////////////////////////////////////////////////////////
140void t_panel::addWidget(QWidget* widget, int row, int col,
141 int rSpan, int cSpan, const QString& toolTip) {
142
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
153 t_uniLine* uniline = dynamic_cast<t_uniLine*>(widget);
154 if (uniline) {
155 _layout->addWidget(widget, row, col, rSpan, cSpan);
156 }
157 else {
158 QSize size(cSpan*fontW+6, rSpan*fontH+4);
159 widget->setMinimumSize(size);
160 widget->setMaximumSize(size);
161 _layout->addWidget(widget, row, col, rSpan, cSpan,
162 Qt::AlignLeft | Qt::AlignTop);
163 }
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.