]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistview.cpp
Handle font and palette changes in Dolphin list views.
[dolphin.git] / src / kitemviews / kitemlistview.cpp
index b3d805a917ef2c07be519c49acd33a3ce5f6ff8c..ab420cab15c05b6b1418e6663b14810924fc6095 100644 (file)
@@ -111,8 +111,7 @@ KItemListView::KItemListView(QGraphicsWidget* parent) :
 
     m_sizeHintResolver = new KItemListSizeHintResolver(this);
 
-    m_layouter = new KItemListViewLayouter(this);
-    m_layouter->setSizeHintResolver(m_sizeHintResolver);
+    m_layouter = new KItemListViewLayouter(m_sizeHintResolver, this);
 
     m_animation = new KItemListViewAnimation(this);
     connect(m_animation, SIGNAL(finished(QGraphicsWidget*,KItemListViewAnimation::AnimationType)),
@@ -460,9 +459,9 @@ int KItemListView::lastVisibleIndex() const
     return m_layouter->lastVisibleIndex();
 }
 
-QSizeF KItemListView::itemSizeHint(int index) const
+void KItemListView::calculateItemSizeHints(QVector<QSizeF>& sizeHints) const
 {
-    return widgetCreator()->itemSizeHint(index, this);
+    widgetCreator()->calculateItemSizeHints(sizeHints, this);
 }
 
 void KItemListView::setSupportsItemExpanding(bool supportsExpanding)
@@ -609,12 +608,12 @@ KItemListHeader* KItemListView::header() const
     return m_header;
 }
 
-QPixmap KItemListView::createDragPixmap(const QSet<int>& indexes) const
+QPixmap KItemListView::createDragPixmap(const KItemSet& indexes) const
 {
     QPixmap pixmap;
 
     if (indexes.count() == 1) {
-        KItemListWidget* item = m_visibleItems.value(indexes.toList().first());
+        KItemListWidget* item = m_visibleItems.value(indexes.first());
         QGraphicsView* graphicsView = scene()->views()[0];
         if (item && graphicsView) {
             pixmap = item->createDragPixmap(0, graphicsView);
@@ -894,11 +893,23 @@ void KItemListView::onTransactionEnd()
 
 bool KItemListView::event(QEvent* event)
 {
-    // Forward all events to the controller and handle them there
-    if (!m_editingRole && m_controller && m_controller->processEvent(event, transform())) {
-        event->accept();
-        return true;
+    switch (event->type()) {
+    case QEvent::PaletteChange:
+        updatePalette();
+        break;
+
+    case QEvent::FontChange:
+        updateFont();
+        break;
+
+    default:
+        // Forward all other events to the controller and handle them there
+        if (!m_editingRole && m_controller && m_controller->processEvent(event, transform())) {
+            event->accept();
+            return true;
+        }
     }
+
     return QGraphicsWidget::event(event);
 }
 
@@ -951,6 +962,27 @@ QList<KItemListWidget*> KItemListView::visibleItemListWidgets() const
     return m_visibleItems.values();
 }
 
+void KItemListView::updateFont()
+{
+    if (scene() && !scene()->views().isEmpty()) {
+        KItemListStyleOption option = styleOption();
+        option.font = scene()->views().first()->font();
+        option.fontMetrics = QFontMetrics(option.font);
+
+        setStyleOption(option);
+    }
+}
+
+void KItemListView::updatePalette()
+{
+    if (scene() && !scene()->views().isEmpty()) {
+        KItemListStyleOption option = styleOption();
+        option.palette = scene()->views().first()->palette();
+
+        setStyleOption(option);
+    }
+}
+
 void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
 {
     if (m_itemSize.isEmpty()) {
@@ -1305,7 +1337,7 @@ void KItemListView::slotCurrentChanged(int current, int previous)
     QAccessible::updateAccessibility(this, current+1, QAccessible::Focus);
 }
 
-void KItemListView::slotSelectionChanged(const QSet<int>& current, const QSet<int>& previous)
+void KItemListView::slotSelectionChanged(const KItemSet& current, const KItemSet& previous)
 {
     Q_UNUSED(previous);
 
@@ -1502,7 +1534,7 @@ void KItemListView::setController(KItemListController* controller)
         if (previous) {
             KItemListSelectionManager* selectionManager = previous->selectionManager();
             disconnect(selectionManager, SIGNAL(currentChanged(int,int)), this, SLOT(slotCurrentChanged(int,int)));
-            disconnect(selectionManager, SIGNAL(selectionChanged(QSet<int>,QSet<int>)), this, SLOT(slotSelectionChanged(QSet<int>,QSet<int>)));
+            disconnect(selectionManager, SIGNAL(selectionChanged(KItemSet,KItemSet)), this, SLOT(slotSelectionChanged(KItemSet,KItemSet)));
         }
 
         m_controller = controller;
@@ -1510,7 +1542,7 @@ void KItemListView::setController(KItemListController* controller)
         if (controller) {
             KItemListSelectionManager* selectionManager = controller->selectionManager();
             connect(selectionManager, SIGNAL(currentChanged(int,int)), this, SLOT(slotCurrentChanged(int,int)));
-            connect(selectionManager, SIGNAL(selectionChanged(QSet<int>,QSet<int>)), this, SLOT(slotSelectionChanged(QSet<int>,QSet<int>)));
+            connect(selectionManager, SIGNAL(selectionChanged(KItemSet,KItemSet)), this, SLOT(slotSelectionChanged(KItemSet,KItemSet)));
         }
 
         onControllerChanged(controller, previous);