Example #1
0
// Overridden to highlight the changed items
void VarItem::paintCell(QPainter *p, const QColorGroup &cg,
                        int column, int width, int align)
{
    if (p == 0) {
        return;
	}

    if (column == VALUE_COLUMN) {
		// Show color values as colors, and make the text color the same
		// as the base color
		if (dataType_ == COLOR_TYPE) {
			QRegExp color_re("\\s(#.*)>");
			
			if (color_re.search(text(column)) != -1) {
        		QColorGroup color_cg(	cg.foreground(), cg.background(), 
										cg.light(), cg.dark(), cg.mid(), 
										QColor(color_re.cap(1)), QColor(color_re.cap(1)) );
        		QListViewItem::paintCell(p, color_cg, column, width, align);
				return;
			}
		}
		
		// Highlight recently changed items in red
		if (highlight_) {
        	QColorGroup hl_cg(	cg.foreground(), cg.background(), 
								cg.light(), cg.dark(), cg.mid(), 
								red, cg.base() );
        	QListViewItem::paintCell(p, hl_cg, column, width, align);
			return;
		}
	}
	
	QListViewItem::paintCell(p, cg, column, width, align);
	return;
}
Example #2
0
  Piece * Piece::FromString(std::string piece_str)
  {
    string::const_iterator piece_begin = piece_str.begin();
    string::const_iterator piece_end = piece_str.end();

    boost::match_results<string::const_iterator> matches;

    boost::regex
      //piece_re("<\\s*piece.*?\\/>", boost::regex::perl|boost::regex::icase),
      row_re("row\\s*=\\s*(['\"]?)(.*?)\\1", boost::regex::perl|boost::regex::icase),
      col_re("column\\s*=\\s*(['\"]?)(.*?)\\1", boost::regex::perl|boost::regex::icase),
      color_re("color\\s*=\\s*(['\"]?)(.*?)\\1", boost::regex::perl|boost::regex::icase),
      type_re("type\\s*=\\s*(['\"]?)(.*?)\\1", boost::regex::perl|boost::regex::icase);

    if (!(regex_search(piece_begin, piece_end, matches, type_re)))
      { std::cout << "error parsing piece" << std::endl; return NULL; }
    std::string type_str = matches[2];

    if (!(regex_search(piece_begin, piece_end, matches, color_re)))
      { std::cout << "error parsing piece" << std::endl; return NULL; }
    std::string color_str = matches[2];

    if (!(regex_search(piece_begin, piece_end, matches, row_re)))
      { std::cout << "error parsing piece" << std::endl; return NULL; }
    std::string row = matches[2];

    if (!(regex_search(piece_begin, piece_end, matches, col_re)))
      { std::cout << "error parsing piece" << std::endl; return NULL; }
    std::string col = matches[2];

  PieceColor color = (color_str == "white") ? WHITE : BLACK;

  PieceType type = NO_TYPE;
  type = (type_str == "pawn") ? PAWN : type;
  type = (type_str == "rook") ? ROOK : type;
  type = (type_str == "bishop") ? BISHOP : type;
  type = (type_str == "knight") ? KNIGHT : type;
  type = (type_str == "king") ? KING : type;
  type = (type_str == "queen") ? QUEEN : type;

  return Create(type, color, atoi(row.c_str()), atoi(col.c_str()));
  }