예제 #1
0
// Called by thememanager when theme or theme geometry changes. Redraw and resize
// this display.
void DisplayIntro::changeTheme()
{
  // Retrieve theme data
  KConfigGroup config = thememanager()->config(id());

  // Retrieve background pixmap
  QString bgsvgid = config.readEntry("background-svgid");
  QPixmap pixmap  = thememanager()->getPixmap(bgsvgid, scene()->sceneRect().size().toSize());
  scene()->setBackgroundBrush(pixmap);
  mView->update();
}
예제 #2
0
// Store and display current player. This is done by coloring the
// name text sprite.
void ScoreSprite::setTurn(int no)
{
	// Retrieve theme data
  KConfigGroup config     = thememanager()->config(id());
  QColor fontColorActive  = config.readEntry("fontColorActive", QColor(Qt::white));
  QColor fontColor0       = config.readEntry("fontColorPlayer0", QColor(Qt::white));
  QColor fontColor1       = config.readEntry("fontColorPlayer1", QColor(Qt::white));

  // Store data
  mTurn = no;

  // Switch color
  if (no==0)
  {
    mName[0]->setDefaultTextColor(fontColorActive);
    mName[1]->setDefaultTextColor(fontColor1);
  }
  else
  {
    mName[0]->setDefaultTextColor(fontColor0);
    mName[1]->setDefaultTextColor(fontColorActive);
  }

  update();
}
예제 #3
0
// Main themable function. Called for any theme change. The sprites needs to
// resiez and redraw here.
void CardSprite::changeTheme()
{
  // Get scaling change
  double oldscale = this->getScale();
  double scale    = thememanager()->getScale();
  Themable::setScale(scale);

  // Retrieve theme data from configuration
  KConfigGroup config = thememanager()->config(id());
  double width        = config.readEntry("width", 1.0);
  width *= scale;
  mWidth = width; // Store for later use

  // Z-value by program only
  // Nothing to do

  // Animation
  int startFrame      = config.readEntry("start-frame", 0);
  int endFrame        = config.readEntry("end-frame", 0);

  // Pos py program only
  setPos(x()*scale/oldscale, y()*scale/oldscale);

  // Frames (loaded on demand)
  mFrames.clear();
  mHotspots.clear();
  QPixmap nullPixmap;
  for (int i=startFrame;i<=endFrame;i++)
  {
    mFrames.append(nullPixmap);
    mHotspots.append(QPointF(0.0,0.0));
  }

  // Start with backside to save calculation time
  if (mCurrentFrame < 0) mCurrentFrame = endFrame;


  // Set pixmap to sprite
  setFrame(mCurrentFrame, true);
  update();
}
예제 #4
0
// Store and display the button text
void ButtonSprite::setText(const QString &s)
{
  if (s.isNull()) 
  {
    mText->hide();
  }
  else
  {
    //mText->setPlainText(s);
    // Center
    mText->setHtml("<div align=\"center\">"+s+"</div>");
    mText->show();
    thememanager()->updateTheme(this);
  }
}
예제 #5
0
// Redraw the theme.
void ButtonSprite::changeTheme()
{
  // The main display is handled by the parent
  PixmapSprite::changeTheme();
  
  // Retrieve our size
  double width  = this->boundingRect().width();
  double height = this->boundingRect().height();

  // Retrieve theme data
  KConfigGroup config = thememanager()->config(id());

  // Text available?
  if (mText->isVisible())
  {
    // Calculate proper font size
    double fontHeight = config.readEntry("fontHeight", 1.0);
    fontHeight *= height;
    double textWidth = config.readEntry("textWidth", 1.0);
    textWidth *= width;
    double textHeight = config.readEntry("textHeight", 1.0);
    textHeight *= height;
    
    // Retrieve font color
    QColor fontColor;
    fontColor = config.readEntry("fontColor", QColor(Qt::white));

    // Create and set current font
    QFont font;
    fontHeight = KFontUtils::adaptFontSize(mText, textWidth, textHeight, fontHeight, 8.0);
    font.setPointSizeF(fontHeight);

    // Set font and color for all text items
    mText->setFont(font);   
    mText->setDefaultTextColor(fontColor);
    mText->setTextWidth(textWidth);

    // Set position of sub sprites
    QRectF bounding = mText->boundingRect();
    mText->setPos((width - bounding.width()) / 2.0,
                  (height - bounding.height()) / 2.0);
  }
}
예제 #6
0
// Set a new bitmap into the sprite. If the number is the same as the
// current one, nothing is done.
void CardSprite::setFrame(int no, bool force)
{
  if (!force && no == mCurrentFrame) return;
  if (no<0 || no >=mFrames.count()) return;

  // Calulate Pixmap (only done if necessary)
  calcFrame(no);

  // Set frame pixmap
  QPixmap pixmap = mFrames.at(no);
  setPixmap(pixmap);

  // Translation
  QPoint offset   = thememanager()->getOffset();
  resetTransform();
  translate(mHotspots[no].x()+offset.x(), mHotspots[no].y()+offset.y());

  mCurrentFrame = no;
  update();
}
예제 #7
0
// Redraw the theme.
void ScoreSprite::changeTheme()
{
  // The main display is handled by the parent
  PixmapSprite::changeTheme();

  // Retrieve our size
  double width  = this->boundingRect().width();
  double height = this->boundingRect().height();

  // Retrieve theme data
  KConfigGroup config = thememanager()->config(id());
  QPointF posWon0     = config.readEntry("posWon0", QPointF(1.0,1.0));
  QPointF posWon1     = config.readEntry("posWon1", QPointF(1.0,1.0));
  QPointF posDraw0    = config.readEntry("posDraw0", QPointF(1.0,1.0));
  QPointF posDraw1    = config.readEntry("posDraw1", QPointF(1.0,1.0));
  QPointF posLoss0    = config.readEntry("posLoss0", QPointF(1.0,1.0));
  QPointF posLoss1    = config.readEntry("posLoss1", QPointF(1.0,1.0));
  QPointF posBreak0   = config.readEntry("posBreak0", QPointF(1.0,1.0));
  QPointF posBreak1   = config.readEntry("posBreak1", QPointF(1.0,1.0));
  QPointF posName0    = config.readEntry("posName0", QPointF(1.0,1.0));
  QPointF posName1    = config.readEntry("posName1", QPointF(1.0,1.0));
  QPointF posAI       = config.readEntry("posAI", QPointF(1.0,1.0));

  // Calculate proper font size
  double fontHeight = config.readEntry("fontHeight", 1.0);
  fontHeight *= height;
  double fontWidth = config.readEntry("fontWidth", 1.0);
  fontWidth *= width;
  
  // Retrieve font color
  QColor fontColor[2];
  fontColor[0] = config.readEntry("fontColorPlayer0", QColor(Qt::white));
  fontColor[1] = config.readEntry("fontColorPlayer1", QColor(Qt::white));

  // Set position of sub sprites
  mWon[0]->setPos(posWon0.x()*width, posWon0.y()*height);
  mWon[1]->setPos(posWon1.x()*width, posWon1.y()*height);
  mDraw[0]->setPos(posDraw0.x()*width, posDraw0.y()*height);
  mDraw[1]->setPos(posDraw1.x()*width, posDraw1.y()*height);
  mLoss[0]->setPos(posLoss0.x()*width, posLoss0.y()*height);
  mLoss[1]->setPos(posLoss1.x()*width, posLoss1.y()*height);
  mBreak[0]->setPos(posBreak0.x()*width, posBreak0.y()*height);
  mBreak[1]->setPos(posBreak1.x()*width, posBreak1.y()*height);
  mName[0]->setPos(posName0.x()*width, posName0.y()*height);
  mName[1]->setPos(posName1.x()*width, posName1.y()*height);


  // Create and set current font
  QFont font;
  font.setPixelSize(int(fontHeight));

  // Set font and color for all text items
  for (int i=0; i<2; i++)
  {
    mWon[i]->setFont(font);   
    mDraw[i]->setFont(font); 
    mLoss[i]->setFont(font);
    mBreak[i]->setFont(font);
    mName[i]->setFont(font);
    
    mWon[i]->setDefaultTextColor(fontColor[i]);   
    mDraw[i]->setDefaultTextColor(fontColor[i]);
    mLoss[i]->setDefaultTextColor(fontColor[i]);
    mBreak[i]->setDefaultTextColor(fontColor[i]);
    mName[i]->setDefaultTextColor(fontColor[i]);

    mWon[i]->setTextWidth(fontWidth);   
    mDraw[i]->setTextWidth(fontWidth);
    mLoss[i]->setTextWidth(fontWidth);
    mBreak[i]->setTextWidth(fontWidth);
    mName[i]->setTextWidth(fontWidth);

    // Restore the frame of the input device sprite
    if (mInputFrame[i]>=0) mInput[i]->setFrame(mInputFrame[i]);
  }

  // Update next player
  if (mTurn>=0) setTurn(mTurn);
}
예제 #8
0
// Animation loop
void DisplayIntro::loop()
{
  int no = mCards.size();
  // Catch no card error
  if (no<1) return;

  // Retrieve theme data
  KConfigGroup cardconfig = thememanager()->config(QLatin1String( "card" ));
  double card_width       = cardconfig.readEntry("width", 1.0);
  KConfigGroup config     = thememanager()->config(id());
  QPointF start_shift     = config.readEntry("start-shift", QPointF(1.0,1.0));
  QPointF start_pos       = config.readEntry("start-pos", QPointF(1.0,1.0));
  double time_clear_in    = config.readEntry("time-clear-in", 1.0);
  double time_clear_out   = config.readEntry("time-clear-out", 1.0);
  double aspectRatio      = thememanager()->aspectRatio();


  // Display the intro text delayed
  if (mAnimCnt == 2  && mState == Putting && !mTextShown)
  {
    mTextShown = true;
    QString s1 = i18nc("Title of the game - line 1", "Lieutenant Skat");
    QString s2 = i18nc("Title of the game - line 2", "for");
    QString s3 = i18nc("Title of the game - line 3", "K D E");

    // Text sprite title foreground
    TextSprite* text1a = new TextSprite(s1, QLatin1String( "name-front" ), mTheme, scene());
    mSprites.append(text1a);
    text1a->show();

    // Text sprite title background
    TextSprite* text1b = new TextSprite(s1, QLatin1String( "name-back" ), mTheme, scene());
    mSprites.append(text1b);
    text1b->show();

    // Text sprite title foreground
    TextSprite* text2a = new TextSprite(s2, QLatin1String( "for-front" ), mTheme, scene());
    mSprites.append(text2a);
    text2a->show();

    // Text sprite title background
    TextSprite* text2b = new TextSprite(s2, QLatin1String( "for-back" ), mTheme, scene());
    mSprites.append(text2b);
    text2b->show();

    // Text sprite title foreground
    TextSprite* text3a = new TextSprite(s3, QLatin1String( "kde-front" ), mTheme, scene());
    mSprites.append(text3a);
    text3a->show();

    // Text sprite title background
    TextSprite* text3b = new TextSprite(s3, QLatin1String( "kde-back" ), mTheme, scene());
    mSprites.append(text3b);
    text3b->show();
  }

  // Display a card
  if (mAnimCnt < no && mState == Putting)
  {
    double factor = double(mAnimCnt)/double(no-1);
    double fsin = sin(factor*M_PI);

    CardSprite* sprite = mCards[mAnimCnt];

    QPointF pos;
    if (mAnimCnt %2 == 0)
    {
      pos  = QPointF(start_pos.x(), start_pos.y());
      pos += QPointF(start_shift.x() * fsin, start_shift.y() * factor);
    }
    else
    {
      pos  = QPointF(1.0-start_pos.x()-card_width, start_pos.y());
      pos += QPointF(-start_shift.x() * fsin, start_shift.y() * factor);
    }
    sprite->setBackside();
    sprite->setPosition(pos);
    sprite->setZValue(50+mAnimCnt);
    sprite->show();
    mAnimCnt++;
  }
  // Change state to turning
  else if (mState == Putting)
  {
    mState   = Turning;
    mAnimCnt = 0;
  }
  // Turn cards
  else if (mAnimCnt < no && mState == Turning)
  {
    CardSprite* sprite = mCards[mAnimCnt];
    sprite->setTurning(true);
    mAnimCnt++;
  }
  // Change state to waiting
  else if (mState == Turning)
  {
    mState   = Waiting;
    mAnimCnt = 0;
  }
  // Wait
  else if (mAnimCnt < WAIT_CNT && mState == Waiting)
  {
    mAnimCnt++;
  }
  // Change state to clearing the board
  else if (mState == Waiting)
  {
    mState   = Clearing;
    mAnimCnt = 0;
  }
  // Clear the board, step 1
  else if (mAnimCnt == 0 && mState == Clearing)
  {
    for (int i=0; i<no; i++)
    {
      CardSprite* sprite = mCards[i];
      sprite->setMove(QPointF((1.0-card_width)/2.0, (1.0/aspectRatio-card_width)/2.0), time_clear_in);
    }
    mAnimCnt++;
  }
  // Clear the board, step 2
  else if (mAnimCnt < 30 && mState == Clearing)
  {
    mAnimCnt++;
  }
  // Clear the board, step 3 and change state to waiting
  else if (mState == Clearing)
  {
    for (int i=0; i<no; i++)
    {
      double r = 1.0;
      double x = r*cos(double(i)/double(no-1)*M_PI*2.0) + 0.5;
      double y = r*sin(double(i)/double(no-1)*M_PI*2.0) + 0.5;
      CardSprite* sprite = mCards[i];
      sprite->setMove(QPointF(x,y/aspectRatio), time_clear_out);
    }
    mState = Waiting2;
    mAnimCnt = 0;
  }
  // Wait
  else if (mAnimCnt < WAIT_CNT && mState == Waiting2)
  {
    mAnimCnt++;
  }
  // Restart cycle
  else if (mState == Waiting2)
  {
    for (int i=0; i<no; i++)
    {
      CardSprite* sprite = mCards[i];
      sprite->stop();
    }

    mState   = Putting;
    mAnimCnt = 0;
  }

}
예제 #9
0
void TextSprite::setText(const QString &text)
{
  setPlainText(text);
  thememanager()->updateTheme(this);
}