Ejemplo n.º 1
0
//---------------------------------------------------------
//   wheelEvent
//---------------------------------------------------------
void WaveView::wheelEvent(QWheelEvent* ev)
{
  int keyState = ev->modifiers();

  bool shift      = keyState & Qt::ShiftModifier;
  bool ctrl       = keyState & Qt::ControlModifier;

  if (shift) { // scroll vertically
      int delta       = -ev->delta() / WHEEL_DELTA;
      int xpixelscale = 5*MusECore::fast_log10(rmapxDev(1));


      if (xpixelscale <= 0)
            xpixelscale = 1;

      int scrollstep = WHEEL_STEPSIZE * (delta);
      ///if (ev->state() == Qt::ShiftModifier)
  //      if (((QInputEvent*)ev)->modifiers() == Qt::ShiftModifier)
      scrollstep = scrollstep / 10;

      int newXpos = xpos + xpixelscale * scrollstep;

      if (newXpos < 0)
            newXpos = 0;

      //setYPos(newYpos);
      emit horizontalScroll((unsigned)newXpos);


  } else if (ctrl) {  // zoom horizontally
    if (ev->delta()>0)
      emit horizontalZoomIn();
    else
      emit horizontalZoomOut();

  } else { // scroll horizontally
      emit mouseWheelMoved(ev->delta() / 10);
  }

}
Ejemplo n.º 2
0
void WaveView::setPos(int idx, unsigned val, bool adjustScrollbar)
      {
      val = MusEGlobal::tempomap.tick2frame(val);
      if (pos[idx] == val)
            return;
      int opos = mapx(pos[idx]);
      int npos = mapx(val);

      if (adjustScrollbar && idx == 0) {
            switch (MusEGlobal::song->follow()) {
                  case  MusECore::Song::NO:
                        break;
                  case MusECore::Song::JUMP:
                        if (npos >= width()) {
                              int ppos =  val - xorg - rmapxDev(width()/4);
                              if (ppos < 0)
                                    ppos = 0;
                              emit followEvent(ppos);
                              opos = mapx(pos[idx]);
                              npos = mapx(val);
                              }
                        else if (npos < 0) {
                              int ppos =  val - xorg - rmapxDev(width()*3/4);
                              if (ppos < 0)
                                    ppos = 0;
                              emit followEvent(ppos);
                              opos = mapx(pos[idx]);
                              npos = mapx(val);
                              }
                        break;
	    case MusECore::Song::CONTINUOUS:
                        if (npos > (width()*5)/8) {
                              int ppos =  pos[idx] - xorg - rmapxDev(width()*5/8);
                              if (ppos < 0)
                                    ppos = 0;
                              emit followEvent(ppos);
                              opos = mapx(pos[idx]);
                              npos = mapx(val);
                              }
                        else if (npos < (width()*3)/8) {
                              int ppos =  pos[idx] - xorg - rmapxDev(width()*3/8);
                              if (ppos < 0)
                                    ppos = 0;
                              emit followEvent(ppos);
                              opos = mapx(pos[idx]);
                              npos = mapx(val);
                              }
                        break;
                  }
            }

      int x;
      int w = 1;
      if (opos > npos) {
            w += opos - npos;
            x = npos;
            }
      else {
            w += npos - opos;
            x = opos;
            }
      pos[idx] = val;
      //redraw(QRect(x, 0, w, height()));
      redraw(QRect(x-1, 0, w+2, height()));    // p4.0.28 From Canvas::draw (is otherwise identical). Fix for corruption.
      }
Ejemplo n.º 3
0
QRect View::mapDev(const QRect& r) const
      {
      return QRect(mapxDev(r.x()), mapyDev(r.y()),
         rmapxDev(r.width()), rmapyDev(r.height()));
      }
Ejemplo n.º 4
0
void EventCanvas::viewMousePressEvent(QMouseEvent* event)/*{{{*/
{
    ///keyState = event->state();
    _keyState = ((QInputEvent*) event)->modifiers();
    _button = event->button();

    //printf("viewMousePressEvent buttons:%x mods:%x button:%x\n", (int)event->buttons(), (int)keyState, event->button());

    // special events if right button is clicked while operations
    // like moving or drawing lasso is performed.
    if (event->buttons() & Qt::RightButton & ~(event->button()))
    {
        //printf("viewMousePressEvent special buttons:%x mods:%x button:%x\n", (int)event->buttons(), (int)keyState, event->button());
        switch (_drag)
        {
        case DRAG_LASSO:
            _drag = DRAG_OFF;
            redraw();
            return;
        case DRAG_MOVE:
            _drag = DRAG_OFF;
            endMoveItems(_start, MOVE_MOVE, 0);
            return;
        default:
            break;
        }
    }

    // ignore event if (another) button is already active:
    if (event->buttons() & (Qt::LeftButton | Qt::RightButton | Qt::MidButton) & ~(event->button()))
    {
        //printf("viewMousePressEvent ignoring buttons:%x mods:%x button:%x\n", (int)event->buttons(), (int)keyState, event->button());
        return;
    }
    bool shift = _keyState & Qt::ShiftModifier;
    bool alt = _keyState & Qt::AltModifier;
    bool ctrl = _keyState & Qt::ControlModifier;
    _start = event->pos();

    //---------------------------------------------------
    //    set curItem to item mouse is pointing
    //    (if any)
    //---------------------------------------------------

    CItemList list = _items;
    if(multiPartSelectionAction && !multiPartSelectionAction->isChecked())
        list = getItemlistForCurrentPart();
    if (virt())
    {
        _curItem = list.find(_start);//_items.find(_start);
    }
    else
    {
        _curItem = 0; //selectAtTick(_start.x());
        iCItem ius;
        bool usfound = false;
        for (iCItem i = list.begin(); i != list.end(); ++i)
        {
            MidiTrack* mtrack = (MidiTrack*)i->second->part()->track();
            int sy = _start.y();
            int p = y2pitch(sy);
            if(editor->isGlobalEdit())
                p += mtrack->getTransposition();
            int p2 = pitch2y(p);
            QPoint lpos(_start.x(), p2);
            QRect box = i->second->bbox();
            int x = rmapxDev(box.x());
            int y = rmapyDev(box.y());
            int w = rmapxDev(box.width());
            int h = rmapyDev(box.height());
            QRect r(x, y, w, h);
            r.translate(i->second->pos().x(), i->second->pos().y());
            if(r.contains(lpos))
            {
                if (i->second->isSelected())
                {
                    _curItem = i->second;
                    break;
                }
                else if (!usfound)
                {
                    ius = i;
                    usfound = true;
                }
            }
        }
        if (!_curItem && usfound)
            _curItem = ius->second;

    }

    if(editor->isGlobalEdit() && _curItem)
    {
        populateMultiSelect(_curItem);
    }

    if (_curItem && (event->button() == Qt::MidButton))
    {
        if (!_curItem->isSelected())
        {
            selectItem(_curItem, true);
            updateSelection();
            redraw();
        }
        startDrag(_curItem, shift);
    }
    else if (event->button() == Qt::RightButton)
    {
        if (_curItem)
        {
            if (shift)
            {
                _drag = DRAG_RESIZE;
                setCursor();
                int dx = _start.x() - _curItem->x();
                _curItem->setWidth(dx);
                _start.setX(_curItem->x());
                deselectAll();
                selectItem(_curItem, true);
                updateSelection();
                redraw();
            }
            else
            {
                _itemPopupMenu = genItemPopup(_curItem);
                if (_itemPopupMenu)
                {
                    QAction *act = _itemPopupMenu->exec(QCursor::pos());
                    if (act)
                        itemPopup(_curItem, act->data().toInt(), _start);
                    delete _itemPopupMenu;
                }
            }
        }
        else
        {
            _canvasPopupMenu = genCanvasPopup(true);
            if (_canvasPopupMenu)
            {
                QAction *act = _canvasPopupMenu->exec(QCursor::pos(), 0);
                if (act)
                {
                    int actnum = act->data().toInt();
                    canvasPopup(actnum);
                    if(actnum >= 20) //Nome of the tools have a higher number than 9
                    {
                        editor->updateCanvas();
                        los->arranger->updateCanvas();
                    }
                }
                delete _canvasPopupMenu;
            }
        }
    }
    else if (event->button() == Qt::LeftButton)
    {
        switch (_tool)
        {
        case PointerTool:
            if (_curItem)
            {
                /*if (_curItem->part() != _curPart)
                {
                    _curPart = _curItem->part();
                    _curPartId = _curPart->sn();
                    curPartChanged();
                }*/
                itemPressed(_curItem);
                if (shift)
                    _drag = DRAG_COPY_START;
                else if (alt)
                {
                    _drag = DRAG_CLONE_START;
                }
                else if (ctrl)
                { //Select all on the same pitch (e.g. same y-value)
                    deselectAll();
                    //printf("Yes, ctrl and press\n");
                    for (iCItem i = _items.begin(); i != _items.end(); ++i)
                    {
                        if (i->second->y() == _curItem->y())
                            selectItem(i->second, true);
                    }
                    updateSelection();
                    redraw();
                }
                else
                    _drag = DRAG_MOVE_START;
            }
            else
                _drag = DRAG_LASSO_START;
            setCursor();
            break;

            case RubberTool:
            deleteItem(_start);
            _drag = DRAG_DELETE;
            setCursor();
            break;

            case PencilTool:
            if (_curItem)
            {
                _drag = DRAG_RESIZE;
                setCursor();
                int dx = _start.x() - _curItem->x();
                _curItem->setWidth(dx);
                _start.setX(_curItem->x());
            }
            else
            {
                _drag = DRAG_NEW;
                setCursor();
                _curItem = newItem(_start, event->modifiers());
                if (_curItem)
                    _items.add(_curItem);
                else
                {
                    _drag = DRAG_OFF;
                    setCursor();
                }
            }
            deselectAll();
            if (_curItem)
            {
                selectItem(_curItem, true);
                // Play the note
                itemPressed(_curItem);
            }
            updateSelection();
            redraw();
            break;

            default:
            break;
        }
    }
    mousePress(event);
}/*}}}*/
Ejemplo n.º 5
0
void Canvas::setPos(int idx, unsigned val, bool adjustScrollbar)
{
	//if (pos[idx] == val) // Seems to be some refresh problems here, pos[idx] might be val but the gui not updated.
	//    return;          // skipping this return forces update even if values match. Matching values only seem
	// to occur when initializing
	int opos = mapx(_pos[idx]);
	int npos = mapx(val);

	if (adjustScrollbar && idx == 0)
	{
		switch (song->follow())
		{
		case Song::NO:
			break;
		case Song::JUMP:
			if (npos >= width())
			{
				int ppos = val - xorg - rmapxDev(width() / 8);
				if (ppos < 0)
					ppos = 0;
				emit followEvent(ppos);
				opos = mapx(_pos[idx]);
				npos = mapx(val);
			}
			else if (npos < 0)
			{
				int ppos = val - xorg - rmapxDev(width()*3 / 4);
				if (ppos < 0)
					ppos = 0;
				emit followEvent(ppos);
				opos = mapx(_pos[idx]);
				npos = mapx(val);
			}
			break;
			case Song::CONTINUOUS:
			if (npos > (width() / 2))
			{
				int ppos = _pos[idx] - xorg - rmapxDev(width() / 2);
				if (ppos < 0)
					ppos = 0;
				emit followEvent(ppos);
				opos = mapx(_pos[idx]);
				npos = mapx(val);
			}
			else if (npos < (width() / 2))
			{
				int ppos = _pos[idx] - xorg - rmapxDev(width() / 2);
				if (ppos < 0)
					ppos = 0;
				emit followEvent(ppos);
				opos = mapx(_pos[idx]);
				npos = mapx(val);
			}
			break;
		}
	}

	int x;
	int w = 1;
	if (opos > npos)
	{
		w += opos - npos;
		x = npos;
	}
	else
	{
		w += npos - opos;
		x = opos;
	}
	_pos[idx] = val;
	//redraw(QRect(x - 1, 0, w + 2, height()));
	update();
}