Esempio n. 1
0
void QtDNDTabBar::dropEvent(QDropEvent* dropEvent) {
	QtDNDTabBar* sourceTabBar = dynamic_cast<QtDNDTabBar*>(dropEvent->source());
	if (sourceTabBar && dropEvent->mimeData() && dropEvent->mimeData()->data("action") == QByteArray("application/tab-detach")) {
		QtDNDTabBar* source = dynamic_cast<QtDNDTabBar*>(dropEvent->source());

		int targetTabIndex = tabAt(dropEvent->pos());
		QRect rect = tabRect(targetTabIndex);
		if (targetTabIndex >= 0 && (dropEvent->pos().x() - rect.left() - rect.width()/2 > 0)) {
			targetTabIndex++;
		}

		QWidget* tab = source->getDragWidget();
		assert(tab);
		QTabWidget* targetTabWidget = dynamic_cast<QTabWidget*>(parentWidget());

		QString tabText = source->getDragText();

		/*
		 * When you add a widget to an empty QTabWidget, it's automatically made the current widget.
		 * Making the widget the current widget, widget->show() is called for the widget. Directly reacting
		 * to that event, and adding the widget again to the QTabWidget results in undefined behavior. For
		 * example the tab label is shown but the widget is neither has the old nor in the new QTabWidget as
		 * parent. Blocking signals on the QWidget to be added to a QTabWidget prevents this behavior.
		 */
		targetTabWidget->setUpdatesEnabled(false);
		tab->blockSignals(true);
		targetTabWidget->insertTab(targetTabIndex, tab, tabText);
		dropEvent->acceptProposedAction();
		tab->blockSignals(false);
		targetTabWidget->setUpdatesEnabled(true);
		onDropSucceeded();
	}
}
Esempio n. 2
0
void InspectorBase::setElement(Element* e)
      {
      for (int i = 0; i < inspectorItems(); ++i) {
            QWidget* w = item(i).w;
            P_ID id    = item(i).t;
            P_TYPE pt  = propertyType(id);
            QVariant val;
            if (pt == T_SIZE || pt == T_SCALE) {
                  QSizeF sz = e->getProperty(id).toSizeF();
                  if (item(i).sv == 0)
                        val = QVariant(sz.width());
                  else
                        val = QVariant(sz.height());
                  }
            else if (pt == T_POINT) {
                  QPointF sz = e->getProperty(id).toPointF();
                  if (item(i).sv == 0)
                        val = QVariant(sz.x());
                  else
                        val = QVariant(sz.y());
                  }
            else
                  val = e->getProperty(id);

            w->blockSignals(true);
            setValue(i, val);
            w->blockSignals(false);

            QToolButton* r = item(i).r;
            if (r)
                  r->setEnabled(!isDefault(i));
            }
      }
Esempio n. 3
0
void Dataset3D::updateMaskSelect()
{
    QList<Dataset*>dsl1 = Models::getDatasets( Fn::DatasetType::NIFTI_SCALAR, false );

    if( dsl1.size() != m_scalarDSL.size() )
    {
        QWidget* widget = m_properties["maingl"].getWidget( Fn::Property::D_STIPPLE_PROB_MASK );
        widget->blockSignals( true );

        int curScalar = m_properties["maingl"].get( Fn::Property::D_STIPPLE_PROB_MASK ).toInt();

        PropertySelection* prop = static_cast<PropertySelection*> ( m_properties["maingl"].getProperty( Fn::Property::D_STIPPLE_PROB_MASK ) );
        prop->clear();

        for ( int i = 0; i < dsl1.size(); ++i )
        {
            prop->addOption( dsl1[i]->properties().get( Fn::Property::D_NAME ).toString() );
        }

        if ( dsl1.size() > m_scalarDSL.size() )
        {
            m_properties["maingl"].set( Fn::Property::D_STIPPLE_PROB_MASK, qMax( 0, curScalar ) );
        }
        else
        {
            m_properties["maingl"].set( Fn::Property::D_STIPPLE_PROB_MASK, 0 );
        }
        m_scalarDSL.clear();
        for ( int i = 0; i < dsl1.size(); ++i )
        {
            m_scalarDSL.push_back( static_cast<DatasetScalar*>( dsl1[i] ) );
        }
        widget->blockSignals( false );

    }
}
void PEMetadataView::initMetadata(const QDomDocument & doc) 
{
    QWidget * widget = QApplication::focusWidget();
    if (widget) {
        QList<QWidget *> children = m_mainFrame->findChildren<QWidget *>();
        if (children.contains(widget)) {
            widget->blockSignals(true);
        }
    }

    if (m_mainFrame) {
        this->setWidget(NULL);
        delete m_mainFrame;
        m_mainFrame = NULL;
    }

    QDomElement root = doc.documentElement();
    QDomElement label = root.firstChildElement("label");
    QDomElement author = root.firstChildElement("author");
    QDomElement descr = root.firstChildElement("description");
    QDomElement title = root.firstChildElement("title");
    QDomElement date = root.firstChildElement("date");
    QDomElement url = root.firstChildElement("url");

	QStringList readOnlyKeys;
    QHash<QString, QString> tagHash;    
    QDomElement tags = root.firstChildElement("tags");
    QDomElement tag = tags.firstChildElement("tag");
    while (!tag.isNull()) {
        tagHash.insert(tag.text(), "");
        tag = tag.nextSiblingElement("tag");
    }

    QString family;
    QString variant;

    QHash<QString, QString> propertyHash;    
    QDomElement properties = root.firstChildElement("properties");
    QDomElement prop = properties.firstChildElement("property");
    while (!prop.isNull()) {
        QString name = prop.attribute("name");
        QString value = prop.text();
        if (name.compare("family", Qt::CaseInsensitive) == 0) {
            family = value;
        }
        else if (name.compare("variant", Qt::CaseInsensitive) == 0) {
            variant = value;
        }
        else {
            propertyHash.insert(name, value);
        }

        prop = prop.nextSiblingElement("property");
    }


	m_mainFrame = new QFrame(this);
	m_mainFrame->setObjectName("metadataMainFrame");
	QVBoxLayout *mainLayout = new QVBoxLayout(m_mainFrame);
    mainLayout->setSizeConstraint( QLayout::SetMinAndMaxSize );

    QLabel *explanation = new QLabel(tr("This is where you edit the metadata for the part ..."));
    mainLayout->addWidget(explanation);

    QFormLayout * formLayout = new QFormLayout();
    QFrame * formFrame = new QFrame;
    mainLayout->addWidget(formFrame);

    m_titleEdit = new QLineEdit();
    m_titleEdit->setText(title.text());
	connect(m_titleEdit, SIGNAL(editingFinished()), this, SLOT(titleEntry()));
	m_titleEdit->setObjectName("PartsEditorLineEdit");
    m_titleEdit->setStatusTip(tr("Set the part's title"));
    formLayout->addRow(tr("Title"), m_titleEdit);

    m_dateEdit = new QLineEdit();
    m_dateEdit->setText(date.text());
	connect(m_dateEdit, SIGNAL(editingFinished()), this, SLOT(dateEntry()));
	m_dateEdit->setObjectName("PartsEditorLineEdit");
    m_dateEdit->setStatusTip(tr("Set the part's date"));
    m_dateEdit->setEnabled(false);
    formLayout->addRow(tr("Date"), m_dateEdit);

    m_authorEdit = new QLineEdit();
    m_authorEdit->setText(author.text());
	connect(m_authorEdit, SIGNAL(editingFinished()), this, SLOT(authorEntry()));
	m_authorEdit->setObjectName("PartsEditorLineEdit");
    m_authorEdit->setStatusTip(tr("Set the part's author"));
    formLayout->addRow(tr("Author"), m_authorEdit);

    m_descriptionEdit = new FocusOutTextEdit();
    m_descriptionEdit->setText(descr.text());
	m_descriptionEdit->document()->setModified(false);
	connect(m_descriptionEdit, SIGNAL(focusOut()), this, SLOT(descriptionEntry()));
	m_descriptionEdit->setObjectName("PartsEditorTextEdit");
    m_descriptionEdit->setStatusTip(tr("Set the part's description--you can use simple html (as defined by Qt's Rich Text)"));
    formLayout->addRow(tr("Description"), m_descriptionEdit);

    m_labelEdit = new QLineEdit();
    m_labelEdit->setText(label.text());
	connect(m_labelEdit, SIGNAL(editingFinished()), this, SLOT(labelEntry()));
	m_labelEdit->setObjectName("PartsEditorLineEdit");
    m_labelEdit->setStatusTip(tr("Set the default part label prefix"));
    formLayout->addRow(tr("Label"), m_labelEdit);

    m_urlEdit = new QLineEdit();
    m_urlEdit->setText(url.text());
	connect(m_urlEdit, SIGNAL(editingFinished()), this, SLOT(urlEntry()));
	m_urlEdit->setObjectName("PartsEditorLineEdit");
    m_urlEdit->setStatusTip(tr("Set the part's url if it is described on a web page"));
    formLayout->addRow(tr("URL"), m_urlEdit);

    m_familyEdit = new QLineEdit();
    m_familyEdit->setText(family);
	connect(m_familyEdit, SIGNAL(editingFinished()), this, SLOT(familyEntry()));
	m_familyEdit->setObjectName("PartsEditorLineEdit");
    m_familyEdit->setStatusTip(tr("Set the part's family--what other parts is this part related to"));
    formLayout->addRow(tr("Family"), m_familyEdit);

    m_variantEdit = new QLineEdit();
    m_variantEdit->setText(variant);
	connect(m_variantEdit, SIGNAL(editingFinished()), this, SLOT(variantEntry()));
	m_variantEdit->setObjectName("PartsEditorLineEdit");
    m_variantEdit->setStatusTip(tr("Set the part's variant--this makes it unique from all other parts in the same family"));
    formLayout->addRow(tr("Variant"), m_variantEdit);

    m_propertiesEdit = new HashPopulateWidget("", propertyHash, readOnlyKeys, false, this);
	m_propertiesEdit->setObjectName("PartsEditorPropertiesEdit");
    m_propertiesEdit->setStatusTip(tr("Set the part's properties"));
    connect(m_propertiesEdit, SIGNAL(changed()), this, SLOT(propertiesEntry()));
    formLayout->addRow(tr("Properties"), m_propertiesEdit);

    m_tagsEdit = new HashPopulateWidget("", tagHash, readOnlyKeys, true, this);
	m_tagsEdit->setObjectName("PartsEditorPropertiesEdit");
    m_tagsEdit->setStatusTip(tr("Set the part's tags"));
    connect(m_tagsEdit, SIGNAL(changed()), this, SLOT(tagsEntry()));
    formLayout->addRow(tr("Tags"), m_tagsEdit);

    formFrame->setLayout(formLayout);
    m_mainFrame->setLayout(mainLayout);

    this->setWidget(m_mainFrame);
}