void RenderMathMLFraction::layoutBlock(bool relayoutChildren, LayoutUnit) { ASSERT(needsLayout()); if (!relayoutChildren && simplifiedLayout()) return; if (!isValid()) { setLogicalWidth(0); setLogicalHeight(0); clearNeedsLayout(); return; } numerator().layoutIfNeeded(); denominator().layoutIfNeeded(); setLogicalWidth(std::max(numerator().logicalWidth(), denominator().logicalWidth())); updateLineThickness(); LayoutUnit verticalOffset = 0; // This is the top of the renderer. LayoutPoint numeratorLocation(horizontalOffset(numerator(), element().numeratorAlignment()), verticalOffset); numerator().setLocation(numeratorLocation); LayoutUnit numeratorAscent = ascentForChild(numerator()); LayoutUnit numeratorDescent = numerator().logicalHeight() - numeratorAscent; LayoutUnit denominatorAscent = ascentForChild(denominator()); LayoutUnit denominatorDescent = denominator().logicalHeight() - denominatorAscent; if (isStack()) { LayoutUnit gapMin, topShiftUp, bottomShiftDown; getStackParameters(gapMin, topShiftUp, bottomShiftDown); LayoutUnit gap = topShiftUp - numeratorDescent + bottomShiftDown - denominatorAscent; if (gap < gapMin) { // If the gap is not large enough, we increase the shifts by the same value. LayoutUnit delta = (gapMin - gap) / 2; topShiftUp += delta; bottomShiftDown += delta; } verticalOffset += numeratorAscent + topShiftUp; // This is the middle of the stack gap. m_ascent = verticalOffset + mathAxisHeight(); verticalOffset += bottomShiftDown - denominatorAscent; } else { LayoutUnit numeratorGapMin, denominatorGapMin, numeratorMinShiftUp, denominatorMinShiftDown; getFractionParameters(numeratorGapMin, denominatorGapMin, numeratorMinShiftUp, denominatorMinShiftDown); verticalOffset += std::max(numerator().logicalHeight() + numeratorGapMin + m_lineThickness / 2, numeratorAscent + numeratorMinShiftUp); // This is the middle of the fraction bar. m_ascent = verticalOffset + mathAxisHeight(); verticalOffset += std::max(m_lineThickness / 2 + denominatorGapMin, denominatorMinShiftDown - denominatorAscent); } LayoutPoint denominatorLocation(horizontalOffset(denominator(), element().denominatorAlignment()), verticalOffset); denominator().setLocation(denominatorLocation); verticalOffset = std::max(verticalOffset + denominator().logicalHeight(), m_ascent + denominatorDescent); // This is the bottom of our renderer. setLogicalHeight(verticalOffset); clearNeedsLayout(); }
void GroupedIconView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command) { QVector<QModelIndex> indexes(IntersectingItems(rect.translated(horizontalOffset(), verticalOffset()))); QItemSelection selection; foreach (const QModelIndex& index, indexes) { selection << QItemSelectionRange(index); }
void cCustomShotTable::mouseMoveEvent(QMouseEvent *event) { if (IsDragOn!=1) { setCursor(Qt::ArrowCursor); QTableWidget::mouseMoveEvent(event); } else { if ((columnCount()==0)||(DiaporamaObject==NULL)) return; int ThumbHeight=rowHeight(0); int ThumbWidth =columnWidth(0); int NbrX =width()/ThumbWidth; int NbrY =height()/ThumbHeight; if (NbrY>rowCount()) NbrY=rowCount(); int ToUse =DragItemDest; if (DragItemDest==columnCount()) ToUse--; // Try to scroll left if ((event->pos().x()<0)&&(horizontalScrollBar()->value()>0)) horizontalScrollBar()->setValue(horizontalScrollBar()->value()-1); // Try to scroll right else if ((event->pos().x()>=NbrX*ThumbWidth)&&(horizontalScrollBar()->value()<horizontalScrollBar()->maximum())) horizontalScrollBar()->setValue(horizontalScrollBar()->value()+1); else { // Get item number under mouse int Selected=(event->pos().x()+horizontalOffset())/ThumbWidth; if ((Selected>NbrItem())||(Selected==DragItemSource)||((Selected==DragItemSource+1)&&(Selected!=NbrItem()))) { DragItemDest=-1; setCursor(Qt::ForbiddenCursor); } else { setCursor(Qt::ClosedHandCursor); DragItemDest=Selected; } } // Force a repaint setUpdatesEnabled(false); setUpdatesEnabled(true); } }
QRect AMScanThumbnailGridView::visualRect(const QModelIndex &index) const { QRect rowContentRect; if(index.parent().isValid()) { // is a thumbnail rowContentRect = geometryManager_->contentGeometryAt(index.parent().row(), horizontalOffset(), verticalOffset()); } else { rowContentRect = geometryManager_->contentGeometryAt(index.row(), horizontalOffset(), verticalOffset()); } if(!index.parent().isValid()) { // Is Scan switch(index.column()) { case 0: return geometryManager_->scanSerialRectangle(rowContentRect); case 1: return geometryManager_->scanNameRectangle(rowContentRect); case 3: return geometryManager_->scanDateRectangle(rowContentRect); case 4: return geometryManager_->scanTechniqueRectangle(rowContentRect); default: return QRect(); } } else { // Is Thumbnail switch(index.column()) { case 1: return geometryManager_->thumbnailImageRectangle(rowContentRect); case 2: return geometryManager_->thumbnailTitleRectangle(rowContentRect); default: return QRect(); } } }
void ImageView::paintEvent(QPaintEvent *event) { //QItemSelectionModel *selections = selectionModel(); QStyleOptionViewItem option = viewOptions(); //QStyle::State state = option.state; //QBrush background = option.palette.base(); QPen foreground(option.palette.color(QPalette::WindowText)); //QBrush highlight(option.palette.color(QPalette::Highlight)); //p.fillRect(event->rect(),background); if (!model()) return; QPainter p(viewport()); int n = model()->rowCount(); p.translate(-horizontalOffset(),-verticalOffset()); for (int i=0;i<n;i++) { QModelIndex index = model()->index(i,0); QRect rect = itemRect(index); p.setPen(foreground); //p.drawRect(rect); QVariant decoration = model()->data(index,Qt::DecorationRole); if (decoration.type() == QVariant::Pixmap) { QPixmap pixmap = qvariant_cast<QPixmap>(decoration); if (!pixmap.isNull()) { QSize pixmapSize = pixmap.size(); QSize itemSize = rect.size(); pixmapSize.scale(itemSize,Qt::KeepAspectRatio); QSize rest = (itemSize - pixmapSize)/2; QRect pixmapRect(QPoint(rest.width(),rest.height()),pixmapSize); pixmapRect.translate(rect.topLeft()); p.drawPixmap(pixmapRect,pixmap); } } if (index == currentIndex()) { QColor color(option.palette.color(QPalette::Highlight)); color.setAlpha(100); p.fillRect(rect,color); } //qDebug() << rect << foreground.color() << background.color(); //p.drawText(rect,Qt::AlignCenter,QString::number(i)); } event->accept(); }
QModelIndex GroupedIconView::indexAt(const QPoint& p) const { const QPoint viewport_p = p + QPoint(horizontalOffset(), verticalOffset()); const int count = visual_rects_.count(); for (int i=0 ; i<count ; ++i) { if (visual_rects_[i].contains(viewport_p)) { return model()->index(i, 0); } } return QModelIndex(); }
QRect AMScanThumbnailGridView::backgroundRect(const QModelIndex &index) const { QRect rowContentRect; rowContentRect = geometryManager_->contentGeometryAt(index.row(), horizontalOffset(), verticalOffset()); return rowContentRect; }
QModelIndex AMScanThumbnailGridView::indexAt(const QPoint &point) const { if(!model()) return QModelIndex(); QPoint adjustedPoint(point.x() + horizontalOffset(), point.y() + verticalOffset()); int integerIndexAt = geometryManager_->contentIndexAt(adjustedPoint); if(integerIndexAt == -1) return QModelIndex(); return model()->index(integerIndexAt, 1, QModelIndex()); }
void EditDeleteComboBoxView::mousePressEvent( QMouseEvent *event ) { DEBUG_BLOCK QModelIndex index = indexAt( event->pos() ); QPoint mousePressPos = event->pos(); mousePressPos.rx() += horizontalOffset(); mousePressPos.ry() += verticalOffset(); if ( EditDeleteDelegate::hitsEdit( mousePressPos, rectForIndex( index ) ) ) emit( editItem( index.data().toString() ) ); else if ( EditDeleteDelegate::hitsDelete( mousePressPos, rectForIndex( index ) ) ) emit( deleteItem( index.data().toString() ) ); QListView::mousePressEvent( event ); }
void cCustomShotTable::mousePressEvent(QMouseEvent *event) { QTableWidget::mousePressEvent(event); if ((IsDragOn==1)||(columnCount()==0)||(DiaporamaObject==NULL)) return; setCursor(Qt::ArrowCursor); IsDragOn=0; // Get item number under mouse int ThumbWidth =columnWidth(0); int Selected =(event->pos().x()+horizontalOffset())/ThumbWidth; if ((Selected>=0)&&(Selected<NbrItem())) { // if item is correct, check if it was previously selected. Then if not select it if (Selected!=CurrentSelected()) SetCurrentCell(Selected); else { // if it was previously selected then start a drag & drop operation IsDragOn=1; DragItemSource=Selected; DragItemDest =Selected; //RepaintCell(Selected); setCursor(Qt::ClosedHandCursor); } } }
void AMScanThumbnailGridView::scrollTo(const QModelIndex &index, QAbstractItemView::ScrollHint hint) { // Note: currently ignores the scroll hint. Places the corresponding scan as close to the top of // the view as is possible Q_UNUSED(hint); if(!index.isValid()) return; // If the passed index refers to a thumbnail (i.e. its parent is valid) then we need to // scrollTo the index of the parent scan if(index.parent().isValid()) { scrollTo(index.parent(), hint); return; } // Obtian the geometry of the index int itemCellIndex = index.row(); QRect indexCellGeometry = geometryManager_->cellGeometryAt(itemCellIndex, horizontalOffset(), verticalOffset()); verticalScrollBar()->setValue(indexCellGeometry.y()); horizontalScrollBar()->setValue(indexCellGeometry.x()); }
void cMaterialItemView::paintEvent(QPaintEvent *event) { QAbstractItemView::paintEvent(event); QPainter painter(viewport()); painter.setRenderHint(QPainter::Antialiasing); // paint selection box QModelIndex current = currentIndex(); QRect rectCurrent = visualRect(current); rectCurrent.translate(QPoint(0, 0)); rectCurrent.adjust(-3, -3, 3, 3); painter.fillRect(rectCurrent, QApplication::palette().highlight()); // paint labels for (int r = 0; r < model()->rowCount(); r++) { QString name = model()->headerData(r, Qt::Horizontal).toString(); int x = r * (cMaterialWidget::previewWidth + iconMargin) + iconMargin - horizontalOffset(); painter.drawText(QRect(x, cMaterialWidget::previewHeight + iconMargin, cMaterialWidget::previewWidth, maxNameHeight), Qt::AlignHCenter | Qt::TextWordWrap, name); } }
//----------------------------------------------------------------------------- void vktraceviewer_QTimelineView::drawBaseTimelines(QPainter* painter, const QRect& rect, const QList<uint32_t> &threadList) { int numThreads = threadList.count(); painter->save(); QFont font = painter->font(); int fontHeight = qMin((int)(m_threadHeight * 0.3), font.pointSize()); font.setPointSize(fontHeight); painter->setFont(font); for (int i = 0; i < numThreads; i++) { int threadTop = (i*m_threadHeight); painter->drawText(0, threadTop + fontHeight, QString("Thread %1").arg(threadList[i])); // draw the timeline in the middle of this thread's area int lineStart = m_margin - horizontalOffset(); int lineEnd = lineStart + scaleDurationHorizontally(m_lineLength); int lineY = threadTop + m_threadHeight/2; painter->drawLine(lineStart, lineY, lineEnd, lineY); } painter->restore(); }
QRect cMaterialItemView::visualRect(const QModelIndex &index) const { return QRect( iconMargin + index.row() * (cMaterialWidget::previewWidth + iconMargin) - horizontalOffset(), iconMargin, cMaterialWidget::previewWidth, cMaterialWidget::previewHeight + maxNameHeight); }
inline int tst_horizontalOffset() const { return horizontalOffset(); }
int HorizontalOffset() const { return horizontalOffset(); }
QModelIndex cMaterialItemView::indexAt(const QPoint &point) const { int r = (point.x() + horizontalOffset() - iconMargin) / (cMaterialWidget::previewWidth + iconMargin); return QModelIndex(model()->index(r, 0, QModelIndex())); }
void GroupedIconView::paintEvent(QPaintEvent* e) { // This code was adapted from QListView::paintEvent(), changed to use the // visualRect() of items, and to draw headers. QStyleOptionViewItemV4 option(viewOptions()); if (isWrapping()) option.features = QStyleOptionViewItemV2::WrapText; option.locale = locale(); option.locale.setNumberOptions(QLocale::OmitGroupSeparator); option.widget = this; QPainter painter(viewport()); const QRect viewport_rect(e->rect().translated(horizontalOffset(), verticalOffset())); QVector<QModelIndex> toBeRendered = IntersectingItems(viewport_rect); const QModelIndex current = currentIndex(); const QAbstractItemModel *itemModel = model(); const QItemSelectionModel *selections = selectionModel(); const bool focus = (hasFocus() || viewport()->hasFocus()) && current.isValid(); const QStyle::State state = option.state; const QAbstractItemView::State viewState = this->state(); const bool enabled = (state & QStyle::State_Enabled) != 0; int maxSize = (flow() == TopToBottom) ? viewport()->size().width() - 2 * spacing() : viewport()->size().height() - 2 * spacing(); QVector<QModelIndex>::const_iterator end = toBeRendered.constEnd(); for (QVector<QModelIndex>::const_iterator it = toBeRendered.constBegin(); it != end; ++it) { if (!it->isValid()) { continue; } option.rect = visualRect(*it); if (flow() == TopToBottom) option.rect.setWidth(qMin(maxSize, option.rect.width())); else option.rect.setHeight(qMin(maxSize, option.rect.height())); option.state = state; if (selections && selections->isSelected(*it)) option.state |= QStyle::State_Selected; if (enabled) { QPalette::ColorGroup cg; if ((itemModel->flags(*it) & Qt::ItemIsEnabled) == 0) { option.state &= ~QStyle::State_Enabled; cg = QPalette::Disabled; } else { cg = QPalette::Normal; } option.palette.setCurrentColorGroup(cg); } if (focus && current == *it) { option.state |= QStyle::State_HasFocus; if (viewState == EditingState) option.state |= QStyle::State_Editing; } itemDelegate()->paint(&painter, option, *it); } // Draw headers foreach (const Header& header, headers_) { const QRect header_rect = QRect( header_indent_, header.y, viewport()->width() - header_indent_ * 2, header_height()); // Is this header contained in the area we're drawing? if (!header_rect.intersects(viewport_rect)) { continue; } // Draw the header DrawHeader(model()->index(header.first_row, 0), header_rect.translated(-horizontalOffset(), -verticalOffset()), &painter); } }
void ListView_Impl::paintDropTarget(QPainter *painter, const QModelIndex& index, int where) { QStyleOptionViewItem option = viewOptions(); QRect rect = this->visualRect(index); QWidget *viewport = this->viewport(); QColor highlight = palette().color(QPalette::HighlightedText); QColor color = option.state & QStyle::State_Selected ? highlight : palette().color(QPalette::Highlight); QPen pen(color); painter->save(); if (!index.isValid()) where = SL_EVENT_DRAG_ON_VIEWPORT; switch (where) { case SL_EVENT_DRAG_BELOW_ITEM: case SL_EVENT_DRAG_ABOVE_ITEM: { if (viewMode() == IconMode) { QSize size = gridSize(); if (size.isEmpty()) size = rect.size(); int x, y, height = size.height(); int cellWidth = size.width() + spacing(); int cellHeight = height + spacing(); x = rect.left() + horizontalOffset(); if (where == SL_EVENT_DRAG_BELOW_ITEM) x += cellWidth; x = ((x / cellWidth) * cellWidth) - horizontalOffset(); y = (((rect.top() + verticalOffset()) / cellHeight) * cellHeight) - verticalOffset(); height = qMax(5, height - 5); painter->setRenderHint(QPainter::Antialiasing); pen.setWidth(3); pen.setColor(highlight); painter->setPen(pen); painter->drawEllipse(QPointF(x, y + height), 3, 3); painter->drawLine(x, y + 5, x, y + height - 3); pen.setWidth(2); pen.setColor(color); painter->setPen(pen); painter->drawEllipse(QPointF(x, y + height), 3, 3); painter->drawLine(x, y + 5, x, y + height - 3); } else { int x, y, width; if (where == SL_EVENT_DRAG_BELOW_ITEM) y = rect.bottom() + 1; else y = rect.top(); x = rect.left(); width = viewport->width() - rect.left() - 10; painter->setRenderHint(QPainter::Antialiasing); pen.setWidth(3); pen.setColor(highlight); painter->setPen(pen); painter->drawEllipse(QPointF(x + width, y), 3, 3); painter->drawLine(x, y, x + width - 3, y); pen.setWidth(2); pen.setColor(color); painter->setPen(pen); painter->drawEllipse(QPointF(x + width, y), 3, 3); painter->drawLine(x, y, x + width - 3, y); } } break; case SL_EVENT_DRAG_ON_ITEM: { option.rect = rect; rect.adjust(1, 1, -1, -1); painter->setRenderHint(QPainter::Antialiasing); int radius = qMin(8, rect.height() / 2); pen.setWidth(3); pen.setColor(highlight); painter->setPen(pen); painter->drawRoundedRect(rect, radius, radius); pen.setWidth(2); if (viewMode() == IconMode) { color = palette().color(QPalette::Inactive, QPalette::Highlight); pen.setColor(color); painter->setPen(pen); painter->setBrush(QBrush(color)); painter->drawRoundedRect(rect, radius, radius); QItemSelectionModel *selection = selectionModel(); if ((selection) && (selection->isSelected(index))) option.state |= QStyle::State_Selected; if (!(model()->flags(index) & Qt::ItemIsEnabled)) option.state &= ~QStyle::State_Enabled; if (option.state & QStyle::State_Enabled) option.palette.setCurrentColorGroup(QPalette::Normal); else option.palette.setCurrentColorGroup(QPalette::Disabled); itemDelegate(index)->paint(painter, option, index); } else { pen.setColor(color); painter->setPen(pen); painter->drawRoundedRect(rect, radius, radius); } } break; case SL_EVENT_DRAG_ON_VIEWPORT: { rect = viewport->rect(); rect.adjust(0, 0, -1, -1); painter->setRenderHint(QPainter::Antialiasing, false); pen.setWidth(5); pen.setColor(highlight); painter->setPen(pen); painter->drawRect(rect); pen.setWidth(3); pen.setColor(color); painter->setPen(pen); painter->drawRect(rect); } break; } painter->restore(); }
QRect GroupedIconView::visualRect(const QModelIndex& index) const { if (index.row() < 0 || index.row() >= visual_rects_.count()) return QRect(); return visual_rects_[index.row()].translated(-horizontalOffset(), -verticalOffset()); }