[rkward-cvs] rkward/rkward/dataeditor editlabelsdialog.cpp,1.5,1.6 editlabelsdialog.h,1.3,1.4 twintabledatamember.cpp,1.11,1.12 twintablemember.cpp,1.18,1.19 twintablemember.h,1.16,1.17 twintablemetamember.cpp,1.13,1.14

Thomas Friedrichsmeier tfry at users.sourceforge.net
Fri Apr 7 13:43:09 UTC 2006


Update of /cvsroot/rkward/rkward/rkward/dataeditor
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24180

Modified Files:
	editlabelsdialog.cpp editlabelsdialog.h 
	twintabledatamember.cpp twintablemember.cpp twintablemember.h 
	twintablemetamember.cpp 
Log Message:
Remove code triplication regarding cell-painting. Set blueish-gray background for selected trailing rows/cols

Index: twintablemember.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/twintablemember.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** twintablemember.cpp	7 Apr 2006 13:02:44 -0000	1.18
--- twintablemember.cpp	7 Apr 2006 13:43:06 -0000	1.19
***************
*** 19,22 ****
--- 19,24 ----
  
  #include <qevent.h>
+ #include <qpainter.h>
+ #include <qstyle.h>
  
  #include "celleditor.h"
***************
*** 226,228 ****
--- 228,292 ----
  }
  
+ void TwinTableMember::paintCellInternal (QPainter *p, int row, int col, const QRect &cr, bool selected, const QColorGroup &cg, QBrush *brush_override, QPen *pen_override, const QString &text, int alignment) {
+ 	// no trace for paint operations
+ 
+ 	// draw background
+ 	QBrush brush = cg.brush (QColorGroup::Base);
+ 	if (!brush_override) {
+ 		if (selected) {
+ 			brush = cg.brush(QColorGroup::Highlight);
+ 			if ((row >= numTrueRows ()) || (col >= numTrueCols ())) {
+ 				brush = QBrush (QColor (127, 127, 255));
+ 			}
+ 		} else {
+ 			if ((row >= numTrueRows ()) || (col >= numTrueCols ())) {
+ 				brush = QBrush (Qt::gray);
+ 			}
+ 		}
+ 	} else {
+ 		brush = *brush_override;
+ 	}
+ 	p->fillRect(0, 0, cr.width(), cr.height(), brush);
+ 
+ 	// draw grid
+ 	QPen pen (p->pen ());
+ 	int gridColor = style ().styleHint (QStyle::SH_Table_GridLineColor, this);
+ 	if (gridColor != -1) {
+ 		const QPalette &pal = palette ();
+ 		if (cg != colorGroup () && cg != pal.disabled () && cg != pal.inactive ()) p->setPen (cg.mid ());
+ 		else p->setPen ((QRgb) gridColor);
+ 	} else {
+ 		p->setPen (cg.mid ());
+ 	}
+ 	int x2 = cr.width () - 1;
+ 	int y2 = cr.height () - 1;
+ 	p->drawLine (x2, 0, x2, y2);
+ 	p->drawLine (0, y2, x2, y2);
+ 	p->setPen (pen);
+ 
+ 	if (tted && (currEditRow () == row) && (currEditCol () == col)) {
+ 		tted->raise ();
+ 		return;
+ 	}
+ 
+ 	if (text.isNull ()) return;
+ 
+ 	if (!pen_override) {
+ 		if (selected) {
+ 			p->setPen (cg.highlightedText());
+ 		} else {
+ 			p->setPen (cg.text ());
+ 		}
+ 	} else {
+ 		p->setPen (*pen_override);
+ 	}
+ 
+ 	if (alignment == 1) {
+ 		p->drawText (2, 0, cr.width () - 4, cr.height (), Qt::AlignRight, text);
+ 	} else {
+ 		p->drawText (2, 0, cr.width () - 4, cr.height (), Qt::AlignLeft, text);
+ 	}
+ }
+ 
+ 
  #include "twintablemember.moc"

Index: editlabelsdialog.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/editlabelsdialog.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** editlabelsdialog.cpp	7 Apr 2006 13:02:44 -0000	1.5
--- editlabelsdialog.cpp	7 Apr 2006 13:43:06 -0000	1.6
***************
*** 140,149 ****
  }
  
! QString LevelsTable::text (int row, int col) const {
  	RK_TRACE (EDITOR);
- 	RK_ASSERT (col == 0);
- 	RK_ASSERT (row < numTrueRows ());
  
! 	return ((*storage)[QString::number (row+1)]);
  }
  
--- 140,150 ----
  }
  
! QString LevelsTable::text (int row, int) const {
  	RK_TRACE (EDITOR);
  
! 	if (row < numTrueRows ()) {
! 		return ((*storage)[QString::number (row+1)]);
! 	}
! 	return QString::null;
  }
  
***************
*** 151,199 ****
  	// no trace for paint operations
  
! 	// draw background
! 	QBrush brush = QBrush (Qt::red);
! 	if (selected) {
! 		brush = cg.brush(QColorGroup::Highlight);
! 	} else {
! 			brush = cg.brush (QColorGroup::Base);
! 	}
! 	if (row >= numTrueRows ()) {
! 		brush = QBrush (Qt::gray);
! 	}
! 
! 	p->fillRect(0, 0, cr.width(), cr.height(), brush);
! 
! 	// draw grid
! 	QPen pen (p->pen ());
! 	int gridColor = style ().styleHint (QStyle::SH_Table_GridLineColor, this);
! 	if (gridColor != -1) {
! 		const QPalette &pal = palette ();
! 		if (cg != colorGroup () && cg != pal.disabled () && cg != pal.inactive ()) p->setPen (cg.mid ());
! 		else p->setPen ((QRgb) gridColor);
! 	} else {
! 		p->setPen (cg.mid ());
! 	}
! 	int x2 = cr.width () - 1;
! 	int y2 = cr.height () - 1;
! 	p->drawLine (x2, 0, x2, y2);
! 	p->drawLine (0, y2, x2, y2);
! 	p->setPen (pen);
! 
! 	if (tted && (currEditRow () == row) && (currEditCol () == col)) {
! 		tted->raise ();
! 		return;
! 	}
! 	
! 	// draw text
! 	if (selected) {
! 		p->setPen (cg.highlightedText());
! 	} else {
! 		p->setPen (cg.text ());
! 	}
! 
! 	p->drawText (2, 0, cr.width () - 4, cr.height (), Qt::AlignLeft, (*storage)[QString::number (row+1)]);
  }
  
- 
  QWidget *LevelsTable::beginEdit (int row, int col, bool) {
  	RK_TRACE (EDITOR);
--- 152,158 ----
  	// no trace for paint operations
  
! 	paintCellInternal (p, row, col, cr, selected, cg, 0, 0, text (row, col), 0);
  }
  
  QWidget *LevelsTable::beginEdit (int row, int col, bool) {
  	RK_TRACE (EDITOR);

Index: twintabledatamember.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/twintabledatamember.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** twintabledatamember.cpp	2 Oct 2005 17:19:02 -0000	1.11
--- twintabledatamember.cpp	7 Apr 2006 13:43:06 -0000	1.12
***************
*** 62,120 ****
  void TwinTableDataMember::paintCell (QPainter *p, int row, int col, const QRect &cr, bool selected, const QColorGroup &cg) {
  	// no trace for paint operations
  	RKVariable *var = table->getColObject (col);
  	RKVariable::Status cell_state = RKVariable::ValueInvalid;
  	if (var) cell_state = var->cellStatus (row);
- 	
- 	// draw background
- 	QBrush brush = QBrush (Qt::red);
- 	if (selected) {
- 		brush = cg.brush(QColorGroup::Highlight);
- 	}
- 	if ((row >= numTrueRows ()) || (!var)) {
- 		brush = QBrush (Qt::gray);
- 	} else if (cell_state != RKVariable::ValueInvalid) {
- 		if (!selected) {
- 			brush = cg.brush (QColorGroup::Base);
- 		}
- 	}
- 	p->fillRect(0, 0, cr.width(), cr.height(), brush);
- 
- 	// draw grid
- 	QPen pen (p->pen ());
- 	int gridColor = style ().styleHint (QStyle::SH_Table_GridLineColor, this);
- 	if (gridColor != -1) {
- 		const QPalette &pal = palette ();
- 		if (cg != colorGroup () && cg != pal.disabled () && cg != pal.inactive ()) p->setPen (cg.mid ());
- 		else p->setPen ((QRgb) gridColor);
- 	} else {
- 		p->setPen (cg.mid ());
- 	}
- 	int x2 = cr.width () - 1;
- 	int y2 = cr.height () - 1;
- 	p->drawLine (x2, 0, x2, y2);
- 	p->drawLine (0, y2, x2, y2);
- 	p->setPen (pen);
  
! 	if (tted && (currEditRow () == row) && (currEditCol () == col)) {
! 		tted->raise ();
! 		return;
! 	}
! 	
! 	// draw text
! 	if (selected) {
! 		p->setPen (cg.highlightedText());
! 	} else if (cell_state == RKVariable::ValueUnknown) {
! 		p->setPen (cg.light ());
! 	} else {
! 		p->setPen (cg.text ());
  	}
  
  	if (var && (row < numTrueRows ())) {
! 		if (var->getAlignment () == RKVariable::AlignCellRight) {
! 			p->drawText (2, 0, cr.width () - 4, cr.height (), Qt::AlignRight, var->getFormatted (row));
! 		} else {
! 			p->drawText (2, 0, cr.width () - 4, cr.height (), Qt::AlignLeft, var->getFormatted (row));
! 		}
  	}
  }
  
--- 62,90 ----
  void TwinTableDataMember::paintCell (QPainter *p, int row, int col, const QRect &cr, bool selected, const QColorGroup &cg) {
  	// no trace for paint operations
+ 
  	RKVariable *var = table->getColObject (col);
  	RKVariable::Status cell_state = RKVariable::ValueInvalid;
  	if (var) cell_state = var->cellStatus (row);
  
! 	QBrush *brush_override = 0;
! 	QPen *pen_override = 0;
! 	if (var) {
! 		if (cell_state == RKVariable::ValueInvalid) {
! 			brush_override = new QBrush (Qt::red);
! 		} else if (cell_state == RKVariable::ValueUnknown) {
! 			pen_override = new QPen (cg.light ());
! 		}
  	}
  
+ 	QString text;
+ 	int align = 0;
  	if (var && (row < numTrueRows ())) {
! 		text = var->getFormatted (row);
! 		align = var->getAlignment ();
  	}
+ 	paintCellInternal (p, row, col, cr, selected, cg, brush_override, pen_override, text, align);
+ 
+ 	delete pen_override;
+ 	delete brush_override;
  }
  

Index: editlabelsdialog.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/editlabelsdialog.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** editlabelsdialog.h	7 Apr 2006 13:02:44 -0000	1.3
--- editlabelsdialog.h	7 Apr 2006 13:43:06 -0000	1.4
***************
*** 38,46 ****
  /** reimplemented form QTable not to add trailing rows/cols if needed */
  	QWidget *beginEdit (int row, int col, bool replace);
! /** reimplemented form QTable not to work on RObject::ValueLabels instead of QTableItems */
  	void paintCell (QPainter *p, int row, int col, const QRect &cr, bool selected, const QColorGroup &cg);
! /** reimplemented form QTable not to work on RObject::ValueLabels instead of QTableItems */
  	void setText (int row, int col, const QString &text);
! /** reimplemented form QTable not to work on RObject::ValueLabels instead of QTableItems */
  	QString text (int row, int col) const;
  public slots:
--- 38,46 ----
  /** reimplemented form QTable not to add trailing rows/cols if needed */
  	QWidget *beginEdit (int row, int col, bool replace);
! /** reimplemented form QTable  to work on RObject::ValueLabels instead of QTableItems */
  	void paintCell (QPainter *p, int row, int col, const QRect &cr, bool selected, const QColorGroup &cg);
! /** reimplemented form QTable to work on RObject::ValueLabels instead of QTableItems */
  	void setText (int row, int col, const QString &text);
! /** reimplemented form QTable to work on RObject::ValueLabels instead of QTableItems */
  	QString text (int row, int col) const;
  public slots:

Index: twintablemetamember.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/twintablemetamember.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** twintablemetamember.cpp	2 Oct 2005 17:19:02 -0000	1.13
--- twintablemetamember.cpp	7 Apr 2006 13:43:06 -0000	1.14
***************
*** 71,118 ****
  	// no trace for paint operations
  	RKVariable *var = table->getColObject (col);
- 	
- 	// draw background
- 	QBrush brush = QBrush (Qt::red);
- 	if (selected) {
- 		brush = cg.brush(QColorGroup::Highlight);
- 	} else {
- 		brush = cg.brush (QColorGroup::Base);
- 	}	
- 	if ((row >= numTrueRows ()) || (!var)) {
- 		brush = QBrush (Qt::gray);
- 	}
- 	p->fillRect(0, 0, cr.width(), cr.height(), brush);
- 
- 	// draw grid
- 	QPen pen (p->pen ());
- 	int gridColor = style ().styleHint (QStyle::SH_Table_GridLineColor, this);
- 	if (gridColor != -1) {
- 		const QPalette &pal = palette ();
- 		if (cg != colorGroup () && cg != pal.disabled () && cg != pal.inactive ()) p->setPen (cg.mid ());
- 		else p->setPen ((QRgb) gridColor);
- 	} else {
- 		p->setPen (cg.mid ());
- 	}
- 	int x2 = cr.width () - 1;
- 	int y2 = cr.height () - 1;
- 	p->drawLine (x2, 0, x2, y2);
- 	p->drawLine (0, y2, x2, y2);
- 	p->setPen (pen);
- 
- 	if (tted && (currEditRow () == row) && (currEditCol () == col)) {
- 		tted->raise ();
- 		return;
- 	}
- 	
- 	// draw text
- 	if (selected) {
- 		p->setPen (cg.highlightedText());
- 	} else {
- 		p->setPen (cg.text ());
- 	}
  
  	if (var && (row < numTrueRows ())) {
! 		p->drawText (2, 0, cr.width () - 4, cr.height (), Qt::AlignLeft, formattedText (row, col));
  	}
  }
  
--- 71,80 ----
  	// no trace for paint operations
  	RKVariable *var = table->getColObject (col);
  
+ 	QString text;
  	if (var && (row < numTrueRows ())) {
! 		text = formattedText (row, col);
  	}
+ 	paintCellInternal (p, row, col, cr, selected, cg, 0, 0, text, 0);
  }
  

Index: twintablemember.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/twintablemember.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** twintablemember.h	7 Apr 2006 13:02:44 -0000	1.16
--- twintablemember.h	7 Apr 2006 13:43:06 -0000	1.17
***************
*** 87,90 ****
--- 87,96 ----
  /** shortcut to get the boundaries of the current selection */
  	void getSelectionBoundaries (int *top_row, int *left_col, int *bottom_row, int *right_col);
+ /** internal function to paint the cell. Accepts the parameters of QTable::paintCell, and also:
+ @param brush_override If not null, the cell-background will be painted in this brush
+ @param pen_override If not null, the cell text will be painted in this pen
+ @param text The text to draw
+ @param aligment Alignment of the text. 0 = Left, 1=Right */
+ 	void paintCellInternal (QPainter *p, int row, int col, const QRect &cr, bool selected, const QColorGroup &cg, QBrush *brush_override, QPen *pen_override, const QString &text, int alignment);
  signals:
  	void headerRightClick (int row, int col);





More information about the rkward-tracker mailing list