QString QGraphicsSceneBspTree::debug(int index) const { const Node *node = &nodes.at(index); QString tmp; if (node->type == Node::Leaf) { QRectF rect = rectForIndex(index); if (!leaves[node->leafIndex].isEmpty()) { tmp += QString::fromLatin1("[%1, %2, %3, %4] contains %5 items\n") .arg(rect.left()).arg(rect.top()) .arg(rect.width()).arg(rect.height()) .arg(leaves[node->leafIndex].size()); } } else { if (node->type == Node::Horizontal) { tmp += debug(firstChildIndex(index)); tmp += debug(firstChildIndex(index) + 1); } else { tmp += debug(firstChildIndex(index)); tmp += debug(firstChildIndex(index) + 1); } } return tmp; }
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 DivePictureWidget::mousePressEvent(QMouseEvent *event) { ulong doubleClickInterval = static_cast<ulong>(qApp->styleHints()->mouseDoubleClickInterval()); static qint64 lasttime = 0L; qint64 timestamp = QDateTime::currentDateTime().toMSecsSinceEpoch(); if (timestamp - lasttime <= doubleClickInterval) { doubleClicked(indexAt(event->pos())); } else { lasttime = timestamp; QPixmap pixmap = model()->data(indexAt(event->pos()), Qt::DecorationRole).value<QPixmap>(); QString filename = model()->data(indexAt(event->pos()), Qt::DisplayPropertyRole).toString(); QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); dataStream << filename << event->pos(); QMimeData *mimeData = new QMimeData; mimeData->setData("application/x-subsurfaceimagedrop", itemData); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(pixmap); drag->setHotSpot(event->pos() - rectForIndex(indexAt(event->pos())).topLeft()); drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction); } }
QPoint CodeCompleterListView::infoFramePos() const { const QRect &r = rectForIndex(currentIndex()); QPoint p((parentWidget()->mapToGlobal( parentWidget()->rect().topRight())).x() + 3, mapToGlobal(r.topRight()).y() - verticalOffset() ); return p; }
QPoint CodeCompleterListView::infoFramePos() const { const QRect &r = rectForIndex(currentIndex()); int xoffset = this->frameWidth()+3; int yoffset = this->frameWidth()-verticalOffset(); QScrollBar *vsb = this->verticalScrollBar(); if (vsb && vsb->isVisible()) xoffset += this->horizontalScrollBar()->sizeHint().height(); QPoint pt = this->mapToGlobal(r.topRight()); pt.rx() += xoffset; pt.ry() += yoffset; return pt; }
void Pageview::slotPagePartChanged (const QModelIndex &index, const QImage &image, int scaled_linenum) { const Pagedelegate *del = (Pagedelegate *)itemDelegate (); QStyleOptionViewItem option = getViewOptions (); int hvalue = horizontalScrollBar()->value(); int vvalue = verticalScrollBar()->value(); QRect rect = rectForIndex (index); QRect part_rect; option.rect = rect; del->getPagePart (option, index, scaled_linenum, image.height (), part_rect); part_rect.translate (-hvalue, -vvalue); QWidget *vp = viewport (); // qDebug () << "repaint" << part_rect; // part_rect.setHeight (part_rect.height () - 1); // leave blank line (for testing!) // vp->repaint (part_rect); vp->update (part_rect); }
QRectF QGraphicsSceneBspTree::rectForIndex(int index) const { if (index <= 0) return rect; int parentIdx = parentIndex(index); QRectF rect = rectForIndex(parentIdx); const Node *parent = &nodes.at(parentIdx); if (parent->type == Node::Horizontal) { if (index & 1) rect.setRight(parent->offset); else rect.setLeft(parent->offset); } else { if (index & 1) rect.setBottom(parent->offset); else rect.setTop(parent->offset); } return rect; }
void GroupedIconView::LayoutItems() { if (!model()) return; const int count = model()->rowCount(); QString last_group; QPoint next_position(0, 0); int max_row_height = 0; visual_rects_.clear(); visual_rects_.reserve(count); headers_.clear(); for (int i=0 ; i<count ; ++i) { const QModelIndex index(model()->index(i, 0)); const QString group = index.data(Role_Group).toString(); const QSize size(rectForIndex(index).size()); // Is this the first item in a new group? if (group != last_group) { // Add the group header. Header header; header.y = next_position.y() + max_row_height + header_indent_; header.first_row = i; header.text = group; if (!last_group.isNull()) { header.y += header_spacing_; } headers_ << header; // Remember this group so we don't add it again. last_group = group; // Move the next item immediately below the header. next_position.setX(0); next_position.setY(header.y + header_height() + header_indent_ + header_spacing_); max_row_height = 0; } // Take into account padding and spacing QPoint this_position(next_position); if (this_position.x() == 0) { this_position.setX(this_position.x() + item_indent_); } else { this_position.setX(this_position.x() + spacing()); } // Should this item wrap? if (next_position.x() != 0 && this_position.x() + size.width() >= viewport()->width()) { next_position.setX(0); next_position.setY(next_position.y() + max_row_height); this_position = next_position; this_position.setX(this_position.x() + item_indent_); max_row_height = 0; } // Set this item's geometry visual_rects_.append(QRect(this_position, size)); // Update next index next_position.setX(this_position.x() + size.width()); max_row_height = qMax(max_row_height, size.height()); } verticalScrollBar()->setRange(0, next_position.y() + max_row_height - viewport()->height()); update(); }
const QRect AppListView::indexRect(const QModelIndex &index) const { return rectForIndex(index); }