LCOV - code coverage report
Current view: top level - muse/framework/uicomponents/qml/Muse/UiComponents - popupview.h Coverage Total Hit
Test: filtered_coverage.info Lines: 0.0 % 3 0
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2025 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : #pragma once
      23              : 
      24              : #include <qqmlintegration.h>
      25              : 
      26              : #include "windowview.h"
      27              : 
      28              : #include "internal/popupviewclosecontroller.h"
      29              : 
      30              : namespace muse::uicomponents {
      31              : namespace PopupPosition {
      32              : Q_NAMESPACE;
      33              : QML_ELEMENT;
      34              : 
      35              : enum Type: int {
      36              :     Left = 0x01,
      37              :     Right = 0x02,
      38              :     Horizontal = 0x03,
      39              :     Bottom = 0x04,
      40              :     Top = 0x08,
      41              :     Vertical = 0x0C,
      42              : };
      43              : 
      44            0 : Q_ENUM_NS(Type)
      45              : }
      46              : 
      47              : class PopupView : public WindowView
      48              : {
      49              :     Q_OBJECT
      50              :     QML_ELEMENT
      51              : 
      52              :     Q_PROPERTY(ClosePolicies closePolicies READ closePolicies WRITE setClosePolicies NOTIFY closePoliciesChanged)
      53              : 
      54              :     Q_PROPERTY(QQuickItem * anchorItem READ anchorItem WRITE setAnchorItem NOTIFY anchorItemChanged)
      55              :     Q_PROPERTY(PlacementPolicies placementPolicies READ placementPolicies WRITE setPlacementPolicies NOTIFY placementPoliciesChanged)
      56              :     Q_PROPERTY(muse::uicomponents::PopupPosition::Type popupPosition READ popupPosition WRITE setPopupPosition NOTIFY popupPositionChanged)
      57              : 
      58              :     // Relative to parentItem
      59              :     Q_PROPERTY(qreal x READ localX WRITE setLocalX NOTIFY xChanged)
      60              :     Q_PROPERTY(qreal y READ localY WRITE setLocalY NOTIFY yChanged)
      61              : 
      62              :     Q_PROPERTY(bool showArrow READ showArrow WRITE setShowArrow NOTIFY showArrowChanged)
      63              :     Q_PROPERTY(int arrowX READ arrowX WRITE setArrowX NOTIFY arrowXChanged)
      64              :     Q_PROPERTY(int arrowY READ arrowY WRITE setArrowY NOTIFY arrowYChanged)
      65              :     Q_PROPERTY(int padding READ padding WRITE setPadding NOTIFY paddingChanged)
      66              : 
      67              : public:
      68              :     explicit PopupView(QQuickItem* parent = nullptr);
      69              :     ~PopupView() override;
      70              : 
      71              :     enum class ClosePolicy {
      72              :         NoAutoClose = 0x00000000,
      73              :         CloseOnPressOutsideParent = 0x00000001,
      74              :     };
      75              :     Q_DECLARE_FLAGS(ClosePolicies, ClosePolicy)
      76            0 :     Q_FLAG(ClosePolicies)
      77              : 
      78              :     enum class PlacementPolicy {
      79              :         Default = 0x00000000,
      80              :         PreferBelow = 0x00000001,
      81              :         PreferAbove = 0x00000002,
      82              :         PreferLeft = 0x00000004,
      83              :         PreferRight = 0x00000008,
      84              :         IgnoreFit = 0x0000000F,
      85              :     };
      86              :     Q_DECLARE_FLAGS(PlacementPolicies, PlacementPolicy)
      87            0 :     Q_FLAG(PlacementPolicies)
      88              : 
      89              :     void setParentItem(QQuickItem* parent) override;
      90              : 
      91              :     ClosePolicies closePolicies() const;
      92              :     void setClosePolicies(ClosePolicies closePolicies);
      93              : 
      94              :     QQuickItem* anchorItem() const;
      95              :     void setAnchorItem(QQuickItem* anchorItem);
      96              :     QRectF anchorGeometry() const;
      97              : 
      98              :     PlacementPolicies placementPolicies() const;
      99              :     void setPlacementPolicies(PlacementPolicies placementPolicies);
     100              : 
     101              :     PopupPosition::Type popupPosition() const;
     102              :     void setPopupPosition(PopupPosition::Type position);
     103              : 
     104              :     qreal localX() const;
     105              :     qreal localY() const;
     106              :     void setLocalX(qreal x);
     107              :     void setLocalY(qreal y);
     108              : 
     109              :     bool showArrow() const;
     110              :     void setShowArrow(bool showArrow);
     111              : 
     112              :     int arrowX() const;
     113              :     void setArrowX(int arrowX);
     114              : 
     115              :     int arrowY() const;
     116              :     void setArrowY(int arrowY);
     117              : 
     118              :     int padding() const;
     119              :     void setPadding(int padding);
     120              : 
     121              :     void close(bool force = false) override;
     122              : 
     123              :     Q_INVOKABLE void repositionWindowIfNeed() override;
     124              : 
     125              : signals:
     126              :     void closePoliciesChanged(muse::uicomponents::PopupView::ClosePolicies closePolicies);
     127              : 
     128              :     void anchorItemChanged(QQuickItem* anchorItem);
     129              :     void placementPoliciesChanged(muse::uicomponents::PopupView::PlacementPolicies placementPolicies);
     130              :     void popupPositionChanged(muse::uicomponents::PopupPosition::Type position);
     131              : 
     132              :     void xChanged(qreal x);
     133              :     void yChanged(qreal y);
     134              : 
     135              :     void showArrowChanged(bool showArrow);
     136              :     void arrowXChanged(int arrowX);
     137              :     void arrowYChanged(int arrowY);
     138              :     void paddingChanged(int padding);
     139              : 
     140              : protected:
     141              :     void initView() override;
     142              : 
     143              :     void beforeOpen() override;
     144              :     void onHidden() override;
     145              : 
     146              :     bool eventFilter(QObject* watched, QEvent* event) override;
     147              : 
     148              :     void initCloseController();
     149              : 
     150              :     void updateGeometry() override;
     151              :     virtual void updateContentPosition();
     152              : 
     153              :     QPointF m_localPos;
     154              : 
     155              : private:
     156              :     ClosePolicies m_closePolicies = { ClosePolicy::CloseOnPressOutsideParent };
     157              : 
     158              :     QQuickItem* m_anchorItem = nullptr;
     159              :     PlacementPolicies m_placementPolicies = { PlacementPolicy::Default };
     160              :     PopupPosition::Type m_popupPosition = { PopupPosition::Bottom };
     161              : 
     162              :     bool m_showArrow = false;
     163              :     int m_arrowX = 0;
     164              :     int m_arrowY = 0;
     165              :     int m_padding = 0;
     166              : 
     167              :     PopupViewCloseController* m_closeController = nullptr;
     168              : };
     169              : }
        

Generated by: LCOV version 2.0-1