void MyHeader::mouseMoveEvent(QMouseEvent* event) { if (orientation() == Qt::Horizontal) return; static int index = 0; if (index != logicalIndexAt(event->pos())) { index = logicalIndexAt(event->pos()); if (event->buttons() & Qt::LeftButton) { qDebug() << "mouseMoveEvent" << event; m_isOn[index] = !m_isOn[index]; updateSection(index); stateChanged(m_isOn, orientation()); } } }
void QtlCheckableHeaderView::mousePressEvent(QMouseEvent* event) { // Process this event when it occurs in the first section of the header, inside the checkbox. if (event != 0 && logicalIndexAt(event->pos()) == 0 && checkBoxRect().contains(event->pos())) { // We force either checked or unchecked in repaint. if (_checkState != Qt::Unchecked) { _checkState = Qt::Unchecked; } else { _checkState = Qt::Checked; } _forceCheck = true; // The state always changes here, process the change. processCheckStateChanged(); // Update all check boxes in first column. updateAllRows(); } // Update the widget. update(); // Let the superclass process other effects for this event. QHeaderView::mousePressEvent(event); }
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 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 QSpreadsheetHeaderView::mouseMoveEvent(QMouseEvent * event) { QHeaderView::mouseMoveEvent(event); // Required to refresh the button menu enable/disable state. int logicalIndex = logicalIndexAt(event->pos()); updateSection(logicalIndex); }
void RotatedHeader::mousePressEvent(QMouseEvent *e) { m_p = e->pos(); int idx = logicalIndexAt(e->pos()); if (idx > 0 && idx < count() && e->button() == Qt::RightButton) { emit section_right_clicked(idx); } QHeaderView::mousePressEvent(e); }
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); }
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 FixHeaderView::mouseDoubleClickEvent(QMouseEvent *me) { QModelIndex index; qint32 logicalIndex = logicalIndexAt(me->pos()); if (me->button() == Qt::RightButton) { index = indexAt(me->pos()); if (logicalIndex == 0) { me->accept(); emit column0DoubleClicked(logicalIndex,me->globalPos()); } } else QHeaderView::mouseDoubleClickEvent(me); }
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 FixHeaderView::mousePressEvent(QMouseEvent *me) { QModelIndex index; if (me->button() == Qt::RightButton) { index = indexAt(me->pos()); int logicalIndex = logicalIndexAt(me->pos()); if (logicalIndex > 0) { // want double click for column 0 // as it toggles filter me->accept(); emit doPopup(logicalIndex,me->globalPos()); } } else QHeaderView::mousePressEvent(me); }
void RotatedHeader::contextMenuEvent(QContextMenuEvent *evt) { int idx = logicalIndexAt(evt->pos()); if (idx == 0) { //name header QMenu *m = new QMenu(this); QAction *a = m->addAction(tr("Sort Alphabetically Ascending"), this, SLOT(sort_action())); a->setData(DwarfModelProxy::DSR_NAME_ASC); a = m->addAction(tr("Sort Alphabetically Descending"), this, SLOT(sort_action())); a->setData(DwarfModelProxy::DSR_NAME_DESC); a = m->addAction(tr("Sort by ID Ascending"), this, SLOT(sort_action())); a->setData(DwarfModelProxy::DSR_ID_ASC); a = m->addAction(tr("Sort by ID Descending"), this, SLOT(sort_action())); a->setData(DwarfModelProxy::DSR_ID_DESC); a = m->addAction(tr("Sort in Game Order"), this, SLOT(sort_action())); a->setData(DwarfModelProxy::DSR_GAME_ORDER); m->exec(viewport()->mapToGlobal(evt->pos())); } }
void MyHeader::mousePressEvent(QMouseEvent* event) { int index = logicalIndexAt(event->pos()); if (orientation() == Qt::Horizontal) { for (int var = 0; var < count(); ++var) m_isOn[var] = false; m_isOn[index] = true; for (int var = 0; var < count(); ++var) updateSection(var); } else { m_isOn[index] = !m_isOn[index]; updateSection(index); } stateChanged(m_isOn, orientation()); QHeaderView::mousePressEvent(event); }
void PlaylistHeader::contextMenuEvent(QContextMenuEvent* e) { menu_section_ = logicalIndexAt(e->pos()); if (menu_section_ == -1 || ( menu_section_ == logicalIndex(0) && logicalIndex(1) == -1)) hide_action_->setVisible(false); else { hide_action_->setVisible(true); QString title(model()->headerData(menu_section_, Qt::Horizontal).toString()); hide_action_->setText(tr("&Hide %1").arg(title)); } qDeleteAll(show_actions_); show_actions_.clear(); for (int i=0 ; i<count() ; ++i) { AddColumnAction(i); } menu_->popup(e->globalPos()); }
void QSpreadsheetHeaderView::mousePressEvent ( QMouseEvent * event ) { QHeaderView::mousePressEvent(event); int logicalIndex = logicalIndexAt(event->pos()); if (buttonMenuRect(logicalIndex).contains(event->pos())) { QMenu menu(this); QAction *hideCol = menu.addAction("Hide column"); QAction *sortAZ = menu.addAction("Sort sheet A->Z"); QAction *sortZA = menu.addAction("Sort sheet Z->A"); // Disable hide column if only one column remains. Otherwise // the gui is no more available to show them back. hideCol->setEnabled(hiddenSectionCount() < count() - 1); QAction *res = menu.exec(mapToGlobal(event->pos())); if (res == hideCol) { hideSection(logicalIndex); updateSection(logicalIndex-1); } if (res == sortAZ) model()->sort(logicalIndex, Qt::AscendingOrder); if (res == sortZA) model()->sort(logicalIndex, Qt::DescendingOrder); } // Catch previous arrow mouse click. if (prevRect(logicalIndex).contains(event->pos())) { showSection(logicalIndex - 1); updateSection(logicalIndex - 2); } // Catch next arrow mouse click. if (nextRect(logicalIndex).contains(event->pos())) { showSection(logicalIndex + 1); updateSection(logicalIndex + 2); } }