134
QSGNode *UCListItemDivider::paint(QSGNode *paintNode, const QRectF &rect)
134
QSGNode *UCListItemDivider::paint(const QRectF &rect)
136
136
if (m_visible && !m_lastItem && (m_gradient.size() > 0)) {
137
QSGRectangleNode *rectNode = static_cast<QSGRectangleNode *>(paintNode);
139
rectNode = m_listItem->sceneGraphContext()->createRectangleNode();
137
// the parent always recreates the node, so no worries for the existing child node
138
QSGRectangleNode *rectNode = m_listItem->sceneGraphContext()->createRectangleNode();
141
139
rectNode->setRect(QRectF(m_leftMargin, rect.height() - m_thickness,
142
140
rect.width() - m_leftMargin - m_rightMargin, m_thickness));
143
141
rectNode->setGradientStops(m_gradient);
144
142
rectNode->update();
207
204
/******************************************************************************
210
UCListItemContent::UCListItemContent(QQuickItem *parent)
212
, m_color(Qt::transparent)
213
, m_pressedColor(Qt::yellow)
216
setFlag(QQuickItem::ItemHasContents);
217
// catch theme palette changes
218
connect(&UCTheme::instance(), &UCTheme::paletteChanged, this, &UCListItemContent::updateColors);
222
UCListItemContent::~UCListItemContent()
226
void UCListItemContent::setColor(const QColor &color)
228
if (m_color == color) {
233
Q_EMIT colorChanged();
236
void UCListItemContent::setPressedColor(const QColor &color)
238
if (m_pressedColor == color) {
241
m_pressedColor = color;
242
// no more theme change watch
243
disconnect(&UCTheme::instance(), &UCTheme::paletteChanged, this, &UCListItemContent::updateColors);
245
Q_EMIT pressedColorChanged();
248
void UCListItemContent::updateColors()
250
m_pressedColor = getPaletteColor("selected", "background");
255
void UCListItemContent::itemChange(ItemChange change, const ItemChangeData &data)
257
if (change == ItemParentHasChanged) {
258
m_item = qobject_cast<UCListItem*>(data.item);
260
QQuickItem::itemChange(change, data);
263
QSGNode *UCListItemContent::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
267
UCListItemPrivate *dd = UCListItemPrivate::get(m_item);
268
bool pressed = (dd && dd->pressed);
269
bool selected = (dd && dd->selectable && dd->selected);
270
QColor color = (pressed || selected) ? m_pressedColor : m_color;
273
if (width() <= 0 || height() <= 0 || (color.alpha() == 0)) {
277
QSGRectangleNode *rectNode = QQuickItemPrivate::get(this)->sceneGraphContext()->createRectangleNode();
278
rectNode->setColor(color);
279
rectNode->setRect(boundingRect());
285
/******************************************************************************
286
* ListItemBasePrivate
288
207
UCListItemPrivate::UCListItemPrivate()
289
208
: UCStyledItemBasePrivate()
210
, pressedColorChanged(false)
293
213
, selectable(false)
294
214
, selected(false)
296
216
, xAxisMoveThresholdGU(1.5)
217
, color(Qt::transparent)
218
, pressedColor(Qt::transparent)
297
219
, reboundAnimation(0)
298
220
, flickableInteractive(0)
221
, contentItem(new QQuickItem)
299
222
, disabledOpacity(0)
300
, contentItem(new UCListItemContent)
301
223
, divider(new UCListItemDivider)
302
224
, leadingOptions(0)
303
225
, trailingOptions(0)
319
241
divider->init(q);
320
242
// content will be redirected to the contentItem, therefore we must report
321
243
// children changes as it would come from the main component
322
QObject::connect(contentItem, &UCListItemContent::childrenChanged,
244
QObject::connect(contentItem, &QQuickItem::childrenChanged,
323
245
q, &UCListItem::childrenChanged);
324
246
q->setFlag(QQuickItem::ItemHasContents);
325
247
// turn activeFocusOnPress on
326
248
activeFocusOnPress = true;
251
// catch theme palette changes
252
QObject::connect(&UCTheme::instance(), SIGNAL(paletteChanged()), q, SLOT(_q_updateColors()));
329
255
// watch size change and set implicit size;
330
256
QObject::connect(&UCUnits::instance(), SIGNAL(gridUnitChanged()), q, SLOT(_q_updateSize()));
346
272
void UCListItemPrivate::setFocusable()
348
// alsways accept mouse events
274
// always accept mouse events
350
276
q->setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton);
351
277
q->setFiltersChildMouseEvents(true);
280
void UCListItemPrivate::_q_updateColors()
283
pressedColor = getPaletteColor("selected", "background");
354
287
void UCListItemPrivate::_q_dimmDisabled()
610
544
* ways on it. However, when used in list views, the content must be carefully
611
545
* chosen to in order to keep the kinetic behavior and the highest FPS possible.
613
* \c contentItem is an essential part of the component. Beside the fact that it
614
* holds all components and resources declared as child to ListItem, it can also
615
* configure the color of the background when in normal mode or when pressed. Being
616
* an item, all other properties can be accessed or altered, with the exception
547
* The component provides two color properties which configures the item's background
548
* when normal or pressed. This can be configures through \l color and \l pressedColor
551
* \c contentItem holds all components and resources declared as child to ListItem.
552
* Being an Item, all other properties can be accessed or altered, with the exception
619
555
* \li do not alter \c x, \c y, \c width or \c height properties as those are
785
721
QSGNode *UCListItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
789
if (width() <= 0 || height() <= 0 || !d->divider) {
726
QColor color = (d->pressed || (d->selectable && d->selected))? d->pressedColor : d->color;
729
if (width() <= 0 || height() <= 0) {
794
return d->divider->paint(oldNode, boundingRect());
733
QSGRectangleNode *rectNode = 0;
734
if (color.alpha() > 0) {
735
rectNode = QQuickItemPrivate::get(this)->sceneGraphContext()->createRectangleNode();
736
rectNode->setColor(color);
737
rectNode->setRect(boundingRect());
741
if (d->divider && d->divider->m_visible) {
742
QSGNode * dividerNode = d->divider->paint(boundingRect());
743
if (dividerNode && oldNode) {
744
oldNode->appendChildNode(dividerNode);
745
} else if (dividerNode) {
746
oldNode = dividerNode;
797
752
void UCListItem::mousePressEvent(QMouseEvent *event)
802
757
// while moving, we cannot select or tug any items
806
d->lastPos = d->pressedPos = event->localPos();
807
// connect the Flickable to know when to rebound
808
d->listenToRebind(true);
809
// start pressandhold timer
810
d->pressAndHoldTimer.start(DefaultPressAndHoldDelay, this);
811
// accept the event so we get the rest of the events as well
812
event->setAccepted(true);
760
if (event->button() == Qt::LeftButton) {
762
d->lastPos = d->pressedPos = event->localPos();
763
// connect the Flickable to know when to rebound
764
d->listenToRebind(true);
765
// start pressandhold timer
766
d->pressAndHoldTimer.start(DefaultPressAndHoldDelay, this);
767
// accept the event so we get the rest of the events as well
768
event->setAccepted(true);
815
772
void UCListItem::mouseReleaseEvent(QMouseEvent *event)
990
* \qmlpropertygroup ::ListItem::contentItem
991
* \qmlproperty color ListItem::contentItem.color
992
* \qmlproperty color ListItem::contentItem.pressedColor
947
* \qmlproperty Item ListItem::contentItem
994
* contentItem holds the components placed on a ListItem. \c color configures
995
* the color of the normal contentItem, and \c pressedColor configures the color
949
* contentItem holds the components placed on a ListItem.
998
UCListItemContent* UCListItem::contentItem() const
951
QQuickItem* UCListItem::contentItem() const
1000
953
Q_D(const UCListItem);
1001
954
return d->contentItem;
998
* \qmlproperty color ListItem::color
999
* Configures the color of the normal background. The default value is transparent.
1001
QColor UCListItem::color() const
1003
Q_D(const UCListItem);
1006
void UCListItem::setColor(const QColor &color)
1009
if (d->color == color) {
1014
Q_EMIT colorChanged();
1018
* \qmlproperty color ListItem::pressedColor
1019
* Configures the color when pressed. Defaults to the theme palette's background color.
1021
QColor UCListItem::pressedColor() const
1023
Q_D(const UCListItem);
1024
return d->pressedColor;
1026
void UCListItem::setPressedColor(const QColor &color)
1029
if (d->pressedColor == color) {
1032
d->pressedColor = color;
1033
// no more theme change watch
1034
disconnect(&UCTheme::instance(), SIGNAL(paletteChanged()), this, SLOT(_q_updateColors()));
1036
Q_EMIT pressedColorChanged();
1045
1040
* \qmlproperty bool ListItem::selectable
1046
1041
* The property drives whether a list item is selectable or not. When set, the item
1047
1042
* will show a check box on the leading side hanving the content item pushed towards