Пример #1
0
bool
Basic::eventFilter( QObject* object, QEvent *e )
{
   QWidget* widget = qobject_cast<QWidget*>(object);
   if (!(widget && widget->isVisible()))
      return false;

   switch (e->type())
   {
    case QEvent::MouseMove:
    case QEvent::Timer:
    case QEvent::Move:
    case QEvent::Paint:
        return false; // just for performance - they can occur really often

    case QEvent::Show:
        if (widget->isEnabled())
            play(widget);
        return false;
    case QEvent::Hide:
        _release(widget);
        return false;
    case QEvent::EnabledChange:
        if (widget->isEnabled())
            play(widget);
        else
            _release(widget);
        return false;
    default:
        return false;
   }
}
Пример #2
0
void TestGui::testAddEntry()
{
    EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
    QAction* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
    QVERIFY(entryNewAction->isEnabled());
    QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
    QWidget* entryNewWidget = toolBar->widgetForAction(entryNewAction);
    QVERIFY(entryNewWidget->isVisible());
    QVERIFY(entryNewWidget->isEnabled());

    QTest::mouseClick(entryNewWidget, Qt::LeftButton);

    QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode);

    EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
    QLineEdit* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
    QTest::keyClicks(titleEdit, "test");

    QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
    QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);

    QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::ViewMode);
    QModelIndex item = entryView->model()->index(1, 1);
    Entry* entry = entryView->entryFromIndex(item);

    QCOMPARE(entry->title(), QString("test"));
    QCOMPARE(entry->historyItems().size(), 0);
    // wait for modified timer
    QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("%1*").arg(m_orgDbFileName));

    QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
    QVERIFY(entryEditAction->isEnabled());
    QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction);
    QVERIFY(entryEditWidget->isVisible());
    QVERIFY(entryEditWidget->isEnabled());
    QTest::mouseClick(entryEditWidget, Qt::LeftButton);

    QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode);
    QTest::keyClicks(titleEdit, "something");
    QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);

    QCOMPARE(entry->title(), QString("testsomething"));
    QCOMPARE(entry->historyItems().size(), 1);


    QTest::mouseClick(entryNewWidget, Qt::LeftButton);
    QTest::keyClicks(titleEdit, "something 2");
    QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);


    QTest::mouseClick(entryNewWidget, Qt::LeftButton);
    QTest::keyClicks(titleEdit, "something 3");
    QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);


    QTRY_COMPARE(entryView->model()->rowCount(), 4);
}
Пример #3
0
void TestGui::testSearch()
{
    QAction* searchAction = m_mainWindow->findChild<QAction*>("actionSearch");
    QVERIFY(searchAction->isEnabled());
    QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
    QWidget* searchActionWidget = toolBar->widgetForAction(searchAction);
    QVERIFY(searchActionWidget->isVisible());
    QVERIFY(searchActionWidget->isEnabled());
    QTest::mouseClick(searchActionWidget, Qt::LeftButton);

    EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
    QLineEdit* searchEdit = m_dbWidget->findChild<QLineEdit*>("searchEdit");
    QToolButton* clearSearch = m_dbWidget->findChild<QToolButton*>("clearButton");

    QTest::keyClicks(searchEdit, "ZZZ");

    QTRY_COMPARE(entryView->model()->rowCount(), 0);

    QTest::mouseClick(clearSearch, Qt::LeftButton);
    QTest::keyClicks(searchEdit, "some");

    QTRY_COMPARE(entryView->model()->rowCount(), 2);

    QModelIndex item = entryView->model()->index(0, 1);
    QRect itemRect = entryView->visualRect(item);
    QTest::mouseClick(entryView->viewport(), Qt::LeftButton, Qt::NoModifier, itemRect.center());
    QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
    QVERIFY(entryEditAction->isEnabled());
    QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction);
    QVERIFY(entryEditWidget->isVisible());
    QVERIFY(entryEditWidget->isEnabled());
    QTest::mouseClick(entryEditWidget, Qt::LeftButton);

    QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode);

    EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
    QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
    QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);

    QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::ViewMode);

    QModelIndex item2 = entryView->model()->index(1, 0);
    QRect itemRect2 = entryView->visualRect(item2);
    QTest::mouseClick(entryView->viewport(), Qt::LeftButton, Qt::NoModifier, itemRect2.center());
    QAction* entryDeleteAction = m_mainWindow->findChild<QAction*>("actionEntryDelete");

    QWidget* entryDeleteWidget = toolBar->widgetForAction(entryDeleteAction);
    QVERIFY(entryDeleteWidget->isVisible());
    QVERIFY(entryDeleteWidget->isEnabled());

    QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
    QWidget* closeSearchButton = m_dbWidget->findChild<QToolButton*>("closeSearchButton");
    QTest::mouseClick(closeSearchButton, Qt::LeftButton);

    QCOMPARE(entryView->model()->rowCount(), 1);
}
Пример #4
0
/*! \reimp */
QAccessible::State QAccessibleWidget::state(int child) const
{
    if (child)
        return Normal;

    QAccessible::State state = Normal;

    QWidget *w = widget();
    if (w->testAttribute(Qt::WA_WState_Visible) == false)
        state |= Invisible;
    if (w->focusPolicy() != Qt::NoFocus)
        state |= Focusable;
    if (w->hasFocus())
        state |= Focused;
    if (!w->isEnabled())
        state |= Unavailable;
    if (w->isWindow()) {
        if (w->windowFlags() & Qt::WindowSystemMenuHint)
            state |= Movable;
        if (w->minimumSize() != w->maximumSize())
            state |= Sizeable;
    }

    return state;
}
Пример #5
0
void QWidgetWindow::handleContextMenuEvent(QContextMenuEvent *e)
{
    // We are only interested in keyboard originating context menu events here,
    // mouse originated context menu events for widgets are generated in mouse handling methods.
    if (e->reason() != QContextMenuEvent::Keyboard)
        return;

    QWidget *fw = QWidget::keyboardGrabber();
    if (!fw) {
        if (QApplication::activePopupWidget()) {
            fw = (QApplication::activePopupWidget()->focusWidget()
                  ? QApplication::activePopupWidget()->focusWidget()
                  : QApplication::activePopupWidget());
        } else if (QApplication::focusWidget()) {
            fw = QApplication::focusWidget();
        } else {
            fw = m_widget;
        }
    }
    if (fw && fw->isEnabled()) {
        QPoint pos = fw->inputMethodQuery(Qt::ImMicroFocus).toRect().center();
        QContextMenuEvent widgetEvent(QContextMenuEvent::Keyboard, pos, fw->mapToGlobal(pos),
                                      e->modifiers());
        QGuiApplication::sendSpontaneousEvent(fw, &widgetEvent);
    }
}
Пример #6
0
void KSelectAction_UnitTest::testRequestWidgetMenuModeWidgetParentRemoveActions()
{
    KSelectAction selectAction("selectAction", 0);
    selectAction.setToolBarMode(KSelectAction::MenuMode);

    QToolBar toolBar;
    toolBar.addAction(&selectAction);
    QWidget* widget = toolBar.widgetForAction(&selectAction);

    QVERIFY(widget);

    QAction* action1 = new QAction("action1", &selectAction);
    selectAction.addAction(action1);
    QAction* action2 = new QAction("action2", &selectAction);
    selectAction.addAction(action2);
    QAction* action3 = new QAction("action3", &selectAction);
    selectAction.addAction(action3);

    delete selectAction.removeAction(action1);
    delete selectAction.removeAction(action2);
    delete selectAction.removeAction(action3);

    QVERIFY(!widget->isEnabled());
    QCOMPARE(widget->actions().count(), 1);
    QCOMPARE(widget->actions().at(0)->text(), QString("selectAction"));
}
QWidget* QtEventConsumer::isValidWidget(QObject *obj)
{
    // check the object
    if (!obj->isWidgetType()){
        return NULL;
    }

    // check the widget
    QWidget* w = dynamic_cast<QWidget*>(obj);
    _d("W > " << QWidgetUtils::getWidgetPath(w).toStdString());
    if (!w) {
        DEBUG(D_CONSUMER,"(QtEventConsumer::isValidWidget) Widget is null");
        DEBUG(D_CONSUMER,"(QtEventConsumer::isValidWidget)  -> " + QWidgetUtils::getWidgetPath(w).toStdString());
        return NULL;
    }
    else if (!w->isVisible()) {
        DEBUG(D_CONSUMER,"(QtEventConsumer::isValidWidget) Widget is not visible");
        DEBUG(D_CONSUMER,"(QtEventConsumer::isValidWidget)  -> " + QWidgetUtils::getWidgetPath(w).toStdString());
        return NULL;
    }
    else if (!w->isEnabled()) {
        DEBUG(D_CONSUMER,"(QtEventConsumer::isValidWidget) Widget is not enabled");
        DEBUG(D_CONSUMER,"(QtEventConsumer::isValidWidget)  -> " + QWidgetUtils::getWidgetPath(w).toStdString());
        return NULL;
    }

    _d("W > " << QWidgetUtils::getWidgetPath(w).toStdString());
    _d("VALID WIDGET");

    return w;
}
Пример #8
0
//! The Job options are synchronised using the widgetChanged slot, but we still
//! need to determine if the options should be printed as part of the job.  This
//! is based on whether or not the associated control is enabled or not.
void InputDialog::finalizeJob(Job* job) 
{
   if (!job) return;
   QWidget* w;
   QString name;
   StringMap::const_iterator iter;
   StringMap s = job->getOptions();

   for (iter = s.begin(); iter != s.end(); ++iter) {
       name  = iter.key();
       w = findChild<QWidget*>(name.toLower());
	   // If there is no widget of this name, then we are probably dealing 
       // with something the user wrote into the preview box, so we just 
	   // leave things alone.
       if (w) job->printOption(name, w->isEnabled());
   }

   // Special case code to avoid writing the method keyword when custom is
   // chosen (for backward compatibility)
   QComboBox* method(findChild<QComboBox*>("method"));
   QString m(method->currentText());
   if (method && (m == "Custom" || m == "TD-DFT")) {
      job->printOption("METHOD", false);
      job->printOption("EXCHANGE", true);
   }
}
Пример #9
0
/*!
    \property QStackedLayout::currentIndex
    \brief the index position of the widget that is visible

    The current index is -1 if there is no current widget.

    \sa currentWidget(), indexOf()
*/
void QStackedLayout::setCurrentIndex(int index)
{
    Q_D(QStackedLayout);
    QWidget *prev = currentWidget();
    QWidget *next = widget(index);
    if (!next || next == prev)
        return;

    bool reenableUpdates = false;
    QWidget *parent = parentWidget();

    if (parent && parent->updatesEnabled()) {
        reenableUpdates = true;
        parent->setUpdatesEnabled(false);
    }

    QWidget *fw = parent ? parent->window()->focusWidget() : 0;
    if (prev) {
        prev->clearFocus();
        if (d->stackingMode == StackOne)
            prev->hide();
    }

    d->index = index;
    next->raise();
    next->show();

    // try to move focus onto the incoming widget if focus
    // was somewhere on the outgoing widget.

    if (parent) {
        if (fw && (prev && prev->isAncestorOf(fw))) { // focus was on old page
            // look for the best focus widget we can find
            if (QWidget *nfw = next->focusWidget())
                nfw->setFocus();
            else {
                // second best: first child widget in the focus chain
                QWidget *i = fw;
                while ((i = i->nextInFocusChain()) != fw) {
                    if (((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus)
                        && !i->focusProxy() && i->isVisibleTo(next) && i->isEnabled()
                        && next->isAncestorOf(i)) {
                        i->setFocus();
                        break;
                    }
                }
                // third best: incoming widget
                if (i == fw )
                    next->setFocus();
            }
        }
    }
    if (reenableUpdates)
        parent->setUpdatesEnabled(true);
    emit currentChanged(index);
}
Пример #10
0
void GTUtilsAssemblyBrowser::zoomToMin(HI::GUITestOpStatus &os) {
    Q_UNUSED(os);

    QToolBar* toolbar = GTToolbar::getToolbar(os, MWTOOLBAR_ACTIVEMDI);
    GT_CHECK(NULL != toolbar, "Can't find the toolbar");

    QWidget* zoomOutButton = GTToolbar::getWidgetForActionTooltip(os, toolbar, "Zoom out");
    GT_CHECK(NULL != zoomOutButton, "Can't find the 'Zoom in' button");

    while (zoomOutButton->isEnabled()) {
        GTWidget::click(os, zoomOutButton);
    }
}
Пример #11
0
void KSelectAction_UnitTest::testRequestWidgetMenuModeWidgetParentAddActions()
{
    KSelectAction selectAction("selectAction", 0);
    selectAction.setToolBarMode(KSelectAction::MenuMode);

    QToolBar toolBar;
    toolBar.addAction(&selectAction);
    QWidget* widget = toolBar.widgetForAction(&selectAction);

    QVERIFY(widget);
    QVERIFY(!widget->isEnabled());

    selectAction.addAction(new QAction("action1", &selectAction));
    selectAction.addAction(new QAction("action2", &selectAction));
    selectAction.addAction(new QAction("action3", &selectAction));

    QVERIFY(widget->isEnabled());
    QCOMPARE(widget->actions().count(), 4);
    QCOMPARE(widget->actions().at(0)->text(), QString("selectAction"));
    QCOMPARE(widget->actions().at(1)->text(), QString("action1"));
    QCOMPARE(widget->actions().at(2)->text(), QString("action2"));
    QCOMPARE(widget->actions().at(3)->text(), QString("action3"));
}
Пример #12
0
QStyleOptionMenuItem KxMenuItemWidget::getStyleOption() const
{
    QWidget *q = parentWidget();
    QMenu *menu = (QMenu *)q;
    KxMenuItem *action = fMenuItem;
    QStyleOptionMenuItem opt;

    opt.initFrom(this);
    opt.palette = q->palette();
    opt.state = QStyle::State_None;

    if (q->window()->isActiveWindow())
        opt.state |= QStyle::State_Active;
    if (q->isEnabled() && action->isEnabled()
        && (!action->menu() || action->menu()->isEnabled()))
        opt.state |= QStyle::State_Enabled;
    else
        opt.palette.setCurrentColorGroup(QPalette::Disabled);

    opt.font = action->font();

    if (menu->activeAction() == action && !action->isSeparator()) {
        opt.state |= QStyle::State_Selected;
        // 					 | (mouseDown ? QStyle::State_Sunken : QStyle::State_None);
    }

    if (!action->isCheckable()) {
        opt.checkType = QStyleOptionMenuItem::NotCheckable;
    } else {
        opt.checkType = (action->actionGroup() && action->actionGroup()->isExclusive())
            ? QStyleOptionMenuItem::Exclusive : QStyleOptionMenuItem::NonExclusive;
        opt.checked = action->isChecked();
    }
    if (action->menu())
        opt.menuItemType = QStyleOptionMenuItem::SubMenu;
    else if (action->isSeparator())
        opt.menuItemType = QStyleOptionMenuItem::Separator;
    else if (menu->defaultAction() == action)
        opt.menuItemType = QStyleOptionMenuItem::DefaultItem;
    else
        opt.menuItemType = QStyleOptionMenuItem::Normal;
    opt.icon = action->icon();
    opt.text = action->text();
    opt.menuRect = q->rect();
    return opt;
}
Пример #13
0
/*!\reimp */
void QGroupBox::childEvent(QChildEvent *c)
{
    Q_D(QGroupBox);
    if (c->type() != QEvent::ChildAdded || !c->child()->isWidgetType())
        return;
    QWidget *w = (QWidget*)c->child();
    if (d->checkable) {
        if (d->checked) {
            if (!w->testAttribute(Qt::WA_ForceDisabled))
                w->setEnabled(true);
        } else {
            if (w->isEnabled()) {
                w->setEnabled(false);
                w->setAttribute(Qt::WA_ForceDisabled, false);
            }
        }
    }
}
Пример #14
0
    void FilterWidget::filterButton_clicked()
    {
        TQueryMap opts;

		Attr *a = 0;
		for( int i = 0; i < attrList.size(); i++ )
		{
			QApplication::processEvents();

			a = attrList.at(i);

			if ( widgetMap.contains( a->getName() )  )
			{
				QWidget *w = widgetMap[a->getName() ];
				if ( false == w->isEnabled() )
					continue;

				QString v = getWidgetData( a, w );
				if ( !v.isEmpty() ) {

                    int flag = Like | Case;

					bool ok;
					v.toInt(&ok, 10);

					if ( ok ) {
						flag = Equal;
					}

                    if (a->getType() == Attr::Bool) {
                        flag = Equal;
                    }

					if ( opts.size() > 0 ) {
						flag |= And;
					}

					opts.insert(a->getName(),keeper->prepareParam(flag, v));
				}
			}
		}

        emit filterActivated(opts);
    }
Пример #15
0
/*
  sets all children of the group box except the qt_groupbox_checkbox
  to either disabled/enabled
*/
void QGroupBoxPrivate::_q_setChildrenEnabled(bool b)
{
    Q_Q(QGroupBox);
    QObjectList childList = q->children();
    for (int i = 0; i < childList.size(); ++i) {
        QObject *o = childList.at(i);
        if (o->isWidgetType()) {
            QWidget *w = static_cast<QWidget *>(o);
            if (b) {
                if (!w->testAttribute(Qt::WA_ForceDisabled))
                    w->setEnabled(true);
            } else {
                if (w->isEnabled()) {
                    w->setEnabled(false);
                    w->setAttribute(Qt::WA_ForceDisabled, false);
                }
            }
        }
    }
}
Пример #16
0
// Make Material-blocks:
//-----------------------------------------------------------------------------
void SifGenerator::makeMaterialBlocks()
{
  int sifIndex = 0;

  for(int index = 0; index < materialEditor.size(); index++) {
    DynamicEditor *matEditor = materialEditor[index];
    
    if(matEditor->menuAction != NULL) {      
      te->append("Material " + QString::number(++sifIndex));
      
      QString name = matEditor->nameEdit->text().trimmed();
      te->append("  Name = \"" + name + "\"");
      
      for(int i = 0; i < matEditor->hash.count(); i++) {
	hash_entry_t entry = matEditor->hash.values().at(i); 
	
	QWidget *widget = entry.widget;

	QDomElement elem;
        if ( widget->isEnabled() ) {
          elem = entry.elem;
	  
          if(elem.attribute("Widget", "") == "CheckBox") 
	   handleCheckBox(elem, widget);
	
	 if(elem.attribute("Widget", "") == "Edit")
	   handleLineEdit(elem, widget);
	
	 if(elem.attribute("Widget", "") == "Combo")
	   handleComboBox(elem, widget);

	 if(elem.attribute("Widget", "") == "TextEdit")
	   handleTextEdit(elem, widget);
        }
      }
      te->append("End\n");
    }
  }
}
Пример #17
0
QWidget *QWidgetWindow::getFocusWidget(FocusWidgets fw)
{
    QWidget *tlw = m_widget;
    QWidget *w = tlw->nextInFocusChain();

    QWidget *last = tlw;

    uint focus_flag = qt_tab_all_widgets() ? Qt::TabFocus : Qt::StrongFocus;

    while (w != tlw)
    {
        if (((w->focusPolicy() & focus_flag) == focus_flag)
            && w->isVisibleTo(m_widget) && w->isEnabled())
        {
            last = w;
            if (fw == FirstFocusWidget)
                break;
        }
        w = w->nextInFocusChain();
    }

    return last;
}
Пример #18
0
int SifGenerator::findHashValue(DynamicEditor *de, const QString &sname, const QString &name)
{
    for(int i = 0; i < de->hash.count(); i++) {
      hash_entry_t entry = de->hash.values().at(i); 

      QWidget *widget = entry.widget;
      if (widget->isEnabled()) {
        QString key = de->hash.keys().at(i);
        QStringList keySplitted = key.split("/");
        QString solverName = keySplitted.at(1).trimmed();
        QString labelName = keySplitted.at(3).trimmed();

        QDomElement elem = entry.elem;
        if ( solverName==sname && labelName==name &&
	     elem.attribute("Widget","")=="Edit" ) {
	  QLineEdit *line = static_cast<QLineEdit*>(widget);
	  QString str = line->text().trimmed();
	  if ( str.isEmpty() ) return 0;
	  return str.toInt();
	}
      }
    }
    return 0;
}
Пример #19
0
/*!\reimp */
void QGroupBox::childEvent( QChildEvent *c )
{
    if ( !c->inserted() || !c->child()->isWidgetType() )
        return;
    QWidget *w = (QWidget*)c->child();
#ifndef QT_NO_CHECKBOX
    if ( d->checkbox ) {
        if ( w == d->checkbox )
            return;
        if ( d->checkbox->isChecked() ) {
            if ( !w->testWState( WState_ForceDisabled ) )
                w->setEnabled( TRUE );
        } else {
            if ( w->isEnabled() ) {
                w->setEnabled( FALSE );
                ((QGroupBox*)w)->clearWState( WState_ForceDisabled );
            }
        }
    }
#endif
    if ( !grid )
        return;
    insertWid( w );
}
Пример #20
0
void TestGui::testEditEntry()
{
    EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
    QModelIndex item = entryView->model()->index(0, 1);
    QRect itemRect = entryView->visualRect(item);
    QTest::mouseClick(entryView->viewport(), Qt::LeftButton, Qt::NoModifier, itemRect.center());

    QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
    QVERIFY(entryEditAction->isEnabled());
    QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
    QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction);
    QVERIFY(entryEditWidget->isVisible());
    QVERIFY(entryEditWidget->isEnabled());
    QTest::mouseClick(entryEditWidget, Qt::LeftButton);

    EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
    QVERIFY(m_dbWidget->currentWidget() == editEntryWidget);
    QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
    QVERIFY(editEntryWidgetButtonBox);
    QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
    // make sure the database isn't marked as modified
    // wait for modified timer
    QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), m_orgDbFileName);
}
Пример #21
0
/*! \reimp */
QAccessible::State QAccessibleWidget::state() const
{
    QAccessible::State state;

    QWidget *w = widget();
    if (w->testAttribute(Qt::WA_WState_Visible) == false)
        state.invisible = true;
    if (w->focusPolicy() != Qt::NoFocus)
        state.focusable = true;
    if (w->hasFocus())
        state.focused = true;
    if (!w->isEnabled())
        state.disabled = true;
    if (w->isWindow()) {
        if (w->windowFlags() & Qt::WindowSystemMenuHint)
            state.movable = true;
        if (w->minimumSize() != w->maximumSize())
            state.sizeable = true;
        if (w->isActiveWindow())
            state.active = true;
    }

    return state;
}
Пример #22
0
bool
Hover::eventFilter( QObject* object, QEvent *e )
{
    QWidget* widget = qobject_cast<QWidget*>(object);
    if (!(widget && widget->isVisible() && widget->isEnabled()))
        return false;

    switch (e->type())
    {
    case QEvent::Timer:
    case QEvent::Move:
    case QEvent::Paint:
    case QEvent::MouseMove:
    case QEvent::UpdateRequest:
    case QEvent::MouseButtonPress:
    case QEvent::Wheel:
        return false; // just for performance - they can occur really often
    case QEvent::WindowActivate:
    case QEvent::Enter:
    {
        if (QAbstractScrollArea* area = qobject_cast<QAbstractScrollArea*>(object))
        {
            if (!area->isEnabled())
                return false;
            HANDLE_SCROLL_AREA_EVENT(false);
            return false;
        }
        else if (Q3ScrollView* area = qobject_cast<Q3ScrollView*>(object))
        {
            if (!area->isEnabled())
                return false;
            HANDLE_SCROLL_AREA_EVENT(false);
            return false;
        }
        else if (_scrollAreas.contains(object))
        {
            QObjectList kids = object->children();
            QWidget *sb;
            foreach (QObject *kid, kids)
            {
                if isAttachedScrollbar
                    play(sb);
            }
            return false;
        }
        if (e->type() == QEvent::WindowActivate)
            return false;
        play(widget);
        return false;
    }
    case QEvent::WindowDeactivate:
    case QEvent::Leave:
    {
        if (QAbstractScrollArea* area = qobject_cast<QAbstractScrollArea*>(object))
        {
            if (!area->isEnabled())
                return false;
            HANDLE_SCROLL_AREA_EVENT(true);
            return false;
        }
        else if (Q3ScrollView* area = qobject_cast<Q3ScrollView*>(object))
        {
            HANDLE_SCROLL_AREA_EVENT(true);
            return false;
        }
        else if (_scrollAreas.contains(object))
        {
            QObjectList kids = object->children();
            QWidget *sb;
            foreach (QObject *kid, kids)
            {
                if isAttachedScrollbar
                    play(sb, true);
            }
            return false;
        }
        if (e->type() == QEvent::WindowDeactivate)
            return false;
        play(widget, true);
        return false;
    }
Пример #23
0
void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
{
    static const QEvent::Type contextMenuTrigger =
        QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() ?
        QEvent::MouseButtonRelease : QEvent::MouseButtonPress;
    if (qApp->d_func()->inPopupMode()) {
        QWidget *activePopupWidget = qApp->activePopupWidget();
        QWidget *popup = activePopupWidget;
        QPoint mapped = event->pos();
        if (popup != m_widget)
            mapped = popup->mapFromGlobal(event->globalPos());
        bool releaseAfter = false;
        QWidget *popupChild  = popup->childAt(mapped);

        if (popup != qt_popup_down) {
            qt_button_down = 0;
            qt_popup_down = 0;
        }

        switch (event->type()) {
        case QEvent::MouseButtonPress:
        case QEvent::MouseButtonDblClick:
            qt_button_down = popupChild;
            qt_popup_down = popup;
            break;
        case QEvent::MouseButtonRelease:
            releaseAfter = true;
            break;
        default:
            break; // nothing for mouse move
        }

        int oldOpenPopupCount = openPopupCount;

        if (popup->isEnabled()) {
            // deliver event
            qt_replay_popup_mouse_event = false;
            QWidget *receiver = popup;
            QPoint widgetPos = mapped;
            if (qt_button_down)
                receiver = qt_button_down;
            else if (popupChild)
                receiver = popupChild;
            if (receiver != popup)
                widgetPos = receiver->mapFromGlobal(event->globalPos());
            QWidget *alien = m_widget->childAt(m_widget->mapFromGlobal(event->globalPos()));
            QMouseEvent e(event->type(), widgetPos, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers());
            QGuiApplicationPrivate::setMouseEventSource(&e, QGuiApplicationPrivate::mouseEventSource(event));
            e.setTimestamp(event->timestamp());
            QApplicationPrivate::sendMouseEvent(receiver, &e, alien, m_widget, &qt_button_down, qt_last_mouse_receiver);
        } else {
            // close disabled popups when a mouse button is pressed or released
            switch (event->type()) {
            case QEvent::MouseButtonPress:
            case QEvent::MouseButtonDblClick:
            case QEvent::MouseButtonRelease:
                popup->close();
                break;
            default:
                break;
            }
        }

        if (qApp->activePopupWidget() != activePopupWidget
            && qt_replay_popup_mouse_event) {
            if (m_widget->windowType() != Qt::Popup)
                qt_button_down = 0;
            if (event->type() == QEvent::MouseButtonPress) {
                // the popup disappeared, replay the mouse press event
                QWidget *w = QApplication::widgetAt(event->globalPos());
                if (w && !QApplicationPrivate::isBlockedByModal(w)) {
                    // activate window of the widget under mouse pointer
                    if (!w->isActiveWindow()) {
                        w->activateWindow();
                        w->raise();
                    }

                    QWindow *win = w->windowHandle();
                    if (!win)
                        win = w->nativeParentWidget()->windowHandle();
                    if (win && win->geometry().contains(event->globalPos())) {
                        const QPoint localPos = win->mapFromGlobal(event->globalPos());
                        QMouseEvent e(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(), event->button(), event->buttons(), event->modifiers());
                        QGuiApplicationPrivate::setMouseEventSource(&e, QGuiApplicationPrivate::mouseEventSource(event));
                        e.setTimestamp(event->timestamp());
                        QApplication::sendSpontaneousEvent(win, &e);
                    }
                }
            }
            qt_replay_popup_mouse_event = false;
#ifndef QT_NO_CONTEXTMENU
        } else if (event->type() == contextMenuTrigger
                   && event->button() == Qt::RightButton
                   && (openPopupCount == oldOpenPopupCount)) {
            QWidget *popupEvent = popup;
            if (qt_button_down)
                popupEvent = qt_button_down;
            else if(popupChild)
                popupEvent = popupChild;
            QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers());
            QApplication::sendSpontaneousEvent(popupEvent, &e);
#endif
        }

        if (releaseAfter) {
            qt_button_down = 0;
            qt_popup_down = 0;
        }
        return;
    }

    // modal event handling
    if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type()))
        return;

    // which child should have it?
    QWidget *widget = m_widget->childAt(event->pos());
    QPoint mapped = event->pos();

    if (!widget)
        widget = m_widget;

    if (event->type() == QEvent::MouseButtonPress)
        qt_button_down = widget;

    QWidget *receiver = QApplicationPrivate::pickMouseReceiver(m_widget, event->windowPos().toPoint(), &mapped, event->type(), event->buttons(),
                                                               qt_button_down, widget);

    if (!receiver) {
        if (event->type() == QEvent::MouseButtonRelease)
            QApplicationPrivate::mouse_buttons &= ~event->button();
        return;
    }
    if ((event->type() != QEvent::MouseButtonPress)
        || !(event->flags().testFlag(Qt::MouseEventCreatedDoubleClick))) {

        // The preceding statement excludes MouseButtonPress events which caused
        // creation of a MouseButtonDblClick event. QTBUG-25831
        QMouseEvent translated(event->type(), mapped, event->windowPos(), event->screenPos(),
                               event->button(), event->buttons(), event->modifiers());
        QGuiApplicationPrivate::setMouseEventSource(&translated, QGuiApplicationPrivate::mouseEventSource(event));
        translated.setTimestamp(event->timestamp());
        QApplicationPrivate::sendMouseEvent(receiver, &translated, widget, m_widget,
                                            &qt_button_down, qt_last_mouse_receiver);
    }
#ifndef QT_NO_CONTEXTMENU
    if (event->type() == contextMenuTrigger && event->button() == Qt::RightButton) {
        QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers());
        QGuiApplication::sendSpontaneousEvent(receiver, &e);
    }
#endif
}
Пример #24
0
void Q3WidgetStack::raiseWidget(QWidget *w)
{
    if (!w || w == invisible || w->parent() != this || w == topWidget)
        return;

    if (id(w) == -1)
        addWidget(w);
    if (!isVisible()) {
        topWidget = w;
        return;
    }

    if (w->maximumSize().width() < invisible->width()
            || w->maximumSize().height() < invisible->height())
        invisible->setBackgroundMode(backgroundMode());
    else if (invisible->backgroundMode() != NoBackground)
        invisible->setBackgroundMode(NoBackground);

    if (invisible->isHidden()) {
        invisible->setGeometry(contentsRect());
        invisible->lower();
        invisible->show();
        QApplication::sendPostedEvents(invisible, QEvent::ShowWindowRequest);
    }

    // try to move focus onto the incoming widget if focus
    // was somewhere on the outgoing widget.
    if (topWidget) {
        QWidget * fw = window()->focusWidget();
        if (topWidget->isAncestorOf(fw)) { // focus was on old page
            // look for the best focus widget we can find
            QWidget *p = w->focusWidget();
            if (!p) {
                // second best == first child widget in the focus chain
                QWidget *i = fw;
                while ((i = i->nextInFocusChain()) != fw) {
                    if (((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus)
                            && !i->focusProxy() && i->isVisibleTo(w) && i->isEnabled()
                            && w->isAncestorOf(i)) {
                        p = i;
                        break;
                    }
                }
            }
            if (p)
                p->setFocus();
        } else {
            // the focus wasn't on the old page, so we have to ensure focus doesn't go to
            // the widget in the page that last had focus when we show the page again.
            QWidget *oldfw = topWidget->focusWidget();
            if (oldfw)
                oldfw->clearFocus();
        }
    }

    if (isVisible()) {
        emit aboutToShow(w);
        int i = id(w);
        if (i != -1)
            emit aboutToShow(i);
    }

    topWidget = w;

    QObjectList c = children();
    for (int i = 0; i < c.size(); ++i) {
        QObject * o = c.at(i);
        if (o->isWidgetType() && o != w && o != invisible)
            static_cast<QWidget *>(o)->hide();
    }

    w->setGeometry(invisible->geometry());
    w->show();
}
Пример #25
0
void TestGui::testSearch()
{
    QAction* searchAction = m_mainWindow->findChild<QAction*>("actionSearch");
    QVERIFY(searchAction->isEnabled());
    QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
    QWidget* searchActionWidget = toolBar->widgetForAction(searchAction);
    EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
    QLineEdit* searchEdit = m_dbWidget->findChild<QLineEdit*>("searchEdit");
    QToolButton* clearSearch = m_dbWidget->findChild<QToolButton*>("clearButton");

    QVERIFY(!searchEdit->hasFocus());

    // Enter search
    QTest::mouseClick(searchActionWidget, Qt::LeftButton);
    QTRY_VERIFY(searchEdit->hasFocus());
    // Search for "ZZZ"
    QTest::keyClicks(searchEdit, "ZZZ");
    QTRY_COMPARE(entryView->model()->rowCount(), 0);
    // Escape
    QTest::keyClick(m_mainWindow, Qt::Key_Escape);
    QTRY_VERIFY(!searchEdit->hasFocus());
    // Enter search again
    QTest::mouseClick(searchActionWidget, Qt::LeftButton);
    QTRY_VERIFY(searchEdit->hasFocus());
    // Input and clear
    QTest::keyClicks(searchEdit, "ZZZ");
    QTRY_COMPARE(searchEdit->text(), QString("ZZZ"));
    QTest::mouseClick(clearSearch, Qt::LeftButton);
    QTRY_COMPARE(searchEdit->text(), QString(""));
    // Triggering search should select the existing text
    QTest::keyClicks(searchEdit, "ZZZ");
    QTest::mouseClick(searchActionWidget, Qt::LeftButton);
    QTRY_VERIFY(searchEdit->hasFocus());
    // Search for "some"
    QTest::keyClicks(searchEdit, "some");
    QTRY_COMPARE(entryView->model()->rowCount(), 4);

    clickIndex(entryView->model()->index(0, 1), entryView, Qt::LeftButton);
    QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
    QVERIFY(entryEditAction->isEnabled());
    QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction);
    QVERIFY(entryEditWidget->isVisible());
    QVERIFY(entryEditWidget->isEnabled());
    QTest::mouseClick(entryEditWidget, Qt::LeftButton);

    QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode);

    EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
    QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
    QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);

    QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::ViewMode);

    clickIndex(entryView->model()->index(1, 0), entryView, Qt::LeftButton);
    QAction* entryDeleteAction = m_mainWindow->findChild<QAction*>("actionEntryDelete");

    QWidget* entryDeleteWidget = toolBar->widgetForAction(entryDeleteAction);
    QVERIFY(entryDeleteWidget->isVisible());
    QVERIFY(entryDeleteWidget->isEnabled());
    QVERIFY(!m_db->metadata()->recycleBin());

    QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);

    QCOMPARE(entryView->model()->rowCount(), 3);
    QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 1);

    clickIndex(entryView->model()->index(1, 0), entryView, Qt::LeftButton);
    clickIndex(entryView->model()->index(2, 0), entryView, Qt::LeftButton, Qt::ControlModifier);
    QCOMPARE(entryView->selectionModel()->selectedRows().size(), 2);

    MessageBox::setNextAnswer(QMessageBox::No);
    QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
    QCOMPARE(entryView->model()->rowCount(), 3);
    QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 1);

    MessageBox::setNextAnswer(QMessageBox::Yes);
    QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
    QCOMPARE(entryView->model()->rowCount(), 1);
    QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 3);

    QWidget* closeSearchButton = m_dbWidget->findChild<QToolButton*>("closeSearchButton");
    QTest::mouseClick(closeSearchButton, Qt::LeftButton);

    QCOMPARE(entryView->model()->rowCount(), 1);
}
Пример #26
0
void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
{
    if (qApp->d_func()->inPopupMode()) {
        QWidget *activePopupWidget = qApp->activePopupWidget();
        QWidget *popup = activePopupWidget;
        QPoint mapped = event->pos();
        if (popup != m_widget)
            mapped = popup->mapFromGlobal(event->globalPos());
        bool releaseAfter = false;
        QWidget *popupChild  = popup->childAt(mapped);

        if (popup != qt_popup_down) {
            qt_button_down = 0;
            qt_popup_down = 0;
        }

        switch (event->type()) {
        case QEvent::MouseButtonPress:
        case QEvent::MouseButtonDblClick:
            qt_button_down = popupChild;
            qt_popup_down = popup;
            break;
        case QEvent::MouseButtonRelease:
            releaseAfter = true;
            break;
        default:
            break; // nothing for mouse move
        }

        int oldOpenPopupCount = openPopupCount;

        if (popup->isEnabled()) {
            // deliver event
            qt_replay_popup_mouse_event = false;
            QWidget *receiver = popup;
            QPoint widgetPos = mapped;
            if (qt_button_down)
                receiver = qt_button_down;
            else if (popupChild)
                receiver = popupChild;
            if (receiver != popup)
                widgetPos = receiver->mapFromGlobal(event->globalPos());
            QWidget *alien = m_widget->childAt(m_widget->mapFromGlobal(event->globalPos()));
            QMouseEvent e(event->type(), widgetPos, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers());
            e.setTimestamp(event->timestamp());
            QApplicationPrivate::sendMouseEvent(receiver, &e, alien, m_widget, &qt_button_down, qt_last_mouse_receiver);
        } else {
            // close disabled popups when a mouse button is pressed or released
            switch (event->type()) {
            case QEvent::MouseButtonPress:
            case QEvent::MouseButtonDblClick:
            case QEvent::MouseButtonRelease:
                popup->close();
                break;
            default:
                break;
            }
        }

        if (qApp->activePopupWidget() != activePopupWidget
            && qt_replay_popup_mouse_event) {
            if (m_widget->windowType() != Qt::Popup)
                qt_button_down = 0;
            qt_replay_popup_mouse_event = false;
#ifndef QT_NO_CONTEXTMENU
        } else if (event->type() == QEvent::MouseButtonPress
                   && event->button() == Qt::RightButton
                   && (openPopupCount == oldOpenPopupCount)) {
            QWidget *popupEvent = popup;
            if (qt_button_down)
                popupEvent = qt_button_down;
            else if(popupChild)
                popupEvent = popupChild;
            QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers());
            QApplication::sendSpontaneousEvent(popupEvent, &e);
#endif
        }

        if (releaseAfter) {
            qt_button_down = 0;
            qt_popup_down = 0;
        }
        return;
    }

    // modal event handling
    if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type()))
        return;

    // which child should have it?
    QWidget *widget = m_widget->childAt(event->pos());
    QPoint mapped = event->pos();

    if (!widget)
        widget = m_widget;

    if (event->type() == QEvent::MouseButtonPress && !qt_button_down)
        qt_button_down = widget;

    QWidget *receiver = QApplicationPrivate::pickMouseReceiver(m_widget, event->windowPos().toPoint(), &mapped, event->type(), event->buttons(),
                                                               qt_button_down, widget);

    if (!receiver) {
        if (event->type() == QEvent::MouseButtonRelease)
            QApplicationPrivate::mouse_buttons &= ~event->button();
        return;
    }

    QMouseEvent translated(event->type(), mapped, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers());
    translated.setTimestamp(event->timestamp());
    QApplicationPrivate::sendMouseEvent(receiver, &translated, widget, m_widget, &qt_button_down,
                                        qt_last_mouse_receiver);

#ifndef QT_NO_CONTEXTMENU
    if (event->type() == QEvent::MouseButtonPress && event->button() == Qt::RightButton) {
        QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers());
        QGuiApplication::sendSpontaneousEvent(receiver, &e);
    }
#endif
}
Пример #27
0
bool Controller::eventFilter( QObject * watched, QEvent * event )
{
	QWidget* v = view();
	if( watched != v )
		return false;

	bool done = false;

    // ignore mouse events when disabled
    if ( v && !v->isEnabled()) 
	{
        switch(event->type()) 
		{
        case QEvent::MouseButtonPress:
        case QEvent::MouseButtonRelease:
        case QEvent::MouseButtonDblClick:
        case QEvent::MouseMove:
        // case QEvent::ContextMenu:
        case QEvent::Wheel:
            return false;
        default:
            break;
        }
    }
    switch (event->type()) 
	{
    case QEvent::MouseMove:
        done = mouseMoveEvent((QMouseEvent*)event);
        break;

    case QEvent::MouseButtonPress:
        done = mousePressEvent((QMouseEvent*)event);
        break;

    case QEvent::MouseButtonRelease:
        done = mouseReleaseEvent((QMouseEvent*)event);
        break;

    case QEvent::MouseButtonDblClick:
        done = mouseDoubleClickEvent((QMouseEvent*)event);
        break;
    case QEvent::Wheel:
        done = wheelEvent((QWheelEvent*)event);
        break;
    case QEvent::KeyPress: {
        QKeyEvent *k = (QKeyEvent *)event;
        bool res = false;
        if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
            if (k->key() == Qt::Key_Backtab
                || (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier)))
                res = focusNextPrevChild(false);
            else if (k->key() == Qt::Key_Tab)
                res = focusNextPrevChild(true);
            if (res)
                break;
        }
        done = keyPressEvent(k);
		}
        break;

    case QEvent::KeyRelease:
        done = keyReleaseEvent((QKeyEvent*)event);
        // fall through
    case QEvent::ShortcutOverride:
        break;

    case QEvent::InputMethod:
        done = inputMethodEvent((QInputMethodEvent *) event);
        break;

    case QEvent::FocusIn:
        done = focusInEvent((QFocusEvent*)event);
        break;

    case QEvent::FocusOut:
        done = focusOutEvent((QFocusEvent*)event);
        break;

    case QEvent::Enter:
        done = enterEvent(event);
        break;

    case QEvent::Leave:
        done = leaveEvent(event);
        break;

    case QEvent::Show:
        done = showEvent((QShowEvent*) event);
        break;

    case QEvent::Hide:
        done = hideEvent((QHideEvent*) event);
        break;

    case QEvent::Paint:
        // At this point the event has to be delivered, regardless
        // whether the widget isVisible() or not because it
        // already went through the filters
        done = paintEvent((QPaintEvent*)event);
        break;

    case QEvent::Move:
        done = moveEvent((QMoveEvent*)event);
        break;

    case QEvent::Resize:
        done = resizeEvent((QResizeEvent*)event);
        break;

    case QEvent::Close:
        done = closeEvent((QCloseEvent *)event);
        break;

		/* RK Das überlassen wir weiterhin dem QWidget, da wir ja Gui::Menu haben
    case QEvent::ContextMenu:
        switch (data->context_menu_policy) {
        case Qt::DefaultContextMenu:
            contextMenuEvent(static_cast<QContextMenuEvent *>(event));
            break;
        case Qt::CustomContextMenu:
            emit customContextMenuRequested(static_cast<QContextMenuEvent *>(event)->pos());
            break;
        case Qt::ActionsContextMenu:
            if (d->actions.count()) {
                QMenu::exec(d->actions, static_cast<QContextMenuEvent *>(event)->globalPos());
                break;
            }
            // fall through
        default:
            event->ignore();
            break;
        }
        break;
		*/

    case QEvent::Drop:
        done = dropEvent((QDropEvent*) event);
        break;

    case QEvent::DragEnter:
        done = dragEnterEvent((QDragEnterEvent*) event);
        break;

    case QEvent::DragMove:
        done = dragMoveEvent((QDragMoveEvent*) event);
        break;

    case QEvent::DragLeave:
        done = dragLeaveEvent((QDragLeaveEvent*) event);
        break;

    case QEvent::ToolBarChange:
    case QEvent::ActivationChange:
    case QEvent::EnabledChange:
    case QEvent::FontChange:
    case QEvent::StyleChange:
    case QEvent::PaletteChange:
    case QEvent::WindowTitleChange:
    case QEvent::IconTextChange:
    case QEvent::ModifiedChange:
    case QEvent::MouseTrackingChange:
    case QEvent::ParentChange:
    case QEvent::WindowStateChange:
    case QEvent::LanguageChange:
        done = changeEvent( event);
        break;

	case QEvent::Timer:
		done = tickEvent( (QTimerEvent *)event);
		break;
    default:
        return QObject::eventFilter(watched, event);
    }
    return done;
}
Пример #28
0
void QWidgetStack::raiseWidget( QWidget *w )
{
    if ( !w || w == invisible || w->parent() != this || w == topWidget )
	return;

    if ( id(w) == -1 )
	addWidget( w );
    if ( !isVisible() ) {
	topWidget = w;
	return;
    }

    if (w->maximumSize().width() < invisible->width()
        || w->maximumSize().height() < invisible->height())
        invisible->setBackgroundMode(backgroundMode());
    else if (invisible->backgroundMode() != NoBackground)
        invisible->setBackgroundMode(NoBackground);

    if ( invisible->isHidden() ) {
	invisible->setGeometry( contentsRect() );
	invisible->lower();
	invisible->show();
	QApplication::sendPostedEvents( invisible, QEvent::ShowWindowRequest );
    }

    // try to move focus onto the incoming widget if focus
    // was somewhere on the outgoing widget.
    if ( topWidget ) {
	QWidget * fw = focusWidget();
	QWidget* p = fw;
	while ( p && p != topWidget )
	    p = p->parentWidget();
	if ( p == topWidget ) { // focus was on old page
	    if ( !focusWidgets )
		focusWidgets = new QPtrDict<QWidget>( 17 );
	    focusWidgets->replace( topWidget, fw );
	    fw->clearFocus();
	    // look for the best focus widget we can find
	    // best == what we had (which may be deleted)
	    fw = focusWidgets->take( w );
	    if ( isChildOf( fw, w ) ) {
		fw->setFocus();
	    } else {
		// second best == first child widget in the focus chain
		QFocusData *f = focusData();
		QWidget* home = f->home();
		QWidget *i = home;
		do {
		    if ( ( ( i->focusPolicy() & TabFocus ) == TabFocus )
			 && !i->focusProxy() && i->isVisibleTo(w) && i->isEnabled() ) {
			p = i;
			while ( p && p != w )
			    p = p->parentWidget();
			if ( p == w ) {
			    i->setFocus();
			    break;
			}
		    }
		    i = f->next();
		} while( i != home );
	    }
	}
    }

    if ( isVisible() ) {
	emit aboutToShow( w );
	int i = id( w );
	if ( i != -1 )
	    emit aboutToShow( i );
    }

    topWidget = w;

    const QObjectList * c = children();
    QObjectListIt it( *c );
    QObject * o;

    while( (o=it.current()) != 0 ) {
	++it;
	if ( o->isWidgetType() && o != w && o != invisible )
	    ((QWidget *)o)->hide();
    }

    w->setGeometry( invisible->geometry() );
    w->show();
}
Пример #29
0
QWidget* QgsAttributeEditor::createWidgetFromDef( const QgsAttributeEditorElement* widgetDef, QWidget* parent, QgsVectorLayer* vl, QgsAttributeMap &attrs, QMap<int, QWidget*> &proxyWidgets, bool createGroupBox )
{
  QWidget *newWidget = 0;

  switch ( widgetDef->type() )
  {
    case QgsAttributeEditorElement::AeTypeField:
    {
      const QgsAttributeEditorField* fieldDef = dynamic_cast<const QgsAttributeEditorField*>( widgetDef );
      newWidget = createAttributeEditor( parent, 0, vl, fieldDef->idx(), attrs.value( fieldDef->idx(), QVariant() ), proxyWidgets );


      if ( vl->editType( fieldDef->idx() ) != QgsVectorLayer::Immutable )
      {
        newWidget->setEnabled( newWidget->isEnabled() && vl->isEditable() );
      }

      break;
    }

    case QgsAttributeEditorElement::AeTypeContainer:
    {
      const QgsAttributeEditorContainer* container = dynamic_cast<const QgsAttributeEditorContainer*>( widgetDef );
      QWidget* myContainer;

      if ( createGroupBox )
      {
        QGroupBox* groupBox = new QGroupBox( parent );
        groupBox->setTitle( container->name() );
        myContainer = groupBox;
      }
      else
      {
        myContainer = new QWidget( parent );
      }

      QGridLayout* gbLayout = new QGridLayout( myContainer );

      int index = 0;

      QList<QgsAttributeEditorElement*>children = container->children();

      for ( QList<QgsAttributeEditorElement*>::const_iterator it = children.begin(); it != children.end(); ++it )
      {
        QgsAttributeEditorElement* childDef = *it;
        QWidget* editor = createWidgetFromDef( childDef, myContainer, vl, attrs, proxyWidgets, true );

        if ( childDef->type() == QgsAttributeEditorElement::AeTypeContainer )
        {
          gbLayout->addWidget( editor, index, 0, 1, 2 );
        }
        else
        {
          QLabel * mypLabel = new QLabel( myContainer );
          gbLayout->addWidget( mypLabel, index, 0 );
          mypLabel->setText( childDef->name() );
          gbLayout->addWidget( editor, index, 1 );
        }

        ++index;
      }
      gbLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding ), index , 0 );

      newWidget = myContainer;
      break;
    }

    default:
      QgsDebugMsg( "Unknown attribute editor widget type encountered..." );
      break;
  }

  return newWidget;
}
Пример #30
0
// Parse "Solver specific tab"
//-----------------------------------------------------------------------------
bool SifGenerator::parseSolverSpecificTab(DynamicEditor *solEditor, const QString &solverName)
{
  // Returns true if there is a matrix involved. otherwise returns false.
  if ( !solEditor ) return false;

  bool hasMatrix = true;

  QScriptEngine engine; 

  QScriptValue dim_QSV  = QScriptValue(&engine,dim);
  engine.globalObject().setProperty( "dim", dim_QSV );

  QScriptValue cdim_QSV = QScriptValue(&engine,cdim);
  engine.globalObject().setProperty( "cdim", cdim_QSV );

  for(int i = 0; i < solEditor->hash.count(); i++) {
    hash_entry_t entry = solEditor->hash.values().at(i);

    QString key = solEditor->hash.keys().at(i);
    QStringList keySplitted = key.split("/");	  
    QString tabName   = keySplitted.at(1).trimmed();
    QString labelName = keySplitted.at(3).trimmed();

    if ( tabName != solverName ) continue;

    // Has matrix?
    if(labelName == "No Matrix Equation") {
      if(entry.elem.attribute("Widget", "") == "CheckBox") {
	QCheckBox *cb = static_cast<QCheckBox*>(entry.widget);
	hasMatrix = !cb->isChecked();
      }
    }

    // variable names handled separately...
    // ------------------------------------
    if ( labelName=="Variable" || labelName.mid(0,17)=="Exported Variable" ) {
      if( entry.elem.attribute("Widget", "") != "Edit") continue;

      QLineEdit *l = static_cast<QLineEdit*>(entry.widget);
      QString varName = l->text().trimmed();

      if ( varName == "" ) continue;

      int dofs=1;
      QStringList dofsplit = varName.split("[");
      if ( dofsplit.count()>1 ) {
        varName = dofsplit.at(0).trimmed() + "[";
        QString dof = dofsplit.at(1).trimmed();
        dof = dof.split("]").at(0).trimmed();

        dofsplit = dof.split(":");
        QString subVarName = dofsplit.at(0).trimmed();
        for( int i=1; i<dofsplit.count(); i++)
        {
          dof = dofsplit.at(i).trimmed();

          QStringList subDofSplit = dof.split(" ");
          QString subDof = subDofSplit.at(0).trimmed();

          dofs = engine.evaluate(subDof).toInt32();
          if (i>1) varName = varName + " ";
          varName = varName + subVarName + ":" + QString::number(dofs);

          if ( subDofSplit.count() > 1 )
            subVarName = subDofSplit.at(1).trimmed();
        }
        varName = varName + "]";
        addSifLine( "  " + labelName + " = ", varName );
      } else {
        dofsplit = varName.split("(");
        if ( dofsplit.count()>1 ) {
          varName = dofsplit.at(0).trimmed();
          QString dof = dofsplit.at(1).trimmed();
          dofsplit = dof.split(")");
          dof = dofsplit.at(0).trimmed();
          dofs = engine.evaluate(dof).toInt32();
        }
	// Don't write the the trivial dof==1 case as this leaves possibility to define the number of
	// dofs internally within the solver. 
        if ( dofs <= 1 ) {
	  addSifLine( "  "+labelName+" = ", varName );
	  dofs = 1;
	}
	else {
	  addSifLine( "  "+labelName+" = -dofs ",  QString::number(dofs) + " " + varName );
	}
      }
      continue;
    }

    QWidget *widget = entry.widget;

    QDomElement elem;
    if ( widget->isEnabled() ) {
      elem = entry.elem;

      if(elem.attribute("Widget", "") == "CheckBox")
       handleCheckBox(elem, widget);

     if(elem.attribute("Widget", "") == "Edit")
       handleLineEdit(elem, widget);

     if(elem.attribute("Widget", "") == "Combo")
       handleComboBox(elem, widget);

     if(elem.attribute("Widget", "") == "TextEdit")
       handleTextEdit(elem, widget);
    }
  }

  return hasMatrix;
}