void CardContainer::fillCards(const QList<int> &card_ids, const QList<int> &disabled_ids) { QList<CardItem *> card_items; if (card_ids.isEmpty() && items.isEmpty()) return; else if (card_ids.isEmpty() && !items.isEmpty()) { card_items = items; items.clear(); } else if (!items.isEmpty()) { retained_stack.push(retained()); items_stack.push(items); foreach (CardItem *item, items) item->hide(); items.clear(); } close_button->hide(); if (card_items.isEmpty()) card_items = _createCards(card_ids); int card_width = G_COMMON_LAYOUT.m_cardNormalWidth; QPointF pos1(30 + card_width / 2, 40 + G_COMMON_LAYOUT.m_cardNormalHeight / 2); QPointF pos2(30 + card_width / 2, 184 + G_COMMON_LAYOUT.m_cardNormalHeight / 2); int skip = 102; qreal whole_width = skip * 4; items.append(card_items); int n = items.length(); for (int i = 0; i < n; i++) { QPointF pos; if (n <= 10) { if (i < 5) { pos = pos1; pos.setX(pos.x() + i * skip); } else { pos = pos2; pos.setX(pos.x() + (i - 5) * skip); } } else { int half = (n + 1) / 2; qreal real_skip = whole_width / (half - 1); if (i < half) { pos = pos1; pos.setX(pos.x() + i * real_skip); } else { pos = pos2; pos.setX(pos.x() + (i - half) * real_skip); } } CardItem *item = items[i]; item->setPos(pos); item->setHomePos(pos); item->setOpacity(1.0); item->setHomeOpacity(1.0); item->setFlag(QGraphicsItem::ItemIsFocusable); if (disabled_ids.contains(item->getCard()->getEffectiveId())) item->setEnabled(false); item->show(); } }
void CardContainer::fillCards(const QList<int> &card_ids, const QList<int> &disabled_ids) { QList<CardItem *> card_items; if (card_ids.isEmpty() && items.isEmpty()) return; else if (card_ids.isEmpty() && !items.isEmpty()) { card_items = items; items.clear(); } else if (!items.isEmpty()) { retained_stack.push(retained()); items_stack.push(items); foreach (CardItem *item, items) item->hide(); items.clear(); } close_button->hide(); if (card_items.isEmpty()) card_items = _createCards(card_ids); items.append(card_items); _repaint(); int n = items.length(); const int blank = 3; int card_width = G_COMMON_LAYOUT.m_cardNormalWidth; int card_height = G_COMMON_LAYOUT.m_cardNormalHeight; bool one_row = true; int width = (card_width + blank) * items.length() - blank + 50; if (width * 1.5 > RoomSceneInstance->sceneRect().width()) { width = (card_width + blank) * ((items.length() + 1) / 2) - blank + 50; one_row = false; } int first_row = one_row ? items.length() : (items.length() + 1) / 2; for (int i = 0; i < n; i++) { QPointF pos; if (i < first_row) { pos.setX(25 + (card_width + blank) * i); pos.setY(45); } else { if (n % 2 == 1) pos.setX(25 + card_width / 2 + blank / 2 + (card_width + blank) * (i - first_row)); else pos.setX(25 + (card_width + blank) * (i - first_row)); pos.setY(45 + card_height + blank); } CardItem *item = items[i]; item->resetTransform(); item->setPos(pos); item->setHomePos(pos); item->setOpacity(1.0); item->setHomeOpacity(1.0); item->setFlag(QGraphicsItem::ItemIsFocusable); if (disabled_ids.contains(item->getCard()->getEffectiveId())) item->setEnabled(false); item->show(); } }
void CardContainer::fillCards(const QList<int> &card_ids){ if(card_ids.isEmpty()) return; else if(!items.isEmpty()){ items_stack.push(items); items.clear(); } QList<CardItem*> card_items = _createCards(card_ids); static const QPointF pos1(30, 40); static const QPointF pos2(30, 184); static const int card_width = 93; static const int skip = 102; static const qreal whole_width = skip * 4 + card_width; items.append(card_items); int n = items.length(); for (int i = 0; i < n; i++) { QPointF pos; if(n <= 10){ if(i < 5){ pos = pos1; pos.setX(pos.x() + i * skip); }else{ pos = pos2; pos.setX(pos.x() + (i - 5) * skip); } }else{ int half = n / 2 + 1; qreal real_skip = whole_width / half; if(i < half){ pos = pos1; pos.setX(pos.x() + i * real_skip); }else{ pos = pos2; pos.setX(pos.x() + (i-half) * real_skip); } } CardItem* item = items[i]; item->setPos(pos); item->setHomePos(pos); item->setOpacity(1.0); item->setHomeOpacity(1.0); item->setFlag(QGraphicsItem::ItemIsFocusable); } }
void CardContainer::fillCards(const QList<int> &card_ids, const QList<int> &disabled_ids) { if (card_ids == ids) return; QList<CardItem *> card_items; if (card_ids.isEmpty() && items.isEmpty()) return; else if (card_ids.isEmpty() && !items.isEmpty()) { card_items = items; items.clear(); } else if (!items.isEmpty()) { retained_stack.push(retained()); items_stack.push(items); foreach(CardItem *item, items) item->hide(); items.clear(); } scene_width = RoomSceneInstance->sceneRect().width(); confirm_button->hide(); if (card_items.isEmpty()) card_items = _createCards(card_ids); items.append(card_items); itemCount = items.length(); prepareGeometryChange(); int card_width = G_COMMON_LAYOUT.m_cardNormalWidth; int card_height = G_COMMON_LAYOUT.m_cardNormalHeight; bool one_row = true; int width = (card_width + cardInterval) * itemCount - cardInterval + 50; if (width * 1.5 > scene_width) { width = (card_width + cardInterval) * ((itemCount + 1) / 2) - cardInterval + 50; one_row = false; } int first_row = one_row ? itemCount : (itemCount + 1) / 2; for (int i = 0; i < itemCount; i++) { QPointF pos; if (i < first_row) { pos.setX(25 + (card_width + cardInterval) * i); pos.setY(45); } else { if (itemCount % 2 == 1) pos.setX(25 + card_width / 2 + cardInterval / 2 + (card_width + cardInterval) * (i - first_row)); else pos.setX(25 + (card_width + cardInterval) * (i - first_row)); pos.setY(45 + card_height + cardInterval); } CardItem *item = items[i]; item->resetTransform(); item->setPos(pos); item->setHomePos(pos); item->setOpacity(1.0); item->setHomeOpacity(1.0); item->setFlag(QGraphicsItem::ItemIsFocusable); if (disabled_ids.contains(item->getCard()->getEffectiveId())) item->setEnabled(false); item->setOuterGlowEffectEnabled(true); item->show(); ids << item->getId(); } confirm_button->setPos(boundingRect().center().x() - confirm_button->boundingRect().width() / 2, boundingRect().height() - 60); }