コード例 #1
0
ファイル: RDHeaderView.cpp プロジェクト: silvesthu/renderdoc
void RDHeaderView::cacheSectionMinSizes()
{
  m_sectionMinSizes.resize(count());
  m_sectionMinSizesTotal = 0;

  for(int i = 0; i < m_sectionMinSizes.count(); i++)
  {
    int sz = 0;

    // see if we can fetch the column/row size hint from the item view
    QAbstractItemView *view = qobject_cast<QAbstractItemView *>(parent());
    if(view)
    {
      if(orientation() == Qt::Horizontal)
        sz = view->sizeHintForColumn(i);
      else
        sz = view->sizeHintForRow(i);
    }

    // also include the size for the header as another minimum
    if(orientation() == Qt::Horizontal)
      sz = qMax(sz, sectionSizeFromContents(i).width());
    else
      sz = qMax(sz, sectionSizeFromContents(i).height());

    // finally respect the minimum section size specified
    sz = qMax(sz, minimumSectionSize());

    // update the minimum size for this section and count the total which we'll need
    m_sectionMinSizes[i] = sz;
    m_sectionMinSizesTotal += m_sectionMinSizes[i];
  }
}
コード例 #2
0
void QGraphicsCompleter::showPopup(const QRect& rect)
{
    Qt::LayoutDirection dir = Qt::LeftToRight;
    const int maxVisibleItems = 7;
    QPointF pos;
    int rh, w;

    const QRect screen = p_proxyPopup->scene()->views().at(0)->viewport()->geometry();
    QAbstractItemView *popup = static_cast<QAbstractItemView *>(p_proxyPopup->widget());

    int h = (popup->sizeHintForRow(0) * qMin(maxVisibleItems, popup->model()->rowCount()) + 3) + 3;
    QScrollBar *hsb = popup->horizontalScrollBar();
    if (hsb && hsb->isVisible())
        h += popup->horizontalScrollBar()->sizeHint().height();

    if (rect.isValid()) {
        rh = rect.height();
        w = rect.width();
        pos = rect.bottomLeft();
    } else {
        rh = graphicsItem()->boundingRect().height();
        pos = graphicsItem()->mapRectToScene(
                graphicsItem()->boundingRect()).bottomLeft();
        w = popup->width();
    }

    if (w > screen.width())
        w = screen.width();
    if ((pos.x() + w) > (screen.x() + screen.width()))
        pos.setX(screen.x() + screen.width() - w);
    if (pos.x() < screen.x())
        pos.setX(screen.x());

    int top = pos.y() - rh - screen.top() + 2;
    int bottom = screen.bottom() - pos.y();
    h = qMax(h, popup->minimumHeight());
    if (h > bottom) {
        h = qMin(qMax(top, bottom), h);

        if (top > bottom)
            pos.setY(pos.y() - h - rh+ 2);
    }

    popup->setGeometry(pos.x(), pos.y(), w, h+5);
    p_proxyPopup->update();

    if (!p_proxyPopup->isVisible())
        p_proxyPopup->show();

}
コード例 #3
0
ファイル: toolbarsearch.cpp プロジェクト: porphyr/arora
void ToolbarSearch::setupMenu()
{
    if (m_suggestions.isEmpty()
            || (m_model->rowCount() > 0
                && m_model->item(0) != m_suggestionsItem)) {
        m_model->clear();
        m_suggestionsItem = 0;
    } else {
        m_model->removeRows(1, m_model->rowCount() -1 );
    }

    QFont boldFont;
    boldFont.setBold(true);
    if (!m_suggestions.isEmpty()) {
        if (m_model->rowCount() == 0) {
            if (!m_suggestionsItem) {
                m_suggestionsItem = new QStandardItem();
                m_suggestionsItem->setFont(boldFont);
                retranslate();
            }
            m_model->appendRow(m_suggestionsItem);
        }
        for (int i = 0; i < m_suggestions.count(); ++i) {
            const QString &text = m_suggestions.at(i);
            m_model->appendRow(new QStandardItem(text));
        }
    }

    if (m_recentSearches.isEmpty()) {
        m_recentSearchesItem = new QStandardItem(tr("No Recent Searches"));
        m_recentSearchesItem->setFont(boldFont);
        m_model->appendRow(m_recentSearchesItem);
    } else {
        m_recentSearchesItem = new QStandardItem(tr("Recent Searches"));
        m_recentSearchesItem->setFont(boldFont);
        m_model->appendRow(m_recentSearchesItem);
        for (int i = 0; i < m_recentSearches.count(); ++i) {
            QString text = m_recentSearches.at(i);
            m_model->appendRow(new QStandardItem(text));
        }
    }

    QAbstractItemView *view = completer()->popup();
    view->setFixedHeight(view->sizeHintForRow(0) * m_model->rowCount() + view->frameWidth() * 2);
}