Esempio n. 1
0
void
Hover::timerEvent(QTimerEvent * event)
{
    if (event->timerId() != timer.timerId() || noAnimations())
        return;

    Items::iterator it = items.begin();
    int *step = 0;
    QWidget *widget = 0;
    while (it != items.end())
    {
        widget = it.key();
        if (!widget)
        {
            it = items.erase(it);
            continue;
        }
        step = &it.value()._step;
        if (it.value().backwards)
        {   // fade OUT
            --(*step);
            widget->update();
            if (*step < 1)
            {
#if WOBBLE_HOVER
                if (widget->testAttribute(Qt::WA_UnderMouse))
                    it.value().backwards = false;
                else
#endif
                    it = items.erase(it);
            }
            else
                ++it;
        }
        else
        {   // fade IN
            *step += HOVER_IN_STEP;
            widget->update();
            if ((uint)(*step) > maxSteps-2)
            {
#if WOBBLE_HOVER
                if (widget->testAttribute(Qt::WA_UnderMouse))
                    it.value().backwards = true;
                else
#endif
                    it = items.erase(it);
            }
            else
                ++it;
        }
    }
    if (noAnimations())
        timer.stop();
}
void
HoverIndex::timerEvent(QTimerEvent * event)
{
    if (event->timerId() != timer.timerId() || items.isEmpty())
        return;

    Items::iterator it;
    IndexInfo::Fades::iterator step;
    it = items.begin();
    QWidget *w;
    while (it != items.end())
    {
        if (it.key().isNull())
        {
            it = items.erase(it);
            continue;
        }
        w = const_cast<QWidget*>(it.key().data());
        IndexInfo &info = it.value();
        if (info.fades[In].isEmpty() && info.fades[Out].isEmpty())
        {
            ++it; continue;
        }

        step = info.fades[In].begin();
        while (step != info.fades[In].end())
        {
            step.value() += 2;
            if ((uint)step.value() > (maxSteps-2))
                step = info.fades[In].erase(step);
            else
                ++step;
        }

        step = info.fades[Out].begin();
        while (step != info.fades[Out].end())
        {
            step.value() -= 2;
            if (step.value() < 1)
                step = info.fades[Out].erase(step);
            else
                ++step;
        }

        w->update();

        if (info.index == 0L && // nothing actually hovered
            info.fades[In].isEmpty() && // no fade ins
            info.fades[Out].isEmpty()) // no fade outs
            it = items.erase(it); // so remove this item
        else
            ++it;
    }

    if (items.isEmpty())
        timer.stop();
}
void
HoverComplex::timerEvent(QTimerEvent * event)
{
    if (event->timerId() != timer.timerId() || items.isEmpty())
        return;

    bool update;
    Items::iterator it = items.begin();
    ComplexInfo *info;
    while (it != items.end())
    {
        if (!it.key())
        {
            it = items.erase(it);
            continue;
        }
        info = &it.value();
        update = false;
        for (QStyle::SubControl control = (QStyle::SubControl)0x01;
            control <= (QStyle::SubControl)0x80;
            control = (QStyle::SubControl)(control<<1))
            {
                if (info->fades[In] & control)
                {
                    update = true;
                    info->steps[control] += 2;
                    if (info->steps.value(control) > 4)
                        info->fades[In] &= ~control;
                }
                else if (info->fades[Out] & control)
                {
                    update = true;
                    --info->steps[control];
                    if (info->steps.value(control) < 1)
                        info->fades[Out] &= ~control;
                }
            }
        if (update)
            it.key()->update();
        if (info->active == QStyle::SC_None && // needed to detect changes!
                                                info->fades[Out] == QStyle::SC_None &&
                                                info->fades[In] == QStyle::SC_None)
            it = items.erase(it);
        else
            ++it;
    }

    if (items.isEmpty())
        timer.stop();
}
Esempio n. 4
0
void
Hover::play(QWidget *widget, bool bwd)
{
    if (!widget)
        return;

    const bool needTimer = noAnimations(); // true by next lines
    Items::iterator it = items.find(widget);
    if (it == items.end())
        it = items.insert(widget, Info(bwd ? maxSteps : 1, bwd));
    else
        it.value().backwards = bwd;
    if (needTimer)
        timer.start(timeStep, this);
}
Esempio n. 5
0
 PyObject* values()
 {
     PyObject* pylist = PyList_New( m_items->size() );
     if( !pylist )
         return 0;
     Py_ssize_t listidx = 0;
     Items::iterator it;
     Items::iterator end_it = m_items->end();
     for( it = m_items->begin(); it != end_it; ++it )
     {
         PyList_SET_ITEM( pylist, listidx, newref( it->value() ) );
         ++listidx;
     }
     return pylist;
 }
Esempio n. 6
0
 PyObject* getitem( PyObject* key, PyObject* default_value = 0 )
 {
     Items::iterator it = std::lower_bound(
         m_items->begin(), m_items->end(), key, MapItem::CmpLess()
     );
     if( it == m_items->end() )
     {
         if( default_value )
             return newref( default_value );
         return lookup_fail( key );
     }
     if( MapItem::CmpEq()( *it, key ) )
         return newref( it->value() );
     if( default_value )
         return newref( default_value );
     return lookup_fail( key );
 }
const ComplexInfo *
HoverComplex::_info(const QWidget *widget, QStyle::SubControls active) const
{
    QWidget *w = const_cast<QWidget*>(widget);
    HoverComplex *that = const_cast<HoverComplex*>(this);
    Items::iterator it = that->items.find(w);
    if (it == items.end())
    {
        // we have no entry yet
        if (active == QStyle::SC_None)
            return 0; // no need here
        // ...but we'll need one
        it = that->items.insert(w, ComplexInfo());
        connect(w, SIGNAL(destroyed(QObject*)), this, SLOT(release(QObject*)));
        that->timer.start(timeStep, that);
    }
    // we now have an entry - check for validity and update in case
    ComplexInfo *info = &it.value();
    if (info->active != active)
    {   // sth. changed
        QStyle::SubControls diff = info->active ^ active;
        QStyle::SubControls newActive = diff & active;
        QStyle::SubControls newDead = diff & info->active;
        info->fades[In] &= ~newDead; info->fades[In] |= newActive;
        info->fades[Out] &= ~newActive; info->fades[Out] |= newDead;
        info->active = active;
        for (QStyle::SubControl control = (QStyle::SubControl)0x01;
                                control <= (QStyle::SubControl)0x80;
                                control = (QStyle::SubControl)(control<<1))
        {
            if (newActive & control)
                info->steps[control] = 1;
//             else if (newDead & control)
//             {
//                 info->steps[control] = maxSteps;
//             }
        }
    }
    return info;
}
Esempio n. 8
0
void
Basic::timerEvent(QTimerEvent * event)
{
    if (event->timerId() != timer.timerId() || noAnimations())
        return;
    //Update the registered progressbars.
    QWidget *w;
    Items::iterator it = items.begin();
    while (it != items.end())
    {
        w = it.key();
        if (!w)
        {
            it = items.erase(it);
            continue;
        }
        if (w->paintingActive() || !w->isVisible())
            continue;
        ++it.value();
        w->repaint();
        ++it;
    }
}
const IndexInfo *
HoverIndex::_info(const QWidget *widget, long int idx) const
{
    HoverIndex *that = const_cast<HoverIndex*>(this);
    QWidget *w = const_cast<QWidget*>(widget);
    Items::iterator it = that->items.find(w);
    if (it == items.end())
    {   // we have no entry yet
        if (idx == 0L)
            return 0L;
        // ... but we'll need one
        it = that->items.insert(w, IndexInfo(0L));
        connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(release(QObject*)));
//         if (!timer.isActive())
            that->timer.start(timeStep, that);
    }
    // we now have an entry - check for validity and update in case
    IndexInfo &info = it.value();
    if (info.index != idx)
    {   // sth. changed
        info.fades[In][idx] = 1;
        if (info.index)
        {
            int v = maxSteps;
            IndexInfo::Fades::iterator old = info.fades[In].find(info.index);
            if (old != info.fades[In].end())
            {
                v = old.value();
                info.fades[In].erase(old);
            }
            info.fades[Out][info.index] = v;
        }
        info.index = idx;
    }
    return &info;
}
void
Progress::timerEvent(QTimerEvent * event)
{
    if (event->timerId() != timer.timerId() || noAnimations())
        return;

    //Update the registered progressbars.
    Items::iterator iter;
    QProgressBar *pb;
    bool mkProper = false;
    animationUpdate = true;
    for (iter = items.begin(); iter != items.end(); iter++)
    {
        QWidget *w = const_cast<QWidget*>(iter.key().data());
        if (!w) // not a progressbar - shouldn't be in items, btw...
            { mkProper = true; continue; }

        pb = qobject_cast<QProgressBar*>(w);
        if (!pb)
            continue; // not a progressbar - shouldn't be in items, btw...

        if (pb->maximum() != 0 || pb->minimum() != 0 || pb->paintingActive() || !pb->isVisible())
        {
            pb->setAttribute(Qt::WA_OpaquePaintEvent, false);
            continue; // no paint necessary
        }

        pb->setAttribute(Qt::WA_OpaquePaintEvent);

        ++iter.value();

        // dump pb geometry
        int x,y,l,t, *step = &iter.value()._step;
        if ( pb->orientation() == Qt::Vertical ) // swapped values
            pb->rect().getRect(&y,&x,&t,&l);
        else
            pb->rect().getRect(&x,&y,&l,&t);

        if (*step > l/_speed)
            *step = l/36-(int)(l/_speed);
        else if (*step == -1)
            *step = l/36-1;

        int s = qMin(qMax(l / 10, 16), qMin(t, 20));
        int ss = (3*s)/4;
        int n = l/s;
        if ( pb->orientation() == Qt::Vertical)
            { x = pb->rect().bottom(); x -= (l - n*s)/2 + ss; /*s = -s;*/ }
        else
            { x += (l - n*s)/2; /*s = qAbs(s);*/ }

        x += qMax((int)(_speed*qAbs(*step)*n*s/l) - s, 0);
        if ( pb->orientation() == Qt::Vertical )
            pb->repaint(y,x-s,s,3*s);
        else
            pb->repaint(x-s,y,3*s,s);
    }
    animationUpdate = false;
    if (mkProper)
        _release(NULL);
}
Esempio n. 11
0
void
HoverIndex::timerEvent(QTimerEvent * event)
{
    if (event->timerId() != timer.timerId() || items.isEmpty())
        return;

    Items::iterator it;
    IndexInfo::Fades::iterator step;
    it = items.begin();
    QWidget *w;
    while (it != items.end())
    {
        if (!it.key())
        {
            it = items.erase(it);
            continue;
        }
#if QT_VERSION >= 0x040400
        // below does work in general, but is... ugly?!
        // another way would be to map to a const widget first or perform a static_cast - ughh
        w = const_cast<QWidget*>(it.key().data());
#else
        w = const_cast<QWidget*>(&(*it.key()));
#endif
        IndexInfo &info = it.value();
        if (info.fades[In].isEmpty() && info.fades[Out].isEmpty())
        {
            ++it; continue;
        }

        step = info.fades[In].begin();
        while (step != info.fades[In].end())
        {
            step.value() += 2;
            if ((uint)step.value() > (maxSteps-2))
                step = info.fades[In].erase(step);
            else
                ++step;
        }

        step = info.fades[Out].begin();
        while (step != info.fades[Out].end())
        {
            step.value() -= 2;
            if (step.value() < 1)
                step = info.fades[Out].erase(step);
            else
                ++step;
        }

        w->update();

        if (info.index == 0L && // nothing actually hovered
            info.fades[In].isEmpty() && // no fade ins
            info.fades[Out].isEmpty()) // no fade outs
            it = items.erase(it); // so remove this item
        else
            ++it;
    }

    if (items.isEmpty())
        timer.stop();
}