source: ntrip/trunk/GnssCenter/src/inpedit/panel.cpp@ 5000

Last change on this file since 5000 was 5000, checked in by mervart, 11 years ago
File size: 4.4 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,
28 QMap<QString, t_keyword*>* keywords) : QScrollArea(0) {
29
30 _keywords = keywords;
31
[4824]32 _ok = true;
[4829]33
[4825]34 _layout = new QGridLayout();
[4829]35 _layout->setSpacing(0);
36 _layout->setSizeConstraint(QLayout::SetFixedSize);
37
38 _page = new QWidget();
39 _page->setLayout(_layout);
40
[4831]41 QFont font("Courier");
42 _page->setFont(font);
43
[4829]44 this->setWidget(_page);
45
[4825]46 read(line, inStream);
[4829]47
[4830]48 setWidgetResizable(true);
[4825]49}
[4824]50
[4825]51// Destructor
52////////////////////////////////////////////////////////////////////////////
[4857]53t_panel::~t_panel() {
[4825]54}
55
56// Read Panel
57////////////////////////////////////////////////////////////////////////////
[4857]58void t_panel::read(QString line, QTextStream& inStream) {
[4825]59 int iRow = -1;
[4824]60 while (inStream.status() == QTextStream::Ok && !inStream.atEnd()) {
61 line = inStream.readLine().trimmed();
[4827]62 if (line.isEmpty() || line.indexOf("END_PANEL") != -1) {
[4824]63 break;
64 }
[4825]65 else {
66 ++iRow;
[4832]67
[4873]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 }
[4832]75
[4834]76 // Empty Line
77 // ----------
[4832]78 if (line.trimmed().isEmpty()) {
79 QLabel* label = new QLabel(line, this);
80 addWidget(label, iRow, 0, 1, line.length());
81 continue;
82 }
[4834]83
84 // Non-Editable Text
85 // -----------------
[4832]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()) {
[4834]92 QLabel* label = new QLabel();
[4832]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
[4834]108 // Editable Field
109 // --------------
[4873]110 int fld = -1;
[4869]111 int pos = 0;
[4834]112 while (true) {
[4882]113 QRegExp fldRx(">([^<]+)<");
[4870]114 pos = fldRx.indexIn(line, pos);
[4869]115 if (pos != -1) {
[4873]116 fld += 1;
[4834]117 int len = fldRx.matchedLength();
[4873]118 if (_keywords->contains(keyNames[fld])) {
119 t_keyword* keyword = (*_keywords)[ keyNames[fld] ];
[4882]120 QWidget* widget = keyword->createWidget(fldRx.cap(1).trimmed());
[4874]121 if (widget) {
122 addWidget(widget, iRow, pos, 1, len);
123 }
[4873]124 }
[4869]125 pos += len;
[4834]126 }
127 else {
128 break;
129 }
130 }
[4825]131 }
[4824]132 }
[4823]133}
134
[4832]135//
136////////////////////////////////////////////////////////////////////////////
[4857]137void t_panel::addWidget(QWidget* widget, int row, int col,
[4832]138 int rSpan, int cSpan, const QString& toolTip) {
139
[4834]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
[4881]150 t_uniLine* uniline = dynamic_cast<t_uniLine*>(widget);
151 if (uniline) {
152 _layout->addWidget(widget, row, col, rSpan, cSpan);
153 }
154 else {
[4834]155 QSize size(cSpan*fontW+6, rSpan*fontH+4);
156 widget->setMinimumSize(size);
157 widget->setMaximumSize(size);
[4832]158 _layout->addWidget(widget, row, col, rSpan, cSpan,
159 Qt::AlignLeft | Qt::AlignTop);
[4881]160 }
[4832]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.