Esempio n. 1
0
static QWidget * find_child( QWidget * tlw, QPoint & p )
{
    QWidget * w = tlw;

    p = w->mapFromGlobal( p );
    bool done = FALSE;
    while ( !done ) {
	done = TRUE;
	if ( ((QExtraWidget*)w)->extraData() &&
	     ((QExtraWidget*)w)->extraData()->xDndProxy != 0 )
	    break; // stop searching for widgets under the mouse cursor if found widget is a proxy.
	if ( w->children() ) {
	    QObjectListIt it( *w->children() );
	    it.toLast();
	    QObject * o;
	    while( (o=it.current()) ) {
		--it;
		if ( o->isWidgetType() &&
		     ((QWidget*)o)->isVisible() &&
		     ((QWidget*)o)->geometry().contains( p ) &&
		     !((QWidget*)o)->isTopLevel()) {
		    w = (QWidget *)o;
		    done = FALSE;
		    p = w->mapFromParent( p );
		    break;
		}
	    }
	}
    }
    return w;
}
Esempio n. 2
0
static QWidget * find_child( QWidget * tlw, QPoint & p )
{
    QWidget * w = tlw;

    p = w->mapFromGlobal( p );
    bool done = FALSE;
    while ( !done ) {
	done = TRUE;
	if ( w->children() ) {
	    QObjectListIt it( *w->children() );
	    it.toLast();
	    QObject * o;
	    while( (o=it.current()) ) {
		--it;
		if ( o->isWidgetType() &&
		     ((QWidget*)o)->isVisible() &&
		     ((QWidget*)o)->geometry().contains( p ) ) {
		    w = (QWidget *)o;
		    done = FALSE;
		    p = w->mapFromParent( p );
		    break;
		}
	    }
	}
    }
    return w;
}
Esempio n. 3
0
Support::ToolSelector* GraphicsView::
        toolSelector(int index, Tools::Commands::CommandInvoker* state)
{
    while (index >= layout_widget_->layout()->count())
    {
        EXCEPTION_ASSERT( state );

        QWidget* parent = new QWidget();
        parent->setLayout(new QVBoxLayout());
        parent->layout()->setMargin(0);

        Support::ToolSelector* tool_selector = new Support::ToolSelector( state, parent );
        tool_selector->setParent( parent );

        layout_widget_->layout()->addWidget( parent );
    }

    QWidget* parent = layout_widget_->layout()->itemAt(index)->widget();
    for (int i = 0; i<parent->children().count(); ++i)
    {
        Support::ToolSelector* t = dynamic_cast<Support::ToolSelector*>( parent->children().at(i) );
        if (t)
            return t;
    }

    throw std::logic_error("Support::ToolSelector* GraphicsView::toolSelector");
}
Esempio n. 4
0
int main(int argc,char **argv)
{
    QApplication application(argc,argv);

    QWidget container;
    QVBoxLayout *layout = new QVBoxLayout(&container);

    QPushButton *MyButton = new QPushButton("Press Me");
    QLabel *MyLabel=new QLabel("I am a  label");


    layout->addWidget(MyButton);

    layout->addWidget(MyLabel);

    container.show();

    qDebug() << "Layout Children:" << layout->children().count();
    qDebug() << "Container Children:" << container.children().count();



    QDataStream stream();


    return application.exec();

}
Esempio n. 5
0
void PaletteTreeWidgets::resizeIcons()
{
	if (mParentPalette->iconsView() && mParentPalette->itemsCountInARow() > 1) {
		const int iconSize = 48;
		const int widgetSize = this->size().width() - (iconSize << 1);
		const int itemsCount = maxItemsCountInARow();
		const int newSize = (widgetSize < itemsCount * iconSize)
				? (widgetSize / itemsCount) : iconSize;
		for (int i = 0; i < mEditorTree->topLevelItemCount(); i++) {
			for (int j = 0; j < mEditorTree->topLevelItem(i)->childCount(); j++) {
				QWidget *field = mEditorTree->itemWidget(mEditorTree->topLevelItem(i)->child(j), 0);
				if (!field) {
					break;
				}

				for (QObject *child : field->children()) {
					DraggableElement *element = dynamic_cast<DraggableElement*>(child);
					if (element) {
						element->setIconSize(newSize);
					}
				}
			}
		}
	}
}
Esempio n. 6
0
bool SGMainWindowEvent::eventFilter(QObject* object, QEvent* evt) {
	QWidget* focusWidget = QApplication::focusWidget();
	if (focusWidget == NULL) return true;
	if (m_focusWidgetName == focusWidget->objectName().toStdString().c_str()) return QObject::eventFilter(object, evt);

	QObjectList objList = focusWidget->children();
	bool glWidgetExists = false;
	for (int i = 0; i < objList.length(); i++) {
		QWidget* widget = (QWidget*)objList[i];
		QObjectList objList2 = widget->children();
		for (int j = 0; j < objList2.length(); j++) {
			QWidget* widget2 = (QWidget*)objList2[j];
			if (strcmp(widget2->metaObject()->className(), "QmayaGLWidget") == 0) {
				if (m_beforeWidget != NULL) {
					m_beforeWidget->releaseKeyboard();
					m_beforeWidget->removeEventFilter(toolEvent);
				}
				widget2->installEventFilter(toolEvent);
				widget2->grabKeyboard();

				m_beforeWidget = widget2;

				m_focusWidgetName = focusWidget->objectName().toStdString().c_str();
				glWidgetExists = true;

				SGKey::initializeKeys();
				SGMouse::initializeButtons();
				break;
			}
		}
		if (glWidgetExists)break;
	}

	if (!glWidgetExists) {
		if (m_beforeWidget != NULL) {
			m_beforeWidget->releaseKeyboard();
			m_beforeWidget->removeEventFilter(toolEvent);
		}
		m_focusWidgetName = focusWidget->objectName().toStdString().c_str();
	}

	return QObject::eventFilter(object, evt);
}
Esempio n. 7
0
void MainWindow::onHmidataRuning(bool val){
    QWidget *tab = tabWidget->widget(4);//test widget
    QObjectList list = tab->children();
    foreach(QObject *widget,list){
        if(widget->isWidgetType()){
            ((QWidget *)widget)->setDisabled(val);
        }
    }
    qMdPushButton_11->setDisabled(val);//shazui updown
}
Esempio n. 8
0
void QRWindow::outputSizeReport() {
   if (!m_isDebugMode) return;
   printf("\n\n=============================================[Size Report]===\n");
   stack <QList<QWidget *> > stackWidgets;
   
   QList<QWidget *> listWidgets; listWidgets.append(this);
   stackWidgets.push(listWidgets);
    
   while (!stackWidgets.empty()) {
      QList<QWidget *> widgets = stackWidgets.top(); stackWidgets.pop();
      bool new_level = false;
      while (widgets.size() && !new_level) {
         QWidget *widget = widgets.takeFirst();
         if (QROSE::getName(widget) != "") {
            printf("%*c%s [w:%d,h:%d,x:%d,y:%d]\n", (int) (3*stackWidgets.size()), ' ', 
                QROSE::getName(widget).c_str(), 
                widget->width(), widget->height(),
                widget->x(), widget->y());            
         }
         QList<QWidget *> childrenW;
         int n = widget->children().size();
         for (int i = 0; i < n; i++) {
             QObject *obj = widget->children().at(i);
             if (obj->isWidgetType()) {
                childrenW.append((QWidget *)obj);
             }
         }
         
         if (childrenW.size() != 0) {
            new_level = true;
            stackWidgets.push(widgets);
            stackWidgets.push(childrenW);
         }       
      }
   }
   printf("=============================================================\n");
   
}
Esempio n. 9
0
void DayWidget::setInMotion(bool value)
{
	if (m_inMotion == value)
		return;

	m_inMotion = value;

	if (m_inMotion) { // record the above widget and put itself in the stack top
		QWidget *parent = parentWidget();
		m_aboveWidget = 0;
		for (int index = parent->children().indexOf(this) + 1; index < parent->children().count(); index++) {
			QWidget *widget = qobject_cast<QWidget*>(parent->children()[index]);
			if (widget) {
				m_aboveWidget = widget;
				break;
			}
		}
		raise();
	} else { // restore the widget in the stack
		if (m_aboveWidget)
			stackUnder(m_aboveWidget);
	}
}
Esempio n. 10
0
	void UiManager::mousePressEvent(QMouseEvent *event)
	{
		QWidget *pressedWidget = NULL;
	
		// get the clicked item through the view (respects view and item transformations)
		QGraphicsItem* itemAt = mWidgetView->itemAt(event->pos());
		if ((itemAt) && (itemAt->isWidget()))
		{
			QGraphicsProxyWidget *proxyWidget = qgraphicsitem_cast<QGraphicsProxyWidget *>(itemAt);
			if (proxyWidget)
			{
				QWidget *embeddedWidget = proxyWidget->widget();
	
				// if the widget has children, use them, otherwise use the widget directly
				if (embeddedWidget->children().size() > 0)
				{
					QPoint widgetPoint = proxyWidget->mapFromScene(mWidgetView->mapToScene(event->pos())).toPoint();
					pressedWidget = embeddedWidget->childAt(widgetPoint);
				}
				else
				{
					pressedWidget = embeddedWidget;
				}
			}
		}
	
		// if there was a focused widget and there is none or a different one now, defocus
		if (mFocusedWidget && (!pressedWidget || pressedWidget != mFocusedWidget))
		{
			QEvent foe(QEvent::FocusOut);
			QApplication::sendEvent(mFocusedWidget, &foe);
			mFocusedWidget = NULL;
			mTopLevelWidget->setFocus();
		}
	
		// set the new focus
		if (pressedWidget)
		{
			QEvent fie(QEvent::FocusIn);
			QApplication::sendEvent(pressedWidget, &fie);
			pressedWidget->setFocus(Qt::MouseFocusReason);
			mFocusedWidget = pressedWidget;
		}
	
		QApplication::sendEvent(mWidgetView->viewport(), event);
	}
Esempio n. 11
0
int PaletteTreeWidgets::maxItemsCountInARow() const
{
	int max = 0;
	for (int i = 0; i < mEditorTree->topLevelItemCount(); i++) {
		for (int j = 0; j < mEditorTree->topLevelItem(i)->childCount(); j++) {
			QWidget *field = mEditorTree->itemWidget(mEditorTree->topLevelItem(i)->child(j), 0);
			if (!field) {
				break;
			}

			int itemsCount = field->children().count();
			if (itemsCount > max) {
				max = itemsCount;
			}
		}
	}
	return max;
}
Esempio n. 12
0
void UISerializationUtil::serialize( TamyEditor* rootWidget, MainEditorPanel* editorsPanel, bool save )
{
   // create the settings instance
   QSettings* uiSettings = new QSettings( "Coversion", "TamyEditor" );

   // serialize the editors manager
   {
      if ( save )
      {
         editorsPanel->saveLayout( *uiSettings );
      }
      else
      {
         editorsPanel->loadLayout( *uiSettings );
      }
   }

   // serialize the hierarchy of widgets
   {
      std::list< QWidget* >   widgetsQueue;
      widgetsQueue.push_back( rootWidget );

      while( !widgetsQueue.empty() )
      {
         QWidget* currWidget = widgetsQueue.front();
         widgetsQueue.pop_front();

         serializeWidgetSettings( *currWidget, *uiSettings, save );

         // analyze the widget's children
         const QObjectList& children = currWidget->children();
         foreach( QObject* obj, children )
         {
            QWidget* childWidget = dynamic_cast< QWidget* >( obj );
            if ( childWidget )
            {
               widgetsQueue.push_back( childWidget );
            }
         }
      }
   }
Esempio n. 13
0
void Note::showLineNumbers(bool show)
{
	if (d_line_number_enabled == show)
		return;

	d_line_number_enabled = show;

	for (int i = 0; i < d_tab_widget->count(); i++){
		QWidget *w = d_tab_widget->widget(i);
		if (!w)
			continue;

		QObjectList lst = w->children();
		foreach (QObject *obj, lst){
			LineNumberDisplay *display = qobject_cast<LineNumberDisplay *>(obj);
			if (display){
				display->setVisible(show);
				break;
			}
		}
	}
Esempio n. 14
0
void WidgetSizeHelper::setDefaultFontSize(QWidget* pWidget) {

    // we get all of pWidget's children
    QObjectList children = pWidget->children();

    // for each child
    for ( int i = 0; i < children.length(); i++ ) {

        /*
         * we change its font size if it is of one of those types
         *
         *  - QLabel
         *  - QLineEdit
         *  - QRadioButton
         *  - QGroupBox
         *  - QCheckBox
         *  - QStatusBar
         */
        QWidget* pChild = static_cast<QWidget*> ( children.at(i) );

        if (  qobject_cast<QLabel*>(pChild) != NULL         ||
              qobject_cast<QLineEdit*>(pChild) != NULL      ||
              qobject_cast<QRadioButton*>(pChild) != NULL   ||
              qobject_cast<QGroupBox*>(pChild) != NULL      ||
              qobject_cast<QCheckBox*>(pChild) != NULL      ||
              qobject_cast<QStatusBar*>(pChild) != NULL )
        {
            QFont lFont = pChild->font();
            lFont.setPointSize(Constants::MAC_FONT_SIZE);
            pChild->setFont(lFont);
        }

        // and scan it, if it has children
        if (  ! pChild->children().isEmpty() ) {

            setDefaultFontSize( pChild );
        }
    }
}
Esempio n. 15
0
static QString buddyString(const QWidget *widget)
{
    if (!widget)
        return QString();
    QWidget *parent = widget->parentWidget();
    if (!parent)
        return QString();
#ifndef QT_NO_SHORTCUT
    QObjectList ol = parent->children();
    for (int i = 0; i < ol.size(); ++i) {
        QLabel *label = qobject_cast<QLabel*>(ol.at(i));
        if (label && label->buddy() == widget)
            return label->text();
    }
#endif

#ifndef QT_NO_GROUPBOX
    QGroupBox *groupbox = qobject_cast<QGroupBox*>(parent);
    if (groupbox)
        return groupbox->title();
#endif

    return QString();
}
Esempio n. 16
0
void MainWindow::setupGui()
{
    QWidget* centralWidget = NULL;
#ifdef USE_OPENGL_RENDER

    if(player() && player()->isSupportOpenGL() && m_opengl_enabled)
    {
        bool opengl_windget_created = false;
        do {
            // Enable OpenGL render
            centralWidget = new OpenGLWidgetContainer;
            QOpenGLWidget* opengl_widget = dynamic_cast<QOpenGLWidget*>(centralWidget);
            if(!opengl_widget)
            {
                WARN() << "OpenGL widget not created!";
                break;
            }

            QOpenGLContext* opengl_context = opengl_widget->context();
            if(!opengl_context)
            {
                WARN() << "Invalid OpenGL context!";
                break;
            }
            QPair<int,int> opengl_version = opengl_context->format().version();
            if(!opengl_widget->isValid() || opengl_version.first < 2) // Disable OpenGL for virtualbox
            {
                WARN() << "Invalid OpenGL version!";
                break;
            }
        } while(false);

        if(!opengl_windget_created)
        {
            WARN() << "Can't instantinate OpenGL widget. Falling back to QWidget";
            delete centralWidget;
            centralWidget = new QWidget(this);
        }
    }
    else
    {
        DEBUG() << "OpenGL is disabled or player doesn't support OpenGL rendering. Creating a QWidget renderer";
        centralWidget = new QWidget(this);
    }

#else
    centralWidget = new QWidget(this);
#endif //USE_OPENGL_RENDER
    QStackedLayout* stackedLayout = new QStackedLayout;
    stackedLayout->setObjectName("stackedLayout");
    centralWidget->setLayout(stackedLayout);
    //centralWidget->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    this->setCentralWidget(centralWidget);

    if(browser())
    {
        browser()->setParentWidget(centralWidget);
        browser()->setLayout(stackedLayout);
        browser()->createNewPage();
    }
    else
        WARN() << "Browser plugin not found! The app may not work correctly!";

    if(player() != NULL && player()->isInitialized())
    {
        player()->setAspectRatio(SDK::ASPECT_RATIO_AUTO);
        player()->widget()->setParent(centralWidget);
        stackedLayout->addWidget(player()->widget());
        player()->show();
    }
    else
        WARN() << "No mediplayer plugin found. Media will be disabled!";

    gui()->setTopWidget(SDK::GUI::TOP_WIDGET_BROWSER);

    setMouseTracking(true);
    resizeWebView();

    for(QObject* widget: centralWidget->children())
    {
        DEBUG() << "Stack child" << widget;
    }
}
Esempio n. 17
0
/* Overloading the AbstractController one, because we don't manage the
   Spacing items in the same ways */
void DroppingController::createAndAddWidget( QBoxLayout *newControlLayout,
                                             int i_index,
                                             buttonType_e i_type,
                                             int i_option )
{
    /* Special case for SPACERS, who aren't QWidgets */
    if( i_type == WIDGET_SPACER || i_type == WIDGET_SPACER_EXTEND )
    {
        QLabel *label = new QLabel( this );
        label->setPixmap( ImageHelper::loadSvgToPixmap( ":/toolbar/space.svg", height(), height() ) );
        if( i_type == WIDGET_SPACER_EXTEND )
        {
            label->setSizePolicy( QSizePolicy::MinimumExpanding,
                    QSizePolicy::Preferred );

            /* Create a box around it */
            label->setFrameStyle( QFrame::Panel | QFrame::Sunken );
            label->setLineWidth ( 1 );
            label->setAlignment( Qt::AlignCenter );
        }
        else
            label->setSizePolicy( QSizePolicy::Fixed,
                    QSizePolicy::Preferred );

        /* Install event Filter for drag'n drop */
        label->installEventFilter( this );
        newControlLayout->insertWidget( i_index, label );
    }

    /* Normal Widgets */
    else
    {
        QWidget *widg = createWidget( i_type, i_option );
        if( !widg ) return;

        /* Install the Event Filter in order to catch the drag */
        widg->setParent( this );
        widg->installEventFilter( this );

        /* We are in a complex widget, we need to stop events on children too */
        if( i_type >= TIME_LABEL && i_type < SPECIAL_MAX )
        {
            QList<QObject *>children = widg->children();

            QObject *child;
            foreach( child, children )
            {
                QWidget *childWidg;
                if( ( childWidg = qobject_cast<QWidget *>( child ) ) )
                {
                    child->installEventFilter( this );
                    childWidg->setEnabled( true );
                }
            }

            /* Decorating the frames when possible */
            QFrame *frame;
            if( (i_type >= MENU_BUTTONS || i_type == TIME_LABEL) /* Don't bother to check for volume */
                && ( frame = qobject_cast<QFrame *>( widg ) ) != NULL )
            {
                frame->setFrameStyle( QFrame::Panel | QFrame::Raised );
                frame->setLineWidth ( 1 );
            }
        }
void ParametersToolBox::updateParametersVisibility()
{
	//show/hide not used parameters
	QComboBox * descriptorBox = this->findChild<QComboBox*>(Settings::kFeature2D_2Descriptor());
	QComboBox * detectorBox = this->findChild<QComboBox*>(Settings::kFeature2D_1Detector());
	if(descriptorBox && detectorBox)
	{
		QString group = Settings::kFeature2D_2Descriptor().split('/').first();
		QWidget * panel = 0;
		for(int i=0; i<this->count(); ++i)
		{
			if(this->widget(i)->objectName().compare(group) == 0)
			{
				panel = this->widget(i);
				break;
			}
		}
		if(panel)
		{
			const QObjectList & objects = panel->children();
			QString descriptorName = descriptorBox->currentText();
			QString detectorName = detectorBox->currentText();

			for(int i=0; i<objects.size(); ++i)
			{
				if(!objects[i]->objectName().isEmpty())
				{
					if(objects[i]->objectName().contains(descriptorName) || objects[i]->objectName().contains(detectorName))
					{
						((QWidget*)objects[i])->setVisible(true);
					}
					else if(objects[i]->objectName().contains("Fast") && detectorName == QString("ORB"))
					{
						((QWidget*)objects[i])->setVisible(true);	// ORB uses some FAST parameters
					}
					else if(!objects[i]->objectName().split('/').at(1).at(0).isDigit())
					{
						((QWidget*)objects[i])->setVisible(false);
					}
				}
			}
		}
	}

	QComboBox * nnBox = this->findChild<QComboBox*>(Settings::kNearestNeighbor_1Strategy());
	if(nnBox)
	{
		QString group = Settings::kNearestNeighbor_1Strategy().split('/').first();
		QWidget * panel = 0;
		for(int i=0; i<this->count(); ++i)
		{
			if(this->widget(i)->objectName().compare(group) == 0)
			{
				panel = this->widget(i);
				break;
			}
		}
		if(panel)
		{
			const QObjectList & objects = panel->children();
			QString nnName = nnBox->currentText();

			for(int i=0; i<objects.size(); ++i)
			{
				if(!objects[i]->objectName().isEmpty())
				{
					if(objects[i]->objectName().contains(nnName))
					{
						((QWidget*)objects[i])->setVisible(true);
					}
					else if(!objects[i]->objectName().split('/').at(1).at(0).isDigit())
					{
						((QWidget*)objects[i])->setVisible(false);
						if(nnBox->currentIndex() < 6 && objects[i]->objectName().split('/').at(1).contains("search"))
						{
							//show flann search parameters
							((QWidget*)objects[i])->setVisible(true);
						}
					}
					else if(objects[i]->objectName().split('/').at(1).contains("Distance_type"))
					{
						// don't show distance when bruteforce is selected
						((QWidget*)objects[i])->setVisible(nnBox->currentIndex() != 6);
					}
				}
			}
		}
	}
}