コード例 #1
0
// public slot virtual [base kpView]
void kpZoomedThumbnailView::adjustToEnvironment ()
{
#if DEBUG_KP_ZOOMED_THUMBNAIL_VIEW
    kdDebug () << "kpZoomedThumbnailView(" << name ()
               << ")::adjustToEnvironment()"
               << " width=" << width ()
               << " height=" << height ()
               << endl;
#endif

    if (!document ())
        return;

#if DEBUG_KP_ZOOMED_THUMBNAIL_VIEW
    kdDebug () << "\tdoc: width=" << document ()->width ()
               << " height=" << document ()->height ()
               << endl;
#endif

    if (document ()->width () <= 0 || document ()->height () <= 0)
    {
        kdError () << "kpZoomedThumbnailView::adjustToEnvironment() doc:"
                   << " width=" << document ()->width ()
                   << " height=" << document ()->height ()
                   << endl;
        return;
    }


    int hzoom = QMAX (1, width () * 100 / document ()->width ());
    int vzoom = QMAX (1, height () * 100 / document ()->height ());

    // keep aspect ratio
    if (hzoom < vzoom)
        vzoom = hzoom;
    else
        hzoom = vzoom;

#if DEBUG_KP_ZOOMED_THUMBNAIL_VIEW && 1
    kdDebug () << "\tproposed zoom=" << hzoom << endl;
#endif
    if (hzoom > 100 || vzoom > 100)
    {
#if DEBUG_KP_ZOOMED_THUMBNAIL_VIEW && 1
        kdDebug () << "\twon't magnify - setting zoom to 100%" << endl;
#endif
        hzoom = 100, vzoom = 100;
    }


    if (viewManager ())
        viewManager ()->setQueueUpdates ();

    {
        setZoomLevel (hzoom, vzoom);

        setOrigin (QPoint ((width () - zoomedDocWidth ()) / 2,
                           (height () - zoomedDocHeight ()) / 2));
        setMaskToCoverDocument ();

        if (viewManager ())
            viewManager ()->updateView (this);
    }

    if (viewManager ())
        viewManager ()->restoreQueueUpdates ();
}
コード例 #2
0
// public slot virtual [base kpView]
void kpUnzoomedThumbnailView::adjustToEnvironment ()
{
    if (!buddyView () || !buddyViewScrollableContainer () || !document ())
        return;

    const int scrollViewContentsX =
        buddyViewScrollableContainer()->horizontalScrollBar()->value();
    const int scrollViewContentsY =
        buddyViewScrollableContainer ()->verticalScrollBar()->value();

#if DEBUG_KP_UNZOOMED_THUMBNAIL_VIEW
    qCDebug(kpLogViews) << "kpUnzoomedThumbnailView(" << name ()
               << ")::adjustToEnvironment("
               << scrollViewContentsX
               << ","
               << scrollViewContentsY
               << ") width=" << width ()
               << " height=" << height ()
               << endl;
#endif


#if 1
    int x;
    if (document ()->width () > width ())
    {
        x = (int) buddyView ()->transformViewToDocX (scrollViewContentsX);
        const int rightMostAllowedX = qMax (0, document ()->width () - width ());
    #if DEBUG_KP_UNZOOMED_THUMBNAIL_VIEW
        qCDebug(kpLogViews) << "\tdocX=" << x
                << " docWidth=" << document ()->width ()
                << " rightMostAllowedX=" << rightMostAllowedX
                << endl;
    #endif
        if (x > rightMostAllowedX)
            x = rightMostAllowedX;
    }
    // Thumbnail width <= doc width
    else
    {
        // Center X (rather than flush left to be consistent with
        //           kpZoomedThumbnailView)
        x = -(width () - document ()->width ()) / 2;
    }


    int y;
    if (document ()->height () > height ())
    {
        y = (int) buddyView ()->transformViewToDocY (scrollViewContentsY);
        const int bottomMostAllowedY = qMax (0, document ()->height () - height ());
    #if DEBUG_KP_UNZOOMED_THUMBNAIL_VIEW
        qCDebug(kpLogViews) << "\tdocY=" << y
                    << " docHeight=" << document ()->height ()
                    << " bottomMostAllowedY=" << bottomMostAllowedY
                    << endl;
    #endif
        if (y > bottomMostAllowedY)
            y = bottomMostAllowedY;
    }
    // Thumbnail height <= doc height
    else
    {
        // Center Y (rather than flush top to be consistent with
        //           kpZoomedThumbnailView)
        y = -(height () - document ()->height ()) / 2;
    }
// Prefer to keep visible area centred in thumbnail instead of flushed left.
// Gives more editing context to the left and top.
// But feels awkward for left-to-right users.  So disabled for now.
// Not totally tested.
#else
    if (!buddyViewScrollableContainer ())
        return;

    QRect docRect = buddyView ()->transformViewToDoc (
        QRect (buddyViewScrollableContainer ()->horizontalScrollBar()->value(),
               buddyViewScrollableContainer ()->verticalScrollBar()->value(),
               qMin (buddyView ()->width (), buddyViewScrollableContainer ()->viewport()->width ()),
               qMin (buddyView ()->height (), buddyViewScrollableContainer ()->viewport()->height ())));

    x = docRect.x () - (width () - docRect.width ()) / 2;
    qCDebug(kpLogViews) << "\tnew suggest x=" << x;
    const int rightMostAllowedX = qMax (0, document ()->width () - width ());
    if (x < 0)
        x = 0;
    if (x > rightMostAllowedX)
        x = rightMostAllowedX;

    y = docRect.y () - (height () - docRect.height ()) / 2;
    qCDebug(kpLogViews) << "\tnew suggest y=" << y;
    const int bottomMostAllowedY = qMax (0, document ()->height () - height ());
    if (y < 0)
        y = 0;
    if (y > bottomMostAllowedY)
        y = bottomMostAllowedY;
#endif


    if (viewManager ())
    {
        viewManager ()->setFastUpdates ();
        viewManager ()->setQueueUpdates ();
    }

    {
        // OPT: scrollView impl would be much, much faster
        setOrigin (QPoint (-x, -y));
        setMaskToCoverDocument ();

        // Above might be a NOP even if e.g. doc size changed so force
        // update
        if (viewManager ())
            viewManager ()->updateView (this);
    }

    if (viewManager ())
    {
        viewManager ()->restoreQueueUpdates ();
        viewManager ()->restoreFastUpdates ();
    }
}