Exemplo n.º 1
0
void IngameWindow::MouseLeftDown(const MouseCoords& mc)
{
    // Maus muss sich auf der Titelleiste befinden
    Rect title_rect(
        static_cast<unsigned short>(pos_.x + LOADER.GetImageN("resource", 36)->getWidth()),
        pos_.y,
        static_cast<unsigned short>(width_ - LOADER.GetImageN("resource", 36)->getWidth() - LOADER.GetImageN("resource", 37)->getWidth()),
        LOADER.GetImageN("resource", 43)->getHeight()
        );

    if(Coll(mc.x, mc.y, title_rect))
    {
        // Start mit Bewegung
        isMoving = true;
        lastMousePos = DrawPoint(mc.x, mc.y);
    }

    // beiden Buttons oben links und rechts prfen
    const Rect rec[2] =
    {
        GetLeftButtonRect(),
        GetRightButtonRect()
    };

    for(unsigned char i = 0; i < 2; ++i)
    {
        if(Coll(mc.x, mc.y, rec[i]))
            button_state[i] = BUTTON_PRESSED;
    }
}
Exemplo n.º 2
0
void Export::export_pdf(int columns)
{
    // 1200 dpi -> 200 dpi ~ 12pt font;
    // dims: 9583 x 13699

    int twelve_point = 200;
    int total_width = 9583;
    int total_height = 13699;
    int remaining_height = total_height;
    int puzzle_width = columns > 15 ? 6000 : 5000;
    int puzzle_height = puzzle_width;
    int clues_three_cols_width = total_width - puzzle_width;
    int clues_col_width_w_gap = clues_three_cols_width / 3;
    int col_gap = 225;  // empirically determined
    int clues_col_width = clues_col_width_w_gap - col_gap;
    int col_num = 1;

    //metadata
    QString title = qvariant_cast<QString>(m_metadata.takeAt(0));
    QString date = qvariant_cast<QString>(m_metadata.takeAt(0));
    QString author = qvariant_cast<QString>(m_metadata.takeAt(0));
    QString author_date = author + "          " + date;

    QRect title_rect(0, 0, total_width, (twelve_point * 2));
    remaining_height -= (twelve_point * 2);

    QPoint info_top_left(0, (title_rect.bottom() + 100));
    QSize author_date_size((total_width - puzzle_width), twelve_point);
    QRect author_date_rect(info_top_left, author_date_size);
    remaining_height -= (twelve_point + 100);

    //clues
    QPoint clues_col_top_left(0, (author_date_rect.bottom() + 300));
    remaining_height -= 300;
    QSize clues_col_size(clues_col_width, remaining_height);
    QRect whole_clues_col(clues_col_top_left, clues_col_size);
    QRect eaten_clues_col = whole_clues_col;

    //puzzles
    QImage puzzle = qvariant_cast<QImage>(m_images.takeAt(0));
    QImage puz_ans = qvariant_cast<QImage>(m_images.takeAt(0));
    QSize puz_size(puzzle_width, puzzle_height);
    QPoint puz_top_left((total_width - puzzle_width), title_rect.bottom());
    QRect puz_rect(puz_top_left, puz_size);
    QRect ans_rect(0, 0, (puzzle_width / 2), (puzzle_height / 2));

    //filepath
    QString base_path = QDir::homePath();
    QString file_name = title == "" ? "/untitled.pdf" : "/" + title + ".pdf";

    // PAINTING //
    QPdfWriter pdf(base_path + file_name);
    QPainter painter;

    // getting info on available space in the appropriate units (used for the seemingly random
    // numbers for the constants at the start of the function).
//    QPageLayout layout = pdf.pageLayout();
//    int resolution = pdf.resolution();
//    QRect printable_rect = layout.paintRectPixels(resolution);

    painter.begin(&pdf);

    // make the title
    QFont font = painter.font();
    font.setPixelSize(twelve_point * 2);
    font.setCapitalization(QFont::SmallCaps);
    painter.setFont(font);
    painter.drawText(title_rect, title);

    // make author and date
    font.setPixelSize(twelve_point / 2);
    font.setCapitalization(QFont::MixedCase);
    font.setItalic(true);
    painter.setFont(font);
    painter.drawText(author_date_rect, author_date);

    // across header
    font.setPixelSize(150);
    font.setBold(true);
    font.setItalic(false);
    painter.setFont(font);

    QString across_header = qvariant_cast<QString>(m_acrosses.takeAt(0));
    QRect space_needed = painter.boundingRect(eaten_clues_col, Qt::TextWordWrap, across_header);
    draw_clue(painter, eaten_clues_col, across_header, space_needed, Qt::AlignHCenter);
    eaten_clues_col.setTop(eaten_clues_col.top() + 100);  //ref: Export::paint_clues

    // across clues
    font.setBold(false);
    painter.setFont(font);
    paint_clues(painter, eaten_clues_col, m_acrosses, col_num, whole_clues_col, col_gap, puz_rect);

    // down header
    QVariantList down_header;
    down_header.append(m_downs.takeAt(0));  // is there a better way?

    font.setBold(true);
    painter.setFont(font);
    paint_clues(painter, eaten_clues_col, down_header, col_num, whole_clues_col,
                col_gap, puz_rect, Qt::AlignHCenter);

    // down clues
    font.setBold(false);
    painter.setFont(font);
    paint_clues(painter, eaten_clues_col, m_downs, col_num, whole_clues_col, col_gap, puz_rect);

    // images
    painter.drawImage(puz_rect, puzzle);
    pdf.newPage();
    painter.drawImage(ans_rect, puz_ans);

    painter.end();

    emit export_completed(file_name);
}
Exemplo n.º 3
0
    void URLCompletions::draw(Menu &menu, const WRect &rect, WDrawable &d)
    {
      const menu::Style &style = menu.style();

      fill_rect(d, style.completions_background, rect);

      draw_border(d, style.border_color, style.border_pixels,
                  style.border_pixels, style.border_pixels, 0,
                  rect);

      WRect rect2 = rect.inside_border(style.border_pixels, style.border_pixels, style.border_pixels, 0);

      size_t begin_pos_index, end_pos_index;

      if (selected >= lines)
      {
        end_pos_index = selected + 1;
        begin_pos_index = end_pos_index - lines;
      } else
      {
        end_pos_index = lines;
        begin_pos_index = 0;
      }
      if (end_pos_index > completions.size())
        end_pos_index = completions.size();

      size_t base_y = rect2.y;

      for (size_t pos_index = begin_pos_index; pos_index < end_pos_index; ++pos_index)
      {
        int row = pos_index - begin_pos_index;
        WRect cell_rect(rect2.x,
                        base_y + style.completions_spacing + line_height * row,
                        rect2.width, line_height);

        const WColor *url_color, *title_color;

        WColor title_unselected(d.draw_context(), "gold1");
        WColor title_selected(d.draw_context(), "black");

        if ((int)pos_index == selected)
        {
          fill_rect(d, entry_style.selected_background, cell_rect);

          url_color = &entry_style.selected_url_foreground;
          title_color = &entry_style.selected_title_foreground;
        } else
        {
          url_color = &entry_style.normal_url_foreground;
          title_color = &entry_style.normal_title_foreground;
        }

        WRect url_rect(cell_rect.x, cell_rect.y, cell_rect.width / 2,
                       cell_rect.height);

        WRect title_rect(cell_rect.x + cell_rect.width / 2,
                         cell_rect.y,
                         cell_rect.width - cell_rect.width / 2, cell_rect.height);

        WRect url_rect2 = url_rect.inside_border(style.completions_spacing);

        WRect url_rect3 = url_rect2.inside_lr_tb_border
          (style.label.horizontal_padding,
           style.label.vertical_padding);

        WRect title_rect2 = title_rect.inside_border(style.completions_spacing);

        WRect title_rect3 = title_rect2.inside_lr_tb_border
          (style.label.horizontal_padding,
           style.label.vertical_padding);

        draw_label(d, completions[pos_index].url, style.label.font, *url_color, url_rect3);
        draw_label(d, completions[pos_index].title, style.label.font, *title_color, title_rect3);
      }
    }
Exemplo n.º 4
0
void QuestsItemDelegate::paint(QPainter *painter,
                               const QStyleOptionViewItem &option,
                               const QModelIndex &index) const {

  // Paint the default background
  //QStyledItemDelegate::paint(painter, option, index);

  // Save painter initial state before any modification
  painter->save();
  painter->setRenderHint(QPainter::Antialiasing, true);
  painter->setRenderHint(QPainter::TextAntialiasing, true);

  const QRect& global_rect = option.rect;
  const int padding = 4;
  const QFont &default_font = option.font;

  // Retrieve quest info
  const QVariant& data = index.model()->data(index, Qt::DisplayRole);
  const QuestsModel::QuestInfo& quest_info = data.value<QuestsModel::QuestInfo>();

  // Retrieve info from option
  QStyle::State state = option.state;
  const QStyleOptionViewItem::ViewItemFeatures& features = option.features;
  const QPalette& palette = option.palette;
  bool active = state.testFlag(QStyle::State_Active);
  bool enabled = state.testFlag(QStyle::State_Enabled);
  bool selected = state.testFlag(QStyle::State_Selected);
  bool alternate_rows = features.testFlag(QStyleOptionViewItem::Alternate);
  bool should_alternate = alternate_rows && index.row() % 2;
  //auto focused = state.testFlag(QStyle::State_HasFocus);
  //auto mouse_over = state.testFlag(QStyle::StateFlag::State_MouseOver);

  // Compute colors
  QPalette::ColorGroup color_group =
      !enabled ? QPalette::Disabled
               : (active ? QPalette::Active : QPalette::Inactive);
  QPalette::ColorRole color_role =
      selected ? QPalette::Highlight
               : (should_alternate ? QPalette::AlternateBase : QPalette::Light);
  const QBrush& background = palette.brush(color_group, color_role);

  // Paint background
  painter->fillRect(option.rect, background);

  // Paint icon
  QRect icon_rect(
      global_rect.left() + padding * 2,
      global_rect.top() + (global_rect.height() - _iconSize.height()) / 2,
      _iconSize.width(),
      _iconSize.height());
  QIcon::Mode icon_mode = enabled ? QIcon::Normal : QIcon::Disabled;
  const QPixmap& pixmap = quest_info.icon.pixmap(_iconSize, icon_mode, QIcon::On);
  painter->drawPixmap(icon_rect, pixmap);

  // Compute title font
  QFont title_font = default_font;
  title_font.setPointSize(title_font.pointSize() * 1.25);
  title_font.setWeight(QFont::DemiBold);

  // Compute author font
  QFont author_font = default_font;
  author_font.setWeight(QFont::Normal);

  // Set temporarily the font to compute the title text height
  painter->save();
  painter->setFont(title_font);
  const QFontMetrics& title_font_metrics = painter->fontMetrics();
  painter->restore();

  // Set temporarily the font to compute the author text height
  painter->save();
  painter->setFont(author_font);
  const QFontMetrics& author_font_metrics = painter->fontMetrics();
  painter->restore();

  // Compute author and title text rects
  int title_rect_left = icon_rect.right() + padding * 3;
  int title_rect_width = global_rect.width() - title_rect_left - padding;
  int title_rect_height = title_font_metrics.height();

  int author_rect_left = title_rect_left;
  int author_rect_width = title_rect_width;
  int author_rect_height = author_font_metrics.height();

  QRect title_rect(title_rect_left, 0, title_rect_width, title_rect_height);
  QRect author_rect(author_rect_left, title_rect_height, author_rect_width,
                    author_rect_height);

  int global_text_height = author_rect.bottom() - title_rect.top();
  int global_text_top = (global_rect.height() - global_text_height) / 2;

  int y_translate = global_rect.top() + global_text_top;
  title_rect.translate(0, y_translate);
  author_rect.translate(0, y_translate);

  // Compute title text color
  QPalette::ColorRole pen_color_role = selected ? QPalette::HighlightedText
                               : QPalette::Text;
  const QColor& title_pen_color = palette.brush(color_group, pen_color_role).color();

  // Paint title text
  const QString& title_text = QString::fromStdString(quest_info.properties.get_title());
  if (!title_text.isEmpty()) {
    QString title_elided_text = title_font_metrics.elidedText(title_text,
                                                              Qt::ElideRight,
                                                              title_rect_width);
    painter->setPen(title_pen_color);
    painter->setFont(title_font);
    painter->drawText(title_rect, title_elided_text);
  }

  // Compute title text color
  const QColor& author_pen_color =
      palette.brush(QPalette::Disabled, pen_color_role).color();

  // Paint author text
  QString separator = QString(" %1 ").arg(QChar(0x2022)); // bullet

  QStringList secondary_info;
  QString author_text =
          QString::fromStdString(quest_info.properties.get_author());
  QString date_string =
          QString::fromStdString(quest_info.properties.get_release_date());
  QDate date = QDate::fromString(date_string, "yyyyMMdd");
  QString date_text = date.toString("yyyy");
  if (!date_text.isEmpty()) {
    secondary_info << date_text;
  }
  if (!author_text.isEmpty()) {
    secondary_info << author_text;
  }

  if (!secondary_info.isEmpty()){
    QString secondary_text = secondary_info.join(separator);
    QString secondary_elided_text = author_font_metrics.elidedText(
        secondary_text, Qt::ElideRight, author_rect_width);
    painter->setPen(author_pen_color);
    painter->setFont(author_font);
    painter->drawText(author_rect, secondary_elided_text);
  }
  // Restore painter initial state
  painter->restore();
}