Merge lp:~snowsailor/stellarium/stellarium into lp:stellarium

Proposed by Snow Sailor
Status: Merged
Merged at revision: 9337
Proposed branch: lp:~snowsailor/stellarium/stellarium
Merge into: lp:stellarium
Diff against target: 128 lines (+74/-5)
2 files modified
src/core/modules/CustomObjectMgr.cpp (+72/-5)
src/core/modules/CustomObjectMgr.hpp (+2/-0)
To merge this branch: bzr merge lp:~snowsailor/stellarium/stellarium
Reviewer Review Type Date Requested Status
Alexander Wolf Approve
gzotti Approve
Review via email: mp+323720@code.launchpad.net

Description of the change

Allow custom markers to be removed with a Shift+RightClick within a 15-pixel radius. A click that is 7 pixels away from Marker 1 and 8 pixels away from Marker 2 will result in Marker 1 being removed (it is closer to the click).

All markers can still be removed with Shift+Alt+RightClick.

The two lines that were changed to say "quarter of the screen" from "half the screen" are incorrect. I had changed them to test some other stuff and forgot to change the comments back to what they were.

To post a comment you must log in.
Revision history for this message
gzotti (georg-zotti) wrote :

Nice new feature, thanks. I approve this change alone, but would welcome if you can also solve the Retina-related pixel coordinate bug you reported (https://bugs.launchpad.net/stellarium/+bug/1688985).

review: Approve
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
=== modified file 'src/core/modules/CustomObjectMgr.cpp'
--- src/core/modules/CustomObjectMgr.cpp 2017-03-13 11:34:19 +0000
+++ src/core/modules/CustomObjectMgr.cpp 2017-05-07 00:45:47 +0000
@@ -55,6 +55,7 @@
5555
56void CustomObjectMgr::handleMouseClicks(class QMouseEvent* e)56void CustomObjectMgr::handleMouseClicks(class QMouseEvent* e)
57{57{
58 // Shift + LeftClick
58 if (e->modifiers().testFlag(Qt::ShiftModifier) && e->button()==Qt::LeftButton && e->type()==QEvent::MouseButtonPress)59 if (e->modifiers().testFlag(Qt::ShiftModifier) && e->button()==Qt::LeftButton && e->type()==QEvent::MouseButtonPress)
59 {60 {
60 // Add custom marker61 // Add custom marker
@@ -62,8 +63,8 @@
6263
63 QPoint p = StelMainView::getInstance().getMousePos(); // get screen coordinates of mouse cursor64 QPoint p = StelMainView::getInstance().getMousePos(); // get screen coordinates of mouse cursor
64 Vec3d mousePosition;65 Vec3d mousePosition;
65 float wh = prj->getViewportWidth()/2.; // get half of width of the screen66 float wh = prj->getViewportWidth()/2.; // get quarter of width of the screen
66 float hh = prj->getViewportHeight()/2.; // get half of height of the screen67 float hh = prj->getViewportHeight()/2.; // get quarter of height of the screen
67 float mx = p.x()-wh; // point 0 in center of the screen, axis X directed to right68 float mx = p.x()-wh; // point 0 in center of the screen, axis X directed to right
68 float my = p.y()-hh; // point 0 in center of the screen, axis Y directed to bottom69 float my = p.y()-hh; // point 0 in center of the screen, axis Y directed to bottom
69 // calculate position of mouse cursor via position of center of the screen (and invert axis Y)70 // calculate position of mouse cursor via position of center of the screen (and invert axis Y)
@@ -81,13 +82,62 @@
81 e->setAccepted(true);82 e->setAccepted(true);
82 return;83 return;
83 }84 }
84 if (e->modifiers().testFlag(Qt::ShiftModifier) && e->button()==Qt::RightButton && e->type()==QEvent::MouseButtonPress)85
85 {86 // Shift + Alt + Right click -- Removes all custom markers
86 // Delete custom markers87 // Changed by snowsailor 5/04/2017
88 if(e->modifiers().testFlag(Qt::ShiftModifier) && e->modifiers().testFlag(Qt::AltModifier) && e->button() == Qt::RightButton && e->type() == QEvent::MouseButtonPress) {
89 //Delete ALL custom markers
87 removeCustomObjects();90 removeCustomObjects();
88 e->setAccepted(true);91 e->setAccepted(true);
89 return;92 return;
90 }93 }
94 // Shift + RightClick
95 // Added by snowsailor 5/04/2017 -- Removes the closest marker within a radius specified within
96 if (e->modifiers().testFlag(Qt::ShiftModifier) && e->button()==Qt::RightButton && e->type()==QEvent::MouseButtonPress) {
97 //Limit the click radius to 15px in any direction
98 int radiusLimit = 15;
99
100 StelCore *core = StelApp::getInstance().getCore();
101 const StelProjectorP prj = StelApp::getInstance().getCore()->getProjection(StelCore::FrameJ2000, StelCore::RefractionAuto);
102
103 QPoint p = StelMainView::getInstance().getMousePos(); // get screen coordinates of mouse cursor
104 Vec3d mousePosition;
105 float wh = prj->getViewportWidth()/2.; // get half of width of the screen
106 float hh = prj->getViewportHeight()/2.; // get half of height of the screen
107 float mx = p.x()-wh; // point 0 in center of the screen, axis X directed to right
108 float my = p.y()-hh; // point 0 in center of the screen, axis Y directed to bottom
109 // calculate position of mouse cursor via position of center of the screen (and invert axis Y)
110 prj->unProject(prj->getViewportPosX()+wh+mx, prj->getViewportPosY()+hh+1-my, mousePosition);
111
112 Vec3d winpos;
113 prj->project(mousePosition, winpos);
114 float xpos = winpos[0];
115 float ypos = winpos[1];
116
117 CustomObjectP closest;
118 //Smallest valid radius will be at most `radiusLimit`, so radiusLimit + 10 is plenty as the default
119 float smallestRad = radiusLimit + 10;
120 foreach(CustomObjectP cObj, customObjects) {
121 //Get the position of the custom object
122 Vec3d a = cObj->getJ2000EquatorialPos(core);
123 prj->project(a, winpos);
124 //Distance formula to determine how close we clicked to each of the custom objects
125 float dist = std::sqrt(((xpos-winpos[0])*(xpos-winpos[0])) + ((ypos-winpos[1])*(ypos-winpos[1])));
126 //If the position of the object is within our click radius
127 if(dist <= radiusLimit && dist < smallestRad) {
128 //Update the closest object and the smallest distance.
129 closest = cObj;
130 smallestRad = dist;
131 }
132 }
133 //If there was a custom object within `radiusLimit` pixels...
134 if(smallestRad <= radiusLimit) {
135 //Remove it and return
136 removeCustomObject(closest);
137 e->setAccepted(true);
138 return;
139 }
140 }
91 e->setAccepted(false);141 e->setAccepted(false);
92}142}
93143
@@ -160,9 +210,26 @@
160{210{
161 setSelected("");211 setSelected("");
162 customObjects.clear();212 customObjects.clear();
213 //This marker count can be set to 0 because there will be no markers left and a duplicate will be impossible
163 countMarkers = 0;214 countMarkers = 0;
164}215}
165216
217void CustomObjectMgr::removeCustomObject(CustomObjectP obj) {
218 setSelected("");
219 int i = 0;
220 foreach(const CustomObjectP& cObj, customObjects) {
221 //If we have a match for the thing we want to delete
222 if(cObj && cObj == obj && cObj->initialized) {
223 //Remove the value at the current index and exit loop
224 customObjects.removeAt(i);
225 break;
226 }
227 i++;
228 }
229 //Don't decrememnt marker count. This will prevent multiple markers from being added with the same name.
230 //countMarkers -= 1;
231}
232
166void CustomObjectMgr::draw(StelCore* core)233void CustomObjectMgr::draw(StelCore* core)
167{234{
168 StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);235 StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
169236
=== modified file 'src/core/modules/CustomObjectMgr.hpp'
--- src/core/modules/CustomObjectMgr.hpp 2016-12-11 14:23:57 +0000
+++ src/core/modules/CustomObjectMgr.hpp 2017-05-07 00:45:47 +0000
@@ -124,6 +124,8 @@
124 void addCustomObjectAltAzi(QString designation, const QString& alt, const QString& azi, bool isVisible=false);124 void addCustomObjectAltAzi(QString designation, const QString& alt, const QString& azi, bool isVisible=false);
125 //! Remove all custom objects125 //! Remove all custom objects
126 void removeCustomObjects();126 void removeCustomObjects();
127 //! Remove just one custom object
128 void removeCustomObject(CustomObjectP);
127129
128 //! Set the color used to draw custom object markers.130 //! Set the color used to draw custom object markers.
129 //! @param c The color of the custom object markers (R,G,B)131 //! @param c The color of the custom object markers (R,G,B)