Changeset View
Changeset View
Standalone View
Standalone View
src/context/ContextView.h
Show All 17 Lines | |||||
18 | /* | 18 | /* | ||
19 | Significant parts of this code is inspired and/or copied from KDE Plasma sources, | 19 | Significant parts of this code is inspired and/or copied from KDE Plasma sources, | ||
20 | available at kdebase/workspace/libs/plasma | 20 | available at kdebase/workspace/libs/plasma | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #ifndef AMAROK_CONTEXT_VIEW_H | 23 | #ifndef AMAROK_CONTEXT_VIEW_H | ||
24 | #define AMAROK_CONTEXT_VIEW_H | 24 | #define AMAROK_CONTEXT_VIEW_H | ||
25 | 25 | | |||
26 | #include "Context.h" | | |||
27 | #include "ContextObserver.h" | | |||
28 | #include "ContextScene.h" | | |||
29 | #include "EngineController.h" | | |||
30 | #include "Svg.h" | | |||
31 | #include "amarok_export.h" | | |||
32 | #include "widgets/ContainmentArrow.h" | | |||
33 | #include "widgets/appletexplorer/AppletExplorer.h" | | |||
34 | 26 | | |||
35 | #include <Plasma/Containment> | 27 | #include "amarok_export.h" | ||
36 | 28 | | |||
37 | #include <QMouseEvent> | 29 | #include <QQuickWidget> | ||
38 | #include <QGraphicsView> | | |||
39 | #include <QQueue> | | |||
40 | #include <QAbstractAnimation> | | |||
41 | 30 | | |||
42 | class QPixmap; | | |||
43 | class ContextUrlRunner; | 31 | class ContextUrlRunner; | ||
44 | class QParallelAnimationGroup; | 32 | class FontFilter; | ||
33 | class QPalette; | ||||
34 | class QQmlPropertyMap; | ||||
35 | class QScreen; | ||||
45 | 36 | | |||
46 | namespace Context | 37 | namespace Context | ||
47 | { | 38 | { | ||
48 | 39 | | |||
49 | class ContextScene; | 40 | class AppletLoader; | ||
50 | class ControlBox; | 41 | class AppletModel; | ||
51 | class ViewPrivate; | 42 | class AppletProxyModel; | ||
52 | 43 | | |||
53 | /** | 44 | class AMAROK_EXPORT ContextView : public QQuickWidget | ||
54 | * Plasma::View is no longer present in the plasma API in KF5 and hence it has been replaced | | |||
55 | * with QGraphicsView from which it was derived. | | |||
56 | */ | | |||
57 | class AMAROK_EXPORT ContextView : public QGraphicsView, public ContextSubject | | |||
58 | { | 45 | { | ||
59 | Q_OBJECT | 46 | Q_OBJECT | ||
60 | 47 | | |||
48 | // Properties copied from KF5::Plasma::Units | ||||
49 | Q_PROPERTY( int smallSpacing READ smallSpacing NOTIFY spacingChanged ) | ||||
50 | Q_PROPERTY( int largeSpacing READ largeSpacing NOTIFY spacingChanged ) | ||||
51 | Q_PROPERTY( QQmlPropertyMap *iconSizes READ iconSizes CONSTANT ) | ||||
52 | Q_PROPERTY( qreal devicePixelRatio READ devicePixelRatio NOTIFY devicePixelRatioChanged ) | ||||
53 | | ||||
61 | public: | 54 | public: | ||
62 | ContextView( Plasma::Containment *containment, Plasma::Corona *corona, QWidget* parent = 0 ); | 55 | ContextView( QWidget *parent = Q_NULLPTR ); | ||
63 | ~ContextView(); | 56 | ~ContextView(); | ||
64 | 57 | | |||
65 | /** | 58 | /** | ||
66 | * Singleton pattern accessor. May return 0 if the view was not yet constructed. | 59 | * Singleton pattern accessor. May return 0 if the view was not yet constructed. | ||
67 | */ | 60 | */ | ||
68 | static ContextView *self() { return s_self; } | 61 | static ContextView *self() { return s_self; } | ||
69 | 62 | | |||
70 | /** | 63 | /** | ||
71 | Returns the context scene that this view is attached to. | 64 | * Get the plugin names, in order, of the applets currently in the contextView. | ||
72 | */ | | |||
73 | ContextScene* contextScene(); | | |||
74 | | ||||
75 | /** | | |||
76 | Clears the context scene of all items, but first saves the current state of the scene into the | | |||
77 | config file using as a key the string parameter. | | |||
78 | */ | | |||
79 | void clear( const ContextState& name ); | | |||
80 | | ||||
81 | void clearNoSave(); | | |||
82 | | ||||
83 | /** | | |||
84 | Shows the home state. Loads applets from config file. | | |||
85 | */ | | |||
86 | void showHome(); | | |||
87 | | ||||
88 | /** | | |||
89 | Get the plugin names, in order, of the applets currently in the contextView. | | |||
90 | */ | | |||
91 | QStringList currentApplets(); | | |||
92 | | ||||
93 | /** | | |||
94 | Get the user visible applet names, in order, of the applets currently in the contextView. | | |||
95 | */ | 65 | */ | ||
96 | QStringList currentAppletNames(); | 66 | QStringList currentApplets() const; | ||
97 | 67 | | |||
98 | /** | 68 | /** | ||
99 | Adds a collapse animation | 69 | * Get the user visible applet names, in order, of the applets currently in the contextView. | ||
100 | This object will take ownership of the animation. | | |||
101 | */ | 70 | */ | ||
102 | void addCollapseAnimation( QAbstractAnimation *anim ); | 71 | QStringList currentAppletNames() const; | ||
103 | 72 | | |||
104 | /** | 73 | /** | ||
105 | * @return the containment associated, or 0 if none is | 74 | * Get the Context::AppletModel instance in use. | ||
75 | * It can be used to show, hide enable or disable applets among other things. | ||||
106 | */ | 76 | */ | ||
107 | Containment *containment() const; | 77 | AppletProxyModel *appletModel() const { return m_proxyModel; } | ||
108 | 78 | | |||
109 | public Q_SLOTS: | 79 | Q_INVOKABLE void runLink( const QUrl &link ) const; | ||
110 | /** | 80 | Q_INVOKABLE void debug( const QString &error ) const; | ||
111 | * Convenience methods to show and hide the applet explorer. | 81 | Q_INVOKABLE void warning( const QString &error ) const; | ||
112 | */ | 82 | Q_INVOKABLE void error( const QString &error ) const; | ||
113 | void hideAppletExplorer(); | | |||
114 | void showAppletExplorer(); | | |||
115 | | ||||
116 | /** | | |||
117 | * @param containment the containment to center the view on | | |||
118 | */ | | |||
119 | virtual void setContainment(Plasma::Containment *containment); | | |||
120 | | ||||
121 | Q_SIGNALS: | | |||
122 | void appletExplorerHid(); | | |||
123 | | ||||
124 | /** | | |||
125 | * This signal is emitted whenever the containment being viewed has | | |||
126 | * changed its geometry, but before the View has shifted the viewd scene rect | | |||
127 | * to the new geometry. This is useful for Views which want to keep | | |||
128 | * their rect() in sync with the containment'sa | | |||
129 | */ | | |||
130 | void sceneRectAboutToChange(); | | |||
131 | 83 | | |||
132 | /** | 84 | int smallSpacing() const { return m_smallSpacing; } | ||
133 | * This signal is emitted whenever the containment being viewed has | 85 | int largeSpacing() const { return m_largeSpacing; } | ||
134 | * changed its geometry, and after the View has shifted the viewd scene rect | 86 | QQmlPropertyMap* iconSizes() const { return m_iconSizes; } | ||
135 | * to the new geometry. This is useful for Views which want to keep | 87 | qreal devicePixelRatio() const { return m_devicePixelRatio; } | ||
136 | * their rect() in sync with the containment's. | | |||
137 | */ | | |||
138 | void sceneRectChanged(); | | |||
139 | 88 | | |||
140 | /** | 89 | private slots: | ||
141 | * This is emitted after the containment is destroyed, for views that need to do something about | 90 | void slotStatusChanged( QQuickWidget::Status status ); | ||
142 | * it (like find a new one). | 91 | void updateSpacing(); | ||
143 | */ | 92 | void updateDevicePixelRatio( QScreen *screen ); | ||
144 | void lostContainment(); | 93 | void iconLoaderSettingsChanged(); | ||
94 | void updatePalette( const QPalette &palette ); | ||||
145 | 95 | | |||
146 | protected: | 96 | signals: | ||
147 | void resizeEvent(QResizeEvent *event); | 97 | void spacingChanged(); | ||
148 | void wheelEvent(QWheelEvent *event); | 98 | void iconSizesChanged(); | ||
149 | 99 | void devicePixelRatioChanged(); | |||
150 | private Q_SLOTS: | | |||
151 | void slotTrackChanged( Meta::TrackPtr track ); | | |||
152 | void slotMetadataChanged( Meta::TrackPtr track ); | | |||
153 | void slotPositionAppletExplorer(); | | |||
154 | void slotStartCollapseAnimations(); | | |||
155 | void slotCollapseAnimationsFinished(); | | |||
156 | 100 | | |||
157 | private: | 101 | private: | ||
158 | static ContextView* s_self; | 102 | // copied from KF5::Plasma::Units | ||
103 | int devicePixelIconSize( int size ) const; | ||||
159 | 104 | | |||
160 | void loadConfig(); | 105 | static ContextView *s_self; | ||
161 | | ||||
162 | // holds what is currently being shown | | |||
163 | ContextState m_curState; | | |||
164 | 106 | | |||
165 | ContextUrlRunner * m_urlRunner; | 107 | ContextUrlRunner *m_urlRunner; | ||
166 | 108 | AppletLoader *m_loader; | |||
167 | AppletExplorer *m_appletExplorer; | 109 | AppletModel *m_appletModel; | ||
168 | QParallelAnimationGroup *m_collapseAnimations; | 110 | AppletProxyModel *m_proxyModel; | ||
169 | QAnimationGroup *m_queuedAnimations; | 111 | FontFilter *m_fontFilter; | ||
170 | QTimer *m_collapseGroupTimer; | 112 | | ||
171 | ViewPrivate * const d; | 113 | int m_smallSpacing; | ||
172 | 114 | int m_largeSpacing; | |||
173 | friend class ViewPrivate; | 115 | QQmlPropertyMap *m_iconSizes; | ||
116 | qreal m_devicePixelRatio; | ||||
174 | }; | 117 | }; | ||
175 | 118 | | |||
176 | } // Context namespace | 119 | } // Context namespace | ||
177 | 120 | | |||
178 | #endif | 121 | #endif |