void HierarchicalHeaderView::on_sectionResized(int logicalIndex) { if(isSectionHidden(logicalIndex)) return; QModelIndex leafIndex(_pd->leafIndex(logicalIndex)); if(leafIndex.isValid()) { QModelIndexList leafsList(_pd->leafs(_pd->findRootIndex(leafIndex))); for(int n=leafsList.indexOf(leafIndex); n>0; --n) { --logicalIndex; int w = viewport()->width(); int h = viewport()->height(); int pos = sectionViewportPosition(logicalIndex); QRect r(pos, 0, w - pos, h); if(orientation() == Qt::Horizontal) { if (isRightToLeft()) r.setRect(0, 0, pos + sectionSize(logicalIndex), h); } else r.setRect(0, pos, w, h - pos); viewport()->update(r.normalized()); } } }
void TupExposureHeader::mousePressEvent(QMouseEvent *event) { int section = logicalIndexAt(event->pos()); if (section > -1 && section < count()) { int x = sectionViewportPosition(section) + 3; QFont font = this->font(); font.setPointSize(8); QFontMetrics fm(font); QString text = m_sections[section].title; int w = fm.width(text); int limit = sectionSize(section)/2 - w/2; QRect rect(x + limit - 12, 3, 12, height()-3); if (rect.contains(event->pos())) { notifyVisibilityChange(section); } else { if (m_currentSection != section) emit headerSelectionChanged(section); QHeaderView::mousePressEvent(event); } } else { #ifdef K_DEBUG QString msg = "TupExposureHeader::mousePressEvent() - Fatal Error: Section index is invalid -> " + QString::number(section); #ifdef Q_OS_WIN qDebug() << msg; #else tFatal() << msg; #endif #endif } }
QPair<RDHeaderView::ResizeType, int> RDHeaderView::checkResizing(QMouseEvent *event) { int mousePos = event->x(); int idx = logicalIndexAt(mousePos); bool hasCursor = testAttribute(Qt::WA_SetCursor); bool cursorSet = false; bool leftResize = idx > 0 && (m_sections[idx - 1].group != m_sections[idx].group); bool rightResize = idx >= 0 && hasGroupTitle(idx); if(leftResize || rightResize) { int secSize = sectionSize(idx); int secPos = sectionViewportPosition(idx); int handleWidth = style()->pixelMetric(QStyle::PM_HeaderGripMargin, 0, this); int gapWidth = 0; if(hasGroupGap(idx)) gapWidth = groupGapSize(); if(leftResize && secPos >= 0 && secSize > 0 && mousePos < secPos + handleWidth) { return qMakePair(LeftResize, idx); } if(rightResize && secPos >= 0 && secSize > 0 && mousePos > secPos + secSize - handleWidth - gapWidth) { return qMakePair(RightResize, idx); } } return qMakePair(NoResize, -1); }
void RDHeaderView::currentChanged(const QModelIndex ¤t, const QModelIndex &old) { if(!m_customSizing) return QHeaderView::currentChanged(current, old); // not optimal at all if(current != old) { QRect r = viewport()->rect(); if(old.isValid()) { QRect rect = r; if(orientation() == Qt::Horizontal) { rect.setLeft(sectionViewportPosition(old.column())); rect.setWidth(sectionSize(old.column())); } else { rect.setTop(sectionViewportPosition(old.column())); rect.setHeight(sectionSize(old.column())); } viewport()->update(rect); } if(current.isValid()) { QRect rect = r; if(orientation() == Qt::Horizontal) { rect.setLeft(sectionViewportPosition(current.column())); rect.setWidth(sectionSize(current.column())); } else { rect.setTop(sectionViewportPosition(current.column())); rect.setHeight(sectionSize(current.column())); } viewport()->update(rect); } } }
void handleSectionMoved(int logical, int oldVisualIndex, int newVisualIndex) { for (int i=qMin(oldVisualIndex, newVisualIndex);i<count();i++){ int logical = logicalIndex(i); boxes[logical]->setGeometry(sectionViewportPosition(logical), 0, sectionSize(logical) - 5, height()); } }
void handleSectionResized(int i) { for (int j=visualIndex(i);j<count();j++) { int logical = logicalIndex(j); boxes[logical]->setGeometry(sectionViewportPosition(logical), 0, sectionSize(logical) - 5, height()); } }
void CQHeaderView:: fixWidgetPositions() { for (int i = 0; i < count(); ++i) { QWidget *w = widgets_[i]; w->setGeometry(sectionViewportPosition(i), 0, sectionSize(i) - 5, height()); } }
void CQHeaderView:: handleSectionMoved(int /*logical*/, int oldVisualIndex, int newVisualIndex) { for (int i = qMin(oldVisualIndex, newVisualIndex); i < count(); ++i) { int logical = logicalIndex(i); QWidget *w = widgets_[logical]; w->setGeometry(sectionViewportPosition(logical), 0, sectionSize(logical) - 5, height()); } }
void CQHeaderView:: handleSectionResized(int i) { for (int j = visualIndex(i); j < count(); ++j) { int logical = logicalIndex(j); QWidget *w = widgets_[logical]; w->setGeometry(sectionViewportPosition(logical), 0, sectionSize(logical) - 5, height()); } }
void EditableHeaderView::onEditHeader (int idx) { QRect geo = m_lineEdit->geometry(); geo.setWidth(sectionSize(idx)); geo.moveLeft(sectionViewportPosition(idx)); m_lineEdit->setGeometry(geo); m_lineEdit->setText(model()->headerData(m_idx, Qt::Horizontal).toString()); m_lineEdit->setHidden(0); m_lineEdit->blockSignals(0); m_lineEdit->setFocus(); m_lineEdit->selectAll(); m_idx = idx; }
void KTExposureHeader::showEditorName(int section) { if (section >= 0) { QFont font("Arial", 8, QFont::Normal, false); m_editor->setFont(font); int x = sectionViewportPosition(section); m_editor->setGeometry(x, 0, sectionSize(section), height()); m_sectionEdited = section; m_editor->setText(m_layers[section].title); m_editor->show(); m_editor->setFocus(); } }
void KTExposureHeader::mousePressEvent(QMouseEvent * event) { int section = logicalIndexAt(event->pos()); int x = sectionViewportPosition(section) + 3; QRect rect(x+3, 3, height()-3, height()-3); if (rect.contains(event->pos())) { emitVisibilityChanged(section); } else { if (currentCol != section) emit selectionChanged(section); QHeaderView::mousePressEvent(event); } }
void showEvent(QShowEvent *e) { for (int i=0;i<count();i++) { if (!boxes[i]) { QComboBox *box = new QComboBox(this); box->addItem("test 1"); box->addItem("test 2"); boxes[i] = box; } boxes[i]->setGeometry(sectionViewportPosition(i), 0, sectionSize(i) - 5, height()); boxes[i]->show(); } QHeaderView::showEvent(e); }
void TupExposureHeader::showTitleEditor(int section) { if (section >= 0) { QFont font = this->font(); font.setPointSize(8); m_editor->setFont(font); int x = sectionViewportPosition(section); m_editor->setGeometry(x, 0, sectionSize(section), height()); m_editedSection = section; m_editor->setText(m_sections[section].title); m_editor->show(); m_editor->setFocus(); } }
void RDHeaderView::mousePressEvent(QMouseEvent *event) { int mousePos = event->x(); int idx = logicalIndexAt(mousePos); if(sectionsMovable() && idx >= 0 && event->buttons() == Qt::LeftButton) { int secSize = sectionSize(idx); int secPos = sectionViewportPosition(idx); int handleWidth = style()->pixelMetric(QStyle::PM_HeaderGripMargin, 0, this); if(secPos >= 0 && secSize > 0 && mousePos >= secPos + handleWidth && mousePos <= secPos + secSize - handleWidth) { m_movingSection = idx; m_sectionPreview->resize(secSize, height()); QPixmap preview(m_sectionPreview->size()); preview.fill(QColor::fromRgba(qRgba(0, 0, 0, 100))); QPainter painter(&preview); painter.setOpacity(0.75f); paintSection(&painter, QRect(QPoint(0, 0), m_sectionPreview->size()), idx); painter.end(); m_sectionPreview->setPixmap(preview); m_sectionPreviewOffset = mousePos - secPos; m_sectionPreview->move(mousePos - m_sectionPreviewOffset, 0); m_sectionPreview->show(); return; } } if(m_customSizing) { m_resizeState = checkResizing(event); m_cursorPos = QCursor::pos().x(); return QAbstractItemView::mousePressEvent(event); } QHeaderView::mousePressEvent(event); }
void CQHeaderView:: initWidgets() { if (! factory_) return; int n = count(); while (widgets_.size() < n) widgets_.push_back(0); while (widgets_.size() > n) { QWidget *w = widgets_.back(); delete w; widgets_.pop_back(); } for (int i = 0; i < n; ++i) { QWidget *w = widgets_[i]; if (! w) { w = factory_->createWidget(i); w->setParent(this); widgets_[i] = w; } w->setGeometry(sectionViewportPosition(i), 0, sectionSize(i) - 5, height()); w->show(); } }
QRect QSpreadsheetHeaderView::sectionRect(int logicalIndex) const { return QRect(sectionViewportPosition(logicalIndex), 0, sectionSize(logicalIndex), height()); }
void fixComboPositions() { for (int i = 0; i<count();i++) boxes[i]->setGeometry(sectionViewportPosition(i), 0, sectionSize(i) - 5, height()); }
void FilterHorizontalHeaderView::updateGeometry(int logical) const { assert(headerWidgets.contains(logical)); headerWidgets[logical]->setGeometry(sectionViewportPosition(logical)+2, 0, sectionSize(logical)-5, height()); }
void RDHeaderView::paintEvent(QPaintEvent *e) { if(!m_customSizing) return QHeaderView::paintEvent(e); if(count() == 0) return; QPainter painter(viewport()); int start = qMax(visualIndexAt(e->rect().left()), 0); int end = visualIndexAt(e->rect().right()); if(end == -1) end = count() - 1; // make sure we always paint the whole header for any merged headers while(start > 0 && !hasGroupTitle(start - 1)) start--; while(end < m_sections.count() && !hasGroupTitle(end)) end++; QRect accumRect; for(int i = start; i <= end; ++i) { int pos = sectionViewportPosition(i); int size = sectionSize(i); if(!hasGroupGap(i) && pos < 0) { size += pos; pos = 0; } // either set or accumulate this section's rect if(accumRect.isEmpty()) accumRect.setRect(pos, 0, size, viewport()->height()); else accumRect.setWidth(accumRect.width() + size); if(hasGroupTitle(i)) { painter.save(); accumRect.setWidth(accumRect.width() - 1); if(accumRect.left() < m_pinnedWidth && i >= m_pinnedColumns) accumRect.setLeft(m_pinnedWidth); paintSection(&painter, accumRect, i); painter.restore(); // if we have more sections to go, reset so we can accumulate the next group if(i < end) accumRect = QRect(); } } // clear the remainder of the header if there's a gap if(accumRect.right() < e->rect().right()) { QStyleOption opt; opt.init(this); opt.state |= QStyle::State_Horizontal; opt.rect = QRect(accumRect.right() + 1, 0, e->rect().right() - accumRect.right(), viewport()->height()); style()->drawControl(QStyle::CE_HeaderEmptyArea, &opt, &painter, this); } }