Enable focus node change

Show instruments
This commit is contained in:
Alexander Bock
2015-05-04 10:02:47 +02:00
parent 14270b316e
commit 810480d5d8
4 changed files with 66 additions and 12 deletions

View File

@@ -47,6 +47,20 @@ namespace {
{ "2015-07-14T12:04:35.00", "PlutoProjection", "Pluto" },
{ "2015-07-14T15:02:46.00", "PlutoProjection", "Pluto" }
};
struct FocusNode {
QString guiName;
QString name;
QString coordinateSystem;
};
const FocusNode FocusNodes[] = {
{ "Earth", "Earth", "Sun" },
{ "Sun", "Sun", "Sun" },
{ "Pluto", "PlutoProjection", "Pluto" },
{ "Charon", "Charon", "Pluto" },
{ "Jupiter", "JupiterProjection", "Jupiter" },
{ "New Horizons", "NewHorizons", ""}
};
}
ControlWidget::ControlWidget(QWidget* parent)
@@ -59,6 +73,7 @@ ControlWidget::ControlWidget(QWidget* parent)
, _pause(new QPushButton("||"))
, _play(new QPushButton("|>"))
, _forward(new QPushButton(">>"))
, _focusNode(new QComboBox)
{
for (const ImportantDate& d : ImportantDates)
_setTime->addItem(d.date);
@@ -69,6 +84,14 @@ ControlWidget::ControlWidget(QWidget* parent)
SLOT(onDateChange())
);
for (const FocusNode& f : FocusNodes)
_focusNode->addItem(f.guiName);
QObject::connect(
_focusNode,
SIGNAL(currentIndexChanged(int)),
this,
SLOT(onFocusChange())
);
_setDelta->setMinimum(-100);
_setDelta->setMaximum(100);
@@ -124,6 +147,8 @@ ControlWidget::ControlWidget(QWidget* parent)
controlContainer->setLayout(controlContainerLayout);
layout->addWidget(controlContainer, 3, 0, 1, 2);
layout->addWidget(_focusNode, 4, 0, 1, 2);
setLayout(layout);
}
@@ -167,7 +192,23 @@ void ControlWidget::onDateChange() {
"openspace.time.setTime('" + date + "');\
openspace.setOrigin('" + focus + "');\
openspace.changeCoordinateSystem('" + coordinateSystem + "');";
//QString script =
// "openspace.setOrigin('" + focus + "');";
emit scriptActivity(script);
}
void ControlWidget::onFocusChange() {
int index = _focusNode->currentIndex();
QString name = FocusNodes[index].name;
QString coordinateSystem = FocusNodes[index].coordinateSystem;
if (coordinateSystem.isEmpty()) {
int date = _currentTime->text().left(4).toInt();
if (date < 2008)
coordinateSystem = "Jupiter";
else if (date < 2014)
coordinateSystem = "Sun";
else
coordinateSystem = "Pluto";
}
QString script = "openspace.setOrigin('" + name + "');openspace.changeCoordinateSystem('" + coordinateSystem + "');";
emit scriptActivity(script);
}

View File

@@ -45,6 +45,7 @@ signals:
private slots:
void onValueChange();
void onDateChange();
void onFocusChange();
void onRewindButton();
void onPauseButton();
void onPlayButton();
@@ -60,8 +61,7 @@ private:
QPushButton* _pause;
QPushButton* _play;
QPushButton* _forward;
bool _stateNoNotification = false;
QComboBox* _focusNode;
};
#endif // __CONTROLWIDGET_H__

View File

@@ -188,19 +188,32 @@ void TimelineWidget::drawImages(
{
int width = rect.width();
for (std::vector<Image>::const_iterator cur = beginning; cur != ending; ++cur) {
for (std::vector<Image>::const_iterator cur = beginning; cur <= ending; ++cur) {
//double tBeg = (cur->beginning - minimumTime) / (maximumTime - minimumTime);
//double tEnd = (cur->ending - minimumTime) / (maximumTime - minimumTime);
double t = (cur->beginning - minimumTime) / (maximumTime - minimumTime);
int loc = rect.top() + rect.height() * t;
int height = 25;
//int begin = rect.top() + rect.height() * tBeg;
//int end = rect.top() + rect.height() * tEnd;
std::string target = cur->target;
auto it = std::find(_targets.begin(), _targets.end(), target);
int iTarget = std::distance(_targets.begin(), it);
QColor targetColor = targetColors[iTarget];
//painter.drawRect(begin, 0, width, end);
painter.drawLine(QPointF(0, loc), QPointF(rect.width(), loc));
std::vector<std::string> instruments = cur->instruments;
std::vector<QColor> colors;
for (std::string instrument : instruments) {
auto it = std::find(_instruments.begin(), _instruments.end(), instrument);
int i = std::distance(_instruments.begin(), it);
colors.push_back(instrumentColors[i]);
}
painter.setBrush(QBrush(targetColor));
if (colors.empty()))
painter.setPen(QPen(Qt::black));
else
painter.setPen(QPen(colors[0]));
painter.drawRect(0, loc, rect.width(), height);
}
}