void CATextField::setMarginImageRight(const DSize& imgSize, const std::string& filePath) { setMarginRight(imgSize.width); CAImageView* ima = (CAImageView*)this->getSubviewByTag(1011); if (!ima) { ima = CAImageView::create(); ima->setTag(1011); this->addSubview(ima); } ima->setCenter(DRect(getBounds().size.width - imgSize.width / 2, getBounds().size.height / 2, imgSize.width, imgSize.height)); ima->setImage(CAImage::create(filePath)); }
void LayoutScrollbarPart::computeScrollbarWidth() { if (!m_scrollbar->owningLayoutObject()) return; // FIXME: We are querying layout information but nothing guarantees that it's up-to-date, especially since we are called at style change. // FIXME: Querying the style's border information doesn't work on table cells with collapsing borders. int visibleSize = m_scrollbar->owningLayoutObject()->size().width() - m_scrollbar->owningLayoutObject()->style()->borderLeftWidth() - m_scrollbar->owningLayoutObject()->style()->borderRightWidth(); int w = calcScrollbarThicknessUsing(MainOrPreferredSize, style()->width(), visibleSize); int minWidth = calcScrollbarThicknessUsing(MinSize, style()->minWidth(), visibleSize); int maxWidth = style()->maxWidth().isMaxSizeNone() ? w : calcScrollbarThicknessUsing(MaxSize, style()->maxWidth(), visibleSize); setWidth(std::max(minWidth, std::min(maxWidth, w))); // Buttons and track pieces can all have margins along the axis of the scrollbar. setMarginLeft(minimumValueForLength(style()->marginLeft(), visibleSize)); setMarginRight(minimumValueForLength(style()->marginRight(), visibleSize)); }
void AP_UnixDialog_PageSetup::event_OK (void) { fp_PageSize fp = m_PageSize; if(fp.Width(DIM_IN) < 1.0 || fp.Height(DIM_IN) < 1.0) { // "The margins selected are too large to fit on the page." // Not quite the right message, but it's pretty close, // and I don't know how to add strings. m_pFrame->showMessageBox(AP_STRING_ID_DLG_PageSetup_ErrBigMargins, XAP_Dialog_MessageBox::b_O, XAP_Dialog_MessageBox::a_OK); setAnswer(a_CANCEL); return; } setMarginUnits (last_margin_unit); setPageSize (fp); setPageOrientation (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (m_radioPagePortrait)) ? PORTRAIT : LANDSCAPE); setPageScale (gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (m_spinPageScale))); setMarginTop (gtk_spin_button_get_value (GTK_SPIN_BUTTON (m_spinMarginTop))); setMarginBottom (gtk_spin_button_get_value (GTK_SPIN_BUTTON (m_spinMarginBottom))); setMarginLeft (gtk_spin_button_get_value (GTK_SPIN_BUTTON (m_spinMarginLeft))); setMarginRight (gtk_spin_button_get_value (GTK_SPIN_BUTTON (m_spinMarginRight))); setMarginHeader (gtk_spin_button_get_value (GTK_SPIN_BUTTON (m_spinMarginHeader))); setMarginFooter (gtk_spin_button_get_value (GTK_SPIN_BUTTON (m_spinMarginFooter))); // The window will only close (on an OK click) if the margins // fit inside the paper size. if ( validatePageSettings() ) { setAnswer (a_OK); } else { // "The margins selected are too large to fit on the page." m_pFrame->showMessageBox(AP_STRING_ID_DLG_PageSetup_ErrBigMargins, XAP_Dialog_MessageBox::b_O, XAP_Dialog_MessageBox::a_OK); } }
void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode) { // load styles used by all widgets for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag() == "color") setColor(node->value<Color>()); else if(node->tag() == "x") setX(node->value<int>()); else if(node->tag() == "y") setY(node->value<int>()); else if(node->tag() == "pos") setPosition(node->value<Point>()); else if(node->tag() == "width") setWidth(node->value<int>()); else if(node->tag() == "height") setHeight(node->value<int>()); else if(node->tag() == "rect") setRect(node->value<Rect>()); else if(node->tag() == "background") setBackgroundColor(node->value<Color>()); else if(node->tag() == "background-color") setBackgroundColor(node->value<Color>()); else if(node->tag() == "background-offset-x") setBackgroundOffsetX(node->value<int>()); else if(node->tag() == "background-offset-y") setBackgroundOffsetY(node->value<int>()); else if(node->tag() == "background-offset") setBackgroundOffset(node->value<Point>()); else if(node->tag() == "background-width") setBackgroundWidth(node->value<int>()); else if(node->tag() == "background-height") setBackgroundHeight(node->value<int>()); else if(node->tag() == "background-size") setBackgroundSize(node->value<Size>()); else if(node->tag() == "background-rect") setBackgroundRect(node->value<Rect>()); else if(node->tag() == "icon") setIcon(stdext::resolve_path(node->value(), node->source())); else if(node->tag() == "icon-source") setIcon(stdext::resolve_path(node->value(), node->source())); else if(node->tag() == "icon-color") setIconColor(node->value<Color>()); else if(node->tag() == "icon-offset-x") setIconOffsetX(node->value<int>()); else if(node->tag() == "icon-offset-y") setIconOffsetY(node->value<int>()); else if(node->tag() == "icon-offset") setIconOffset(node->value<Point>()); else if(node->tag() == "icon-width") setIconWidth(node->value<int>()); else if(node->tag() == "icon-height") setIconHeight(node->value<int>()); else if(node->tag() == "icon-size") setIconSize(node->value<Size>()); else if(node->tag() == "icon-rect") setIconRect(node->value<Rect>()); else if(node->tag() == "opacity") setOpacity(node->value<float>()); else if(node->tag() == "enabled") setEnabled(node->value<bool>()); else if(node->tag() == "visible") setVisible(node->value<bool>()); else if(node->tag() == "checked") setChecked(node->value<bool>()); else if(node->tag() == "dragable") setChecked(node->value<bool>()); else if(node->tag() == "on") setOn(node->value<bool>()); else if(node->tag() == "focusable") setFocusable(node->value<bool>()); else if(node->tag() == "phantom") setPhantom(node->value<bool>()); else if(node->tag() == "size") setSize(node->value<Size>()); else if(node->tag() == "fixed-size") setFixedSize(node->value<bool>()); else if(node->tag() == "clipping") setClipping(node->value<bool>()); else if(node->tag() == "border") { auto split = stdext::split(node->value(), " "); if(split.size() == 2) { setBorderWidth(stdext::safe_cast<int>(split[0])); setBorderColor(stdext::safe_cast<Color>(split[1])); } else throw OTMLException(node, "border param must have its width followed by its color"); } else if(node->tag() == "border-width") setBorderWidth(node->value<int>()); else if(node->tag() == "border-width-top") setBorderWidthTop(node->value<int>()); else if(node->tag() == "border-width-right") setBorderWidthRight(node->value<int>()); else if(node->tag() == "border-width-bottom") setBorderWidthBottom(node->value<int>()); else if(node->tag() == "border-width-left") setBorderWidthLeft(node->value<int>()); else if(node->tag() == "border-color") setBorderColor(node->value<Color>()); else if(node->tag() == "border-color-top") setBorderColorTop(node->value<Color>()); else if(node->tag() == "border-color-right") setBorderColorRight(node->value<Color>()); else if(node->tag() == "border-color-bottom") setBorderColorBottom(node->value<Color>()); else if(node->tag() == "border-color-left") setBorderColorLeft(node->value<Color>()); else if(node->tag() == "margin-top") setMarginTop(node->value<int>()); else if(node->tag() == "margin-right") setMarginRight(node->value<int>()); else if(node->tag() == "margin-bottom") setMarginBottom(node->value<int>()); else if(node->tag() == "margin-left") setMarginLeft(node->value<int>()); else if(node->tag() == "margin") { std::string marginDesc = node->value(); std::vector<std::string> split; boost::split(split, marginDesc, boost::is_any_of(std::string(" "))); if(split.size() == 4) { setMarginTop(stdext::safe_cast<int>(split[0])); setMarginRight(stdext::safe_cast<int>(split[1])); setMarginBottom(stdext::safe_cast<int>(split[2])); setMarginLeft(stdext::safe_cast<int>(split[3])); } else if(split.size() == 3) { int marginTop = stdext::safe_cast<int>(split[0]); int marginHorizontal = stdext::safe_cast<int>(split[1]); int marginBottom = stdext::safe_cast<int>(split[2]); setMarginTop(marginTop); setMarginRight(marginHorizontal); setMarginBottom(marginBottom); setMarginLeft(marginHorizontal); } else if(split.size() == 2) { int marginVertical = stdext::safe_cast<int>(split[0]); int marginHorizontal = stdext::safe_cast<int>(split[1]); setMarginTop(marginVertical); setMarginRight(marginHorizontal); setMarginBottom(marginVertical); setMarginLeft(marginHorizontal); } else if(split.size() == 1) { int margin = stdext::safe_cast<int>(split[0]); setMarginTop(margin); setMarginRight(margin); setMarginBottom(margin); setMarginLeft(margin); } } else if(node->tag() == "padding-top") setPaddingTop(node->value<int>()); else if(node->tag() == "padding-right") setPaddingRight(node->value<int>()); else if(node->tag() == "padding-bottom") setPaddingBottom(node->value<int>()); else if(node->tag() == "padding-left") setPaddingLeft(node->value<int>()); else if(node->tag() == "padding") { std::string paddingDesc = node->value(); std::vector<std::string> split; boost::split(split, paddingDesc, boost::is_any_of(std::string(" "))); if(split.size() == 4) { setPaddingTop(stdext::safe_cast<int>(split[0])); setPaddingRight(stdext::safe_cast<int>(split[1])); setPaddingBottom(stdext::safe_cast<int>(split[2])); setPaddingLeft(stdext::safe_cast<int>(split[3])); } else if(split.size() == 3) { int paddingTop = stdext::safe_cast<int>(split[0]); int paddingHorizontal = stdext::safe_cast<int>(split[1]); int paddingBottom = stdext::safe_cast<int>(split[2]); setPaddingTop(paddingTop); setPaddingRight(paddingHorizontal); setPaddingBottom(paddingBottom); setPaddingLeft(paddingHorizontal); } else if(split.size() == 2) { int paddingVertical = stdext::safe_cast<int>(split[0]); int paddingHorizontal = stdext::safe_cast<int>(split[1]); setPaddingTop(paddingVertical); setPaddingRight(paddingHorizontal); setPaddingBottom(paddingVertical); setPaddingLeft(paddingHorizontal); } else if(split.size() == 1) { int padding = stdext::safe_cast<int>(split[0]); setPaddingTop(padding); setPaddingRight(padding); setPaddingBottom(padding); setPaddingLeft(padding); } } // layouts else if(node->tag() == "layout") { std::string layoutType; if(node->hasValue()) layoutType = node->value(); else layoutType = node->valueAt<std::string>("type", ""); if(!layoutType.empty()) { UILayoutPtr layout; if(layoutType == "horizontalBox") layout = UIHorizontalLayoutPtr(new UIHorizontalLayout(asUIWidget())); else if(layoutType == "verticalBox") layout = UIVerticalLayoutPtr(new UIVerticalLayout(asUIWidget())); else if(layoutType == "grid") layout = UIGridLayoutPtr(new UIGridLayout(asUIWidget())); else if(layoutType == "anchor") layout = UIAnchorLayoutPtr(new UIAnchorLayout(asUIWidget())); else throw OTMLException(node, "cannot determine layout type"); setLayout(layout); } if(node->hasChildren()) m_layout->applyStyle(node); } // anchors else if(boost::starts_with(node->tag(), "anchors.")) { UIWidgetPtr parent = getParent(); if(!parent) { if(m_firstOnStyle) throw OTMLException(node, "cannot create anchor, there is no parent widget!"); else continue; } UIAnchorLayoutPtr anchorLayout = parent->getLayout()->asUIAnchorLayout(); if(!anchorLayout) throw OTMLException(node, "cannot create anchor, the parent widget doesn't use anchor layout!"); std::string what = node->tag().substr(8); if(what == "fill") { fill(node->value()); } else if(what == "centerIn") { centerIn(node->value()); } else { Fw::AnchorEdge anchoredEdge = Fw::translateAnchorEdge(what); if(node->value() == "none") { removeAnchor(anchoredEdge); } else { std::vector<std::string> split = stdext::split(node->value(), "."); if(split.size() != 2) throw OTMLException(node, "invalid anchor description"); std::string hookedWidgetId = split[0]; Fw::AnchorEdge hookedEdge = Fw::translateAnchorEdge(split[1]); if(anchoredEdge == Fw::AnchorNone) throw OTMLException(node, "invalid anchor edge"); if(hookedEdge == Fw::AnchorNone) throw OTMLException(node, "invalid anchor target edge"); addAnchor(anchoredEdge, hookedWidgetId, hookedEdge); } } // lua functions } else if(boost::starts_with(node->tag(), "@")) { // load once if(m_firstOnStyle) { std::string funcName = node->tag().substr(1); std::string funcOrigin = "@" + node->source() + "[" + node->tag() + "]"; g_lua.loadFunction(node->value(), funcOrigin); luaSetField(funcName); } // lua fields value } else if(boost::starts_with(node->tag(), "&")) { std::string fieldName = node->tag().substr(1); std::string fieldOrigin = "@" + node->source() + "[" + node->tag() + "]"; g_lua.evaluateExpression(node->value(), fieldOrigin); luaSetField(fieldName); } } }
bool SkinSogou::loadSkin(const QString skinPath) { init(); QFile sogouSkinConfFile(skinPath + "skin.ini"); if (!sogouSkinConfFile.exists()) return false; if (!sogouSkinConfFile.open(QIODevice::ReadOnly)) return false; QString line; QString key, value; /// parse ini file content bool general = false; bool display = false; bool scheme_h1 = false; bool scheme_v1 = false; bool statusbar = false; int h_pt, h_pb, h_pl, h_pr; int v_pt, v_pb, v_pl, v_pr; unsigned int pinyin_color, zhongwen_color, zhongwen_first_color, comphint_color; int fontPixelSize = 12; setAdjustWidth(10); setAdjustHeight(30); setHorizontalTileMode("Stretch"); setVerticalTileMode("Stretch"); setInputStringPosX(0); setInputStringPosY(0); setOutputCandPosX(0); setOutputCandPosY(0); QTextStream textStream(sogouSkinConfFile.readAll()); do { line = textStream.readLine(); if (line.isEmpty() || line.at(0) == '#') continue; if (line.at(0) == '[') { general = (line == "[General]"); display = (line == "[Display]"); scheme_h1 = (line == "[Scheme_H1]"); scheme_v1 = (line == "[Scheme_V1]"); statusbar = (line == "[StatusBar]"); continue; } if (!line.contains('=')) continue; key = line.split('=').at(0); value = line.split('=').at(1); if (value.isEmpty()) continue; if (display) { if (key == "font_size") setFontSize(value.toInt()); else if (key == "pinyin_color"){ pinyin_color = value.toUInt(0, 0); setInputColor(QColor(qBlue(pinyin_color), qGreen(pinyin_color), qRed(pinyin_color))); } else if (key == "zhongwen_color"){ zhongwen_color = value.toUInt(0, 0); setOtherColor(QColor(qBlue(zhongwen_color), qGreen(zhongwen_color), qRed(zhongwen_color))); } else if (key == "zhongwen_first_color"){ zhongwen_first_color = value.toUInt(0, 0); setFirstCandColor(QColor(qBlue(zhongwen_first_color), qGreen(zhongwen_first_color), qRed(zhongwen_first_color))); } else if (key == "comphint_color"){ //FIXME //comphint_color = value.toUInt(0, 0); } }else if (scheme_h1) { if (key == "pic" && MainModel::self()->isHorizontal()) { setInputBackImg("file:/" + skinPath + value); } else if (key == "pinyin_marge") { QStringList list = value.split(','); h_pt = list.at(0).trimmed().toInt(); h_pb = list.at(1).trimmed().toInt(); h_pl = list.at(2).trimmed().toInt(); h_pr = list.at(3).trimmed().toInt(); if (MainModel::self()->isHorizontal()){ setMarginTop(h_pt); setMarginBottom(h_pb); setMarginLeft(h_pl); setMarginRight(h_pr); } } else if (key == "custom0_align") { //todo } else if (key == "custom0") { mCustomImgH1[0] = value; setCustomImg0 ("file:/" + skinPath + value); } else if (key == "custom1") { mCustomImgH1[1] = value; setCustomImg1 ("file:/" + skinPath + value); } else if (key == "custom_cnt") { mCustomCntH1 = value.toInt(); } }else if (scheme_v1) { if (key == "pic" && !MainModel::self()->isHorizontal()) { setInputBackImg("file:/" + skinPath + value); } else if (key == "pinyin_marge") { QStringList list = value.split(','); v_pt = list.at(0).trimmed().toInt(); v_pb = list.at(1).trimmed().toInt(); v_pl = list.at(2).trimmed().toInt(); v_pr = list.at(3).trimmed().toInt(); if (!MainModel::self()->isHorizontal()){ setMarginTop(v_pt); setMarginBottom(v_pb); setMarginLeft(v_pl); setMarginRight(v_pr); } } else if (key == "custom0") { mCustomImgV1[0] = value; //qDebug() << "cuystom0 " << value; //setCustomImg0(value); } else if (key == "custom1") { mCustomImgV1[1] = value; qDebug() << "cuystom1 " << value; //setCustomImg1(value); } else if (key == "custom_cnt") { mCustomCntV1 = value.toInt(); //qDebug() << "cuystom_cnt " << mCustomCntV1; } } else if (statusbar) { if (key == "pic") { //FIXME //setTipsImg("file:/" + skinPath + value); } } } while (!line.isNull()); sogouSkinConfFile.close(); return true; }