GlobeEngine
OverviewMapDialog.h
Go to the documentation of this file.
1 #ifndef ExoViewer_OverviewMapDialog_h
2 #define ExoViewer_OverviewMapDialog_h
3 
4 #include "OpenGL_Includes.h"
5 #include "System.h"
6 #include <QDialog>
7 #include <QVBoxLayout>
8 #include <QCompleter>
9 #include <QLineEdit>
10 #include <qwidget.h>
11 #include <qpainter.h>
12 #include <limits>
13 
14 namespace geExoViewer {
15  class OverviewMapDialog : public QDialog
16  {
17  Q_OBJECT
18 
19  public:
20  OverviewMapDialog(const std::vector<std::shared_ptr<geAstro::System>>& _systems, QWidget * parent = 0, Qt::WindowFlags f = 0);
22 
24  private:
25  QVBoxLayout* layout;
26  //RenderArea* windowWidget;
27 
28  private slots:
29  void tryToNavigate();
30 
31  //signals:
32  // void navigateToWrittenBody(std::string s);
33 
34  };
35 
36 
37  class RenderArea : public QWidget
38  {
39  public:
40  RenderArea(const std::vector<std::shared_ptr<geAstro::System>>& _systems, int _size, QWidget *parent = 0) : QWidget(parent){ systems = &_systems; size = _size; systemInFocus = NULL; };
41  void setSystemInFocus(std::shared_ptr<geAstro::System> _sif){
42  systemInFocus = _sif;
43  };
44  protected:
45  void paintEvent(QPaintEvent *event) {
46 
47  QPainter painter(this);
48  painter.setBrush(Qt::gray);
49  painter.drawRect(QRect(0, 0, width() - 1, height() - 1));
50 
51  //double minX = std::numeric_limits<double>::max();
52  //double maxX = 0.0;
53 
54  //double minY = std::numeric_limits<double>::max();
55  //double maxY = 0.0;
56 
57  double min = std::numeric_limits<double>::max();
58  double max = 0.0;
59 
60  for (int i = 1; i < systems->size(); i++){
61  //vmml::Vector3d pos = systems->at(i)->getPosition();
62  vmml::Vector3d pos = systems->at(i)->getWorldPosition();
63  //if (pos.x() > maxX){ maxX = pos.x(); }
64  //if (pos.x() < minX){ minX = pos.x(); }
65  //if (pos.y() > maxY){ maxY = pos.y(); }
66  //if (pos.y() < minY){ minY = pos.y(); }
67 
68  if (pos.x() > max){ max = pos.x(); }
69  if (pos.x() < min){ min = pos.x(); }
70  if (pos.y() > max){ max = pos.y(); }
71  if (pos.y() < min){ min = pos.y(); }
72  }
73 
74  int diameter = 4;
75  int margin = 10;
76 
77  int newUpperBound = size - margin;
78  int newLowerBound = 0 + margin;
79  //theoretical function: newXValue = ((0 - minX)/(maxX - minX))*(newUpperBound - newLowerBound) + newLowerBound
80 
81  for (int i = 1; i < systems->size(); i++){
82  //vmml::Vector3d pos = systems->at(i)->getPosition();
83  vmml::Vector3d pos = systems->at(i)->getWorldPosition();
84  painter.setPen(QColor(1.0, 0.0, 0.0, 1.0));
85  painter.setBrush(Qt::red);
86  //double x = ((pos.x() - minX) / (maxX - minX))*(newUpperBound - newLowerBound) + newLowerBound;
87  //double y = ((pos.y() - minY) / (maxY - minY))*(newUpperBound - newLowerBound) + newLowerBound;
88 
89  double x = ((pos.x() - min) / (max - min))*(newUpperBound - newLowerBound) + newLowerBound;
90  double y = ((pos.y() - min) / (max - min))*(newUpperBound - newLowerBound) + newLowerBound;
91 
92  painter.drawEllipse(QRectF(x + diameter / 2, y - diameter / 2, diameter, diameter));
93  }
94 
95  diameter += 2;
96  //special case for Solar System: blue!!
97  painter.setBrush(Qt::yellow);
98  painter.drawEllipse(QRectF(((0 - min) / (max - min))*(newUpperBound - newLowerBound) + newLowerBound + diameter / 2, ((0 - min) / (max - min))*(newUpperBound - newLowerBound) + newLowerBound - diameter / 2, diameter, diameter));
99 
100 
101  //special case for System in focus!!
102  if (systemInFocus != NULL){
103  painter.setBrush(Qt::blue);
104  painter.drawEllipse(QRectF(((systemInFocus->getWorldPosition().x() - min) / (max - min))*(newUpperBound - newLowerBound) + newLowerBound + diameter / 2, ((systemInFocus->getWorldPosition().y() - min) / (max - min))*(newUpperBound - newLowerBound) + newLowerBound - diameter / 2, diameter, diameter));
105  }
106 
107 
108  };
109 
110  private:
111  const std::vector<std::shared_ptr<geAstro::System>>* systems;
112 
113  std::shared_ptr<geAstro::System> systemInFocus;
114  int size;
115  };
116 }
117 #endif
RenderArea(const std::vector< std::shared_ptr< geAstro::System >> &_systems, int _size, QWidget *parent=0)
Definition: OverviewMapDialog.h:40
void setSystemInFocus(std::shared_ptr< geAstro::System > _sif)
Definition: OverviewMapDialog.h:41
void setSystemInFocus(geAstro::System *_sif)
Definition: OverviewMapDialog.cpp:25
Definition: OverviewMapDialog.h:37
OverviewMapDialog(const std::vector< std::shared_ptr< geAstro::System >> &_systems, QWidget *parent=0, Qt::WindowFlags f=0)
Definition: OverviewMapDialog.cpp:4
~OverviewMapDialog()
Definition: OverviewMapDialog.cpp:16
Definition: System.h:20
Definition: OverviewMapDialog.h:15
void paintEvent(QPaintEvent *event)
Definition: OverviewMapDialog.h:45
Definition: BodySelectionDialog.h:12