Esempio n. 1
0
void PanelAppletOverlay::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event)

    QStyleOption op;
    op.initFrom(this);

    bool hovered = op.state & QStyle::State_MouseOver;
    bool mover = mouseGrabber() == this;
    if (!hovered || mover) {
        return;
    }

    QPainter p(this);
    KIcon icon("transform-move");
    int iconSize;
    QRect iconRect;


    if (!m_applet) {
        return;
    }

    if (m_orientation == Qt::Horizontal) {
        iconSize = qMin(qMin(height(), int(m_applet->size().width())), 64);
        iconRect = QRect(rect().center() - QPoint(iconSize / 2, iconSize / 2), QSize(iconSize, iconSize));
    } else {
        iconSize = qMin(qMin(width(), int(m_applet->size().height())), 64);
        iconRect = QRect(rect().center() - QPoint(iconSize / 2, iconSize / 2), QSize(iconSize, iconSize));
    }

    p.drawPixmap(iconRect, icon.pixmap(iconSize, iconSize));
}
void 
Context::AppletItemOverlay::paintEvent( QPaintEvent *event )
{
    Q_UNUSED( event )
    QStyleOption op;
    op.initFrom( this );

    bool hovered = op.state & QStyle::State_MouseOver;
    bool mover = mouseGrabber() == this;
    if( !hovered || mover ) 
    {
        return;
    }

    QPainter p( this );
    p.save();
    KIcon icon( "transform-move" );
    int iconSize;
    QRect iconRect;

    if( m_applet )
    {   // it's possible m_applet is null if we just opened amarok and it failed to load the applet plugin
        // so the user is seeing a big red X and trying to get rid of item
        iconSize = qMin( qMin( height(), int( m_applet->size().width() ) ), 64 );
        iconRect = QRect( rect().center() - QPoint( iconSize / 2, iconSize / 2 ), QSize( iconSize, iconSize ) );
        p.drawPixmap( iconRect, icon.pixmap( iconSize, iconSize ) );        
    }

    p.restore();
}
Esempio n. 3
0
    //____________________________________________________________________
    void SplitterProxy::clearSplitter( void )
    {

        // check if changed
        if( !_splitter ) return;

        // release mouse
        if( mouseGrabber() == this ) releaseMouse();

        // hide
        parentWidget()->setUpdatesEnabled(false);
        hide();
        parentWidget()->setUpdatesEnabled(true);

        // set hover event
        if( _splitter )
        {
            QHoverEvent hoverEvent(
                qobject_cast<QSplitterHandle*>(_splitter.data()) ? QEvent::HoverLeave : QEvent::HoverMove,
                _splitter.data()->mapFromGlobal(QCursor::pos()), _hook);
            QCoreApplication::sendEvent( _splitter.data(), &hoverEvent );
            _splitter.clear();

        }

        // kill timer if any
        if( _timerId )
        {
            killTimer( _timerId );
            _timerId = 0;
        }

    }
Esempio n. 4
0
PanelAppletOverlay::~PanelAppletOverlay()
{
    bool mover = mouseGrabber() == this;
    if (mover) {
        kDebug() << "MOVER!" << m_layout << m_index;
        releaseMouse();
        if (m_layout && m_applet) {
            m_layout->insertItem(m_index, m_applet);
        }
    }

    if (m_spacer) {
        if (m_layout) {
            m_layout->removeItem(m_spacer);
        }

        m_spacer->deleteLater();
        m_spacer = 0;
    }

    --s_appletHandleCount;
    if (s_appletHandleCount < 1) {
        delete s_appletHandle;
        s_appletHandle = 0;
        s_appletHandleCount = 0;
    }
}
Esempio n. 5
0
void LapsusOSD::mouseMoveEvent( QMouseEvent* e )
{
	if( _dragging && this == mouseGrabber() )
	{
		// check if the OSD has been dragged out of the current screen
		int currentScreen = QApplication::desktop()->screenNumber( e->globalPos() );

		if( currentScreen != -1 ) _screen = currentScreen;

		const QRect& screen = QApplication::desktop()->screenGeometry( _screen );

		// make sure the position is valid
		_position = fixupPosition( e->globalPos() - _dragOffset - screen.topLeft() );

		// move us to the new position
		move( _position );

		// fix the position
		int midH = screen.width()/2;
		int midV = screen.height()/2;

		if( _position.x() + width() > midH ) _position.rx() += width();
		if( _position.y() + height() > midV ) _position.ry() += height();
	}
}
Esempio n. 6
0
void MouseButton::mousePressEvent(QMouseEvent *event)
{

    if (!mouseGrabber()) {
        setText(i18n("Press a mouse button..."));
        KPushButton::mousePressEvent(event);
    }

}
//____________________________________________________________________
bool SplitterProxy::eventFilter( QObject* object, QEvent* event )
{

    // do nothing if disabled
    if( !_enabled ) return false;

    // do nothing in case of mouse grab
    if( mouseGrabber() ) return false;

    switch( event->type() )
    {

    case QEvent::HoverEnter:
        if( !isVisible() )
        {

            // cast to splitter handle
            if( QSplitterHandle* handle = qobject_cast<QSplitterHandle*>( object ) )
            {
                setSplitter( handle );
            }

        }

        return false;

    case QEvent::HoverMove:
    case QEvent::HoverLeave:
        return isVisible() && object == _splitter.data();

    case QEvent::MouseMove:
    case QEvent::Timer:
    case QEvent::Move:
        return false;

    case QEvent::CursorChange:
        if( QWidget *window = qobject_cast<QMainWindow*>( object ) )
        {
            if( window->cursor().shape() == Qt::SplitHCursor || window->cursor().shape() == Qt::SplitVCursor )
            {
                setSplitter( window );
            }
        }
        return false;

    case QEvent::WindowDeactivate:
    case QEvent::MouseButtonRelease:
        clearSplitter();
        return false;

    default:
        return false;

    }

}
Esempio n. 8
0
void
OSDPreviewWidget::mouseMoveEvent( QMouseEvent *e )
{
    if( m_dragging && this == mouseGrabber() )
    {
        // Here we implement a "snap-to-grid" like positioning system for the preview widget

        const QRect screenRect  = QApplication::desktop()->screenGeometry( screen() );
        const uint  hcenter     = screenRect.width() / 2;
        const uint  eGlobalPosX = e->globalPos().x() - screenRect.left();
        const uint  snapZone    = screenRect.width() / 24;

        QPoint destination = e->globalPos() - m_dragOffset - screenRect.topLeft();
        int maxY = screenRect.height() - height() - MARGIN;
        if( destination.y() < MARGIN )
            destination.ry() = MARGIN;
        if( destination.y() > maxY )
            destination.ry() = maxY;

        if( eGlobalPosX < ( hcenter - snapZone ) )
        {
            setAlignment(Left);
            destination.rx() = MARGIN;
        }
        else if( eGlobalPosX > ( hcenter + snapZone ) )
        {
            setAlignment(Right);
            destination.rx() = screenRect.width() - MARGIN - width();
        }
        else {
            const uint eGlobalPosY = e->globalPos().y() - screenRect.top();
            const uint vcenter     = screenRect.height() / 2;

            destination.rx() = hcenter - width() / 2;

            if( eGlobalPosY >= ( vcenter - snapZone ) && eGlobalPosY <= ( vcenter + snapZone ) )
            {
                setAlignment(Center);
                destination.ry() = vcenter - height() / 2;
            }
            else
                setAlignment(Middle);
        }

        destination += screenRect.topLeft();

        move( destination );
    }
}
void RecGestureWidget::mouseReleaseEvent(QMouseEvent *event)
{
        mainStaLayout->setStackingMode(QStackedLayout::StackOne);
        mainStaLayout->setCurrentIndex(0);
        mouseGrabber()->releaseMouse();
        recordGesBegin = false;
        if (m_path.size() >= 100)
        {
            //m_recResult = m_rec->recognize(m_path);
            DealWithGesture();
        }
        m_path.clear();
        update();
        //cout<<"RecGestureWidget mouse release"<<endl;
}
Esempio n. 10
0
void OSDWidget::mouseMoveEvent( QMouseEvent *e ) {
	//Doesn't work, I mean it's ugly (blinking)
	/*if(!m_linking&&!this->m_srt->anchorAt(e->pos()).isEmpty()){
		this->grabMouse(KCursor::handCursor());
		m_linking=true;
		return;
	}
	else if(m_linking&&this==mouseGrabber()){
		releaseMouse();
		this->m_linking=false;
		return;
	}*/
	if ( m_dragging && this == mouseGrabber() ) {
		const QRect screen      = QApplication::desktop()->screenGeometry( m_screen );
		const uint  hcenter     = screen.width() / 2;
		const uint  eGlobalPosX = e->globalPos().x() - screen.left();
		const uint  snapZone    = screen.width() / 8;

		QPoint destination = e->globalPos() - m_dragOffset - screen.topLeft();
		int maxY = screen.height() - height() - MARGIN;
		if( destination.y() < MARGIN ) destination.ry() = MARGIN;
		if( destination.y() > maxY ) destination.ry() = maxY;

		if( eGlobalPosX < (hcenter-snapZone) ) {
			m_alignment = Left;
			destination.rx() = MARGIN;
		} else if( eGlobalPosX > (hcenter+snapZone) ) {
			m_alignment = Right;
			destination.rx() = screen.width() - MARGIN - width();
		} else {
			const uint eGlobalPosY = e->globalPos().y() - screen.top();
			const uint vcenter     = screen.height()/2;

			destination.rx() = hcenter - width()/2;

			if( eGlobalPosY >= (vcenter-snapZone) && eGlobalPosY <= (vcenter+snapZone) ) {
				m_alignment = Center;
				destination.ry() = vcenter - height()/2;
			} else m_alignment = Middle;
		}

		destination += screen.topLeft();

		move( destination );
	}
}
Esempio n. 11
0
void MouseButton::wheelEvent(QWheelEvent *event)
{

    if (!mouseGrabber()) {
        KPushButton::wheelEvent(event);
    }   else {
        const Button oldButton = m_button;
        releaseMouse();
        if (event->delta() > 0) {
            setButton(WheelUp);
        } else {
            setButton(WheelDown);
        }
        setChecked(false);
        emit buttonChanged(oldButton, m_button);
    }

}
Esempio n. 12
0
void OSDPreviewWidget::mouseMoveEvent( QMouseEvent *e )
{
    if ( m_dragging && this == mouseGrabber() )
    {
        const QRect screen      = QApplication::desktop()->screenGeometry( m_screen );
        const uint  hcenter     = screen.width() / 2;
        const uint  eGlobalPosX = e->globalPos().x() - screen.left();
        const uint  snapZone    = screen.width() / 8;

        QPoint destination = e->globalPos() - m_dragOffset - screen.topLeft();
        int maxY = screen.height() - height() - MARGIN;
        if( destination.y() < MARGIN ) destination.ry() = MARGIN;
        if( destination.y() > maxY ) destination.ry() = maxY;

        if( eGlobalPosX < (hcenter-snapZone) )
        {
            m_alignment = Left;
            destination.rx() = MARGIN;
        }
        else if( eGlobalPosX > (hcenter+snapZone) )
        {
            m_alignment = Right;
            destination.rx() = screen.width() - MARGIN - width();
        }
        else
        {
            const uint eGlobalPosY = e->globalPos().y() - screen.top();
            const uint vcenter     = screen.height()/2;

            destination.rx() = hcenter - width()/2;

            if( eGlobalPosY >= (vcenter-snapZone) && eGlobalPosY <= (vcenter+snapZone) )
            {
                m_alignment = Center;
                destination.ry() = vcenter - height()/2;
            }
            else m_alignment = Middle;
        }

        destination += screen.topLeft();

        move( destination );
    }
}
Esempio n. 13
0
void MouseButton::mouseReleaseEvent(QMouseEvent *event)
{

    if (!mouseGrabber()) {
        KPushButton::mouseReleaseEvent(event);
    } else {
        releaseMouse();
        const Button oldButton = m_button;
        switch (event->button()) {
        case Qt::NoButton: setButton(NoButton); break;
        case Qt::LeftButton: setButton(LeftButton); break;
        case Qt::RightButton: setButton(RightButton); break;
        case Qt::MidButton: setButton(MiddleButton); break;
        case Qt::XButton1: setButton(SpecialButton1); break;
        case Qt::XButton2: setButton(SpecialButton2); break;
        default: setButton(NoButton); break;
        }
        setChecked(false);
        emit buttonChanged(oldButton, m_button);
    }

}
Esempio n. 14
0
    //____________________________________________________________________
    bool SplitterProxy::event( QEvent *event )
    {
        switch( event->type() )
        {

            case QEvent::MouseMove:
            case QEvent::MouseButtonPress:
            case QEvent::MouseButtonRelease:
            {

                // check splitter
                if( !_splitter ) return false;

                event->accept();

                // grab on mouse press
                if( event->type() == QEvent::MouseButtonPress) grabMouse();

                parentWidget()->setUpdatesEnabled(false);
                resize(1,1);
                parentWidget()->setUpdatesEnabled(true);

                // cast to mouse event
                QMouseEvent *mouseEvent( static_cast<QMouseEvent*>( event ) );

                // get relevant position to post mouse drag event to application
                if( event->type() == QEvent::MouseButtonPress )
                {

                    // use hook, to make sure splitter is properly dragged
                    QMouseEvent mouseEvent2(
                        mouseEvent->type(),
                        _hook,
                        _splitter.data()->mapToGlobal(_hook),
                        mouseEvent->button(),
                        mouseEvent->buttons(), mouseEvent->modifiers());

                    QCoreApplication::sendEvent( _splitter.data(), &mouseEvent2 );

                } else {

                    // map event position to current splitter and post.
                   QMouseEvent mouseEvent2(
                        mouseEvent->type(),
                        _splitter.data()->mapFromGlobal( mouseEvent->globalPos() ),
                        mouseEvent->globalPos(),
                        mouseEvent->button(),
                        mouseEvent->buttons(), mouseEvent->modifiers());

                    QCoreApplication::sendEvent( _splitter.data(), &mouseEvent2 );


                }

                // release grab on mouse-Release
                if( event->type() == QEvent::MouseButtonRelease && mouseGrabber() == this )
                { releaseMouse(); }

                return true;

            }

            case QEvent::Timer:
            if( static_cast<QTimerEvent*>( event )->timerId() != _timerId )
            { return QWidget::event( event ); }

            if( mouseGrabber() == this )
            { return true; }

            /*
            Fall through is intended.
            We somehow lost a QEvent::Leave and gonna fix that from here
            */

            case QEvent::HoverLeave:
            case QEvent::Leave:
            {

                // reset splitter
                if( isVisible() && !rect().contains( mapFromGlobal( QCursor::pos() ) ) )
                { clearSplitter(); }
                return true;

            }

            default:
            return QWidget::event( event );

        }

    }
Esempio n. 15
0
bool KickerTip::eventFilter(QObject *object, QEvent *event)
{
    if (!tippingEnabled())
    {
        return false;
    }

    if (!object->isWidgetType())
    {
        return false;
    }

    QWidget *widget = static_cast<QWidget*>(object);

    switch (event->type())
    {
        case QEvent::Enter:
            if (!KickerSettings::showMouseOverEffects())
            {
                return false;
            }

            if (!mouseGrabber() &&
                !qApp->activePopupWidget() &&
                !isTippingFor(widget))
            {
                m_toolTipsEnabled = QToolTip::isGloballyEnabled();
                QToolTip::setGloballyEnabled(false);

                tipFor(widget);
                m_timer.stop();
                disconnect(&m_timer, SIGNAL(timeout()), 0, 0);
                connect(&m_timer, SIGNAL(timeout()), SLOT(display()));

                // delay to avoid false starts
                // e.g. when the user quickly zooms their mouse over
                // a button then out of kicker
                if (isVisible())
                {
                    m_timer.start(150, true);
                }
                else
                {
                    m_timer.start(KickerSettings::mouseOversShowDelay(), true);
                }
            }
            break;
        case QEvent::Leave:
            QToolTip::setGloballyEnabled(m_toolTipsEnabled);

            m_timer.stop();

            if (isTippingFor(widget) && isVisible())
            {
                disconnect(&m_timer, SIGNAL(timeout()), 0, 0);
                connect(&m_timer, SIGNAL(timeout()), SLOT(hide()));
                m_timer.start(KickerSettings::mouseOversHideDelay(), true);
            }

            tipFor(0);
            break;
        case QEvent::MouseButtonPress:
            QToolTip::setGloballyEnabled(m_toolTipsEnabled);
            m_timer.stop();
            m_frameTimer.stop();
            hide();
        default:
            break;
    }

    return false;
}