1 //=============================================================================
2 //  MuseScore
3 //  Music Composition & Notation
4 //
5 //  Copyright (C) 2011 Werner Schweer and others
6 //
7 //  This program is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License version 2
9 //  as published by the Free Software Foundation and appearing in
10 //  the file LICENSE.GPL
11 //=============================================================================
12 
13 #ifndef __INSPECTOR_BASE_H__
14 #define __INSPECTOR_BASE_H__
15 
16 #include "libmscore/property.h"
17 #include "libmscore/style.h"
18 
19 namespace Ms {
20 
21 class Inspector;
22 class Element;
23 class InspectorScrollPreventer;
24 
25 //---------------------------------------------------------
26 //   InspectorPanel
27 //---------------------------------------------------------
28 
29 struct InspectorPanel {
30       QToolButton* title;
31       QWidget* panel;
32       };
33 
34 //---------------------------------------------------------
35 //   InspectorItem
36 //---------------------------------------------------------
37 
38 struct InspectorItem {
39       Pid t;           // property id
40       int parent;       // apply to parent() element level
41       QWidget* w;
42       // QToolButton* r;   // reset to default button (if any)
43       QWidget* r;   // reset to default button (if any)
44       };
45 
46 //---------------------------------------------------------
47 //   InspectorBase
48 //---------------------------------------------------------
49 
50 class InspectorBase : public QWidget {
51       Q_OBJECT
52 
53       bool dirty() const;
54       void checkDifferentValues(const InspectorItem&);
55       bool compareValues(const InspectorItem& ii, QVariant a, QVariant b);
56       Element* effectiveElement(const InspectorItem&) const;
57       InspectorScrollPreventer* scrollPreventer;
58 
59    signals:
60       void elementChanged();
61 
62    private slots:
63       void resetToStyle();
64 
65    protected slots:
66       virtual void valueChanged(int idx, bool reset);
67       virtual void valueChanged(int idx);
68       void resetClicked(int);
69       void setStyleClicked(int);
70 
71    protected:
72       std::vector<InspectorItem> iList;
73       std::vector<InspectorPanel> pList;
74       QVBoxLayout* _layout;
75       Inspector* inspector;
76 
77       virtual void setValue(const InspectorItem&, QVariant);
78       QVariant getValue(const InspectorItem&) const;
79       bool isDefault(const InspectorItem&);
80       void mapSignals(const std::vector<InspectorItem>& il = std::vector<InspectorItem>(), const std::vector<InspectorPanel>& pl = std::vector<InspectorPanel>());
81       void setupLineStyle(QComboBox*);
82 
83    public:
84       InspectorBase(QWidget* parent);
85       virtual void setElement();
postInit()86       virtual void postInit() {} // called in setElement and valueChanged
87       QWidget* addWidget();
88 
89       friend class InspectorScriptEntry;
90       };
91 
92 //---------------------------------------------------------
93 //   InspectorScrollPreventer
94 //---------------------------------------------------------
95 
96 class InspectorScrollPreventer : public QObject {
97       Q_OBJECT
98 
99    protected:
100       bool eventFilter(QObject* watched, QEvent* event) override;
101 
102    public:
InspectorScrollPreventer(QObject * parent)103       InspectorScrollPreventer(QObject* parent) : QObject(parent) {}
104       };
105 
106 //---------------------------------------------------------
107 //   InspectorEventObserver
108 //---------------------------------------------------------
109 
110 class InspectorEventObserver {
111       static std::unique_ptr<InspectorEventObserver> i;
112 
113       InspectorEventObserver() = default;
114 
115    public:
116       enum EventType {
117             PropertyChange,
118             PropertyReset,
119             PropertySetStyle,
120             };
121       void event(EventType evtType, const InspectorItem& ii, const Element* e);
122 
instance()123       static InspectorEventObserver* instance()
124             {
125             if (!i)
126                   i.reset(new InspectorEventObserver());
127             return i.get();
128             }
129       };
130 
131 } // namespace Ms
132 #endif
133 
134