Example #1
0
/**
*  Note caller must create _iconPanel before calling
*/
/*protected*/ void IconItemPanel::addIconsToPanel(QMap<QString, NamedIcon*>* iconMap)
{
 _iconPanel = new ImagePanel();
 _iconPanel->setLayout(new QHBoxLayout());
 //Iterator<Entry<QString, NamedIcon*>*> it = iconMap.entrySet().iterator();
 QMapIterator<QString, NamedIcon*> it(*iconMap);
 while (it.hasNext())
 {
  //Entry<String, NamedIcon> entry = it.next();
  it.next();
  NamedIcon* icon = new NamedIcon(it.value());    // make copy for possible reduction
  QGroupBox* panel = new QGroupBox();
  panel->setLayout(new QVBoxLayout());
  QString borderName = ItemPalette::convertText(it.key());
  //panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black),
  //                                                 borderName));
  QString     gbStyleSheet = "QGroupBox { border: 2px solid gray; border-radius: 3px;} QGroupBox::title { /*background-color: transparent;*/  subcontrol-position: top left; /* position at the top left*/  padding:0 0px;} ";

  panel->setTitle(borderName);
  panel->setStyleSheet(gbStyleSheet);
  try
  {
   IconDragJLabel* label = new IconDragJLabel(new DataFlavor(Editor::POSITIONABLE_FLAVOR), _level, this);
   label->setName(borderName);
   //panel->layout()->addWidget(label);
   if (icon->getIconWidth()<1 || icon->getIconHeight()<1)
   {
    label->setText(tr("invisibleIcon"));
//               label->setForeground(QColor(Qt::lightGray);
   }
   else
   {
    icon->reduceTo(50, 80, 0.2);
   }
   label->setIcon(icon);
   label->setAlignment(Qt::AlignCenter);
   label->setMargin(6);

   int width = qMax(100, panel->minimumSize().width());
   panel->setMinimumSize(QSize(width, panel->minimumSize().height()));
   ((QBoxLayout*)panel->layout())->addWidget(label,0, Qt::AlignCenter);

  } catch (ClassNotFoundException cnfe) {
           //cnfe.printStackTrace();
  }
  _iconPanel->layout()->addWidget(panel);
 }
 thisLayout->addWidget(_iconPanel/*, 1*/);
 //_iconPanel->addMouseListener(this);
}
/*protected*/ void ReporterItemPanel::makeDndIconPanel(QHash<QString, NamedIcon*>* /*iconMap*/, QString /*displayKey*/)
{
 if (_update)
 {
  return;
 }
 _reporter = new ReporterIcon(_editor);
 QGroupBox*  panel = new QGroupBox();
 QString borderName = tr("Drag to Panel");
 QString     gbStyleSheet = "QGroupBox { border: 2px solid gray; border-radius: 3px;} QGroupBox::title { /*background-color: transparent;*/  subcontrol-position: top left; /* position at the top left*/  padding:0 0px;} ";
 panel->setLayout(new QHBoxLayout);
 panel->setTitle(borderName);
 panel->setStyleSheet(gbStyleSheet);
 QWidget*  comp;
 DataFlavor* flavor;
 try {
     //comp = getDragger(flavor = new DataFlavor(Editor::POSITIONABLE_FLAVOR));
     comp = getDragger(flavor = new DataFlavor(_reporter,"ReporterIcon"));
     flavor->setMimeTypeParameter("reporter", _reporter->getName());
     comp->setToolTip(tr("Drag an icon from this panel to add it to the control panel"));
 } catch (ClassNotFoundException cnfe) {
     //cnfe.printStackTrace();
     comp = new QWidget();
 }
 comp->setLayout(new FlowLayout);
 comp->layout()->addWidget(_reporter);
 panel->layout()->addWidget(comp);
 //panel.validate();
 int width = qMax(100, panel->sizeHint().width());
 panel->setMinimumSize( QSize(width, panel->minimumSize().height()));
 panel->setToolTip(tr("Drag an icon from this panel to add it to the control panel"));
 _dragIconPanel->layout()->addWidget( panel);
 _dragIconPanel->setToolTip(tr("Drag an icon from this panel to add it to the control panel"));
}