diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.cpp index a812f298680e33435c7e6903ff2785c9f2f3133d..48164c5f9eef22cb6ae513513953e24bb80dfd40 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.cpp @@ -153,6 +153,7 @@ ItemLibrary::ItemLibrary(QWidget *parent) : QDeclarativeItem *rootItem = qobject_cast<QDeclarativeItem*>(m_d->m_itemsView->rootObject()); connect(rootItem, SIGNAL(itemSelected(int)), this, SLOT(showItemInfo(int))); connect(rootItem, SIGNAL(itemDragged(int)), this, SLOT(startDragAndDrop(int))); + connect(this, SIGNAL(scrollItemsView(QVariant)), rootItem, SLOT(scrollView(QVariant))); connect(this, SIGNAL(resetItemsView()), rootItem, SLOT(resetView())); /* create Resources view and its model */ @@ -318,4 +319,14 @@ void ItemLibrary::showItemInfo(int /*itemLibId*/) // qDebug() << "showing item info about id" << itemLibId; } +void ItemLibrary::wheelEvent(QWheelEvent *event) +{ + if (m_d->m_stackedWidget->currentIndex() == 0 && + m_d->m_itemsView->rect().contains(event->pos())) { + emit scrollItemsView(event->delta()); + event->accept(); + } else + QFrame::wheelEvent(event); +} + } diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.h index 26637e5a40074b550edf1703bd1f043dd3eb64fb..0eff37dee910e7e35f924c9f96ec8f4faa422a28 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.h +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.h @@ -61,8 +61,12 @@ public Q_SLOTS: void startDragAndDrop(int itemLibId); void showItemInfo(int itemLibId); +protected: + void wheelEvent(QWheelEvent *event); + signals: void itemActivated(const QString& itemName); + void scrollItemsView(QVariant delta); void resetItemsView(); private: diff --git a/src/plugins/qmldesigner/components/itemlibrary/qml/ItemsView.qml b/src/plugins/qmldesigner/components/itemlibrary/qml/ItemsView.qml index 002a003d694db4d8fb59b4496cbc2e24e3e6deaa..6b47b38c77848551c79db408eab81232233e8e0f 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/qml/ItemsView.qml +++ b/src/plugins/qmldesigner/components/itemlibrary/qml/ItemsView.qml @@ -60,6 +60,10 @@ Rectangle { // public + function scrollView(delta) { + scrollbar.scroll(-delta / style.scrollbarWheelDeltaFactor) + } + function resetView() { expandAllEntries() scrollbar.reset() diff --git a/src/plugins/qmldesigner/components/itemlibrary/qml/ItemsViewStyle.qml b/src/plugins/qmldesigner/components/itemlibrary/qml/ItemsViewStyle.qml index 13242e3ae37eee5dc807a299ade8810c0660e5de..1cdae226dcb244a06de36e5c01a85c7a83102d8b 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/qml/ItemsViewStyle.qml +++ b/src/plugins/qmldesigner/components/itemlibrary/qml/ItemsViewStyle.qml @@ -41,6 +41,7 @@ Item { property string scrollbarGradientMiddleColor: "#656565" property string scrollbarGradientEndColor: "#888888" property int scrollbarClickScrollAmount: 40 + property int scrollbarWheelDeltaFactor: 4 property string itemNameTextColor: "#FFFFFF" diff --git a/src/plugins/qmldesigner/components/itemlibrary/qml/Scrollbar.qml b/src/plugins/qmldesigner/components/itemlibrary/qml/Scrollbar.qml index a882c2fa140b0804b86d9a2e67fbef4d0fc19d9d..34dca1c30aac20ac87aa4bb5892e7eee595998a7 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/qml/Scrollbar.qml +++ b/src/plugins/qmldesigner/components/itemlibrary/qml/Scrollbar.qml @@ -38,6 +38,10 @@ Item { property variant flickable + function scroll(delta) { + handle.y = Math.max(0, Math.min(scrollHeight, handle.y + delta)) + } + function reset() { handle.y = 0 } @@ -100,7 +104,7 @@ Item { anchors.right: parent.right anchors.top: parent.top anchors.bottom: handle.top - onClicked: handle.y = Math.max(0, handle.y - style.scrollbarClickScrollAmount) + onClicked: scroll(-style.scrollbarClickScrollAmount) } Item { @@ -151,6 +155,6 @@ Item { anchors.right: parent.right anchors.top: handle.bottom anchors.bottom: parent.bottom - onClicked: handle.y = Math.min(scrollHeight, handle.y + style.scrollbarClickScrollAmount) + onClicked: scroll(style.scrollbarClickScrollAmount) } }