Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions data/gui/normalStyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ QFrame[frameShape="5"] { /* QFrame::VLine == 0x0005 */
border: 1px solid rgb(31, 31, 31);
}

#StelToolTip,
QToolTip {
color: rgb(4, 5, 9);
font-size: 100%;
padding: 2px;
background: rgb(143, 143, 143);
border: 1px solid rgb(0, 0, 0);
}

*[nightMode="true"] QToolTip {
Expand Down
47 changes: 47 additions & 0 deletions src/StelMainView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <QGuiApplication>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsAnchorLayout>
#include <QGraphicsProxyWidget>
#include <QGraphicsWidget>
#include <QGraphicsEffect>
#include <QFileInfo>
Expand Down Expand Up @@ -349,6 +350,47 @@ class StelGraphicsScene : public QGraphicsScene
//pass event on to items otherwise
QGraphicsScene::keyPressEvent(event);
}
void helpEvent(QGraphicsSceneHelpEvent* event) override
{
const QPoint pos(parent->mapFromGlobal(event->screenPos()));
QList<QGraphicsItem*> itemsToCheck;
if (parent->isTransformed())
{
const auto xform = parent->viewportTransform();
itemsToCheck = items(xform.inverted().map(pos), Qt::IntersectsItemShape,
Qt::DescendingOrder, xform);
}
else
{
itemsToCheck = items(pos, Qt::IntersectsItemShape, Qt::DescendingOrder);
}
QString text;
QPoint point;
for (auto*const item : itemsToCheck)
{
if (const auto proxy = dynamic_cast<QGraphicsProxyWidget*>(item))
{
const auto itemWidget = proxy->widget();
if (!itemWidget) continue;
const auto child = itemWidget->childAt(pos);
if (child && !child->toolTip().isEmpty())
{
text = child->toolTip();
point = pos;
break;
}
}
if (!item->toolTip().isEmpty())
{
text = item->toolTip();
point = pos;
break;
}
}

parent->showToolTip(point, text);
event->setAccepted(!text.isEmpty());
}

private:
StelMainView* parent;
Expand Down Expand Up @@ -1990,6 +2032,11 @@ Vec3f StelMainView::getSkyBackgroundColor() const
return rootItem->getSkyBackgroundColor();
}

void StelMainView::showToolTip(const QPoint& scenePos, const QString& text)
{
gui->showToolTip(scenePos, text);
}

QRectF StelMainView::setWindowSize(int width, int height)
{
// Make sure to leave fullscreen if necessary.
Expand Down
2 changes: 2 additions & 0 deletions src/StelMainView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ public slots:
//! Get the sky background color. (Actually retrieves from the StelRootItem.) Everything else than black creates a work of art!
Vec3f getSkyBackgroundColor() const;

void showToolTip(const QPoint& scenePos, const QString& text);

protected:
//! Hack to determine current monitor pixel ratio
//! @todo Find a better way to handle this
Expand Down
2 changes: 2 additions & 0 deletions src/core/StelGuiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class StelGuiBase

virtual void init(QGraphicsWidget *atopLevelGraphicsWidget);

virtual void showToolTip(const QPoint& scenePos, const QString& text) = 0;

//! Load color scheme matching the section name.
virtual void setStelStyle(const QString& section) =0;

Expand Down
7 changes: 7 additions & 0 deletions src/gui/StelGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ void StelGui::init(QGraphicsWidget *atopLevelGraphicsWidget)
astroCalcDialog = new AstroCalcDialog(atopLevelGraphicsWidget);
obsListDialog = new ObsListDialog(atopLevelGraphicsWidget);

toolTip = new StelToolTip(atopLevelGraphicsWidget);

///////////////////////////////////////////////////////////////////////
// Create all the main actions of the program, associated with shortcuts

Expand Down Expand Up @@ -646,6 +648,11 @@ void StelGui::update()
}
}

void StelGui::showToolTip(const QPoint& scenePos, const QString& text)
{
toolTip->showToolTip(scenePos, text);
}

void StelGui::displayAllInfo()
{
setInfoTextFilters(StelObject::InfoStringGroup(StelObject::AllInfo));
Expand Down
5 changes: 5 additions & 0 deletions src/gui/StelGui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
class QGraphicsSceneMouseEvent;
class QTimeLine;
class StelButton;
class StelToolTip;
class BottomStelBar;
class InfoPanel;
class ConfigurationDialog;
Expand Down Expand Up @@ -90,6 +91,8 @@ class StelGui : public QObject, public StelGuiBase
void init(QGraphicsWidget* topLevelGraphicsWidget) override;
void update();

void showToolTip(const QPoint& scenePos, const QString& text) override;

StelStyle getStelStyle() const {return currentStelStyle;}

///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -379,6 +382,8 @@ private slots:
AstroCalcDialog* astroCalcDialog;
ObsListDialog* obsListDialog;

StelToolTip* toolTip;

bool flagShowFlipButtons;
StelButton* flipVert;
StelButton* flipHoriz;
Expand Down
47 changes: 47 additions & 0 deletions src/gui/StelGuiItems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <QGraphicsLineItem>
#include <QRectF>
#include <QDebug>
#include <QLabel>
#include <QScreen>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsTextItem>
Expand All @@ -55,6 +56,52 @@
#include <QSettings>
#include <QGuiApplication>

StelToolTip::StelToolTip(QGraphicsItem* parent)
: QGraphicsProxyWidget(parent)
, label(new QLabel(""))
{
setZValue(1e38); // Show on top
label->setObjectName("StelToolTip");
setWidget(label);
setVisible(false);

setSizePolicy({QSizePolicy::Minimum, QSizePolicy::Fixed});
connect(dynamic_cast<StelGui*>(StelApp::getInstance().getGui()),
&StelGui::guiStyleChanged, this,
[this](const QString &style){ label->setStyleSheet(style); });

connect(&StelApp::getInstance(), &StelApp::guiFontSizeChanged,
this, &StelToolTip::setFontSizeFromApp);
setFontSizeFromApp(StelApp::getInstance().getGuiFontSize());
}

void StelToolTip::setFontSizeFromApp(const int size)
{
auto font = QGuiApplication::font();
font.setPixelSize(size);
setFont(font);
}

void StelToolTip::showToolTip(const QPoint& scenePos, const QString& text)
{
if (isVisible() && label->text() == text)
{
// Avoid moving the tooltip when the text doesn't change
return;
}

label->setText(text);
// The shift avoids clicking the tooltip instead of the control it's annotating
const QPoint shift(2, 2);
setPos(scenePos + shift);
updateGeometry();
setVisible(!text.isEmpty());
}

void StelToolTip::mousePressEvent(QGraphicsSceneMouseEvent*)
{
showToolTip({}, "");
}

void StelButton::brightenImage(QImage &img, float factor)
{
Expand Down
15 changes: 15 additions & 0 deletions src/gui/StelGuiItems.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifndef STELGUIITEMS_HPP
#define STELGUIITEMS_HPP

#include <QGraphicsProxyWidget>
#include <QGraphicsPixmapItem>
#include <QGraphicsWidget>
#include <QDebug>
Expand All @@ -29,9 +30,23 @@ class QGraphicsSceneMouseEvent;
class QTimeLine;
class QGraphicsTextItem;
class QTimer;
class QLabel;
class StelProgressController;
class QProgressBar;

class StelToolTip : public QGraphicsProxyWidget
{
public:
StelToolTip(QGraphicsItem* parent);
void showToolTip(const QPoint& scenePos, const QString& text);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
private:
void setFontSizeFromApp(int size);

QLabel* label = nullptr;
};

// Progress bars in the lower right corner
class StelProgressBarMgr : public QGraphicsWidget
{
Expand Down
Loading