bool KSimBaseIntSpinBox::eventFilter(QObject * obj, QEvent * ev)
{
	switch(ev->type())
	{
		case QEvent::MouseButtonPress:
		{
			if (((QMouseEvent*)ev)->button() == QMouseEvent::RightButton)
			{
				QPopupMenu * popup = new QPopupMenu(0,"KSimBaseIntSpinBox RMB Popup");
				Q_CHECK_PTR(popup);
		
				initRmbMenu(popup);
				if (popup->count() != 0)
				{
					int id = popup->exec(QCursor::pos());
					if (id != -1)
					{
						execRmbMenu(id);
					}
				}
				delete popup;
				return true;
			}
			break;
		}
		
		case QEvent::FocusOut:
		{
			emit undoRequest();
			break;
		}
		
		default:
			break;
	}
	return KSimSpinBox::eventFilter(obj,ev);
}
示例#2
0
void CostTypeView::context(QListViewItem* i, const QPoint & p, int)
{
  QPopupMenu popup;

  TraceCostType* ct = i ? ((CostTypeItem*) i)->costType() : 0;

  if (ct)
    popup.insertItem(i18n("Set Secondary Event Type"), 99);
  if (_costType2)
    popup.insertItem(i18n("Remove Secondary Event Type"), 98);
  if (popup.count()>0)
    popup.insertSeparator();

  if (ct && !ct->isReal()) {
      popup.insertItem(i18n("Edit Long Name"), 93);
      popup.insertItem(i18n("Edit Short Name"), 94);
      popup.insertItem(i18n("Edit Formula"), 95);
      popup.insertItem(i18n("Remove"), 96);
      popup.insertSeparator();
  }

  addGoMenu(&popup);

  popup.insertSeparator();
  popup.insertItem(i18n("New Cost Type ..."), 97);

  int r = popup.exec(p);
  if (r == 98) selectedCostType2(0);
  else if (r == 99) selectedCostType2(ct);
  else if (r == 93) i->startRename(0);
  else if (r == 94) i->startRename(3);
  else if (r == 95) i->startRename(5);
  else if (r == 96) {

    // search for a previous type 
    TraceCostType* prev = 0, *ct = 0;
    TraceCostMapping* m = _data->mapping();
    for (int i=0;i<m->realCount();i++) {
	ct = m->realType(i);
	if (ct) prev = ct;
    }
    for (int i=0;i<m->virtualCount();i++) {
	ct = m->virtualType(i);
	if (ct == _costType) break;
	if (ct) prev = ct;
    }

    if (_data->mapping()->remove(ct)) {
      // select previous cost type
      selectedCostType(prev);
      if (_costType2 == ct)
	selectedCostType2(prev);
      refresh();
    }
  }
  else if (r == 97) {
    int i = 1;
    while(1) {
      if (!TraceCostType::knownVirtualType(i18n("New%1").arg(i)))
	break;
      i++;
    }
    // add same new cost type to this mapping and to known types
    QString shortName = i18n("New%1").arg(i);
    QString longName  = i18n("New Cost Type %1").arg(i);
    TraceCostType::add(new TraceCostType(shortName, longName, "0"));
    _data->mapping()->add(new TraceCostType(shortName, longName, "0"));
    refresh();
  }
}