CustomObjectMgr.cpp   CustomObjectMgr.cpp 
skipping to change at line 28 skipping to change at line 28
#include "StelPainter.hpp" #include "StelPainter.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelTextureMgr.hpp" #include "StelTextureMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "StelMainView.hpp"
#include "CustomObjectMgr.hpp" #include "CustomObjectMgr.hpp"
#include <QSettings> #include <QSettings>
#include <QKeyEvent> #include <QKeyEvent>
CustomObjectMgr::CustomObjectMgr() CustomObjectMgr::CustomObjectMgr()
: countMarkers(0) : countMarkers(0)
, radiusLimit(15)
{ {
setObjectName("CustomObjectMgr"); setObjectName("CustomObjectMgr");
conf = StelApp::getInstance().getSettings(); conf = StelApp::getInstance().getSettings();
font.setPixelSize(StelApp::getInstance().getBaseFontSize()); font.setPixelSize(StelApp::getInstance().getBaseFontSize());
} }
CustomObjectMgr::~CustomObjectMgr() CustomObjectMgr::~CustomObjectMgr()
{ {
StelApp::getInstance().getStelObjectMgr().unSelect(); StelApp::getInstance().getStelObjectMgr().unSelect();
} }
skipping to change at line 58 skipping to change at line 58
{ {
if (actionName==StelModule::ActionDraw) if (actionName==StelModule::ActionDraw)
return StelApp::getInstance().getModuleMgr().getModule("Land scapeMgr")->getCallOrder(actionName)+10.; return StelApp::getInstance().getModuleMgr().getModule("Land scapeMgr")->getCallOrder(actionName)+10.;
if (actionName==StelModule::ActionHandleMouseClicks) if (actionName==StelModule::ActionHandleMouseClicks)
return -11; return -11;
return 0; return 0;
} }
void CustomObjectMgr::handleMouseClicks(class QMouseEvent* e) void CustomObjectMgr::handleMouseClicks(class QMouseEvent* e)
{ {
StelCore *core = StelApp::getInstance().getCore();
Vec3d mousePosition = core->getMouseJ2000Pos();
// Shift + LeftClick
if (e->modifiers().testFlag(Qt::ShiftModifier) && e->button()==Qt::L eftButton && e->type()==QEvent::MouseButtonPress) if (e->modifiers().testFlag(Qt::ShiftModifier) && e->button()==Qt::L eftButton && e->type()==QEvent::MouseButtonPress)
{ {
// Add custom marker // Add custom marker
const StelProjectorP prj = StelApp::getInstance().getCore()- >getProjection(StelCore::FrameJ2000, StelCore::RefractionAuto); addCustomObject(QString("%1 %2").arg(N_("Marker")).arg(count Markers + 1), mousePosition, true);
QPoint p = StelMainView::getInstance().getMousePos(); // get
screen coordinates of mouse cursor
Vec3d mousePosition;
float wh = prj->getViewportWidth()/2.; // get half of width
of the screen
float hh = prj->getViewportHeight()/2.; // get half of heigh
t of the screen
float mx = p.x()-wh; // point 0 in center of the screen, axi
s X directed to right
float my = p.y()-hh; // point 0 in center of the screen, axi
s Y directed to bottom
// calculate position of mouse cursor via position of center
of the screen (and invert axis Y)
// If coordinates are invalid, don't draw them.
bool coordsValid = prj->unProject(prj->getViewportPosX()+wh+
mx, prj->getViewportPosY()+hh+1-my, mousePosition);
if (coordsValid)
{ // Nick Fedoseev patch
Vec3d win;
prj->project(mousePosition,win);
float dx = prj->getViewportPosX()+wh+mx - win.v[0];
float dy = prj->getViewportPosY()+hh+1-my - win.v[1]
;
prj->unProject(prj->getViewportPosX()+wh+mx+dx, prj-
>getViewportPosY()+hh+1-my+dy, mousePosition);
addCustomObject(QString("%1 %2").arg(N_("Marker")).a
rg(countMarkers + 1), mousePosition, true);
}
e->setAccepted(true); e->setAccepted(true);
return; return;
} }
if (e->modifiers().testFlag(Qt::ShiftModifier) && e->button()==Qt::R // Shift + Alt + Right click -- Removes all custom markers
ightButton && e->type()==QEvent::MouseButtonPress) // Changed by snowsailor 5/04/2017
if(e->modifiers().testFlag(Qt::ShiftModifier) && e->modifiers().test
Flag(Qt::AltModifier) && e->button() == Qt::RightButton && e->type() == QEv
ent::MouseButtonPress)
{ {
// Delete custom markers //Delete ALL custom markers
removeCustomObjects(); removeCustomObjects();
e->setAccepted(true); e->setAccepted(true);
return; return;
} }
// Shift + RightClick
// Added by snowsailor 5/04/2017 -- Removes the closest marker withi
n a radius specified within
if (e->modifiers().testFlag(Qt::ShiftModifier) && e->button()==Qt::R
ightButton && e->type()==QEvent::MouseButtonPress)
{
const StelProjectorP prj = core->getProjection(StelCore::Fra
meJ2000, StelCore::RefractionAuto);
Vec3d winpos;
prj->project(mousePosition, winpos);
float xpos = winpos[0];
float ypos = winpos[1];
CustomObjectP closest;
//Smallest valid radius will be at most `radiusLimit`, so ra
diusLimit + 10 is plenty as the default
float smallestRad = radiusLimit + 10;
foreach(CustomObjectP cObj, customObjects)
{
//Get the position of the custom object
Vec3d a = cObj->getJ2000EquatorialPos(core);
prj->project(a, winpos);
//Distance formula to determine how close we clicked
to each of the custom objects
float dist = std::sqrt(((xpos-winpos[0])*(xpos-winpo
s[0])) + ((ypos-winpos[1])*(ypos-winpos[1])));
//If the position of the object is within our click
radius
if(dist <= radiusLimit && dist < smallestRad)
{
//Update the closest object and the smallest
distance.
closest = cObj;
smallestRad = dist;
}
}
//If there was a custom object within `radiusLimit` pixels..
.
if(smallestRad <= radiusLimit)
{
//Remove it and return
removeCustomObject(closest);
e->setAccepted(true);
return;
}
}
e->setAccepted(false); e->setAccepted(false);
} }
void CustomObjectMgr::init() void CustomObjectMgr::init()
{ {
texPointer = StelApp::getInstance().getTextureManager().createTextur e(StelFileMgr::getInstallationDir()+"/textures/pointeur2.png"); texPointer = StelApp::getInstance().getTextureManager().createTextur e(StelFileMgr::getInstallationDir()+"/textures/pointeur2.png");
customObjects.clear(); customObjects.clear();
setMarkersColor(StelUtils::strToVec3f(conf->value("color/custom_mark er_color", "0.1,1.0,0.1").toString())); setMarkersColor(StelUtils::strToVec3f(conf->value("color/custom_mark er_color", "0.1,1.0,0.1").toString()));
setMarkersSize(conf->value("gui/custom_marker_size", 5.f).toFloat()) ; setMarkersSize(conf->value("gui/custom_marker_size", 5.f).toFloat()) ;
// Limit the click radius to 15px in any direction
setActiveRadiusLimit(conf->value("gui/custom_marker_radius_limit", 1
5).toInt());
GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this); GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this);
} }
void CustomObjectMgr::deinit() void CustomObjectMgr::deinit()
{ {
customObjects.clear(); customObjects.clear();
texPointer.clear(); texPointer.clear();
} }
skipping to change at line 163 skipping to change at line 189
StelUtils::spheToRect(dAzi, dAlt, aim); StelUtils::spheToRect(dAzi, dAlt, aim);
addCustomObject(designation, StelApp::getInstance().getCore()->altAz ToJ2000(aim, StelCore::RefractionAuto), isVisible); addCustomObject(designation, StelApp::getInstance().getCore()->altAz ToJ2000(aim, StelCore::RefractionAuto), isVisible);
} }
void CustomObjectMgr::removeCustomObjects() void CustomObjectMgr::removeCustomObjects()
{ {
setSelected(""); setSelected("");
customObjects.clear(); customObjects.clear();
//This marker count can be set to 0 because there will be no markers left and a duplicate will be impossible
countMarkers = 0; countMarkers = 0;
} }
void CustomObjectMgr::removeCustomObject(CustomObjectP obj)
{
setSelected("");
customObjects.removeOne(obj);
}
void CustomObjectMgr::removeCustomObject(QString englishName)
{
setSelected("");
foreach(const CustomObjectP& cObj, customObjects)
{
//If we have a match for the thing we want to delete
if(cObj && cObj->getEnglishName()==englishName && cObj->init
ialized)
customObjects.removeOne(cObj);
}
}
void CustomObjectMgr::draw(StelCore* core) void CustomObjectMgr::draw(StelCore* core)
{ {
StelProjectorP prj = core->getProjection(StelCore::FrameJ2000); StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
StelPainter painter(prj); StelPainter painter(prj);
painter.setFont(font); painter.setFont(font);
foreach (const CustomObjectP& cObj, customObjects) foreach (const CustomObjectP& cObj, customObjects)
{ {
if (cObj && cObj->initialized) if (cObj && cObj->initialized)
cObj->draw(core, &painter); cObj->draw(core, &painter);
skipping to change at line 239 skipping to change at line 283
} }
StelObjectP CustomObjectMgr::searchByName(const QString& englishName) const StelObjectP CustomObjectMgr::searchByName(const QString& englishName) const
{ {
foreach(const CustomObjectP& cObj, customObjects) foreach(const CustomObjectP& cObj, customObjects)
{ {
if (cObj->getEnglishName().toUpper() == englishName.toUpper( )) if (cObj->getEnglishName().toUpper() == englishName.toUpper( ))
return qSharedPointerCast<StelObject>(cObj); return qSharedPointerCast<StelObject>(cObj);
} }
return NULL; return Q_NULLPTR;
} }
StelObjectP CustomObjectMgr::searchByNameI18n(const QString& nameI18n) cons t StelObjectP CustomObjectMgr::searchByNameI18n(const QString& nameI18n) cons t
{ {
foreach(const CustomObjectP& cObj, customObjects) foreach(const CustomObjectP& cObj, customObjects)
{ {
if (cObj->getNameI18n().toUpper() == nameI18n.toUpper()) if (cObj->getNameI18n().toUpper() == nameI18n.toUpper())
return qSharedPointerCast<StelObject>(cObj); return qSharedPointerCast<StelObject>(cObj);
} }
return NULL; return Q_NULLPTR;
} }
QStringList CustomObjectMgr::listMatchingObjects(const QString& objPrefix, int maxNbItem, bool useStartOfWords, bool inEnglish) const QStringList CustomObjectMgr::listMatchingObjects(const QString& objPrefix, int maxNbItem, bool useStartOfWords, bool inEnglish) const
{ {
return StelObjectModule::listMatchingObjects(objPrefix, maxNbItem, u seStartOfWords, inEnglish); return StelObjectModule::listMatchingObjects(objPrefix, maxNbItem, u seStartOfWords, inEnglish);
} }
QStringList CustomObjectMgr::listAllObjects(bool inEnglish) const QStringList CustomObjectMgr::listAllObjects(bool inEnglish) const
{ {
QStringList result; QStringList result;
skipping to change at line 334 skipping to change at line 378
void CustomObjectMgr::setMarkersSize(const float size) void CustomObjectMgr::setMarkersSize(const float size)
{ {
CustomObject::markerSize = size; CustomObject::markerSize = size;
} }
float CustomObjectMgr::getMarkersSize() const float CustomObjectMgr::getMarkersSize() const
{ {
return CustomObject::markerSize; return CustomObject::markerSize;
} }
void CustomObjectMgr::setActiveRadiusLimit(const int radius)
{
radiusLimit = radius;
}
 End of changes. 14 change blocks. 
35 lines changed or deleted 81 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/