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(); }
int setitem( PyObject* key, PyObject* value ) { Items::iterator it = std::lower_bound( m_items->begin(), m_items->end(), key, MapItem::CmpLess() ); if( it == m_items->end() ) m_items->push_back( MapItem( key, value ) ); else if( MapItem::CmpEq()( *it, key ) ) it->update( value ); else m_items->insert( it, MapItem( key, value ) ); return 0; }
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(); }
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); }
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; }
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 ); }
void HoverIndex::release(QObject *o) { QWidget *w = qobject_cast<QWidget*>(o); if (!w) return; Items::iterator it = items.begin(), end = items.end(); while (it != end) { if (it.key().isNull()) { it = items.erase(it); continue; } if (it.key().data() == w) { items.erase(it); break; } ++it; } if (items.isEmpty()) timer.stop(); }
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; }
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 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 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); }
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(); }
void ComboBox::createGraphicsImplementation() { Style *style = (getStyle() != 0) ? getStyle() : Style::instance().get(); _buttonSwitch = new osg::Switch; _popup = new osgUI::Popup; _popup->setVisible(false); _popup->setFrameSettings(getFrameSettings()); osg::BoundingBox extents(_extents); osg::ref_ptr<osg::Group> group = new osg::Group; bool requiresFrame = (getFrameSettings() && getFrameSettings()->getShape() != osgUI::FrameSettings::NO_FRAME); float frameWidth = 0.0; float unFocused = 0.92; float withFocus = 0.97; osg::Vec4 frameColor(unFocused, unFocused, unFocused, 1.0f); if (requiresFrame) { frameWidth = getFrameSettings()->getLineWidth(); group->addChild(style->createFrame(_extents, getFrameSettings(), frameColor)); extents.xMin() += frameWidth; extents.xMax() -= frameWidth; extents.yMin() += frameWidth; extents.yMax() -= frameWidth; } bool itemsHaveColor = false; for (Items::iterator itr = _items.begin(); itr != _items.end(); ++itr) { Item *item = itr->get(); if (item->getColor().a() != 0.0f) { itemsHaveColor = true; break; } } // work out position of carat. float h = extents.yMax() - extents.yMin(); float w = h * 0.7; float minItemWidth = (extents.xMax() - extents.xMin()) * 0.5f; if (w > minItemWidth) w = minItemWidth; float xDivision = extents.xMax() - w; osg::BoundingBox backgroundExtents = extents; osg::BoundingBox iconExtents = backgroundExtents; iconExtents.xMin() = xDivision; extents.xMax() = xDivision; if (itemsHaveColor) { backgroundExtents.xMin() = xDivision; } OSG_NOTICE << "itemsHaveColor = " << itemsHaveColor << std::endl; // clear background of edit region _backgroundSwitch = new osg::Switch; _backgroundSwitch->addChild(style->createPanel(backgroundExtents, osg::Vec4(unFocused, unFocused, unFocused, 1.0))); _backgroundSwitch->addChild(style->createPanel(backgroundExtents, osg::Vec4(withFocus, withFocus, withFocus, 1.0))); _backgroundSwitch->setSingleChildOn(0); // assign carat group->addChild(_backgroundSwitch.get()); group->addChild(_buttonSwitch.get()); // group->addChild(style->createIcon(iconExtents, "cow.osgt", osg::Vec4(withFocus, withFocus, withFocus,1.0))); group->addChild(style->createIcon(iconExtents, "Images/osg64.png", osg::Vec4(withFocus, withFocus, withFocus, 1.0))); if (!_items.empty()) { float margin = (extents.yMax() - extents.yMin()) * 0.1f; // float itemWidth = (_extents.xMax()-_extents.xMin()) - 2.0f*frameWidth; float itemHeight = (_extents.yMax() - _extents.yMin()) - 2.0f * frameWidth; float popupHeight = (itemHeight) * _items.size() + margin * static_cast<float>(_items.size() - 1) + 2.0f * frameWidth; float popupTop = _extents.yMin() - frameWidth - margin * 1.0f; float popupLeft = _extents.xMin(); float popupRight = _extents.xMax(); osg::BoundingBox popupExtents(popupLeft, popupTop - popupHeight, _extents.zMin(), popupRight, popupTop, _extents.zMax()); _popup->setExtents(popupExtents); osg::BoundingBox popupItemExtents(popupExtents.xMin() + frameWidth, popupTop - frameWidth - itemHeight, popupExtents.zMin(), popupExtents.xMax() - frameWidth, popupTop - frameWidth, popupExtents.zMax()); _popupItemOrigin.set(popupItemExtents.xMin(), popupItemExtents.yMax(), popupExtents.zMin()); _popupItemSize.set(popupItemExtents.xMax() - popupItemExtents.xMin(), -(itemHeight + margin), 0.0); unsigned int index = 0; for (Items::iterator itr = _items.begin(); itr != _items.end(); ++itr, ++index) { Item *item = itr->get(); OSG_NOTICE << "Creating item " << item->getText() << ", " << item->getColor() << std::endl; // setup graphics for button { osg::ref_ptr<osg::Group> group = new osg::Group; if (item->getColor().a() != 0.0f) group->addChild(style->createPanel(extents, item->getColor())); if (!item->getText().empty()) group->addChild(style->createText(extents, getAlignmentSettings(), getTextSettings(), item->getText())); _buttonSwitch->addChild(group.get()); } // setup graphics for popup { osg::ref_ptr<osg::Group> group = new osg::Group; if (item->getColor().a() != 0.0f) group->addChild(style->createPanel(popupItemExtents, item->getColor())); if (!item->getText().empty()) group->addChild(style->createText(popupItemExtents, getAlignmentSettings(), getTextSettings(), item->getText())); _popup->addChild(group.get()); popupItemExtents.yMin() -= (itemHeight + margin); popupItemExtents.yMax() -= (itemHeight + margin); } } } else { _buttonSwitch->addChild(style->createPanel(_extents, frameColor)); } _buttonSwitch->setSingleChildOn(_currentIndex); style->setupClipStateSet(_extents, getOrCreateWidgetStateSet()); setGraphicsSubgraph(0, group.get()); addChild(_popup.get()); }