void MetronomeWindow::setAccents(int numAccents) { static int prevNum = 0; numAccents = this->accentsBox->value(); QHBoxLayout *cont = this->accentContainer; if( prevNum==0 ) { prevNum = numAccents; for( int i=0; i<prevNum; i++ ) { QCheckBox* box = new QCheckBox( QString::number(i+1), this ); cont->addWidget(box); this->accentChecks.append(box); } } else if( numAccents > prevNum ) { for( int i=prevNum; i<numAccents; i++ ) { QCheckBox* box = new QCheckBox( QString::number(i+1), this ); cont->addWidget(box); this->accentChecks.append(box); } prevNum = numAccents; } else if( numAccents < prevNum ) { for( int i=prevNum; i>numAccents; i-- ) { QCheckBox* box = this->accentChecks.at(i-1); this->accentChecks.removeAt(i-1); cont->removeWidget(box); delete box; } prevNum = numAccents; } }
void ezQtPropertyTypeWidget::SetSelection(const ezHybridArray<ezPropertySelection, 8>& items) { ezQtScopedUpdatesDisabled _(this); ezQtPropertyWidget::SetSelection(items); QHBoxLayout* pLayout = m_pGroup != nullptr ? m_pGroupLayout : m_pLayout; QWidget* pOwner = m_pGroup != nullptr ? m_pGroup->GetContent() : this; if (m_pTypeWidget) { pLayout->removeWidget(m_pTypeWidget); delete m_pTypeWidget; m_pTypeWidget = nullptr; } // Retrieve the objects the property points to. This could be an embedded class or // an element of an array, be it pointer or embedded class. ezHybridArray<ezPropertySelection, 8> ResolvedObjects; for (const auto& item : m_Items) { ezUuid ObjectGuid = m_pObjectAccessor->Get<ezUuid>(item.m_pObject, m_pProp, item.m_Index); ezPropertySelection sel; sel.m_pObject = m_pObjectAccessor->GetObject(ObjectGuid); // sel.m_Index; intentionally invalid as we just retrieved the value so it is a pointer to an object ResolvedObjects.PushBack(sel); } const ezRTTI* pCommonType = nullptr; if (m_pProp->GetFlags().IsSet(ezPropertyFlags::Pointer)) { pCommonType = ezQtPropertyWidget::GetCommonBaseType(ResolvedObjects); } else { // If we create a widget for a member class we already determined the common base type at the parent type widget. // As we are not dealing with a pointer in this case the type must match the property exactly. pCommonType = m_pProp->GetSpecificType(); } m_pTypeWidget = new ezQtTypeWidget(pOwner, m_pGrid, m_pObjectAccessor, pCommonType, nullptr, nullptr); m_pTypeWidget->SetSelection(ResolvedObjects); pLayout->addWidget(m_pTypeWidget); }
void ActionLineEdit::actionEvent ( QActionEvent * event ) { QHBoxLayout *lo = (QHBoxLayout *)layout(); QAction *act = event->action(); ActionLineEditButton *btn; if (event->type() == QEvent::ActionAdded) { btn = new ActionLineEditButton(this); QAction *before = event->before(); int beforeInd; if (before && (beforeInd = actions().indexOf(before)) >= 0) { //TODO test it lo->insertWidget(beforeInd + 1, btn); //1 - first item is spacer. skip it } else { lo->addWidget(btn); } btn->setDefaultAction(act); } else if (event->type() == QEvent::ActionRemoved) { for (int i=1, count=lo->count(); i<count; i++) { btn = (ActionLineEditButton *)lo->itemAt(i)->widget(); if (btn->defaultAction() == act) { lo->removeWidget(btn); delete btn; break; } } } int sumWidth = 0; for (int i=1, count=lo->count(); i<count; i++) { btn = (ActionLineEditButton *)lo->itemAt(i)->widget(); if (btn->defaultAction()->isVisible()) { sumWidth += btn->width(); } } sumWidth += 4; //+4px padding between text and buttons. should looks better (magic number) int mLeft, mTop, mRight, mBottom; getTextMargins(&mLeft, &mTop, &mRight, &mBottom); setTextMargins(mLeft, mTop, sumWidth, mBottom); }
void GameWidgetScrollArea::resizeEvent(QResizeEvent * event) { int widgetWidth = GameChoiceWidget::getWidgetWidth(); int widgetsPerRowNew = event->size().width() / widgetWidth; if (widgetsPerRowNew <= 0) { fprintf(stderr, "Error: window too small. Exiting.\n"); static GameController* instance = GameController::acquire(); instance->terminateApplication(); } if (widgetsPerRowNew < m_widgetsPerRow) { // too many widgets per row, must make rows shorter QVBoxLayout* overallLayout = (QVBoxLayout*) this->widget()->layout(); int numToMove = m_widgetsPerRow - widgetsPerRowNew; for (int i = 0; i < overallLayout->count() - 1 && numToMove > 0; ++i) { QHBoxLayout* horizontalRow = (QHBoxLayout*) overallLayout->itemAt(i)->layout(); QHBoxLayout* nextHorizontalRow; for (int j = 0; j < numToMove; ++j) { QWidget* lastWidget = horizontalRow->itemAt( horizontalRow->count() - 2)->widget(); horizontalRow->removeWidget(lastWidget); if (i == overallLayout->count() - 2) { QHBoxLayout* newRow = new QHBoxLayout(); newRow->addStretch(ms_stretchFactor); overallLayout->insertLayout(overallLayout->count() - 1, newRow); } nextHorizontalRow = (QHBoxLayout*) overallLayout->itemAt(i + 1)->layout(); nextHorizontalRow->insertWidget(0, lastWidget, 0, Qt::AlignLeading); } numToMove = nextHorizontalRow->count() - widgetsPerRowNew - 1; } m_widgetsPerRow = std::min(widgetsPerRowNew, m_totalNumberGameWidgets); } else if (m_widgetsPerRow < m_totalNumberGameWidgets && widgetsPerRowNew > m_widgetsPerRow) { // add widgets to each row to make each longer and have less rows QVBoxLayout* overallLayout = (QVBoxLayout*) this->widget()->layout(); int numToMove = widgetsPerRowNew - m_widgetsPerRow; QHBoxLayout* currentHorizontalRow = (QHBoxLayout*) overallLayout->itemAt(0)->layout(); for (int i = 1; i < overallLayout->count() - 1; ++i) { QHBoxLayout* nextHorizontalRow = (QHBoxLayout*) overallLayout->itemAt(i)->layout(); for (int j = 0; j < numToMove; ++j) { if (nextHorizontalRow->count() <= 1) { if (i == overallLayout->count() - 2) { overallLayout->removeItem(overallLayout->itemAt(i)); break; } overallLayout->removeItem(overallLayout->itemAt(i)); nextHorizontalRow = (QHBoxLayout*) overallLayout->itemAt(i)->layout(); } QWidget* firstWidget = nextHorizontalRow->itemAt(0)->widget(); nextHorizontalRow->removeWidget(firstWidget); currentHorizontalRow->insertWidget( currentHorizontalRow->count() - 1, firstWidget); } currentHorizontalRow = nextHorizontalRow; numToMove = widgetsPerRowNew - (nextHorizontalRow->count() - 1); } m_widgetsPerRow = std::min(widgetsPerRowNew, m_totalNumberGameWidgets); } QWidget* content = this->widget(); content->resize(this->width(), content->sizeHint().height()); }