This repository has been archived by the owner on Nov 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
InfoWidget.cpp
173 lines (140 loc) · 5.04 KB
/
InfoWidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Copyright (C) 2012-2015, Ali Baharev
// All rights reserved.
// This code is published under the GNU Lesser General Public License.
#include <QBoxLayout>
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QLabel>
#include <QRadioButton>
#include "InfoWidget.hpp"
namespace {
const char GREEN[] = "QLabel { background-color : #33FF00; }";
const char YELLOW[] = "QLabel { background-color : #FFFF00; }";
const char RED[] = "QLabel { background-color : #FF0000; }";
const char FIELD[] = "Field";
}
InfoWidget::InfoWidget(QWidget *parent) : QFrame(parent) {
projectLabel = new QLabel("Please create a new or edit / select an existing file by clicking on one of icons on the left!", this);
projectLabel->setAlignment(Qt::AlignHCenter);
projectLabel->setFocusPolicy(Qt::NoFocus);
rgfLabel = new QLabel(this);
setLabel = new QLabel(this);
xyLabel = new QLabel(this);
QHBoxLayout* hboxLayout = new QHBoxLayout(this);
hboxLayout->addWidget(rgfLabel, 1);
hboxLayout->addWidget(setLabel, 1);
hboxLayout->addWidget( xyLabel, 1);
hboxLayout->setContentsMargins(0, 0, 0, 0);
fieldRadio = new QRadioButton("Field data processing", this);
fieldRadio->setChecked(true);
wellRadio = new QRadioButton("Well data processing", this);
trjLabel = new QLabel(this);
// keep this line after trjLabel initialization:
// updateModePanel() references trjLabel
connect(fieldRadio, SIGNAL(toggled(bool)), this, SLOT(updateModePanel()));
QHBoxLayout* modeLayout = new QHBoxLayout(this);
modeLayout->addWidget(fieldRadio, 1);
modeLayout->addWidget(wellRadio, 1);
modeLayout->addWidget(trjLabel, 2);
modeLayout->setContentsMargins(0, 0, 0, 0);
QVBoxLayout* vboxLayout = new QVBoxLayout(this);
vboxLayout->addWidget(projectLabel);
QWidget* dummy2 = new QWidget(this);
dummy2->setLayout(modeLayout);
vboxLayout->addWidget(dummy2);
QWidget* dummy = new QWidget(this);
dummy->setLayout(hboxLayout);
vboxLayout->addWidget(dummy);
setLayout(vboxLayout);
setFrameStyle(QFrame::Box | QFrame::Raised);
// a hack to make the infowidget as wide as the settings panel
setContentsMargins(10, 5, 10, 5);
vboxLayout->setContentsMargins(10, 5, 10, 5);
fieldRadio->setFocusPolicy(Qt::StrongFocus);
wellRadio->setFocusPolicy(Qt::StrongFocus);
}
void InfoWidget::setFocus(Qt::FocusReason reason) {
if (wellRadio->isChecked())
wellRadio->setFocus(reason);
else
fieldRadio->setFocus(reason);
}
void InfoWidget::checkSetFile() {
updateSetLabel(fileExists(".set"));
}
void InfoWidget::newProjectSelected(const QString& newProjectPath, const QString& newProjectName) {
projectPath = newProjectPath;
projectName = newProjectName;
projectLabel->setText("Project: <b>"+projectName+"</b>, path: "+QDir::toNativeSeparators(projectPath));
updateRgfLabel();
bool isSetFileOK = false;
updateSetLabel(isSetFileOK); // will be updated later anyway
updateXyLabel();
}
bool InfoWidget::fileExists(const char extension[]) {
QFileInfo finfo(projectPath+"/"+projectName+extension);
return (finfo.exists() && finfo.isFile()) ? true : false;
}
void InfoWidget::setOkText(QLabel* lbl, const QString& msg) {
lbl->setText(msg);
lbl->setStyleSheet(GREEN);
}
void InfoWidget::setWarnText(QLabel* lbl, const QString& msg) {
lbl->setText(msg);
lbl->setStyleSheet(YELLOW);
}
void InfoWidget::setErrorText(QLabel* lbl, const QString& msg) {
lbl->setText(msg);
lbl->setStyleSheet(RED);
}
void InfoWidget::updateModePanel() {
bool isWell = wellRadio->isChecked();
if (isWell) {
if (fileExists(".trj"))
setOkText(trjLabel, "Trajectory file found");
else
setWarnText(trjLabel, "No trajectory file found, assuming vertical trajectory");
}
else {
trjLabel->clear();
trjLabel->setStyleSheet("background-color: rgba(0,0,0,0%)");
}
emit runModeChanged(isWell);
}
void InfoWidget::newSettingsFileLoaded(bool isWell, bool loadedCleanly) {
if (isWell)
wellRadio->setChecked(true);
else
fieldRadio->setChecked(true);
updateModePanel();
updateSetLabel(loadedCleanly);
}
void InfoWidget::updateRgfLabel() {
if (fileExists(".rgf"))
setOkText(rgfLabel, "Data file found");
else
setErrorText(rgfLabel, "Don\'t forget to create the data file!");
}
void InfoWidget::updateSetLabel(bool isOK) {
if (isOK)
setOkText(setLabel, "Settings from a previous run found");
else
setWarnText(setLabel, "The settings below need your attention");
}
void InfoWidget::updateXyLabel() {
if (fileExists(".xy"))
setOkText(xyLabel, "Coordinate file found");
else
setWarnText(xyLabel, "Not using any coordinate file");
}
void InfoWidget::freezeLabelSize() {
freezeWidth(projectLabel);
freezeWidth(rgfLabel);
freezeWidth(setLabel);
freezeWidth(xyLabel);
freezeWidth(trjLabel);
}
void InfoWidget::freezeWidth(QLabel* lbl) {
lbl->setFixedWidth(lbl->width());
}