void NowPlaying::constraintsEvent(Plasma::Constraints constraints) { if (constraints & Plasma::FormFactorConstraint) { switch (formFactor()) { case Plasma::Horizontal: layoutHorizontal(); break; case Plasma::Vertical: layoutHorizontal(); // FIXME break; default: layoutPlanar(); break; } } if (constraints & Plasma::SizeConstraint) { switch (formFactor()) { case Plasma::Horizontal: setPreferredSize(contentsRect().height() * 2, contentsRect().height()); break; case Plasma::Vertical: setPreferredSize(contentsRect().width(), contentsRect().width() / 2); break; default: break; } } }
void InternalWindow::borderDragMouseDragged(MouseEventDetails* const e) { Vec2f Size; bool PositionChange; Pnt2f Position; Pnt2f BottomRight(getPosition() + getSize()); switch(_BorderDragged) { case WINDOW_LEFT_BORDER: Size.setValues(BottomRight.x() - e->getLocation().x(), getPreferredSize().y()); PositionChange = true; Position = BottomRight - Size; break; case WINDOW_RIGHT_BORDER: PositionChange = false; Size.setValues(e->getLocation().x() - getPosition().x(), getPreferredSize().y()); break; case WINDOW_TOP_BORDER: Size.setValues(getPreferredSize().x(), BottomRight.y() - e->getLocation().y()); PositionChange = true; Position = BottomRight - Size; break; case WINDOW_BOTTOM_BORDER: PositionChange = false; Size.setValues(getPreferredSize().x(), e->getLocation().y() - getPosition().y()); break; case WINDOW_TOP_LEFT_BORDER: Size.setValues(BottomRight.x() - e->getLocation().x(), BottomRight.y() - e->getLocation().y()); PositionChange = true; Position = BottomRight - Size; break; case WINDOW_BOTTOM_RIGHT_BORDER: PositionChange = false; Size.setValues(e->getLocation().x() - getPosition().x(), e->getLocation().y() - getPosition().y()); break; case WINDOW_TOP_RIGHT_BORDER: Size.setValues(e->getLocation().x() - getPosition().x(), BottomRight.y() - e->getLocation().y()); PositionChange = true; Position.setValues(getPosition().x(), BottomRight.y() - Size.y()); break; case WINDOW_BOTTOM_LEFT_BORDER: Size.setValues(BottomRight.x() - e->getLocation().x(), e->getLocation().y() - getPosition().y()); PositionChange = true; Position.setValues( BottomRight.x() - Size.x(), getPosition().y()); break; } if(PositionChange) { setPreferredSize(Size); setPosition(Position); } else { setPreferredSize(Size); } }
ControlButton* ButtonUtils::createButton(const std::string& normalFrame, const std::string& highLightFrame, const std::string& disableFrame, Size size, const std::string& label, float labelSize , Color3B labelColor) { auto normal = Scale9Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(normalFrame)); auto highLight = Scale9Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(highLightFrame)); auto disable = Scale9Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(disableFrame)); auto btn = ControlButton::create(label,"Arial",labelSize); //ÉèÖÃÏÔʾ³ß´ç btn->setPreferredSize(size); //¸ù¾Ý״̬ÉèÖñ³¾° btn->setBackgroundSpriteForState(normal,Control::State::NORMAL); btn->setBackgroundSpriteForState(highLight,Control::State::HIGH_LIGHTED); btn->setBackgroundSpriteForState(disable,Control::State::DISABLED); //¸ù¾Ý״̬ÉèÖð´Å¥ÎÄ×ÖÑÕÉ« btn->setTitleColorForState(labelColor,Control::State::NORMAL); btn->setTitleColorForState(labelColor,Control::State::HIGH_LIGHTED); btn->setTitleColorForState(labelColor,Control::State::DISABLED); //--TODOÉèÖô¥Ãþ¼¶±ð return btn; }
void Separator::setSize(qreal size) { m_size = size; if (m_isVisible) { if (m_applet->location() == Plasma::LeftEdge || m_applet->location() == Plasma::RightEdge) { setPreferredSize(m_size, (m_size / 4)); } else { setPreferredSize((m_size / 4), m_size); } } }
void button_t::layout() { g_dimension labelPreferred = label.getPreferredSize(); labelPreferred.width += insets.left + insets.right; labelPreferred.height += insets.top + insets.bottom; setPreferredSize(labelPreferred); }
int QGraphicsLayoutItem_setPreferredSize(lua_State* const state) { auto self = lua::get<QGraphicsLayoutItem*>(state, 1); if (lua_gettop(state) == 2) { // void setPreferredSize(const QSizeF & size) self->setPreferredSize(lua::get<const QSizeF&>(state, 2)); } else { // void setPreferredSize(qreal w, qreal h) self->setPreferredSize( lua::get<qreal>(state, 2), lua::get<qreal>(state, 3) ); } return 0; }
void HelloWorld::testControlBtn() { //创建正常状态下九宫格精灵 auto btnNormal = Scale9Sprite::create("switch-on.png"); //创建点击状态下九宫格精灵 auto btnSelected = Scale9Sprite::create("switch-off.png"); /*创建标题*/ auto title = LabelTTF::create("", "Marker Felt", 30); /* 根据标题和九宫格图片创建按钮 */ auto controlBtn = ControlButton::create(title, btnNormal); //setPreferredSize 设置大小*/ controlBtn->setPreferredSize(Size(128, 128)); /* 设置点击时候显示的图片 */ controlBtn->setBackgroundSpriteForState(btnSelected, Control::State::HIGH_LIGHTED); controlBtn->setPosition(Point(200, 200)); //注册事件 controlBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::btnClicked), Control::EventType::TOUCH_UP_INSIDE); controlBtn->setTag(10); this->addChild(controlBtn); }
void DateTimeGroup::updateSize() { Plasma::FormFactor f = formFactor(); if (f != Plasma::Vertical && f != Plasma::Horizontal) { const QFontMetricsF metrics(KGlobalSettings::smallestReadableFont()); setMinimumSize(metrics.size(Qt::TextSingleLine, dtg)); } int aspect = 12; int w, h; w = (int)(contentsRect().height() * aspect); h = (int)(contentsRect().width() / aspect); if (f == Plasma::Horizontal) { setMinimumSize(QSize(w, 0)); } else { setMinimumSize(QSize(0, h)); } setPreferredSize(QSize(w, h)); emit sizeHintChanged(Qt::PreferredSize); if (m_isDefaultFont) { expandFontToMax(m_plainDateTimeGroupFont, dtg); } generatePixmap(); }
//获取一个排名项 MTTMatchState::PaiMingItem* MTTMatchState::GetPaiMingItem() { PaiMingItem *paimingItem = nullptr; if (m_vecPaiMingOld.empty()) { auto spriteBg = ui::Scale9Sprite::create("gamefriendlist/bgitem.png", Rect(0,0,662,90), Rect(150,20,362,50)); spriteBg->setPreferredSize(Size(686, 100)); m_pScrollViewType[1]->addChild(spriteBg); auto httpSprite = CreateUserHeadSprite("defaulticon.png", "gamefriendlist/iconclipmask.png", spriteBg, Vec2(10, 4), "gamefriendlist/iconround.png"); auto rankFlag = CreateNode3AndPosAddTo<FrameSprite>("ranklist/ranklistreword.png", 1, 4, 20, 96, spriteBg, 0); auto spriteCoin = CreateNode1AndPosAddTo<Sprite>("gamemtt/mttcoin.png", 450, 50, spriteBg, 0); auto labelRankId = CreateLabelMSYHAndAnchorPosClrAddTo(18, "", Vec2(0.5,0.5), 31, 21, Color4B(0xff,0xd2,0x00,0xff), rankFlag, 0); auto labelPlayerName = CreateLabelMSYHAndAnchorPosClrAddTo(26, "", Vec2(0,0.5), 120, 50, Color4B::WHITE, spriteBg, 0); auto labelCash = CreateLabelMSYHAndAnchorPosClrAddTo(26, "", Vec2(0,0.5), 475, 50, Color4B(0xff,0xd2,0x00,0xff), spriteBg, 0); PaiMingItem *item= new PaiMingItem; item->m_spriteItemBg = spriteBg; item->m_httpSpriteIcon = httpSprite; item->m_spriteRankFlag = rankFlag; item->m_spriteCoin = spriteCoin; item->m_labelRankId = labelRankId; item->m_labelPlayerName = labelPlayerName; item->m_labelCash = labelCash; paimingItem = item; } else { paimingItem = m_vecPaiMingOld.back(); m_vecPaiMingOld.pop_back(); } return paimingItem; }
GLabelItem::GLabelItem( qreal w, qreal h, const PHIAItem *it, QGraphicsItem *parent ) : GWidgetItem( w, h, it, parent ) { qDebug( "GLabelItem::GLabelItem()" ); _l=new QLabel(); _l->setTextInteractionFlags( Qt::TextSelectableByMouse ); _l->setWordWrap( false ); _l->setAutoFillBackground( false ); setWidget( _l ); setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::Label ); setPreferredSize( w, h ); setMinimumSize( 0, 0 ); //setMinimumSize( PHI::minimumSizeForPix() ); //setPreferredHeight( PHI::defaultHeight() ); //setMinimumHeight( PHI::minimumHeight() ); //setMinimumWidth( PHI::minimumWidth() ); resize( w, h ); /* connect( _l, SIGNAL( linkActivated( const QString& ) ), it, SLOT( slotLinkActivated( const QString ) ) ); connect( _l, SIGNAL( linkHovered( const QString& ) ), it, SLOT( slotLinkHovered( const QString& ) ) ); */ _alignment=0; }
MonitorIcon::MonitorIcon(QGraphicsItem *parent) : QGraphicsWidget(parent), d(new Private) { setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); setPreferredSize(d->imageSize.width() + 2 * MARGIN, d->imageSize.height() + 2 * MARGIN); }
bool Score::init() { if (!Node::init()) { return false; } auto csize = Size(280, 54); this->setContentSize(csize); auto bg = Scale9Sprite::createWithSpriteFrameName("num_bg.png"); bg->setPreferredSize(csize); bg->setAnchorPoint(Vec2::ZERO); this->addChild(bg); auto scoreTxt = Label::createWithBMFont(ResourceManager::getInstance()->getFntRes( MYMultiLanguageManager::getInstance()->getText("Score_fnt") ), MYMultiLanguageManager::getInstance()->getText("Score:")); scoreTxt->setAnchorPoint(Vec2(0, 0)); scoreTxt->setAlignment(TextHAlignment::LEFT, TextVAlignment::CENTER); scoreTxt->setPosition(Vec2(12, 2)); this->addChild(scoreTxt); m_numLab = Label::createWithBMFont(ResourceManager::getInstance()->getFntRes("Score"), "0"); m_numLab->setAnchorPoint(Vec2(0, 0.5)); m_numLab->setPosition(Vec2(120, 20)); m_numLab->setAlignment(TextHAlignment::LEFT, TextVAlignment::CENTER); this->addChild(m_numLab); return true; }
void Clock::constraintsEvent(Plasma::Constraints constraints) { ClockApplet::constraintsEvent(constraints); if (constraints & Plasma::SizeConstraint) { invalidateCache(); } if (constraints & Plasma::FormFactorConstraint) { if (formFactor() == Plasma::Planar || formFactor() == Plasma::MediaCenter) { setPreferredSize(256, 256); } else { setPreferredSize(-1, -1); } } }
void Clef::setClef(int clef) { if(m_clef != clef){ m_clef = clef; m_svgRenderer->load(m_clefs->value(clef)); } setPreferredSize(getRectForClef().size()); }
void Button_t::layout() { Dimension labelPreferred = label.getPreferredSize(); labelPreferred.width = labelPreferred.width + insets.left + insets.right; labelPreferred.height = labelPreferred.height + insets.bottom; setPreferredSize(labelPreferred); }
void HudLabel::setText(const QString& text) { d->mText = text; QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont); QFontMetrics fm(font); QSize minSize = fm.size(0, d->mText); setMinimumSize(minSize); setPreferredSize(minSize); }
GraphicsIcon::GraphicsIcon(const QPixmap& pixmap, QGraphicsItem* parent) : QGraphicsWidget(parent), d(new Private) { d->pixmap = pixmap; resize(pixmap.size()); setAcceptHoverEvents(true); setAcceptedMouseButtons(Qt::LeftButton); setPreferredSize(pixmap.size()); }
ControlButton *ControlButtonTest_Styling::standardButtonWithTitle(const char *title) { /** Creates and return a button with a default background and title color. */ auto backgroundButton = ui::Scale9Sprite::create("extensions/button.png"); backgroundButton->setPreferredSize(Size(45, 45)); // Set the prefered size auto backgroundHighlightedButton = ui::Scale9Sprite::create("extensions/buttonHighlighted.png"); backgroundHighlightedButton->setPreferredSize(Size(45, 45)); // Set the prefered size auto titleButton = Label::createWithTTF(title, "fonts/Marker Felt.ttf", 30); titleButton->setColor(Color3B(159, 168, 176)); ControlButton *button = ControlButton::create(titleButton, backgroundButton); button->setBackgroundSpriteForState(backgroundHighlightedButton, Control::State::HIGH_LIGHTED); button->setTitleColorForState(Color3B::WHITE, Control::State::HIGH_LIGHTED); return button; }
void Bubble::constraintsEvent(Plasma::Constraints constraints) { Plasma::Applet::constraintsEvent(constraints); if (constraints & Plasma::FormFactorConstraint) { if (formFactor() == Plasma::Horizontal || formFactor() == Plasma::Vertical) { setPreferredSize(-1,-1); } else { setPreferredSize(150, 150); } } if (formFactor() == Plasma::Planar || formFactor() == Plasma::MediaCenter) { setMinimumSize(30,30); } else { setMinimumSize(0,0); } }
IconItem::IconItem(const QString &filename, QGraphicsItem *parent) : GvbWidget(parent) , m_filename(filename) , m_rotation(0.0) , m_opacityEffect(0) , m_smoothTransformation(false) { setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); setContentsMargins(0,0,0,0); setPreferredSize(58,58); }
void UIDrawObjectCanvas::changed(ConstFieldMaskArg whichField, UInt32 origin, BitVector details) { Inherited::changed(whichField, origin, details); if( (whichField & DrawObjectsFieldMask) ) { setPreferredSize(getRequestedSize()); } }
void CCControlBase::layoutChildren(ELayoutMode layoutMode, bool resize) { // now check for all sub layers and call needsLayout to CCArray* children(getChildren()); CCObject* child; const float verticalOffset(static_cast<float>(m_marginV)); if(resize == true) { const CCSize& currentContentSize(getContentSize()); float contentHeight(verticalOffset); // determine the new content height CCARRAY_FOREACH(children, child) { CCControlBase* ctrlBase(dynamic_cast<CCControlBase*>(child)); if(ctrlBase != nullptr) { CCSize preferredSize(CCSizeMake(currentContentSize.width - (m_marginH * 2),0)); CCSize ctrlPreferredSize(ctrlBase->getPreferredSize()); ctrlPreferredSize.width = preferredSize.width; ctrlBase->setPreferredSize(ctrlPreferredSize); ctrlBase->needsLayout(); contentHeight += ctrlBase->getContentSize().height; contentHeight += verticalOffset; } else { CCScale9Sprite* sprite(dynamic_cast<CCScale9Sprite*>(child)); if(sprite == _backGroundSprite) { } else { CCControlButton* btn(dynamic_cast<CCControlButton*>(child)); if(btn != nullptr) { contentHeight += (btn->getContentSize().height + verticalOffset * 2); contentHeight += verticalOffset * 2; } else { CCNode* node(dynamic_cast<CCNode*>(child)); if(node != nullptr) { contentHeight += node->getContentSize().height; contentHeight += verticalOffset; } } } } } CCSize newContentSize(getContentSize()); newContentSize.height = contentHeight; setPreferredSize(newContentSize); needsLayout(); layoutChildren(ELayoutMode_topLeftDown); }
TextField::TextField(std::string initialText, const mw::Font& font) : font_(font), editable_(true), textColor_(0, 0, 0), alignment_(LEFT), markerDeltaTime_(0), markerChanged_(false) { setPreferredSize(150, 20); setBackgroundColor(0.8f, 0.8f, 0.8f); inputFormatter_.update(initialText.c_str()); text_ = mw::Text(inputFormatter_.getText(), font); // One pixel to the right of the last character. markerWidth_ = text_.getWidth() + 1; }
bool MyControlButton::initWithLabelAndBackgroundSprite(Node* node, ui::Scale9Sprite* backgroundSprite,bool isSallowTouch) { if (init(isSallowTouch)) { CCASSERT(node != nullptr, "node must not be nil."); LabelProtocol* label = dynamic_cast<LabelProtocol*>(node); CCASSERT(backgroundSprite != nullptr, "Background sprite must not be nil."); CCASSERT(label != nullptr, "label must not be nil."); _parentInited = true; _isPushed = false; // Adjust the background image by default setAdjustBackgroundImage(true); setPreferredSize(Size::ZERO); // Zooming button by default _zoomOnTouchDown = true; _scaleRatio = 1.1f; // Set the default anchor point ignoreAnchorPointForPosition(false); setAnchorPoint(Vec2::ANCHOR_MIDDLE); // Set the nodes setTitleLabel(node); setBackgroundSprite(backgroundSprite); // Set the default color and opacity setColor(Color3B::WHITE); setOpacity(255.0f); setOpacityModifyRGB(true); // Initialize the dispatch table setTitleForState(label->getString(), Control::State::NORMAL); setTitleColorForState(node->getColor(), Control::State::NORMAL); setTitleLabelForState(node, Control::State::NORMAL); setBackgroundSpriteForState(backgroundSprite, Control::State::NORMAL); setLabelAnchorPoint(Vec2::ANCHOR_MIDDLE); // Layout update needsLayout(); return true; } //couldn't init the Control else { return false; } }
void InternalWindow::setMaximize(bool Maximize) { if(Maximize && !getIsMaximized()) { _PreviousPosition = getPosition(); _PreviousSize = getSize(); setIsMaximized(Maximize); setPosition(Pnt2f(0,0)); setPreferredSize(Vec2f(getParentDrawingSurface()->getSize().x(),getParentDrawingSurface()->getSize().x())); } else if(!Maximize && getIsMaximized()) { setIsMaximized(Maximize); Vec2f TempSize(_PreviousSize); Pnt2f TempPos(_PreviousPosition); setPreferredSize(TempSize); setPosition(TempPos); _PreviousPosition = getPosition(); _PreviousSize = getSize(); } }
GRolloverButton::GRolloverButton( qreal w, qreal h, const PHIAItem *it, QGraphicsItem *parent ) : GLabelItem( w, h, it, parent ) { qDebug( "GRolloverButton::GRolloverButton()" ); setWidget( 0 ); delete _l; // delete QLabel _pixLabel=new PHIPixLabel(); setWidget( _pixLabel ); setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::Label ); setPreferredSize( w, h ); setMinimumSize( 0, 0 ); resize( w, h ); }
void MenuBar::updateLayout(void) { //Determine the Max Preferred Height of my MenuItems Real32 MaxHeight(0); Real32 TotalWidth(0); for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i) { if(MaxHeight < getChildren(i)->getPreferredSize().y()) { MaxHeight = getChildren(i)->getPreferredSize().y(); } TotalWidth += getChildren(i)->getPreferredSize().x(); } //Set My preferred Size Pnt2f TopLeft, BottomRight; Pnt2f InsetsTopLeft, InsetsBottomRight; getBounds(TopLeft, BottomRight); getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); Vec2f InsetSize( (BottomRight-TopLeft) - (InsetsBottomRight-InsetsTopLeft) ); Vec2f NewSize( TotalWidth+InsetSize.x(), MaxHeight+InsetSize.y()); if(getPreferredSize() != NewSize) { setPreferredSize(NewSize); } getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); //Now position and size the Items Real32 LeftOffset(InsetsTopLeft.x()); Vec2f Size; Pnt2f Pos; for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i) { Size.setValues(getChildren(i)->getPreferredSize().x(), MaxHeight); if(getChildren(i)->getSize() != Size) { getChildren(i)->setSize(Size); } Pos.setValues(LeftOffset, InsetsTopLeft.y()); if(getChildren(i)->getPosition() != Pos) { getChildren(i)->setPosition(Pos); } LeftOffset += getChildren(i)->getPreferredSize().x(); } }
void ToolTip::changed(ConstFieldMaskArg whichField, UInt32 origin, BitVector details) { Inherited::changed(whichField, origin, details); if(whichField & TextFieldMask) { setPreferredSize(calculatePreferredSize()); if(getSize() != getPreferredSize()) { setSize(getPreferredSize()); } } }
TimelineToolButton::TimelineToolButton(QAction *action, QGraphicsItem *parent) : QGraphicsWidget(parent) , m_action(action) { resize(TimelineConstants::toolButtonSize, TimelineConstants::toolButtonSize); setPreferredSize(size()); setAcceptHoverEvents(true); connect(action, &QAction::changed, this, [this]() { setVisible(m_action->isVisible()); update(); }); connect(this, &TimelineToolButton::clicked, action, &QAction::trigger); setEnabled(m_action->isEnabled()); setVisible(m_action->isVisible()); setCursor(Qt::ArrowCursor); }
ControlButton* ChoiceLayer::createButton(int idx, string title) { string choiceBtnBg = GlobalConfig::getInstance()->getChoiceMenuBgPath(); Size screenSize = Director::getInstance()->getVisibleSize(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) GBKToUTF(title); #endif auto button = ControlButton::create(title, GlobalConfig::getInstance()->getChoiceMenuFontName(), GlobalConfig::getInstance()->getChoiceMenuFontSize()); button->addTargetWithActionForControlEvents(this, cccontrol_selector(ChoiceLayer::choicesCallback), Control::EventType::TOUCH_UP_INSIDE); button->setBackgroundSpriteForState(Scale9Sprite::create(choiceBtnBg), Control::State::NORMAL); button->setPreferredSize(Size(screenSize.width*0.6, GlobalConfig::getInstance()->getChoiceMenuFontSize() + 10)); button->setOpacity(0); button->setTitleColorForState(GlobalConfig::getInstance()->getChoiceMenuFontColor(), Control::State::NORMAL); addChild(button, 0, idx); return button; }