void MaterialEditor::SetSize(const Vector2 &newSize) { DraggableDialog::SetSize(newSize); btnSetupFog->SetPosition(Vector2(newSize.x - ControlsFactory::BUTTON_WIDTH, ControlsFactory::BUTTON_HEIGHT)); btnSetupColor->SetPosition(Vector2(newSize.x - ControlsFactory::BUTTON_WIDTH*2, ControlsFactory::BUTTON_HEIGHT)); line->SetPosition(Vector2(newSize.x - ControlsFactory::BUTTON_WIDTH*3, ControlsFactory::BUTTON_HEIGHT * 3)); Rect setupFogRect(newSize.x - ControlsFactory::BUTTON_WIDTH, ControlsFactory::BUTTON_HEIGHT, ControlsFactory::BUTTON_WIDTH, ControlsFactory::BUTTON_HEIGHT); Rect fogRect(setupFogRect.x - ControlsFactory::BUTTON_WIDTH, setupFogRect.dy + setupFogRect.y, ControlsFactory::BUTTON_WIDTH * 2, ControlsFactory::BUTTON_HEIGHT * 5); fogControl->SetRect(fogRect); Rect setupColorRect(setupFogRect); setupColorRect.x -= ControlsFactory::BUTTON_WIDTH; Rect colorRect(setupColorRect.x - ControlsFactory::BUTTON_WIDTH, setupColorRect.dy + setupColorRect.y, ControlsFactory::BUTTON_WIDTH * 3, ControlsFactory::BUTTON_HEIGHT * 5); colorControl->SetRect(colorRect); float32 materialListWidth = materialsList->GetSize().x; Rect noMaterialsRect = noMaterials->GetRect(); noMaterials->SetRect(Rect(materialListWidth, noMaterialsRect.y, newSize.x - materialListWidth, noMaterialsRect.dy)); Rect propsRect = materialProps->GetRect(); RemoveControl(materialProps); SafeRelease(materialProps); materialProps = new MaterialPropertyControl(Rect(materialListWidth, propsRect.y, newSize.x - materialListWidth, propsRect.dy), false); materialProps->SetDelegate(this); AddControl(materialProps); SelectMaterial(selectedMaterial); }
/** * 功能: * 绘制单元格背景 */ void WinDigitalDelegate::drawBackground(QPainter *painter,const QStyleOptionViewItem &option, const QModelIndex &index) const { painter->save(); QPainterPath path; path.addRoundedRect(option.rect,5,5); painter->setClipPath(path);//倒角 /***************绘制背景色***************/ QRectF rect(option.rect); painter->setPen(Qt::transparent); painter->setBrush(option.backgroundBrush); painter->drawRect(rect); /*****************绘制色卡******************/ QRectF colorRect(rect); colorRect.setLeft(rect.right()-rect.width()/18); painter->setBrush(QBrush(index.data(ChannelColor).value<QColor>())); painter->drawRect(colorRect); /****************绘制光照效果****************/ QLinearGradient skinColor(rect.topLeft(),rect.bottomLeft()); skinColor.setColorAt(0,QColor(255,255,255,170)); skinColor.setColorAt(0.09,QColor(255,255,255,170)); skinColor.setColorAt(0.10,QColor(255,255,255,50)); skinColor.setColorAt(0.48,QColor(0,0,0,5)); skinColor.setColorAt(0.49,QColor(100,100,100,20)); skinColor.setColorAt(0.97,QColor(255,255,255,0)); skinColor.setColorAt(0.98,QColor(255,255,255,50)); skinColor.setColorAt(1,QColor(255,255,255,150)); painter->setPen(Qt::transparent); painter->setBrush(QBrush(skinColor)); painter->drawRect(rect); painter->restore(); }
void WinBarDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { if(index.isValid() && index.data(ChannelData).isValid()){ painter->save(); painter->setRenderHint(QPainter::Antialiasing); /**************配置*****************/ QRectF rect(option.rect.marginsAdded(margins)); if(option.state & QStyle::State_Sunken && option.state & QStyle::State_HasFocus){ rect.moveTo(rect.x() + 1, rect.y() + 1); } QRectF topRect(rect); topRect.setHeight(rect.height()/6); QFont font = option.font; font.setFamily(font.defaultFamily()); /*****************色卡*****************/ QRectF colorRect(topRect); colorRect.setHeight(topRect.height()/5 * 3); painter->setPen(QColor(0,0,0,0)); painter->setBrush(QColor(index.data(ChannelColor).value<QColor>())); painter->drawRoundedRect(colorRect,5,5); /****************头部背景色**************/ QRectF headRect(topRect); headRect.setTop(colorRect.center().y()); painter->setBrush(QBrush(QColor(240,240,240))); painter->drawRect(headRect); /******************底部背景色*******************/ QRectF bottomRect(rect); bottomRect.setTop(topRect.bottom() + 2); painter->setPen(QColor(0,0,0,0)); painter->setBrush(QBrush(QColor(240,240,240))); painter->drawRect(bottomRect); /******************色柱********************/ QRectF barRect(bottomRect); quint8 base = index.data(ChannelBarBase).toUInt(); qreal mesureVal = index.data(ChannelData).toDouble(); qreal rangeUpper = index.data(ChannelDispUpper).toDouble(); qreal rangeDowner = index.data(ChannelDispDowner).toDouble(); if(mesureVal >= 0){ barRect.setTop(barRect.top() + barRect.height()/2 * (1 - mesureVal/rangeUpper)); }else if(mesureVal < 0){ barRect.setTop(barRect.top() + barRect.height()/2 * (1 + mesureVal/rangeDowner)); } if(base == 1){ barRect.setBottom(bottomRect.center().y()); }else if(base == 2){ barRect.setBottom(bottomRect.top()); } painter->setPen(QColor(0,0,0,0)); painter->setBrush(QColor(index.data(ChannelColor).value<QColor>())); painter->drawRect(barRect); /****************光泽效果*****************/ QLinearGradient skinColor(rect.topLeft(),rect.topRight()); skinColor.setColorAt(0,QColor(255,255,255,0)); skinColor.setColorAt(0.09,QColor(255,255,255,0)); skinColor.setColorAt(0.1,QColor(255,255,255,200)); skinColor.setColorAt(0.13,QColor(255,255,255,200)); skinColor.setColorAt(0.14,QColor(255,255,255,80)); skinColor.setColorAt(0.50,QColor(0,0,0,20)); skinColor.setColorAt(0.75,QColor(0,0,0,10)); skinColor.setColorAt(0.76,QColor(255,255,255,30)); skinColor.setColorAt(0.95,QColor(255,255,255,150)); skinColor.setColorAt(0.96,QColor(255,255,255,0)); skinColor.setColorAt(1,QColor(255,255,255,0)); painter->setPen(QPen(QColor(200,230,255,0))); painter->setBrush(skinColor); painter->drawRect(rect); /*****************刻度*********************/ qreal baseX = bottomRect.right(); qreal baseY = bottomRect.top(); qreal len = bottomRect.width()/8; quint8 count = index.data(ChannelBarDiv).toUInt(); qreal span = bottomRect.height()/count; painter->setPen(Qt::black); painter->setBrush(QBrush(QColor(0,0,0,0))); for(quint8 i=1; i<count; ++i){ painter->drawLine(baseX - len, baseY + i*span, baseX, baseY + i*span); } /**************量程*****************/ QRectF valRect(bottomRect); valRect.setHeight(span); font.setPixelSize(valRect.height()/2); painter->setFont(font); painter->setPen(QPen(Qt::black,1)); painter->drawText(valRect,QString::number(rangeUpper,'f',4)); valRect.moveBottom(bottomRect.bottom()); painter->drawText(valRect,Qt::AlignBottom,QString::number(rangeDowner,'f',4)); /**************测量值*********************/ valRect.moveBottom(barRect.top()); if(valRect.top() < baseY + span){ valRect.moveTop(baseY + span); }else if(valRect.bottom() > bottomRect.bottom() - 2 * span){ valRect.moveBottom(bottomRect.bottom() - 2 * span); } painter->drawText(valRect,Qt::AlignBottom|Qt::AlignHCenter,QString::number(mesureVal,'f',4)); /*******************单位***********************/ valRect.moveTop(valRect.bottom()); valRect.setRight(baseX - len); //painter->setPen(QColor(100,100,100)); painter->drawText(valRect,Qt::AlignRight|Qt::AlignTop,index.data(ChannelUnit).toString()); /****************标记********************/ font.setPixelSize(headRect.height()/2); painter->setFont(font); painter->setPen(QColor(100,100,100)); painter->drawText(headRect,Qt::AlignCenter,index.data(ChannelTag).toString()); /*****************擦除头尾连接**********************/ painter->setBrush(QBrush(QColor(0,0,0,0))); painter->setPen(QPen(Qt::black,1)); painter->drawRect(bottomRect); painter->eraseRect(QRectF(topRect.bottomLeft(), bottomRect.topRight())); /*********************按压效果*************************/ if(option.state & QStyle::State_Sunken && option.state & QStyle::State_HasFocus){ painter->setPen(QPen(QColor(0,0,255,100),3)); painter->setBrush(QBrush(QColor(180,180,180,50))); painter->drawRoundedRect(rect,6,6); } painter->restore(); } }
MaterialEditor::MaterialEditor() : DraggableDialog(Rect(GetScreenWidth()/8, GetScreenHeight()/8, GetScreenWidth()/4*3, GetScreenHeight()/4*3)) {//todo: create draggable dealog ControlsFactory::CustomizeDialog(this); displayMode = EDM_ALL; workingMaterial = NULL; workingSceneNode = NULL; workingScene = NULL; float32 materialListWidth = size.x * materialListPart; btnAll = ControlsFactory::CreateButton(Rect(0, ControlsFactory::BUTTON_HEIGHT, materialListWidth/2, ControlsFactory::BUTTON_HEIGHT), LocalizedString(L"materialeditor.all")); btnAll->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &MaterialEditor::OnAllPressed)); btnSelected = ControlsFactory::CreateButton(Rect(materialListWidth/2, ControlsFactory::BUTTON_HEIGHT, materialListWidth/2, ControlsFactory::BUTTON_HEIGHT), LocalizedString(L"materialeditor.selected")); btnSelected->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &MaterialEditor::OnSelectedPressed)); Rect setupFogRect(GetRect().dx - ControlsFactory::BUTTON_WIDTH, ControlsFactory::BUTTON_HEIGHT, ControlsFactory::BUTTON_WIDTH, ControlsFactory::BUTTON_HEIGHT); btnSetupFog = ControlsFactory::CreateButton(setupFogRect, LocalizedString(L"materialeditor.setupfog")); btnSetupFog->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &MaterialEditor::OnSetupFog)); AddControl(btnSetupFog); Rect setupColorRect(setupFogRect); setupColorRect.x -= ControlsFactory::BUTTON_WIDTH; btnSetupColor = ControlsFactory::CreateButton(setupColorRect, L"Setup Color"); btnSetupColor->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &MaterialEditor::OnSetupColor)); AddControl(btnSetupColor); line = ControlsFactory::CreateLine(Rect(GetRect().dx - ControlsFactory::BUTTON_WIDTH*3, ControlsFactory::BUTTON_HEIGHT * 2, ControlsFactory::BUTTON_WIDTH*3, 1), Color::White()); AddControl(line); Rect fogRect(setupFogRect.x - ControlsFactory::BUTTON_WIDTH, setupFogRect.dy + setupFogRect.y, ControlsFactory::BUTTON_WIDTH * 2, ControlsFactory::BUTTON_HEIGHT * 5); fogControl = new FogControl(fogRect, this); Rect colorRect(setupColorRect.x - ControlsFactory::BUTTON_WIDTH, setupColorRect.dy + setupColorRect.y, ControlsFactory::BUTTON_WIDTH * 3, ControlsFactory::BUTTON_HEIGHT * 5); colorControl = new ColorControl(colorRect, this); materialsList = new UIList(Rect(0, ControlsFactory::BUTTON_HEIGHT * 2, materialListWidth, size.y - ControlsFactory::BUTTON_HEIGHT * 2), UIList::ORIENTATION_VERTICAL); materialsList->SetDelegate(this); ControlsFactory::SetScrollbar(materialsList); ControlsFactory::CusomizeListControl(materialsList); AddControl(materialsList); UIStaticText *text = new UIStaticText(Rect(0, 0, size.x * materialListPart, ControlsFactory::BUTTON_HEIGHT)); text->SetFont(ControlsFactory::GetFont12()); text->SetText(LocalizedString(L"materialeditor.materials")); text->SetTextColor(ControlsFactory::GetColorLight()); AddControl(text); SafeRelease(text); float32 textY = (GetRect().dy - ControlsFactory::BUTTON_HEIGHT ) / 2.f; noMaterials = new UIStaticText(Rect(materialListWidth, textY, GetRect().dx - materialListWidth, (float32)ControlsFactory::BUTTON_HEIGHT)); noMaterials->SetFont(ControlsFactory::GetFont12()); noMaterials->SetTextColor(ControlsFactory::GetColorLight()); noMaterials->SetText(LocalizedString(L"materialeditor.nomaterials")); selectedMaterial = -1; lastSelection = NULL; Vector<String> v; for (int i = 0; i < Material::MATERIAL_TYPES_COUNT; i++) { v.push_back(Material::GetTypeName((Material::eType)i)); } materialProps = new MaterialPropertyControl(Rect(size.x * materialListPart, size.y * previewHeightPart, size.x - size.x * materialListPart, size.y - size.y * previewHeightPart), false); materialProps->SetDelegate(this); AddControl(materialProps); }