void DBFRedactorDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem m_option(option); if (index.data(Qt::UserRole).toBool()) { m_option.palette.setBrush(QPalette::Background, m_settings.value("Removed_Color", Qt::darkGray).value<QColor>()); painter->fillRect(option.rect, m_option.palette.background()); } if (option.state & QStyle::State_Selected) painter->fillRect(option.rect, option.palette.highlight()); QString text; switch (m_redactor->field(index.column()).type) { case DBFRedactor::TYPE_LOGICAL: { QStyleOptionViewItem opt(option); opt.rect = checkRect(option, option.rect); opt.state = opt.state & ~QStyle::State_HasFocus; opt.state |= (index.data(Qt::CheckStateRole).toInt() == Qt::Checked ? QStyle::State_On : QStyle::State_Off); qApp->style()->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &opt, painter); return; break; } case DBFRedactor::TYPE_DATE: m_option.displayAlignment |= static_cast<Qt::AlignmentFlag> (m_settings.value("Date_Alignment", Qt::AlignHCenter).toInt()); m_option.palette.setColor(QPalette::Text, m_settings.value("Date_Color", Qt::darkYellow).value<QColor>()); m_option.font = m_settings.value("Date_Font", option.font).value<QFont> (); text = index.data(Qt::DisplayRole).toDate().toString(Qt::SystemLocaleShortDate); break; case DBFRedactor::TYPE_FLOAT: m_option.displayAlignment |= static_cast<Qt::AlignmentFlag> (m_settings.value("Float_Alignment", Qt::AlignRight).toInt()); m_option.palette.setColor(QPalette::Text, m_settings.value("Float_Color", Qt::darkBlue).value<QColor>()); m_option.font = m_settings.value("Float_Font", option.font).value<QFont> (); text = index.data(Qt::DisplayRole).toString(); break; case DBFRedactor::TYPE_NUMERIC: m_option.displayAlignment |= static_cast<Qt::AlignmentFlag> (m_settings.value("Numeric_Alignment", Qt::AlignRight).toInt()); m_option.palette.setColor(QPalette::Text, m_settings.value("Numeric_Color", Qt::darkBlue).value<QColor>()); m_option.font = m_settings.value("Numeric_Font", option.font).value<QFont> (); text = index.data(Qt::DisplayRole).toString(); break; case DBFRedactor::TYPE_CHAR: m_option.displayAlignment |= static_cast<Qt::AlignmentFlag> (m_settings.value("String_Alignment", Qt::AlignLeft).toInt()); m_option.palette.setColor(QPalette::Text, m_settings.value("String_Color", option.palette.color(QPalette::Text)).value<QColor>()); m_option.font = m_settings.value("String_Font", option.font).value<QFont> (); text = index.data(Qt::DisplayRole).toString(); break; case DBFRedactor::TYPE_MEMO: m_option.displayAlignment |= static_cast<Qt::AlignmentFlag> (m_settings.value("Memo_Alignment", Qt::AlignLeft).toInt()); m_option.palette.setColor(QPalette::Text, m_settings.value("Memo_Color", option.palette.color(QPalette::Text)).value<QColor>()); m_option.font = m_settings.value("Memo_Font", option.font).value<QFont> (); text = index.data(Qt::DisplayRole).toString(); break; default: text = index.data(Qt::DisplayRole).toString(); } drawDisplay(painter, m_option, m_option.rect, text); drawFocus(painter, m_option, m_option.rect); }
void pole::generate_obstacle() { QRect checkRect(this->currentX-g->size/2, this->currentY-g->size/2, g->size,g->size); for(int i=0;i<this->iks;i++) { for(int j=0;j<this->igrek;j++) { if(checkRect.contains(this->siatka[i][j].xpos,this->siatka[i][j].ypos)) { if(this->isClickedLeft) { this->siatka[i][j].free_status=true; } if(this->isClickedRight) { this->siatka[i][j].free_status=false; } } } } }
void spatialPFTracker::update(const cv::Mat &image, cv::Rect &roi){ double sum_w=0.0; for (size_t i=0; i<xpPred.size(); i++){ //prediction cv::Rect2d rect_ = xpPred[i]; rect_.x += rng->gaussian(sigX); rect_.y += rng->gaussian(sigY); xpPred[i] = checkRect(image, rect_); // evaluate weights spatiogram model_; cv::Mat patch = image(xpPred[i]); if (xpPred[i].width<=0 && xpPred[i].height<=0){ weights[i]=0.0; continue; } computeSpatiogram(patch, nBins, model_); double rho_1 = 1-compareSpatiograms(targetModel, model_); weights[i] = std::exp(-lambda*(rho_1)*(rho_1)); sum_w += weights[i]; } // normalize weights std::transform( weights.begin(), weights.end(), weights.begin(), std::bind1st(std::multiplies<double>(),1/(sum_w+std::numeric_limits<double>::epsilon())) ); // program the function!!!! //std::cout<<"SIZE IM: "<<image.rows<<","<<image.cols<<std::endl; //std::cout<<"preda="<<xpPred[0].x<<","<<xpPred[0].y<<","<<xpPred[0].width<<","<<xpPred[0].height<<std::endl; cv::Rect2d roi2d = propagEstimate( xpPred, weights, rng ); //std::cout<<"predb="<<xpPred[0].x<<","<<xpPred[0].y<<","<<xpPred[0].width<<","<<xpPred[0].height<<std::endl; //std::cout<<"pred="<<roi2d.x<<","<<roi2d.y<<","<<roi2d.width<<","<<roi2d.height<<std::endl; roi2d = checkRect(image, roi2d); //std::cout<<"pred="<<roi2d.x<<","<<roi2d.y<<","<<roi2d.width<<","<<roi2d.height<<std::endl; roi.x = int(std::floor(roi2d.x)); roi.y = int(std::floor(roi2d.y)); roi.height = int(std::floor(roi2d.height)); roi.width = int(std::floor(roi2d.width)); /*cv::Mat im1=image.clone(); std::cout<<"SIZE PRED: "<<xpPred.size()<<std::endl; for (size_t i=0; i<xpPred.size(); i++){ cv::rectangle( im1, xpPred[i], cv::Scalar( 255, 255, 255 ), 2, 1 ); cv::imshow("a",im1); } cv::waitKey(0);*/ }
void OccArea::resizeTo(const Rectangle& newRect) { Rectangle checkRect( newRect ); if ( !checkNewRect( checkRect ) ) { return; } resetOccupant(); Area::resizeTo( checkRect ); }
//------------------------------------------------------------ void nsGfxCheckboxControlFrame::PaintCheckBox(nsIRenderingContext& aRenderingContext, nsPoint aPt, const nsRect& aDirtyRect) { // REVIEW: moved the mAppearance test out so we avoid constructing // a display item if it's not needed nsRect checkRect(aPt, mRect.Size()); checkRect.Deflate(GetUsedBorderAndPadding()); const nsStyleColor* color = GetStyleColor(); aRenderingContext.SetColor(color->mColor); PaintCheckMark(aRenderingContext, checkRect); }
void GuideManager::nextStep(int step) { CCLOG("step = %d",step); const StepInfo& stepInfo = m_vecStep.at(step); if (getWait()) { return; } if (isLimit(stepInfo)) { return; } m_guideLayer->removeFromParent(); getParent()->addChild(m_guideLayer, GUIDE_LAYER_ZORDER); if (stepInfo.getNextStepId() == END) { endGuide(); return; } else if (stepInfo.getNextStepId() == WAIT) { setWait(true); } else if (stepInfo.getNextStepId() == SLEEP) { getGuideLayer()->sleep(); } else if (stepInfo.getNextStepId() == WAKE) { getGuideLayer()->wake(); } // by order checkDialog(stepInfo); checkRect(stepInfo); checkTalk(stepInfo); checkHand(stepInfo); checkEvent(stepInfo); setNextStepId(step + 1); }
void spatialPFTracker::init(const cv::Mat &image, const cv::Rect &roi){ imPatch = image(roi).clone(); boundBox = roi; computeSpatiogram(imPatch, nBins, targetModel); started=true; // initialize particles for (size_t i=0; i<xpPred.size(); i++){ cv::Rect2d rect_; rect_ = boundBox; rect_.x += rng->gaussian(sigX); rect_.y += rng->gaussian(sigY); xpPred[i] = checkRect(image, rect_); } }
void AVTPlotWidget::mouseMoveEvent( QMouseEvent *e ) { QRect checkRect( leftPadding(), topPadding(), pixRect().width(), pixRect().height() ); int Xcursor = e->x(); int Ycursor = e->y(); if ( ! checkRect.contains( e->x(), e->y() ) ) { if ( e->x() < checkRect.left() ) Xcursor = checkRect.left(); if ( e->x() > checkRect.right() ) Xcursor = checkRect.right(); if ( e->y() < checkRect.top() ) Ycursor = checkRect.top(); if ( e->y() > checkRect.bottom() ) Ycursor = checkRect.bottom(); } Xcursor -= leftPadding(); Ycursor -= topPadding(); MousePoint = QPoint( Xcursor, Ycursor ); update(); }
//! draws the element and its children void CGUICheckBox::draw() { if (!IsVisible) return; IGUISkin* skin = Environment->getSkin(); if (skin) { const core::rect<s32> rect = AbsoluteRect; const s32 height = skin->getSize(EGDS_CHECK_BOX_WIDTH); core::rect<s32> checkRect(AbsoluteRect.UpperLeftCorner.X, ((AbsoluteRect.getHeight() - height) / 2) + AbsoluteRect.UpperLeftCorner.Y, 0, 0); checkRect.LowerRightCorner.X = checkRect.UpperLeftCorner.X + height; checkRect.LowerRightCorner.Y = checkRect.UpperLeftCorner.Y + height; EGUI_DEFAULT_COLOR col = EGDC_GRAY_EDITABLE; if ( isEnabled() ) col = Pressed ? EGDC_FOCUSED_EDITABLE : EGDC_EDITABLE; skin->draw3DSunkenPane(this, skin->getColor(col), false, true, checkRect, &AbsoluteClippingRect); if (Checked) { skin->drawIcon(this, EGDI_CHECK_BOX_CHECKED, checkRect.getCenter(), checkTime, os::Timer::getTime(), false, &AbsoluteClippingRect); } if (Text.size()) { checkRect = AbsoluteRect; checkRect.UpperLeftCorner.X += height + 5; IGUIFont* font = skin->getFont(); if (font) { font->draw(Text.c_str(), checkRect, skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), false, true, &AbsoluteClippingRect); } } } IGUIElement::draw(); }
BORDER4 HelloWorld::checkRect(cocos2d::CCPoint* pt) { //Top float top = m_Rect.origin.y + m_Rect.size.height; if (pt->y > top) { pt->y = 2*top - pt->y; } //Left float left = m_Rect.origin.x; if (pt->x < left) { pt->x = 2*left - pt->x; } //Buttom float buttom = m_Rect.origin.y; if (pt->y < buttom) { pt->y = 2*buttom - pt->y; } //Right float right = m_Rect.origin.x + m_Rect.size.width; if (pt->x > right) { pt->x = 2*right - pt->x; } if (!m_Rect.containsPoint(*pt)) { checkRect(pt); } return BORDER_BOTTOM; }
void PhaseItem::mousePressEvent(QGraphicsSceneMouseEvent* e) { if(mControlsVisible && checkRect().contains(e->pos())) { //qDebug() << "-> Check clicked"; // Do not select phase when clicking on the box e->accept(); if(mState == Qt::PartiallyChecked) mState = Qt::Checked; else if(mState == Qt::Checked) mState = Qt::Unchecked; else if(mState == Qt::Unchecked) mState = Qt::Checked; MainWindow::getInstance()->getProject()->updatePhaseEvents(mData[STATE_ID].toInt(), mState); //update(); //if(scene()) // scene()->update(); } else if(mControlsVisible && eyeRect().contains(e->pos())) { //qDebug() << "-> Eye clicked"; // Do not select phase when clicking on the box e->accept(); mEyeActivated = !mEyeActivated; ((PhasesScene*)mScene)->updateEyedPhases(); update(); if(scene()) scene()->update(); } else { AbstractItem::mousePressEvent(e); } }
//! draws the element and its children void CGUICheckBox::draw() { if (!IsVisible) return; IGUISkin* skin = Environment->getSkin(); core::rect<s32> rect = AbsoluteRect; s32 height = skin->getSize(EGDS_CHECK_BOX_WIDTH); core::rect<s32> checkRect(AbsoluteRect.UpperLeftCorner.X, ((AbsoluteRect.getHeight() - height) / 2) + AbsoluteRect.UpperLeftCorner.Y, 0, 0); checkRect.LowerRightCorner.X = checkRect.UpperLeftCorner.X + height; checkRect.LowerRightCorner.Y = checkRect.UpperLeftCorner.Y + height; skin->draw3DSunkenPane(this, skin->getColor(Pressed || !IsEnabled ? EGDC_3D_FACE : EGDC_ACTIVE_CAPTION), false, true, checkRect, &AbsoluteClippingRect); if (Checked && Environment->getSkin()) Environment->getSkin()->drawIcon(this, EGDI_CHECK_BOX_CHECKED, checkRect.getCenter(), checkTime, os::Timer::getTime(), false, &AbsoluteClippingRect); if (Text.size()) { checkRect = AbsoluteRect; checkRect.UpperLeftCorner.X += height + 5; IGUIFont* font = skin->getFont(); if (font) font->draw(Text.c_str(), checkRect, skin->getColor(IsEnabled ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), false, true, &AbsoluteClippingRect); } IGUIElement::draw(); }
bool DBFRedactorDelegate::editorEvent (QEvent* ev, QAbstractItemModel* model,const QStyleOptionViewItem& option, const QModelIndex& index) { if (m_redactor->field(index.column()).type != DBFRedactor::TYPE_LOGICAL) return QItemDelegate::editorEvent(ev, model, option, index); if(!ev || ! model) return false; const Qt::ItemFlags flags = model->flags(index); if (!(option.state & QStyle::State_Enabled) || !(flags & Qt::ItemIsEnabled)) return false; switch(ev->type()) { case QEvent::MouseButtonRelease: { QRect rect(checkRect(option, option.rect)); QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(ev); if (mouseEvent->button() != Qt::LeftButton || !rect.contains(mouseEvent->pos())) return true; break; } case QEvent::MouseButtonDblClick: { return true; } case QEvent::KeyPress: { QKeyEvent* keyEvent = static_cast<QKeyEvent*>(ev); if(keyEvent->key() != Qt::Key_Space && keyEvent->key() != Qt::Key_Select) return false; break; } default: return false; } const Qt::CheckState &value = index.data(Qt::CheckStateRole).toInt() == Qt::Checked ? Qt::Unchecked : Qt::Checked; return model->setData(index, value, Qt::EditRole); }
float HelloWorld::getAngle(CCPoint* des, CCPoint* tar) { float angle; float _x = tar->x - des->x; float _y = tar->y - des->y; angle = atan2f(_y, _x); for (int i = 0; i < m_vDot.size(); i++) { float height = i*DOT_SEGMENT; float y = sinf(angle)*height; float x = cosf(angle)*height; CCPoint pt = ccp(x,y); checkRect(&pt); m_vDot[i]->setPosition(pt); } return angle; }
bool IconsetDelegate::editorEvent(QEvent *AEvent, QAbstractItemModel *AModel, const QStyleOptionViewItem &AOption, const QModelIndex &AIndex) { Qt::ItemFlags flags = AModel->flags(AIndex); if (!(flags & Qt::ItemIsUserCheckable) || !(AOption.state & QStyle::State_Enabled) || !(flags & Qt::ItemIsEnabled)) return false; QVariant value = AIndex.data(Qt::CheckStateRole); if (!value.isValid()) return false; if ((AEvent->type() == QEvent::MouseButtonRelease) || (AEvent->type() == QEvent::MouseButtonDblClick)) { int space = 2; QRect drawRect = AOption.rect.adjusted(space,space,-space,-space); QRect checkRect(drawRect.topLeft(),checkButtonRect(AOption, AOption.rect, Qt::Checked).size()); if (!checkRect.contains(static_cast<QMouseEvent*>(AEvent)->pos())) return false; if (AEvent->type() == QEvent::MouseButtonDblClick) return true; } else if (AEvent->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent*>(AEvent); if (keyEvent->key() != Qt::Key_Space && keyEvent->key() != Qt::Key_Select) return false; } else { return false; } Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked ? Qt::Unchecked : Qt::Checked); return AModel->setData(AIndex, state, Qt::CheckStateRole); }
//! draws the element and its children void CGUICheckBox::draw() { if (!IsVisible) return; IGUISkin* skin = Environment->getSkin(); if (skin) { video::IVideoDriver* driver = Environment->getVideoDriver(); core::rect<s32> frameRect(AbsoluteRect); // draw background if (Background) { video::SColor bgColor = skin->getColor(gui::EGDC_3D_FACE); driver->draw2DRectangle(bgColor, frameRect, &AbsoluteClippingRect); } // draw the border if (Border) { skin->draw3DSunkenPane(this, 0, true, false, frameRect, &AbsoluteClippingRect); frameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X); frameRect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X); } const s32 height = skin->getSize(EGDS_CHECK_BOX_WIDTH); // the rectangle around the "checked" area. core::rect<s32> checkRect(frameRect.UpperLeftCorner.X, ((frameRect.getHeight() - height) / 2) + frameRect.UpperLeftCorner.Y, 0, 0); checkRect.LowerRightCorner.X = checkRect.UpperLeftCorner.X + height; checkRect.LowerRightCorner.Y = checkRect.UpperLeftCorner.Y + height; EGUI_DEFAULT_COLOR col = EGDC_GRAY_EDITABLE; if ( isEnabled() ) col = Pressed ? EGDC_FOCUSED_EDITABLE : EGDC_EDITABLE; skin->draw3DSunkenPane(this, skin->getColor(col), false, true, checkRect, &AbsoluteClippingRect); // the checked icon if (Checked) { skin->drawIcon(this, EGDI_CHECK_BOX_CHECKED, checkRect.getCenter(), CheckTime, os::Timer::getTime(), false, &AbsoluteClippingRect); } // associated text if (Text.size()) { checkRect = frameRect; checkRect.UpperLeftCorner.X += height + 5; IGUIFont* font = skin->getFont(); if (font) { font->draw(Text.c_str(), checkRect, skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), false, true, &AbsoluteClippingRect); } } } IGUIElement::draw(); }
void CCustomStyle::drawMenuItem(const QStyleOption *option, QPainter *painter, const QWidget *widget ) const { painter->save(); if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) { // 先绘制一层背景(否则在透明情况下, 会直接透过去); painter->setPen(colItemBg); painter->setBrush(colItemBg); painter->drawRect(option->rect); if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) { int w = 0; if (!menuItem->text.isEmpty()) { // 绘制分隔符文字 painter->setFont(menuItem->font); proxy()->drawItemText(painter, menuItem->rect.adjusted(5, 0, -5, 0), Qt::AlignLeft | Qt::AlignVCenter, menuItem->palette, menuItem->state & State_Enabled, menuItem->text, QPalette::Text); w = menuItem->fontMetrics.width(menuItem->text) + 5; } painter->setPen(colSeparator); bool reverse = menuItem->direction == Qt::RightToLeft; painter->drawLine(menuItem->rect.left() + 5 + (reverse ? 0 : w), menuItem->rect.center().y(), menuItem->rect.right() - 5 - (reverse ? w : 0), menuItem->rect.center().y()); painter->restore(); return; } bool selected = menuItem->state & State_Selected && menuItem->state & State_Enabled; if (selected) { QRect r = option->rect; painter->fillRect(r, colItemHighlight); } bool checkable = menuItem->checkType != QStyleOptionMenuItem::NotCheckable; bool checked = menuItem->checked; bool sunken = menuItem->state & State_Sunken; bool enabled = menuItem->state & State_Enabled; bool ignoreCheckMark = false; int checkcol = qMax(menuItem->maxIconWidth, 20); if (qobject_cast<const QComboBox*>(widget)) { ignoreCheckMark = true; //ignore the checkmarks provided by the QComboMenuDelegate } if (!ignoreCheckMark) { // Check QRect checkRect(option->rect.left() + 7, option->rect.center().y() - 6, 14, 14); checkRect = visualRect(menuItem->direction, menuItem->rect, checkRect); if (checkable) { if (menuItem->checkType & QStyleOptionMenuItem::Exclusive) { // Radio button 未实现 if (checked || sunken) { /* painter->setRenderHint(QPainter::Antialiasing); painter->setPen(Qt::NoPen); QPalette::ColorRole textRole = !enabled ? QPalette::Text: selected ? QPalette::HighlightedText : QPalette::ButtonText; painter->setBrush(option->palette.brush( option->palette.currentColorGroup(), textRole)); painter->drawEllipse(checkRect.adjusted(4, 4, -4, -4)); */ } } else { // Check box if (menuItem->icon.isNull()) { QStyleOptionButton box; box.QStyleOption::operator=(*option); box.rect = checkRect; if (checked) { box.state |= State_On; } proxy()->drawPrimitive(PE_IndicatorCheckBox, &box, painter, widget); } } } } else { //ignore checkmark if (menuItem->icon.isNull()) { checkcol = 0; } else { checkcol = menuItem->maxIconWidth; } } // Text and icon, ripped from windows style bool dis = !(menuItem->state & State_Enabled); bool act = menuItem->state & State_Selected; const QStyleOption *opt = option; const QStyleOptionMenuItem *menuitem = menuItem; QPainter *p = painter; QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x() + 4, menuitem->rect.y(), checkcol, menuitem->rect.height())); if (!menuItem->icon.isNull()) { QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal; if (act && !dis) { mode = QIcon::Active; } QPixmap pixmap; int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize, option, widget); QSize iconSize(smallIconSize, smallIconSize); if (const QComboBox *combo = qobject_cast<const QComboBox*>(widget)) { iconSize = combo->iconSize(); } if (checked) { pixmap = menuItem->icon.pixmap(iconSize, mode, QIcon::On); } else { pixmap = menuItem->icon.pixmap(iconSize, mode); } int pixw = pixmap.width(); int pixh = pixmap.height(); QRect pmr(0, 0, pixw, pixh); pmr.moveCenter(vCheckRect.center()); painter->setPen(colText);//menuItem->palette.text().color() if (checkable && checked) { QStyleOption opt = *option; if (act) { QColor activeColor = mergedColors( colItemBg, //option->palette.background().color(), colItemHighlight // option->palette.highlight().color()); ); opt.palette.setBrush(QPalette::Button, activeColor); } opt.state |= State_Sunken; opt.rect = vCheckRect; proxy()->drawPrimitive(PE_PanelButtonCommand, &opt, painter, widget); } painter->drawPixmap(pmr.topLeft(), pixmap); } if (selected) { painter->setPen(colText);//menuItem->palette.highlightedText().color() } else { painter->setPen(colText); //menuItem->palette.text().color() } int x, y, w, h; menuitem->rect.getRect(&x, &y, &w, &h); int tab = menuitem->tabWidth; QColor discol; if (dis) { discol = colDisText; //menuitem->palette.text().color() p->setPen(discol); } int xm = windowsItemFrame + checkcol + windowsItemHMargin + 2; int xpos = menuitem->rect.x() + xm; //modify text position(if we don't add xm, we can make text left-aligned) QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin); QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect); QString s = menuitem->text; if (!s.isEmpty()) { // draw text p->save(); int t = s.indexOf(QLatin1Char('\t')); int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (!QProxyStyle::styleHint(SH_UnderlineShortcut, menuitem, widget)) { text_flags |= Qt::TextHideMnemonic; } text_flags |= Qt::AlignLeft; if (t >= 0) { QRect vShortcutRect = visualRect(opt->direction, menuitem->rect, QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom()))); if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, option, widget)) { p->setPen(colText);//menuitem->palette.light().color() p->drawText(vShortcutRect.adjusted(1, 1, 1, 1), text_flags, s.mid(t + 1)); p->setPen(discol); } p->drawText(vShortcutRect, text_flags, s.mid(t + 1)); s = s.left(t); } QFont font = menuitem->font; // font may not have any "hard" flags set. We override // the point size so that when it is resolved against the device, this font will win. // This is mainly to handle cases where someone sets the font on the window // and then the combo inherits it and passes it onward. At that point the resolve mask // is very, very weak. This makes it stonger. font.setPointSizeF(QFontInfo(menuItem->font).pointSizeF()); if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem) { font.setBold(true); } p->setFont(font); if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, option, widget)) { p->setPen(menuitem->palette.light().color()); p->drawText(vTextRect.adjusted(1, 1, 1, 1), text_flags, s.left(t)); p->setPen(discol); } p->drawText(vTextRect, text_flags, s.left(t)); p->restore(); } // Arrow 绘制子菜单指示符 if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu) { // draw sub menu arrow int dim = (menuItem->rect.height() - 4) / 2; PrimitiveElement arrow; arrow = option->direction == Qt::RightToLeft ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight; int xpos = menuItem->rect.left() + menuItem->rect.width() - 3 - dim; QRect vSubMenuRect = visualRect(option->direction, menuItem->rect, QRect(xpos, menuItem->rect.top() + menuItem->rect.height() / 2 - dim / 2, dim, dim)); QStyleOptionMenuItem newMI = *menuItem; newMI.rect = vSubMenuRect; newMI.state = !enabled ? State_None : State_Enabled; if (selected) { newMI.palette.setColor(QPalette::ButtonText,// 此处futionstyle 有误, QPalette::Foreground改为ButtonText colIndicatorArrow); //newMI.palette.highlightedText().color() } else { newMI.palette.setColor(QPalette::ButtonText, colIndicatorArrow); } proxy()->drawPrimitive(arrow, &newMI, painter, widget); } } painter->restore(); }
void PhaseItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); painter->setRenderHint(QPainter::Antialiasing); QRectF rect = boundingRect(); int rounded = 15; QColor phaseColor = QColor(mData[STATE_COLOR_RED].toInt(), mData[STATE_COLOR_GREEN].toInt(), mData[STATE_COLOR_BLUE].toInt()); QColor fontColor = getContrastedColor(phaseColor); painter->setPen(Qt::NoPen); painter->setBrush(phaseColor); painter->drawRoundedRect(rect, rounded, rounded); if(mControlsVisible) { // Checked QRectF cRect = checkRect(); drawCheckBoxBox(*painter, cRect, mState, Qt::white, QColor(150, 150, 150)); // Eye QRectF eRect = eyeRect(); painter->setBrush(Qt::white); painter->setPen(Qt::black); painter->drawRoundedRect(eRect, 10, 10); if(mEyeActivated) { QPixmap eye(":eye.png"); painter->drawPixmap(eRect, eye, eye.rect()); } } // Name QRectF tr(rect.x() + mBorderWidth + 2*mEltsMargin + mTitleHeight, rect.y() + mBorderWidth + mEltsMargin, rect.width() - 2*mBorderWidth - 2*(mTitleHeight + 2*mEltsMargin), mTitleHeight); QFont font = qApp->font(); painter->setFont(font); QFontMetrics metrics(font); QString name = mData[STATE_NAME].toString(); name = metrics.elidedText(name, Qt::ElideRight, tr.width()); painter->setPen(fontColor); painter->drawText(tr, Qt::AlignCenter, name); // Change font font.setPointSizeF(pointSize(11.f)); painter->setFont(font); // Type (duration tau) QString tauStr = getTauString(); if(!tauStr.isEmpty()) { QRectF tpr(rect.x() + mBorderWidth + mEltsMargin, rect.y() + rect.height() - mBorderWidth - mEltsMargin - mEltsHeight, rect.width() - 2*mBorderWidth - 2*mEltsMargin, mEltsHeight); painter->setPen(Qt::black); painter->setBrush(Qt::white); painter->drawRect(tpr); painter->drawText(tpr, Qt::AlignCenter, tauStr); } // Events QRectF r(rect.x() + mBorderWidth + mEltsMargin, rect.y() + mBorderWidth + mEltsMargin + mTitleHeight + mEltsMargin, rect.width() - 2 * (mEltsMargin + mBorderWidth), mEltsHeight); QJsonArray events = getEvents(); double dy = mEltsMargin + mEltsHeight; for(int i=0; i<events.size(); ++i) { QJsonObject event = events[i].toObject(); QColor eventColor(event[STATE_COLOR_RED].toInt(), event[STATE_COLOR_GREEN].toInt(), event[STATE_COLOR_BLUE].toInt()); if(i > 0) r.adjust(0, dy, 0, dy); painter->fillRect(r, eventColor); painter->setPen(getContrastedColor(eventColor)); painter->drawText(r, Qt::AlignCenter, event[STATE_NAME].toString()); } // Border painter->setBrush(Qt::NoBrush); if(isSelected()) { painter->setPen(QPen(Qt::white, 5.f)); painter->drawRoundedRect(rect.adjusted(1, 1, -1, -1), rounded, rounded); painter->setPen(QPen(Qt::red, 3.f)); painter->drawRoundedRect(rect.adjusted(1, 1, -1, -1), rounded, rounded); } }
void RenderRadio::paintObject(PaintInfo& i, int _tx, int _ty) { ASSERT(node()); Element* element = static_cast<Element*>(node()); InputElement* inputElement = toInputElement(element); bool isEnabled = element->isEnabledFormControl(); bool isChecked = inputElement->isChecked(); i.context->save(); RefPtr<Image> image = Image::loadPlatformResource( "radioButtonStates" ).get(); IntPoint destPt( _tx, _ty ); IntRect srcRect( 0, 0, 14, 16 ); if (isEnabled) { if (node()->active()) { if (isChecked) { srcRect.move( 75, 0 ); } else { srcRect.move( 60, 0 ); } } else if (node()->hovered()) { if (isChecked) { srcRect.move( 45, 0 ); } else { srcRect.move( 30, 0 ); } } else { if (isChecked) { srcRect.move( 15, 0 ); } else { } } } else { if (isChecked) { srcRect.move( 105, 0 ); } else { srcRect.move( 90, 0 ); } } i.context->drawImage( image.get(), DeviceColorSpace, destPt, srcRect ); // draw the focus ring. // if (node()->focused()) { IntRect focusRingSrcRect( 120, 0, 15, 17 ); i.context->drawImage( image.get(), DeviceColorSpace, destPt, focusRingSrcRect ); } #if 0 // this is the old "moveto - lineto" drawing code IntRect checkRect(_tx + borderLeft() , _ty + borderTop() , width() - borderLeft() - borderRight() , height() - borderBottom() - borderTop()); Color fillColor(0xff, 0xff, 0xff, 0x00); Color rectColor(0x18, 0x52, 0x84); Color checkColor(0x21, 0xa5, 0x21); if (!node()->isEnabled()) { rectColor = Color(0xce, 0xce, 0xdb); checkColor = Color(0xce, 0xce, 0xdb); } i.context->setStrokeThickness(1); i.context->setStrokeStyle(SolidStroke); i.context->setStrokeColor(rectColor); i.context->setFillColor(fillColor); i.context->drawEllipse(checkRect); if(node()->isEnabled() && node()->hovered()) { i.context->setStrokeColor(Color(0xff, 0xb5, 0x31)); IntRect hoverRect = checkRect; hoverRect.inflateX(-1); hoverRect.inflateY(-1); i.context->drawEllipse( hoverRect ); hoverRect.inflateX(-1); hoverRect.inflateY(-1); i.context->drawEllipse( hoverRect ); } if (isChecked) { i.context->setStrokeThickness(2); i.context->setStrokeColor(checkColor); i.context->setFillColor(checkColor); IntRect fillRect = checkRect; fillRect.inflateX(-2); fillRect.inflateY(-2); i.context->drawEllipse(fillRect); } #endif i.context->restore(); }