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 TupLayerIndexHeader::paintSection(QPainter * painter, const QRect & rect, int logicalIndex) const { if (!rect.isValid()) return; QStyleOptionHeader headerOption; headerOption.rect = rect; headerOption.orientation = Qt::Horizontal; headerOption.position = QStyleOptionHeader::Middle; QStyle::State state = QStyle::State_None; if (isEnabled()) state |= QStyle::State_Enabled; if (window()->isActiveWindow()) state |= QStyle::State_Active; style()->drawControl(QStyle::CE_HeaderSection, &headerOption, painter); //painter->drawRect(rect.normalized().adjusted(0, 1, 0, -1)); QString text = model()->headerData(logicalIndex, orientation(), Qt::DisplayRole).toString();; //QFontMetrics fm(painter->font()); QFont label("Arial", 9, QFont::Bold, false); QFontMetrics fm(label); int x = rect.x() + (sectionSize(logicalIndex) - fm.width( text ))/2; //int y = fm.height() + (rect.y() / 2); int y = 17; painter->setFont(label); painter->drawText(x, y, text); }
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 } }
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 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 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 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 CQHeaderView:: fixWidgetPositions() { for (int i = 0; i < count(); ++i) { QWidget *w = widgets_[i]; w->setGeometry(sectionViewportPosition(i), 0, sectionSize(i) - 5, height()); } }
/** Redefined. */ void PlaylistHeaderView::paintEvent(QPaintEvent *) { QStylePainter p(this->viewport()); QLinearGradient vLinearGradient(rect().topLeft(), QPoint(rect().left(), rect().top() + rect().height())); /// XXX QPalette palette = QApplication::palette(); if (SettingsPrivate::instance()->isCustomColors()) { vLinearGradient.setColorAt(0, palette.base().color().lighter(110)); vLinearGradient.setColorAt(1, palette.base().color()); } else { vLinearGradient.setColorAt(0, palette.base().color()); vLinearGradient.setColorAt(1, palette.window().color()); } QStyleOptionHeader opt; opt.initFrom(this->viewport()); p.fillRect(rect(), QBrush(vLinearGradient)); p.setPen(opt.palette.windowText().color()); QRect r; p.save(); if (QGuiApplication::isLeftToRight()) { p.translate(-offset(), 0); } else { p.translate(offset(), 0); } for (int i = 0; i < count(); i++) { QRect r2(sectionPosition(i), viewport()->rect().y(), sectionSize(i), viewport()->rect().height()); p.drawText(r2, Qt::AlignCenter, model()->headerData(i, Qt::Horizontal).toString()); if (r2.contains(mapFromGlobal(QCursor::pos()))) { r = r2; } } p.restore(); if (!r.isNull()) { p.save(); p.setPen(palette.highlight().color()); p.drawLine(r.x(), r.y() + r.height() / 4, r.x(), r.y() + 3 * r.height() / 4); p.drawLine(r.x() + r.width() - 1, r.y() + r.height() / 4, r.x() + r.width() - 1, r.y() + 3 * r.height() / 4); p.restore(); } // Bottom frame p.setPen(QApplication::palette().mid().color()); p.drawLine(rect().bottomLeft(), QPoint(rect().left() + rect().width(), rect().top() + rect().height())); // Vertical frame if (QGuiApplication::isLeftToRight()) { p.drawLine(rect().topLeft(), QPoint(rect().left(), rect().top() + rect().height())); } else { p.drawLine(rect().topRight(), QPoint(rect().right(), rect().top() + rect().height())); } }
void FilterTableHeader::adjustPositions() { // Loop through all widgets for(int i=0;i < filterWidgets.size(); ++i) { // Get the current widget, move it and reisize it QWidget* w = filterWidgets.at(i); w->move(sectionPosition(i) - offset(), filterWidgets.at(i)->sizeHint().height() + 2); // The two adds some extra space between the header label and the input widget w->resize(sectionSize(i), filterWidgets.at(i)->sizeHint().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 RDHeaderView::mouseReleaseEvent(QMouseEvent *event) { if(m_movingSection >= 0) { int mousePos = event->x(); int idx = logicalIndexAt(mousePos); if(idx >= 0) { int secSize = sectionSize(idx); int secPos = sectionPosition(idx); int srcSection = visualIndex(m_movingSection); int dstSection = visualIndex(idx); if(srcSection >= 0 && dstSection >= 0 && srcSection != dstSection) { // the half-way point of the section decides whether we're dropping to the left // or the right of it. if(mousePos < secPos + secSize / 2) { // if we're moving from the left, place it to the left of dstSection if(srcSection < dstSection) moveSection(srcSection, dstSection - 1); else moveSection(srcSection, dstSection); } else { // if we're moving it from the right, place it to the right of dstSection if(srcSection > dstSection) moveSection(srcSection, dstSection + 1); else moveSection(srcSection, dstSection); } } } m_sectionPreview->hide(); } m_movingSection = -1; if(m_customSizing) { m_resizeState = qMakePair(NoResize, -1); return QAbstractItemView::mouseReleaseEvent(event); } QHeaderView::mouseReleaseEvent(event); }
/*! adjust geometry and repaint header . */ void SpreadsheetHeaderView::refresh() { //TODO // adjust geometry and repaint header (still looking for a more elegant solution) int width = sectionSize(count()-1); m_slave->setStretchLastSection(true); // ugly hack /*(flaw in Qt? Does anyone know a better way?)*/ m_slave->updateGeometry(); m_slave->setStretchLastSection(false); // ugly hack part 2 setStretchLastSection(true); // ugly hack (flaw in Qt? Does anyone know a better way?) updateGeometry(); setStretchLastSection(false); // ugly hack part 2 resizeSection(count()-1, width); update(); }
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(); } }
QPoint Pin::offset(bool exterior) { int extra = exterior ? _length : 0; switch (position.side()) { case PinPosition::Right: return QPoint(sectionSize().width() + extra, position.offset() * grid()); break; case PinPosition::Top: return QPoint(position.offset() * grid(), -extra); break; case PinPosition::Left: return QPoint(-extra, position.offset() * grid()); break; case PinPosition::Bottom: return QPoint(position.offset() * grid(), sectionSize().height() + extra); break; default: break; } return QPoint(); }
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); }
bool KexiTableViewHeader::eventFilter(QObject * watched, QEvent * e) { if (e->type() == QEvent::MouseMove) { const int section = sectionAt(static_cast<QMouseEvent*>(e)->x()); if (section != m_lastToolTipSection && section >= 0 && section < (int)m_toolTips.count()) { //QToolTip::remove(this, m_toolTipRect); #ifdef __GNUC__ #warning TODO KexiTableViewHeader::eventFilter #else #pragma WARNING( TODO KexiTableViewHeader::eventFilter ) #endif QString tip = m_toolTips[ section ]; if (tip.isEmpty()) { //try label QFontMetrics fm(font()); int minWidth = fm.width(label(section)) + style()->pixelMetric(QStyle::PM_HeaderMargin); QIcon *iset = iconSet(section); if (iset) minWidth += (2 + iset->pixmap(IconSize(KIconLoader::Small)).width()); //taken from QHeader::sectionSizeHint() if (minWidth > sectionSize(section)) tip = label(section); } if (tip.isEmpty()) { m_lastToolTipSection = -1; } else { #ifdef __GNUC__ #warning QToolTip::showText() OK? #else #pragma WARNING( QToolTip::showText() OK? ) #endif QToolTip::showText(static_cast<QMouseEvent*>(e)->globalPos(), tip, this, m_toolTipRect = sectionRect(section)); m_lastToolTipSection = section; } } } else if (e->type() == QEvent::ToolTip) { // QHelpEvent *helpEvent = static_cast<QHelpEvent *>(e); #ifdef __GNUC__ #warning TODO #else #pragma WARNING( TODO ) #endif } // if (e->type()==QEvent::MouseButtonPress) { // todo // } return Q3Header::eventFilter(watched, e); }
void StretchHeaderView::SetStretchEnabled(bool enabled) { stretch_enabled_ = enabled; if (enabled) { // Initialise the list of widths from the current state of the widget column_widths_.resize(count()); for (int i=0 ; i<count() ; ++i) { column_widths_[i] = ColumnWidthType(sectionSize(i)) / width(); } // Stretch the columns to fill the widget NormaliseWidths(); UpdateWidths(); } emit StretchEnabledChanged(enabled); }
void CCustomHeaderView::sectionsAboutToBeRemoved ( const QModelIndex & parent, int logicalFirst, int logicalLast ) { //remove selected sections for(int iX=logicalFirst;iX<=logicalLast;++iX) { CCustomHeaderViewEntry * ptrEntry = m_ptrPriv->m_vSectionsWidget[logicalFirst]; m_ptrPriv->m_vSectionsWidget.erase(m_ptrPriv->m_vSectionsWidget.begin()+logicalFirst); //ptrEntry delete ptrEntry; int stSize = sectionSize(0); onSectionResized(0,stSize,stSize); m_ptrPriv->setSectionsValues(); } if (m_ptrPriv->sectionsCount()==1) { CCustomHeaderViewEntry * ptrEntry = m_ptrPriv->m_vSectionsWidget.back(); ptrEntry->move(QPoint(ciEntrySeparator/2,ciEntrySeparator/2)); } }
void StretchHeaderView::HideSection(int logical) { // Would this hide the last section? bool all_hidden = true; for (int i=0 ; i<count() ; ++i) { if (i != logical && !isSectionHidden(i) && sectionSize(i) > 0) { all_hidden = false; break; } } if (all_hidden) { return; } if (!stretch_enabled_) { hideSection(logical); return; } column_widths_[logical] = 0.0; NormaliseWidths(); UpdateWidths(); }
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()); }
bool SymbolTable::addByName(const Atom &newAtom) { StringRef name = newAtom.name(); assert(!name.empty()); const Atom *existing = findByName(name); if (existing == nullptr) { // Name is not in symbol table yet, add it associate with this atom. _nameTable[name] = &newAtom; return true; } // Do nothing if the same object is added more than once. if (existing == &newAtom) return false; // Name is already in symbol table and associated with another atom. bool useNew = true; switch (collide(existing->definition(), newAtom.definition())) { case NCR_First: useNew = false; break; case NCR_Second: useNew = true; break; case NCR_DupDef: assert(existing->definition() == Atom::definitionRegular); assert(newAtom.definition() == Atom::definitionRegular); switch (mergeSelect(((DefinedAtom*)existing)->merge(), ((DefinedAtom*)&newAtom)->merge())) { case MCR_First: useNew = false; break; case MCR_Second: useNew = true; break; case MCR_Largest: { uint64_t existingSize = sectionSize((DefinedAtom*)existing); uint64_t newSize = sectionSize((DefinedAtom*)&newAtom); useNew = (newSize >= existingSize); break; } case MCR_SameSize: { uint64_t existingSize = sectionSize((DefinedAtom*)existing); uint64_t newSize = sectionSize((DefinedAtom*)&newAtom); if (existingSize == newSize) { useNew = true; break; } llvm::errs() << "Size mismatch: " << existing->name() << " (" << existingSize << ") " << newAtom.name() << " (" << newSize << ")\n"; // fallthrough } case MCR_Error: if (!_context.getAllowDuplicates()) { llvm::errs() << "Duplicate symbols: " << existing->name() << ":" << existing->file().path() << " and " << newAtom.name() << ":" << newAtom.file().path() << "\n"; llvm::report_fatal_error("duplicate symbol error"); } useNew = false; break; } break; case NCR_DupUndef: { const UndefinedAtom* existingUndef = cast<UndefinedAtom>(existing); const UndefinedAtom* newUndef = cast<UndefinedAtom>(&newAtom); bool sameCanBeNull = (existingUndef->canBeNull() == newUndef->canBeNull()); if (!sameCanBeNull && _context.warnIfCoalesableAtomsHaveDifferentCanBeNull()) { llvm::errs() << "lld warning: undefined symbol " << existingUndef->name() << " has different weakness in " << existingUndef->file().path() << " and in " << newUndef->file().path() << "\n"; } const UndefinedAtom *existingFallback = existingUndef->fallback(); const UndefinedAtom *newFallback = newUndef->fallback(); bool hasDifferentFallback = (existingFallback && newFallback && existingFallback->name() != newFallback->name()); if (hasDifferentFallback) { llvm::errs() << "lld warning: undefined symbol " << existingUndef->name() << " has different fallback: " << existingFallback->name() << " in " << existingUndef->file().path() << " and " << newFallback->name() << " in " << newUndef->file().path() << "\n"; } bool hasNewFallback = newUndef->fallback(); if (sameCanBeNull) useNew = hasNewFallback; else useNew = (newUndef->canBeNull() < existingUndef->canBeNull()); break; } case NCR_DupShLib: { const SharedLibraryAtom *curShLib = cast<SharedLibraryAtom>(existing); const SharedLibraryAtom *newShLib = cast<SharedLibraryAtom>(&newAtom); bool sameNullness = (curShLib->canBeNullAtRuntime() == newShLib->canBeNullAtRuntime()); bool sameName = curShLib->loadName().equals(newShLib->loadName()); if (sameName && !sameNullness && _context.warnIfCoalesableAtomsHaveDifferentCanBeNull()) { // FIXME: need diagonstics interface for writing warning messages llvm::errs() << "lld warning: shared library symbol " << curShLib->name() << " has different weakness in " << curShLib->file().path() << " and in " << newShLib->file().path(); } if (!sameName && _context.warnIfCoalesableAtomsHaveDifferentLoadName()) { // FIXME: need diagonstics interface for writing warning messages llvm::errs() << "lld warning: shared library symbol " << curShLib->name() << " has different load path in " << curShLib->file().path() << " and in " << newShLib->file().path(); } useNew = false; break; } case NCR_Error: llvm::errs() << "SymbolTable: error while merging " << name << "\n"; llvm::report_fatal_error("duplicate symbol error"); break; } if (useNew) { // Update name table to use new atom. _nameTable[name] = &newAtom; // Add existing atom to replacement table. _replacedAtoms[existing] = &newAtom; } else { // New atom is not being used. Add it to replacement table. _replacedAtoms[&newAtom] = existing; } return false; }
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); } }
void FilterHorizontalHeaderView::updateGeometry(int logical) const { assert(headerWidgets.contains(logical)); headerWidgets[logical]->setGeometry(sectionViewportPosition(logical)+2, 0, sectionSize(logical)-5, height()); }