From 17fea75fb7c5c8cee9d5610e3886f2ec4c489d7b Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Wed, 16 Oct 2013 17:07:13 +0200 Subject: Optimize TableView by using ImageProvider This optimizes tableview as we were not able to utilize the image atlas efficiently without it. Change-Id: I3cce48b7557d843fb057cc1597dc4363c35bdef8 Reviewed-by: Caroline Chao Reviewed-by: J-P Nurmi --- src/controls/Private/qmldir | 1 - src/controls/Private/qquickstyleitem.cpp | 41 +++++++++++++++++++++ src/controls/Private/qquickstyleitem_p.h | 9 +++++ src/controls/Styles/Desktop/RowItemSingleton.qml | 46 ++++++++++++++++++++++++ src/controls/Styles/Desktop/TableViewStyle.qml | 19 +++++----- src/controls/Styles/Desktop/qmldir | 2 ++ src/controls/Styles/styles.pri | 2 ++ src/controls/plugin.cpp | 3 +- 8 files changed, 110 insertions(+), 13 deletions(-) create mode 100644 src/controls/Styles/Desktop/RowItemSingleton.qml create mode 100644 src/controls/Styles/Desktop/qmldir (limited to 'src') diff --git a/src/controls/Private/qmldir b/src/controls/Private/qmldir index f099634c..35138780 100644 --- a/src/controls/Private/qmldir +++ b/src/controls/Private/qmldir @@ -20,4 +20,3 @@ MenuContentItem 1.0 MenuContentItem.qml MenuContentScroller 1.0 MenuContentScroller.qml ColumnMenuContent 1.0 ColumnMenuContent.qml singleton TextSingleton 1.0 TextSingleton.qml - diff --git a/src/controls/Private/qquickstyleitem.cpp b/src/controls/Private/qquickstyleitem.cpp index 68f86d36..a14a22d1 100644 --- a/src/controls/Private/qquickstyleitem.cpp +++ b/src/controls/Private/qquickstyleitem.cpp @@ -1684,4 +1684,45 @@ void QQuickStyleItem::updatePolish() } } +QPixmap QQuickTableRowImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) +{ + Q_UNUSED (requestedSize); + int width = 16; + int height = 16; + if (size) + *size = QSize(width, height); + + QPixmap pixmap(width, height); + + QStyleOptionViewItem opt; + opt.state |= QStyle::State_Enabled; + opt.rect = QRect(0, 0, width, height); + QString style = qApp->style()->metaObject()->className(); + opt.features = 0; + + if (id.contains("selected")) + opt.state |= QStyle::State_Selected; + + if (id.contains("active")) { + opt.state |= QStyle::State_Active; + opt.palette.setCurrentColorGroup(QPalette::Active); + } else + opt.palette.setCurrentColorGroup(QPalette::Inactive); + + if (id.contains("alternate")) + opt.features |= QStyleOptionViewItem::Alternate; + + QPalette pal = QApplication::palette("QAbstractItemView"); + if (opt.state & QStyle::State_Selected && (style.contains("Mac") || + !qApp->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected))) { + pal.setCurrentColorGroup(opt.palette.currentColorGroup()); + pixmap.fill(pal.highlight().color()); + } else { + pixmap.fill(pal.base().color()); + QPainter pixpainter(&pixmap); + qApp->style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, &pixpainter); + } + return pixmap; +} + QT_END_NAMESPACE diff --git a/src/controls/Private/qquickstyleitem_p.h b/src/controls/Private/qquickstyleitem_p.h index 7ab37a52..a13cd4cc 100644 --- a/src/controls/Private/qquickstyleitem_p.h +++ b/src/controls/Private/qquickstyleitem_p.h @@ -44,6 +44,7 @@ #include #include +#include #include "qquickpadding_p.h" QT_BEGIN_NAMESPACE @@ -51,6 +52,14 @@ QT_BEGIN_NAMESPACE class QWidget; class QStyleOption; +class QQuickTableRowImageProvider : public QQuickImageProvider +{ +public: + QQuickTableRowImageProvider() + : QQuickImageProvider(QQuickImageProvider::Pixmap) {} + QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize); +}; + class QQuickStyleItem: public QQuickItem { Q_OBJECT diff --git a/src/controls/Styles/Desktop/RowItemSingleton.qml b/src/controls/Styles/Desktop/RowItemSingleton.qml new file mode 100644 index 00000000..b78fc043 --- /dev/null +++ b/src/controls/Styles/Desktop/RowItemSingleton.qml @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +pragma Singleton +import QtQuick.Controls.Private 1.0 +StyleItem { + elementType: "itemrow" +} diff --git a/src/controls/Styles/Desktop/TableViewStyle.qml b/src/controls/Styles/Desktop/TableViewStyle.qml index d636b1b8..88611ab5 100644 --- a/src/controls/Styles/Desktop/TableViewStyle.qml +++ b/src/controls/Styles/Desktop/TableViewStyle.qml @@ -40,6 +40,7 @@ import QtQuick 2.1 import QtQuick.Controls 1.1 import QtQuick.Controls.Private 1.0 +import "." ScrollViewStyle { id: root @@ -81,17 +82,13 @@ ScrollViewStyle { styleData.column === 0 ? "beginning" : "" } - property Component rowDelegate: StyleItem { - id: rowstyle - elementType: "itemrow" - activeControl: styleData.alternate ? "alternate" : "" - selected: styleData.selected ? true : false - height: Math.max(16, rowstyle.implicitHeight) - active: styleData.hasActiveFocus - border.left: 4 - border.right: 4 - textureWidth: 16 - textureHeight: 16 + property Component rowDelegate: BorderImage { + visible: styleData.selected || styleData.alternate + source: "image://__tablerow/" + (styleData.alternate ? "alternate_" : "") + + (styleData.selected ? "selected_" : "") + + (styleData.hasActiveFocus ? "active" : "") + height: Math.max(16, RowItemSingleton.implicitHeight) + border.left: 4 ; border.right: 4 } property Component itemDelegate: Item { diff --git a/src/controls/Styles/Desktop/qmldir b/src/controls/Styles/Desktop/qmldir new file mode 100644 index 00000000..ac80635c --- /dev/null +++ b/src/controls/Styles/Desktop/qmldir @@ -0,0 +1,2 @@ +singleton RowItemSingleton 1.0 RowItemSingleton.qml + diff --git a/src/controls/Styles/styles.pri b/src/controls/Styles/styles.pri index ba0f8f44..5a36767e 100644 --- a/src/controls/Styles/styles.pri +++ b/src/controls/Styles/styles.pri @@ -25,6 +25,8 @@ STYLES_QML_FILES = \ # Desktop STYLES_QML_FILES += \ + $$PWD/Desktop/qmldir \ + $$PWD/Desktop/RowItemSingleton.qml \ $$PWD/Desktop/ButtonStyle.qml \ $$PWD/Desktop/BusyIndicatorStyle.qml \ $$PWD/Desktop/CheckBoxStyle.qml \ diff --git a/src/controls/plugin.cpp b/src/controls/plugin.cpp index 52e7cb0d..2a676e48 100644 --- a/src/controls/plugin.cpp +++ b/src/controls/plugin.cpp @@ -57,6 +57,7 @@ #include "Private/qquickcontrolsprivate_p.h" #ifdef QT_WIDGETS_LIB +#include #include "Private/qquickstyleitem_p.h" #endif @@ -134,8 +135,8 @@ void QtQuickControlsPlugin::initializeEngine(QQmlEngine *engine, const char *uri #ifdef QT_WIDGETS_LIB qmlRegisterType(private_uri, 1, 0, "StyleItem"); + engine->addImageProvider("__tablerow", new QQuickTableRowImageProvider); #endif - engine->addImageProvider("desktoptheme", new QQuickDesktopIconProvider); if (isLoadedFromResource()) engine->addImportPath(QStringLiteral("qrc:/")); -- cgit v1.2.1