void ContentWindowGraphicsItem::wheelEvent(QGraphicsSceneWheelEvent * event)
{
    // on Mac we've seen that mouse events can go to the wrong graphics item
    // this is due to the bug: https://bugreports.qt.nokia.com/browse/QTBUG-20493
    // here we ignore the event if it shouldn't have been sent to us, which ensures
    // it will go to the correct item...
    if(boundingRect().contains(event->pos()) == false)
    {
        event->ignore();
        return;
    }

    ContentWindowManagerPtr contentWindow = getContentWindowManager();

    if( contentWindow )
    {
        // handle wheel movements differently depending on state of item window
        if (selected())
        {
            contentWindow->getInteractionDelegate().wheelEvent(event);
        }
        else
        {
            // scale size based on wheel delta
            // typical delta value is 120, so scale based on that
            double factor = 1. + (double)event->delta() / (10. * 120.);

            scaleSize(factor);
        }
    }
}
void ContentWindowGraphicsItem::keyReleaseEvent(QKeyEvent *event)
{
    if (selected())
    {
        ContentWindowManagerPtr contentWindow = getContentWindowManager();

        if( contentWindow )
        {
            contentWindow->getInteractionDelegate().keyReleaseEvent(event);
        }
    }
}
void ContentWindowGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
{
    // handle mouse movements differently depending on selected mode of item
    if(!selected())
    {
        if(event->buttons().testFlag(Qt::LeftButton))
        {
            if(resizing_)
            {
                QRectF r = boundingRect();
                QPointF eventPos = event->pos();

                r.setBottomRight(eventPos);

                QRectF sceneRect = mapRectToScene(r);

                double w = sceneRect.width();
                double h = sceneRect.height();

                setSize(w, h);
            }
            else
            {
                QPointF delta = event->pos() - event->lastPos();

                double new_x = coordinates_.x() + delta.x();
                double new_y = coordinates_.y() + delta.y();

                setPosition(new_x, new_y);
            }
        }
    }
    else
    {
        ContentWindowManagerPtr contentWindow = getContentWindowManager();
        if(contentWindow)
        {
            // Zoom or forward event depending on type
            contentWindow->getInteractionDelegate().mouseMoveEvent(event);

            // force a redraw to update window info label
            update();
        }
    }
}
void ContentWindowGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
{
    resizing_ = false;
    moving_ = false;

    ContentWindowManagerPtr contentWindow = getContentWindowManager();

    if( contentWindow )
    {
        contentWindow->getContent()->blockAdvance( false );

        if (selected())
        {
            contentWindow->getInteractionDelegate().mouseReleaseEvent(event);
        }
    }

    QGraphicsItem::mouseReleaseEvent(event);
}
void ContentWindowGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent * event)
{
    // on Mac we've seen that mouse events can go to the wrong graphics item
    // this is due to the bug: https://bugreports.qt.nokia.com/browse/QTBUG-20493
    // here we ignore the event if it shouldn't have been sent to us, which ensures
    // it will go to the correct item...
    if(boundingRect().contains(event->pos()) == false)
    {
        event->ignore();
        return;
    }

    // button dimensions
    float buttonWidth, buttonHeight;
    getButtonDimensions(buttonWidth, buttonHeight);

    // item rectangle and event position
    QRectF r = boundingRect();
    QPointF eventPos = event->pos();

    // check to see if user clicked on the close button
    if(fabs((r.x()+r.width()) - eventPos.x()) <= buttonWidth &&
       fabs(r.y() - eventPos.y()) <= buttonHeight)
    {
        close();

        return;
    }

    // move to the front of the GUI display
    moveToFront();

    ContentWindowManagerPtr contentWindow = getContentWindowManager();
    if (!contentWindow)
        return;

    if (selected())
    {
        contentWindow->getInteractionDelegate().mousePressEvent(event);
        return;
    }

    contentWindow->getContent()->blockAdvance( true );

    // check to see if user clicked on the resize button
    if(fabs((r.x()+r.width()) - eventPos.x()) <= buttonWidth &&
       fabs((r.y()+r.height()) - eventPos.y()) <= buttonHeight)
    {
        resizing_ = true;
    }
    // check to see if user clicked on the fullscreen button
    else if(fabs(r.x() - eventPos.x()) <= buttonWidth &&
            fabs((r.y()+r.height()) - eventPos.y()) <= buttonHeight)
    {
        toggleFullscreen();
    }
    else if(fabs(((r.x()+r.width())/2) - eventPos.x() - buttonWidth) <= buttonWidth &&
            fabs((r.y()+r.height()) - eventPos.y()) <= buttonHeight &&
            g_configuration->getOptions()->getShowMovieControls( ))
    {
        contentWindow->setControlState( ControlState(contentWindow->getControlState() ^ STATE_PAUSED) );
    }
    else if(fabs(((r.x()+r.width())/2) - eventPos.x()) <= buttonWidth &&
            fabs((r.y()+r.height()) - eventPos.y()) <= buttonHeight &&
            g_configuration->getOptions()->getShowMovieControls( ))
    {
        contentWindow->setControlState( ControlState(contentWindow->getControlState() ^ STATE_LOOP) );
    }
    else
        moving_ = true;

    QGraphicsItem::mousePressEvent(event);
}