1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#include "gridchooser.h"
#include "qtquick2applicationviewer.h"
#include <algorithm>
#include <cmath>
#include <QEventLoop>
#include <QQuickItem>
#include <QQmlContext>
#include <QDebug>
#include <QCoreApplication>
namespace btm {
GridChooser::GridChooser(QtQuick2ApplicationViewer* viewer)
: viewer_(viewer),
gridChooserObject_(0) {
QQuickItem * rootObject = viewer_->rootObject();
if (rootObject != 0)
gridChooserObject_ = rootObject->findChild<QQuickItem*>("gridChooser");
}
GridChooser::~GridChooser() {
}
void GridChooser::open(const QStringList& stringList, const QString& highlight, const QString& title) {
Q_ASSERT(gridChooserObject_ != 0);
if (gridChooserObject_ == 0)
return;
gridChooserObject_->disconnect();
bool ok = connect(gridChooserObject_, SIGNAL(accepted(QString)),
this, SLOT(gridChooserAccepted(QString)));
Q_ASSERT(ok);
setProperties(stringList, highlight, title);
}
void GridChooser::setProperties(const QStringList& list, const QString& hightlight, const QString& title) {
QQmlContext* ctx = viewer_->rootContext();
ctx->setContextProperty("gridChooserModel",list);
gridChooserObject_->setProperty("selected",hightlight);
gridChooserObject_->setProperty("titleText",title);
int maxLength = 0;
for (int i = 0; i < list.count(); ++i) {
QString text = list.at(i);
maxLength = std::max(maxLength, text.length());
}
gridChooserObject_->setProperty("maxLength", maxLength);
gridChooserObject_->setProperty("visible",true);
}
void GridChooser::gridChooserAccepted(QString value) {
emit accepted(value);
}
void GridChooser::gridChooserCanceled() {
emit canceled();
}
} // end namespace
|