Salome HOME
#29481: Show parts in study tree (parts drag and drop)
[modules/shaper.git] / src / ModuleBase / ModuleBase_ListView.h
index 27c22622d3bd159efdbffcbc60f0cdd5669c1755..e534fbd98e575a7f3b4f88c48c845382406d380d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2022  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #ifndef ModuleBase_ListView_H_
@@ -25,6 +24,8 @@
 
 #include <QModelIndex>
 #include <QObject>
+#include <QListWidget>
+#include <QTimer>
 
 #include <set>
 
@@ -32,6 +33,59 @@ class QAction;
 class QListWidget;
 class QWidget;
 
+
+/**
+* Customization of a List Widget to make it to be placed on full width of container
+*/
+class CustomListWidget : public QListWidget
+{
+  Q_OBJECT
+public:
+  /// Constructor
+  /// \param theParent a parent widget
+  CustomListWidget(QWidget* theParent)
+    : QListWidget(theParent)
+  {
+  }
+
+  /// Redefinition of virtual method
+  virtual QSize        sizeHint() const
+  {
+    int aHeight = 2 * QFontMetrics(font()).height();
+    QSize aSize = QListWidget::sizeHint();
+    return QSize(aSize.width(), aHeight);
+  }
+
+  /// Redefinition of virtual method
+  virtual QSize        minimumSizeHint() const
+  {
+    int aHeight = 4/*2*/ * QFontMetrics(font()).height();
+    QSize aSize = QListWidget::minimumSizeHint();
+    return QSize(aSize.width(), aHeight);
+  }
+
+signals:
+  void activated();
+
+protected:
+  virtual void mouseReleaseEvent(QMouseEvent* e) {
+    QListWidget::mouseReleaseEvent(e);
+    emit activated();
+  }
+
+#ifndef WIN32
+  // The code is necessary only for Linux because
+  //it can not update viewport on widget resize
+protected:
+  void resizeEvent(QResizeEvent* theEvent)
+  {
+    QListWidget::resizeEvent(theEvent);
+    QTimer::singleShot(5, viewport(), SLOT(repaint()));
+  }
+#endif
+};
+
+
 /**
 * \ingroup GUI
 * An extension of QListWidget to provide Undo/Redo functionality
@@ -56,10 +110,18 @@ public:
   /// \param theIndex an item internal index
   void addItem(const QString& theTextValue, const int theIndex);
 
+  /// Returns True if the control already contains an item with the given text
+  /// \param theTextValue tex of item to find
+  bool hasItem(const QString& theTextValue) const;
+
   /// Returns list of internal list view item indices
   /// \param theIndices an output container for indices
   void getSelectedIndices(std::set<int>& theIndices);
 
+  /// Selects items with indices
+  /// \param theIndices indices
+  void selectIndices(const std::set<int>& theIndices);
+
   /// Removes selected items from the list widget
   void removeSelectedItems();
 
@@ -81,10 +143,13 @@ protected slots:
   /// Slot is called on selection of list of selected items
   void onListSelection();
 
+
 signals:
   /// Signal about delete action click
   void deleteActionClicked();
 
+  void listActivated();
+
 protected:
   QListWidget* myListControl; ///< List control