Esempio n. 1
0
void WidgetSelection::updateActive()
{
    const WidgetState ws = widgetState(m_formWindow->core(), m_widget);
    bool active[WidgetHandle::TypeCount];
    qFill(active, active + WidgetHandle::TypeCount, false);
    // Determine active handles
    switch (ws) {
    case UnlaidOut:
        qFill(active, active + WidgetHandle::TypeCount, true);
        break;
    case ManagedGridLayout: // Grid: Allow changing span
        active[WidgetHandle::Left] = active[WidgetHandle::Top] = active[WidgetHandle::Right] = active[WidgetHandle::Bottom] = true;
        break;
    case ManagedFormLayout:  // Form: Allow changing column span
        if (const unsigned operation = ChangeFormLayoutItemRoleCommand::possibleOperations(m_formWindow->core(), m_widget)) {
            active[WidgetHandle::Left]  = operation & (ChangeFormLayoutItemRoleCommand::SpanningToField|ChangeFormLayoutItemRoleCommand::FieldToSpanning);
            active[WidgetHandle::Right] = operation & (ChangeFormLayoutItemRoleCommand::SpanningToLabel|ChangeFormLayoutItemRoleCommand::LabelToSpanning);
        }
        break;
    default:
        break;
    }

    for (int i = WidgetHandle::LeftTop; i < WidgetHandle::TypeCount; ++i)
        if (WidgetHandle *h = m_handles[i]) {
            h->setWidget(m_widget);
            h->setActive(active[i]);
        }
}
Esempio n. 2
0
bool EventWidget::eventFilter( QObject *ob, QEvent *ev )
{
  QPoint mousePos, pmousePos;
  QWidget *wob = (QWidget *) ob;
  int xPos, yPos, buttonState;
  unsigned int kCode;
  VCalDrag *vcd;

  switch(ev->type()) {
  case Event_MouseButtonPress:
    mousePos = ((QMouseEvent *) ev)->pos();
    if (ob != this)
      mousePos = wob->mapToParent(mousePos);

    xPos = DragCenterX = mousePos.x();
    yPos = DragCenterY = mousePos.y();
    buttonState = ((QMouseEvent *) ev)->button();

    if ((State == Edit) && 
	(buttonState != RightButton) &&
	(wob == textBox)) {
      // clicked inside the text box, and we are in edit mode.
      // let it through.
      return FALSE;
    }

    if (!widgetSelected)
      emit selected(this);
    setState(NoState);
    // if it was the left or middle button, we are possibly in resize mode.
    // otherwise, we are not; we are in 'right mouse button menu mode.'
    // or regular select mode
    if ((buttonState == LeftButton) || (buttonState == MidButton)) {
      if( xPos < DRAGBORDER )
	ResizeStatus = RESIZELEFT;
      else if( xPos > width()- DRAGBORDER )
	ResizeStatus = RESIZERIGHT;
      else if( yPos < DRAGBORDER )
	ResizeStatus = RESIZETOP;
      else if( yPos > (height() - DRAGBORDER) )
	ResizeStatus = RESIZEBOTTOM;
      else
	// mouse inside valid boundaries, don't resize
	ResizeStatus = 0;
      
      if (ResizeStatus)
	setState(Resize);
      else if (wob == textBox) {
	// click was inside the text editor.  Switch to edit mode
	// and let event through
	setState(Edit);
	return FALSE;
      }
      return TRUE;
    } else { // it was a right mouse button click
      // right mouse button has no associated state
      rmbPopup->popup(QCursor::pos());
      return TRUE;
    }
    debug("error! should never reach here in EventWidget::eventFilter()\n");
    return FALSE; // should never get here, but...
    break;

  case Event_MouseButtonDblClick:
    setState(NoState);
    if (!widgetSelected)
      emit selected(this);
    emit editEventSignal( widgetEvent );
    return TRUE;
    break;

  case Event_MouseButtonRelease:
    if ((State == Drag) || (State == Resize)) {
      setState(NoState);
      setCursor(ArrowCursor);
    }
    return FALSE;
    break;
      
  case Event_MouseMove: 
    mousePos = ((QMouseEvent *) ev)->pos();
    if (ob != this) 
      mousePos = wob->mapToParent(mousePos);
    pmousePos = mapToParent(mousePos);
    xPos =  mousePos.x();
    yPos =  mousePos.y();
    DragX = pmousePos.x();
    DragY = pmousePos.y() - DragCenterY;
    ResizeY = pmousePos.y();

    buttonState = ((QMouseEvent *) ev)->state();

    // test if we want to do DND, not regular dragging
    if (State == Drag && ob == handleFrame) {
      vcd = calendar->createDrag(widgetEvent, handleFrame);
      // we really should be doing event deletion here if the move
      // is successful, but dragMove() always appears to be returning
      // false at the moment.  So it is up to the dropEvent handlers.  BAD.
      setState(NoState);
      vcd->dragMove();
      emit eventChanged(widgetEvent, EVENTDELETED);
      return TRUE;
    }

    // make sure cursor is the proper one.
    // ONLY need to set the cursor if we aren't already in resize mode.
    if (State != Resize && State != Drag && !buttonState) {
      if (xPos < DRAGBORDER)
	setCursor(SizeHorCursor);
      else if (xPos > width()- DRAGBORDER)
	setCursor(SizeHorCursor);
      else if (yPos < DRAGBORDER)
	setCursor(SizeVerCursor);
      else if (yPos > height() - DRAGBORDER)
	setCursor(SizeVerCursor);
      else
	setCursor(ArrowCursor);
    }

    switch (State) {
      //    case Edit:
      //      return FALSE;
      //      break;
    case Resize:
      // if we need to tell that we are resizing, send signal. 
      if (ResizeStatus != 0) 
	/*	if (wob != this)
	  emit widgetState((EventWidget *) wob->parentWidget(), ResizeStatus);
	  else*/
	  emit widgetState(this, ResizeStatus);
      return TRUE;
      break;
    case Drag:
      // we may only want to do this if we have moved past a certain
      // threshold, or maybe only on mouse button release.  Think about it.
      /*      if (wob != this)
	emit widgetState((EventWidget *) wob->parentWidget(), MOVE);
	else*/
	emit widgetState(this, MOVE);
      return TRUE;
      break;
    default:
      // see if we need to turn on dragging mode.
      if (((buttonState & LeftButton) || (buttonState & MidButton)) &&
	  ((abs(xPos - DragCenterX) > DRAGTHRESHOLD) ||
	  (abs(yPos - DragCenterY) > DRAGTHRESHOLD)) &&
	  (widgetEvent->doesRecur() == FALSE) &&
	  (widgetEvent->isMultiDay() == FALSE)) {
	setState(Drag);
	if (wob == handleFrame) // get outta here now if we are setting up DND
	  return TRUE;
	setCursor(SizeAllCursor);
	textBox->setCursor(SizeAllCursor);
	/*	if (wob != this)
	  emit widgetState((EventWidget *) wob->parentWidget(), MOVE);
	  else*/
	  emit widgetState(this, MOVE);
	return TRUE;
      }
    }
    return FALSE;
    break;
    
  case Event_FocusIn:
    if (!widgetSelected) {
      emit selected(this);
    }
    return FALSE;
    break;

  case Event_FocusOut:
    if (State == Edit)
      endEdit();
    return FALSE;
    break;

  case Event_KeyPress:
    kCode = ((QKeyEvent*)ev)->key();
    switch(kCode) {
    case Key_Return:
    case Key_Enter:
      if (State == Edit)
		endEdit();
      else 
		startEdit();
      return TRUE;
      break;
    case Key_Delete:
      emit deleteEventSignal( widgetEvent );
      return TRUE;
      break;
    case Key_Plus:
      widgetEvent->setDtEnd( widgetEvent->getDtEnd().addSecs( 5*60 ) );
      emit widgetState( this, DTCHANGE );
      return TRUE;
      break;
    case Key_Minus:
      widgetEvent->setDtEnd( widgetEvent->getDtEnd().addSecs( -5*60 ) );
      emit widgetState( this, DTCHANGE );
      return TRUE;
      break;

	case Key_Up:
	case Key_Down:
	case Key_PageUp:
	case Key_PageDown:
		;
    }

    ((QKeyEvent *) ev)->ignore();
    return FALSE;
    break;
    
  default:
    return FALSE;
  }
}