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

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