int ExtendedTableWidget::numVisibleRows() { // Get the row numbers of the rows currently visible at the top and the bottom of the widget int row_top = rowAt(0) == -1 ? 0 : rowAt(0); int row_bottom = rowAt(height()) == -1 ? model()->rowCount() : rowAt(height()); // Calculate the number of visible rows return row_bottom - row_top; }
const RowData* TreeModel::toRow(const QModelIndex& index) const { if (!index.isValid()) { return nullptr; } if (const auto parent = toParentRow(index)) { return rowAt(parent->children, index.row()); } else { return rowAt(m_data, index.row()); } }
void KVocTrainTable::keyPressEvent(QKeyEvent * e) { delayTimer->stop(); switch(e->key()) { case Key_Right: { int topCell = rowAt(0); int lastRowVisible = QMIN(numRows(), rowAt(contentsHeight())); if (numCols() > 2) for (int i = topCell; i <= lastRowVisible; i++) updateCell(i, KV_COL_ORG); } // fallthrough case Key_Up: case Key_Down: case Key_Next: case Key_Prior: QTable::keyPressEvent(e); break; case Key_Left: { QTable::keyPressEvent(e); int topCell = rowAt(0); int lastRowVisible = QMIN(numRows(), rowAt(contentsHeight())); if (numCols() > 2) for (int i = topCell; i <= lastRowVisible; i++) updateCell(i, KV_COL_ORG); } break; case Key_Shift: case Key_Alt: case Key_Control: // fallthrough QTable::keyPressEvent(e); emit forwardKeyPressEvent(e); break; case Key_Minus: case Key_Plus: case Key_Tab: case Key_Backtab: // fallthrough emit forwardKeyPressEvent(e); break; default: QTable::keyPressEvent(e); break; } }
void QWellArray::paintEvent(QPaintEvent *e) { QRect r = e->rect(); int cx = r.x(); int cy = r.y(); int ch = r.height(); int cw = r.width(); int colfirst = columnAt(cx); int collast = columnAt(cx + cw); int rowfirst = rowAt(cy); int rowlast = rowAt(cy + ch); if (isRightToLeft()) { int t = colfirst; colfirst = collast; collast = t; } QPainter painter(this); QPainter *p = &painter; QRect rect(0, 0, cellWidth(), cellHeight()); if (collast < 0 || collast >= ncols) collast = ncols-1; if (rowlast < 0 || rowlast >= nrows) rowlast = nrows-1; // Go through the rows for (int r = rowfirst; r <= rowlast; ++r) { // get row position and height int rowp = rowY(r); // Go through the columns in the row r // if we know from where to where, go through [colfirst, collast], // else go through all of them for (int c = colfirst; c <= collast; ++c) { if (ncols*r+c >= ncells) return; // get position and width of column c int colp = columnX(c); // Translate painter and draw the cell rect.translate(colp, rowp); paintCell(p, r, c, rect); rect.translate(-colp, -rowp); } } }
void KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e) { if(!isEnabled() || e->button() != LeftButton) { KNotifyClient::beep(); return; } // ----- int row, col; QPoint mouseCoord; // ----- mouseCoord = e->pos(); row=rowAt(mouseCoord.y()); col=columnAt(mouseCoord.x()); if(row<0 || col<0) { // the user clicked on the frame of the table activeCol = -1; activeRow = -1; } else { activeCol = col; activeRow = row; updateCell( row, col /*, false */ ); } }
void SeView::mouseMoveEvent(QMouseEvent* e) { if ((Mpressed) && ((Mpos - e->pos()).manhattanLength() > 4)) { Mpressed = false; int a = rowAt(e->pos().y()); int b = columnAt(e->pos().x()); if ((a != -1) && (b != -1)) { QTableWidgetItem* ite = item(a, b); if (ite != 0) { if (ite->type() == 1002) { SeItem* it = (SeItem*)ite; QString str(it->pageName); bool dummy; int p = GetPage(a, b, &dummy); QString tmp; QMimeData *mimeData = new QMimeData; mimeData->setData("page/magic", "2 "+tmp.setNum(p).toLocal8Bit()+" "+str.toLocal8Bit()); mimeData->setText("2 "+tmp.setNum(p)+" "+str); QDrag *dr = new QDrag(this); dr->setMimeData(mimeData); const QPixmap& pm = loadIcon("doc.png"); dr->setDragCursor(pm, Qt::CopyAction); dr->setDragCursor(pm, Qt::MoveAction); dr->exec(Qt::CopyAction | Qt::MoveAction); QApplication::setOverrideCursor(Qt::ArrowCursor); } } } } QTableWidget::mouseMoveEvent(e); }
void CSVWorld::NestedTable::contextMenuEvent (QContextMenuEvent *event) { if (!mEditIdAction) return; QModelIndexList selectedRows = selectionModel()->selectedRows(); QMenu menu(this); int currentRow = rowAt(event->y()); int currentColumn = columnAt(event->x()); if (mEditIdAction->isValidIdCell(currentRow, currentColumn)) { mEditIdAction->setCell(currentRow, currentColumn); menu.addAction(mEditIdAction); menu.addSeparator(); } if (mAddNewRowAction && mRemoveRowAction) { if (selectionModel()->selectedRows().size() == 1) menu.addAction(mRemoveRowAction); menu.addAction(mAddNewRowAction); } menu.exec (event->globalPos()); }
void SeView::dragMoveEvent(QDragMoveEvent *e) { QString str, tmp; if (e->mimeData()->hasFormat("page/magic")) { e->acceptProposedAction(); str = e->mimeData()->text(); int a = rowAt(e->pos().y()); int b = columnAt(e->pos().x()); ClearPix(); if ((a == -1) || (b == -1)) return; if (columnCount() == 1) { if ((a % 2) == 0) { item(a, 0)->setBackground(Qt::darkBlue); } } else { if (((b % 2) == 0) || (a == rowCount()-1)) { item(a, b)->setBackground(Qt::darkBlue); } } } }
void ScreenSetupView::dragMoveEvent(QDragMoveEvent* event) { if (event->mimeData()->hasFormat(ScreenSetupModel::mimeType())) { // where does the event come from? myself or someone else? if (event->source() == this) { // myself is ok, but then it must be a move action, never a copy event->setDropAction(Qt::MoveAction); event->accept(); } else { int col = columnAt(event->pos().x()); int row = rowAt(event->pos().y()); // a drop from outside is not allowed if there's a screen already there. if (!model()->screen(col, row).isNull()) event->ignore(); else event->acceptProposedAction(); } } else event->ignore(); }
bool MyTableView::viewportEvent(QEvent * event) { if ( event->type() == QEvent::ToolTip ) { qDebug() << "3"; QHelpEvent *hev = static_cast<QHelpEvent *>(event); int col = columnAt(hev->x()); int row = rowAt(hev->y()); qDebug() << "col = " << col << ", row = " << row; QModelIndex idx = model()->index(row, col, QModelIndex()); QString text = idx.data().toString(); QFont font = viewOptions().font; QFontMetrics fm(font); int requiredWidth = fm.width(text); qDebug() << "require width = " << requiredWidth; qDebug() << "col width = " << columnWidth(col); if ( columnWidth(col) > requiredWidth ) { // don't show the tooltip if all text is visible return true; } } return QTableView::viewportEvent(event); }
//================================================================== void KCharSelectTable::mouseMoveEvent( QMouseEvent *e ) { const int row = rowAt( e->y() ); const int col = columnAt( e->x() ); if ( row >= 0 && row < numRows() && col >= 0 && col < numCols() ) { const QPoint oldPos = vPos; vPos.setX( col ); vPos.setY( row ); vChr = QChar( vTableNum * 256 + numCols() * vPos.y() + vPos.x() ); const QPoint oldFocus = focusPos; focusPos = vPos; focusItem = vChr; repaintCell( oldFocus.y(), oldFocus.x(), true ); repaintCell( oldPos.y(), oldPos.x(), true ); repaintCell( vPos.y(), vPos.x(), true ); emit highlighted( vChr ); emit highlighted(); emit focusItemChanged( focusItem ); emit focusItemChanged(); } }
void WTable::moveRow(int from, int to) { if (from < 0 || from >= (int)rows_.size()) { LOG_ERROR("moveRow: the from index is not a valid row index."); return; } WTableRow* from_tr = rowAt(from); Utils::erase(rows_, from_tr); if (to > (int)rows_.size()) rowAt(to); rows_.insert(rows_.begin() + to, from_tr); flags_.set(BIT_GRID_CHANGED); repaint(RepaintSizeAffected); }
QList<QStandardItem *> SubmitFileModel::findRow(const QString &text, int column) const { // Single item const QList<QStandardItem *> items = findItems(text, Qt::MatchExactly, column); if (items.empty()) return items; // Compile row return rowAt(items.front()->row()); }
// ---------------------------------------------------------------------- // -------------------------------------------------------------------------------- void QmvTable::contentsMousePressEvent( QMouseEvent * mre ) { // are we moving to a new cell? is_current_cell = ( rowAt(mre->y()) == currentRow() ) && (columnAt(mre->x()) == currentColumn() ); // The order of events is PRESS/RELEASE/DOUBLECLICK/RELEASE // Flag the press, to differentiate the susequent release events. first_click = true; QTable::contentsMousePressEvent( mre ); }
void FixedWidthTableView::dropEvent(QDropEvent *event) { int row = rowAt(event->pos().y()); int col = columnAt(event->pos().x()); if (model()->dropMimeData(event->mimeData(), event->dropAction(), row, col, QModelIndex())) { event->accept(); } else event->ignore(); }
/*!\reimp */ void QGridView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) { int colfirst = columnAt( cx ); int collast = columnAt( cx + cw ); int rowfirst = rowAt( cy ); int rowlast = rowAt( cy + ch ); if ( rowfirst == -1 || colfirst == -1 ) { paintEmptyArea( p, cx, cy, cw, ch ); return; } if ( collast < 0 || collast >= ncols ) collast = ncols-1; if ( rowlast < 0 || rowlast >= nrows ) rowlast = nrows-1; // Go through the rows for ( int r = rowfirst; r <= rowlast; ++r ) { // get row position and height int rowp = r * cellh; // Go through the columns in the row r // if we know from where to where, go through [colfirst, collast], // else go through all of them for ( int c = colfirst; c <= collast; ++c ) { // get position and width of column c int colp = c * cellw; // Translate painter and draw the cell p->translate( colp, rowp ); paintCell( p, r, c ); p->translate( -colp, -rowp ); } } // Paint empty rects paintEmptyArea( p, cx, cy, cw, ch ); }
WTableRow* WTable::insertRow(int row) { if (row >= rowCount()) return rowAt(row); // trigger a simple expand() else { WTableRow* tableRow = new WTableRow(this, columnCount()); rows_.insert(rows_.begin() + row, tableRow); flags_.set(BIT_GRID_CHANGED); repaint(RepaintInnerHtml); return tableRow; } }
void KVocTrainTable::contentsMousePressEvent(QMouseEvent * e) { delayTimer->stop(); int cc = columnAt(e->x()); int cr = rowAt(e->y()); int co = currentColumn(); QTable::contentsMousePressEvent(e); if(cc >= KV_EXTRA_COLS) { // update color of original when column changes and more than 1 translation bool update_org = false; if (cc != co && numCols() > 2) update_org = true; int topCell = rowAt(0); int lastRowVisible = QMIN(numRows(), rowAt(contentsHeight())); if (update_org) for (int i = topCell; i <= lastRowVisible; i++) updateCell(i, KV_COL_ORG); } if(e->button() == LeftButton) setCurrentCell(cr, cc); }
void KPrTimeLineView::mousePressEvent(QMouseEvent *event) { int row = rowAt(event->y()); int column = columnAt(event->x()); m_mainView->setSelectedRow(row); m_mainView->setSelectedColumn(column); // Request context menu if (event->button()== Qt::RightButton) { emit customContextMenuRequested(event->pos()); } // Check if user wants to move the time bars if (event->button() == Qt::LeftButton) { if (column == KPrShapeAnimations::StartTime) { m_resize = false; m_move = false; QRectF lineRect = getRowRect(row, column); QRectF endLineRect = QRectF(lineRect.right() - RESIZE_RADIUS, lineRect.top(), RESIZE_RADIUS * 2, lineRect.height()); // If the user clicks near the end of the line they could resize otherwise they move the bar. if (endLineRect.contains(event->x(), event->y())) { m_resize = true; m_resizedRow = row; setCursor(Qt::SizeHorCursor); } else { m_resize = false; m_move = false; if (lineRect.contains(event->x(), event->y())) { startDragPos = event->x() - lineRect.x(); m_move = true; m_resizedRow = row; setCursor( #if QT_VERSION >= 0x040700 Qt::DragMoveCursor #else Qt::ClosedHandCursor #endif ); } } } } emit clicked(m_mainView->model()->index(row, column)); }
void ScreenSetupView::mouseDoubleClickEvent(QMouseEvent* event) { if (event->buttons() & Qt::LeftButton) { int col = columnAt(event->pos().x()); int row = rowAt(event->pos().y()); if (!model()->screen(col, row).isNull()) { ScreenSettingsDialog dlg(this, &model()->screen(col, row)); dlg.exec(); } } else event->ignore(); }
void FingerList::mousePressEvent(QMouseEvent *e) { int col = columnAt(e->x()); int row = rowAt(e->y() + contentsY()); int n = row * perRow + col; if ((n >= 0) && (n < num)) { curSel = row * perRow + col; repaintCell(oldRow, oldCol); repaintCell(row, col); oldCol = col; oldRow = row; emit chordSelected(appl[curSel].f); } }
int MovableTableWidget::dropRow(QPoint pos) { int result = rowAt(pos.y()); if (result == -1) { result = rowCount(); } else if (columnCount() > 0) { QRect itemRect = visualItemRect(item(result, 0)); if (itemRect.bottom() - pos.y() < pos.y() - itemRect.top()) { result++; } } return result; }
void SeView::mouseReleaseEvent(QMouseEvent* e) { e->accept(); Mpressed = false; /* if (e->button() == RightButton) { QPopupMenu *pmen = new QPopupMenu(); qApp->setOverrideCursor(QCursor(Qt::ArrowCursor), true); int px = pmen->insertItem( tr("Show Master Page Names"), this, SLOT(ToggleNam())); if (Namen) pmen->setItemChecked(px, true); pmen->exec(QCursor::pos()); delete pmen; } */ emit Click(rowAt(e->pos().y()), columnAt(e->pos().x()), e->button()); QTableWidget::mouseReleaseEvent(e); }
// -------------------------------------------------------------------------------- void QmvTable::realSingleClick() { // Build an event from the stored press event and dispatch to the standard // QTable handler. QMouseEvent * mre = new QMouseEvent( hold_mre.type, hold_mre.pos, hold_mre.globalPos, hold_mre.button, hold_mre.state); QTable::contentsMouseReleaseEvent( mre ); delete mre; // QTable::contentsMouseReleaseEvent() filters out non-left buttonclicks. // so send the signal now. if ( mre->button() != LeftButton ) emit clicked( rowAt(hold_mre.pos.y()), columnAt(hold_mre.pos.x()), hold_mre.button, mapFromGlobal( hold_mre.globalPos ) ); }
bool KPrTimeLineView::event(QEvent *event) { if (event->type() == QEvent::ToolTip) { QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event); QModelIndex index = m_mainView->model()->index(rowAt(helpEvent->pos().y()),columnAt(helpEvent->pos().x())); if (index.isValid()) { QString text = m_mainView->model()->data(index, Qt::ToolTipRole).toString(); QToolTip::showText(helpEvent->globalPos(), text); } else { QToolTip::hideText(); event->ignore(); } return true; } return QWidget::event(event); }
void CloneTasksTableView::contextMenuEvent(QContextMenuEvent *event) { QPoint pos = event->pos(); int row = rowAt(pos.y()); qDebug("row = %d\n", row); if (row == -1) { return; } CloneTasksTableModel *model = (CloneTasksTableModel *)this->model(); CloneTask task = model->taskAt(row); prepareContextMenu(task); pos = viewport()->mapToGlobal(pos); context_menu_->exec(pos); }
void SyncErrorsTableView::contextMenuEvent(QContextMenuEvent *event) { QPoint pos = event->pos(); int row = rowAt(pos.y()); qDebug("row = %d\n", row); if (row == -1) { return; } SyncErrorsTableModel *model = (SyncErrorsTableModel *)this->model(); SyncError error = model->errorAt(row); prepareContextMenu(error); pos = viewport()->mapToGlobal(pos); context_menu_->exec(pos); }
void KDateTable::contentsMousePressEvent(QMouseEvent *e) { if(e->type()!=QEvent::MouseButtonPress) { // the KDatePicker only reacts on mouse press events: return; } if(!isEnabled()) { KNotifyClient::beep(); return; } int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; // ----- int row, col, pos, temp; QPoint mouseCoord; // ----- mouseCoord = e->pos(); row=rowAt(mouseCoord.y()); col=columnAt(mouseCoord.x()); if(row<0 || col<0) { // the user clicked on the frame of the table return; } pos=7*(row-1)+col+1; if(pos+dayoff<=firstday) { // this day is in the previous month KNotifyClient::beep(); return; } if(firstday+numdays<pos+dayoff) { // this date is in the next month KNotifyClient::beep(); return; } temp=firstday+date.day()-dayoff-1; setDate(QDate(date.year(), date.month(), pos-firstday+dayoff)); updateCell(temp/7+1, temp%7); // Update the previously selected cell updateCell(row, col); // Update the selected cell // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); emit(tableClicked()); }
void KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e) { if (e->state() & LeftButton) { int row, col; QPoint mouseCoord; // ----- mouseCoord = e->pos(); row=rowAt(mouseCoord.y()); col=columnAt(mouseCoord.x()); int tmpRow = -1, tmpCol = -1; if(row<0 || col<0) { // the user clicked on the frame of the table if ( activeCol > -1 ) { tmpRow = activeRow; tmpCol = activeCol; } activeCol = -1; activeRow = -1; } else { bool differentCell = (activeRow != row || activeCol != col); if ( activeCol > -1 && differentCell) { tmpRow = activeRow; tmpCol = activeCol; } if ( differentCell) { activeRow = row; activeCol = col; updateCell( row, col /*, false */ ); // mark the new active cell } } if ( tmpRow > -1 ) // repaint the former active cell updateCell( tmpRow, tmpCol /*, true */ ); } }
void KDateInternalMonthPicker::contentsMouseReleaseEvent(QMouseEvent *e) { if(!isEnabled()) { return; } // ----- int row, col, pos; QPoint mouseCoord; // ----- mouseCoord = e->pos(); row=rowAt(mouseCoord.y()); col=columnAt(mouseCoord.x()); if(row<0 || col<0) { // the user clicked on the frame of the table emit(closeMe(0)); } pos=3*row+col+1; result=pos; emit(closeMe(1)); }