32 private final static String TAG =
"QtQuickView";
35 private String[] m_qmlImportPaths =
null;
38 private boolean m_hasQueuedStatus =
false;
39 private WeakReference<QtQuickViewContent> m_loadedComponent;
40 private QtSignalQueue m_signalQueue =
new QtSignalQueue();
42 native
void createQuickView(
String qmlUri,
int width,
int height,
long parentWindowReference,
43 long viewReference,
String[] qmlImportPaths);
44 native
void setRootObjectProperty(
long windowReference,
String propertyName,
Object value);
45 native
Object getRootObjectProperty(
long windowReference,
String propertyName);
46 native
boolean addRootObjectSignalListener(
long windowReference,
String signalName,
48 native
boolean removeRootObjectSignalListener(
long windowReference,
int signalListenerId);
64 throws InvalidParameterException {
65 this(
context, qmlUri, appName,
null);
84 throws InvalidParameterException
87 if (qmlUri ==
null || qmlUri.isEmpty()) {
88 throw new InvalidParameterException(
89 "QtQuickView: argument 'qmlUri' may not be empty or null");
92 m_qmlImportPaths = qmlImportPaths;
119 public <T extends QtQuickViewContent>
void loadContent(T qmlContent,
String[] qmlImportPaths)
120 throws InvalidParameterException
122 String libName = qmlContent.getLibraryName();
123 String qmlUri = qmlContent.getFilePath();
125 if (libName ==
null || libName.isEmpty()) {
126 throw new InvalidParameterException(
127 "QtQuickViewContent: return value of getLibraryName() may not be empty or null");
130 if (qmlUri ==
null || qmlUri.isEmpty()) {
131 throw new InvalidParameterException(
132 "QtQuickViewContent: return value of getFilePath() may not be empty or null");
136 m_qmlImportPaths = qmlImportPaths;
138 if (m_loadedComponent !=
null)
139 m_loadedComponent.clear();
141 m_loadedComponent =
new WeakReference<>(qmlContent);
142 qmlContent.detachView();
143 qmlContent.attachView(
this);
148 if (windowReference() == 0) {
149 loadQtLibraries(libName);
151 createQuickView(m_qmlUri, getWidth(), getHeight(), 0, windowReference(),
157 void setWindowReference(
long windowReference) {
158 super.setWindowReference(windowReference);
159 m_signalQueue.connectQueuedSignalListeners(
this);
162 private boolean hasUnderlyingView() {
163 return m_windowReference != 0L;
174 public <T extends QtQuickViewContent>
void loadContent(T qmlContent)
175 throws InvalidParameterException
177 loadContent(qmlContent,
null);
182 createQuickView(m_qmlUri, getWidth(), getHeight(), parentWindowReference, windowReference(),
203 setRootObjectProperty(windowReference(), propertyName,
value);
223 @SuppressWarnings(
"unchecked")
224 public <T> T getProperty(
String propertyName)
226 return (T)getRootObjectProperty(windowReference(), propertyName);
243 QtSignalListener<T> listener)
263 connectSignalListener(
signalName, argTypes, listener,
id);
281 if (hasUnderlyingView())
282 addRootObjectSignalListener(windowReference(),
signalName, argTypes, listener,
id);
284 m_signalQueue.add(
signalName, argTypes, listener,
id);
299 if (hasUnderlyingView())
300 return removeRootObjectSignalListener(windowReference(), signalListenerId);
302 return m_signalQueue.remove(signalListenerId);
332 m_statusChangeListener = listener;
334 if (m_hasQueuedStatus) {
335 sendStatusChanged(m_lastStatus);
336 m_hasQueuedStatus =
false;
375 private void handleStatusChange(
int status)
379 }
catch (IllegalArgumentException e) {
380 m_lastStatus = QtQmlStatus.
NULL;
384 if (m_statusChangeListener ==
null)
385 m_hasQueuedStatus =
true;
387 sendStatusChanged(m_lastStatus);
390 private void sendStatusChanged(QtQmlStatus status)
392 if (m_statusChangeListener !=
null) {
393 QtQuickViewContent content = m_loadedComponent !=
null ? m_loadedComponent.get() :
null;