OSDN Git Service

QuickDesigner.itemLibrary: enable mouse wheel interaction in items view
authorJörg Schummer <ext-jorg.2.schummer@nokia.com>
Mon, 31 May 2010 12:27:52 +0000 (15:27 +0300)
committerKai Koehne <kai.koehne@nokia.com>
Tue, 8 Jun 2010 14:52:32 +0000 (16:52 +0200)
Task-number: BAUHAUS-657

src/plugins/qmldesigner/components/itemlibrary/itemlibrary.cpp
src/plugins/qmldesigner/components/itemlibrary/itemlibrary.h
src/plugins/qmldesigner/components/itemlibrary/qml/ItemsView.qml
src/plugins/qmldesigner/components/itemlibrary/qml/ItemsViewStyle.qml
src/plugins/qmldesigner/components/itemlibrary/qml/Scrollbar.qml

index a812f29..48164c5 100644 (file)
@@ -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);
+}
+
 }
index 26637e5..0eff37d 100644 (file)
@@ -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:
index 002a003..6b47b38 100644 (file)
@@ -60,6 +60,10 @@ Rectangle {
 
     // public
 
+    function scrollView(delta) {
+        scrollbar.scroll(-delta / style.scrollbarWheelDeltaFactor)
+    }
+
     function resetView() {
         expandAllEntries()
         scrollbar.reset()
index 13242e3..1cdae22 100644 (file)
@@ -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"
 
index a882c2f..34dca1c 100644 (file)
@@ -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)
     }
 }