Merge lp:~sibi-antony/stellarium/tui-enhancements into lp:stellarium

Proposed by Sibi Antony
Status: Merged
Approved by: Alexander Wolf
Approved revision: 5552
Merged at revision: 5572
Proposed branch: lp:~sibi-antony/stellarium/tui-enhancements
Merge into: lp:stellarium
Diff against target: 240 lines (+122/-27)
3 files modified
data/default_config.ini (+1/-0)
plugins/TextUserInterface/src/TextUserInterface.cpp (+106/-27)
plugins/TextUserInterface/src/TextUserInterface.hpp (+15/-0)
To merge this branch: bzr merge lp:~sibi-antony/stellarium/tui-enhancements
Reviewer Review Type Date Requested Status
Alexander Wolf Approve
Review via email: mp+121582@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alexander Wolf (alexwolf) wrote :

Well, code's enhancement look good but me really don't like implementation of shutdown.

Revision history for this message
Sibi Antony (sibi-antony) wrote :

Alexwolf: Thanks for the review!

Shutdown - In my humble opinion, the shutdown has to be left to the user to choose, as it is a platform specific operation. Also the only people who will use the shutdown option will be planetarium folks, who doesn't have the luxury of a keyboard+console or GUI during presentations.

So with this implementation, we give an interface wherein user can supply a shutdown command/script. The privileges required for the operation is to be set by the user.
Besides, this is one reason we call it 'Admin->shutdown'. It requires the user to be admin! :)

I can document on the new option in stellarium wiki. If you think there are better ways of implementing this, please let me know.

Revision history for this message
Alexander Wolf (alexwolf) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/default_config.ini'
2--- data/default_config.ini 2012-08-25 15:21:39 +0000
3+++ data/default_config.ini 2012-08-28 11:35:36 +0000
4@@ -179,6 +179,7 @@
5 flag_show_tui_datetime = false
6 flag_show_tui_short_obj_info = false
7 tui_font_size = 15
8+admin_shutdown_cmd = ""
9
10 [navigation]
11 auto_zoom_out_resets_direction = false
12
13=== modified file 'plugins/TextUserInterface/src/TextUserInterface.cpp'
14--- plugins/TextUserInterface/src/TextUserInterface.cpp 2012-02-21 14:20:52 +0000
15+++ plugins/TextUserInterface/src/TextUserInterface.cpp 2012-08-28 11:35:36 +0000
16@@ -35,6 +35,7 @@
17 #include "StelModuleMgr.hpp"
18 #include "StarMgr.hpp"
19 #include "StelMovementMgr.hpp"
20+#include "StelObjectMgr.hpp"
21 #include "StelSkyDrawer.hpp"
22 #include "ConstellationMgr.hpp"
23 #include "NebulaMgr.hpp"
24@@ -57,6 +58,8 @@
25 #include <QKeyEvent>
26 #include <QDebug>
27 #include <QLabel>
28+#include <QTime>
29+#include <QProcess>
30
31 /*************************************************************************
32 Utility functions
33@@ -471,7 +474,8 @@
34 TuiNode* m8_2 = new TuiNodeActivate(N_("Save current configuration"),
35 this, SLOT(saveDefaultSettings()),
36 m8, m8_1);
37- TuiNode* m8_3 = new TuiNode(N_("Shut down"), m8, m8_2);
38+ TuiNode* m8_3 = new TuiNodeActivate(N_("Shut down"), this, SLOT(shutDown()),
39+ m8, m8_2);
40 m8_1->setNextNode(m8_2);
41 m8_2->setNextNode(m8_3);
42 m8_3->setNextNode(m8_1);
43@@ -491,6 +495,9 @@
44 Q_ASSERT(conf);
45
46 font.setPixelSize(conf->value("tui/tui_font_size", 15).toInt());
47+ tuiDateTime = conf->value("tui/flag_show_tui_datetime", false).toBool();
48+ tuiObjInfo = conf->value("tui/flag_show_tui_short_obj_info", false).toBool();
49+ tuiGravityUi = conf->value("tui/flag_show_gravity_ui", false).toBool();
50 }
51
52 /*************************************************************************
53@@ -498,37 +505,103 @@
54 *************************************************************************/
55 void TextUserInterface::draw(StelCore* core)
56 {
57+ if (!tuiActive && !tuiDateTime && !tuiObjInfo)
58+ return;
59+
60+ int x = 0, y = 0;
61+ int xVc = 0, yVc = 0;
62+ int pixOffset = 15;
63+ int fovOffsetX = 0, fovOffsetY=0;
64+ bool fovMaskDisk = false;
65+
66+ StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
67+ if (gui->getVisible())
68+ {
69+ QGraphicsItem* bottomBar = dynamic_cast<QGraphicsItem*>(gui->getButtonBar());
70+ LeftStelBar* sideBar = gui->getWindowsButtonBar();
71+ x = (sideBar) ? sideBar->boundingRectNoHelpLabel().right() : 50;
72+ y = (bottomBar) ? bottomBar->boundingRect().height() : 50;
73+ }
74+
75+ // Alternate x,y for Disk viewport
76+ if (core->getProjection(StelCore::FrameJ2000)->getMaskType() == StelProjector::MaskDisk)
77+ {
78+ fovMaskDisk = true;
79+ StelProjector::StelProjectorParams projParams = core->getCurrentStelProjectorParams();
80+ xVc = projParams.viewportCenter[0];
81+ yVc = projParams.viewportCenter[1];
82+ fovOffsetX = projParams.viewportFovDiameter*std::sin(20)/2;
83+ fovOffsetY = projParams.viewportFovDiameter*std::cos(20)/2;
84+ }
85+ else
86+ {
87+ xVc = core->getProjection(StelCore::FrameJ2000)->getViewportWidth()/2;
88+ }
89+
90 if (tuiActive)
91 {
92- int x = 0, y = 0;
93- StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
94- if (gui->getVisible())
95- {
96- QGraphicsItem* bottomBar = dynamic_cast<QGraphicsItem*>(gui->getButtonBar());
97- LeftStelBar* sideBar = gui->getWindowsButtonBar();
98- x = (sideBar) ? sideBar->boundingRectNoHelpLabel().right() : 50;
99- y = (bottomBar) ? bottomBar->boundingRect().height() : 50;
100- }
101-
102- // Alternate x,y for Disk viewport
103- if (core->getProjection(StelCore::FrameJ2000)->getMaskType() == StelProjector::MaskDisk)
104- {
105- StelProjector::StelProjectorParams projParams = core->getCurrentStelProjectorParams();
106- x = projParams.viewportCenter[0] - projParams.viewportFovDiameter/2;
107- y = projParams.viewportCenter[1];
108- }
109-
110- x += 20;
111- y += 15;
112-
113+ int text_x = x + pixOffset, text_y = y + pixOffset;
114+ if (fovMaskDisk) {
115+ text_x = xVc - fovOffsetX + pixOffset;
116+ text_y = yVc - fovOffsetY + pixOffset;
117+ }
118+
119 QString tuiText = q_("[no TUI node]");
120- if (currentNode!=NULL)
121+ if (currentNode!=NULL) {
122 tuiText = currentNode->getDisplayText();
123+ }
124+
125+ StelPainter painter(core->getProjection(StelCore::FrameJ2000));
126+ painter.setFont(font);
127+ painter.setColor(0.3,1,0.3);
128+ painter.drawText(text_x, text_y, tuiText, 0, 0, 0, !tuiGravityUi);
129+ }
130+
131+ if (tuiDateTime)
132+ {
133+ double jd = core->getJDay();
134+ int text_x = x + xVc*2/3, text_y = y + pixOffset;
135+
136+ QString newDate = StelApp::getInstance().getLocaleMgr().getPrintableDateLocal(jd) + " "
137+ +StelApp::getInstance().getLocaleMgr().getPrintableTimeLocal(jd);
138+
139+ if (fovMaskDisk) {
140+ text_x = xVc + fovOffsetY - pixOffset;
141+ text_y = yVc - fovOffsetX + pixOffset;
142+ }
143
144 StelPainter painter(core->getProjection(StelCore::FrameAltAz));
145 painter.setFont(font);
146 painter.setColor(0.3,1,0.3);
147- painter.drawText(x, y, tuiText, 0, 0, 0, false);
148+ painter.drawText(text_x, text_y, newDate, 0, 0, 0, !tuiGravityUi);
149+ }
150+
151+ if (tuiObjInfo)
152+ {
153+ QString objInfo = "";
154+ StelObject::InfoStringGroup tuiInfo(StelObject::Name|StelObject::CatalogNumber
155+ |StelObject::Distance|StelObject::PlainText);
156+ int text_x = x + xVc*4/3, text_y = y + pixOffset;
157+
158+ QList<StelObjectP> selectedObj = GETSTELMODULE(StelObjectMgr)->getSelectedObject();
159+ if (selectedObj.isEmpty()) {
160+ objInfo = "";
161+ } else {
162+ objInfo = selectedObj[0]->getInfoString(core, tuiInfo);
163+ objInfo.replace("\n"," ");
164+ objInfo.replace("Distance:"," ");
165+ objInfo.replace("Light Years","ly");
166+ }
167+
168+ if (fovMaskDisk) {
169+ text_x = xVc + fovOffsetX - pixOffset;
170+ text_y = yVc + fovOffsetY - pixOffset;
171+ }
172+
173+ StelPainter painter(core->getProjection(StelCore::FrameJ2000));
174+ painter.setFont(font);
175+ painter.setColor(0.3,1,0.3);
176+ painter.drawText(text_x, text_y, objInfo, 0, 0, 0, !tuiGravityUi);
177 }
178 }
179
180@@ -739,6 +812,12 @@
181 qDebug() << "TextUserInterface::saveDefaultSettings done";
182 }
183
184-
185-
186-
187+void TextUserInterface::shutDown()
188+{
189+ QSettings* conf = StelApp::getInstance().getSettings();
190+ QString shutdownCmd = conf->value("tui/admin_shutdown_cmd", "").toString();
191+ int err;
192+ if (!(err = QProcess::execute(shutdownCmd))) {
193+ qDebug() << "[TextUserInterface] shutdown error, QProcess::execute():" << err;
194+ }
195+}
196
197=== modified file 'plugins/TextUserInterface/src/TextUserInterface.hpp'
198--- plugins/TextUserInterface/src/TextUserInterface.hpp 2012-02-19 11:43:38 +0000
199+++ plugins/TextUserInterface/src/TextUserInterface.hpp 2012-08-28 11:35:36 +0000
200@@ -21,6 +21,7 @@
201
202 #include "StelModule.hpp"
203 #include "DummyDialog.hpp"
204+
205 #include <QObject>
206 #include <QString>
207 #include <QFont>
208@@ -48,6 +49,16 @@
209 //! Loads the module's configuration from the config file.
210 void loadConfiguration(void);
211
212+public slots:
213+ //! Show/hide the TUI menu
214+ void setTuiMenuActive(bool tActive) { tuiActive = tActive;}
215+ //! Show/hide the TUI date time display
216+ void setTuiDateTime(bool tDateTime) { tuiDateTime = tDateTime; }
217+ //! Show/hide the selected object's short object information
218+ void setTuiObjInfo(bool tObjInfo) { tuiObjInfo = tObjInfo; }
219+ //! Set Gravity text for the TUI text
220+ void setTuiGravityUi(bool tGravityUi) { tuiGravityUi = tGravityUi; }
221+
222 private slots:
223 void setHomePlanet(QString planetName);
224 void setAltitude(int altitude);
225@@ -59,11 +70,15 @@
226 void setSkyCulture(QString i18);
227 void setAppLanguage(QString lang);
228 void saveDefaultSettings(void);
229+ void shutDown(void);
230
231 private:
232 DummyDialog dummyDialog;
233 QFont font;
234 bool tuiActive;
235+ bool tuiDateTime;
236+ bool tuiObjInfo;
237+ bool tuiGravityUi;
238 TuiNode* currentNode;
239
240 double getLatitude(void);