Salome HOME
Merge branch 'Dev_0.7.1' of newgeom:newgeom into Dev_0.7.1
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetMultiSelector.cpp
index 2113803386cf3b49289e117e35dbf50946d2d1b5..5ee8ac64a38bd0bab91c132eb4b3a475fdebfac9 100644 (file)
@@ -25,6 +25,9 @@
 #include <QString>
 #include <QComboBox>
 #include <QEvent>
+#include <QAction>
+#include <QApplication>
+#include <QClipboard>
 
 #include <memory>
 #include <string>
@@ -34,7 +37,7 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
                                                                const Config_WidgetAPI* theData,
                                                                const std::string& theParentId)
     : ModuleBase_ModelWidget(theParent, theData, theParentId),
-      myWorkshop(theWorkshop), myIsActive(false), myUseSubShapes(false)
+      myWorkshop(theWorkshop), myIsActive(false)
 {
   myMainWidget = new QWidget(theParent);
   QGridLayout* aMainLay = new QGridLayout(myMainWidget);
@@ -59,11 +62,16 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
   aMainLay->addWidget(new QLabel(myMainWidget));
   aMainLay->setRowMinimumHeight(3, 20);
   myMainWidget->setLayout(aMainLay);
-  //TODO: Move into the base class
-  myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false);
-  //TODO_END
   connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onSelectionTypeChanged()));
 
+  myCopyAction = new QAction(QIcon(":pictures/copy.png"), tr("Copy"), this);
+  myCopyAction->setShortcut(QKeySequence::Copy);
+  myCopyAction->setEnabled(false);
+  connect(myCopyAction, SIGNAL(triggered(bool)), SLOT(onCopyItem()));
+  myListControl->addAction(myCopyAction);
+  myListControl->setContextMenuPolicy(Qt::ActionsContextMenu);
+  connect(myListControl, SIGNAL(itemSelectionChanged()), SLOT(onListSelection()));
+
   activateSelection(true);
 }
 
@@ -260,23 +268,28 @@ void ModuleBase_WidgetMultiSelector::updateSelectionList(AttributeSelectionListP
     AttributeSelectionPtr aAttr = theList->value(i);
     myListControl->addItem(aAttr->namingName().c_str());
   }
-  //QString aType;
-  //if (myTypeCombo->currentText().toLower() == "vertices")
-  //  aType = "vertex";
-  //else if (myTypeCombo->currentText().toLower() == "edges")
-  //  aType = "edge";
-  //else if (myTypeCombo->currentText().toLower() == "faces")
-  //  aType = "face";
-  //else if (myTypeCombo->currentText().toLower() == "solids")
-  //  aType = "solid";
-  //myListControl->clear();
-  //int i = 1;
-  //foreach (GeomSelection aSel, mySelection) {
-  //  QString aName(aSel.first->data()->name().c_str());
-  //  aName += ":" + aType + QString("_%1").arg(i);
-  //  myListControl->addItem(aName);
-  //  i++;
-  //}
-  //myListControl->repaint();
 }
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::onCopyItem()
+{
+  QList<QListWidgetItem*> aItems = myListControl->selectedItems();
+  QString aRes;
+  foreach(QListWidgetItem* aItem, aItems) {
+    if (!aRes.isEmpty())
+      aRes += "\n";
+    aRes += aItem->text();
+  }
+  if (!aRes.isEmpty()) {
+    QClipboard *clipboard = QApplication::clipboard();
+    clipboard->setText(aRes);
+  }
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::onListSelection()
+{
+  QList<QListWidgetItem*> aItems = myListControl->selectedItems();
+  myCopyAction->setEnabled(!aItems.isEmpty());
+}
+