]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #888: Do not highlight non selectable tree items in Object Browser
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 30 Oct 2015 12:32:14 +0000 (15:32 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 30 Oct 2015 12:32:27 +0000 (15:32 +0300)
src/XGUI/XGUI_DataModel.cpp
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_ObjectsBrowser.h

index bac4aedaedd8c59127e137e8549799a1ac0228fc..afb0aba04ebb6ce375f7c87fe9ceb85e4d8a4b61 100644 (file)
@@ -375,13 +375,13 @@ QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const
       case Qt::DecorationRole:
         return QIcon(myXMLReader.rootFolderIcon(theIndexRow).c_str());
       case Qt::ForegroundRole:
-        if ((flags(theIndex) & Qt::ItemIsEditable) == 0)
+        if ((theIndex.flags() & Qt::ItemIsEditable) == 0)
           return QBrush(Qt::lightGray);
         return ACTIVE_COLOR;
     }
   } else { // an object or sub-document
     if (theRole == Qt::ForegroundRole) {
-      if ((flags(theIndex) & Qt::ItemIsEditable) == 0)
+      if ((theIndex.flags() & Qt::ItemIsEditable) == 0)
         return QBrush(Qt::lightGray);
       return ACTIVE_COLOR;
     }
index 147d0c3beb9ccf86155b07d74647d85169a6e3d3..992ed73ac1ce044dfe52d37f5d5152b3493b7aa4 100644 (file)
@@ -61,6 +61,8 @@ private:
 XGUI_DataTree::XGUI_DataTree(QWidget* theParent)
     : QTreeView(theParent)
 {
+  myStyle = new XGUI_TreeViewStyle();
+  setStyle(myStyle);
   setHeaderHidden(true);
   setEditTriggers(QAbstractItemView::NoEditTriggers);
   setSelectionBehavior(QAbstractItemView::SelectRows);
@@ -169,6 +171,37 @@ void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex)
   }
 }
 
+void XGUI_DataTree::drawRow(QPainter* thePainter,
+                            const QStyleOptionViewItem& theOptions,
+                            const QModelIndex& theIndex) const
+{
+  QStyleOptionViewItemV4 aOptions = theOptions;
+  myStyle->setIndex(theIndex);
+  QTreeView::drawRow(thePainter, aOptions, theIndex);
+}
+
+//********************************************************************
+//********************************************************************
+//********************************************************************
+void XGUI_TreeViewStyle::drawPrimitive(PrimitiveElement theElement, 
+                                       const QStyleOption* theOption,
+                                       QPainter* thePainter, const QWidget* theWidget) const
+{
+  if ((theElement == QStyle::PE_PanelItemViewRow) || (theElement == QStyle::PE_PanelItemViewItem)) {
+    const QStyleOptionViewItemV4* aOptions = qstyleoption_cast<const QStyleOptionViewItemV4 *>(theOption);
+    if (myIndex.isValid() && ((myIndex.flags() & Qt::ItemIsSelectable) == 0)) {
+      QStyle::State aState = aOptions->state;
+      if ((aState & QStyle::State_MouseOver) != 0)
+        aState &= ~QStyle::State_MouseOver;
+      QStyleOptionViewItemV4* aOpt = (QStyleOptionViewItemV4*) aOptions;
+      aOpt->state = aState;
+      QWindowsVistaStyle::drawPrimitive(theElement, aOpt, thePainter, theWidget);
+    }
+  }
+  QWindowsVistaStyle::drawPrimitive(theElement, theOption, thePainter, theWidget);
+}
+
+
 //********************************************************************
 //********************************************************************
 //********************************************************************
index 8c33e24f9b8bc83f09ddcec3277a97f3ebc9294f..9816e1e2cfa6c5f4c89145accab3fb529b63a410 100644 (file)
@@ -12,6 +12,7 @@
 #include <QWidget>
 #include <QTreeView>
 #include <QLineEdit>
+#include <QWindowsVistaStyle>
 
 class ModuleBase_IDocumentDataModel;
 class XGUI_DataModel;
@@ -51,6 +52,27 @@ private:
   bool myIsSelected;
 };
 
+/**
+* \ingroup GUI
+* Implementation of XGUI_DataTree custom style
+*/
+class XGUI_TreeViewStyle : public QWindowsVistaStyle
+{
+  Q_OBJECT
+public:
+  XGUI_TreeViewStyle() : QWindowsVistaStyle() {}
+
+  void drawPrimitive(PrimitiveElement theElement, const QStyleOption* theOption,
+                     QPainter* thePainter, const QWidget* theWidget = 0) const;
+
+  void setIndex(const QModelIndex& theIndex) { myIndex = theIndex; }
+  QModelIndex index() const { return myIndex; }
+
+private:
+  QModelIndex myIndex;
+};
+
+
 /**
 * \ingroup GUI
 * Implementation of Data Tree object for Object Browser
@@ -90,6 +112,11 @@ public slots:
    /// Redefinition of virtual method
   virtual void resizeEvent(QResizeEvent* theEvent);
 
+  virtual void drawRow(QPainter* thePainter,
+                        const QStyleOptionViewItem& theOptions,
+                        const QModelIndex& theIndex) const;
+private:
+  XGUI_TreeViewStyle* myStyle;
 };
 
 /**\class XGUI_ObjectsBrowser