From ff35fc61cc8d6b103da4f079fce170d82406cea0 Mon Sep 17 00:00:00 2001 From: Geir Vattekar Date: Wed, 2 Jun 2010 09:21:35 +0200 Subject: Doc: Removed a link to Qt3 support in QSlider Task-number: QTBUG-6394 --- src/gui/widgets/qslider.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/widgets/qslider.cpp b/src/gui/widgets/qslider.cpp index a5e62cf..5755202 100644 --- a/src/gui/widgets/qslider.cpp +++ b/src/gui/widgets/qslider.cpp @@ -621,7 +621,7 @@ QSlider::TickPosition QSlider::tickPosition() const \brief the interval between tickmarks This is a value interval, not a pixel interval. If it is 0, the - slider will choose between lineStep() and pageStep(). + slider will choose between singleStep() and pageStep(). The default value is 0. -- cgit v0.12 From af8b034e2886ecb11db51d4fecc29177595b86ab Mon Sep 17 00:00:00 2001 From: Geir Vattekar Date: Fri, 4 Jun 2010 13:50:36 +0200 Subject: Doc: QTreeWidgetItems remove themselves from views when deleted. Task-number: QTBUG-10640 --- src/gui/itemviews/qtreewidget.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gui/itemviews/qtreewidget.cpp b/src/gui/itemviews/qtreewidget.cpp index 0e06f34..8f55734 100644 --- a/src/gui/itemviews/qtreewidget.cpp +++ b/src/gui/itemviews/qtreewidget.cpp @@ -1472,6 +1472,10 @@ QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem *parent, QTreeWidgetItem *after /*! Destroys this tree widget item. + + The item will be removed from \l{QTreeWidget}s to which it has + been added. This makes it safe to delete an item at any time. + */ QTreeWidgetItem::~QTreeWidgetItem() -- cgit v0.12 From 7ffb1c2e821cc4d508dcedcdb7363756f9f693ff Mon Sep 17 00:00:00 2001 From: Geir Vattekar Date: Fri, 4 Jun 2010 15:06:45 +0200 Subject: Doc: Said to not access events after they are posted(postEvent). Task-number: QTBUG-10210 --- src/corelib/kernel/qcoreapplication.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 4e6e6b9..0a5e06e 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -1073,7 +1073,7 @@ void QCoreApplication::exit(int returnCode) The event must be allocated on the heap since the post event queue will take ownership of the event and delete it once it has been - posted. It is \e {not safe} to modify or delete the event after + posted. It is \e {not safe} to access the event after it has been posted. When control returns to the main event loop, all events that are @@ -1104,7 +1104,7 @@ void QCoreApplication::postEvent(QObject *receiver, QEvent *event) The event must be allocated on the heap since the post event queue will take ownership of the event and delete it once it has been - posted. It is \e {not safe} to modify or delete the event after + posted. It is \e {not safe} to access the event after it has been posted. When control returns to the main event loop, all events that are -- cgit v0.12 From f96d6a5d7d422847d302f4ed1180b66436683191 Mon Sep 17 00:00:00 2001 From: Sami Merila Date: Fri, 11 Jun 2010 15:21:14 +0300 Subject: Stylus menu for Share (QT app) is different from native S60 apps First part of corrections to make menu items more native like. This fixes: - In Sym^3 "separator items" are drawn automatically between items, using a simple line graphic with theme color and alpha values - highlight for menu item is positioned better - menu items themselves are better positioned - the corners of highlight are now more rounded for Sym^3 devices Task-number: QT-3295 Reviewed-by: Alessandro Portale --- src/gui/styles/qs60style.cpp | 76 +++++++++++++++++++++++++++++++--------- src/gui/styles/qs60style_s60.cpp | 10 ++++-- 2 files changed, 67 insertions(+), 19 deletions(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 91d3fa6..9745d9c 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -1762,40 +1762,64 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, if (!styleHint(SH_UnderlineShortcut, menuItem, widget)) text_flags |= Qt::TextHideMnemonic; - const bool selected = (option->state & State_Selected) && (option->state & State_Enabled); - if (selected) - QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ListHighlight, painter, option->rect, flags); - QRect iconRect = subElementRect(SE_ItemViewItemDecoration, &optionMenuItem, widget); QRect textRect = subElementRect(SE_ItemViewItemText, &optionMenuItem, widget); //todo: move the vertical spacing stuff into subElementRect const int vSpacing = QS60StylePrivate::pixelMetric(PM_LayoutVerticalSpacing); + QStyleOptionMenuItem optionCheckBox; if (checkable){ const int hSpacing = QS60StylePrivate::pixelMetric(PM_LayoutHorizontalSpacing); - QStyleOptionMenuItem optionCheckBox; optionCheckBox.QStyleOptionMenuItem::operator=(*menuItem); optionCheckBox.rect.setWidth(pixelMetric(PM_IndicatorWidth)); optionCheckBox.rect.setHeight(pixelMetric(PM_IndicatorHeight)); optionCheckBox.rect.moveCenter(QPoint( optionCheckBox.rect.center().x(), menuItem->rect.center().y())); - const int moveByX = optionCheckBox.rect.width() + vSpacing; + const int moveByX = optionCheckBox.rect.width() + vSpacing + + pixelMetric(PM_DefaultFrameWidth) + 1; if (optionMenuItem.direction == Qt::LeftToRight) { - textRect.translate(moveByX, 0); - iconRect.translate(moveByX, 0); - iconRect.setWidth(iconRect.width() + vSpacing); - textRect.setWidth(textRect.width() - moveByX - vSpacing); + if (iconRect.isValid()) { + iconRect.translate(moveByX, 0); + iconRect.setWidth(iconRect.width() + vSpacing); + } + if (textRect.isValid()) { + textRect.translate(moveByX, 0); + textRect.setWidth(textRect.width() - moveByX - vSpacing); + } optionCheckBox.rect.translate(vSpacing >> 1, hSpacing >> 1); } else { - textRect.setWidth(textRect.width() - moveByX); - iconRect.setWidth(iconRect.width() + vSpacing); - iconRect.translate(-optionCheckBox.rect.width() - vSpacing, 0); + if (textRect.isValid()) + textRect.setWidth(textRect.width() - moveByX); + if (iconRect.isValid()) { + iconRect.setWidth(iconRect.width() + vSpacing); + iconRect.translate(-optionCheckBox.rect.width() - vSpacing, 0); + } optionCheckBox.rect.translate(textRect.width() + iconRect.width(), 0); } - if (!ignoreCheckMark) - drawPrimitive(PE_IndicatorMenuCheckMark, &optionCheckBox, painter, widget); } + + const bool selected = (option->state & State_Selected) && (option->state & State_Enabled); + const int spacing = pixelMetric(PM_DefaultFrameWidth) * 2; + if (selected) { + int start; int end; + if (QApplication::layoutDirection() == Qt::LeftToRight) { + start = optionMenuItem.rect.left() + spacing; + end = qMax(textRect.right(), iconRect.right() + spacing); + } else { + start = qMax(spacing, qMin(textRect.left(), iconRect.left() - spacing)); + end = optionMenuItem.rect.right() - spacing; + } + //-1 adjustment to avoid highlight being on top of possible separator item + const QRect highlightRect = QRect( + QPoint(start, option->rect.top()), + QPoint(end, option->rect.bottom() - 1)); + QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ListHighlight, painter, highlightRect, flags); + } + + if (checkable && !ignoreCheckMark) + drawPrimitive(PE_IndicatorMenuCheckMark, &optionCheckBox, painter, widget); + //draw icon and/or checkState QPixmap pix = menuItem->icon.pixmap(pixelMetric(PM_SmallIconSize), enabled ? QIcon::Normal : QIcon::Disabled); @@ -1806,7 +1830,7 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, textRect.translate(vSpacing, 0); else textRect.translate(-vSpacing, 0); - textRect.setWidth(textRect.width()-vSpacing); + textRect.setWidth(textRect.width() - vSpacing); } //draw indicators @@ -1844,6 +1868,23 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, QCommonStyle::drawItemText(painter, textRect, text_flags, optionMenuItem.palette, enabled, optionMenuItem.text, QPalette::Text); + + //In Sym^3, native menu items have "lines" between them + if (QS60StylePrivate::isSingleClickUi()) { + const QColor lineColorAlpha = QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnLineColors, 15, 0); + //native platform sets each color byte to same value for "line 16" which just defines alpha for + //menuitem lines; lets use first byte "red". + QColor lineColor = optionMenuItem.palette.text().color(); + if (lineColorAlpha.isValid()) + lineColor.setAlpha(lineColorAlpha.red()); + painter->save(); + painter->setPen(lineColor); + + const int lineStartX = optionMenuItem.rect.left() + (QS60StylePrivate::pixelMetric(PM_FrameCornerWidth) - 2) + spacing; + const int lineEndX = optionMenuItem.rect.right() - (QS60StylePrivate::pixelMetric(PM_FrameCornerWidth) - 2) - spacing; + painter->drawLine(QPoint(lineStartX, optionMenuItem.rect.bottom()), QPoint(lineEndX, optionMenuItem.rect.bottom())); + painter->restore(); + } if (!enabled) painter->restore(); } @@ -2555,6 +2596,8 @@ QSize QS60Style::sizeFromContents(ContentsType ct, const QStyleOption *opt, } } sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget); + //native items have small empty areas at the beginning and end of menu item + sz.setWidth(sz.width() + 2 * pixelMetric(PM_MenuHMargin)); if (QS60StylePrivate::isTouchSupported()) //Make itemview easier to use in touch devices //QCommonStyle does not adjust height with horizontal margin, it only adjusts width @@ -2996,7 +3039,6 @@ QRect QS60Style::subElementRect(SubElement element, const QStyleOption *opt, con ret.setWidth(indicatorWidth); } } else { - ret = menuItem->rect; if (!menuItem->icon.isNull()) if (menuItem->direction == Qt::LeftToRight) ret.adjust(indicatorWidth, 0, 0, 0); diff --git a/src/gui/styles/qs60style_s60.cpp b/src/gui/styles/qs60style_s60.cpp index e5c74ad..4bb2ea8 100644 --- a/src/gui/styles/qs60style_s60.cpp +++ b/src/gui/styles/qs60style_s60.cpp @@ -1023,8 +1023,14 @@ TRect QS60StyleModeSpecifics::innerRectFromElement(QS60StylePrivate::SkinFrameEl heightShrink = heightShrink >> 1; break; case QS60StylePrivate::SF_ListHighlight: - widthShrink = widthShrink - 2; - heightShrink = heightShrink - 2; + //In Sym^3 devices highlights are less blocky + if (QSysInfo::s60Version() > QSysInfo::SV_S60_5_0) { + widthShrink += 2; + heightShrink += 2; + } else { + widthShrink -= 2; + heightShrink -= 2; + } break; case QS60StylePrivate::SF_PopupBackground: widthShrink = widthShrink + 5; -- cgit v0.12 From b18a343cc63f93a8e97a8c6c623e56a666775b57 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 15 Jun 2010 15:23:28 +1000 Subject: Fix bug with childrenRect resizing on startup. This also optimizes the implementation. Task-number: QTBUG-11383 --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 28 ++++++++++------------ src/declarative/graphicsitems/qdeclarativeitem_p.h | 7 +++--- .../qdeclarativeitem/data/childrenRectBug.qml | 23 ++++++++++++++++++ .../qdeclarativeitem/tst_qdeclarativeitem.cpp | 17 +++++++++++++ 4 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeitem/data/childrenRectBug.qml diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 18806e7..42b370b 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -231,9 +231,10 @@ QT_BEGIN_NAMESPACE \brief The QDeclarativeContents class gives access to the height and width of an item's contents. */ - -QDeclarativeContents::QDeclarativeContents() : m_x(0), m_y(0), m_width(0), m_height(0) +QDeclarativeContents::QDeclarativeContents(QDeclarativeItem *item) : m_item(item), m_x(0), m_y(0), m_width(0), m_height(0) { + //### optimize + connect(this, SIGNAL(rectChanged(QRectF)), m_item, SIGNAL(childrenRectChanged(QRectF))); } QDeclarativeContents::~QDeclarativeContents() @@ -328,12 +329,8 @@ void QDeclarativeContents::calcWidth(QDeclarativeItem *changed) emit rectChanged(rectF()); } -void QDeclarativeContents::setItem(QDeclarativeItem *item) +void QDeclarativeContents::complete() { - m_item = item; - //### optimize - connect(this, SIGNAL(rectChanged(QRectF)), m_item, SIGNAL(childrenRectChanged(QRectF))); - QList children = m_item->childItems(); for (int i = 0; i < children.count(); ++i) { QDeclarativeItem *child = qobject_cast(children.at(i)); @@ -343,9 +340,7 @@ void QDeclarativeContents::setItem(QDeclarativeItem *item) //###what about changes to visibility? } - //### defer until componentComplete - calcHeight(); - calcWidth(); + calcGeometry(); } void QDeclarativeContents::itemGeometryChanged(QDeclarativeItem *changed, const QRectF &newGeometry, const QRectF &oldGeometry) @@ -360,16 +355,14 @@ void QDeclarativeContents::itemDestroyed(QDeclarativeItem *item) { if (item) QDeclarativeItemPrivate::get(item)->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed); - calcWidth(); - calcHeight(); + calcGeometry(); } void QDeclarativeContents::childRemoved(QDeclarativeItem *item) { if (item) QDeclarativeItemPrivate::get(item)->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed); - calcWidth(); - calcHeight(); + calcGeometry(); } void QDeclarativeContents::childAdded(QDeclarativeItem *item) @@ -1752,8 +1745,9 @@ QRectF QDeclarativeItem::childrenRect() { Q_D(QDeclarativeItem); if (!d->_contents) { - d->_contents = new QDeclarativeContents; - d->_contents->setItem(this); + d->_contents = new QDeclarativeContents(this); + if (d->_componentComplete) + d->_contents->complete(); } return d->_contents->rectF(); } @@ -2619,6 +2613,8 @@ void QDeclarativeItem::componentComplete() } if (d->keyHandler) d->keyHandler->componentComplete(); + if (d->_contents) + d->_contents->complete(); } QDeclarativeStateGroup *QDeclarativeItemPrivate::_states() diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h index 184d6f1..fb416c2 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem_p.h +++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h @@ -83,16 +83,17 @@ class QDeclarativeContents : public QObject, public QDeclarativeItemChangeListen { Q_OBJECT public: - QDeclarativeContents(); + QDeclarativeContents(QDeclarativeItem *item); ~QDeclarativeContents(); QRectF rectF() const; - void setItem(QDeclarativeItem *item); - void childRemoved(QDeclarativeItem *item); void childAdded(QDeclarativeItem *item); + void calcGeometry() { calcWidth(); calcHeight(); } + void complete(); + Q_SIGNALS: void rectChanged(QRectF); diff --git a/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug.qml b/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug.qml new file mode 100644 index 0000000..4a2f056 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug.qml @@ -0,0 +1,23 @@ +import Qt 4.7 + +Rectangle { + width: 400 + height: 200 + + Item { + objectName: "theItem" + anchors.centerIn: parent + width: childrenRect.width + height: childrenRect.height + Rectangle { + id: text1 + anchors.verticalCenter: parent.verticalCenter + width: 100; height: 100; color: "green" + } + Rectangle { + anchors.left: text1.right + anchors.verticalCenter: parent.verticalCenter + width: 100; height: 100; color: "green" + } + } +} diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index c2d3660..0a66245 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -72,6 +72,7 @@ private slots: void transforms(); void transforms_data(); void childrenRect(); + void childrenRectBug(); void childrenProperty(); void resourcesProperty(); @@ -736,6 +737,22 @@ void tst_QDeclarativeItem::childrenRect() delete o; } +// QTBUG-11383 +void tst_QDeclarativeItem::childrenRectBug() +{ + QDeclarativeView *canvas = new QDeclarativeView(0); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/childrenRectBug.qml")); + canvas->show(); + + QGraphicsObject *o = canvas->rootObject(); + QDeclarativeItem *item = o->findChild("theItem"); + QCOMPARE(item->width(), qreal(200)); + QCOMPARE(item->height(), qreal(100)); + QCOMPARE(item->x(), qreal(100)); + + delete canvas; +} + template T *tst_QDeclarativeItem::findItem(QGraphicsObject *parent, const QString &objectName) { -- cgit v0.12 From c1e6d97b9476c859abc3927046144b4006fcf735 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 15 Jun 2010 15:49:08 +1000 Subject: Remove duplicated code. --- src/declarative/graphicsitems/qdeclarativetextedit.cpp | 8 +------- src/declarative/graphicsitems/qdeclarativetextinput.cpp | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 3b4f2a7..3106daf 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -1113,13 +1113,7 @@ void QDeclarativeTextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event) Q_D(QDeclarativeTextEdit); if (d->focusOnPress){ bool hadFocus = hasFocus(); - QGraphicsItem *p = parentItem();//###Is there a better way to find my focus scope? - while(p) { - if (p->flags() & QGraphicsItem::ItemIsFocusScope) - p->setFocus(); - p = p->parentItem(); - } - setFocus(true); + forceFocus(); if (d->showInputPanelOnFocus) { if (hasFocus() && hadFocus && !isReadOnly()) { // re-open input panel on press if already focused diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index 633c01e..cba01ef 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -924,13 +924,7 @@ void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event) Q_D(QDeclarativeTextInput); if(d->focusOnPress){ bool hadFocus = hasFocus(); - QGraphicsItem *p = parentItem();//###Is there a better way to find my focus scope? - while(p) { - if (p->flags() & QGraphicsItem::ItemIsFocusScope) - p->setFocus(); - p = p->parentItem(); - } - setFocus(true); + forceFocus(); if (d->showInputPanelOnFocus) { if (hasFocus() && hadFocus && !isReadOnly()) { // re-open input panel on press if already focused -- cgit v0.12 From d6bcab9e1cfb3a3b91b45269d68a594f6f079914 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 15 Jun 2010 10:14:18 +0200 Subject: Fix regression, remove artificial emboldening of monospaced fonts In change 889e13652e00ba64060e7b62ed3377ea04d44faa we employed usage of artificial emboldening of fonts with FreeType when a bold variant of the font does not exist. This introduced a regression for monospaced fonts, where the contract says that all glyphs must be the same width. Since the artificial emboldening algorithm does not support this contract, it has been turned off for monospaced fonts, reverting to the old behavior for this particular class of fonts. Task-number: QTBUG-11353 Reviewed-by: Paul --- src/gui/text/qfontengine_ft.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp index 9056012..2c4fbab 100644 --- a/src/gui/text/qfontengine_ft.cpp +++ b/src/gui/text/qfontengine_ft.cpp @@ -690,7 +690,7 @@ bool QFontEngineFT::init(FaceId faceId, bool antialias, GlyphFormat format) if (fake_oblique) transform = true; // fake bold - if ((fontDef.weight == QFont::Bold) && !(face->style_flags & FT_STYLE_FLAG_BOLD)) + if ((fontDef.weight == QFont::Bold) && !(face->style_flags & FT_STYLE_FLAG_BOLD) && !FT_IS_FIXED_WIDTH(face)) embolden = true; // underline metrics line_thickness = QFixed::fromFixed(FT_MulFix(face->underline_thickness, face->size->metrics.y_scale)); -- cgit v0.12 From a041e4eca3467c1baa6245b6fb47def127f30f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Tue, 15 Jun 2010 10:45:23 +0200 Subject: Added missing sanity checks in qimage.cpp We should be consistent and do sanity checks whenever we allocate new images. Task-number: QTBUG-1985 Reviewed-by: Eskil --- src/gui/image/qimage.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index d89ffe6..adc2632 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -4210,6 +4210,7 @@ QImage QImage::createHeuristicMask(bool clipTight) const int w = width(); int h = height(); QImage m(w, h, Format_MonoLSB); + QIMAGE_SANITYCHECK_MEMORY(m); m.setColorCount(2); m.setColor(0, QColor(Qt::color0).rgba()); m.setColor(1, QColor(Qt::color1).rgba()); @@ -4302,6 +4303,7 @@ QImage QImage::createMaskFromColor(QRgb color, Qt::MaskMode mode) const if (!d) return QImage(); QImage maskImage(size(), QImage::Format_MonoLSB); + QIMAGE_SANITYCHECK_MEMORY(maskImage); maskImage.fill(0); uchar *s = maskImage.bits(); @@ -4362,6 +4364,7 @@ QImage QImage::mirrored(bool horizontal, bool vertical) const int h = d->height; // Create result image, copy colormap QImage result(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(result); // check if we ran out of of memory.. if (!result.d) @@ -4499,6 +4502,7 @@ QImage QImage::rgbSwapped() const case Format_ARGB32: case Format_ARGB32_Premultiplied: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { uint *q = (uint*)res.scanLine(i); uint *p = (uint*)scanLine(i); @@ -4512,6 +4516,7 @@ QImage QImage::rgbSwapped() const break; case Format_RGB16: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { ushort *q = (ushort*)res.scanLine(i); const ushort *p = (const ushort*)scanLine(i); @@ -4525,6 +4530,7 @@ QImage QImage::rgbSwapped() const break; case Format_ARGB8565_Premultiplied: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { quint8 *p = (quint8*)scanLine(i); const quint8 *end = p + d->width * sizeof(qargb8565); @@ -4537,6 +4543,7 @@ QImage QImage::rgbSwapped() const break; case Format_RGB666: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { qrgb666 *q = reinterpret_cast(res.scanLine(i)); const qrgb666 *p = reinterpret_cast(scanLine(i)); @@ -4549,6 +4556,7 @@ QImage QImage::rgbSwapped() const break; case Format_ARGB6666_Premultiplied: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { qargb6666 *q = reinterpret_cast(res.scanLine(i)); const qargb6666 *p = reinterpret_cast(scanLine(i)); @@ -4561,6 +4569,7 @@ QImage QImage::rgbSwapped() const break; case Format_RGB555: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { ushort *q = (ushort*)res.scanLine(i); const ushort *p = (const ushort*)scanLine(i); @@ -4574,6 +4583,7 @@ QImage QImage::rgbSwapped() const break; case Format_ARGB8555_Premultiplied: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { quint8 *p = (quint8*)scanLine(i); const quint8 *end = p + d->width * sizeof(qargb8555); @@ -4586,6 +4596,7 @@ QImage QImage::rgbSwapped() const break; case Format_RGB888: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { quint8 *q = reinterpret_cast(res.scanLine(i)); const quint8 *p = reinterpret_cast(scanLine(i)); @@ -4601,6 +4612,7 @@ QImage QImage::rgbSwapped() const break; case Format_RGB444: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { quint8 *q = reinterpret_cast(res.scanLine(i)); const quint8 *p = reinterpret_cast(scanLine(i)); @@ -4615,6 +4627,7 @@ QImage QImage::rgbSwapped() const break; case Format_ARGB4444_Premultiplied: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); for (int i = 0; i < d->height; i++) { quint8 *q = reinterpret_cast(res.scanLine(i)); const quint8 *p = reinterpret_cast(scanLine(i)); -- cgit v0.12 From 78560390b948127262a9ebb5f4dd355b6c517e94 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 15 Jun 2010 13:49:26 +0300 Subject: Change $${EPOCROOT} to also have drive if EPOCROOT env variable has it Since sbsv2 toolchain supports having sources and SDK on different drives, $${EPOCROOT} needs to contain drive letter to make it work. Reviewed-by: Jason Barron --- qmake/generators/symbian/symbiancommon.cpp | 3 --- qmake/generators/symbian/symmake_sbsv2.cpp | 4 +++- src/s60installs/s60installs.pro | 4 ++-- tools/shared/symbian/epocroot.cpp | 4 ---- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/qmake/generators/symbian/symbiancommon.cpp b/qmake/generators/symbian/symbiancommon.cpp index 58729d2..3a4bdbc 100644 --- a/qmake/generators/symbian/symbiancommon.cpp +++ b/qmake/generators/symbian/symbiancommon.cpp @@ -433,9 +433,6 @@ void SymbianCommonGenerator::generatePkgFile(const QString &iconFile, bool epocB if (from.size() > 1 && from.at(1) == QLatin1Char(':')) from = from.mid(2); from.prepend(zDir); - } else { - if (from.size() > 1 && from.at(1) == QLatin1Char(':')) - from = from.mid(2); } } diff --git a/qmake/generators/symbian/symmake_sbsv2.cpp b/qmake/generators/symbian/symmake_sbsv2.cpp index c2f1d1a..78f6f85 100644 --- a/qmake/generators/symbian/symmake_sbsv2.cpp +++ b/qmake/generators/symbian/symmake_sbsv2.cpp @@ -99,7 +99,9 @@ void SymbianSbsv2MakefileGenerator::writeSbsDeploymentList(const DeploymentList& fromItem.replace("\\", "/"); toItem.replace("\\", "/"); #if defined(Q_OS_WIN) - toItem.prepend(QDir::current().absolutePath().left(2)); // add drive + // add drive if it doesn't have one yet + if (toItem.size() > 1 && toItem[1] != QLatin1Char(':')) + toItem.prepend(QDir::current().absolutePath().left(2)); #endif t << "OPTION DEPLOY_SOURCE " << fromItem << endl; t << "OPTION DEPLOY_TARGET " << toItem << endl; diff --git a/src/s60installs/s60installs.pro b/src/s60installs/s60installs.pro index d751134..ce0f4f1 100644 --- a/src/s60installs/s60installs.pro +++ b/src/s60installs/s60installs.pro @@ -16,8 +16,8 @@ symbian: { # It is also expected that devices newer than those based on S60 5.0 all have sqlite3.dll. contains(S60_VERSION, 3.1)|contains(S60_VERSION, 3.2)|contains(S60_VERSION, 5.0) { BLD_INF_RULES.prj_exports += \ - "sqlite3.sis $${EPOCROOT}epoc32/data/qt/sis/sqlite3.sis" \ - "sqlite3_selfsigned.sis $${EPOCROOT}epoc32/data/qt/sis/sqlite3_selfsigned.sis" + "sqlite3.sis /epoc32/data/qt/sis/sqlite3.sis" \ + "sqlite3_selfsigned.sis /epoc32/data/qt/sis/sqlite3_selfsigned.sis" symbian-abld|symbian-sbsv2 { sqlitedeployment = \ "; Deploy sqlite onto phone that does not have it already" \ diff --git a/tools/shared/symbian/epocroot.cpp b/tools/shared/symbian/epocroot.cpp index 064e056..ae1dcb1 100644 --- a/tools/shared/symbian/epocroot.cpp +++ b/tools/shared/symbian/epocroot.cpp @@ -105,10 +105,6 @@ static void fixEpocRoot(QString &path) { path.replace("\\", "/"); - if (path.size() > 1 && path[1] == QChar(':')) { - path = path.mid(2); - } - if (!path.size() || path[path.size()-1] != QChar('/')) { path += QChar('/'); } -- cgit v0.12 From c5b06919a8fb5d20aae41f0edf9e2ffa99eb1a8a Mon Sep 17 00:00:00 2001 From: Geir Vattekar Date: Tue, 15 Jun 2010 13:59:41 +0200 Subject: Doc: Documented qputenv and qgetenv Task-number: QTBUG-4041 Reviewed-by: Morten Engvoldsen --- src/corelib/global/qglobal.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 373c0b4..b31c83b 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -2503,6 +2503,19 @@ void qFatal(const char *msg, ...) // getenv is declared as deprecated in VS2005. This function // makes use of the new secure getenv function. +/*! + \relates + + Returns the value of the environment variable with name \a + varName. To get the variable string, use QByteArray::constData(). + + \note qgetenv() was introduced because getenv() from the standard + C library was deprecated in VC2005 (and later versions). qgetenv() + uses the new replacement function in VC, and calls the standard C + library's implementation on all other platforms. + + \sa qputenv() +*/ QByteArray qgetenv(const char *varName) { #if defined(_MSC_VER) && _MSC_VER >= 1400 @@ -2522,6 +2535,20 @@ QByteArray qgetenv(const char *varName) #endif } +/*! + \relates + + This function sets the \a value of the environment variable named + \a varName. It will create the variable if it does not exist. It + returns 0 if the variable could not be set. + + \note qputenv() was introduced because putenv() from the standard + C library was deprecated in VC2005 (and later versions). qputenv() + uses the replacement function in VC, and calls the standard C + library's implementation on all other platforms. + + \sa qgetenv() +*/ bool qputenv(const char *varName, const QByteArray& value) { #if defined(_MSC_VER) && _MSC_VER >= 1400 -- cgit v0.12 From c28efecdcfdd5fa0049bf482cb102814338c0d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Tue, 15 Jun 2010 12:33:39 +0200 Subject: Fixed missing stroke for flat ellipses. The behavior should be the same as for arcs and rects. Task-number: QTBUG-2743 Reviewed-by: Eskil --- src/gui/painting/qpaintengine_raster.cpp | 1 + src/gui/painting/qpaintengine_x11.cpp | 5 +++++ src/gui/painting/qpainter.cpp | 4 ---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 9f1128b..f10f12f 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -3789,6 +3789,7 @@ void QRasterPaintEngine::drawEllipse(const QRectF &rect) if (((qpen_style(s->lastPen) == Qt::SolidLine && s->flags.fast_pen) || (qpen_style(s->lastPen) == Qt::NoPen && !s->flags.antialiased)) && qMax(rect.width(), rect.height()) < QT_RASTER_COORD_LIMIT + && !rect.isEmpty() && s->matrix.type() <= QTransform::TxScale) // no shear { ensureBrush(); diff --git a/src/gui/painting/qpaintengine_x11.cpp b/src/gui/painting/qpaintengine_x11.cpp index b8ad9b3..910b2df 100644 --- a/src/gui/painting/qpaintengine_x11.cpp +++ b/src/gui/painting/qpaintengine_x11.cpp @@ -1453,6 +1453,11 @@ void QX11PaintEngine::drawEllipse(const QRectF &rect) void QX11PaintEngine::drawEllipse(const QRect &rect) { + if (rect.isEmpty()) { + drawRects(&rect, 1); + return; + } + Q_D(QX11PaintEngine); QRect devclip(SHRT_MIN, SHRT_MIN, SHRT_MAX*2 - 1, SHRT_MAX*2 - 1); QRect r(rect); diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index e8c4599..d17c711 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -4238,8 +4238,6 @@ void QPainter::drawEllipse(const QRectF &r) return; QRectF rect(r.normalized()); - if (rect.isEmpty()) - return; if (d->extended) { d->extended->drawEllipse(rect); @@ -4281,8 +4279,6 @@ void QPainter::drawEllipse(const QRect &r) return; QRect rect(r.normalized()); - if (rect.isEmpty()) - return; if (d->extended) { d->extended->drawEllipse(rect); -- cgit v0.12 From df55141aa260c8a10c06aa990b6f20d6fb4718f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Tue, 15 Jun 2010 13:06:19 +0200 Subject: Fixed QImageReader::format() inconsistency. If state is set to ReadHeader before canRead() then setFormat("png") never gets called. We should make sure that setFormat() gets set whenever canRead() returns true. Task-number: QTBUG-2263 Reviewed-by: Kent Hansen --- src/gui/image/qbmphandler.cpp | 10 +++++---- src/gui/image/qpnghandler.cpp | 10 +++++---- src/gui/image/qppmhandler.cpp | 10 +++++---- src/gui/image/qxbmhandler.cpp | 10 +++++---- src/gui/image/qxpmhandler.cpp | 8 ++++++-- src/plugins/imageformats/gif/qgifhandler.cpp | 4 ++-- src/plugins/imageformats/jpeg/qjpeghandler.cpp | 10 +++++---- src/plugins/imageformats/mng/qmnghandler.cpp | 8 ++++---- tests/auto/qimagereader/tst_qimagereader.cpp | 28 ++++++++++++++++++++++++++ 9 files changed, 70 insertions(+), 28 deletions(-) diff --git a/src/gui/image/qbmphandler.cpp b/src/gui/image/qbmphandler.cpp index 42e19b8..074b8f0 100644 --- a/src/gui/image/qbmphandler.cpp +++ b/src/gui/image/qbmphandler.cpp @@ -674,13 +674,15 @@ bool QBmpHandler::readHeader() bool QBmpHandler::canRead() const { - if (state == Ready) { - if (!canRead(device())) - return false; + if (state == Ready && !canRead(device())) + return false; + + if (state != Error) { setFormat("bmp"); return true; } - return state != Error; + + return false; } bool QBmpHandler::canRead(QIODevice *device) diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp index dd31834..2cf8222 100644 --- a/src/gui/image/qpnghandler.cpp +++ b/src/gui/image/qpnghandler.cpp @@ -892,13 +892,15 @@ QPngHandler::~QPngHandler() bool QPngHandler::canRead() const { - if (d->state == QPngHandlerPrivate::Ready) { - if (!canRead(device())) - return false; + if (d->state == QPngHandlerPrivate::Ready && !canRead(device())) + return false; + + if (d->state != QPngHandlerPrivate::Error) { setFormat("png"); return true; } - return d->state != QPngHandlerPrivate::Error; + + return false; } bool QPngHandler::canRead(QIODevice *device) diff --git a/src/gui/image/qppmhandler.cpp b/src/gui/image/qppmhandler.cpp index cbbbef4..a9e796c 100644 --- a/src/gui/image/qppmhandler.cpp +++ b/src/gui/image/qppmhandler.cpp @@ -409,13 +409,15 @@ bool QPpmHandler::readHeader() bool QPpmHandler::canRead() const { - if (state == Ready) { - if (!canRead(device(), &subType)) - return false; + if (state == Ready && !canRead(device(), &subType)) + return false; + + if (state != Error) { setFormat(subType); return true; } - return state != Error; + + return false; } bool QPpmHandler::canRead(QIODevice *device, QByteArray *subType) diff --git a/src/gui/image/qxbmhandler.cpp b/src/gui/image/qxbmhandler.cpp index 385340a..0dd4e99 100644 --- a/src/gui/image/qxbmhandler.cpp +++ b/src/gui/image/qxbmhandler.cpp @@ -261,13 +261,15 @@ bool QXbmHandler::readHeader() bool QXbmHandler::canRead() const { - if (state == Ready) { - if (!canRead(device())) - return false; + if (state == Ready && !canRead(device())) + return false; + + if (state != Error) { setFormat("xbm"); return true; } - return state != Error; + + return false; } bool QXbmHandler::canRead(QIODevice *device) diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp index a475cd0..b97afd3 100644 --- a/src/gui/image/qxpmhandler.cpp +++ b/src/gui/image/qxpmhandler.cpp @@ -1225,11 +1225,15 @@ bool QXpmHandler::readImage(QImage *image) bool QXpmHandler::canRead() const { - if (state == Ready && canRead(device())) { + if (state == Ready && !canRead(device())) + return false; + + if (state != Error) { setFormat("xpm"); return true; } - return state != Error; + + return false; } bool QXpmHandler::canRead(QIODevice *device) diff --git a/src/plugins/imageformats/gif/qgifhandler.cpp b/src/plugins/imageformats/gif/qgifhandler.cpp index 8abc2d1..5e2157e 100644 --- a/src/plugins/imageformats/gif/qgifhandler.cpp +++ b/src/plugins/imageformats/gif/qgifhandler.cpp @@ -1061,12 +1061,12 @@ bool QGifHandler::imageIsComing() const bool QGifHandler::canRead() const { - if (!nextDelay && canRead(device())) { + if (!nextDelay && canRead(device()) || imageIsComing()) { setFormat("gif"); return true; } - return imageIsComing(); + return false; } bool QGifHandler::canRead(QIODevice *device) diff --git a/src/plugins/imageformats/jpeg/qjpeghandler.cpp b/src/plugins/imageformats/jpeg/qjpeghandler.cpp index 72dde15..60e7cce 100644 --- a/src/plugins/imageformats/jpeg/qjpeghandler.cpp +++ b/src/plugins/imageformats/jpeg/qjpeghandler.cpp @@ -802,13 +802,15 @@ QJpegHandler::~QJpegHandler() bool QJpegHandler::canRead() const { - if(d->state == QJpegHandlerPrivate::Ready) { - if (!canRead(device())) - return false; + if(d->state == QJpegHandlerPrivate::Ready && !canRead(device())) + return false; + + if (d->state != QJpegHandlerPrivate::Error) { setFormat("jpeg"); return true; } - return d->state != QJpegHandlerPrivate::Error; + + return false; } bool QJpegHandler::canRead(QIODevice *device) diff --git a/src/plugins/imageformats/mng/qmnghandler.cpp b/src/plugins/imageformats/mng/qmnghandler.cpp index d408e6c..c134fd6 100644 --- a/src/plugins/imageformats/mng/qmnghandler.cpp +++ b/src/plugins/imageformats/mng/qmnghandler.cpp @@ -381,10 +381,10 @@ QMngHandler::~QMngHandler() bool QMngHandler::canRead() const { Q_D(const QMngHandler); - if (!d->haveReadNone) - return (!d->haveReadAll || (d->haveReadAll && (d->nextIndex < d->frameCount))); - - if (canRead(device())) { + if ((!d->haveReadNone + && (!d->haveReadAll || (d->haveReadAll && (d->nextIndex < d->frameCount)))) + || canRead(device())) + { setFormat("mng"); return true; } diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp index aadee5b..7e57973 100644 --- a/tests/auto/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/qimagereader/tst_qimagereader.cpp @@ -138,6 +138,9 @@ private slots: void sizeBeforeRead_data(); void sizeBeforeRead(); + void sizeBeforeFormat_data(); + void sizeBeforeFormat(); + void imageFormatBeforeRead_data(); void imageFormatBeforeRead(); @@ -706,6 +709,31 @@ void tst_QImageReader::sizeBeforeRead() QCOMPARE(size, image.size()); } +void tst_QImageReader::sizeBeforeFormat_data() +{ + imageFormat_data(); +} + +void tst_QImageReader::sizeBeforeFormat() +{ + QFETCH(QString, fileName); + + QByteArray formatA, formatB; + + { + QImageReader reader(prefix + fileName); + formatA = reader.format(); + } + + { + QImageReader reader(prefix + fileName); + QSize size = reader.size(); + formatB = reader.format(); + } + + QCOMPARE(formatA, formatB); +} + void tst_QImageReader::imageFormatBeforeRead_data() { imageFormat_data(); -- cgit v0.12 From 86b13101afe31934eddb0c904ac6d2815cd39e5e Mon Sep 17 00:00:00 2001 From: Sami Merila Date: Tue, 15 Jun 2010 15:34:01 +0300 Subject: Stylus menu for Share (QT app) is different from native S60 apps This is part two of the fix. This fix makes the menu item to be layoutted always with space reserved for checkbox indicator, even if the menu item is not having one (just like native side). Also, the right and left "gap areas" (between menu border and menu item highlight) match the native side more closely now. There is still some difference if using QMenu (instead of QComboBoxListView), since we can't just ignore margin set from widget. Also, the Sym^3 "separator lines" are now started from correct position. Finally, the menu item height now matches the native side. Task-number: QT-3295 Reviewed-by: Alessandro Portale --- src/gui/styles/qs60style.cpp | 66 +++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 9745d9c..1a8dd78 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -1768,40 +1768,41 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, //todo: move the vertical spacing stuff into subElementRect const int vSpacing = QS60StylePrivate::pixelMetric(PM_LayoutVerticalSpacing); QStyleOptionMenuItem optionCheckBox; - if (checkable){ - const int hSpacing = QS60StylePrivate::pixelMetric(PM_LayoutHorizontalSpacing); - optionCheckBox.QStyleOptionMenuItem::operator=(*menuItem); - optionCheckBox.rect.setWidth(pixelMetric(PM_IndicatorWidth)); - optionCheckBox.rect.setHeight(pixelMetric(PM_IndicatorHeight)); - optionCheckBox.rect.moveCenter(QPoint( - optionCheckBox.rect.center().x(), - menuItem->rect.center().y())); - const int moveByX = optionCheckBox.rect.width() + vSpacing + - pixelMetric(PM_DefaultFrameWidth) + 1; - if (optionMenuItem.direction == Qt::LeftToRight) { - if (iconRect.isValid()) { - iconRect.translate(moveByX, 0); - iconRect.setWidth(iconRect.width() + vSpacing); - } - if (textRect.isValid()) { - textRect.translate(moveByX, 0); - textRect.setWidth(textRect.width() - moveByX - vSpacing); - } - optionCheckBox.rect.translate(vSpacing >> 1, hSpacing >> 1); - } else { - if (textRect.isValid()) - textRect.setWidth(textRect.width() - moveByX); - if (iconRect.isValid()) { - iconRect.setWidth(iconRect.width() + vSpacing); - iconRect.translate(-optionCheckBox.rect.width() - vSpacing, 0); - } - optionCheckBox.rect.translate(textRect.width() + iconRect.width(), 0); + + //Regardless of checkbox visibility, make room for it, this mirrors native implementation, + //where text and icon placement is static regardless of content of menu item. + const int hSpacing = QS60StylePrivate::pixelMetric(PM_LayoutHorizontalSpacing); + optionCheckBox.QStyleOptionMenuItem::operator=(*menuItem); + optionCheckBox.rect.setWidth(pixelMetric(PM_IndicatorWidth)); + optionCheckBox.rect.setHeight(pixelMetric(PM_IndicatorHeight)); + optionCheckBox.rect.moveCenter(QPoint( + optionCheckBox.rect.center().x(), + menuItem->rect.center().y())); + const int moveByX = optionCheckBox.rect.width() + vSpacing + + pixelMetric(PM_DefaultFrameWidth); + if (optionMenuItem.direction == Qt::LeftToRight) { + if (iconRect.isValid()) { + iconRect.translate(moveByX, 0); + iconRect.setWidth(iconRect.width() + vSpacing); + } + if (textRect.isValid()) { + textRect.translate(moveByX, 0); + textRect.setWidth(textRect.width() - moveByX - vSpacing); + } + optionCheckBox.rect.translate(vSpacing + pixelMetric(PM_DefaultFrameWidth), hSpacing >> 1); + } else { + if (textRect.isValid()) + textRect.setWidth(textRect.width() - moveByX); + if (iconRect.isValid()) { + iconRect.setWidth(iconRect.width() + vSpacing); + iconRect.translate(-optionCheckBox.rect.width() - vSpacing, 0); } + optionCheckBox.rect.translate(textRect.width() + iconRect.width(), 0); } const bool selected = (option->state & State_Selected) && (option->state & State_Enabled); - const int spacing = pixelMetric(PM_DefaultFrameWidth) * 2; if (selected) { + const int spacing = pixelMetric(PM_DefaultFrameWidth) * 2; int start; int end; if (QApplication::layoutDirection() == Qt::LeftToRight) { start = optionMenuItem.rect.left() + spacing; @@ -1872,6 +1873,7 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, //In Sym^3, native menu items have "lines" between them if (QS60StylePrivate::isSingleClickUi()) { const QColor lineColorAlpha = QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnLineColors, 15, 0); + const int spacing = QS60StylePrivate::pixelMetric(PM_FrameCornerWidth); //native platform sets each color byte to same value for "line 16" which just defines alpha for //menuitem lines; lets use first byte "red". QColor lineColor = optionMenuItem.palette.text().color(); @@ -2281,6 +2283,8 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti if (QS60StylePrivate::canDrawThemeBackground(option->palette.base(), widget) && option->palette.window().texture().cacheKey() == QS60StylePrivate::m_themePalette->window().texture().cacheKey()) + //todo: for combobox listviews, the background should include area for menu scrollers, + //but this produces drawing issues as we need to turn clipping off. QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_PopupBackground, painter, option->rect, flags); else commonStyleDraws = true; @@ -2597,11 +2601,11 @@ QSize QS60Style::sizeFromContents(ContentsType ct, const QStyleOption *opt, } sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget); //native items have small empty areas at the beginning and end of menu item - sz.setWidth(sz.width() + 2 * pixelMetric(PM_MenuHMargin)); + sz.setWidth(sz.width() + 2 * pixelMetric(PM_MenuHMargin) + 2 * QS60StylePrivate::pixelMetric(PM_FrameCornerWidth)); if (QS60StylePrivate::isTouchSupported()) //Make itemview easier to use in touch devices //QCommonStyle does not adjust height with horizontal margin, it only adjusts width - sz.setHeight(sz.height() + 2 * pixelMetric(PM_FocusFrameVMargin)); + sz.setHeight(sz.height() + 2 * pixelMetric(PM_FocusFrameVMargin) - 8); //QCommonstyle adds 8 to height that this style handles through PM values break; #ifndef QT_NO_COMBOBOX case CT_ComboBox: { -- cgit v0.12 From 28ce5c1f2c0dbbfe45b5c3744bf03a2548c12223 Mon Sep 17 00:00:00 2001 From: Sami Merila Date: Tue, 15 Jun 2010 16:09:41 +0300 Subject: ComboBox popuplist is not correctly layouted in fullscreen mode This is part two of the fix for issue QTBUG-9913. This corrects the left margin of the ComboBox menu to start from the left screen border (for LetToRight UI Layout), instead of having small margin. Task-number: QTBUG-9913 Reviewed-by: Alessandro Portale --- src/gui/styles/qs60style.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 1a8dd78..45bcc00 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -2870,16 +2870,7 @@ QRect QS60Style::subControlRect(ComplexControl control, const QStyleOptionComple } break; case SC_ComboBoxListBoxPopup: { - const QRect desktopContent = QApplication::desktop()->availableGeometry(); - - // take the size of this and position bottom above available area - QRect popupRect; - const int width = desktopContent.width() - pixelMetric(PM_LayoutRightMargin) - pixelMetric(PM_LayoutLeftMargin); - popupRect.setWidth(width); - popupRect.setHeight(desktopContent.height()); //combobox resets height anyway based on content - popupRect.setBottom(desktopContent.bottom()); - popupRect.translate(pixelMetric(PM_LayoutLeftMargin), 0); - ret = popupRect; + ret = QApplication::desktop()->availableGeometry(); } break; default: -- cgit v0.12 From 0ee0c77738faaeced93980dab33867d42efcf2cc Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 15 Jun 2010 10:57:28 +1000 Subject: Document section.delegate --- src/declarative/graphicsitems/qdeclarativelistview.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index dcf18af..48ac4a4 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1936,6 +1936,8 @@ void QDeclarativeListView::setCacheBuffer(int b) /*! \qmlproperty string ListView::section.property \qmlproperty enumeration ListView::section.criteria + \qmlproperty Component ListView::section.delegate + These properties hold the expression to be evaluated for the \l section attached property. \c section.property hold the name of the property to use to determine @@ -1949,6 +1951,8 @@ void QDeclarativeListView::setCacheBuffer(int b) \o ViewSection.FirstCharacter - section is the first character of the property value. \endlist + \c section.delegate holds the delegate component for each section. + Each item in the list has attached properties named \c ListView.section and \c ListView.prevSection. These may be used to place a section header for related items. The example below assumes that the model is sorted by size of @@ -1985,7 +1989,7 @@ QString QDeclarativeListView::currentSection() const These properties hold the move and resize animation speed of the highlight delegate. - \c highlightFollowsCurrentItem must be true for these properties + \l highlightFollowsCurrentItem must be true for these properties to have effect. The default value for the speed properties is 400 pixels/second. -- cgit v0.12 From cbc1541ecf32ef0c52086b0fc83e1bca70a668ba Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 15 Jun 2010 14:46:37 +1000 Subject: Document QML_IMPORT_TRACE --- doc/src/declarative/qdeclarativedebugging.qdoc | 31 ++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/doc/src/declarative/qdeclarativedebugging.qdoc b/doc/src/declarative/qdeclarativedebugging.qdoc index 4ff7fde..99dd2d2 100644 --- a/doc/src/declarative/qdeclarativedebugging.qdoc +++ b/doc/src/declarative/qdeclarativedebugging.qdoc @@ -60,8 +60,35 @@ Rectangle { \section1 Debugging Transitions When a transition doesn't look quite right, it can be helpful to view it in slow -motion to see what is happening more clearly. The \l {Qt Declarative UI Runtime}{qml} tool provides a -"Slow Down Animations" menu option to facilitate this. +motion to see what is happening more clearly. This functionality is supported +in the \l {Qt Declarative UI Runtime}{qmlviewer} tool: to enable this, +click on the "Debugging" menu, then "Slow Down Animations". + + +\section1 Debugging module imports + +The \c QML_IMPORT_TRACE environment variable can be set to enable debug output +from QML's import loading mechanisms. + +For example, for a simple QML file like this: + +\qml +import Qt 4.7 + +Rectangle { width: 100; height: 100 } +\endqml + +If you set \c {QML_IMPORT_TRACE=1} before running the \l {Qt Declarative UI Runtime}{qmlviewer} +(or your QML C++ application), you will see output similar to this: + +\code +QDeclarativeImportDatabase::addImportPath "/qt-sdk/imports" +QDeclarativeImportDatabase::addImportPath "/qt-sdk/bin/QMLViewer.app/Contents/MacOS" +QDeclarativeImportDatabase::addToImport 0x106237370 "." -1.-1 File as "" +QDeclarativeImportDatabase::addToImport 0x106237370 "Qt" 4.7 Library as "" +QDeclarativeImportDatabase::resolveType "Rectangle" = "QDeclarativeRectangle" +\endcode + \section1 Debugging with Qt Creator -- cgit v0.12 From eb05fde709f958a0a67f83455c02dcde3dfc1493 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 15 Jun 2010 15:55:58 +1000 Subject: Clean up list examples --- .../declarative/modelviews/listview/PetsModel.qml | 101 +++++++++ .../modelviews/listview/RecipesModel.qml | 130 +++++++++++ .../listview/content/ClickAutoRepeating.qml | 71 ------ .../modelviews/listview/content/MediaButton.qml | 75 ------- .../listview/content/PressAndHoldButton.qml | 79 +++++++ .../modelviews/listview/content/TextButton.qml | 78 +++++++ .../modelviews/listview/dummydata/MyPetsModel.qml | 101 --------- .../modelviews/listview/dummydata/Recipes.qml | 130 ----------- .../modelviews/listview/dynamiclist.qml | 244 +++++++-------------- .../modelviews/listview/expandingdelegates.qml | 74 ++++--- .../declarative/modelviews/listview/highlight.qml | 34 ++- .../modelviews/listview/highlightranges.qml | 70 +++--- .../declarative/modelviews/listview/sections.qml | 77 +++---- 13 files changed, 578 insertions(+), 686 deletions(-) create mode 100644 examples/declarative/modelviews/listview/PetsModel.qml create mode 100644 examples/declarative/modelviews/listview/RecipesModel.qml delete mode 100644 examples/declarative/modelviews/listview/content/ClickAutoRepeating.qml delete mode 100644 examples/declarative/modelviews/listview/content/MediaButton.qml create mode 100644 examples/declarative/modelviews/listview/content/PressAndHoldButton.qml create mode 100644 examples/declarative/modelviews/listview/content/TextButton.qml delete mode 100644 examples/declarative/modelviews/listview/dummydata/MyPetsModel.qml delete mode 100644 examples/declarative/modelviews/listview/dummydata/Recipes.qml diff --git a/examples/declarative/modelviews/listview/PetsModel.qml b/examples/declarative/modelviews/listview/PetsModel.qml new file mode 100644 index 0000000..70cdcdd --- /dev/null +++ b/examples/declarative/modelviews/listview/PetsModel.qml @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt 4.7 + +// ListModel allows free form list models to be defined and populated. + +ListModel { + id: petsModel + ListElement { + name: "Polly" + type: "Parrot" + age: 12 + size: "Small" + } + ListElement { + name: "Penny" + type: "Turtle" + age: 4 + size: "Small" + } + ListElement { + name: "Warren" + type: "Rabbit" + age: 2 + size: "Small" + } + ListElement { + name: "Spot" + type: "Dog" + age: 9 + size: "Medium" + } + ListElement { + name: "Schrödinger" + type: "Cat" + age: 2 + size: "Medium" + } + ListElement { + name: "Joey" + type: "Kangaroo" + age: 1 + size: "Medium" + } + ListElement { + name: "Kimba" + type: "Bunny" + age: 65 + size: "Large" + } + ListElement { + name: "Rover" + type: "Dog" + age: 5 + size: "Large" + } + ListElement { + name: "Tiny" + type: "Elephant" + age: 15 + size: "Large" + } +} diff --git a/examples/declarative/modelviews/listview/RecipesModel.qml b/examples/declarative/modelviews/listview/RecipesModel.qml new file mode 100644 index 0000000..03ab961 --- /dev/null +++ b/examples/declarative/modelviews/listview/RecipesModel.qml @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt 4.7 + +ListModel { + id: recipesModel + ListElement { + title: "Pancakes" + picture: "content/pics/pancakes.jpg" + ingredients: " +
    +
  • 1 cup (150g) self-raising flour +
  • 1 tbs caster sugar +
  • 3/4 cup (185ml) milk +
  • 1 egg +
+ " + method: " +
    +
  1. Sift flour and sugar together into a bowl. Add a pinch of salt. +
  2. Beat milk and egg together, then add to dry ingredients. Beat until smooth. +
  3. Pour mixture into a pan on medium heat and cook until bubbles appear on the surface. +
  4. Turn over and cook other side until golden. +
+ " + } + ListElement { + title: "Fruit Salad" + picture: "content/pics/fruit-salad.jpg" + ingredients: "* Seasonal Fruit" + method: "* Chop fruit and place in a bowl." + } + ListElement { + title: "Vegetable Soup" + picture: "content/pics/vegetable-soup.jpg" + ingredients: " +
    +
  • 1 onion +
  • 1 turnip +
  • 1 potato +
  • 1 carrot +
  • 1 head of celery +
  • 1 1/2 litres of water +
+ " + method: " +
    +
  1. Chop vegetables. +
  2. Boil in water until vegetables soften. +
  3. Season with salt and pepper to taste. +
+ " + } + ListElement { + title: "Hamburger" + picture: "content/pics/hamburger.jpg" + ingredients: " +
    +
  • 500g minced beef +
  • Seasoning +
  • lettuce, tomato, onion, cheese +
  • 1 hamburger bun for each burger +
+ " + method: " +
    +
  1. Mix the beef, together with seasoning, in a food processor. +
  2. Shape the beef into burgers. +
  3. Grill the burgers for about 5 mins on each side (until cooked through) +
  4. Serve each burger on a bun with ketchup, cheese, lettuce, tomato and onion. +
+ " + } + ListElement { + title: "Lemonade" + picture: "content/pics/lemonade.jpg" + ingredients: " +
    +
  • 1 cup Lemon Juice +
  • 1 cup Sugar +
  • 6 Cups of Water (2 cups warm water, 4 cups cold water) +
+ " + method: " +
    +
  1. Pour 2 cups of warm water into a pitcher and stir in sugar until it dissolves. +
  2. Pour in lemon juice, stir again, and add 4 cups of cold water. +
  3. Chill or serve over ice cubes. +
+ " + } +} diff --git a/examples/declarative/modelviews/listview/content/ClickAutoRepeating.qml b/examples/declarative/modelviews/listview/content/ClickAutoRepeating.qml deleted file mode 100644 index dc23b78..0000000 --- a/examples/declarative/modelviews/listview/content/ClickAutoRepeating.qml +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import Qt 4.7 - -Item { - id: page - property int repeatdelay: 300 - property int repeatperiod: 75 - property bool isPressed: false - - signal pressed - signal released - signal clicked - - SequentialAnimation on isPressed { - running: false - id: autoRepeat - PropertyAction { target: page; property: "isPressed"; value: true } - ScriptAction { script: page.pressed() } - ScriptAction { script: page.clicked() } - PauseAnimation { duration: repeatdelay } - SequentialAnimation { - loops: Animation.Infinite - ScriptAction { script: page.clicked() } - PauseAnimation { duration: repeatperiod } - } - } - MouseArea { - anchors.fill: parent - onPressed: autoRepeat.start() - onReleased: { autoRepeat.stop(); parent.isPressed = false; page.released() } - } -} diff --git a/examples/declarative/modelviews/listview/content/MediaButton.qml b/examples/declarative/modelviews/listview/content/MediaButton.qml deleted file mode 100644 index 2aed6e0..0000000 --- a/examples/declarative/modelviews/listview/content/MediaButton.qml +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import Qt 4.7 - -Item { - property variant text - signal clicked - - id: container - Image { - id: normal - source: "pics/button.png" - } - Image { - id: pressed - source: "pics/button-pressed.png" - opacity: 0 - } - MouseArea { - id: clickRegion - anchors.fill: normal - onClicked: { container.clicked(); } - } - Text { - font.bold: true - color: "white" - anchors.centerIn: normal - text: container.text - } - width: normal.width - - states: State { - name: "Pressed" - when: clickRegion.pressed == true - PropertyChanges { target: pressed; opacity: 1 } - } -} diff --git a/examples/declarative/modelviews/listview/content/PressAndHoldButton.qml b/examples/declarative/modelviews/listview/content/PressAndHoldButton.qml new file mode 100644 index 0000000..7c174e3 --- /dev/null +++ b/examples/declarative/modelviews/listview/content/PressAndHoldButton.qml @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt 4.7 + +Image { + id: container + + property int repeatDelay: 300 + property int repeatDuration: 75 + property bool pressed: false + + signal clicked + + scale: pressed ? 0.9 : 1 + + SequentialAnimation on pressed { + id: autoRepeatClicks + running: false + + PropertyAction { target: container; property: "pressed"; value: true } + ScriptAction { script: container.clicked() } + PauseAnimation { duration: repeatDelay } + + SequentialAnimation { + loops: Animation.Infinite + ScriptAction { script: container.clicked() } + PauseAnimation { duration: repeatDuration } + } + } + + MouseArea { + anchors.fill: parent + + onPressed: autoRepeatClicks.start() + onReleased: { + autoRepeatClicks.stop() + container.pressed = false + } + } +} + diff --git a/examples/declarative/modelviews/listview/content/TextButton.qml b/examples/declarative/modelviews/listview/content/TextButton.qml new file mode 100644 index 0000000..ded7a11 --- /dev/null +++ b/examples/declarative/modelviews/listview/content/TextButton.qml @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt 4.7 + +Rectangle { + id: container + + property alias text: label.text + + signal clicked + + width: label.width + 20; height: label.height + 6 + smooth: true + radius: 10 + + gradient: Gradient { + GradientStop { id: gradientStop; position: 0.0; color: palette.light } + GradientStop { position: 1.0; color: palette.button } + } + + SystemPalette { id: palette } + + MouseArea { + id: mouseArea + anchors.fill: parent + onClicked: { container.clicked() } + } + + Text { + id: label + anchors.centerIn: parent + } + + states: State { + name: "pressed" + when: mouseArea.pressed + PropertyChanges { target: gradientStop; color: palette.dark } + } +} + diff --git a/examples/declarative/modelviews/listview/dummydata/MyPetsModel.qml b/examples/declarative/modelviews/listview/dummydata/MyPetsModel.qml deleted file mode 100644 index 70cdcdd..0000000 --- a/examples/declarative/modelviews/listview/dummydata/MyPetsModel.qml +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import Qt 4.7 - -// ListModel allows free form list models to be defined and populated. - -ListModel { - id: petsModel - ListElement { - name: "Polly" - type: "Parrot" - age: 12 - size: "Small" - } - ListElement { - name: "Penny" - type: "Turtle" - age: 4 - size: "Small" - } - ListElement { - name: "Warren" - type: "Rabbit" - age: 2 - size: "Small" - } - ListElement { - name: "Spot" - type: "Dog" - age: 9 - size: "Medium" - } - ListElement { - name: "Schrödinger" - type: "Cat" - age: 2 - size: "Medium" - } - ListElement { - name: "Joey" - type: "Kangaroo" - age: 1 - size: "Medium" - } - ListElement { - name: "Kimba" - type: "Bunny" - age: 65 - size: "Large" - } - ListElement { - name: "Rover" - type: "Dog" - age: 5 - size: "Large" - } - ListElement { - name: "Tiny" - type: "Elephant" - age: 15 - size: "Large" - } -} diff --git a/examples/declarative/modelviews/listview/dummydata/Recipes.qml b/examples/declarative/modelviews/listview/dummydata/Recipes.qml deleted file mode 100644 index 03ab961..0000000 --- a/examples/declarative/modelviews/listview/dummydata/Recipes.qml +++ /dev/null @@ -1,130 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import Qt 4.7 - -ListModel { - id: recipesModel - ListElement { - title: "Pancakes" - picture: "content/pics/pancakes.jpg" - ingredients: " -
    -
  • 1 cup (150g) self-raising flour -
  • 1 tbs caster sugar -
  • 3/4 cup (185ml) milk -
  • 1 egg -
- " - method: " -
    -
  1. Sift flour and sugar together into a bowl. Add a pinch of salt. -
  2. Beat milk and egg together, then add to dry ingredients. Beat until smooth. -
  3. Pour mixture into a pan on medium heat and cook until bubbles appear on the surface. -
  4. Turn over and cook other side until golden. -
- " - } - ListElement { - title: "Fruit Salad" - picture: "content/pics/fruit-salad.jpg" - ingredients: "* Seasonal Fruit" - method: "* Chop fruit and place in a bowl." - } - ListElement { - title: "Vegetable Soup" - picture: "content/pics/vegetable-soup.jpg" - ingredients: " -
    -
  • 1 onion -
  • 1 turnip -
  • 1 potato -
  • 1 carrot -
  • 1 head of celery -
  • 1 1/2 litres of water -
- " - method: " -
    -
  1. Chop vegetables. -
  2. Boil in water until vegetables soften. -
  3. Season with salt and pepper to taste. -
- " - } - ListElement { - title: "Hamburger" - picture: "content/pics/hamburger.jpg" - ingredients: " -
    -
  • 500g minced beef -
  • Seasoning -
  • lettuce, tomato, onion, cheese -
  • 1 hamburger bun for each burger -
- " - method: " -
    -
  1. Mix the beef, together with seasoning, in a food processor. -
  2. Shape the beef into burgers. -
  3. Grill the burgers for about 5 mins on each side (until cooked through) -
  4. Serve each burger on a bun with ketchup, cheese, lettuce, tomato and onion. -
- " - } - ListElement { - title: "Lemonade" - picture: "content/pics/lemonade.jpg" - ingredients: " -
    -
  • 1 cup Lemon Juice -
  • 1 cup Sugar -
  • 6 Cups of Water (2 cups warm water, 4 cups cold water) -
- " - method: " -
    -
  1. Pour 2 cups of warm water into a pitcher and stir in sugar until it dissolves. -
  2. Pour in lemon juice, stir again, and add 4 cups of cold water. -
  3. Chill or serve over ice cubes. -
- " - } -} diff --git a/examples/declarative/modelviews/listview/dynamiclist.qml b/examples/declarative/modelviews/listview/dynamiclist.qml index df2e094..0e290f5 100644 --- a/examples/declarative/modelviews/listview/dynamiclist.qml +++ b/examples/declarative/modelviews/listview/dynamiclist.qml @@ -37,16 +37,18 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - import Qt 4.7 import "content" -import "../../ui-components/scrollbar" + +// This example shows how items can be dynamically added to and removed from +// a ListModel, and how these list modifications can be animated. Rectangle { id: container width: 640; height: 480 color: "#343434" + // The model: ListModel { id: fruitModel @@ -77,55 +79,43 @@ Rectangle { ListElement { description: "Smelly" } ] } - ListElement { - name: "Elderberry"; cost: 0.05 - attributes: [ - ListElement { description: "Berry" } - ] - } - ListElement { - name: "Fig"; cost: 0.25 - attributes: [ - ListElement { description: "Flower" } - ] - } } + // The delegate for each fruit in the model: Component { - id: fruitDelegate - + id: listDelegate + Item { - id: wrapper - width: container.width; height: 55 + id: delegateItem + width: listView.width; height: 55 + clip: true - Column { - id: moveButtons - x: 5; width: childrenRect.width; anchors.verticalCenter: parent.verticalCenter + Row { + anchors.verticalCenter: parent.verticalCenter + spacing: 10 - Image { - source: "content/pics/go-up.png" - MouseArea { anchors.fill: parent; onClicked: fruitModel.move(index,index-1,1) } - } - Image { source: "content/pics/go-down.png" - MouseArea { anchors.fill: parent; onClicked: fruitModel.move(index,index+1,1) } + Column { + Image { + source: "content/pics/go-up.png" + MouseArea { anchors.fill: parent; onClicked: fruitModel.move(index,index-1,1) } + } + Image { source: "content/pics/go-down.png" + MouseArea { anchors.fill: parent; onClicked: fruitModel.move(index,index+1,1) } + } } - } - Column { - anchors { right: itemButtons.left; verticalCenter: parent.verticalCenter; left: moveButtons.right; leftMargin: 10 } + Column { + anchors.verticalCenter: parent.verticalCenter - Text { - id: label - width: parent.width - color: "White" - font.bold: true; font.pixelSize: 15 - text: name; elide: Text.ElideRight - } - Row { - spacing: 5 - Repeater { - model: attributes - Component { + Text { + text: name + font.pixelSize: 15 + color: "white" + } + Row { + spacing: 5 + Repeater { + model: attributes Text { text: description; color: "White" } } } @@ -133,149 +123,81 @@ Rectangle { } Row { - id: itemButtons - - anchors { right: removeButton.left; rightMargin: 35; verticalCenter: parent.verticalCenter } - width: childrenRect.width + anchors.verticalCenter: parent.verticalCenter + anchors.right: parent.right spacing: 10 - Image { + PressAndHoldButton { + anchors.verticalCenter: parent.verticalCenter source: "content/pics/list-add.png" - scale: clickUp.isPressed ? 0.9 : 1 - - ClickAutoRepeating { - id: clickUp - anchors.fill: parent - onClicked: fruitModel.setProperty(index, "cost", cost+0.25) - } + onClicked: fruitModel.setProperty(index, "cost", cost + 0.25) } - Text { id: costText; text: '$'+Number(cost).toFixed(2); font.pixelSize: 15; color: "White"; font.bold: true; } + Text { + id: costText + anchors.verticalCenter: parent.verticalCenter + text: '$' + Number(cost).toFixed(2) + font.pixelSize: 15 + color: "white" + font.bold: true + } - Image { + PressAndHoldButton { + anchors.verticalCenter: parent.verticalCenter source: "content/pics/list-remove.png" - scale: clickDown.isPressed ? 0.9 : 1 + onClicked: fruitModel.setProperty(index, "cost", Math.max(0,cost-0.25)) + } - ClickAutoRepeating { - id: clickDown - anchors.fill: parent - onClicked: fruitModel.setProperty(index, "cost", Math.max(0,cost-0.25)) - } + Image { + source: "content/pics/archive-remove.png" + MouseArea { anchors.fill:parent; onClicked: fruitModel.remove(index) } } } - Image { - id: removeButton - anchors { verticalCenter: parent.verticalCenter; right: parent.right; rightMargin: 10 } - source: "content/pics/archive-remove.png" - MouseArea { anchors.fill:parent; onClicked: fruitModel.remove(index) } + // Animate adding and removing of items: + + ListView.onAdd: SequentialAnimation { + PropertyAction { target: delegateItem; property: "height"; value: 0 } + NumberAnimation { target: delegateItem; property: "height"; to: 55; duration: 250; easing.type: Easing.InOutQuad } } - // Animate adding and removing items - ListView.delayRemove: true // so that the item is not destroyed immediately - ListView.onAdd: state = "add" - ListView.onRemove: state = "remove" - states: [ - State { - name: "add" - PropertyChanges { target: wrapper; height: 55; clip: true } - }, - State { - name: "remove" - PropertyChanges { target: wrapper; height: 0; clip: true } - } - ] - transitions: [ - Transition { - to: "add" - SequentialAnimation { - NumberAnimation { properties: "height"; from: 0; to: 55 } - PropertyAction { target: wrapper; property: "state"; value: "" } - } - }, - Transition { - to: "remove" - SequentialAnimation { - NumberAnimation { properties: "height" } - // Make sure delayRemove is set back to false so that the item can be destroyed - PropertyAction { target: wrapper; property: "ListView.delayRemove"; value: false } - } - } - ] + ListView.onRemove: SequentialAnimation { + PropertyAction { target: delegateItem; property: "ListView.delayRemove"; value: true } + NumberAnimation { target: delegateItem; property: "height"; to: 0; duration: 250; easing.type: Easing.InOutQuad } + + // Make sure delayRemove is set back to false so that the item can be destroyed + PropertyAction { target: delegateItem; property: "ListView.delayRemove"; value: false } + } } } + // The view: ListView { - id: view - anchors { top: parent.top; left: parent.left; right: parent.right; bottom: buttons.top } + id: listView + anchors.fill: parent; anchors.margins: 20 model: fruitModel - delegate: fruitDelegate - } - - // Attach scrollbar to the right edge of the view. - ScrollBar { - id: verticalScrollBar - - width: 8; height: view.height; anchors.right: view.right - opacity: 0 - orientation: Qt.Vertical - position: view.visibleArea.yPosition - pageSize: view.visibleArea.heightRatio - - // Only show the scrollbar when the view is moving. - states: State { - name: "ShowBars"; when: view.movingVertically - PropertyChanges { target: verticalScrollBar; opacity: 1 } - } - transitions: Transition { - NumberAnimation { properties: "opacity"; duration: 400 } - } + delegate: listDelegate } Row { - id: buttons - - x: 8; width: childrenRect.width; height: childrenRect.height - anchors { bottom: parent.bottom; bottomMargin: 8 } - spacing: 8 - - Image { - source: "content/pics/archive-insert.png" - - MouseArea { - anchors.fill: parent - onClicked: { - fruitModel.append({ - "name": "Pizza Margarita", - "cost": 5.95, - "attributes": [{"description": "Cheese"},{"description": "Tomato"}] - }) - } - } - } - - Image { - source: "content/pics/archive-insert.png" - - MouseArea { - anchors.fill: parent; - onClicked: { - fruitModel.insert(0, { - "name": "Pizza Supreme", - "cost": 9.95, - "attributes": [{"description": "Cheese"},{"description": "Tomato"},{"description": "The Works"}] - }) - } + anchors { left: parent.left; bottom: parent.bottom; margins: 20 } + spacing: 10 + + TextButton { + text: "Add an item" + onClicked: { + fruitModel.append({ + "name": "Pizza Margarita", + "cost": 5.95, + "attributes": [{"description": "Cheese"}, {"description": "Tomato"}] + }) } } - Image { - source: "content/pics/archive-remove.png" - - MouseArea { - anchors.fill: parent - onClicked: fruitModel.clear() - } + TextButton { + text: "Remove all items" + onClicked: fruitModel.clear() } } } + diff --git a/examples/declarative/modelviews/listview/expandingdelegates.qml b/examples/declarative/modelviews/listview/expandingdelegates.qml index f4b97ea..94ea48f 100644 --- a/examples/declarative/modelviews/listview/expandingdelegates.qml +++ b/examples/declarative/modelviews/listview/expandingdelegates.qml @@ -41,7 +41,7 @@ import Qt 4.7 import "content" -// This example illustrates expanding a list item to show a more detailed view +// This example illustrates expanding a list item to show a more detailed view. Rectangle { id: page @@ -49,13 +49,13 @@ Rectangle { color: "black" // Delegate for the recipes. This delegate has two modes: - // 1. the list mode (default), which just shows the picture and title of the recipe. - // 2. the details mode, which also shows the ingredients and method. + // 1. List mode (default), which just shows the picture and title of the recipe. + // 2. Details mode, which also shows the ingredients and method. Component { id: recipeDelegate Item { - id: wrapper + id: recipe // Create a property to contain the visibility of the details. // We can bind multiple element's opacity to this one property, @@ -63,14 +63,15 @@ Rectangle { // want to fade. property real detailsOpacity : 0 - width: list.width + width: listView.width + height: 70 // A simple rounded rectangle for the background Rectangle { id: background - x: 1; y: 2; width: parent.width - 2; height: parent.height - 4 - color: "#FEFFEE" - border.color: "#FFBE4F" + x: 2; y: 2; width: parent.width - x*2; height: parent.height - y*2 + color: "ivory" + border.color: "orange" radius: 5 } @@ -78,50 +79,53 @@ Rectangle { // When clicked it changes mode to 'Details'. If we are already // in Details mode, then no change will happen. MouseArea { - id: pageMouse anchors.fill: parent - onClicked: wrapper.state = 'Details'; + onClicked: recipe.state = 'Details'; } - // Layout the page. Picture, title and ingredients at the top, method at the + // Lay out the page: picture, title and ingredients at the top, and method at the // bottom. Note that elements that should not be visible in the list - // mode have their opacity set to wrapper.detailsOpacity. + // mode have their opacity set to recipe.detailsOpacity. Row { id: topLayout - x: 10; y: 10; height: recipePic.height; width: parent.width + x: 10; y: 10; height: recipeImage.height; width: parent.width spacing: 10 Image { - id: recipePic - source: picture; width: 48; height: 48 + id: recipeImage + width: 50; height: 50 + source: picture } Column { - width: background.width-recipePic.width-20; height: recipePic.height; + width: background.width - recipeImage.width - 20; height: recipeImage.height spacing: 5 - Text { id: name; text: title; font.bold: true; font.pointSize: 16 } + Text { + text: title + font.bold: true; font.pointSize: 16 + } Text { text: "Ingredients" font.pointSize: 12; font.bold: true - opacity: wrapper.detailsOpacity + opacity: recipe.detailsOpacity } Text { text: ingredients wrapMode: Text.WordWrap width: parent.width - opacity: wrapper.detailsOpacity + opacity: recipe.detailsOpacity } } } Item { id: details - x: 10; width: parent.width-20 + x: 10; width: parent.width - 20 anchors { top: topLayout.bottom; topMargin: 10; bottom: parent.bottom; bottomMargin: 10 } - opacity: wrapper.detailsOpacity + opacity: recipe.detailsOpacity Text { id: methodTitle @@ -153,30 +157,28 @@ Rectangle { } // A button to close the detailed view, i.e. set the state back to default (''). - MediaButton { - y: 10; anchors { right: background.right; rightMargin: 5 } - opacity: wrapper.detailsOpacity + TextButton { + y: 10 + anchors { right: background.right; rightMargin: 10 } + opacity: recipe.detailsOpacity text: "Close" - onClicked: wrapper.state = ''; + onClicked: recipe.state = ''; } - // Set the default height to the height of the picture, plus margin. - height: 68 - states: State { name: "Details" PropertyChanges { target: background; color: "white" } - PropertyChanges { target: recipePic; width: 128; height: 128 } // Make picture bigger - PropertyChanges { target: wrapper; detailsOpacity: 1; x: 0 } // Make details visible - PropertyChanges { target: wrapper; height: list.height } // Fill the entire list area with the detailed view + PropertyChanges { target: recipeImage; width: 130; height: 130 } // Make picture bigger + PropertyChanges { target: recipe; detailsOpacity: 1; x: 0 } // Make details visible + PropertyChanges { target: recipe; height: listView.height } // Fill the entire list area with the detailed view // Move the list so that this item is at the top. - PropertyChanges { target: wrapper.ListView.view; explicit: true; contentY: wrapper.y } + PropertyChanges { target: recipe.ListView.view; explicit: true; contentY: recipe.y } // Disallow flicking while we're in detailed view - PropertyChanges { target: wrapper.ListView.view; interactive: false } + PropertyChanges { target: recipe.ListView.view; interactive: false } } transitions: Transition { @@ -191,10 +193,10 @@ Rectangle { // The actual list ListView { - id: list + id: listView anchors.fill: parent - clip: true - model: Recipes + model: RecipesModel {} delegate: recipeDelegate + clip: true } } diff --git a/examples/declarative/modelviews/listview/highlight.qml b/examples/declarative/modelviews/listview/highlight.qml index 239272a..5748974 100644 --- a/examples/declarative/modelviews/listview/highlight.qml +++ b/examples/declarative/modelviews/listview/highlight.qml @@ -41,12 +41,7 @@ import Qt 4.7 Rectangle { - width: 400; height: 300 - - // MyPets model is defined in dummydata/MyPetsModel.qml - // The launcher automatically loads files in dummydata/* to assist - // development without a real data source. - // This one contains my pets. + width: 200; height: 300 // Define a delegate component. A component will be // instantiated for each visible item in the list. @@ -54,42 +49,45 @@ Rectangle { id: petDelegate Item { id: wrapper - width: 200; height: 50 + width: 200; height: 55 Column { Text { text: 'Name: ' + name } Text { text: 'Type: ' + type } Text { text: 'Age: ' + age } } - // Use the ListView.isCurrentItem attached property to - // indent the item if it is the current item. + // indent the item if it is the current item states: State { name: "Current" when: wrapper.ListView.isCurrentItem - PropertyChanges { target: wrapper; x: 10 } + PropertyChanges { target: wrapper; x: 20 } } transitions: Transition { NumberAnimation { properties: "x"; duration: 200 } } } } - // Specify a highlight with custom movement. Note that highlightFollowsCurrentItem - // is set to false in the ListView so that we can control how the - // highlight moves to the current item. + + // Define a highlight with customised movement between items. Component { - id: petHighlight + id: highlightBar Rectangle { width: 200; height: 50 color: "#FFFF88" - SpringFollow on y { to: list1.currentItem.y; spring: 3; damping: 0.1 } + SpringFollow on y { to: listView.currentItem.y; spring: 3; damping: 0.1 } } } ListView { - id: list1 + id: listView width: 200; height: parent.height - model: MyPetsModel + + model: PetsModel {} delegate: petDelegate - highlight: petHighlight; highlightFollowsCurrentItem: false focus: true + + // Set the highlight delegate. Note we must also set highlightFollowsCurrentItem + // to false so the highlight delegate can control how the highlight is moved. + highlight: highlightBar + highlightFollowsCurrentItem: false } } diff --git a/examples/declarative/modelviews/listview/highlightranges.qml b/examples/declarative/modelviews/listview/highlightranges.qml index a8a95c4..162d8b7 100644 --- a/examples/declarative/modelviews/listview/highlightranges.qml +++ b/examples/declarative/modelviews/listview/highlightranges.qml @@ -43,46 +43,20 @@ import Qt 4.7 Rectangle { width: 600; height: 300 - // MyPets model is defined in dummydata/MyPetsModel.qml - // The viewer automatically loads files in dummydata/* to assist - // development without a real data source. - // This one contains my pets. - - // Define a delegate component. A component will be - // instantiated for each visible item in the list. - Component { - id: petDelegate - Item { - width: 200; height: 50 - Column { - Text { text: 'Name: ' + name } - Text { text: 'Type: ' + type } - Text { text: 'Age: ' + age } - } - } - } - - // Define a highlight component. Just one of these will be instantiated - // by each ListView and placed behind the current item. - Component { - id: petHighlight - Rectangle { color: "#FFFF88" } - } - // Show the model in three lists, with different highlight ranges. // preferredHighlightBegin and preferredHighlightEnd set the // range in which to attempt to maintain the highlight. // - // Note that the second and third ListView - // set their currentIndex to be the same as the first, and that - // the first ListView is given keyboard focus. + // The second and third ListView set their currentIndex to be the + // same as the first, and the first ListView is given keyboard focus. // - // The default mode allows the currentItem to move freely - // within the visible area. If it would move outside the visible - // area, the view is scrolled to keep it visible. + // The first list does not set a highlight range, so its currentItem + // can move freely within the visible area. If it moves outside the + // visible area, the view is automatically scrolled to keep the current + // item visible. // // The second list sets a highlight range which attempts to keep the - // current item within the the bounds of the range, however + // current item within the the bounds of the range. However, // items will not scroll beyond the beginning or end of the view, // forcing the highlight to move outside the range at the ends. // @@ -98,21 +72,22 @@ Rectangle { ListView { id: list1 width: 200; height: parent.height - model: MyPetsModel + model: PetsModel {} delegate: petDelegate - highlight: petHighlight + highlight: Rectangle { color: "lightsteelblue" } currentIndex: list3.currentIndex focus: true } ListView { id: list2 - x: 200; width: 200; height: parent.height - model: MyPetsModel + x: list1.width + width: 200; height: parent.height + model: PetsModel {} delegate: petDelegate - highlight: petHighlight + highlight: Rectangle { color: "yellow" } currentIndex: list1.currentIndex preferredHighlightBegin: 80; preferredHighlightEnd: 220 highlightRangeMode: ListView.ApplyRange @@ -120,14 +95,25 @@ Rectangle { ListView { id: list3 - x: 400; width: 200; height: parent.height - model: MyPetsModel + x: list1.width + list2.width + width: 200; height: parent.height + model: PetsModel {} delegate: petDelegate - highlight: Rectangle { color: "lightsteelblue" } + highlight: Rectangle { color: "yellow" } currentIndex: list1.currentIndex preferredHighlightBegin: 125; preferredHighlightEnd: 125 highlightRangeMode: ListView.StrictlyEnforceRange - flickDeceleration: 1000 + } + + // The delegate for each list + Component { + id: petDelegate + Column { + width: 200 + Text { text: 'Name: ' + name } + Text { text: 'Type: ' + type } + Text { text: 'Age: ' + age } + } } } diff --git a/examples/declarative/modelviews/listview/sections.qml b/examples/declarative/modelviews/listview/sections.qml index d2f9aba..8c038a0 100644 --- a/examples/declarative/modelviews/listview/sections.qml +++ b/examples/declarative/modelviews/listview/sections.qml @@ -42,70 +42,43 @@ import Qt 4.7 //! [0] Rectangle { + id: container width: 200 - height: 240 + height: 250 - // MyPets model is defined in dummydata/MyPetsModel.qml - // The viewer automatically loads files in dummydata/* to assist - // development without a real data source. - // This one contains my pets. - - // Define a delegate component that includes a separator for sections. - Component { - id: petDelegate - - Item { - id: wrapper - width: 200 - height: desc.height // height is the combined height of the description and the section separator + ListModel { + id: animalsModel + ListElement { name: "Parrot"; size: "Small" } + ListElement { name: "Guinea pig"; size: "Small" } + ListElement { name: "Dog"; size: "Medium" } + ListElement { name: "Cat"; size: "Medium" } + ListElement { name: "Elephant"; size: "Large" } + } - Item { - id: desc - x: 5; height: layout.height + 4 + // The delegate for each section header + Component { + id: sectionHeading + Rectangle { + width: container.width + height: childrenRect.height + color: "lightsteelblue" - Column { - id: layout - y: 2 - Text { text: 'Name: ' + name } - Text { text: 'Type: ' + type } - Text { text: 'Age: ' + age } - } + Text { + text: section + font.bold: true } } } - // Define a highlight component. Just one of these will be instantiated - // by each ListView and placed behind the current item. - Component { - id: petHighlight - Rectangle { color: "#FFFF88" } - } - - // The list ListView { - id: myList + anchors.fill: parent + model: animalsModel + delegate: Text { text: name } - width: 200; height: parent.height - model: MyPetsModel - delegate: petDelegate - highlight: petHighlight - focus: true - - // The sectionExpression is simply the size of the pet. - // We use this to determine which section we are in above. section.property: "size" section.criteria: ViewSection.FullString - section.delegate: Rectangle { - color: "lightsteelblue" - width: 200 - height: 20 - Text { - x: 2; height: parent.height - verticalAlignment: Text.AlignVCenter - text: section - font.bold: true - } - } + section.delegate: sectionHeading } } //! [0] + -- cgit v0.12