Beispiel #1
0
void MiniProgrammerUI::setVertical(bool vertical)
{
    if(m_isVertical == vertical)
        return;

    m_isVertical = vertical;

    QBoxLayout *from = ui->horLayout;
    QBoxLayout *to = ui->vertLayout;

    if(!vertical)
        std::swap(from, to);

    while(from->count() != 0)
    {
        QLayoutItem *i = from->takeAt(0);
        if(i->layout())
        {
            i->layout()->setParent(0);
            to->addLayout(i->layout());
        }
        else
            to->addItem(i);
    }

    delete to->takeAt(to->count()-1);
    to->addStretch(1);
}
void PropertyToolBox::addPage( QWidget* page )
{
    QBoxLayout* pageLayout = qobject_cast<QBoxLayout*>( page->layout() );
    if ( pageLayout && pageLayout->direction() == QBoxLayout::TopToBottom ) {
        pageLayout->setContentsMargins( 5, 5, 5, 5 );
        pageLayout->setSpacing( 3 );
        for ( int i = 0; i < pageLayout->count(); i++ ) {
            QLayoutItem* item = pageLayout->itemAt( i );
            if ( item->spacerItem() )
                continue;
            QLabel* label = qobject_cast<QLabel*>( item->widget() );
            if ( label ) {
                QString style = "border: none; border-bottom: 1px solid palette(dark);";
                if ( i > 0 )
                    style += "margin-top: 2px;";
                label->setStyleSheet( style );
                continue;
            }
            QBoxLayout* itemLayout = qobject_cast<QBoxLayout*>( item->layout() );
            if ( itemLayout && itemLayout->direction() == QBoxLayout::LeftToRight ) {
                itemLayout->insertSpacing( 0, 10 );
            } else {
                pageLayout->removeItem( item );
                QHBoxLayout* wrapperLayout = new QHBoxLayout();
                wrapperLayout->addSpacing( 10 );
                wrapperLayout->addItem( item );
                pageLayout->insertLayout( i, wrapperLayout );
            }
        }
    }

    page->setBackgroundRole( QPalette::Base );

    addItem( page, page->windowTitle() );
}
Beispiel #3
0
int QBoxLayoutProto::count() const
{
  QBoxLayout *item = qscriptvalue_cast<QBoxLayout*>(thisObject());
  if (item)
    return item->count();
  return 0;
}
Beispiel #4
0
void
TokenDropTarget::drop( Token *token, const QPoint &pos )
{
    if ( !token )
        return;

    // unlayout in case of move
    if ( QBoxLayout *box = rowBox( token ) )
        box->removeWidget( token );
    token->setParent( parentWidget() );

    QBoxLayout *box = 0;
    if ( Token *brother = qobject_cast<Token*>( childAt( pos ) ) )
    {   // we hit a sibling, -> prepend
        QPoint idx;
        box = rowBox( brother, &idx );
        if ( pos.x() > brother->geometry().x() + 2*brother->width()/3 )
            box->insertWidget( idx.x() + 1, token );
        else
            box->insertWidget( idx.x(), token );
    }
    else
    {
        if ( rowLimit() && rows() >= (int)rowLimit() ) // we usually don't want more rows
            box = qobject_cast<QBoxLayout*>( layout()->itemAt( rows() - 1 )->layout() );

        if ( !box )
        {
            box = rowBox( pos ); // maybe this is on an existing row
            if ( !box )
                box = appendRow();
        }
        int idx = ( box->count() > trailingStretch && box->itemAt(0)->widget() &&
                    pos.x() < box->itemAt(0)->widget()->geometry().x() ) ? 0 : box->count() - trailingStretch;
        box->insertWidget( idx, token ); // append to existing row
    }
    token->show();
    update(); // count changed
    emit changed();

    token->setFocus( Qt::OtherFocusReason ); // select the new token right away
}
Beispiel #5
0
void ProgressFrame::addToButtonBox(QDialogButtonBox *button_box, QObject *main_window)
{
    // We have a ProgressFrame in the main status bar which is controlled
    // from the capture file and other parts of the application via
    // create_progress_dlg and delayed_create_progress_dlg.
    // Create a new ProgressFrame and pair it with the main instance.
    ProgressFrame *main_progress_frame = main_window->findChild<ProgressFrame *>();
    if (!button_box || !main_progress_frame) return;

    QBoxLayout *layout = qobject_cast<QBoxLayout *>(button_box->layout());
    if (!layout) return;

    ProgressFrame *progress_frame = new ProgressFrame(button_box);

    // Insert ourselves after the first spacer we find, otherwise the
    // far right of the button box.
    int idx = layout->count();
    for (int i = 0; i < layout->count(); i++) {
        if (layout->itemAt(i)->spacerItem()) {
            idx = i + 1;
            break;
        }
    }
    layout->insertWidget(idx, progress_frame);

    int one_em = progress_frame->fontMetrics().height();
    progress_frame->setMaximumWidth(one_em * 8);
    connect(main_progress_frame, SIGNAL(showRequested(bool,bool,gboolean*)),
            progress_frame, SLOT(show(bool,bool,gboolean*)));
    connect(main_progress_frame, SIGNAL(maximumValueChanged(int)),
            progress_frame, SLOT(setMaximumValue(int)));
    connect(main_progress_frame, SIGNAL(valueChanged(int)),
            progress_frame, SLOT(setValue(int)));
    connect(main_progress_frame, SIGNAL(setHidden()),
            progress_frame, SLOT(hide()));

    connect(progress_frame, SIGNAL(stopLoading()),
            main_progress_frame, SIGNAL(stopLoading()));
}
/** Add a radio button to the plot options
 *
 * @param text :: text on the radio button
 * @param tooltip :: tooltip
 * @param bIntegrated :: flag to indicate that the dimension is integrated.
 */
void LinePlotOptions::addPlotRadioButton(const std::string &text,
                                         const std::string &tooltip,
                                         const bool bIntegrated) {
  QRadioButton *rad;
  rad = new QRadioButton(ui.widgetPlotAxis);
  rad->setText(QString::fromStdString(text));
  rad->setToolTip(QString::fromStdString(tooltip));
  rad->setEnabled(!bIntegrated);
  // Insert it one before the horizontal spacer.
  QBoxLayout *layout = qobject_cast<QBoxLayout *>(ui.widgetPlotAxis->layout());
  layout->insertWidget(layout->count() - 1, rad);
  m_radPlots.push_back(rad);
  QObject::connect(rad, SIGNAL(toggled(bool)), this, SLOT(radPlot_changed()));
}
Beispiel #7
0
void
TokenDropTarget::deleteEmptyRows()
{
    QBoxLayout *box = 0;
    for ( int row = 0; row <= rows(); )
    {
        box = qobject_cast<QBoxLayout*>( layout()->itemAt( row )->layout() );
        if ( box && box->count() < ( 1 + trailingStretch ) ) // sic! last is spacer
        {
            layout()->removeItem( box );
            delete box;
        }
        else
            ++row;
    }
    update(); // in case we're empty now
    emit changed();
}
Beispiel #8
0
void SliderDialog::addSlider(CSlider* pSlider)
{
  if (mpParentWindow == NULL)
    return;

  // check if there already is a slider for this  object
  CCopasiDataModel * pDataModel = pSlider->getObjectDataModel();
  assert(pDataModel != NULL);
  SCopasiXMLGUI* pGUI = pDataModel->getGUI();
  assert(pGUI);

  if (!equivalentSliderExists(pSlider))
    {
      CObjectInterface::ContainerList listOfContainers;
      assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
      listOfContainers.push_back(pDataModel->getModel());
      pSlider->compile(listOfContainers);
      pGUI->getSliderList()->add(pSlider, true);
    }

  CopasiSlider* tmp = findCopasiSliderForCSlider(pSlider);

  if (!tmp)
    {
      setCurrentSlider(new CopasiSlider(pSlider, mpParentWindow->getDataModel(), mpSliderBox));
      mpCurrSlider->installEventFilter(this);
      mpCurrSlider->setHidden(true);
      mpCurrSlider->updateSliderData();
      // make sure the slider points to the correct object
      // for the currently set framework
      this->setCorrectSliderObject(this->mpCurrSlider);
      mSliderMap[mCurrentFolderId].push_back(mpCurrSlider);
      QBoxLayout* layout = static_cast<QBoxLayout*>(mpSliderBox->layout());
      int childCount = layout->count() - 1;
      layout->insertWidget(childCount, mpCurrSlider);
      connect(mpCurrSlider, SIGNAL(valueChanged(double)), this , SLOT(sliderValueChanged()));
      connect(mpCurrSlider, SIGNAL(sliderReleased()), this, SLOT(sliderReleased()));
      connect(mpCurrSlider, SIGNAL(sliderPressed()), this, SLOT(sliderPressed()));
      connect(mpCurrSlider, SIGNAL(closeClicked(CopasiSlider*)), this, SLOT(removeSlider(CopasiSlider*)));
      connect(mpCurrSlider, SIGNAL(editClicked(CopasiSlider*)), this, SLOT(editSlider(CopasiSlider*)));
      mpCurrSlider->setHidden(false);
      mChanged = true;
    }
Beispiel #9
0
void ContentsDialog::setCheckBox(const QString &text, bool state)
{
	if (!m_checkBox)
	{
		QBoxLayout *mainLayout = static_cast<QBoxLayout*>(layout());

		if (!mainLayout)
		{
			return;
		}

		m_checkBox = new QCheckBox(this);

		mainLayout->insertWidget((mainLayout->count() - 1), m_checkBox);
	}

	m_checkBox->setText(text);
	m_checkBox->setChecked(state);

	adjustSize();
}
Beispiel #10
0
 void ui_layout::set_stretch_for_last_item(unsigned s)
 {
   QBoxLayout* l = stack_.top();
   l->setStretch(l->count() - 1, s);
 }
Beispiel #11
0
//-----------------------------------------------------------------------------
//!
//-----------------------------------------------------------------------------
void tMediaButtonBox::paintEvent( QPaintEvent* /*pEvent*/ )
{
    QPainter painter( this );
    const QRect rect = contentsRect();

    // background
    painter.fillRect( rect, palette().window() );

    // separator drawing is supported only for QBoxLayout
    QBoxLayout* pLayout = qobject_cast< QBoxLayout* >( layout() );
    if( !pLayout )
        return;

    // if there is no space between the items, we don't draw any separator
    int halfSpacing = qRound( pLayout->spacing() * 0.5 );
    if( halfSpacing == 0 )
        return;

    // setup the pen to draw separators
    tNOSStyle* pNosStyle = qobject_cast< tNOSStyle* >( style() );
    if( pNosStyle )
    {
        QColor c = pNosStyle->GetColor( tNOSStyle::eNCR_Alternative1 );
        c.setAlpha( 127 );
        QPen pen( c );
        pen.setCosmetic( true );
        painter.setPen( pen );
    }

    // separator bounds (X for horizontal sep, Y for vertical sep)
    int separatorOffset;
    if( pLayout->direction() == QBoxLayout::LeftToRight || pLayout->direction() == QBoxLayout::RightToLeft )
    {
        separatorOffset = rect.height() / 7;
    }
    else
    {
        separatorOffset = rect.width() / 8;
    }
    int separatorX1 = rect.left() + separatorOffset;
    int separatorX2 = rect.right() - separatorOffset;
    int separatorY1 = rect.top() + separatorOffset;
    int separatorY2 = rect.bottom() - separatorOffset;

    // find the first visible widget or spacer (layouts are not handled yet, see below)
    int from = 0;
    QLayoutItem* fromItem = 0;
    for( from = 0; from < pLayout->count(); ++from )
    {
        fromItem = pLayout->itemAt( from );
        if( ( fromItem->widget() && fromItem->widget()->isVisible() ) || fromItem->spacerItem() )
            break;
    }

    // iterate over each item and draw a separator between:
    // - two visible widgets
    // - a spacer and a visible widget
    // - a visible widget and a spacer
    // to be noted that embedded layouts are not handled yet (must be wrapped in a widget)
    for( int to = from + 1; to < pLayout->count(); ++to )
    {
        QLayoutItem* toItem = pLayout->itemAt( to );

        if( toItem->widget() )
        {
            // if toItem is a visible widget, process it; if it is hidden, skip it
            if( toItem->widget()->isHidden() )
                continue;
        }
        else if( toItem->spacerItem() )
        {
            // skip empty spacer
            if( toItem->geometry().isEmpty() )
                continue;

            if( fromItem->spacerItem() )
            {
                // if fromItem and toItem are spacers, just take toItem as
                // the new reference but don't draw any separator
                from = to;
                fromItem = toItem;
                continue;
            }
        }

        // because a spacer item "eat" the spacing (i.e. there is no spacing added after a spacer)
        // we need to adjust the separator offset
        int tunedHalfSpacing = halfSpacing;
        if( fromItem->spacerItem() )
            tunedHalfSpacing -= pLayout->spacing();

        switch( pLayout->direction() )
        {
        case QBoxLayout::LeftToRight:
            {
                int x = fromItem->geometry().right() + tunedHalfSpacing;
                painter.drawLine( x, separatorY1, x, separatorY2 );
            }
            break;

        case QBoxLayout::RightToLeft:
            {
                int x = fromItem->geometry().left() - tunedHalfSpacing;
                painter.drawLine( x, separatorY1, x, separatorY2 );
            }
            break;

        case QBoxLayout::TopToBottom:
            {
                int y = fromItem->geometry().bottom() + tunedHalfSpacing;
                painter.drawLine( separatorX1, y, separatorX2, y );
            }
            break;

        case QBoxLayout::BottomToTop:
            {
                int y = fromItem->geometry().top() - tunedHalfSpacing;
                painter.drawLine( separatorX1, y, separatorX2, y );
            }
            break;
        }

        from = to;
        fromItem = toItem;
    }
}