void CardView::drawRubberBands( int pos ) { if (!d->mSpan || ((pos - d->mFirstX) / d->mSpan) - d->mColspace - d->mSepWidth < MIN_ITEM_WIDTH) return; int tmpcw = (d->mRubberBandAnchor - d->mFirstX) / d->mSpan; int x = d->mFirstX + tmpcw - d->mSepWidth - contentsX(); int h = visibleHeight(); QPainter p( viewport() ); // FIXME porting //p.setRasterOp( XorROP ); p.setPen( Qt::gray ); p.setBrush( Qt::gray ); uint n = d->mFirst; // erase if ( d->mRubberBandAnchor ) do { p.drawRect( x, 0, 2, h ); x += tmpcw; n++; } while ( x < visibleWidth() && n < d->mSeparatorList.count() ); // paint new if ( ! pos ) return; tmpcw = (pos - d->mFirstX) / d->mSpan; n = d->mFirst; x = d->mFirstX + tmpcw - d->mSepWidth - contentsX(); do { p.drawRect( x, 0, 2, h ); x += tmpcw; n++; } while ( x < visibleWidth() && n < d->mSeparatorList.count() ); d->mRubberBandAnchor = pos; }
void DrawZone::setZoom(double z) { _zoom=z; imageRect.setHeight(myround(image.height()*_zoom)); imageRect.setWidth(myround(image.width()*_zoom)); zoomedImage=QPixmap(imageRect.width(),imageRect.height()); QPainter p(&zoomedImage); p.scale(z,z); QPixmap pix; pix.convertFromImage(image); // if the picture has transparent areas, // fill them with Gimp like background if (pix.mask()) { QPixmap backPix(32,32); QPainter p2(&backPix); p2.fillRect(0,0,32,32,QColor(156,149,156)); p2.fillRect(0,16,16,16,QColor(98,105,98)); p2.fillRect(16,0,16,16,QColor(98,105,98)); p2.flush(); p.setPen(QPen()); p.fillRect(imageRect.left(),imageRect.top(),imageRect.width(),imageRect.height(),QBrush(QColor("black"),backPix)); } p.drawPixmap(imageRect.left(),imageRect.top(),pix); p.flush(); resizeContents(visibleWidth()>imageRect.width() ? visibleWidth() : imageRect.width(), visibleHeight()>imageRect.height() ? visibleHeight() : imageRect.height()); repaintContents(0,0,contentsWidth(),contentsHeight(),true); }
void MarkList::viewportResizeEvent ( QResizeEvent * ) { MarkListItem *_item; if( visibleWidth() != columnWidth( 0 ) ) { setColumnWidth( 0, visibleWidth() ); for( int i = 0; i < numRows(); ++i ) { _item = dynamic_cast<MarkListItem *>( cellWidget( i, 0 ) ); assert( _item ); _item->setFixedSize( visibleWidth(), _item->height() ); } } }
void RosegardenScrollView::updateScrollBars() { horizontalScrollBar()->setPageStep(visibleWidth()); // horizontalScrollBar()->setLineStep(visibleWidth() / 10); horizontalScrollBar()->setMaximum( std::max(contentsWidth()-visibleWidth(),0)); verticalScrollBar()->setPageStep(visibleHeight()); // verticalScrollBar()->setLineStep(visibleHeight() / 10); verticalScrollBar()->setMaximum( std::max(contentsHeight()-visibleHeight(),0)); // RG_DEBUG << "RosegardenScrollView::updateScrollBars :" << // " pagewidth - " << visibleWidth() << // " pageheight - " << visibleHeight(); }
/****************************************************************************** * Sets the last column in the list view to extend at least to the right hand * edge of the list view. */ void EventListViewBase::resizeLastColumn() { int lastColumnWidth = mLastColumnHeaderWidth; for (EventListViewItemBase* item = firstChild(); item; item = item->nextSibling()) { int mw = item->lastColumnWidth(); if (mw > lastColumnWidth) lastColumnWidth = mw; } QHeader* head = header(); int x = head->sectionPos(mLastColumn); int availableWidth = visibleWidth() - x; int rightColWidth = 0; int index = head->mapToIndex(mLastColumn); if (index < mLastColumn) { // The last column has been dragged by the user to a different position. // Ensure that the columns now to the right of it are still shown. for (int i = index + 1; i <= mLastColumn; ++i) rightColWidth += columnWidth(head->mapToSection(i)); availableWidth -= rightColWidth; } if (availableWidth < lastColumnWidth) availableWidth = lastColumnWidth; setColumnWidth(mLastColumn, availableWidth); if (contentsWidth() > x + availableWidth + rightColWidth) resizeContents(x + availableWidth + rightColWidth, contentsHeight()); }
void DrawZone::resizeEvent(QResizeEvent* e) { QScrollView::resizeEvent(e); int width=(int) (image.width()*_zoom); int height=(int) (image.height()*_zoom); if (visibleWidth()>width) width=visibleWidth(); if (visibleHeight()>height) height=visibleHeight(); resizeContents(width,height); imageRect.setLeft(0); imageRect.setTop(0); imageRect.setHeight((int)(image.height()*_zoom)); imageRect.setWidth((int)(image.width()*_zoom)); }
int ScrollableArea::pageStep(ScrollbarOrientation orientation) const { int length = (orientation == HorizontalScrollbar) ? visibleWidth() : visibleHeight(); int minPageStep = static_cast<float>(length) * minFractionToStepWhenPaging(); int pageStep = std::max(minPageStep, length - maxOverlapBetweenPages()); return std::max(pageStep, 1); }
void UIPageText::updateContents() { int ch = contentsHeight(); int vw = visibleWidth(); ensureVisible( 0, ch, 0, 0 ); repaintContents( 0, ch - 40, vw, 40, true ); }
void RosegardenScrollView::resizeContents(int w, int h) // Code lifted from Q3ScrollView { int ow = m_vwidth; int oh = m_vheight; m_vwidth = w; m_vheight = h; // d->scrollbar_timer.start(0, true); // This was necessary until I fixed the resizeEvent connection //### CJ - Don't think this is necessary - slightly confused as we're resizing the content, not the widget // if (d->children.isEmpty() && d->policy == Default) // setResizePolicy(Manual); if (ow > w) { // Swap int t=w; w=ow; ow=t; } // Refresh area ow..w if (ow < visibleWidth() && w >= 0) { if (ow < 0) ow = 0; if (w > visibleWidth()) w = visibleWidth(); this->viewport()->update(contentsX()+ow, 0, w-ow, visibleHeight()); } if (oh > h) { // Swap int t=h; h=oh; oh=t; } // Refresh area oh..h if (oh < visibleHeight() && h >= 0) { if (oh < 0) oh = 0; if (h > visibleHeight()) h = visibleHeight(); this->viewport()->update(0, contentsY()+oh, visibleWidth(), h-oh); } }
bool ScrollView::platformHandleHorizontalAdjustment(const IntSize& scroll) { if (m_horizontalAdjustment) { m_horizontalAdjustment->page_size = visibleWidth(); m_horizontalAdjustment->step_increment = cScrollbarPixelsPerLineStep; m_horizontalAdjustment->page_increment = visibleWidth() - cAmountToKeepWhenPaging; m_horizontalAdjustment->lower = 0; m_horizontalAdjustment->upper = contentsWidth(); gtk_adjustment_changed(m_horizontalAdjustment); if (m_horizontalAdjustment->value != scroll.width()) { m_horizontalAdjustment->value = scroll.width(); gtk_adjustment_value_changed(m_horizontalAdjustment); } return true; } return false; }
bool ScrollView::platformHandleHorizontalAdjustment(const IntSize& scroll) { if (m_horizontalAdjustment) { m_horizontalAdjustment->page_size = visibleWidth(); m_horizontalAdjustment->step_increment = visibleWidth() / 10.0; m_horizontalAdjustment->page_increment = visibleWidth() * 0.9; m_horizontalAdjustment->lower = 0; m_horizontalAdjustment->upper = contentsWidth(); gtk_adjustment_changed(m_horizontalAdjustment); if (m_scrollOffset.width() != scroll.width()) { m_horizontalAdjustment->value = scroll.width(); gtk_adjustment_value_changed(m_horizontalAdjustment); } return true; } return false; }
PlayListWidget::PlayListWidget(QWidget* parent) : QTreeWidget(parent){ // qDebug() << this << "constructor()"; setRootIsDecorated(false); setSortingEnabled(false); setAcceptDrops(true); setDragEnabled(true); setItemsExpandable(false); setTabKeyNavigation(false); setSelectionMode(QAbstractItemView::ExtendedSelection); setAlternatingRowColors(true); setAllColumnsShowFocus(true); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); header()->setContextMenuPolicy(Qt::CustomContextMenu); connect( header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(headerContextMenu(const QPoint&)) ); QStringList headerLabels; headerLabels << "*" << "Artist" << "Album" << "Title" << "Date" << "Genre"<< "Track No." << "Length"; setHeaderLabels(headerLabels); tabs=(PlayListTabs*) parentWidget(); dropPointer=new DropPointer(this); dropPointer->hide(); dropPointer->setWidth(visibleWidth()); dropPointer->moveTo(0); refreshConfig(); connectConfigUpdate(); connect( this, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(doubleClicked(QTreeWidgetItem*,int)) ); connect( this, SIGNAL(playItem(PlayListItem*)), tabs, SLOT(playItem(PlayListItem*)) ); connect( this, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(deselect(QTreeWidgetItem*,int)) ); connect( verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(printPos(int)) ); firstShow=true; scrollPosition=0; }
void PlayListWidget::refreshConfig(){ // qDebug() << this << "refreshConfig()"; disconnectConfigUpdate(); for(int i=0; i<columnCount(); ++i){ setColumnHidden(i,!tabs->columnsVisibility[i]); setColumnWidth(i, (int)((double)visibleWidth() * tabs->columnsWidth[i])); header()->moveSection(header()->visualIndex(i), tabs->columnsPosition[i]); } connectConfigUpdate(); }
void RosegardenScrollView::updateContents(int x, int y, int w, int h) // Code lifted from Q3ScrollView { if (!isVisible() || !updatesEnabled()) return; // RG_DEBUG << "RosegardenScrollView::updateContents" << endl; QWidget* vp = viewport(); // Translate x -= contentsX(); y -= contentsY(); if (x < 0) { w += x; x = 0; } if (y < 0) { h += y; y = 0; } if (w < 0 || h < 0) return; if (x > visibleWidth() || y > visibleHeight()) return; if (w > visibleWidth()) w = visibleWidth(); if (h > visibleHeight()) h = visibleHeight(); //### CJ - I don't think we used a clipped_viewport on Q3ScrollView //if (d->clipped_viewport) { //// Translate clipper() to viewport() //x -= d->clipped_viewport->x(); //y -= d->clipped_viewport->y(); //} vp->update(x, y, w, h); updateScrollBars(); }
void K3bListView::placeEditor( K3bListViewItem* item, int col ) { ensureItemVisible( item ); QRect r = itemRect( item ); r.setX( contentsToViewport( QPoint(header()->sectionPos( col ), 0) ).x() ); r.setWidth( header()->sectionSize( col ) - 1 ); // check if the column is fully visible if( visibleWidth() < r.right() ) r.setRight(visibleWidth()); r = QRect( viewportToContents( r.topLeft() ), r.size() ); if( item->pixmap( col ) ) { r.setX( r.x() + item->pixmap(col)->width() ); } // the tree-stuff is painted in the first column if( col == 0 ) { r.setX( r.x() + item->depth() * treeStepSize() ); if( rootIsDecorated() ) r.setX( r.x() + treeStepSize() ); } if( item->needButton(col) ) { prepareButton( item, col ); m_editorButton->setFixedHeight( r.height() ); // for now we make a square button m_editorButton->setFixedWidth( m_editorButton->height() ); r.setWidth( r.width() - m_editorButton->width() ); moveChild( m_editorButton, r.right(), r.y() ); } if( QWidget* editor = prepareEditor( item, col ) ) { editor->resize( r.size() ); // editor->resize( QSize( r.width(), editor->minimumSizeHint().height() ) ); moveChild( editor, r.x(), r.y() ); } }
void PageView::calculateCurrentPageNumber(int x, int y) { // Safety check if (widgetList == 0) return; QRect viewportRect(x, y, visibleWidth(), visibleHeight()); //kdDebug() << "viewportRect(" << viewportRect.x() << ", " << viewportRect.y() << ", " // << viewportRect.width() << ", " << viewportRect.height() << ")" << endl; int maxVisiblePixels = 0; DocumentWidget* _currentWidget = 0; for (Q_UINT16 i = 0; i < widgetList->size(); i++) { DocumentWidget* documentWidget = widgetList->at(i); // Safety check if (documentWidget == 0) continue; // Check if the Widget is visible int cx = childX(documentWidget); int cy = childY(documentWidget); QRect widgetRect(cx, cy, documentWidget->width(), documentWidget->height()); bool isVisible = widgetRect.intersects(viewportRect); if (!isVisible) continue; // Calculate the number of visible pixels of the widget QRect visibleRect = widgetRect.intersect(viewportRect); int visiblePixels = visibleRect.width() * visibleRect.height(); //kdDebug() << visiblePixels << " pixels are visible of page " << documentWidget->getPageNumber() << endl; // If a bigger part of this widget as of the previous widgets is visible make it the current widget. if (maxVisiblePixels < visiblePixels) { maxVisiblePixels = visiblePixels; _currentWidget = documentWidget; } } // No page is visible if (_currentWidget == 0) return; // Return the number of the current page emit currentPageChanged(_currentWidget->getPageNumber()); }
int Q3ScrollView::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = Q3Frame::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 23) qt_static_metacall(this, _c, _id, _a); _id -= 23; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< ResizePolicy*>(_v) = resizePolicy(); break; case 1: *reinterpret_cast< ScrollBarMode*>(_v) = vScrollBarMode(); break; case 2: *reinterpret_cast< ScrollBarMode*>(_v) = hScrollBarMode(); break; case 3: *reinterpret_cast< int*>(_v) = visibleWidth(); break; case 4: *reinterpret_cast< int*>(_v) = visibleHeight(); break; case 5: *reinterpret_cast< int*>(_v) = contentsWidth(); break; case 6: *reinterpret_cast< int*>(_v) = contentsHeight(); break; case 7: *reinterpret_cast< int*>(_v) = contentsX(); break; case 8: *reinterpret_cast< int*>(_v) = contentsY(); break; case 9: *reinterpret_cast< bool*>(_v) = dragAutoScroll(); break; } _id -= 10; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setResizePolicy(*reinterpret_cast< ResizePolicy*>(_v)); break; case 1: setVScrollBarMode(*reinterpret_cast< ScrollBarMode*>(_v)); break; case 2: setHScrollBarMode(*reinterpret_cast< ScrollBarMode*>(_v)); break; case 9: setDragAutoScroll(*reinterpret_cast< bool*>(_v)); break; } _id -= 10; } else if (_c == QMetaObject::ResetProperty) { _id -= 10; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 10; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 10; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 10; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 10; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 10; } #endif // QT_NO_PROPERTIES return _id; }
void RosegardenScrollView::slotScrollHorizSmallSteps(int hpos) { QScrollBar* hbar = getMainHorizontalScrollBar(); int currentContentYPos = contentsY(); int diff = 0; if (hpos == 0) { // returning to zero // hbar->setValue(0); setContentsPos(0, currentContentYPos); } else if ((diff = int(hpos - (contentsX() + visibleWidth() * 0.90))) > 0) { // moving off the right hand side of the view int delta = diff / 6; int diff10 = std::min(diff, (int)m_minDeltaScroll); delta = std::max(delta, diff10); // hbar->setValue(hbar->value() + delta); setContentsPos(hbar->value() + delta, currentContentYPos); } else if ((diff = int(hpos - (contentsX() + visibleWidth() * 0.10))) < 0) { // moving off the left int delta = -diff / 6; int diff10 = std::min( -diff, (int)m_minDeltaScroll); delta = std::max(delta, diff10); // hbar->setValue(hbar->value() - delta); setContentsPos(hbar->value() - delta, currentContentYPos); } }
void LightTablePreview::setDragAndDropMessage() { if (d->dragAndDropEnabled) { QPixmap pix(visibleWidth(), visibleHeight()); pix.fill(ThemeEngine::instance()->baseColor()); QPainter p(&pix); p.setPen(QPen(ThemeEngine::instance()->textRegColor())); p.drawText(0, 0, pix.width(), pix.height(), Qt::AlignCenter|Qt::TextWordWrap, i18n("Drag and drop an image here")); p.end(); setImage(DImg(pix.toImage())); } }
IntRect ScrollableArea::visibleContentRectInternal(VisibleContentRectIncludesScrollbars scrollbarInclusion, VisibleContentRectBehavior) const { int verticalScrollbarWidth = 0; int horizontalScrollbarHeight = 0; if (scrollbarInclusion == IncludeScrollbars) { if (Scrollbar* verticalBar = verticalScrollbar()) verticalScrollbarWidth = verticalBar->occupiedWidth(); if (Scrollbar* horizontalBar = horizontalScrollbar()) horizontalScrollbarHeight = horizontalBar->occupiedHeight(); } return IntRect(scrollPosition().x(), scrollPosition().y(), std::max(0, visibleWidth() + verticalScrollbarWidth), std::max(0, visibleHeight() + horizontalScrollbarHeight)); }
void ThumbnailList::updateWidgets() { // find all widgets that intersects the viewport and update them QRect viewportRect( contentsX(), contentsY(), visibleWidth(), visibleHeight() ); QValueList<ThumbnailWidget *>::iterator vIt = m_visibleThumbnails.begin(), vEnd = m_visibleThumbnails.end(); for ( ; vIt != vEnd; ++vIt ) { ThumbnailWidget * t = *vIt; QRect widgetRect( childX( t ), childY( t ), t->width(), t->height() ); // update only the exposed area of the widget (saves pixels..) QRect relativeRect = viewportRect.intersect( widgetRect ); if ( !relativeRect.isValid() ) continue; relativeRect.moveBy( -widgetRect.left(), -widgetRect.top() ); t->update( relativeRect ); } }
IntRect ScrollableArea::visibleContentRect(bool includeScrollbars) const { int verticalScrollbarWidth = 0; int horizontalScrollbarHeight = 0; if (includeScrollbars) { if (Scrollbar* verticalBar = verticalScrollbar()) verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? verticalBar->width() : 0; if (Scrollbar* horizontalBar = horizontalScrollbar()) horizontalScrollbarHeight = !horizontalBar->isOverlayScrollbar() ? horizontalBar->height() : 0; } return IntRect(scrollPosition().x(), scrollPosition().y(), std::max(0, visibleWidth() + verticalScrollbarWidth), std::max(0, visibleHeight() + horizontalScrollbarHeight)); }
void RosegardenScrollView::slotScrollHoriz(int hpos) { QScrollBar* hbar = getMainHorizontalScrollBar(); int currentContentYPos = contentsY(); /* Lots of performance hitting debug RG_DEBUG << "RosegardenScrollView::slotScrollHoriz: hpos is " << hpos << ", contentsX is " << contentsX() << ", visibleWidth is " << visibleWidth() << endl; */ if (hpos == 0) { // returning to zero // hbar->setValue(0); setContentsPos(0, currentContentYPos); //@@@ // possible replacement: ?? //this->widget()->move( 0, currentContentYPos ) } else if (hpos > (contentsX() + visibleWidth() * 1.6) || hpos < (contentsX() - visibleWidth() * 0.7)) { // miles off one side or the other // hbar->setValue(hpos - int(visibleWidth() * 0.4)); setContentsPos(hpos - int(visibleWidth() * 0.4), currentContentYPos); } else if (hpos > (contentsX() + visibleWidth() * 0.9)) { // moving off the right hand side of the view // hbar->setValue(hbar->value() + int(visibleWidth() * 0.6)); setContentsPos(hbar->value() + int(visibleWidth() * 0.6), currentContentYPos); } else if (hpos < (contentsX() + visibleWidth() * 0.1)) { // moving off the left // hbar->setValue(hbar->value() - int(visibleWidth() * 0.6)); setContentsPos(hbar->value() - int(visibleWidth() * 0.6), currentContentYPos); } }
void UIListView::triggerUpdate() { int vis = visibleWidth(); int num = columns(); // // grab all the max width columns // for ( int col = 0; col < columns(); col++ ) { if (( columnWidth( col ) == 0 ) || ( columnWidthMode( col ) == Maximum )) { vis -= columnWidth( col ); num -= 1; } } // // split all the other columns into equal sized bites // if ( num == 0 ) return ; int avg = vis / num; for ( int col = 0; col < num; col++ ) { if ( columnWidthMode( col ) == Maximum ) continue; if ( columnWidth( col ) == 0 ) continue; setColumnWidth( col, avg ); } // reimpl QListView::triggerUpdate(); }
void SchemaEditor::zoom(float factor) { _zoom+=factor; if (_zoom < 0.2f) _zoom = 0.2f; int oldcenterx = visibleWidth()/2; int oldcentery = visibleHeight()/2; int x, y; viewportToContents(oldcenterx, oldcentery, x, y); inverseWorldMatrix().map(x, y, &x, &y); QMatrix wm; wm.scale(_zoom, _zoom); setWorldMatrix(wm); //worldMatrix().map(x, y, &x, &y); //setContentsPos(x-oldcenterx, y-oldcentery); }
void KfindWindow::resetColumns(bool init) { QFontMetrics fm = fontMetrics(); if(init) { setColumnWidth(2, QMAX(fm.width(columnText(2)), fm.width("0000000")) + 15); QString sampleDate = KGlobal::locale()->formatDateTime(QDateTime::currentDateTime()); setColumnWidth(3, QMAX(fm.width(columnText(3)), fm.width(sampleDate)) + 15); setColumnWidth(4, QMAX(fm.width(columnText(4)), fm.width(i18n(perm[RO]))) + 15); setColumnWidth(5, QMAX(fm.width(columnText(5)), fm.width("some text")) + 15); } int free_space = visibleWidth() - columnWidth(2) - columnWidth(3) - columnWidth(4) - columnWidth(5); // int name_w = QMIN((int)(free_space*0.5), 150); // int dir_w = free_space - name_w; int name_w = QMAX((int)(free_space * 0.5), fm.width("some long filename")); int dir_w = name_w; setColumnWidth(0, name_w); setColumnWidth(1, dir_w); }
/*! Scrolls the browser so that the part of the document named \a name is at the top of the view (or as close to the top as the size of the document allows). */ void QTextBrowser::scrollToAnchor(const QString& name) { if ( name.isEmpty() ) return; d->curmark = name; QRichTextIterator it( richText() ); do { if ( it.format()->anchorName() == name ) { QTextParagraph* b = it.outmostParagraph(); if ( b->dirty ) { // QTextView layouts delayed in the background, so this may happen QRichTextFormatter tc( richText() ); tc.gotoParagraph( 0, &richText() ); tc.updateLayout(); resizeContents( QMAX( richText().flow()->widthUsed-1, visibleWidth() ), richText().flow()->height ); } QRect r = it.lineGeometry(); setContentsPos( contentsX(), r.top() ); return; } } while ( it.right( FALSE ) ); }
IntPoint ScrollableArea::maximumScrollPosition() const { return IntPoint(contentsSize().width() - visibleWidth(), contentsSize().height() - visibleHeight()); }
void PageView::layoutPages(bool zoomChanged) { // Paranoid safety check if (widgetList == 0) return; // If there are no widgets, e.g. because the last widget has been // removed, the matter is easy: set the contents size to 0. If there // are no widgets because previously existing widgets were removed // (we detect that by looking at the contentsWidth and -Height). if (widgetList->isEmpty()) { if ((contentsWidth() != 0) || (contentsHeight() != 0)) { QScrollView::resizeContents(0,0); } return; } // Ok, now we are in a situation where we do have some widgets that // shall be centered. int distance = distanceBetweenWidgets; if (singlePageFullScreenMode()) { // In single page fullscreen mode we don't want a margin around the pages distance = 0; } QMemArray<Q_UINT32> colWidth(nrCols); for(Q_UINT8 i=0; i<colWidth.size(); i++) colWidth[i] = 0; Q_UINT16 numRows; if(nrCols <= 2) { numRows = (widgetList->size()+2*nrCols-2) / nrCols; } else { numRows = (Q_INT16)ceil(((double)widgetList->size()) / nrCols); } QMemArray<Q_UINT32> rowHeight(numRows); for(Q_UINT16 i=0; i<rowHeight.size(); i++) rowHeight[i] = 0; // Now find the widths and heights of the columns for(Q_UINT16 i=0; i<widgetList->size(); i++) { Q_UINT8 col; Q_UINT16 row; if (nrCols == 2) { // In two-column display, start with the right column col = (i+1+nrCols) % nrCols; row = (i+1+nrCols) / nrCols - 1; } else { col = (i+nrCols) % nrCols; row = (i+nrCols) / nrCols - 1; } colWidth[col] = QMAX(colWidth[col], (Q_UINT32)widgetList->at(i)->pageSize().width()); rowHeight[row] = QMAX(rowHeight[row], (Q_UINT32)widgetList->at(i)->pageSize().height()); } // Calculate the total width and height of the display Q_UINT32 totalHeight = 0; for(Q_UINT16 i=0; i<rowHeight.size(); i++) totalHeight += rowHeight[i]; totalHeight += (numRows+1)*distance; Q_UINT32 totalWidth = 0; for(Q_UINT8 i=0; i<colWidth.size(); i++) totalWidth += colWidth[i]; totalWidth += (nrCols+1)*distance; QSize newViewportSize = viewportSize( totalWidth, totalHeight ); Q_UINT32 centeringLeft = 0; if( (Q_UINT32)newViewportSize.width() > totalWidth ) centeringLeft = ( newViewportSize.width() - totalWidth )/2; Q_UINT32 centeringTop = 0; if( (Q_UINT32)newViewportSize.height() > totalHeight ) centeringTop = ( newViewportSize.height() - totalHeight)/2; // Resize the viewport if (((Q_UINT32)contentsWidth() != totalWidth) || ((Q_UINT32)contentsHeight() != totalHeight)) { // Calculate the point in the coordinates of the contents which is currently at the center of the viewport. QPoint midPoint = QPoint(visibleWidth() / 2 + contentsX(), visibleHeight() / 2 + contentsY()); double midPointRatioX = (double)(midPoint.x()) / contentsWidth(); double midPointRatioY = (double)(midPoint.y()) / contentsHeight(); resizeContents(totalWidth,totalHeight); // If the zoom changed recenter the former midPoint if (zoomChanged) center((int)(contentsWidth() * midPointRatioX), (int)(contentsHeight() * midPointRatioY)); } // Finally, calculate the left and top coordinates of each row and // column, respectively QMemArray<Q_UINT32> colLeft(nrCols); colLeft[0] = distance; for(Q_UINT8 i=1; i<colLeft.size(); i++) colLeft[i] = colLeft[i-1]+colWidth[i-1]+distance; QMemArray<Q_UINT32> rowTop(numRows); rowTop[0] = distance; for(Q_UINT16 i=1; i<rowTop.size(); i++) rowTop[i] = rowTop[i-1]+rowHeight[i-1]+distance; for(Q_UINT16 i=0; i<widgetList->size(); i++) { Q_UINT8 col; Q_UINT16 row; if (nrCols == 2) { // In two column-mode start with the right column. col = (i+nrCols-1) % nrCols; row = (i+nrCols-1) / nrCols; } else { col = (i+nrCols) % nrCols; row = i / nrCols; } if (nrCols == 2) { // in 2-column mode right justify the first column, and leftjustify the second column int width = widgetList->at(i)->width(); int left; if (col == 0) left = centeringLeft + colLeft[col] + colWidth[col]-width + distance/2; else left = centeringLeft + colLeft[col]; moveChild( widgetList->at(i), left, centeringTop+rowTop[row]); } else { // in single column and overview mode center the widgets int widgetWidth = widgetList->at(i)->width(); int left = centeringLeft + colLeft[col] + ((int)colWidth[col]-widgetWidth)/2; moveChild(widgetList->at(i), left, centeringTop+rowTop[row]); } } calculateCurrentPageNumber(); }
IntPoint maximumScrollPosition() const override { return IntPoint(contentsSize().width() - visibleWidth(), contentsSize().height() - visibleHeight()); }