/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id$ * * Copyright (C) 2010 Robert Bieber * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/ #include "rbalbumart.h" #include #include "parsetreenode.h" RBAlbumArt::RBAlbumArt(QGraphicsItem *parent, int x, int y, int maxWidth, int maxHeight, int artWidth, int artHeight, ParseTreeNode* node, char hAlign, char vAlign) : RBMovable(parent),artWidth(artWidth), artHeight(artHeight), hAlign(hAlign), vAlign(vAlign), texture(":/render/albumart.png"), node(node) { size = QRectF(0, 0, maxWidth, maxHeight); setFlag(ItemSendsGeometryChanges, false); setPos(x, y); hide(); } void RBAlbumArt::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QRectF drawArea; /* Making sure the alignment flags are sane */ if(hAlign != 'c' && hAlign != 'l' && hAlign != 'r') hAlign = 'c'; if(vAlign != 'c' && vAlign != 't' && vAlign != 'b') vAlign = 'c'; if(artWidth <= size.width() && artHeight <= size.height()) { /* If the art is smaller than the viewport, just center it up */ drawArea.setX((size.width() - artWidth) / 2); drawArea.setY((size.height() - artHeight) / 2); drawArea.setWidth(artWidth); drawArea.setHeight(artHeight); } else { /* Otherwise, figure out our scale factor, and which dimension needs * to be scaled, and how to align said dimension */ double xScale = size.width() / artWidth; double yScale = size.height() / artHeight; double scale = xScale < yScale ? xScale : yScale; double scaleWidth = artWidth * scale; double scaleHeight = artHeight * scale; if(hAlign == 'l') drawArea.setX(0); else if(hAlign == 'c') drawArea.setX((size.width() - scaleWidth) / 2 ); else drawArea.setX(size.width() - scaleWidth); if(vAlign == 't') drawArea.setY(0); else if(vAlign == 'c') drawArea.setY((size.height() - scaleHeight) / 2); else drawArea.setY(size.height() - scaleHeight); drawArea.setWidth(scaleWidth); drawArea.setHeight(scaleHeight); } painter->fillRect(drawArea, texture); RBMovable::paint(painter, option, widget); } void RBAlbumArt::saveGeometry() { QPointF origin = pos(); QRectF bounds = boundingRect(); node->modParam(static_cast(origin.x()), 0); node->modParam(static_cast(origin.y()), 1); node->modParam(static_cast(bounds.width()), 2); node->modParam(static_cast(bounds.height()), 3); } '>10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#include "rocklibc.h"

unsigned long int strtoul(const char *ptr, char **endptr, int base)
{
  int neg = 0, overflow = 0;
  unsigned long int v=0;
  const char* orig;
  const char* nptr=ptr;

  while(isspace(*nptr)) ++nptr;

  if (*nptr == '-') { neg=1; nptr++; }
  else if (*nptr == '+') ++nptr;
  orig=nptr;
  if (base==16 && nptr[0]=='0') goto skip0x;
  if (base) {
    register unsigned int b=base-2;
    if (__unlikely(b>34)) { errno=EINVAL; return 0; }
  } else {
    if (*nptr=='0') {
      base=8;
skip0x:
      if ((nptr[1]=='x'||nptr[1]=='X') && isxdigit(nptr[2])) {
	nptr+=2;
	base=16;
      }
    } else
      base=10;
  }
  while(__likely(*nptr)) {
    register unsigned char c=*nptr;
    c=(c>='a'?c-'a'+10:c>='A'?c-'A'+10:c<='9'?c-'0':0xff);
    if (__unlikely(c>=base)) break;	/* out of base */
    {
      register unsigned long x=(v&0xff)*base+c;
      register unsigned long w=(v>>8)*base+(x>>8);
      if (w>(ULONG_MAX>>8)) overflow=1;
      v=(w<<8)+(x&0xff);
    }
    ++nptr;
  }
  if (__unlikely(nptr==orig)) {		/* no conversion done */
    nptr=ptr;
    errno=EINVAL;
    v=0;
  }
  if (endptr) *endptr=(char *)nptr;
  if (overflow) {
    errno=ERANGE;
    return ULONG_MAX;
  }
  return (neg?-v:v);
}