void QDesignerFormBuilder::applyProperties(QObject *o, const QList<DomProperty*> &properties) { typedef QList<DomProperty*> DomPropertyList; if (properties.empty()) return; const QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), o); const QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core()->extensionManager(), o); const bool changingMetaObject = WidgetFactory::classNameOf(core(), o) == QStringLiteral("QAxWidget"); const QDesignerMetaObjectInterface *meta = core()->introspection()->metaObject(o); const bool dynamicPropertiesAllowed = dynamicSheet && dynamicSheet->dynamicPropertiesAllowed(); QDesignerPropertySheet *designerPropertySheet = qobject_cast<QDesignerPropertySheet *>( core()->extensionManager()->extension(o, Q_TYPEID(QDesignerPropertySheetExtension))); if (designerPropertySheet) { if (designerPropertySheet->pixmapCache()) designerPropertySheet->setPixmapCache(m_pixmapCache); if (designerPropertySheet->iconCache()) designerPropertySheet->setIconCache(m_iconCache); } const DomPropertyList::const_iterator cend = properties.constEnd(); for (DomPropertyList::const_iterator it = properties.constBegin(); it != cend; ++it) { DomProperty *p = *it; QVariant v; if (!readDomEnumerationValue(p, sheet, v)) v = toVariant(o->metaObject(), p); if (v.isNull()) continue; const QString attributeName = p->attributeName(); if (d->applyPropertyInternally(o, attributeName, v)) continue; // refuse fake properties like current tab name (weak test) if (!dynamicPropertiesAllowed) { if (changingMetaObject) // Changes after setting control of QAxWidget meta = core()->introspection()->metaObject(o); if (meta->indexOfProperty(attributeName) == -1) continue; } QObject *obj = o; QAbstractScrollArea *scroll = qobject_cast<QAbstractScrollArea *>(o); if (scroll && attributeName == QStringLiteral("cursor") && scroll->viewport()) obj = scroll->viewport(); // a real property obj->setProperty(attributeName.toUtf8(), v); } }
VisualNode* TreeCanvas::eventNode(QEvent* event) { int x = 0; int y = 0; switch (event->type()) { case QEvent::ToolTip: { QHelpEvent* he = static_cast<QHelpEvent*>(event); x = he->x(); y = he->y(); break; } case QEvent::MouseButtonDblClick: case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseMove: { QMouseEvent* me = static_cast<QMouseEvent*>(event); x = me->x(); y = me->y(); break; } case QEvent::ContextMenu: { QContextMenuEvent* ce = static_cast<QContextMenuEvent*>(event); x = ce->x(); y = ce->y(); break; } default: return NULL; } QAbstractScrollArea* sa = static_cast<QAbstractScrollArea*>(parentWidget()->parentWidget()); int xoff = sa->horizontalScrollBar()->value()/scale; int yoff = sa->verticalScrollBar()->value()/scale; BoundingBox bb = root->getBoundingBox(); int w = static_cast<int>((bb.right-bb.left+Layout::extent)*scale); if (w < sa->viewport()->width()) xoff -= (sa->viewport()->width()-w)/2; VisualNode* n; n = root->findNode(*na, static_cast<int>(x/scale-xtrans+xoff), static_cast<int>((y-30)/scale+yoff)); return n; }
void FlickCharm::deactivateFrom(QWidget *widget) { QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea*>(widget); if (scrollArea) { QWidget *viewport = scrollArea->viewport(); viewport->removeEventFilter(this); scrollArea->removeEventFilter(this); delete d->flickData[viewport]; d->flickData.remove(viewport); return; } QWebView *webView = qobject_cast<QWebView*>(widget); if (webView) { webView->removeEventFilter(this); delete d->flickData[webView]; d->flickData.remove(webView); return; } }
static void createPlatformGraphicsContext3DFromWidget(QWidget* widget, PlatformGraphicsContext3D* context, PlatformGraphicsSurface3D* surface) { *context = 0; *surface = 0; QAbstractScrollArea* scrollArea = qobject_cast<QAbstractScrollArea*>(widget); if (!scrollArea) return; QGLWidget* glViewport = qobject_cast<QGLWidget*>(scrollArea->viewport()); if (!glViewport) return; QGLWidget* glWidget = new QGLWidget(0, glViewport); if (glWidget->isValid()) { // Geometry can be set to zero because m_glWidget is used only for its QGLContext. glWidget->setGeometry(0, 0, 0, 0); #if HAVE(QT5) *surface = glWidget->windowHandle(); *context = glWidget->context()->contextHandle(); #else *surface = glWidget; *context = const_cast<QGLContext*>(glWidget->context()); #endif } else { delete glWidget; glWidget = 0; } }
void KoCursorPrivate::setAutoHideCursor( QWidget *w, bool enable, bool customEventFilter ) { if ( !w || !enabled ) return; QWidget* viewport = 0; QAbstractScrollArea * sv = qobject_cast<QAbstractScrollArea *>( w ); if ( sv ) viewport = sv->viewport(); if ( enable ) { if ( m_eventFilters.contains( w ) ) return; KoCursorPrivateAutoHideEventFilter* filter = new KoCursorPrivateAutoHideEventFilter( w ); m_eventFilters.insert( w, filter ); if (viewport) { m_eventFilters.insert( viewport, filter ); connect(viewport, SIGNAL(destroyed(QObject*)), this, SLOT(slotViewportDestroyed(QObject*))); } if ( !customEventFilter ) { w->installEventFilter( filter ); // for key events if (viewport) viewport->installEventFilter( filter ); // for mouse events } connect( w, SIGNAL(destroyed(QObject*)), this, SLOT(slotWidgetDestroyed(QObject*)) ); } else {
void TreeCanvas::centerCurrentNode(void) { QMutexLocker locker(&mutex); int x=0; int y=0; VisualNode* c = currentNode; while (c != NULL) { x += c->getOffset(); y += Layout::dist_y; c = c->getParent(*na); } x = static_cast<int>((xtrans+x)*scale); y = static_cast<int>(y*scale); QAbstractScrollArea* sa = static_cast<QAbstractScrollArea*>(parentWidget()->parentWidget()); x -= sa->viewport()->width() / 2; y -= sa->viewport()->height() / 2; sourceX = sa->horizontalScrollBar()->value(); targetX = std::max(sa->horizontalScrollBar()->minimum(), x); targetX = std::min(sa->horizontalScrollBar()->maximum(), targetX); sourceY = sa->verticalScrollBar()->value(); targetY = std::max(sa->verticalScrollBar()->minimum(), y); targetY = std::min(sa->verticalScrollBar()->maximum(), targetY); if (!smoothScrollAndZoom) { sa->horizontalScrollBar()->setValue(targetX); sa->verticalScrollBar()->setValue(targetY); } else { scrollTimeLine.stop(); scrollTimeLine.setFrameRange(0,100); scrollTimeLine.setDuration(std::max(200, std::min(1000, std::min(std::abs(sourceX-targetX), std::abs(sourceY-targetY))))); scrollTimeLine.start(); } }
// The widget which gets mouse events, and that shows the cursor // (that is the viewport, for a QAbstractScrollArea) QWidget* KoCursorPrivateAutoHideEventFilter::mouseWidget() const { QWidget* w = m_widget; // Is w a QAbstractScrollArea ? Call setCursor on the viewport in that case. QAbstractScrollArea * sv = qobject_cast<QAbstractScrollArea *>( w ); if ( sv ) w = sv->viewport(); return w; }
void MetaInfoDialog::artworkContextMenuRequested(const QPoint &pos) { QAbstractScrollArea *scrollArea = dynamic_cast<QAbstractScrollArea*>(QObject::sender()); QWidget *sender = scrollArea ? scrollArea->viewport() : dynamic_cast<QWidget*>(QObject::sender()); if(sender) { if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0) { m_contextMenuArtwork->popup(sender->mapToGlobal(pos)); } } }
void TreeCanvas::paintEvent(QPaintEvent* event) { QMutexLocker locker(&layoutMutex); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); QAbstractScrollArea* sa = static_cast<QAbstractScrollArea*>(parentWidget()->parentWidget()); int xoff = sa->horizontalScrollBar()->value()/scale; int yoff = sa->verticalScrollBar()->value()/scale; BoundingBox bb = root->getBoundingBox(); int w = static_cast<int>((bb.right-bb.left+Layout::extent)*scale); if (w < sa->viewport()->width()) xoff -= (sa->viewport()->width()-w)/2; QRect origClip = event->rect(); painter.translate(0, 30); painter.scale(scale,scale); painter.translate(xtrans-xoff, -yoff); QRect clip(static_cast<int>(origClip.x()/scale-xtrans+xoff), static_cast<int>(origClip.y()/scale+yoff), static_cast<int>(origClip.width()/scale), static_cast<int>(origClip.height()/scale)); DrawingCursor dc(root, *na, curBest, painter, clip, showCopies); PreorderNodeVisitor<DrawingCursor>(dc).run(); // int nodesLayouted = 1; // clock_t t0 = clock(); // while (v.next()) { nodesLayouted++; } // double t = (static_cast<double>(clock()-t0) / CLOCKS_PER_SEC) * 1000.0; // double nps = static_cast<double>(nodesLayouted) / // (static_cast<double>(clock()-t0) / CLOCKS_PER_SEC); // std::cout << "Drawing done. " << nodesLayouted << " nodes in " // << t << " ms. " << nps << " nodes/s." << std::endl; }
MouseMachine::MouseMachine(QWidget* parent, MouseMachine::Options options) : QObject(parent) , theParent(parent) , m_options(options) , machine(0) , trPressed2Idle(0) , trPressed2Man(0) , trManScrolling(0) , trIdle2Pressed(0) , trMan2Auto(0) , trMan2Idle(0) , trAuto2Idle(0) , trAuto2Man(0) , trDoubleclick(0) { #ifdef Q_OS_SYMBIAN iTouchFeedback = MTouchFeedback::Instance(); #endif speedTimer.setInterval(SPEED_INTERVAL); connect(&speedTimer, SIGNAL(timeout()), SLOT(slotCalculateSpeed())); dblclickTimer.setInterval(DBLCLICK_INTERVAL); dblclickTimer.setSingleShot(true); connect(&dblclickTimer, SIGNAL(timeout()), SLOT(slotSingleTap())); scrollTimeline.setCurveShape(QTimeLine::EaseOutCurve); scrollTimeline.setEasingCurve(QEasingCurve::OutQuad); connect(&scrollTimeline, SIGNAL(valueChanged(qreal)), SLOT(slotAutoscroll(qreal))); connect(&scrollTimeline, SIGNAL(finished()), SLOT(slotAutoscrollFinished())); tapHoldTimer.setInterval(TAPHOLD_TIMEOUT); tapHoldTimer.setSingleShot(true); theTarget = theParent; QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea*>(theParent); if (scrollArea) { scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); theTarget = scrollArea->viewport(); theTarget->installEventFilter(this); } theParent->installEventFilter(this); buildMachine(); machine->start(); }
void FlickCharm::activateOn(QWidget *widget) { QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea*>(widget); if (scrollArea) { scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); QWidget *viewport = scrollArea->viewport(); viewport->installEventFilter(this); scrollArea->installEventFilter(this); d->flickData.remove(viewport); d->flickData[viewport] = new FlickData; d->flickData[viewport]->widget = widget; d->flickData[viewport]->state = FlickData::Steady; return; } QWebView *webView = qobject_cast<QWebView*>(widget); if (webView) { QWebFrame *frame = webView->page()->mainFrame(); frame->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); frame->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); webView->installEventFilter(this); d->flickData.remove(webView); d->flickData[webView] = new FlickData; d->flickData[webView]->widget = webView; d->flickData[webView]->state = FlickData::Steady; return; } qWarning() << "FlickCharm only works on QAbstractScrollArea (and derived classes)"; qWarning() << "or QWebView (and derived classes)"; }
void FindBar::find(FindBar::FindDirection dir) { Q_ASSERT(m_associatedWebView); if (isHidden()) { QPoint previous_position = m_associatedWebView->page()->currentFrame()->scrollPosition(); m_associatedWebView->page()->focusNextPrevChild(true); m_associatedWebView->page()->currentFrame()->setScrollPosition(previous_position); return; } QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument; if (dir == Backward) options |= QWebPage::FindBackward; if (matchCase()) options |= QWebPage::FindCaseSensitively; // HACK Because we're using the QWebView inside a QScrollArea container, the attempts // to scroll the QWebView itself have no direct effect. // Therefore we temporarily shrink the page viewport to the message viewport (ie. the size it // can cover at max), then perform the search, store the scrollPosition, restore the page viewport // and finally scroll the messageview to the gathered scrollPosition, mapped to the message (ie. // usually offset by the mail header) auto emb = qobject_cast<EmbeddedWebView *>(m_associatedWebView); QAbstractScrollArea *container = emb ? static_cast<QAbstractScrollArea*>(emb->scrollParent()) : nullptr; const QSize oldVpS = m_associatedWebView->page()->viewportSize(); const bool useResizeTrick = container ? !!container->verticalScrollBar() : false; // first shrink the page viewport if (useResizeTrick) { m_associatedWebView->setUpdatesEnabled(false); // don't let the user see the flicker we might produce QSize newVpS = oldVpS.boundedTo(container->size()); m_associatedWebView->page()->setViewportSize(newVpS); } // now perform the search (pot. in the shrinked viewport) bool found = m_associatedWebView->page()->findText(_lastStringSearched, options); notifyMatch(found); // scroll and reset the page viewport if necessary if (useResizeTrick) { Q_ASSERT(container->verticalScrollBar()); // the page has now a usable scroll position ... int scrollPosition = m_associatedWebView->page()->currentFrame()->scrollPosition().y(); // ... which needs to be extended by the pages offset (usually the header widget) // NOTICE: QWidget::mapTo() fails as the viewport child position can be negative, so we run ourself QWidget *runner = m_associatedWebView; while (runner->parentWidget() != container->viewport()) { scrollPosition += runner->y(); runner = runner->parentWidget(); } // reset viewport to original size ... m_associatedWebView->page()->setViewportSize(oldVpS); // ... let the user see the change ... m_associatedWebView->setUpdatesEnabled(true); // ... and finally scroll to the desired position if (found) container->verticalScrollBar()->setValue(scrollPosition); } if (!found) { QPoint previous_position = m_associatedWebView->page()->currentFrame()->scrollPosition(); m_associatedWebView->page()->focusNextPrevChild(true); m_associatedWebView->page()->currentFrame()->setScrollPosition(previous_position); } }