Ejemplo n.º 1
0
void tst_QColumnView::clicked()
{
    ColumnView view;

    QDirModel model;
    view.setModel(&model);
    view.resize(800,300);
    view.show();

    QModelIndex home = model.index(QDir::homePath());
    QVERIFY(home.isValid());
    view.setCurrentIndex(home);
    QTest::qWait(ANIMATION_DELAY);

    QModelIndex parent = home.parent();
    QVERIFY(parent.isValid());

    qRegisterMetaType<QModelIndex>("QModelIndex");
    QSignalSpy clickedSpy(&view, SIGNAL(clicked(const QModelIndex &)));

    QPoint localPoint = view.visualRect(home).center();
    QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, localPoint);
    QCOMPARE(clickedSpy.count(), 1);
    qApp->processEvents();
    
    if (sizeof(qreal) != sizeof(double)) {
        QSKIP("Skipped due to rounding errors", SkipAll);
    }
    
    for (int i = 0; i < view.createdColumns.count(); ++i) {
        QAbstractItemView *column = view.createdColumns.at(i);
        if (column && column->selectionModel() && (column->rootIndex() == home))
                QVERIFY(column->selectionModel()->selectedIndexes().isEmpty());
    }
}
Ejemplo n.º 2
0
/*
 * This slot uses for setting root index in a current view only if a dir was activated.
 * If there are trying to activate a file, nothing will be done.
 */
void MainWindow::slotActivatedOnlyDirs(const QModelIndex &index)
{
    QAbstractItemView *view = 0;
    if (isDir(index) && (view = dynamic_cast<QAbstractItemView *>(sender()) ) )
        view->setRootIndex(index);
    resetRightView(index);
}
Ejemplo n.º 3
0
QWidget *ComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
	QComboBox *comboDelegate = new QComboBox(parent);
	comboDelegate->setModel(model);
	comboDelegate->setEditable(true);
	comboDelegate->setAutoCompletion(true);
	comboDelegate->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive);
	comboDelegate->completer()->setCompletionMode(QCompleter::PopupCompletion);
	comboDelegate->view()->setEditTriggers(QAbstractItemView::AllEditTriggers);
	comboDelegate->lineEdit()->installEventFilter(const_cast<QObject *>(qobject_cast<const QObject *>(this)));
	comboDelegate->view()->installEventFilter(const_cast<QObject *>(qobject_cast<const QObject *>(this)));
	QAbstractItemView *comboPopup = comboDelegate->lineEdit()->completer()->popup();
	comboPopup->setMouseTracking(true);
	connect(comboDelegate, SIGNAL(highlighted(QString)), this, SLOT(testActivation(QString)));
	connect(comboDelegate, SIGNAL(activated(QString)), this, SLOT(fakeActivation()));
	connect(comboPopup, SIGNAL(entered(QModelIndex)), this, SLOT(testActivation(QModelIndex)));
	connect(comboPopup, SIGNAL(activated(QModelIndex)), this, SLOT(fakeActivation()));
	currCombo.comboEditor = comboDelegate;
	currCombo.currRow = index.row();
	currCombo.model = const_cast<QAbstractItemModel *>(index.model());
	keyboardFinished = false;

	// Current display of things on Gnome3 looks like shit, so
	// let`s fix that.
	if (isGnome3Session()) {
		QPalette p;
		p.setColor(QPalette::Window, QColor(Qt::white));
		p.setColor(QPalette::Base, QColor(Qt::white));
		comboDelegate->lineEdit()->setPalette(p);
		comboDelegate->setPalette(p);
	}
	return comboDelegate;
}
Ejemplo n.º 4
0
void FilterItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
	QAbstractItemView *view = qobject_cast<QAbstractItemView*>(parent());
	QLabel *label;

	if (view->indexWidget(index) == 0)
	{
		label = new QLabel();

		label->installEventFilter(filter);
		label->setAutoFillBackground(true);
		label->setFocusPolicy(Qt::TabFocus);
		label->setText(index.data().toString());
		view->setIndexWidget(index, label);
	}

	label = (QLabel*)view->indexWidget(index);

	if (option.state & QStyle::State_Selected)
		if (option.state & QStyle::State_HasFocus)
			label->setBackgroundRole(QPalette::Highlight);
		else
			label->setBackgroundRole(QPalette::Window);
	else
		label->setBackgroundRole(QPalette::Base);
}
Ejemplo n.º 5
0
HistoryWindow::HistoryWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::HistoryWindow)
{
    ui->setupUi(this);

    connect(FlowMeterManager::Instance, SIGNAL(PourFinished()), this, SLOT(pourFinishedSlot()));
    connect(this->ui->scrollPane, SIGNAL(SelectionChanged(int)), this, SLOT(setSelectedIndex(int)));

    picIndex = 0;
    selectedIndex = -1;
    selectedPour = NULL;

    QAbstractItemView *view = this->ui->usersComboBox->view();
    view->setItemDelegate(new CustomComboBoxItem(this));
    connect(this->ui->usersComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(userSelectedSlot(int)));

    vector<User*>::iterator iter;
    for (iter = User::UsersList.begin(); iter != User::UsersList.end(); ++iter)
    {
        User* user = (*iter);
        this->ui->usersComboBox->addItem(QString(user->Name.c_str()));
    }
    this->ui->usersComboBox->setCurrentIndex(-1);

    //QtConcurrent::run(this, &HistoryWindow::updateButtons);
}
Ejemplo n.º 6
0
 /** A method that simplifies checking a view's current item and selection */
 static void verifyCurrentItemAndSelection(const QAbstractItemView& view, const QModelIndex& expectedCurrent, const QModelIndexList& expectedSelection) {
     QCOMPARE(view.currentIndex(), expectedCurrent);
     const QModelIndexList selectedIndexes = view.selectionModel()->selectedIndexes();
     QCOMPARE(selectedIndexes.count(), expectedSelection.count());
     foreach(const QModelIndex& index, expectedSelection) {
         QVERIFY(selectedIndexes.contains(index));
     }
Ejemplo n.º 7
0
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];
  }
}
Ejemplo n.º 8
0
QList<std::shared_ptr<const UICommon::GameFile>> GameList::GetSelectedGames() const
{
  QAbstractItemView* view;
  QSortFilterProxyModel* proxy;
  if (currentWidget() == m_list)
  {
    view = m_list;
    proxy = m_list_proxy;
  }
  else
  {
    view = m_grid;
    proxy = m_grid_proxy;
  }
  QList<std::shared_ptr<const UICommon::GameFile>> selected_list;
  QItemSelectionModel* sel_model = view->selectionModel();
  if (sel_model->hasSelection())
  {
    QModelIndexList index_list =
        currentWidget() == m_list ? sel_model->selectedRows() : sel_model->selectedIndexes();
    for (const auto& index : index_list)
    {
      QModelIndex model_index = proxy->mapToSource(index);
      selected_list.push_back(m_model->GetGameFile(model_index.row()));
    }
  }
  return selected_list;
}
Ejemplo n.º 9
0
void tst_QColumnView::moveGrip()
{
    QFETCH(bool, reverse);
    if (reverse)
        qApp->setLayoutDirection(Qt::RightToLeft);
    ColumnView view;
    TreeModel model;
    view.setModel(&model);
    QModelIndex home = model.thirdLevel();
    view.setCurrentIndex(home);
    view.resize(640, 200);
    view.show();
    QTest::qWait(ANIMATION_DELAY);

    int columnNum = view.createdColumns.count() - 2;
    QVERIFY(columnNum >= 0);
    QObjectList list = view.createdColumns[columnNum]->children();
    QColumnViewGrip *grip = 0;
    for (int i = 0; i < list.count(); ++i) {
        if ((grip = qobject_cast<QColumnViewGrip *>(list[i]))) {
            break;
        }
    }
    if (!grip)
        return;

    QAbstractItemView *column = qobject_cast<QAbstractItemView *>(grip->parent());
    int oldX = column->width();
    QCOMPARE(view.columnWidths()[columnNum], oldX);
    grip->moveGrip(10);
    QCOMPARE(view.columnWidths()[columnNum], (oldX + (reverse ? -10 : 10)));
}
Ejemplo n.º 10
0
void OutputWidget::scrollToIndex( const QModelIndex& idx )
{
    QWidget* w = currentWidget();
    if( !w )
        return;
    QAbstractItemView *view = dynamic_cast<QAbstractItemView*>(w);
    view->scrollTo( idx );
}
Ejemplo n.º 11
0
Palapeli::CollectionDelegate::CollectionDelegate (QObject* parent)
        : QStyledItemDelegate(parent)
{
    QAbstractItemView* view = qobject_cast<QAbstractItemView*>(parent);
    if (view) {
        view->setItemDelegate(this);
        m_viewport = view->viewport();
    }
}
Ejemplo n.º 12
0
void TabPage::forward() {
  // remember current scroll position
  BrowseHistoryItem& item = history_.currentItem();
  QAbstractItemView* childView = folderView_->childView();
  item.setScrollPos(childView->verticalScrollBar()->value());

  history_.forward();
  chdir(history_.currentPath(), false);
}
Ejemplo n.º 13
0
void StartPage::handle_selectionChanged()
{
    QItemSelectionModel * sel_model = qobject_cast<QItemSelectionModel *>(sender());
    Q_ASSERT(sel_model);
    QAbstractItemView * area = area_of(sel_model->model());
    Q_ASSERT(area);
    QString button_name = area->property("open_button_name").toString();
    QAbstractButton * button = findChild<QAbstractButton *>(button_name);
    Q_ASSERT(button);
    button->setEnabled( area->currentIndex().isValid() );
}
Ejemplo n.º 14
0
void TabPage::jumpToHistory(int index)
{
  if(index >=0 && index < history_.size()) {
    // remember current scroll position
    BrowseHistoryItem& item = history_.currentItem();
    QAbstractItemView* childView = folderView_->childView();
    item.setScrollPos(childView->verticalScrollBar()->value());

    history_.setCurrentIndex(index);
    chdir(history_.currentPath(), false);
  }
}
Ejemplo n.º 15
0
void BookmarksWidget::rename()
{
    QWidget *w = focusWidget();
    QAbstractItemView *view = qobject_cast<QAbstractItemView*>(w);
    if (view) {
        QModelIndexList indexes = view->selectionModel()->selectedIndexes();
        if (indexes.isEmpty())
            return;
        QModelIndex index = indexes.first();
        view->edit(index);
    }
}
Ejemplo n.º 16
0
bool TooltipFilter::eventFilter(QObject *obj, QEvent *event)
{
    if (event->type() == QEvent::ToolTip)
    {
        QWidget *w = static_cast<QWidget *>(obj);
        QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
        QPoint pos = helpEvent->globalPos();
        QString itemTooltip = w->toolTip();
        QRect rect = w->rect();

        // case of instrument tables inside a scrollarea viewport
        if (w->objectName() == QLatin1String("qt_scrollarea_viewport"))
        {
            QAbstractItemView* view = qobject_cast<QAbstractItemView*>(obj->parent());
            if (!view)
            {
                return false;
            }
            w = view;

            QPoint position = helpEvent->pos();

            QModelIndex index = view->indexAt(position);
            if (!index.isValid())
            {
                return false;
            }
            rect = view->visualRect(index);
            itemTooltip = view->model()->data(index, Qt::ToolTipRole).toString();
        }

        switch (tooltipType_)
        {
            case TooltipType::NoTooltip:
                QToolTip::hideText();
                return true;
            case TooltipType::StdTooltip:
                QToolTip::showText(pos, itemTooltip, w, rect);
                return true;
            case TooltipType::CustomTooltip:
                break;
            default:
                QToolTip::hideText();
                emit updateTooltipRequest(itemTooltip);
                return true;
        }
    }

    return QObject::eventFilter(obj, event);
}
Ejemplo n.º 17
0
void tst_QColumnView::rowDelegate()
{
    ColumnView view;
    QItemDelegate *d = new QItemDelegate;
    view.setItemDelegateForRow(3, d);

    QDirModel model;
    view.setModel(&model);
    for (int i = 0; i < view.createdColumns.count(); ++i) {
        QAbstractItemView *column = view.createdColumns.at(i);
        QCOMPARE(column->itemDelegateForRow(3), (QAbstractItemDelegate*)d);
    }
    delete d;
}
Ejemplo n.º 18
0
void OutputWidget::copySelection()
{
    QWidget* widget = currentWidget();
    if( !widget )
        return;
    QAbstractItemView *view = dynamic_cast<QAbstractItemView*>(widget);
    if( !view )
        return;

    QClipboard *cb = QApplication::clipboard();
    QModelIndexList indexes = view->selectionModel()->selectedRows();
    QString content;
    Q_FOREACH( const QModelIndex& index, indexes) {
      content += index.data().toString() + '\n';
    }
Ejemplo n.º 19
0
bool BAutoCompletionHelper::eventFilter(QObject *object, QEvent *event)
{
    if (event->type() != QEvent::KeyPress)
        return false;
    QKeyEvent *ke = static_cast<QKeyEvent *>(event);
    if (ke->key() != Qt::Key_Enter && ke->key() != Qt::Key_Return)
        return false;
    QAbstractItemView *popup = qobject_cast<QAbstractItemView *>(object);
    if (!popup || !popup->isVisible())
        return false;
    popup->hide();
    completerActivated(popup->currentIndex());
    ke->ignore();
    return true;
}
Ejemplo n.º 20
0
void QGraphicsCompleter::complete(const QRect &rect)
{
    if (p_proxyPopup->scene() == 0)
        p_graphicsItem->scene()->addItem(p_proxyPopup);

    QAbstractItemView *popup = static_cast<QAbstractItemView *>(p_proxyPopup->widget());
    if (popup->model()->rowCount() == 0)
    {
        popup->hide();
        p_graphicsItem->setFocus();
        return;
    }

   showPopup(rect);
}
/* Load data to corresponding widgets from cache,
 * this task SHOULD be performed in GUI thread only: */
void UIMachineSettingsSystem::getFromCache()
{
    /* Get system data from cache: */
    const UIDataSettingsMachineSystem &systemData = m_cache.base();

    /* Repopulate 'pointing HID type' combo.
     * We are doing that *now* because it has dynamical content
     * which depends on recashed value: */
    repopulateComboPointingHIDType();

    /* Load motherboard data to page: */
    m_pSliderMemorySize->setValue(systemData.m_iMemorySize);
    /* Remove any old data in the boot view: */
    QAbstractItemView *iv = qobject_cast <QAbstractItemView*> (mTwBootOrder);
    iv->model()->removeRows(0, iv->model()->rowCount());
    /* Apply internal variables data to QWidget(s): */
    for (int i = 0; i < systemData.m_bootItems.size(); ++i)
    {
        UIBootItemData data = systemData.m_bootItems[i];
        QListWidgetItem *pItem = new UIBootTableItem(data.m_type);
        pItem->setCheckState(data.m_fEnabled ? Qt::Checked : Qt::Unchecked);
        mTwBootOrder->addItem(pItem);
    }
    /* Load other motherboard data to page: */
    int iChipsetTypePosition = m_pComboChipsetType->findData(systemData.m_chipsetType);
    m_pComboChipsetType->setCurrentIndex(iChipsetTypePosition == -1 ? 0 : iChipsetTypePosition);
    int iHIDTypePosition = m_pComboPointingHIDType->findData(systemData.m_pointingHIDType);
    m_pComboPointingHIDType->setCurrentIndex(iHIDTypePosition == -1 ? 0 : iHIDTypePosition);
    m_pCheckBoxApic->setChecked(systemData.m_fEnabledIoApic);
    m_pCheckBoxEFI->setChecked(systemData.m_fEnabledEFI);
    m_pCheckBoxUseUTC->setChecked(systemData.m_fEnabledUTC);

    /* Load CPU data to page: */
    m_pSliderCPUCount->setValue(systemData.m_cCPUCount);
    m_pSliderCPUExecCap->setValue(systemData.m_iCPUExecCap);
    m_pCheckBoxPAE->setChecked(systemData.m_fEnabledPAE);

    /* Load acceleration data to page: */
    m_pCheckBoxVirtualization->setChecked(systemData.m_fEnabledHwVirtEx);
    m_pCheckBoxNestedPaging->setChecked(systemData.m_fEnabledNestedPaging);

    /* Polish page finally: */
    polishPage();

    /* Revalidate: */
    revalidate();
}
Ejemplo n.º 22
0
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);
}
Ejemplo n.º 23
0
/*!
    \property QColumnView::resizeGripsVisible
    \brief the way to specify if the list views gets resize grips or not

    By default, \c visible is set to true

    \sa setRootIndex()
*/
void QColumnView::setResizeGripsVisible(bool visible)
{
    Q_D(QColumnView);
    if (d->showResizeGrips == visible)
        return;
    d->showResizeGrips = visible;
    for (int i = 0; i < d->columns.count(); ++i) {
        QAbstractItemView *view = d->columns[i];
        if (visible) {
            QColumnViewGrip *grip = new QColumnViewGrip(view);
            view->setCornerWidget(grip);
            connect(grip, SIGNAL(gripMoved(int)), this, SLOT(_q_gripMoved(int)));
        } else {
            QWidget *widget = view->cornerWidget();
            view->setCornerWidget(0);
            widget->deleteLater();
        }
    }
    void doChDir(const QDir& dir)
    {
        QString path = dir.canonicalPath();
        if (fsModel)
            currentModelIndex = fsModel->setRootPath(path);
        if (view)
            view->setRootIndex(fsModel->index(path));

    }
Ejemplo n.º 25
0
//qt3to4 -- BW
//void ComboBoxToolTip::ShowHideTip( int index, QLabel* tipL, Q3ListBox* lb, const QString& text )
void ComboBoxToolTip::ShowHideTip( int index, QLabel* tipL, QComboBox* lb, const QString& text )
{

 //if ( lb->isVisible() && !lb->isHidden() && lb->hasMouse() )
 if ( lb->isVisible() && !lb->isHidden() )
  {
        //qt3to4 -- BW
        QAbstractItemView* qv = lb->view();
        //qt3to4 -- BW
        //QRect rect = lb->itemRect ( lb->item( index ) );
        QRect rect = qv->visualRect(lb->rootModelIndex());
        tipL->setMargin(1);
        tipL->setIndent(0);
        //qt3to4 -- BW
        //tipL->setAutoMask( FALSE );
        tipL->setFrameStyle( QFrame::Plain | QFrame::Box );
        tipL->setLineWidth( 1 );
        tipL->setAlignment( Qt::AlignLeft | Qt::AlignTop );
        //tipL->polish();
        tipL->setText(text);
        tipL->adjustSize();
        QPoint pos;
   	      pos.setX( rect.right() + 15 );
	      pos.setY( rect.top() );
	      pos = lb->mapToGlobal( pos );
         tipL->move( pos.x(), pos.y() );
         tipL->show();
         tipL->raise();
         return;
  }
  else{
	if (!tipL->isHidden() )
		tipL->hide();
  }

  /*
  if ( !lb->isVisible() || lb->isHidden() ||
       !lb->hasMouse()) {
            tipL->hide();
  }
  */


}
Ejemplo n.º 26
0
bool FilterItemEventFilter::eventFilter(QObject *object, QEvent *event) 
{
	QAbstractItemView *view = qobject_cast<QAbstractItemView*>(parent());

	if (event->type() == QEvent::KeyPress || event->type() == QEvent::MouseButtonPress)
	{
		QCoreApplication::sendEvent(view, event);

		return true;
	}
	else if (event->type() == QEvent::FocusIn)
	{
		view->setFocus();

		return true;
	}
	else
		return QObject::eventFilter(object, event);
}
Ejemplo n.º 27
0
void TransactionView::openTransactionInLedger()
{
    QAbstractItemView *view = transactionView;
    if (!view->selectionModel())
        return;

    QModelIndexList selection = view->selectionModel()->selectedRows(0);
    if (!selection.isEmpty())
    {
        QString url;
        if (fTestNet) {
            url = "http://testnet.MonedaDelEmprendimiento.com/transaction/";
        } else {
            url = "http://ledger.MonedaDelEmprendimiento.com/transaction/";
        }

        url.append(selection.at(0).data(TransactionTableModel::TxIDRole).toString());
        QDesktopServices::openUrl(QUrl(url));
    }
}
Ejemplo n.º 28
0
void QBB10BrightStyle::polish(QWidget *widget)
{
    // Hide the text by default
    if (QProgressBar *pb = qobject_cast<QProgressBar*>(widget))
        pb->setTextVisible(false);

    if (QComboBox *cb = qobject_cast<QComboBox*>(widget)) {
        QAbstractItemView *list = cb->view();
        QPalette p = list->palette();
        p.setBrush(QPalette::HighlightedText, p.brush(QPalette::Text));
        list->setPalette(p);
    }

    if (qobject_cast<QAbstractItemView*>(widget)) {
        QPalette p = widget->palette();
        p.setBrush(QPalette::Disabled, QPalette::HighlightedText, p.brush(QPalette::Text));
        widget->setPalette(p);
    }

    QPixmapStyle::polish(widget);
}
Ejemplo n.º 29
0
//-----------------------------------------------------------------------------
void ctkPathLineEditPrivate::_q_recomputeCompleterPopupSize()
{
  QSize lineEditSize = this->LineEdit->size();

  QAbstractItemView* view = this->LineEdit->completer()->popup();
  const QFontMetrics& fm = view->fontMetrics();

  int iconWidth = 0;
  int textWidth = 0;

  QStyleOptionFrame option;
  int frameWidth = view->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &option, view);
  int frame = 2 * frameWidth
      + view->contentsMargins().left()
      + view->contentsMargins().right();

  QAbstractItemModel* model = this->LineEdit->completer()->completionModel();
  for (int i = 0; i < model->rowCount(); ++i)
    {
    QVariant icon = model->data(model->index(i, 0), Qt::DecorationRole);
    if (icon.isValid() && icon.canConvert<QIcon>())
      {
      iconWidth = qMax(iconWidth, icon.value<QIcon>().availableSizes().front().width() + 4);
      }
    textWidth = qMax(textWidth, fm.boundingRect(model->data(model->index(i, 0)).toString()).width());
    }

  view->setMinimumWidth(qMax(frame + iconWidth + textWidth, lineEditSize.width()));
}
Ejemplo n.º 30
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();

}