protected void drawBackground(QPainter painter, QRectF exposed) {
   // Draws all tiles that intersect the exposed area.
   for (int y = 0; y < numTilesV; ++y) {
     for (int x = 0; x < numTilesH; ++x) {
       QRectF rect = rectForTile(x, y);
       if (exposed.intersects(rect)) painter.drawPixmap(rect.topLeft(), tiles[y][x]);
     }
   }
 }
    @Override
    protected void paintEvent(QPaintEvent e) {
      QPainter p = new QPainter(this);

      switch (transition) {
        case Fade:
          p.drawPixmap(0, 0, start);
          p.setOpacity(level);
          p.drawPixmap(0, 0, end);
          break;
        case ScrollLeft:
          p.drawPixmap(0, 0, end);
          p.drawPixmap((int) (level * width()), 0, start);
          break;
        case ScrollRight:
          p.drawPixmap(0, 0, end);
          p.drawPixmap((int) (-level * width()), 0, start);
          break;
        case ScrollUp:
          p.drawPixmap(0, 0, end);
          p.drawPixmap(0, (int) (-level * height()), start);
          break;
        case ScrollDown:
          p.drawPixmap(0, 0, end);
          p.drawPixmap(0, (int) (level * height()), start);
          break;
        case SplitHorizontal:
          if (level < 0.2) {
            level *= 5;
            p.drawLine(0, height() / 2, (int) (level * width()), height() / 2);
          } else {
            level = (level - 0.2) / 0.8;
            int h2 = start.height() / 2;
            p.drawPixmap(0, 0, end);
            p.drawPixmap(
                0, (int) (-level * height()), start.width(), h2, start, 0, 0, start.width(), h2);
            p.drawPixmap(
                0,
                (int) (level * height()) + h2,
                start.width(),
                h2,
                start,
                0,
                h2,
                start.width(),
                h2);
          }
          break;
        case SplitVertical:
          if (level < 0.2) {
            level *= 5;
            p.drawLine(width() / 2, 0, width() / 2, (int) (level * height()));
          } else {
            level = (level - 0.2) / 0.8;
            int w2 = start.width() / 2;
            p.drawPixmap(0, 0, end);
            p.drawPixmap(
                (int) (level * width()) + w2,
                0,
                w2,
                start.height(),
                start,
                w2,
                0,
                w2,
                start.height());
            p.drawPixmap(
                (int) (-level * height()), 0, w2, start.height(), start, 0, 0, w2, start.height());
          }
          break;
        case Rotate:
          p.eraseRect(rect());

          p.setRenderHint(RenderHint.SmoothPixmapTransform);
          p.rotate(level * 90);
          p.drawPixmap(0, 0, start);

          p.rotate(-90);
          p.drawPixmap(0, 0, end);
          break;

        case Rect:
          int w = start.width();
          int h = start.height();

          p.drawPixmap(
              (int) (w / 2 - w / 2 * level),
              (int) (h / 2 - h / 2 * level),
              end,
              (int) (w / 2 - w / 2 * level),
              (int) (h / 2 - h / 2 * level),
              (int) (w * level),
              (int) (h * level));
          p.drawRoundRect(
              (int) (w / 2 - w / 2 * level),
              (int) (h / 2 - h / 2 * level),
              (int) (w * level),
              (int) (h * level),
              10,
              10);
          break;

        case Flip:
          double l = Math.sin(level * Math.PI / 2);

          p.eraseRect(rect());
          p.setRenderHint(RenderHint.SmoothPixmapTransform);
          if (l < 0.5) {
            p.translate(0, height() * l);
            p.scale(1, 1 - l * 2);
            p.drawPixmap(0, 0, start);
          } else {
            p.translate(0, height() * (1 - l));
            p.scale(1, (0.5 - l) * -2);
            p.drawPixmap(0, 0, end);
          }
          break;
        case Stuff:
          p.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform);
          p.fillRect(rect(), palette().brush(backgroundRole()));

          int x = (int) ((1 - level) * width());
          int h2 = height() / 2;

          QTransform t = new QTransform();
          t.translate(x, h2);
          t.rotate(level * 90, Qt.Axis.YAxis);
          p.setTransform(t);
          p.drawPixmap(-start.width(), -h2, start);

          t = new QTransform();
          t.translate(x, h2);
          t.rotate((1 - level) * -90, Qt.Axis.YAxis);
          p.setTransform(t);
          p.drawPixmap(0, -h2, end);
      }
    }