]> cloud.milkyroute.net Git - dolphin.git/commitdiff
KItemListWidget: Use initStyleOption
authorAnton Kreuzkamp <anton.kreuzkamp@kdab.com>
Mon, 3 Dec 2018 14:01:36 +0000 (15:01 +0100)
committerAnton Kreuzkamp <anton.kreuzkamp@kdab.com>
Mon, 3 Dec 2018 14:15:56 +0000 (15:15 +0100)
Instead of using QStyleOption::initFrom, let's use
QGraphicsWidget::initStyleOption, which is made for exactly the purpose
of KItemListWidget. This is especially important since, according to the
docs of QGraphicsItem::paint "The widget argument is optional. [...]
For cached painting, widget is always 0.". Even though currently no code
in dolphin does cached painting, for the sake of modularity one should
not rely on widget to be non-null. Using QStyleOption::initFrom does
assume that, though.

In fact, GammaRay asks the items to do cached painting when attaching it
to the application, causing it to crash.

src/kitemviews/kitemlistview.cpp
src/kitemviews/kitemlistwidget.cpp

index 316daa88d13a88d98a38bd57c91bda8251ddb3a1..9f1380c75c08e33c4ca9aba127b90164cacf8869 100644 (file)
@@ -670,7 +670,7 @@ void KItemListView::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt
         }
 
         QStyleOptionRubberBand opt;
-        opt.initFrom(widget);
+        initStyleOption(&opt);
         opt.shape = QRubberBand::Rectangle;
         opt.opaque = false;
         opt.rect = rubberBandRect.toRect();
index 28b374620c38ff7fe1122164f8011756a4489faa..e8482216d55937fd8981a0c8304891f86d0a6286 100644 (file)
@@ -127,7 +127,7 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
 
     if (m_current && m_editedRole.isEmpty()) {
         QStyleOptionFocusRect focusRectOption;
-        focusRectOption.initFrom(widget);
+        initStyleOption(&focusRectOption);
         focusRectOption.rect = textFocusRect().toRect();
         focusRectOption.state = QStyle::State_Enabled | QStyle::State_Item | QStyle::State_KeyboardFocusChange;
         if (m_selected) {
@@ -517,11 +517,11 @@ void KItemListWidget::clearHoverCache()
 void KItemListWidget::drawItemStyleOption(QPainter* painter, QWidget* widget, QStyle::State styleState)
 {
     QStyleOptionViewItem viewItemOption;
-    viewItemOption.initFrom(widget);
+    initStyleOption(&viewItemOption);
     viewItemOption.state = styleState;
     viewItemOption.viewItemPosition = QStyleOptionViewItem::OnlyOne;
     viewItemOption.showDecorationSelected = true;
     viewItemOption.rect = selectionRect().toRect();
-    widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget);
+    style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget);
 }