W32Widget::Size W32HBox::minimumSize() const { if (myElements.empty()) { return Size(leftMargin() + rightMargin(), topMargin() + bottomMargin()); } Size size; int elementCounter = 0; for (W32WidgetList::const_iterator it = myElements.begin(); it != myElements.end(); ++it) { if ((*it)->isVisible()) { Size elementSize = (*it)->minimumSize(); if (homogeneous()) { size.Width = std::max(size.Width, elementSize.Width); } else { size.Width += elementSize.Width; } size.Height = std::max(size.Height, elementSize.Height); ++elementCounter; } } if (homogeneous()) { size.Width *= elementCounter; } size.Width += leftMargin() + rightMargin() + spacing() * (elementCounter - 1); size.Height += topMargin() + bottomMargin(); return size; }
void W32HBox::setPosition(int x, int y, Size size) { int elementCounter = visibleElementsNumber(); if (elementCounter == 0) { return; } x += leftMargin(); y += topMargin(); if (homogeneous()) { Size elementSize(0, size.Height - topMargin() - bottomMargin()); for (W32WidgetList::const_iterator it = myElements.begin(); it != myElements.end(); ++it) { if ((*it)->isVisible()) { Size currentSize = (*it)->minimumSize(); elementSize.Width = std::max(currentSize.Width, elementSize.Width); } } if (myAlignment != LEFT) { const short extraWidth = size.Width - leftMargin() - rightMargin() - elementSize.Width * elementCounter - spacing() * (elementCounter - 1); if (myAlignment == CENTER) { x += extraWidth / 2; } else if (myAlignment == RIGHT) { x += extraWidth; } else if (myAlignment == FILL) { elementSize.Width += extraWidth / elementCounter; } } const short deltaX = elementSize.Width + spacing(); for (W32WidgetList::const_iterator it = myElements.begin(); it != myElements.end(); ++it) { if ((*it)->isVisible()) { (*it)->setPosition(x, y, elementSize); x += deltaX; } } } else { if (myAlignment != LEFT) { short extraWidth = size.Width - leftMargin() - rightMargin() - spacing() * (elementCounter - 1); for (W32WidgetList::const_iterator it = myElements.begin(); it != myElements.end(); ++it) { if ((*it)->isVisible()) { Size currentSize = (*it)->minimumSize(); extraWidth -= currentSize.Width; } } if (myAlignment == CENTER) { x += extraWidth / 2; } else if (myAlignment == RIGHT) { x += extraWidth; } } const int elementHeight = size.Height - topMargin() - bottomMargin(); Size elementSize; for (W32WidgetList::const_iterator it = myElements.begin(); it != myElements.end(); ++it) { if ((*it)->isVisible()) { Size elementSize = (*it)->minimumSize(); elementSize.Height = elementHeight; (*it)->setPosition(x, y, elementSize); x += elementSize.Width + spacing(); } } } }
void W32VBox::setPosition(int x, int y, Size size) { int elementCounter = visibleElementsNumber(); if (elementCounter == 0) { return; } x += leftMargin(); y += topMargin(); if (homogeneous()) { const Size elementSize( size.Width - leftMargin() - rightMargin(), (size.Height - topMargin() - bottomMargin() - spacing() * (elementCounter - 1)) / elementCounter ); const short deltaY = elementSize.Height + spacing(); for (W32WidgetList::const_iterator it = myElements.begin(); it != myElements.end(); ++it) { if ((*it)->isVisible()) { (*it)->setPosition(x, y, elementSize); y += deltaY; } } } else { const short elementWidth = size.Width - leftMargin() - rightMargin(); for (W32WidgetList::const_iterator it = myElements.begin(); it != myElements.end(); ++it) { if ((*it)->isVisible()) { Size elementSize = (*it)->minimumSize(); elementSize.Width = elementWidth; (*it)->setPosition(x, y, elementSize); y += elementSize.Height + spacing(); } } } }
W32Widget::Size W32VBorderBox::minimumSize() const { Size size; int counter = 0; if (!myTopElement.isNull() && myTopElement->isVisible()) { ++counter; Size elementSize = myTopElement->minimumSize(); size.Height += elementSize.Height; size.Width = std::max(size.Width, elementSize.Width); } if (!myCenterElement.isNull() && myCenterElement->isVisible()) { ++counter; Size elementSize = myCenterElement->minimumSize(); size.Height += elementSize.Height; size.Width = std::max(size.Width, elementSize.Width); } if (!myBottomElement.isNull() && myBottomElement->isVisible()) { ++counter; Size elementSize = myBottomElement->minimumSize(); size.Height += elementSize.Height; size.Width = std::max(size.Width, elementSize.Width); } if (counter > 0) { size.Height += (counter - 1) * mySpacing; } size.Width += leftMargin() + rightMargin(); size.Height += topMargin() + bottomMargin(); return size; }
void PageTemplate::write(QXmlStreamWriter *xml) { QLocale locale; QString thisLanguage = locale.name().split('_').at(0); xml->writeStartElement("page-template"); xml->writeAttribute("name",name()); if( !isHalfOf().isEmpty() ) xml->writeAttribute("is-half-of",isHalfOf()); xml->writeStartElement("long-name"); xml->writeAttribute("lang",thisLanguage); xml->writeCharacters(longName()); xml->writeEndElement(); // long-name for(int i=0; i<aOtherLongNames.count(); i++) { xml->writeStartElement("long-name"); xml->writeAttribute("lang",aOtherLongNames.at(i).lang); xml->writeCharacters(aOtherLongNames.at(i).string); xml->writeEndElement(); // long-name } xml->writeTextElement("width",QString::number(width())); xml->writeTextElement("height",QString::number(height())); xml->writeTextElement("header",QString::number(header())); xml->writeTextElement("footer",QString::number(footer())); xml->writeStartElement("margins"); xml->writeAttribute("side","right"); xml->writeTextElement("left-margin",QString::number(leftMargin(Book::Right))); xml->writeTextElement("right-margin",QString::number(rightMargin(Book::Right))); xml->writeTextElement("top-margin",QString::number(topMargin(Book::Right))); xml->writeTextElement("bottom-margin",QString::number(bottomMargin(Book::Right))); xml->writeEndElement(); // margins xml->writeStartElement("margins"); xml->writeAttribute("side","left"); xml->writeTextElement("left-margin",QString::number(leftMargin(Book::Left))); xml->writeTextElement("right-margin",QString::number(rightMargin(Book::Left))); xml->writeTextElement("top-margin",QString::number(topMargin(Book::Left))); xml->writeTextElement("bottom-margin",QString::number(bottomMargin(Book::Left))); xml->writeEndElement(); // margins xml->writeEndElement(); // page-template }
void hist_impl::render(const void* pWnd, int pX, int pY, int pVPW, int pVPH) { float w = float(pVPW - (leftMargin()+rightMargin()+tickSize())); float h = float(pVPH - (bottomMargin()+topMargin()+tickSize())); float offset_x = (2.0f * (leftMargin()+tickSize()) + (w - pVPW)) / pVPW; float offset_y = (2.0f * (bottomMargin()+tickSize()) + (h - pVPH)) / pVPH; float scale_x = w / pVPW; float scale_y = h / pVPH; CheckGL("Begin Histogram::render"); /* Enavle scissor test to discard anything drawn beyond viewport. * Set scissor rectangle to clip fragments outside of viewport */ glScissor(pX+leftMargin()+tickSize(), pY+bottomMargin()+tickSize(), pVPW - (leftMargin()+rightMargin()+tickSize()), pVPH - (bottomMargin()+topMargin()+tickSize())); glEnable(GL_SCISSOR_TEST); glm::mat4 trans = glm::translate(glm::scale(glm::mat4(1), glm::vec3(scale_x, scale_y, 1)), glm::vec3(offset_x, offset_y, 0)); glUseProgram(mHistBarProgram); glUniformMatrix4fv(mHistBarMatIndex, 1, GL_FALSE, glm::value_ptr(trans)); glUniform4fv(mHistBarColorIndex, 1, mBarColor); glUniform1f(mHistBarNBinsIndex, (GLfloat)mNBins); glUniform1f(mHistBarYMaxIndex, ymax()); /* render a rectangle for each bin. Same * rectangle is scaled and translated accordingly * for each bin. This is done by OpenGL feature of * instanced rendering */ bindResources(pWnd); glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, mNBins); unbindResources(); glUseProgram(0); /* Stop clipping */ glDisable(GL_SCISSOR_TEST); renderChart(pWnd, pX, pY, pVPW, pVPH); CheckGL("End Histogram::render"); }
QRect QCommandLinkButtonPrivate::titleRect() const { Q_Q(const QCommandLinkButton); QRect r = q->rect().adjusted(textOffset(), topMargin(), -rightMargin(), 0); if (description.isEmpty()) { QFontMetrics fm(titleFont()); r.setTop(r.top() + qMax(0, (q->icon().actualSize(q->iconSize()).height() - fm.height()) / 2)); } return r; }
void ZLTextView::paint() { context().clear(backgroundColor()); myTextAreaController.area().setOffsets( textArea().isRtl() ? rightMargin() : leftMargin(), topMargin() + headerHeight() ); preparePaintInfo(); if (textArea().isEmpty()) { return; } myTextAreaController.area().paint(); shared_ptr<ZLTextPositionIndicatorInfo> indicatorInfo = this->indicatorInfo(); if (!indicatorInfo.isNull()) { switch (indicatorInfo->type()) { default: break; case ZLTextPositionIndicatorInfo::PAGE_FOOTER: positionIndicator()->draw(); break; case ZLTextPositionIndicatorInfo::PAGE_HEADER: paintHeader(); break; } } if (myDoUpdateScrollbar && !indicatorInfo.isNull()) { myDoUpdateScrollbar = false; const std::size_t full = sizeOfTextBeforeParagraph(endTextIndex()); const std::size_t from = sizeOfTextBeforeCursor(textArea().startCursor()); const std::size_t to = sizeOfTextBeforeCursor(textArea().endCursor()); bool showScrollbar = (indicatorInfo->type() == ZLTextPositionIndicatorInfo::OS_SCROLLBAR) && (to - from < full); if (showScrollbar) { setScrollbarEnabled(VERTICAL, true); setScrollbarParameters(VERTICAL, full, from, to); } else { setScrollbarEnabled(VERTICAL, false); } } ZLTextParagraphCursorCache::cleanup(); }
int LineEditExtension::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 1) qt_static_metacall(this, _c, _id, _a); _id -= 1; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< int*>(_v) = leftMargin(); break; case 1: *reinterpret_cast< int*>(_v) = rightMargin(); break; case 2: *reinterpret_cast< int*>(_v) = topMargin(); break; case 3: *reinterpret_cast< int*>(_v) = bottomMargin(); break; } _id -= 4; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setLeftMargin(*reinterpret_cast< int*>(_v)); break; case 1: setRightMargin(*reinterpret_cast< int*>(_v)); break; case 2: setTopMargin(*reinterpret_cast< int*>(_v)); break; case 3: setBottomMargin(*reinterpret_cast< int*>(_v)); break; } _id -= 4; } else if (_c == QMetaObject::ResetProperty) { _id -= 4; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 4; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 4; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 4; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 4; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 4; } #endif // QT_NO_PROPERTIES return _id; }
void ZLTextView::preparePaintInfo() { size_t newWidth = std::max(context().width() - leftMargin() - rightMargin(), 1); int viewHeight = context().height() - topMargin() - bottomMargin(); shared_ptr<ZLTextPositionIndicatorInfo> indicatorInfo = this->indicatorInfo(); if (!indicatorInfo.isNull() && (indicatorInfo->type() == ZLTextPositionIndicatorInfo::FB_INDICATOR)) { viewHeight -= indicatorInfo->height() + indicatorInfo->offset(); } size_t newHeight = std::max(viewHeight, 1); AppLog("newWidth %d newHeight=%d",newWidth,newHeight); if (newWidth != myTextAreaController.area().width() || newHeight != myTextAreaController.area().height()) { myTextAreaController.area().setSize(newWidth, newHeight); myTextAreaController.rebuildPaintInfo(false); } if (myTextAreaController.preparePaintInfo()) { myDoUpdateScrollbar = true; } }
void BookTextView::paintHeader() const { const int unit = baseStyle()->fontSize() / 4; const int left = leftMargin(); const int right = context().width() - rightMargin() - 1; const int bottom = topMargin() + unit * 4; context().setColor(color(ZLTextStyle::REGULAR_TEXT)); context().setFont(baseStyle()->fontFamily(), unit * 3, false, true); context().drawLine(left, bottom, right, bottom); // TODO: use chapter name instead const std::string leftText = myBook->title(); context().drawString(left, bottom - unit, leftText.c_str(), leftText.length(), false); std::string rightText; ZLStringUtil::appendNumber(rightText, 1 + sizeOfTextBeforeCursor(textArea().endCursor()) / 2048); rightText += '/'; ZLStringUtil::appendNumber(rightText, 1 + sizeOfTextBeforeParagraph(endTextIndex()) / 2048); const std::size_t rightTextWidth = context().stringWidth(rightText.c_str(), rightText.length(), false); context().drawString(right - rightTextWidth, bottom - unit, rightText.c_str(), rightText.length(), false); }
// Calculates the height of the description text based on widget width int QCommandLinkButtonPrivate::descriptionHeight(int widgetWidth) const { // Calc width of actual paragraph int lineWidth = widgetWidth - textOffset() - rightMargin(); qreal descriptionheight = 0; if (!description.isEmpty()) { QTextLayout layout(description); layout.setFont(descriptionFont()); layout.beginLayout(); while (true) { QTextLine line = layout.createLine(); if (!line.isValid()) break; line.setLineWidth(lineWidth); line.setPosition(QPointF(0, descriptionheight)); descriptionheight += line.height(); } layout.endLayout(); } return qRound(descriptionheight); }
void KoSectionStyle::saveOdf(KoGenStyle &style) { // only custom style have a displayname. automatic styles don't have a name set. if (!d->name.isEmpty() && !style.isDefaultStyle()) { style.addAttribute("style:display-name", d->name); } QList<int> keys = d->stylesPrivate.keys(); foreach(int key, keys) { if (key == KoSectionStyle::TextProgressionDirection) { int directionValue = 0; bool ok = false; directionValue = d->stylesPrivate.value(key).toInt(&ok); if (ok) { QString direction; if (directionValue == KoText::LeftRightTopBottom) direction = "lr-tb"; else if (directionValue == KoText::RightLeftTopBottom) direction = "rl-tb"; else if (directionValue == KoText::TopBottomRightLeft) direction = "tb-lr"; else if (directionValue == KoText::InheritDirection) direction = "page"; if (!direction.isEmpty()) style.addProperty("style:writing-mode", direction, KoGenStyle::DefaultType); } } else if (key == QTextFormat::BackgroundBrush) { QBrush backBrush = background(); if (backBrush.style() != Qt::NoBrush) style.addProperty("fo:background-color", backBrush.color().name(), KoGenStyle::ParagraphType); else style.addProperty("fo:background-color", "transparent", KoGenStyle::DefaultType); } else if (key == QTextFormat::BlockLeftMargin) { style.addPropertyPt("fo:margin-left", leftMargin(), KoGenStyle::DefaultType); } else if (key == QTextFormat::BlockRightMargin) { style.addPropertyPt("fo:margin-right", rightMargin(), KoGenStyle::DefaultType); } } }
void W32VBorderBox::setPosition(int x, int y, Size size) { const short elementX = x + leftMargin(); const short elementWidth = size.Width - leftMargin() - rightMargin(); short centerElementX = elementX; short centerElementY = y + topMargin(); short centerElementHeight = size.Height - topMargin() - bottomMargin(); if (!myTopElement.isNull() && myTopElement->isVisible()) { Size topElementSize = myTopElement->minimumSize(); myTopElement->setPosition(elementX, centerElementY, Size(elementWidth, topElementSize.Height)); centerElementY += topElementSize.Height + mySpacing; centerElementHeight -= topElementSize.Height + mySpacing; } if (!myBottomElement.isNull() && myBottomElement->isVisible()) { Size bottomElementSize = myBottomElement->minimumSize(); myBottomElement->setPosition(elementX, y + size.Height - bottomMargin() - bottomElementSize.Height, Size(elementWidth, bottomElementSize.Height)); centerElementHeight -= bottomElementSize.Height + mySpacing; } if (!myCenterElement.isNull() && myCenterElement->isVisible()) { myCenterElement->setPosition(centerElementX, centerElementY, Size(elementWidth, centerElementHeight)); } }
W32Widget::Size W32Table::minimumSize() const { std::vector<short> widths, heights; calculateSizes(widths, heights); Size size( leftMargin() + rightMargin() + myHorizontalSpacing * (widths.size() - 1), topMargin() + bottomMargin() ); for (std::vector<short>::const_iterator it = widths.begin(); it != widths.end(); ++it) { size.Width += *it; } int hCount = 0; for (std::vector<short>::const_iterator it = heights.begin(); it != heights.end(); ++it) { if (*it > 0) { size.Height += *it; ++hCount; } } if (hCount > 1) { size.Height += myVerticalSpacing * (hCount - 1); } return size; }
QRect QCommandLinkButtonPrivate::descriptionRect() const { Q_Q(const QCommandLinkButton); return q->rect().adjusted(textOffset(), descriptionOffset(), -rightMargin(), -bottomMargin()); }
QRect QCommandLinkButtonPrivate::titleRect() const { Q_Q(const QCommandLinkButton); return q->rect().adjusted(textOffset(), topMargin(), -rightMargin(), 0); }
int GtkPaintContext::width() const { if (myPixmap == NULL) { return 0; } return myWidth - leftMargin() - rightMargin(); }
void W32Table::setPosition(int x, int y, Size size) { std::vector<short> widths, heights, lefts, rights; calculateSizes(widths, heights); if ((widths.size() == 0) || (heights.size() == 0)) { return; } Size minSize( leftMargin() + rightMargin() + myHorizontalSpacing * (widths.size() - 1), topMargin() + bottomMargin() ); for (std::vector<short>::const_iterator it = widths.begin(); it != widths.end(); ++it) { minSize.Width += *it; } int hCount = 0; for (std::vector<short>::const_iterator it = heights.begin(); it != heights.end(); ++it) { if (*it > 0) { minSize.Height += *it; ++hCount; } } if (hCount == 0) { return; } minSize.Height += myVerticalSpacing * (hCount - 1); { short delta = size.Width - minSize.Width; int len = widths.size(); lefts.reserve(len); rights.reserve(len); short currentX = x + leftMargin(); for (int i = 0; i < len; ++i) { short d = delta / (len - i); widths[i] += d; delta -= d; lefts.push_back(currentX); currentX += widths[i]; rights.push_back(currentX); currentX += myHorizontalSpacing; } } { short delta = size.Height - minSize.Height; int len = hCount; for (std::vector<short>::iterator it = heights.begin(); len > 0; ++it) { if (*it > 0) { short d = delta / len; *it += d; delta -= d; --len; } } } int ey = y + topMargin(); for (std::vector<RowList>::const_iterator it = myRows.begin(); it != myRows.end(); ++it) { short h = heights[it - myRows.begin()]; if (h > 0) { for (RowList::const_iterator jt = it->begin(); jt != it->end(); ++jt) { if (jt->Widget->isVisible()) { jt->Widget->setPosition(lefts[jt->XFrom], ey, Size(rights[jt->XTo] - lefts[jt->XFrom], h)); } } ey += h + myVerticalSpacing; } } }