コード例 #1
0
/* 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();
}
コード例 #2
0
void StartMainPage::showRecentFoldersViewContextMenu(const QPoint& pos)
{
    QAbstractItemView* view = qobject_cast<QAbstractItemView*>(sender());
    KUrl url;
    QModelIndex index = view->indexAt(pos);
    if (index.isValid()) {
        QVariant data = index.data(KFilePlacesModel::UrlRole);
        url = data.toUrl();
    }

    // Create menu
    QMenu menu(this);
    bool fromRecentUrls = view == d->mRecentUrlsView;
    QAction* addToPlacesAction = fromRecentUrls ? 0 : menu.addAction(KIcon("bookmark-new"), i18n("Add to Places"));
    QAction* removeAction = menu.addAction(KIcon("edit-delete"), fromRecentUrls ? i18n("Forget this URL") : i18n("Forget this Folder"));
    menu.addSeparator();
    QAction* clearAction = menu.addAction(KIcon("edit-delete-all"), i18n("Forget All"));

    if (!index.isValid()) {
        if (addToPlacesAction) {
            addToPlacesAction->setEnabled(false);
        }
        removeAction->setEnabled(false);
    }

    // Handle menu
    QAction* action = menu.exec(view->mapToGlobal(pos));
    if (!action) {
        return;
    }
    if (action == addToPlacesAction) {
        QString text = url.fileName();
        if (text.isEmpty()) {
            text = url.pathOrUrl();
        }
        d->mBookmarksModel->addPlace(text, url);
    } else if (action == removeAction) {
        view->model()->removeRow(index.row());
    } else if (action == clearAction) {
        view->model()->removeRows(0, view->model()->rowCount());
    }
}
コード例 #3
0
ファイル: TableViewTooltip.cpp プロジェクト: biophor/AdBook
bool TableViewTooltip::eventFilter(QObject * obj, QEvent * event)
{
    if (event->type() != QEvent::ToolTip) {
        return false;
    }
    QAbstractItemView* view = qobject_cast<QAbstractItemView*>(obj->parent());
    if (!view) {
        return false;
    }
    
    QHelpEvent * helpEvent = static_cast<QHelpEvent*>(event);
    QPoint pos = helpEvent->pos();
    QModelIndex index = view->indexAt(pos);
    if (!index.isValid()) {
        return false;
    }
    QString itemTooltip = view->model()->data(index, Qt::ToolTipRole).toString();
    if (itemTooltip.isEmpty()) {
        QToolTip::hideText();
        return true;
    }
    QString itemText = view->model()->data(index).toString();
    
    QFontMetrics fm(view->font());
    int textIdentWidth =6;// fm.width('r'); // don't know how to calculate an ident for text in an item :-( 
    int itemTextWidth = fm.width(itemText) + textIdentWidth;
    QRect rect = view->visualRect(index);
    
    int rectWidth = rect.width();

    if (itemTextWidth > rectWidth) {
        QToolTip::showText(helpEvent->globalPos(), itemTooltip, view, rect);
    }
    else {
        QToolTip::hideText();
    }
    return true;    
}
コード例 #4
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();

}
コード例 #5
0
void ModelInspectorWidget::widgetSelected(QWidget *widget)
{
  QAbstractItemView *view = Util::findParentOfType<QAbstractItemView>(widget);
  if (view && view->model()) {
    QAbstractItemModel *model = ui->modelView->model();
    const QModelIndexList indexList =
      model->match(model->index(0, 0),
                   ObjectModel::ObjectRole,
                   QVariant::fromValue<QObject*>(view->model()), 1,
                   Qt::MatchExactly | Qt::MatchRecursive);
    if (indexList.isEmpty()) {
      return;
    }

    const QModelIndex index = indexList.first();
    ui->modelView->selectionModel()->select(
      index,
      QItemSelectionModel::Select | QItemSelectionModel::Clear |
      QItemSelectionModel::Rows | QItemSelectionModel::Current);
    ui->modelView->scrollTo(index);
    modelSelected(index);
  }
}
コード例 #6
0
ファイル: tooltipfilter.cpp プロジェクト: LI-COR/eddypro-gui
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);
}
コード例 #7
0
/* 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();

    /* 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 system data to page: */
    mCbApic->setChecked(systemData.m_fIoApicEnabled);
    mCbEFI->setChecked(systemData.m_fEFIEnabled);
    mCbTCUseUTC->setChecked(systemData.m_fUTCEnabled);
    mCbUseAbsHID->setChecked(systemData.m_fUseAbsHID);
    mCbPae->setChecked(systemData.m_fPAEEnabled);
    mCbVirt->setChecked(systemData.m_fHwVirtExEnabled);
    mCbNestedPaging->setChecked(systemData.m_fNestedPagingEnabled);
    mSlMemory->setValue(systemData.m_iRAMSize);
    mSlCPU->setValue(systemData.m_cCPUCount);
    mSlCPUExecCap->setValue(systemData.m_cCPUExecCap);
    int iChipsetPositionPos = mCbChipset->findData(systemData.m_chipsetType);
    mCbChipset->setCurrentIndex(iChipsetPositionPos == -1 ? 0 : iChipsetPositionPos);

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

    /* Revalidate if possible: */
    if (mValidator)
        mValidator->revalidate();
}
コード例 #8
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);
}
コード例 #9
0
ファイル: ColumnToolTip.cpp プロジェクト: helkatz/LogViewer
bool ColumnToolTip::eventFilter(QObject* obj, QEvent* event)
{
	if (event->type() == QEvent::ToolTip)
	{
		QAbstractItemView* view = qobject_cast<QAbstractItemView*>(obj->parent());
		if (!view)
		{
			return false;
		}

		QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);
		QPoint pos = helpEvent->pos();
		QModelIndex index = view->indexAt(pos);
		if (!index.isValid())
			return false;

		QString itemText = view->model()->data(index).toString();
		QString itemTooltip = view->model()->data(index, Qt::ToolTipRole).toString();

		QFontMetrics fm(view->font());
		int itemTextWidth = fm.width(itemText);
		QRect rect = view->visualRect(index);
		int rectWidth = rect.width();

		if ((itemTextWidth > rectWidth) && !itemTooltip.isEmpty())
		{
			QToolTip::showText(helpEvent->globalPos(), itemTooltip, view, rect);
		}
		else
		{
			QToolTip::hideText();
		}
		return true;
	}
	return false;
}
コード例 #10
0
ファイル: ddateedit.cpp プロジェクト: UIKit0/digikam
void DDateEdit::showPopup()
{
    if ( d->readOnly )
    {
        return;
    }

    QRect desk          = KGlobalSettings::desktopGeometry( this );
    QPoint popupPoint   = mapToGlobal( QPoint( 0,0 ) );
    int dateFrameHeight = d->popup->sizeHint().height();

    if ( popupPoint.y() + height() + dateFrameHeight > desk.bottom() )
    {
        popupPoint.setY( popupPoint.y() - dateFrameHeight );
    }
    else
    {
        popupPoint.setY( popupPoint.y() + height() );
    }

    int dateFrameWidth = d->popup->sizeHint().width();

    if ( popupPoint.x() + dateFrameWidth > desk.right() )
    {
        popupPoint.setX( desk.right() - dateFrameWidth );
    }

    if ( popupPoint.x() < desk.left() )
    {
        popupPoint.setX( desk.left() );
    }

    if ( popupPoint.y() < desk.top() )
    {
        popupPoint.setY( desk.top() );
    }

    if ( d->date.isValid() )
    {
        d->popup->setDate( d->date );
    }
    else
    {
        d->popup->setDate( QDate::currentDate() );
    }

    d->popup->popup( popupPoint );

    // The combo box is now shown pressed. Make it show not pressed again
    // by causing its (invisible) list box to emit a 'selected' signal.
    // First, ensure that the list box contains the date currently displayed.
    QDate date = parseDate();
    assignDate( date );
    updateView();
    // Now, simulate an Enter to unpress it
    QAbstractItemView* lb = view();

    if (lb)
    {
        lb->setCurrentIndex( lb->model()->index( 0, 0 ) );
        QKeyEvent* keyEvent = new QKeyEvent(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
        QApplication::postEvent(lb, keyEvent);
    }
}