QmlMaterial 0.1.0
Loading...
Searching...
No Matches
search_view.hpp
1#pragma once
2
3#include "qml_material/control/popup.hpp"
4
5Q_MOC_INCLUDE("qml_material/control/search_bar.hpp")
6Q_MOC_INCLUDE("qml_material/input/search_state.hpp")
7
8namespace qml_material
9{
10class SearchBar;
11class SearchState;
12class Page;
13
14class QML_MATERIAL_API SearchView : public Popup {
15 Q_OBJECT
16 QML_NAMED_ELEMENT(SearchViewBase)
17 Q_PROPERTY(SearchBar* searchBar READ searchBar WRITE setSearchBar NOTIFY searchBarChanged FINAL)
18 Q_PROPERTY(SearchState* searchState READ searchState NOTIFY searchStateChanged FINAL)
19 Q_PROPERTY(
20 QString searchText READ searchText WRITE setSearchText NOTIFY searchTextChanged FINAL)
21 Q_PROPERTY(Presentation presentation READ presentation WRITE setPresentation NOTIFY
22 presentationChanged FINAL)
23 Q_PROPERTY(QQuickItem* header READ header WRITE setHeader NOTIFY headerChanged FINAL)
24 Q_PROPERTY(
25 QQuickItem* inputField READ inputField WRITE setInputField NOTIFY inputFieldChanged FINAL)
26 Q_PROPERTY(qreal expansion READ expansion WRITE setExpansion NOTIFY expansionChanged FINAL)
27 Q_PROPERTY(bool autoShowKeyboard READ autoShowKeyboard WRITE setAutoShowKeyboard NOTIFY
28 autoShowKeyboardChanged FINAL)
29public:
30 enum Presentation
31 {
32 Docked,
33 FullScreen
34 };
35 Q_ENUM(Presentation)
36 explicit SearchView(QObject* parent = nullptr);
37 ~SearchView() override;
38 SearchBar* searchBar() const;
39 void setSearchBar(SearchBar*);
40 SearchState* searchState() const;
41 QString searchText() const;
42 void setSearchText(const QString&);
43 Presentation presentation() const { return m_presentation; }
44 void setPresentation(Presentation);
45 QQuickItem* header() const;
46 void setHeader(QQuickItem*);
47 QQuickItem* inputField() const { return m_inputField; }
48 void setInputField(QQuickItem*);
49 qreal expansion() const { return m_expansion; }
50 void setExpansion(qreal);
51 bool autoShowKeyboard() const { return m_autoShowKeyboard; }
52 void setAutoShowKeyboard(bool);
53 Q_INVOKABLE void clear();
54 Q_INVOKABLE void submit();
55 void open() override;
56 void close() override;
57 Q_SIGNAL void searchBarChanged();
58 Q_SIGNAL void searchStateChanged();
59 Q_SIGNAL void searchTextChanged();
60 Q_SIGNAL void presentationChanged();
61 Q_SIGNAL void headerChanged();
62 Q_SIGNAL void inputFieldChanged();
63 Q_SIGNAL void expansionChanged();
64 Q_SIGNAL void autoShowKeyboardChanged();
65 Q_SIGNAL void accepted();
66
67protected:
68 void componentComplete() override;
69 QPointF surfacePosition() const override;
70 QSizeF surfaceSize() const override;
71 QList<TransitionTarget> transitionTargets(bool) const override;
72 void finalizeTransition(bool) override;
73
74private:
75 Page* page() const;
76 QRectF originRect() const;
77 void observeState();
78 void focusInput();
79 QPointer<SearchBar> m_bar;
80 SearchState* m_defaultState;
81 QPointer<QQuickItem> m_inputField;
82 QList<QMetaObject::Connection> m_barConnections;
83 QMetaObject::Connection m_queryConnection, m_inputConnection;
84 Presentation m_presentation = Docked;
85 qreal m_expansion = 0;
86 bool m_autoShowKeyboard = true, m_componentComplete = false, m_initialRequest = false;
87 quint64 m_revision = 0;
88};
89} // namespace qml_material