void CFlashingWnd::CheckRect(int diffx, int diffy) { CRect saveRect(m_cRect); m_cRect.OffsetRect(diffx, diffy); TRACE(_T("m_cRect.Width: %d\nsaveRect.Width: %d\n"), m_cRect.Width(), saveRect.Width()); if (m_cRect.left < 0) { m_cRect.left = 0; m_cRect.right = m_cRect.left + saveRect.Width(); } if (m_cRect.top < 0) { m_cRect.top = 0; m_cRect.bottom = m_cRect.top + saveRect.Height(); } if ((maxxScreen - 1) < m_cRect.right) { m_cRect.right = maxxScreen - 1; m_cRect.left = m_cRect.right - saveRect.Width(); } if ((maxyScreen - 1) < m_cRect.bottom) { m_cRect.bottom = maxyScreen - 1; m_cRect.top = m_cRect.bottom - saveRect.Height(); } TRACE(_T("m_cRect.Width: %d\nsaveRect.Width: %d\n"), m_cRect.Width(), saveRect.Width()); }
////////////////////////////////////////////////////////////////////////////// // draw ////////////////////////////////////////////////////////////////////////////// void CrossTab::Draw(QPainter & paint) { paint.save(); // Calculate the number of rows and columns that we can display int lastColumn(0); int lastRow(0); CalculateDisplayedRowsAndColumns(lastColumn, lastRow, m_rect); paint.drawRect(m_rect); QRect sampleRect(0,0,0,0); // Name itemRectangle QRect saveRect(0,0,0,0); int idRow=m_rowIndexStored; int idCol=m_columnIndexStored; // Start at the correct place CrossTabRowIndex::iterator rowIt(m_rowIndex.begin()); CrossTabColumnIndex::iterator columnIt(m_columnIndex.begin()); for (idRow = 0, rowIt = m_rowIndex.begin() ; ((idRow <= lastRow) && (rowIt != m_rowIndex.end())); ++idRow, ++rowIt) { // Should this row cell be displayed // Skip header column if not wanted if ( ((0 == idRow) && (0 != m_rowIndexStored) && !m_columnHeaderEachPage) || //Skip already displayed rows ((0 < idRow) && (idRow < m_rowIndexStored)) || //Skip rows that are not part of the already drawn table part (m_tableWrapDisplayAllColumnsFirst && (0 < idRow) && (idRow > m_rowIndexStoredLast) && (0 != m_columnIndexStored)) ) { continue; } for (idCol = 0, columnIt = m_columnIndex.begin() ; ((idCol <= lastColumn) && (columnIt != m_columnIndex.end())); ++idCol, ++columnIt) { // Should this column cell be displayed // Skip header row if not wanted if (((0 == idCol) && (0 != m_columnIndexStored) && !m_rowHeaderEachPage) || // Skip already displayed columns ((0 < idCol) && (idCol < m_columnIndexStored))) { continue; } // Get width of this column QString dataTekst (columnIt.key()); sampleRect.setWidth (columnIt.value().m_columnMaxWidth + m_cellLeftMargin + m_cellRightMargin); sampleRect.setHeight (rowIt.value().m_rowMaxHeight + m_cellTopMargin + m_cellBottomMargin); // Save rectangle saveRect = sampleRect; paint.setBackgroundMode(Qt::OpaqueMode); // Draw headers row if (idRow == 0) { paint.setBrush(QBrush(QColor(0, 0, 255, 127), Qt::SolidPattern)); } // Header column else if ((idRow != 0) && (idCol == 0)) { // Odd rows if ((idRow%2) != 0 ) { paint.setBrush(QBrush(QColor(0, 0, 255, 200), Qt::SolidPattern)); } // Even rows else { paint.setBrush(QBrush(QColor(90, 210, 255, 150), Qt::SolidPattern)); } } // Values else if ((idRow != 0) && (idCol != 0)) { // Odd rows if ((idRow%2) != 0 ) { paint.setBrush(QBrush(QColor(0, 0, 0, 0), Qt::SolidPattern)); } // Even rows else { paint.setBrush(QBrush(QColor(90, 210, 255, 127), Qt::SolidPattern)); } } // Draw rectangle paint.drawRect(sampleRect); paint.setBackgroundMode(Qt::TransparentMode); paint.setPen(Qt::SolidLine); // Skip margins: Adjust rectangle for data insertion sampleRect.setX(sampleRect.x() + m_cellLeftMargin); sampleRect.setY(sampleRect.y() + m_cellTopMargin); sampleRect.setWidth (columnIt.value().m_columnMaxWidth); sampleRect.setHeight (rowIt.value().m_rowMaxHeight); // get Font QFontMetrics fm(GetFont()); QRect dataRect; // Header if ((idRow == 0) && (idCol == 0)) { // Do nothing } // Headerrow else if ((idRow == 0) && (idCol != 0)) { dataRect = fm.boundingRect(sampleRect, m_hAlignMap["column"] | m_vAlignMap["column"], columnIt.key()); paint.drawText(dataRect, m_hAlignMap["column"] | m_vAlignMap["column"], columnIt.key()); } // Headercol else if ((idCol == 0) && (idRow != 0)) { dataRect = fm.boundingRect(sampleRect, m_hAlignMap["row"] | m_vAlignMap["row"], rowIt.key()); paint.drawText(dataRect, m_hAlignMap["row"] | m_vAlignMap["row"], rowIt.key()); } // Value else { dataRect = fm.boundingRect(sampleRect, m_hAlignMap["value"] | m_vAlignMap["value"], GetValue(columnIt.key(), rowIt.key())); paint.drawText(dataRect, m_hAlignMap["value"] | m_vAlignMap["value"], GetValue(columnIt.key(), rowIt.key())); } // Restore rectangle sampleRect = saveRect; sampleRect.setX(sampleRect.x() + sampleRect.width()); } // end for // Reset basic column id idCol = m_columnIndexStored; // Adjust item display rectangle sampleRect.setY(sampleRect.y()+sampleRect.height()); sampleRect.setX(0); } // Store indexes for iterative purpose m_rowIndexStored = lastRow + 1; m_columnIndexStored = lastColumn + 1; // Now that we are done return the paint device back to the state // it was when we started to mess with it paint.restore(); }