コード例 #1
0
	void View::update(Core *c){
		if (not _is_transposed){
			_contents_frame.p.x = _frame.p.x;
			_contents_frame.p.y = _frame.p.y;
			_contents_frame.s.w = _frame.s.w;
			_contents_frame.s.h = _frame.s.h - header_height();
		}
		else{
			_contents_frame.p.y = _frame.p.x;
			_contents_frame.p.x = _frame.p.y;
			_contents_frame.s.h = _frame.s.w;
			_contents_frame.s.w = _frame.s.h - header_height();
		}

		_header_frame.p.x = _frame.p.x;
		_header_frame.p.y = _frame.p.y + _frame.s.h - header_height();
		_header_frame.s.w = _frame.s.w;
		_header_frame.s.h = header_height();

		if (not _is_transposed){
			update_contents(c);
		}
		else{
			glPushMatrix();
			double m[16] = {
				0.0, 1.0, 0.0, 0.0,
				1.0, 0.0, 0.0, 0.0,
				0.0, 0.0, 1.0, 0.0,
				0.0, 0.0, 0.0, 1.0,
			};
			glMultMatrixd(m);
			update_contents(c);
			glPopMatrix();
		}

		if (_has_header)
			update_header(c);
	}
コード例 #2
0
	size_t View::max_h() { 
		if (not _is_transposed)
			return max_contents_h()+header_height(); 
		else
			return max_contents_w()+header_height(); 
	}
コード例 #3
0
void GroupedIconView::paintEvent(QPaintEvent* e) {
  // This code was adapted from QListView::paintEvent(), changed to use the
  // visualRect() of items, and to draw headers.

  QStyleOptionViewItemV4 option(viewOptions());
  if (isWrapping())
    option.features = QStyleOptionViewItemV2::WrapText;
  option.locale = locale();
  option.locale.setNumberOptions(QLocale::OmitGroupSeparator);
  option.widget = this;

  QPainter painter(viewport());

  const QRect viewport_rect(e->rect().translated(horizontalOffset(), verticalOffset()));
  QVector<QModelIndex> toBeRendered = IntersectingItems(viewport_rect);

  const QModelIndex current = currentIndex();
  const QAbstractItemModel *itemModel = model();
  const QItemSelectionModel *selections = selectionModel();
  const bool focus = (hasFocus() || viewport()->hasFocus()) && current.isValid();
  const QStyle::State state = option.state;
  const QAbstractItemView::State viewState = this->state();
  const bool enabled = (state & QStyle::State_Enabled) != 0;

  int maxSize = (flow() == TopToBottom)
      ? viewport()->size().width() - 2 * spacing()
      : viewport()->size().height() - 2 * spacing();

  QVector<QModelIndex>::const_iterator end = toBeRendered.constEnd();
  for (QVector<QModelIndex>::const_iterator it = toBeRendered.constBegin(); it != end; ++it) {
    if (!it->isValid()) {
      continue;
    }

    option.rect = visualRect(*it);

    if (flow() == TopToBottom)
      option.rect.setWidth(qMin(maxSize, option.rect.width()));
    else
      option.rect.setHeight(qMin(maxSize, option.rect.height()));

    option.state = state;
    if (selections && selections->isSelected(*it))
      option.state |= QStyle::State_Selected;
    if (enabled) {
      QPalette::ColorGroup cg;
      if ((itemModel->flags(*it) & Qt::ItemIsEnabled) == 0) {
        option.state &= ~QStyle::State_Enabled;
        cg = QPalette::Disabled;
      } else {
        cg = QPalette::Normal;
      }
      option.palette.setCurrentColorGroup(cg);
    }
    if (focus && current == *it) {
      option.state |= QStyle::State_HasFocus;
      if (viewState == EditingState)
        option.state |= QStyle::State_Editing;
    }

    itemDelegate()->paint(&painter, option, *it);
  }

  // Draw headers
  foreach (const Header& header, headers_) {
    const QRect header_rect = QRect(
          header_indent_, header.y,
          viewport()->width() - header_indent_ * 2, header_height());

    // Is this header contained in the area we're drawing?
    if (!header_rect.intersects(viewport_rect)) {
      continue;
    }

    // Draw the header
    DrawHeader(model()->index(header.first_row, 0),
               header_rect.translated(-horizontalOffset(), -verticalOffset()),
               &painter);
  }
}
コード例 #4
0
void GroupedIconView::LayoutItems() {
  if (!model())
    return;

  const int count = model()->rowCount();

  QString last_group;
  QPoint next_position(0, 0);
  int max_row_height = 0;

  visual_rects_.clear();
  visual_rects_.reserve(count);
  headers_.clear();

  for (int i=0 ; i<count ; ++i) {
    const QModelIndex index(model()->index(i, 0));
    const QString group = index.data(Role_Group).toString();
    const QSize size(rectForIndex(index).size());

    // Is this the first item in a new group?
    if (group != last_group) {
      // Add the group header.
      Header header;
      header.y = next_position.y() + max_row_height + header_indent_;
      header.first_row = i;
      header.text = group;

      if (!last_group.isNull()) {
        header.y += header_spacing_;
      }

      headers_ << header;

      // Remember this group so we don't add it again.
      last_group = group;

      // Move the next item immediately below the header.
      next_position.setX(0);
      next_position.setY(header.y + header_height() + header_indent_ + header_spacing_);
      max_row_height = 0;
    }

    // Take into account padding and spacing
    QPoint this_position(next_position);
    if (this_position.x() == 0) {
      this_position.setX(this_position.x() + item_indent_);
    } else {
      this_position.setX(this_position.x() + spacing());
    }

    // Should this item wrap?
    if (next_position.x() != 0 && this_position.x() + size.width() >= viewport()->width()) {
      next_position.setX(0);
      next_position.setY(next_position.y() + max_row_height);
      this_position = next_position;
      this_position.setX(this_position.x() + item_indent_);

      max_row_height = 0;
    }

    // Set this item's geometry
    visual_rects_.append(QRect(this_position, size));

    // Update next index
    next_position.setX(this_position.x() + size.width());
    max_row_height = qMax(max_row_height, size.height());
  }

  verticalScrollBar()->setRange(0, next_position.y() + max_row_height - viewport()->height());
  update();
}