int MToolBarLayoutPolicy::takenSlots() const { if (textEditIndex != -1) return widgetCount()+1; //textedit counts for two slots else return widgetCount(); }
bool FormWindowCursor::movePosition(MoveOperation op, MoveMode mode) { if (widgetCount() == 0) return false; int iterator = position(); if (mode == MoveAnchor) m_formWindow->clearSelection(false); switch (op) { case Next: ++iterator; if (iterator >= widgetCount()) iterator = 0; m_formWindow->selectWidget(m_formWindow->widgetAt(iterator), true); return true; case Prev: --iterator; if (iterator < 0) iterator = widgetCount() - 1; if (iterator < 0) return false; m_formWindow->selectWidget(m_formWindow->widgetAt(iterator), true); return true; default: return false; } }
void MToolBarLayoutPolicy::removeWidgetAtPreservingSpacers(int widgetIndex) { if (widgetIndex < 0 || widgetIndex > widgetCount()) return; if (widgetIndex == textEditIndex) textEditIndex = -1; else if (textEditIndex != -1 && widgetIndex < textEditIndex) textEditIndex--; updateLayoutPositionDueToRemove(widgetIndex); int policyIndex = widgetIndexToPolicyIndex(widgetIndex); Q_ASSERT(MLinearLayoutPolicy::count() >= policyIndex); bool lastItem = (widgetIndex == widgetCount()-1); bool onlyItem = (widgetCount() == 1); MLinearLayoutPolicy::removeAt(policyIndex); if (!onlyItem) { //remove and delete spacer int spacerIndex = lastItem ? policyIndex-1 : policyIndex; QGraphicsLayoutItem *item = MLinearLayoutPolicy::itemAt(spacerIndex); MLinearLayoutPolicy::removeAt(spacerIndex); delete item; } }
void MToolBarLayoutPolicy::insertWidgetAndRemoveOverflow(int widgetIndex, QGraphicsLayoutItem *item) { widgetIndex = qMin((uint)widgetIndex, (uint)widgetCount()); Q_ASSERT(item); //A ugly hack to try to cope with QTBUG-11134 item->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); if (dynamic_cast<MTextEdit *>(item->graphicsItem())) { if (textEditIndex != -1) //Remove any previous text edit removeWidgetAtPreservingSpacers(textEditIndex); textEditIndex = widgetIndex; } else if (widgetIndex <= textEditIndex) textEditIndex++; int policyIndex = widgetIndexToPolicyIndex(widgetIndex); Q_ASSERT(MLinearLayoutPolicy::count() >= policyIndex); if (widgetCount() > 0) { bool lastItem = (widgetIndex == widgetCount()); if (lastItem) { MLinearLayoutPolicy::insertItem(policyIndex-1, item, Qt::AlignVCenter); insertSpacer(policyIndex-1); } else { MLinearLayoutPolicy::insertItem(policyIndex, item, Qt::AlignVCenter); insertSpacer(policyIndex+1); } } else MLinearLayoutPolicy::insertItem(policyIndex, item, Qt::AlignVCenter); updateLayoutPositionDueToInsert(widgetIndex); removeOverflownWidgets(); updateSpacers(); }
qreal MToolBarLayoutPolicy::effectiveCenterOffset() const { if (centerAllWidgets && centerOffsetEnabledForAll) return centerOffset; //center offset is active for all widgets else if (centerLabelOnlyButtons && centerOffsetEnabledForLabelOnly && widgetCount() > 0 && labelOnlyButtonCount() == widgetCount()) return centerOffset; //center offset is active for label only buttons and all buttons are such; else if (widgetCount() == 1 && labelOnlyButtonCount() == 1) return centerOffset; //single label only button -> possible center offset is used return 0.0f; }
void FormWindowCursor::setPosition(int pos, MoveMode mode) { if (!widgetCount()) return; if (mode == MoveAnchor) m_formWindow->clearSelection(false); if (pos >= widgetCount()) pos = 0; m_formWindow->selectWidget(m_formWindow->widgetAt(pos), true); }
void PHN_Widget::setColor(int colorId, color_t color) { colors.set(colorId, color); for (int i = 0; i < widgetCount(); i++) { widget(i)->setColor(colorId, color); } invalidate(); }
QGraphicsLayoutItem *MToolBarLayoutPolicy::widgetAt(int widgetIndex) const { if (widgetIndex < 0 || widgetIndex >= widgetCount()) return 0; return MLinearLayoutPolicy::itemAt(widgetIndexToPolicyIndex(widgetIndex)); }
void MToolBarLayoutPolicy::updateAllLayoutPositions() { if (!isActive()) return; if (widgetCount() == 1) { setLayoutPosition(0, M::DefaultPosition); } else if (widgetCount() > 1) { bool leftToRight = layout()->layoutDirection() == Qt::LeftToRight; setLayoutPosition(0, leftToRight ? M::HorizontalLeftPosition : M::HorizontalRightPosition); setLayoutPosition(widgetCount()-1, leftToRight ? M::HorizontalRightPosition : M::HorizontalLeftPosition); for (int i = 1; i < widgetCount()-1; ++i) { setLayoutPosition(i, M::HorizontalCenterPosition); } } }
int MToolBarLayoutPolicy::widgetIndexOf(const QGraphicsLayoutItem *item) const { int base = leftSpacer ? 1 : 0; for (int i = widgetCount()-1; i >= 0; i--) { if (MLinearLayoutPolicy::itemAt(base+i*2) == item) return i; } return -1; }
void MToolBarLayoutPolicy::updateLayoutPositionDueToInsert(int widgetIndex) { if (!isActive()) return; if (widgetCount() <= 3) updateAllLayoutPositions(); else { bool leftToRight = layout()->layoutDirection() == Qt::LeftToRight; if (widgetIndex == 0) { // Added to first position setLayoutPosition(0, leftToRight ? M::HorizontalLeftPosition : M::HorizontalRightPosition); setLayoutPosition(1, M::HorizontalCenterPosition); } else if (widgetIndex == widgetCount() - 1) { // Added to last position setLayoutPosition(widgetCount()-2, M::HorizontalCenterPosition); setLayoutPosition(widgetCount()-1, leftToRight ? M::HorizontalRightPosition : M::HorizontalLeftPosition); } else // Added to middle setLayoutPosition(widgetIndex, M::HorizontalCenterPosition); } }
MToolBarLayoutPolicy::~MToolBarLayoutPolicy() { for (int i = widgetCount()-1; i >= 0; i--) removeWidgetAtPreservingSpacers(i); while (MLinearLayoutPolicy::count()) { // Remove left and right spacers QGraphicsLayoutItem *item = MLinearLayoutPolicy::itemAt(count()-1); MLinearLayoutPolicy::removeAt(count()-1); delete item; } }
void MToolBarLayoutPolicy::updateSpacers() { updateContentsMargins(); if (centerAllWidgets || (centerLabelOnlyButtons && widgetCount() > 0 && labelOnlyButtonCount() == widgetCount()) || (widgetCount() == 1 && labelOnlyButtonCount() == 1)) { activateLeftSpacer(true); activateRightSpacer(true); activateMiddleSpacers(false); return; } // Activate side spacer if there is just single widget in justified alignment // or alignment is neither to that direction nor justified. bool singleWidgetInJustified = (widgetCount() == 1 && isJustifiedAlignment()); activateLeftSpacer(singleWidgetInJustified || !isAlignedLeftOrJustified()); activateRightSpacer(singleWidgetInJustified || !isAlignedRightOrJustified()); activateMiddleSpacers(spacesBetween); }
void MToolBarLayoutPolicy::updateLayoutPositionDueToRemove(int widgetIndex) { if (!isActive()) return; setLayoutPosition(widgetIndex, M::DefaultPosition); if (widgetCount()-1 > 0) { if (widgetCount()-1 == 1) { // Only one will be left setLayoutPosition((widgetIndex == 0) ? 1 : 0, M::DefaultPosition); } else { bool leftToRight = layout()->layoutDirection() == Qt::LeftToRight; if (widgetIndex == 0) // Second is the new number one setLayoutPosition(1, leftToRight ? M::HorizontalLeftPosition : M::HorizontalRightPosition); else if (widgetIndex == widgetCount()-1) // Second but last will be last setLayoutPosition(widgetCount()-2, leftToRight ? M::HorizontalRightPosition : M::HorizontalLeftPosition); } } }
int MToolBarLayoutPolicy::labelOnlyButtonCount() const { int cnt(0); for (int i = 0; i < widgetCount(); i++) { MButton *button = dynamic_cast<MButton *>(widgetAt(i)); if (button && !button->text().isEmpty() && button->iconID().isEmpty() && button->viewType() == MButton::defaultType) { cnt++; } } return cnt; }
bool MToolBarLayoutPolicy::roomForWidget(int widgetIndex, bool textEdit) const { widgetIndex = qMin((uint)widgetIndex, (uint)widgetCount()); if (textEdit) { if (textEditIndex != -1 && widgetIndex > textEditIndex) { //If we come first, we push the old textedit out of the way return false; //No room for us } else if (widgetIndex+1 >= effectiveMaxWidgetSlots()) return false; //No room to add } else if (widgetIndex >= effectiveMaxWidgetSlots()) return false; //No room to add else if (textEditIndex != -1 && widgetIndex >= effectiveMaxWidgetSlots() -1) return false; //No room to add because textedit takes up two spaces return true; }
void MToolBarLayoutPolicy::removeOverflownWidgets() { while (takenSlots() > effectiveMaxWidgetSlots()) removeWidgetAtPreservingSpacers(widgetCount()-1); }
void MToolBarLayoutPolicy::removeAllWidgets() { for (int i = widgetCount()-1; i >= 0; i--) { removeWidgetAtPreservingSpacers(i); } }