File indexing completed on 2024-11-10 06:30:28

0001 /*
0002     SPDX-FileCopyrightText: 2009 Khudyakov Alexey <alexey.skladnoy@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QWidget>
0010 #include <QPoint>
0011 #include <QList>
0012 #include <QString>
0013 #include <QStringList>
0014 
0015 class SkyPoint;
0016 class SkyObject;
0017 class InfoBoxWidget;
0018 
0019 /**
0020  * @brief The InfoBoxes class is a collection of InfoBoxWidget objects that display a transparent box for display of text messages
0021  */
0022 class InfoBoxes : public QWidget
0023 {
0024     Q_OBJECT
0025 
0026   public:
0027     explicit InfoBoxes(QWidget *parent = nullptr);
0028 
0029     virtual ~InfoBoxes() override = default;
0030 
0031     void addInfoBox(InfoBoxWidget *ibox);
0032     QList<InfoBoxWidget *> getInfoBoxes() const { return m_boxes; }
0033 
0034   protected:
0035     void resizeEvent(QResizeEvent *event) override;
0036 
0037   private:
0038     QList<InfoBoxWidget *> m_boxes;
0039 };
0040 
0041 /**
0042 * @brief The InfoBoxWidget class is a widget that displays a transparent box for display of text messages.
0043 */
0044 class InfoBoxWidget : public QWidget
0045 {
0046     Q_OBJECT
0047   public:
0048     /** Alignment of widget. */
0049     enum
0050     {
0051         NoAnchor     = 0,
0052         AnchorRight  = 1,
0053         AnchorBottom = 2,
0054         AnchorBoth   = 3
0055     };
0056 
0057     /** Create one infobox. */
0058     InfoBoxWidget(bool shade, const QPoint &pos, int anchor = 0, const QStringList &str = QStringList(),
0059                   QWidget *parent = nullptr);
0060     /** Destructor */
0061     virtual ~InfoBoxWidget() override = default;
0062 
0063     /** Check whether box is shaded. In this case only one line is shown. */
0064     bool shaded() const { return m_shaded; }
0065     /** Get stickyness status of */
0066     int sticky() const { return m_anchor; }
0067 
0068     /** Adjust widget's position */
0069     void adjust();
0070 
0071   public slots:
0072     /** Set information about time. Data is taken from KStarsData. */
0073     void slotTimeChanged();
0074     /** Set information about location. Data is taken from KStarsData. */
0075     void slotGeoChanged();
0076     /** Set information about object. */
0077     void slotObjectChanged(SkyObject *obj);
0078     /** Set information about pointing. */
0079     void slotPointChanged(SkyPoint *p);
0080   signals:
0081     /** Emitted when widget is clicked */
0082     void clicked();
0083 
0084   protected:
0085     void paintEvent(QPaintEvent *event) override;
0086     void mouseDoubleClickEvent(QMouseEvent *event) override;
0087     void mousePressEvent(QMouseEvent *event) override;
0088     void mouseMoveEvent(QMouseEvent *event) override;
0089     void mouseReleaseEvent(QMouseEvent *event) override;
0090     void showEvent(QShowEvent *event) override;
0091 
0092   private:
0093     /** Uset to set information about object. */
0094     void setPoint(QString name, SkyPoint *p);
0095     /** Recalculate size of widget */
0096     void updateSize();
0097 
0098     /// List of string to show
0099     QStringList m_strings;
0100     /// True if widget coordinates were adjusted
0101     bool m_adjusted { true };
0102     /// True if widget is dragged around
0103     bool m_grabbed { true };
0104     /// True if widget if shaded
0105     bool m_shaded { true };
0106     /// Vertical alignment of widget
0107     int m_anchor { 0 };
0108 
0109     static const int padX;
0110     static const int padY;
0111 };