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
1=== modified file 'src/core/modules/CustomObjectMgr.cpp'
2--- src/core/modules/CustomObjectMgr.cpp 2017-03-13 11:34:19 +0000
3+++ src/core/modules/CustomObjectMgr.cpp 2017-05-07 00:45:47 +0000
4@@ -55,6 +55,7 @@
5
6 void CustomObjectMgr::handleMouseClicks(class QMouseEvent* e)
7 {
8+ // Shift + LeftClick
9 if (e->modifiers().testFlag(Qt::ShiftModifier) && e->button()==Qt::LeftButton && e->type()==QEvent::MouseButtonPress)
10 {
11 // Add custom marker
12@@ -62,8 +63,8 @@
13
14 QPoint p = StelMainView::getInstance().getMousePos(); // get screen coordinates of mouse cursor
15 Vec3d mousePosition;
16- float wh = prj->getViewportWidth()/2.; // get half of width of the screen
17- float hh = prj->getViewportHeight()/2.; // get half of height of the screen
18+ float wh = prj->getViewportWidth()/2.; // get quarter of width of the screen
19+ float hh = prj->getViewportHeight()/2.; // get quarter of height of the screen
20 float mx = p.x()-wh; // point 0 in center of the screen, axis X directed to right
21 float my = p.y()-hh; // point 0 in center of the screen, axis Y directed to bottom
22 // calculate position of mouse cursor via position of center of the screen (and invert axis Y)
23@@ -81,13 +82,62 @@
24 e->setAccepted(true);
25 return;
26 }
27- if (e->modifiers().testFlag(Qt::ShiftModifier) && e->button()==Qt::RightButton && e->type()==QEvent::MouseButtonPress)
28- {
29- // Delete custom markers
30+
31+ // Shift + Alt + Right click -- Removes all custom markers
32+ // Changed by snowsailor 5/04/2017
33+ if(e->modifiers().testFlag(Qt::ShiftModifier) && e->modifiers().testFlag(Qt::AltModifier) && e->button() == Qt::RightButton && e->type() == QEvent::MouseButtonPress) {
34+ //Delete ALL custom markers
35 removeCustomObjects();
36 e->setAccepted(true);
37 return;
38 }
39+ // Shift + RightClick
40+ // Added by snowsailor 5/04/2017 -- Removes the closest marker within a radius specified within
41+ if (e->modifiers().testFlag(Qt::ShiftModifier) && e->button()==Qt::RightButton && e->type()==QEvent::MouseButtonPress) {
42+ //Limit the click radius to 15px in any direction
43+ int radiusLimit = 15;
44+
45+ StelCore *core = StelApp::getInstance().getCore();
46+ const StelProjectorP prj = StelApp::getInstance().getCore()->getProjection(StelCore::FrameJ2000, StelCore::RefractionAuto);
47+
48+ QPoint p = StelMainView::getInstance().getMousePos(); // get screen coordinates of mouse cursor
49+ Vec3d mousePosition;
50+ float wh = prj->getViewportWidth()/2.; // get half of width of the screen
51+ float hh = prj->getViewportHeight()/2.; // get half of height of the screen
52+ float mx = p.x()-wh; // point 0 in center of the screen, axis X directed to right
53+ float my = p.y()-hh; // point 0 in center of the screen, axis Y directed to bottom
54+ // calculate position of mouse cursor via position of center of the screen (and invert axis Y)
55+ prj->unProject(prj->getViewportPosX()+wh+mx, prj->getViewportPosY()+hh+1-my, mousePosition);
56+
57+ Vec3d winpos;
58+ prj->project(mousePosition, winpos);
59+ float xpos = winpos[0];
60+ float ypos = winpos[1];
61+
62+ CustomObjectP closest;
63+ //Smallest valid radius will be at most `radiusLimit`, so radiusLimit + 10 is plenty as the default
64+ float smallestRad = radiusLimit + 10;
65+ foreach(CustomObjectP cObj, customObjects) {
66+ //Get the position of the custom object
67+ Vec3d a = cObj->getJ2000EquatorialPos(core);
68+ prj->project(a, winpos);
69+ //Distance formula to determine how close we clicked to each of the custom objects
70+ float dist = std::sqrt(((xpos-winpos[0])*(xpos-winpos[0])) + ((ypos-winpos[1])*(ypos-winpos[1])));
71+ //If the position of the object is within our click radius
72+ if(dist <= radiusLimit && dist < smallestRad) {
73+ //Update the closest object and the smallest distance.
74+ closest = cObj;
75+ smallestRad = dist;
76+ }
77+ }
78+ //If there was a custom object within `radiusLimit` pixels...
79+ if(smallestRad <= radiusLimit) {
80+ //Remove it and return
81+ removeCustomObject(closest);
82+ e->setAccepted(true);
83+ return;
84+ }
85+ }
86 e->setAccepted(false);
87 }
88
89@@ -160,9 +210,26 @@
90 {
91 setSelected("");
92 customObjects.clear();
93+ //This marker count can be set to 0 because there will be no markers left and a duplicate will be impossible
94 countMarkers = 0;
95 }
96
97+void CustomObjectMgr::removeCustomObject(CustomObjectP obj) {
98+ setSelected("");
99+ int i = 0;
100+ foreach(const CustomObjectP& cObj, customObjects) {
101+ //If we have a match for the thing we want to delete
102+ if(cObj && cObj == obj && cObj->initialized) {
103+ //Remove the value at the current index and exit loop
104+ customObjects.removeAt(i);
105+ break;
106+ }
107+ i++;
108+ }
109+ //Don't decrememnt marker count. This will prevent multiple markers from being added with the same name.
110+ //countMarkers -= 1;
111+}
112+
113 void CustomObjectMgr::draw(StelCore* core)
114 {
115 StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
116
117=== modified file 'src/core/modules/CustomObjectMgr.hpp'
118--- src/core/modules/CustomObjectMgr.hpp 2016-12-11 14:23:57 +0000
119+++ src/core/modules/CustomObjectMgr.hpp 2017-05-07 00:45:47 +0000
120@@ -124,6 +124,8 @@
121 void addCustomObjectAltAzi(QString designation, const QString& alt, const QString& azi, bool isVisible=false);
122 //! Remove all custom objects
123 void removeCustomObjects();
124+ //! Remove just one custom object
125+ void removeCustomObject(CustomObjectP);
126
127 //! Set the color used to draw custom object markers.
128 //! @param c The color of the custom object markers (R,G,B)