Ejemplo n.º 1
0
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;
    }
}
Ejemplo n.º 2
0
    bool eventFilter(QObject *o, QEvent *e) {
        switch (e->type()) {
        case QEvent::MouseMove: {
            if (notRelevant(e))
                return false;
            if (m_panning) {
                const QPoint pos = static_cast<QMouseEvent*>(e)->pos();
                bool noClick = !m_click;
                if (noClick) {
                    const int dx = pos.x() - m_lastPos.x();
                    const int dy = pos.y() - m_lastPos.y();
                    if (QAbstractScrollArea *area = qobject_cast<QAbstractScrollArea*>(o->parent())) {
                        // dolphin stacks a graphicsview into a view inside a view ...
                        QAbstractScrollArea *runner = area;
                        while ((runner = qobject_cast<QAbstractScrollArea*>(runner->parent())))
                            area = runner;

                        if (dx && area->horizontalScrollBar())
                            area->horizontalScrollBar()->setValue(area->horizontalScrollBar()->value() - dx);
                        if (dy && area->verticalScrollBar()) {
                            area->verticalScrollBar()->setValue(area->verticalScrollBar()->value() - dy);
                        }
                    } else { // mostly QWebView
                        int factor[2] = {1, 1};
                        if (o->inherits("QWebView")) {
                            foreach (const QObject *o2, o->children()) {
                                if (o2->inherits("QWebPage")) {
                                    foreach (const QObject *o3, o2->children()) {
                                        if (o3->inherits("QWebFrame")) {
                                            const QSize sz = o3->property("contentsSize").toSize();
                                            if (sz.isValid()) {
                                                const QSize wsz = static_cast<QWidget*>(o)->size();
                                                factor[0] = qMin(6, qRound(float(sz.width()) / wsz.width()));
                                                factor[1] = qMin(6, qRound(float(sz.height()) / wsz.height()));
                                            }
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                        if (dy) {
                            QWheelEvent wev(pos, dy*factor[1], Qt::NoButton, Qt::NoModifier, Qt::Vertical);
                            QApplication::sendEvent(o, &wev);
                        }
                        if (dx) {
                            QWheelEvent weh(pos, dx*factor[0], Qt::NoButton, Qt::NoModifier, Qt::Horizontal);
                            QApplication::sendEvent(o, &weh); // "oi wehh"
                        }
                    }
                }
                m_lastPos = pos;
//                 qDebug() << "mouse move" << m_click << QPoint(m_startPoint - m_lastPos) << QApplication::startDragDistance();
                m_click = m_click && qAbs(QPoint(m_startPoint - m_lastPos).manhattanLength()) <  QApplication::startDragDistance();
//                 qDebug() << "->" << m_click;
                return true; // noClick;
            }
            return false;
        }
Ejemplo n.º 3
0
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;
    }
}
Ejemplo n.º 4
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
    {
Ejemplo n.º 5
0
 void
 TreeCanvas::scroll(int i) {
   QAbstractScrollArea* sa =
     static_cast<QAbstractScrollArea*>(parentWidget()->parentWidget());
   double p = static_cast<double>(i)/100.0;
   double xdiff = static_cast<double>(targetX-sourceX)*p;
   double ydiff = static_cast<double>(targetY-sourceY)*p;
   sa->horizontalScrollBar()->setValue(sourceX+static_cast<int>(xdiff));
   sa->verticalScrollBar()->setValue(sourceY+static_cast<int>(ydiff));
 }
Ejemplo n.º 6
0
// 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 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);
    }
}
Ejemplo n.º 8
0
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));
		}
	}
}
Ejemplo n.º 9
0
  void
  TreeCanvas::layoutDone(int w, int h, int scale0) {
    targetW = w; targetH = h; targetScale = scale0;

    QSize viewport_size = size();
    QAbstractScrollArea* sa =
      static_cast<QAbstractScrollArea*>(parentWidget()->parentWidget());
    sa->horizontalScrollBar()->setRange(0,w-viewport_size.width());
    sa->verticalScrollBar()->setRange(0,h-viewport_size.height());

    if (layoutDoneTimerId == 0)
      layoutDoneTimerId = startTimer(15);
  }
Ejemplo n.º 10
0
  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;
  }
Ejemplo n.º 11
0
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();
}
Ejemplo n.º 12
0
  void
  TreeCanvas::update(void) {
    QMutexLocker locker(&mutex);
    layoutMutex.lock();
    if (root != NULL) {
      root->layout(*na);
      BoundingBox bb = root->getBoundingBox();

      int w = static_cast<int>((bb.right-bb.left+Layout::extent)*scale);
      int h =
        static_cast<int>(2*Layout::extent+
          root->getShape()->depth()*Layout::dist_y*scale);
      xtrans = -bb.left+(Layout::extent / 2);
      
      QSize viewport_size = size();
      QAbstractScrollArea* sa =
        static_cast<QAbstractScrollArea*>(parentWidget()->parentWidget());
      sa->horizontalScrollBar()->setRange(0,w-viewport_size.width());
      sa->verticalScrollBar()->setRange(0,h-viewport_size.height());
      sa->horizontalScrollBar()->setPageStep(viewport_size.width());
      sa->verticalScrollBar()->setPageStep(viewport_size.height());
      sa->horizontalScrollBar()->setSingleStep(Layout::extent);
      sa->verticalScrollBar()->setSingleStep(Layout::extent);
    }
    if (autoZoom)
      zoomToFit();
    layoutMutex.unlock();
    QWidget::update();
  }
Ejemplo n.º 13
0
void FancyStyle::polish(QWidget *widget) {
    QPlastiqueStyle::polish(widget);
    {
        QAbstractScrollArea *sa = qobject_cast<QAbstractScrollArea*>(widget);
        if (sa) {
            if (sa->frameShape() == QFrame::StyledPanel) {
                sa->setFrameShadow(QFrame::Plain);
            }
        }
    }
    #ifdef Q_WS_MAC
    {
        QLabel *l = qobject_cast<QLabel*>(widget);
        if (l) {
            l->setFont(QApplication::font());
        }
    }
    #endif
}
Ejemplo n.º 14
0
bool TextView::eventFilter(QObject *obj, QEvent *event)
{
#ifdef SCINTILLA
    QAbstractScrollArea * sa = scintEditor;
#else
    QAbstractScrollArea * sa = plainTextEdit;
#endif

    if (obj == sa) {
        sa->setAttribute(Qt::WA_NoMousePropagation, false);
        if (event->type() == QEvent::KeyPress) {
             QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
             switch (keyEvent->key())
             {
                 case Qt::Key_Z:
                     if (keyEvent->modifiers().testFlag(Qt::ShiftModifier) && keyEvent->modifiers().testFlag(Qt::ControlModifier)) {
                         byteSource->historyForward();
                         keyEvent->accept();
                         return true;
                     }
                     else if (keyEvent->modifiers().testFlag(Qt::ControlModifier)) {
                         byteSource->historyBackward();
                         keyEvent->accept();
                         return true;
                     }
                    break;
                 default:
                     return false;
             }

        } else if (event->type() == QEvent::Wheel) {
            if (sa->verticalScrollBar()->isVisible()) {
                sa->setAttribute(Qt::WA_NoMousePropagation);
            }

            return false;
        }
    }

    return QWidget::eventFilter(obj, event);

}
Ejemplo n.º 15
0
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)";
}
Ejemplo n.º 16
0
  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;

  }
Ejemplo n.º 17
0
  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();
    }
  }
Ejemplo n.º 18
0
  void
  TreeCanvas::resizeEvent(QResizeEvent* e) {
    QAbstractScrollArea* sa =
      static_cast<QAbstractScrollArea*>(parentWidget()->parentWidget());

    int w = sa->horizontalScrollBar()->maximum()+e->oldSize().width();
    int h = sa->verticalScrollBar()->maximum()+e->oldSize().height();

    sa->horizontalScrollBar()->setRange(0,w-e->size().width());
    sa->verticalScrollBar()->setRange(0,h-e->size().height());
    sa->horizontalScrollBar()->setPageStep(e->size().width());
    sa->verticalScrollBar()->setPageStep(e->size().height());
  }
Ejemplo n.º 19
0
/* Returns a new scrollbar for the given orientation, or set the scrollbar
 * passed as parameter */
wxScrollBar *wxWindowQt::QtSetScrollBar( int orientation, wxScrollBar *scrollBar )
{
    QAbstractScrollArea *scrollArea = QtGetScrollBarsContainer();
    wxCHECK_MSG( scrollArea, NULL, "Window without scrolling area" );

    // Create a new scrollbar if needed
    if ( !scrollBar )
    {
        scrollBar = new wxScrollBar( const_cast< wxWindowQt* >( this ), wxID_ANY,
                                     wxDefaultPosition, wxDefaultSize,
                                     orientation == wxHORIZONTAL ? wxSB_HORIZONTAL : wxSB_VERTICAL);

        // Connect scrollbar events to this window
        scrollBar->Bind( wxEVT_SCROLL_LINEUP, &wxWindowQt::QtOnScrollBarEvent, this );
        scrollBar->Bind( wxEVT_SCROLL_LINEDOWN, &wxWindowQt::QtOnScrollBarEvent, this );
        scrollBar->Bind( wxEVT_SCROLL_PAGEUP, &wxWindowQt::QtOnScrollBarEvent, this );
        scrollBar->Bind( wxEVT_SCROLL_PAGEDOWN, &wxWindowQt::QtOnScrollBarEvent, this );
        scrollBar->Bind( wxEVT_SCROLL_TOP, &wxWindowQt::QtOnScrollBarEvent, this );
        scrollBar->Bind( wxEVT_SCROLL_BOTTOM, &wxWindowQt::QtOnScrollBarEvent, this );
        scrollBar->Bind( wxEVT_SCROLL_THUMBTRACK, &wxWindowQt::QtOnScrollBarEvent, this );
        scrollBar->Bind( wxEVT_SCROLL_THUMBRELEASE, &wxWindowQt::QtOnScrollBarEvent, this );
    }

    // Let Qt handle layout
    if ( orientation == wxHORIZONTAL )
    {
        scrollArea->setHorizontalScrollBar( scrollBar->GetHandle() );
        m_horzScrollBar = scrollBar;
    }
    else
    {
        scrollArea->setVerticalScrollBar( scrollBar->GetHandle() );
        m_vertScrollBar = scrollBar;
    }
    return scrollBar;
}
Ejemplo n.º 20
0
    // scroll by dx, dy
    // return true if the widget was scrolled
    bool scrollWidget(const int dx, const int dy)
    {
        QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea*>(widget);
        if (scrollArea) {
            const int x = scrollArea->horizontalScrollBar()->value();
            const int y = scrollArea->verticalScrollBar()->value();
            scrollArea->horizontalScrollBar()->setValue(x - dx);
            scrollArea->verticalScrollBar()->setValue(y - dy);
            return (scrollArea->horizontalScrollBar()->value() != x
                    || scrollArea->verticalScrollBar()->value() != y);
        }

        QWebView *webView = qobject_cast<QWebView*>(widget);
        if (webView) {
            QWebFrame *frame = webView->page()->mainFrame();
            const QPoint position = frame->scrollPosition();
            frame->setScrollPosition(position - QPoint(dx, dy));
            return frame->scrollPosition() != position;
        }
        return false;
    }
Ejemplo n.º 21
0
/*!
    \fn void CSizeGrip::mousePressEvent(QMouseEvent * event)

    Receives the mouse press events for the widget, and primes the
    resize operation. The mouse press event is passed in the \a event
    parameter.
*/
void CSizeGrip::mousePressEvent(QMouseEvent * e)
{
    ungrabGesture(Qt::TapAndHoldGesture);

    if (e->button() != Qt::LeftButton) {
        QWidget::mousePressEvent(e);
        return;
    }


    QWidget *tlw = qt_sizegrip_topLevelWidget();
    p = e->globalPos();
    gotMousePress = true;
    r = tlw->geometry();

#ifdef Q_WS_X11
    #if QT_VERSION >= 0x050000
    // Use a native X11 sizegrip for "real" top-level windows if supported.
    if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE))
        && !(tlw->windowFlags() & Qt::X11BypassWindowManagerHint)
        && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) {
        XEvent xev;
        xev.xclient.type = ClientMessage;
        xev.xclient.message_type = ATOM(_NET_WM_MOVERESIZE);
        xev.xclient.display = X11->display;
        xev.xclient.window = tlw->winId();
        xev.xclient.format = 32;
        xev.xclient.data.l[0] = e->globalPos().x();
        xev.xclient.data.l[1] = e->globalPos().y();
        if (atBottom())
            xev.xclient.data.l[2] = atLeft() ? 6 : 4; // bottomleft/bottomright
        else
            xev.xclient.data.l[2] = atLeft() ? 0 : 2; // topleft/topright
        xev.xclient.data.l[3] = Button1;
        xev.xclient.data.l[4] = 0;
        XUngrabPointer(X11->display, X11->time);
        XSendEvent(X11->display, QX11Info::appRootWindow(x11Info().screen()), False,
                   SubstructureRedirectMask | SubstructureNotifyMask, &xev);
        return;
    }
#endif
#endif // Q_WS_X11
#ifdef Q_WS_WIN
    #if QT_VERSION >= 0x050000
    if (tlw->isWindow() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) {
        uint orientation = 0;
        if (atBottom())
            orientation = atLeft() ? SZ_SIZEBOTTOMLEFT : SZ_SIZEBOTTOMRIGHT;
        else
            orientation = atLeft() ? SZ_SIZETOPLEFT : SZ_SIZETOPRIGHT;

        ReleaseCapture();
        PostMessage(tlw->winId(), WM_SYSCOMMAND, orientation, 0);
        return;
    }
#endif
#endif // Q_WS_WIN

    // Find available desktop/workspace geometry.
    QRect availableGeometry;
    bool hasVerticalSizeConstraint = true;
    bool hasHorizontalSizeConstraint = true;
    if (tlw->isWindow())
        availableGeometry = QApplication::desktop()->availableGeometry(tlw);
    else {
        const QWidget *tlwParent = tlw->parentWidget();
        // Check if tlw is inside QAbstractScrollArea/QScrollArea.
        // If that's the case tlw->parentWidget() will return the viewport
        // and tlw->parentWidget()->parentWidget() will return the scroll area.
#ifndef QT_NO_SCROLLAREA
        QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(tlwParent->parentWidget());
        if (scrollArea) {
            hasHorizontalSizeConstraint = scrollArea->horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff;
            hasVerticalSizeConstraint = scrollArea->verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff;
        }
#endif // QT_NO_SCROLLAREA
        availableGeometry = tlwParent->contentsRect();
    }

    // Find frame geometries, title bar height, and decoration sizes.
    const QRect frameGeometry = tlw->frameGeometry();
    const int titleBarHeight = qMax(tlw->geometry().y() - frameGeometry.y(), 0);
    const int bottomDecoration = qMax(frameGeometry.height() - tlw->height() - titleBarHeight, 0);
    const int leftRightDecoration = qMax((frameGeometry.width() - tlw->width()) / 2, 0);

    // Determine dyMax depending on whether the sizegrip is at the bottom
    // of the widget or not.
    if (atBottom()) {
        if (hasVerticalSizeConstraint)
            dyMax = availableGeometry.bottom() - r.bottom() - bottomDecoration;
        else
            dyMax = INT_MAX;
    } else {
        if (hasVerticalSizeConstraint)
            dyMax = availableGeometry.y() - r.y() + titleBarHeight;
        else
            dyMax = -INT_MAX;
    }

    // In RTL mode, the size grip is to the left; find dxMax from the desktop/workspace
    // geometry, the size grip geometry and the width of the decoration.
    if (atLeft()) {
        if (hasHorizontalSizeConstraint)
            dxMax = availableGeometry.x() - r.x() + leftRightDecoration;
        else
            dxMax = -INT_MAX;
    } else {
        if (hasHorizontalSizeConstraint)
            dxMax = availableGeometry.right() - r.right() - leftRightDecoration;
        else
            dxMax = INT_MAX;
    }
}
Ejemplo n.º 22
0
  void
  TreeCanvas::scaleTree(int scale0, int zoomx, int zoomy) {
    QMutexLocker locker(&layoutMutex);

    QSize viewport_size = size();
    QAbstractScrollArea* sa =
      static_cast<QAbstractScrollArea*>(parentWidget()->parentWidget());

    if (zoomx==-1)
      zoomx = viewport_size.width()/2;
    if (zoomy==-1)
      zoomy = viewport_size.height()/2;

    int xoff = (sa->horizontalScrollBar()->value()+zoomx)/scale;
    int yoff = (sa->verticalScrollBar()->value()+zoomy)/scale;

    BoundingBox bb;
    scale0 = std::min(std::max(scale0, LayoutConfig::minScale),
                      LayoutConfig::maxScale);
    scale = (static_cast<double>(scale0)) / 100.0;
    bb = root->getBoundingBox();
    int w =
      static_cast<int>((bb.right-bb.left+Layout::extent)*scale);
    int h =
      static_cast<int>(2*Layout::extent+
        root->getShape()->depth()*Layout::dist_y*scale);

    sa->horizontalScrollBar()->setRange(0,w-viewport_size.width());
    sa->verticalScrollBar()->setRange(0,h-viewport_size.height());
    sa->horizontalScrollBar()->setPageStep(viewport_size.width());
    sa->verticalScrollBar()->setPageStep(viewport_size.height());
    sa->horizontalScrollBar()->setSingleStep(Layout::extent);
    sa->verticalScrollBar()->setSingleStep(Layout::extent);

    xoff *= scale;
    yoff *= scale;

    sa->horizontalScrollBar()->setValue(xoff-zoomx);
    sa->verticalScrollBar()->setValue(yoff-zoomy);

    emit scaleChanged(scale0);
    QWidget::update();
  }
Ejemplo n.º 23
0
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);
    }
}
Ejemplo n.º 24
0
void ScrollAreaLayout::setGeometry ( const QRect & r )  {
    QAbstractScrollArea* theChild = dynamic_cast<QAbstractScrollArea*>(theItem->widget());

    //qDebug() << "--------------------------------------";
    // qDebug() << "  Layout geometry:" << r;
    //qDebug() << "  Scroll bar width: " << theChild->verticalScrollBar()->width();

    // get the widget which is scrolled by the scrollarea
    //QWidget* wdg = theChild->widget();
   // qDebug() << "Widget sizeHint():" << wdg->objectName() << " - "<< wdg->sizeHint();
    //qDebug() << "Widget size():" << wdg->objectName() << " - "<< wdg->size();

   // int fh = theChild->fontMetrics().height();
    //qDebug() << "Scroll area max size:" << QSize(36 * fh, 24 * fh);

    int wid = theChild->sizeHint().width(); // frame width is considered!
    int h = theChild->sizeHint().height();  // frame height is considered!
    int xpos = 0;
    int ypos = 0;

    if (r.width() < wid && r.height() < h) {

        // both scrollbars required
        wid = r.width();
        h = r.height();

    } else if (r.width() < wid) {
        // only horizontal scroll bar required

        h += theChild->horizontalScrollBar()->sizeHint().height();

        wid = r.width();

        // the new y position is based on the extended height (including scroll bars)
        // this leads to a lesser smoothly transition from no scroll bars to scroll bars,
        // but avoids an asymmetry once the scroll bars are shown.
        ypos = (r.height() - h) / 2;

        if (r.height() < h) { // again both required
            xpos = 0;
            ypos = 0;
            h = r.height();
        }

    } else if (r.height() < h) {
        // only vertical scroll bar required
        wid += theChild->verticalScrollBar()->sizeHint().width();

        h = r.height();

        // the new x position is based on the extended width (including scroll bars)
        // this leads to a lesser smoothly transition from no scroll bars to scroll bars,
        // but avoids an asymmetry once the scroll bars are shown.
        xpos = (r.width() - wid) / 2;

        if (r.width() < wid) {  // again both required
            xpos = 0;
            ypos = 0;
            wid = r.width();
        }
    } else {
        xpos = (r.width() - wid) / 2;
        ypos = (r.height() - h) / 2;
    }

    int frameWidth = 0; // !!!!
    QRect newRect = QRect(xpos, ypos, wid + frameWidth, h + frameWidth);
    //qDebug() << "  Child geometry:" << newRect;

    theChild->setGeometry(newRect);
}
Ejemplo n.º 25
0
void tst_QAbstractScrollArea::scrollBarWidgets()
{
    QWidget *w1 = new QWidget(0);
    QWidget *w2 = new QWidget(0);
    QWidget *w3 = new QWidget(0);

    Qt::Alignment all = Qt::AlignLeft | Qt::AlignRight | Qt::AlignTop | Qt::AlignBottom;

    QWidgetList w1List = QWidgetList() << w1;
    QWidgetList w2List = QWidgetList() << w2;
    QWidgetList w3List = QWidgetList() << w3;

    QWidgetList w1w2List = w1List + w2List;
    QWidgetList allList = w1List + w2List + w3List;

    QAbstractScrollArea area;
    area.show();
    QCOMPARE(area.scrollBarWidgets(all), QWidgetList());

    area.addScrollBarWidget(w1, Qt::AlignLeft);
    QCOMPARE(area.scrollBarWidgets(all), w1List);
    QCOMPARE(area.scrollBarWidgets(Qt::AlignLeft), w1List);
    QCOMPARE(area.scrollBarWidgets(Qt::AlignRight), QWidgetList());
    QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList());
    QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom), QWidgetList());

    area.addScrollBarWidget(w2, Qt::AlignBottom);
    QCOMPARE(area.scrollBarWidgets(all), w1w2List);
    QCOMPARE(area.scrollBarWidgets(Qt::AlignLeft), w1List);
    QCOMPARE(area.scrollBarWidgets(Qt::AlignRight), QWidgetList());
    QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList());
    QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom), w2List);

    // duplicate add
    area.addScrollBarWidget(w2, Qt::AlignBottom);
    QCOMPARE(area.scrollBarWidgets(all), w1w2List);
    QCOMPARE(area.scrollBarWidgets(Qt::AlignLeft), w1List);
    QCOMPARE(area.scrollBarWidgets(Qt::AlignRight), QWidgetList());
    QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList());
    QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom), w2List);

    //reparent
    w2->setParent(w1);
    QCOMPARE(area.scrollBarWidgets(all), w1List);
    QCOMPARE(area.scrollBarWidgets(Qt::AlignLeft), w1List);
    QCOMPARE(area.scrollBarWidgets(Qt::AlignRight), QWidgetList());
    QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList());
    QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom), QWidgetList());

    // add after reparent
    area.addScrollBarWidget(w2, Qt::AlignBottom);
    QCOMPARE(area.scrollBarWidgets(all), w1w2List);
    QCOMPARE(area.scrollBarWidgets(Qt::AlignLeft), w1List);
    QCOMPARE(area.scrollBarWidgets(Qt::AlignRight), QWidgetList());
    QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList());
    QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom), w2List);

    // two widgets at Bottom.
    area.addScrollBarWidget(w3, Qt::AlignBottom);
    QCOMPARE(area.scrollBarWidgets(all).toSet(), allList.toSet());
    QCOMPARE(area.scrollBarWidgets(Qt::AlignLeft), w1List);
    QCOMPARE(area.scrollBarWidgets(Qt::AlignRight), QWidgetList());
    QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList());
    QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom).toSet(), (w2List + w3List).toSet());

    //delete
    delete w1;
    delete w2;
    delete w3;

    QCOMPARE(area.scrollBarWidgets(all), QWidgetList());
    QCOMPARE(area.scrollBarWidgets(Qt::AlignLeft), QWidgetList());
    QCOMPARE(area.scrollBarWidgets(Qt::AlignRight), QWidgetList());
    QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList());
    QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom), QWidgetList());
}
Ejemplo n.º 26
0
void tst_QAbstractScrollArea::setScrollBars2()
{
    QAbstractScrollArea scrollArea;
    scrollArea.resize(300, 300);

    QScrollBar *hbar = new QScrollBar;
    scrollArea.setHorizontalScrollBar(hbar);
    qApp->processEvents();
    QCOMPARE(scrollArea.horizontalScrollBar(), hbar);

    QScrollBar *vbar = new QScrollBar;
    scrollArea.setVerticalScrollBar(vbar);
    qApp->processEvents();
    QCOMPARE(scrollArea.verticalScrollBar(), vbar);

    scrollArea.horizontalScrollBar()->setRange(0, 100);
    scrollArea.verticalScrollBar()->setRange(0, 100);
    scrollArea.show();

    // Make sure scroll bars are not explicitly hidden by QAbstractScrollArea itself.
    QVERIFY(hbar->isVisible());
    QVERIFY(vbar->isVisible());

    // Hide the OLD scroll bar and ensure that the NEW one is hidden.
    hbar->hide();
    scrollArea.setHorizontalScrollBar(new QScrollBar);
    qApp->processEvents();
    QVERIFY(!scrollArea.horizontalScrollBar()->isVisible());

    vbar->hide();
    scrollArea.setVerticalScrollBar(new QScrollBar);
    qApp->processEvents();
    QVERIFY(!scrollArea.verticalScrollBar()->isVisible());

    scrollArea.verticalScrollBar()->show();
    scrollArea.horizontalScrollBar()->show();

    // Hide the NEW scroll bar and ensure that it's visible
    // (because the OLD one is visible).
    hbar = new QScrollBar;
    hbar->hide();
    scrollArea.setHorizontalScrollBar(hbar);
    qApp->processEvents();
    QVERIFY(hbar->isVisible());

    vbar = new QScrollBar;
    vbar->hide();
    scrollArea.setVerticalScrollBar(vbar);
    qApp->processEvents();
    QVERIFY(vbar->isVisible());

    vbar->setRange(0, 0);
    qApp->processEvents();
    QVERIFY(!vbar->isVisible());

    hbar->setRange(0, 0);
    qApp->processEvents();
    QVERIFY(!hbar->isVisible());
}