QtMvvm  1.1.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
qqmlquickpresenter.h
1 #ifndef QTMVVM_QQMLQUICKPRESENTER_H
2 #define QTMVVM_QQMLQUICKPRESENTER_H
3 
4 #include <tuple>
5 
6 #include <QtCore/QObject>
7 #include <QtCore/QCache>
8 #include <QtCore/QVariant>
9 #include <QtCore/QPointer>
10 #include <QtCore/QUrl>
11 #include <QtCore/QQueue>
12 #include <QtCore/QSharedPointer>
13 
14 #include <QtGui/QColor>
15 
16 #include <QtQml/QQmlComponent>
17 
18 #include <QtMvvmCore/ViewModel>
19 #include <QtMvvmCore/Messages>
20 
21 #include <QtMvvmQuick/InputViewFactory>
22 
23 #ifdef DOXYGEN_RUN
25 
36 class QuickPresenter : public QtObject
37 #else
38 namespace QtMvvm {
39 
40 class QQmlQuickPresenter : public QObject
41 #endif
42 {
43  Q_OBJECT
44 
55  Q_PROPERTY(QString currentStyle READ currentStyle CONSTANT)
66  Q_PROPERTY(InputViewFactory* inputViewFactory READ inputViewFactory NOTIFY inputViewFactoryChanged)
67 
83  Q_PROPERTY(QObject* qmlPresenter MEMBER _qmlPresenter NOTIFY qmlPresenterChanged)
96  Q_PROPERTY(bool viewLoading READ isViewLoading NOTIFY viewLoadingChanged)
111  Q_PROPERTY(qreal loadingProgress READ loadingProgress NOTIFY loadingProgressChanged)
112 
113 public:
115  explicit QQmlQuickPresenter(QQmlEngine *engine);
116 
118  QString currentStyle() const;
120  InputViewFactory* inputViewFactory() const;
122  bool isViewLoading() const;
124  qreal loadingProgress() const;
125 
126 #ifndef DOXYGEN_RUN
127 #define static
128 #endif
129  Q_INVOKABLE static QStringList mimeTypeFilters(const QStringList &mimeTypes) const;
131 
144  QTMVVM_REVISION_1 Q_INVOKABLE static QColor accentTextColor(const QColor &accentColor, const QColor &baseColor) const;
145 
146 #ifdef DOXYGEN_RUN
147 public:
148 #else
149 public Q_SLOTS:
150 #endif
151  static void toggleDrawer();
154  static void popView();
155 
157  static void hapticLongPress();
158 
159 #ifndef DOXYGEN_RUN
160 #undef static
161 #endif
162 
163 Q_SIGNALS:
167  void viewLoadingChanged(bool viewLoading);
169  void loadingProgressChanged(qreal loadingProgress);
171  void inputViewFactoryChanged(InputViewFactory* inputViewFactory);
172 
173 private Q_SLOTS:
174  void present(QtMvvm::ViewModel *viewModel, const QVariantHash &params, const QUrl &viewUrl, QPointer<QtMvvm::ViewModel> parent);
175  void showDialog(const QtMvvm::MessageConfig &config, QtMvvm::MessageResult *result);
176  void statusChanged(QQmlComponent::Status status);
177 
178 private:
179  using PresentTuple = std::tuple<QSharedPointer<QQmlComponent>, ViewModel*, QVariantHash, QPointer<ViewModel>>;
180  QQmlEngine *_engine;
181  QPointer<QObject> _qmlPresenter;
182 
183  QPointer<QQmlComponent> _latestComponent;
185  QQueue<PresentTuple> _loadQueue;
186 
187  void processShowQueue();
188  void addObject(QQmlComponent *component, ViewModel *viewModel, const QVariantHash &params, const QPointer<ViewModel> &parent);
189 };
190 
191 }
192 
193 #endif // QTMVVM_QQMLQUICKPRESENTER_H
void qmlPresenterChanged(QObject *qmlPresenter)
NOTIFY accessor for QuickPresenter::qmlPresenter.
static void toggleDrawer()
Toggles the state of the current drawer, if any is beeing used.
static void popView()
Pops the current top level view.
QObject qmlPresenter
The primary presenter QML object.
A configuration for a simple dialog to be shown from the core code.
Definition: message.h:20
bool viewLoading
Specifies whether the presenter is currently loading a new view component.
QTMVVM_REVISION_1 static Q_INVOKABLE QColor accentTextColor(const QColor &accentColor, const QColor &baseColor) const
Calculates the optimal text color based on the background color.
void inputViewFactoryChanged(InputViewFactory *inputViewFactory)
NOTIFY accessor for QuickPresenter::inputViewFactory.
static Q_INVOKABLE QStringList mimeTypeFilters(const QStringList &mimeTypes) const
Converts a list of mimetypes into a list of extension filters, for a file dialog. ...
static void hapticLongPress()
Performs haptic feedback of a long press (Android only)
void viewLoadingChanged(bool viewLoading)
NOTIFY accessor for QuickPresenter::viewLoading.
void loadingProgressChanged(qreal loadingProgress)
NOTIFY accessor for QuickPresenter::loadingProgress.
The QML import for the QtMvvmQuick QML module.
Definition: ActionButton.qml:4
The base class for all viewmodels.
Definition: viewmodel.h:21
A result watcher to get the result once a dialog has finished.
Definition: message.h:204
The primary namespace of the QtMvvm library.
A QML singleton to access common presenter methods globally.