本文整理汇总了C++中QRectF::center方法的典型用法代码示例。如果您正苦于以下问题:C++ QRectF::center方法的具体用法?C++ QRectF::center怎么用?C++ QRectF::center使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QRectF
的用法示例。
在下文中一共展示了QRectF::center方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: render
/*!
\brief Replay all recorded painter commands
The graphic is scaled to fit into the given rectangle
\param painter Qt painter
\param rect Rectangle for the scaled graphic
\param aspectRatioMode Mode how to scale - See Qt::AspectRatioMode
*/
void QwtGraphic::render( QPainter *painter, const QRectF &rect,
Qt::AspectRatioMode aspectRatioMode ) const
{
if ( isEmpty() || rect.isEmpty() )
return;
double sx = 1.0;
double sy = 1.0;
if ( d_data->pointRect.width() > 0.0 )
sx = rect.width() / d_data->pointRect.width();
if ( d_data->pointRect.height() > 0.0 )
sy = rect.height() / d_data->pointRect.height();
const bool scalePens =
!d_data->renderHints.testFlag( RenderPensUnscaled );
for ( int i = 0; i < d_data->pathInfos.size(); i++ )
{
const PathInfo info = d_data->pathInfos[i];
const double ssx = info.scaleFactorX(
d_data->pointRect, rect, scalePens );
if ( ssx > 0.0 )
sx = qMin( sx, ssx );
const double ssy = info.scaleFactorY(
d_data->pointRect, rect, scalePens );
if ( ssy > 0.0 )
sy = qMin( sy, ssy );
}
if ( aspectRatioMode == Qt::KeepAspectRatio )
{
const double s = qMin( sx, sy );
sx = s;
sy = s;
}
else if ( aspectRatioMode == Qt::KeepAspectRatioByExpanding )
{
const double s = qMax( sx, sy );
sx = s;
sy = s;
}
QTransform tr;
tr.translate( rect.center().x() - 0.5 * sx * d_data->pointRect.width(),
rect.center().y() - 0.5 * sy * d_data->pointRect.height() );
tr.scale( sx, sy );
tr.translate( -d_data->pointRect.x(), -d_data->pointRect.y() );
const QTransform transform = painter->transform();
painter->setTransform( tr, true );
render( painter );
painter->setTransform( transform );
}
示例2: paint
void ChooseGeneralBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) {
//============================================================
//||========================================================||
//|| 萩僉夲�揖米薦議冷繍 ||
//|| ______ ______ ______ ______ ______ ||
//|| | | | | | | | | | | ||
//|| | g1 | | g2 | | g3 | | g4 | | g5 | ||
//|| | | | | | | | | | | ||
//|| !!!!!! !!!!!! !!!!!! !!!!!! !!!!!! ||
//|| ______ ______ ______ ______ ||
//|| | | | | | | | | ||
//|| | g6 | | g7 | | g8 | | g9 | ||
//|| | | | | | | | | ||
//|| !!!!!! !!!!!! !!!!!! !!!!!! ||
//|| ---------------------------------------------- ||
//|| \/ ||
//|| ______ ______ ||
//|| | | | | ||
//|| | hg | | dg | ||
//|| | | | | ||
//|| !!!!!! !!!!!! ||
//|| __________ ||
//|| | 鳩協 | ||
//|| !!!!!!!!!! ||
//|| ========================= ||
//|| ||
//============================================================
//
//
//==================================================
//|| 岑失岑泳鉱心麼繍 ||
//||==============================================||
//|| ||
//|| __________________ ||
//|| | | ||
//|| | | ||
//|| | | ||
//|| | | ||
//|| | | ||
//|| | | ||
//|| | | ||
//|| | | ||
//|| | | ||
//|| | | ||
//|| !!!!!!!!!!!!!!!!!! ||
//|| ||
//|| ================== ||
//|| || confirm || ||
//|| ================== ||
//|| ||
//==================================================
painter->save();
painter->setBrush(QBrush(G_COMMON_LAYOUT.m_chooseGeneralBoxBackgroundColor));
QRectF rect = boundingRect();
const int x = rect.x();
const int y = rect.y();
const int w = rect.width();
const int h = rect.height();
painter->drawRect(QRect(x, y, w, h));
painter->drawRect(QRect(x, y, w, top_dark_bar));
G_COMMON_LAYOUT.m_chooseGeneralBoxTitleFont.paintText(painter, QRect(x, y, w, top_dark_bar), Qt::AlignCenter, single_result ? tr("Please select one general") : tr("Please select the same nationality generals"));
painter->restore();
painter->setPen(G_COMMON_LAYOUT.m_chooseGeneralBoxBorderColor);
painter->drawRect(QRect(x + 1, y + 1, w - 2, h - 2));
if (single_result) return;
int split_line_y = top_blank_width + G_COMMON_LAYOUT.m_cardNormalHeight + card_bottom_to_split_line;
if (general_number > 5)
split_line_y += (card_to_center_line + G_COMMON_LAYOUT.m_cardNormalHeight);
QPixmap line = G_ROOM_SKIN.getPixmap(QSanRoomSkin::S_SKIN_KEY_CHOOSE_GENERAL_BOX_SPLIT_LINE);
const int line_length = boundingRect().width() - 2 * left_blank_width;
painter->drawPixmap(left_blank_width, split_line_y, line, (line.width() - line_length) / 2, y, line_length, line.height());
QPixmap seat = G_ROOM_SKIN.getPixmap(QSanRoomSkin::S_SKIN_KEY_CHOOSE_GENERAL_BOX_DEST_SEAT);
QRect seat1_rect(rect.center().x() - G_COMMON_LAYOUT.m_cardNormalWidth - card_to_center_line - 2, split_line_y + split_line_to_card_seat - 2, G_COMMON_LAYOUT.m_cardNormalWidth + 4, G_COMMON_LAYOUT.m_cardNormalHeight + 4);
painter->drawPixmap(seat1_rect, seat);
IQSanComponentSkin::QSanSimpleTextFont font = G_COMMON_LAYOUT.m_chooseGeneralBoxDestSeatFont;
font.paintText(painter, seat1_rect, Qt::AlignCenter, tr("head_general"));
QRect seat2_rect(rect.center().x() + card_to_center_line - 2, split_line_y + split_line_to_card_seat - 2, G_COMMON_LAYOUT.m_cardNormalWidth + 4, G_COMMON_LAYOUT.m_cardNormalHeight + 4);
painter->drawPixmap(seat2_rect, seat);
font.paintText(painter, seat2_rect, Qt::AlignCenter, tr("deputy_general"));
}
示例3: painter
QPainterPath linePath;
linePath.addText(0, linePos, font(), line);
linePos += lineSpacing;
if ( m_alignment == Qt::AlignHCenter ) {
double offset = (bounding.width() - metrics.width(line)) / 2;
linePath.translate(offset, 0);
} else if ( m_alignment == Qt::AlignRight ) {
double offset = (bounding.width() - metrics.width(line));
linePath.translate(offset, 0);
}
path.addPath(linePath);
}
// Calculate position of text in parent item
QRectF pathRect = QRectF(0, 0, bounding.width(), linePos - lineSpacing + metrics.descent() );
QPointF offset = bounding.center() - pathRect.center() + QPointF(2 * m_shadowBlur, 2 * m_shadowBlur);
path.translate(offset);
QRectF fullSize = bounding.united(path.boundingRect());
m_shadow = QImage(fullSize.width() + qAbs(m_shadowOffset.x()) + 4 * m_shadowBlur, fullSize.height() + qAbs(m_shadowOffset.y()) + 4 * m_shadowBlur, QImage::Format_ARGB32_Premultiplied);
m_shadow.fill(Qt::transparent);
QPainter painter(&m_shadow);
painter.fillPath(path, QBrush(m_shadowColor));
painter.end();
if (m_shadowBlur > 0) {
blurShadow(m_shadow, m_shadowBlur);
}
}
void MyTextItem::blurShadow(QImage &result, int radius)
{
int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
示例4: paintPosterOnCanvasOverlapped
void PosteRazorCore::paintPosterOnCanvasOverlapped(PaintCanvasInterface *paintCanvas) const
{
const QSizeF canvasSize = paintCanvas->size();
QSizeF pagePrintableAreaSize = printablePaperAreaSize();
const QSizeF posterSizePages = posterSize(Types::PosterSizeModePages);
const int pagesHorizontal = (int)ceil(posterSizePages.width());
const int pagesVertical = (int)ceil(posterSizePages.height());
const QSizeF posterSize(
pagesHorizontal*pagePrintableAreaSize.width() - (pagesHorizontal-1)*overlappingWidth() + paperBorderLeft() + paperBorderRight(),
pagesVertical*pagePrintableAreaSize.height() - (pagesVertical-1)*overlappingHeight() + paperBorderTop() + paperBorderBottom()
);
const QSizeF boxSize = previewSize(posterSize, canvasSize.toSize(), true);
const QPointF offset((canvasSize.width() - boxSize.width()) / 2, (canvasSize.height() - boxSize.height()) / 2);
const qreal UnitOfLengthToPixelfactor = boxSize.width()/posterSize.width();
const qreal borderTop = paperBorderTop() * UnitOfLengthToPixelfactor;
const qreal borderRight = paperBorderRight() * UnitOfLengthToPixelfactor;
const qreal borderBottom = paperBorderBottom() * UnitOfLengthToPixelfactor;
const qreal borderLeft = paperBorderLeft() * UnitOfLengthToPixelfactor;
const QSizeF posterPrintableAreaSize(boxSize.width() - borderLeft - borderRight, boxSize.height() - borderTop - borderBottom);
const QPointF posterPrintableAreaOrigin = QPointF(borderLeft, borderTop) + offset;
const QRectF posterPrintableArea(posterPrintableAreaOrigin, posterPrintableAreaSize);
paintCanvas->drawFilledRect(QRectF(offset, boxSize), QColor(128, 128, 128));
paintCanvas->drawFilledRect(posterPrintableArea, QColor(230, 230, 230));
const QSizeF posterSizeAbsolute = this->posterSize(Types::PosterSizeModeAbsolute);
const QSizeF imageSize = posterSizeAbsolute * UnitOfLengthToPixelfactor;
const Qt::Alignment alignment = posterAlignment();
paintCanvas->drawImage(
QRectF(
QPointF(
(
alignment & Qt::AlignLeft?borderLeft
:alignment & Qt::AlignHCenter?qBound(borderLeft, (boxSize.width() - imageSize.width()) / 2, borderLeft + posterPrintableAreaSize.width() - imageSize.width())
:(borderLeft + posterPrintableAreaSize.width() - imageSize.width())
) + offset.x(),
(
alignment & Qt::AlignTop?borderTop
:alignment & Qt::AlignVCenter?qBound(borderTop, (boxSize.height() - imageSize.height()) / 2, borderTop + posterPrintableAreaSize.height() - imageSize.height())
:(borderTop + posterPrintableAreaSize.height() - imageSize.height())
) + offset.y()
),
imageSize
)
);
const qreal overlappingHeight = this->overlappingHeight() * UnitOfLengthToPixelfactor;
const qreal overlappingWidth = this->overlappingWidth() * UnitOfLengthToPixelfactor;
pagePrintableAreaSize *= UnitOfLengthToPixelfactor;
const QColor overlappingColor(255, 128, 128, 128);
qreal overlappingRectangleYPosition = borderTop;
for (int pagesRow = 0; pagesRow < pagesVertical - 1; pagesRow++) {
overlappingRectangleYPosition += pagePrintableAreaSize.height() - overlappingHeight;
paintCanvas->drawFilledRect(QRectF(QPointF(0, overlappingRectangleYPosition) + offset, QSizeF(boxSize.width(), overlappingHeight)), overlappingColor);
}
qreal overlappingRectangleXPosition = borderLeft;
for (int pagesColumn = 0; pagesColumn < pagesHorizontal - 1; pagesColumn++) {
overlappingRectangleXPosition += pagePrintableAreaSize.width() - overlappingWidth;
paintCanvas->drawFilledRect(QRectF(QPointF(overlappingRectangleXPosition, 0) + offset, QSizeF(overlappingWidth, boxSize.height())), overlappingColor);
}
const int fontSize = int(qMin(pagePrintableAreaSize.width() / 2.5, pagePrintableAreaSize.height() / 1.5));
for (int pagesRow = 0; pagesRow < pagesVertical; ++pagesRow) {
for (int pagesColumn = 0; pagesColumn < pagesHorizontal; ++pagesColumn) {
const QPointF pagePrintableAreaOrigin = posterPrintableAreaOrigin + QPointF(
pagesColumn * (pagePrintableAreaSize.width() - overlappingWidth),
pagesRow * (pagePrintableAreaSize.height() - overlappingHeight)
);
const QRectF pageNumberArea = QRectF(pagePrintableAreaOrigin, pagePrintableAreaSize).adjusted(
pagesColumn == 0 ? 0 : overlappingWidth,
pagesRow == 0 ? 0 : overlappingHeight,
pagesColumn == pagesHorizontal - 1 ? 0 : -overlappingWidth,
pagesRow == pagesVertical - 1 ? 0 : -overlappingHeight
);
const int pageNumber = pagesRow * pagesHorizontal + pagesColumn + 1;
paintCanvas->drawOverlayText(pageNumberArea.center(), Qt::AlignCenter, fontSize, QString::number(pageNumber));
}
}
}
示例5: paintLayout
void ChooseGeneralBox::paintLayout(QPainter *painter) {
//============================================================
//||========================================================||
//|| Please select the same nationality generals ||
//|| ______ ______ ______ ______ ______ ||
//|| | | | | | | | | | | ||
//|| | g1 | | g2 | | g3 | | g4 | | g5 | ||
//|| | | | | | | | | | | ||
//|| ------ ------ ------ ------ ------ ||
//|| ______ ______ ______ ______ ||
//|| | | | | | | | | ||
//|| | g6 | | g7 | | g8 | | g9 | ||
//|| | | | | | | | | ||
//|| ------ ------ ------ ------ ||
//|| ---------------------------------------------- ||
//|| \/ ||
//|| ______ ______ ||
//|| | | | | ||
//|| | hg | | dg | ||
//|| | | | | ||
//|| ------ ------ ||
//|| __________ ||
//|| | fight | ||
//|| ---------- ||
//|| ========================= ||
//|| ||
//============================================================
//
//
//==================================================
//|| KnownBoth View Head ||
//||==============================================||
//|| ||
//|| __________________ ||
//|| | | ||
//|| | | ||
//|| | | ||
//|| | | ||
//|| | | ||
//|| | | ||
//|| | | ||
//|| | | ||
//|| | | ||
//|| | | ||
//|| ------------------ ||
//|| ||
//|| ================== ||
//|| || confirm || ||
//|| ================== ||
//|| ||
//==================================================
if (m_viewOnly || single_result) return;
int split_line_y = top_blank_width + G_COMMON_LAYOUT.m_cardNormalHeight + card_bottom_to_split_line;
if (general_number > 5)
split_line_y += (card_to_center_line + G_COMMON_LAYOUT.m_cardNormalHeight);
QPixmap line = G_ROOM_SKIN.getPixmap(QSanRoomSkin::S_SKIN_KEY_CHOOSE_GENERAL_BOX_SPLIT_LINE);
const int line_length = boundingRect().width() - 2 * left_blank_width;
const QRectF rect = boundingRect();
painter->drawPixmap(left_blank_width, split_line_y, line, (line.width() - line_length) / 2, rect.y(), line_length, line.height());
QPixmap seat = G_ROOM_SKIN.getPixmap(QSanRoomSkin::S_SKIN_KEY_CHOOSE_GENERAL_BOX_DEST_SEAT);
QRect seat1_rect(rect.center().x() - G_COMMON_LAYOUT.m_cardNormalWidth - card_to_center_line - 2, split_line_y + split_line_to_card_seat - 2, G_COMMON_LAYOUT.m_cardNormalWidth + 4, G_COMMON_LAYOUT.m_cardNormalHeight + 4);
painter->drawPixmap(seat1_rect, seat);
IQSanComponentSkin::QSanSimpleTextFont font = G_COMMON_LAYOUT.m_chooseGeneralBoxDestSeatFont;
font.paintText(painter, seat1_rect, Qt::AlignCenter, tr("head_general"));
QRect seat2_rect(rect.center().x() + card_to_center_line - 2, split_line_y + split_line_to_card_seat - 2, G_COMMON_LAYOUT.m_cardNormalWidth + 4, G_COMMON_LAYOUT.m_cardNormalHeight + 4);
painter->drawPixmap(seat2_rect, seat);
font.paintText(painter, seat2_rect, Qt::AlignCenter, tr("deputy_general"));
}
示例6: drawLegendIdentifier
/*!
\brief Draw the identifier representing the curve on the legend
\param painter Painter
\param rect Bounding rectangle for the identifier
\sa setLegendAttribute(), QwtPlotItem::Legend
*/
void QwtPlotCurve::drawLegendIdentifier(
QPainter *painter, const QRectF &rect ) const
{
if ( rect.isEmpty() )
return;
const double dim = qMin( rect.width(), rect.height() );
QSizeF size( dim, dim );
QRectF r( 0, 0, size.width(), size.height() );
r.moveCenter( rect.center() );
if ( d_data->legendAttributes == 0 )
{
QBrush brush = d_data->brush;
if ( brush.style() == Qt::NoBrush )
{
if ( style() != QwtPlotCurve::NoCurve )
brush = QBrush( pen().color() );
else if ( d_data->symbol &&
( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
{
brush = QBrush( d_data->symbol->pen().color() );
}
}
if ( brush.style() != Qt::NoBrush )
painter->fillRect( r, brush );
}
if ( d_data->legendAttributes & QwtPlotCurve::LegendShowBrush )
{
if ( d_data->brush.style() != Qt::NoBrush )
painter->fillRect( r, d_data->brush );
}
if ( d_data->legendAttributes & QwtPlotCurve::LegendShowLine )
{
if ( pen() != Qt::NoPen )
{
painter->setPen( pen() );
QwtPainter::drawLine( painter, rect.left(), rect.center().y(),
rect.right() - 1.0, rect.center().y() );
}
}
if ( d_data->legendAttributes & QwtPlotCurve::LegendShowSymbol )
{
if ( d_data->symbol &&
( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
{
QSize symbolSize = d_data->symbol->boundingSize();
symbolSize -= QSize( 2, 2 );
// scale the symbol size down if it doesn't fit into rect.
double xRatio = 1.0;
if ( rect.width() < symbolSize.width() )
xRatio = rect.width() / symbolSize.width();
double yRatio = 1.0;
if ( rect.height() < symbolSize.height() )
yRatio = rect.height() / symbolSize.height();
const double ratio = qMin( xRatio, yRatio );
painter->save();
painter->scale( ratio, ratio );
d_data->symbol->drawSymbol( painter, rect.center() / ratio );
painter->restore();
}
}
}
示例7: drawDial
void drawDial(const QStyleOptionSlider *option, QPainter *painter)
{
QPalette pal = option->palette;
QColor buttonColor = pal.button().color();
const int width = option->rect.width();
const int height = option->rect.height();
const bool enabled = option->state & QStyle::State_Enabled;
qreal r = qMin(width, height) / 2;
r -= r/50;
const qreal penSize = r/20.0;
painter->save();
// Draw notches
if (option->subControls & QStyle::SC_DialTickmarks) {
painter->setPen(option->palette.dark().color().darker(120));
painter->drawLines(QStyleHelper::calcLines(option));
}
// Cache dial background
BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("qdial"));
const qreal d_ = r / 6;
const qreal dx = option->rect.x() + d_ + (width - 2 * r) / 2 + 1;
const qreal dy = option->rect.y() + d_ + (height - 2 * r) / 2 + 1;
QRectF br = QRectF(dx + 0.5, dy + 0.5,
int(r * 2 - 2 * d_ - 2),
int(r * 2 - 2 * d_ - 2));
buttonColor.setHsv(buttonColor .hue(),
qMin(140, buttonColor .saturation()),
qMax(180, buttonColor.value()));
QColor shadowColor(0, 0, 0, 20);
if (enabled) {
// Drop shadow
qreal shadowSize = qMax(1.0, penSize/2.0);
QRectF shadowRect= br.adjusted(-2*shadowSize, -2*shadowSize,
2*shadowSize, 2*shadowSize);
QRadialGradient shadowGradient(shadowRect.center().x(),
shadowRect.center().y(), shadowRect.width()/2.0,
shadowRect.center().x(), shadowRect.center().y());
shadowGradient.setColorAt(qreal(0.91), QColor(0, 0, 0, 40));
shadowGradient.setColorAt(qreal(1.0), Qt::transparent);
p->setBrush(shadowGradient);
p->setPen(Qt::NoPen);
p->translate(shadowSize, shadowSize);
p->drawEllipse(shadowRect);
p->translate(-shadowSize, -shadowSize);
// Main gradient
QRadialGradient gradient(br.center().x() - br.width()/3, dy,
br.width()*1.3, br.center().x(),
br.center().y() - br.height()/2);
gradient.setColorAt(0, buttonColor.lighter(110));
gradient.setColorAt(qreal(0.5), buttonColor);
gradient.setColorAt(qreal(0.501), buttonColor.darker(102));
gradient.setColorAt(1, buttonColor.darker(115));
p->setBrush(gradient);
} else {
p->setBrush(Qt::NoBrush);
}
p->setPen(QPen(buttonColor.darker(280)));
p->drawEllipse(br);
p->setBrush(Qt::NoBrush);
p->setPen(buttonColor.lighter(110));
p->drawEllipse(br.adjusted(1, 1, -1, -1));
if (option->state & QStyle::State_HasFocus) {
QColor highlight = pal.highlight().color();
highlight.setHsv(highlight.hue(),
qMin(160, highlight.saturation()),
qMax(230, highlight.value()));
highlight.setAlpha(127);
p->setPen(QPen(highlight, 2.0));
p->setBrush(Qt::NoBrush);
p->drawEllipse(br.adjusted(-1, -1, 1, 1));
}
END_STYLE_PIXMAPCACHE
QPointF dp = calcRadialPos(option, qreal(0.70));
buttonColor = buttonColor.lighter(104);
buttonColor.setAlphaF(qreal(0.8));
const qreal ds = r/qreal(7.0);
QRectF dialRect(dp.x() - ds, dp.y() - ds, 2*ds, 2*ds);
QRadialGradient dialGradient(dialRect.center().x() + dialRect.width()/2,
dialRect.center().y() + dialRect.width(),
dialRect.width()*2,
dialRect.center().x(), dialRect.center().y());
dialGradient.setColorAt(1, buttonColor.darker(140));
dialGradient.setColorAt(qreal(0.4), buttonColor.darker(120));
dialGradient.setColorAt(0, buttonColor.darker(110));
if (penSize > 3.0) {
painter->setPen(QPen(QColor(0, 0, 0, 25), penSize));
painter->drawLine(calcRadialPos(option, qreal(0.90)), calcRadialPos(option, qreal(0.96)));
}
painter->setBrush(dialGradient);
//.........这里部分代码省略.........
示例8: appendCard
void CustomGraphicsScene::appendCard(int _cardType, const QString& _title, const QString& _description)
{
QPointF scenePosition = sceneRect().center();
//
// Если выделена карточка
//
CardShape* selectedCard = nullptr;
CardShape* previousCard = nullptr;
CardShape* nextCard = nullptr;
CardShape* parentCard = nullptr;
if (!selectedItems().isEmpty()
&& selectedItems().size() == 1
&& (selectedCard = dynamic_cast<CardShape*>(selectedItems().last()))) {
//
// Если карточка вложена в группирующую, то расширяем родителя и вкладываем карту в него
//
if (selectedCard->parentItem() != nullptr) {
//
// Запомним родителя
//
parentCard = dynamic_cast<CardShape*>(selectedCard->parentItem());
}
//
// Если выделен группирующий элемент, то соединять будем с последним из его детей
//
if (hasCards(selectedCard)) {
selectedCard = dynamic_cast<CardShape*>(lastCard(selectedCard));
}
//
// Предыдущей будет выделенная
//
previousCard = selectedCard;
//
// Настроим позицию для добавления новой карточки
//
scenePosition = previousCard->scenePos();
scenePosition.setX(scenePosition.x() + previousCard->boundingRect().width() + SHAPE_MOVE_DELTA);
scenePosition.setY(scenePosition.y() + previousCard->boundingRect().height() + SHAPE_MOVE_DELTA);
//
// Определим карточку, которая будет следовать за новой
//
Flow* flow = cardFlow(previousCard, CARD_ON_FLOW_START);
if (flow != nullptr) {
nextCard = dynamic_cast<CardShape*>(flow->endShape());
removeShape(flow);
}
}
//
// В противном случае добавляем карточку после самой последней карточки, если карточки уже есть
//
else if (hasCards()) {
//
// Определим последнюю карточку
//
Shape* lastCardShape = lastCard();
previousCard = dynamic_cast<CardShape*>(lastCardShape);
//
// Настроим позицию для добавления новой карточки
//
scenePosition = previousCard->scenePos();
scenePosition.setX(scenePosition.x() + previousCard->boundingRect().width() + SHAPE_MOVE_DELTA);
scenePosition.setY(scenePosition.y() + previousCard->boundingRect().height() + SHAPE_MOVE_DELTA);
}
//
// В противном случае добавляем карточку по середине видимой части сцены, если подключены представления
//
else if (!views().isEmpty()) {
if (QGraphicsView* view = views().last()) {
const QRect viewportRect(0, 0, view->viewport()->width(), view->viewport()->height());
const QRectF visibleSceneRect = view->mapToScene(viewportRect).boundingRect();
scenePosition = visibleSceneRect.center();
}
}
//
// Добавляем карточку
//
CardShape* newCard = new CardShape((CardShape::CardType)_cardType, _title, _description, scenePosition, parentCard);
insertShape(newCard, previousCard);
//
// ... корректируем позицию вкладываемой карточки
//
if (parentCard != nullptr) {
const QPointF newPos = parentCard->mapFromScene(newCard->scenePos());
const QPointF newBottomRightPos = newPos + QPointF(newCard->boundingRect().width(), newCard->boundingRect().height());
//
newCard->setParentItem(parentCard);
newCard->setPos(newPos);
//
// ... и масштабируем родителя, если нужно
//
if (!parentCard->contains(newBottomRightPos)) {
QSizeF newSize = parentCard->size();
if (newSize.width() <= newBottomRightPos.x()) {
//.........这里部分代码省略.........
示例9: topCenter
static QPointF topCenter(const QRectF &rect)
{
return QPointF(rect.center().x(), rect.top());
}
示例10: drawPieSurface
/**
Internal method that draws the surface of one of the pies in a pie chart.
\param painter the QPainter to draw in
\param dataset the dataset to draw the pie for
\param pie the pie to draw
*/
void PieDiagram::drawPieSurface( QPainter* painter,
DataValueTextInfoList* list,
uint dataset, uint pie,
qreal granularity )
{
// Is there anything to draw at all?
qreal angleLen = d->angleLens[ pie ];
if ( angleLen ) {
qreal startAngle = d->startAngles[ pie ];
QModelIndex index( model()->index( 0, pie, rootIndex() ) );
const PieAttributes attrs( pieAttributes( index ) );
const ThreeDPieAttributes threeDAttrs( threeDPieAttributes( index ) );
QRectF drawPosition = piePosition( dataset, pie );
painter->setRenderHint ( QPainter::Antialiasing );
QBrush br = brush( index );
if( threeDAttrs.isEnabled() ) {
br = threeDAttrs.threeDBrush( br, drawPosition );
}
painter->setBrush( br );
painter->setPen( pen( index ) );
if ( angleLen == 360 ) {
// full circle, avoid nasty line in the middle
painter->drawEllipse( drawPosition );
//Add polygon to Reverse mapper for showing tool tips.
QPolygonF poly( drawPosition );
d->reverseMapper.addPolygon( index.row(), index.column(), poly );
} else {
// draw the top of this piece
// Start with getting the points for the arc.
const int arcPoints = static_cast<int>(trunc( angleLen / granularity ));
QPolygonF poly( arcPoints+2 );
qreal degree=0.0;
int iPoint = 0;
bool perfectMatch = false;
while ( degree <= angleLen ){
poly[ iPoint ] = pointOnCircle( drawPosition, startAngle + degree );
//qDebug() << degree << angleLen << poly[ iPoint ];
perfectMatch = (degree == angleLen);
degree += granularity;
++iPoint;
}
// if necessary add one more point to fill the last small gap
if( ! perfectMatch ){
poly[ iPoint ] = pointOnCircle( drawPosition, startAngle + angleLen );
// add the center point of the piece
poly.append( drawPosition.center() );
}else{
poly[ iPoint ] = drawPosition.center();
}
//find the value and paint it
//fix value position
d->reverseMapper.addPolygon( index.row(), index.column(), poly );
painter->drawPolygon( poly );
}
// the new code is setting the needed position points according to the slice:
// all is calculated as if the slice were 'standing' on it's tip and the border
// were on top, so North is the middle of the curved outside line and South is the tip
//
const qreal sum = valueTotals();
const QPointF south = drawPosition.center();
const QPointF southEast = south;
const QPointF southWest = south;
const QPointF north = pointOnCircle( drawPosition, startAngle + angleLen/2.0 );
const QPointF northEast = pointOnCircle( drawPosition, startAngle );
const QPointF northWest = pointOnCircle( drawPosition, startAngle + angleLen );
QPointF center = (south + north) / 2.0;
const QPointF east = (south + northEast) / 2.0;
const QPointF west = (south + northWest) / 2.0;
CartesianDiagramDataCompressor::DataValueAttributesList allAttrs( d->aggregatedAttrs( this, index, 0 ) );
const QFontMetrics * fm = (d->cachedFontMetrics( allAttrs.value(index).textAttributes().calculatedFont(d->plane,KDChartEnums::MeasureOrientationMinimum ), this ));
if(!list->isEmpty())
{
QRect textRect = fm->boundingRect(QString::number(list->last().value));
textRect.translated(center.toPoint());
QPoint textRectCenter = textRect.center();
qreal newX = center.x() - textRectCenter.x();
qreal newY = center.y() - textRectCenter.y();
center.setX(newX);
center.setY(newY);
}
PositionPoints points( center, northWest, north, northEast, east, southEast, south, southWest, west);
//.........这里部分代码省略.........
示例11: drawNoteNodeConnector
void CalloutNote::drawNoteNodeConnector(QPainter *painter, bool visible)
{
float width;
float height;
QRectF itemPos;
if(_scene->_pathBubbles[_pid]==NULL) //does not work
return;
PathBubble1* path=_scene->_pathBubbles[_pid];
if(!path || path==NULL || !path->isVisible())
return;
QPointF dis1=this->sceneBoundingRect().center();
QPointF dis2=path->sceneBoundingRect().center();
if(fixedSize)
{
width=graphReferenceSize/2*path->_scale; height=graphReferenceSize/2*path->_scale;
}
else
{
width=this->realRect().width()/2*path->_scale;
height=this->realRect().height()/2*path->_scale;
}
if(_type == 'L' && _id>=path->ANodeRect.size())
return;
switch(_type)
{
case 'C': itemPos = path->complexRect[_id]; break;
case 'E': itemPos = path->physicalEntityRect[_id]; break;
case 'P': itemPos = path->proteinRect[_id]; break;
case 'S': itemPos = path->smallMoleculeRect[_id]; break;
case 'D': itemPos = path->DnaRect[_id]; break;
case 'R': itemPos = path->reactionRect[_id]; break;
case 'L': itemPos = path->ANodeRect[_id]; break;
case 'M': itemPos = path->compartmentRect[_id]; break;
}
QPointF start,end;
start=QPointF(0,0);
end=itemPos.center();
start=start+dis1;
end=end+dis2;
QRectF noteRect=this->sceneBoundingRect();
QRectF pathRect=path->sceneBoundingRect();
float w,h;
w=realRect().width(), h=realRect().height();
noteRect=QRectF(noteRect.center().x()-w/2, noteRect.center().y()-h/2, w, h );
QPointF markPos(end.x()+itemPos.width()*0.5, end.y()-itemPos.height()*0.1);
_deleteMark = QRectF(noteRect.x()+noteRect.width()*0.90, noteRect.y()+noteRect.height()*0.03, noteRect.width()*0.08, noteRect.width()*0.08);
_minimizeMark = QRectF(noteRect.x()+noteRect.width()*0.80, noteRect.y()+noteRect.height()*0.03, noteRect.width()*0.08, noteRect.width()*0.08);
//clip
QColor c=QColor(_colorBoarder.a, _colorBoarder.b, _colorBoarder.c, 255);
if(visible)
{
if(!noteRect.contains(end))
{
drawArrow_5(painter, start, markPos-QPointF(itemPos.width()*0.04,0), QRect(noteRect.center().x()-w/2,noteRect.center().y()-h/2, w, h ), width, height, c );
}
drawCross(painter,_deleteMark, c);
drawMinus(painter,_minimizeMark, c);
}
else
{
//if within the path bubble
if(pathRect.contains(start)|| pathRect.contains(end))
drawNoteMark(painter, start, end, QRect(noteRect.center().x()-w/2,noteRect.center().y()-h/2, w, h ), markPos, markRect, width, height, c );
}
}
示例12: resetGeometry
void KFollowWindow::resetGeometry()
{
Q_D(KFollowWindow);
if(d->target == NULL)
return;
bool bHandled = false;
emit aboutToAdjust(this, &bHandled);
if(bHandled)
{
return;
}
QRectF targetRt = d->target->rectToScreen();
QSizeF targetSize = targetRt.size();
QSizeF winSize = d->winSize;
QRectF winRt(0, 0, winSize.width(), winSize.height());
QPointF winCenterPt = winRt.center();
QPointF targetCenterPt = targetRt.center();
QSizeF hitDistance = (targetSize + winSize) / 2;
Direction tmpDirection = d->direction;
if(tmpDirection == LeftTop)
{
QPointF targetPt = QPointF(targetCenterPt.x(), targetRt.top());
QPointF winPt = QPointF(winCenterPt.x(), winRt.top());
QPointF offsetPt = targetPt - QPointF(hitDistance.width(), 0) - winPt;
offsetPt += d->offsetPt;
winRt.translate(offsetPt);
setGeometry(winRt.toRect());
}
else if(tmpDirection == LeftCenter)
{
QPointF offsetPt = targetCenterPt - QPointF(hitDistance.width(), 0) - winCenterPt;
offsetPt += d->offsetPt;
winRt.translate(offsetPt);
setGeometry(winRt.toRect());
}
else if(tmpDirection == LeftBottom)
{
QPointF targetPt = QPointF(targetCenterPt.x(), targetRt.bottom());
QPointF winPt = QPointF(winCenterPt.x(), winRt.bottom());
QPointF offsetPt = targetPt - QPointF(hitDistance.width(), 0) - winPt;
offsetPt += d->offsetPt;
winRt.translate(offsetPt);
setGeometry(winRt.toRect());
}
else if(tmpDirection == RightTop)
{
QPointF targetPt = QPointF(targetCenterPt.x(), targetRt.top());
QPointF winPt = QPointF(winCenterPt.x(), winRt.top());
QPointF offsetPt = targetPt + QPointF(hitDistance.width(), 0) - winPt;
offsetPt += d->offsetPt;
winRt.translate(offsetPt);
setGeometry(winRt.toRect());
}
else if(tmpDirection == RightCenter)
{
QPointF offsetPt = targetCenterPt + QPointF(hitDistance.width(), 0) - winCenterPt;
offsetPt += d->offsetPt;
winRt.translate(offsetPt);
setGeometry(winRt.toRect());
}
else if(tmpDirection == RightBottom)
{
QPointF targetPt = QPointF(targetCenterPt.x(), targetRt.bottom());
QPointF winPt = QPointF(winCenterPt.x(), winRt.bottom());
QPointF offsetPt = targetPt + QPointF(hitDistance.width(), 0) - winPt;
offsetPt += d->offsetPt;
winRt.translate(offsetPt);
setGeometry(winRt.toRect());
}
else if(tmpDirection == TopLeft)
{
QPointF targetPt = QPointF(targetRt.left(), targetCenterPt.y());
QPointF winPt = QPointF(winRt.left(), winCenterPt.y());
QPointF offsetPt = targetPt - QPointF(0, hitDistance.height()) - winPt;
offsetPt += d->offsetPt;
winRt.translate(offsetPt);
setGeometry(winRt.toRect());
}
else if(tmpDirection == TopCenter)
{
//.........这里部分代码省略.........
示例13: layoutWidgets
void EmulatedCardWindow::layoutWidgets() {
qreal angle = rotationAdjustmentAngle();
int side = 0;
QRectF emuRect = rotateEmulationBoundingRect(angle);
QPointF center = emuRect.center();
qreal height = emuRect.height();
qreal width = emuRect.width();
QPointF bottomCenter = QPointF(center.x(), center.y()+(height/2));
QPointF topCenter = QPointF(center.x(), center.y()-(height/2));
QPointF leftCenter = QPointF(center.x()-(width/2), center.y());
QPointF rightCenter = QPointF(center.x()+(width/2), center.y());
int orient = WindowServer::instance()->getUiOrientation();
//The keyboard button actually tracks the system UI rather than the
//app, so it's laid out independently
QRectF brect = boundingRect();
//X-axis margin: 17px
//Y-axis margin: 18px
m_keyboardButton->setPos(brect.bottomRight().x() - m_keyboardButton->boundingRect().width() - 17,
brect.bottomRight().y() - m_keyboardButton->boundingRect().height() - 18);
//The button should be "fixed", meaning the system orientations map
//as follows:
//
// Up->left
// Left->Up
// Right->down
// down->right
const Event::Orientation app_orientations[] = {Event::Orientation_Up,
Event::Orientation_Left,
Event::Orientation_Down,
Event::Orientation_Right};
const Event::Orientation system_orientations[] = {Event::Orientation_Left,
Event::Orientation_Up,
Event::Orientation_Right,
Event::Orientation_Down};
for (int i=0; i<4; i++) {
if (orient == system_orientations[i]) {
side = app_orientations[i];
}
}
int back_button_offset = 14;
/* Terminology note-- here, "side" means the following:
*
* up -> buttons go on bottom, status bar on top
* right -> buttons go on right, status bar (which shouldn't show) on left
* left -> opposite of right
* down -> opposite of up
*
* This is slightly better self-documenting than relying strictly on the
* adjustment angle.
*/
if (side == Event::Orientation_Up) {
m_gestureStrip->setPos(topCenter.x(), topCenter.y()-m_gestureStrip->boundingRect().height()/2);
m_gestureStrip->setRotation(180);
m_statusBar->setPos(emuRect.right() - emuRect.width()/2,
emuRect.bottom() + Settings::LunaSettings()->positiveSpaceTopPadding/2);
m_statusBar->setRotation(180);
}
else if (side == Event::Orientation_Down) {
m_gestureStrip->setPos(bottomCenter.x(), bottomCenter.y()+m_gestureStrip->boundingRect().height()/2);
m_gestureStrip->setRotation(0);
m_statusBar->setPos(emuRect.right() - emuRect.width()/2,
emuRect.top() - Settings::LunaSettings()->positiveSpaceTopPadding/2);
m_statusBar->setRotation(0);
}
else if (side == Event::Orientation_Left) {
m_gestureStrip->setRotation(-90);
m_gestureStrip->setPos(rightCenter.x()+m_gestureStrip->boundingRect().height()/2, rightCenter.y());
m_statusBar->setPos(emuRect.left()-Settings::LunaSettings()->positiveSpaceTopPadding/2,
emuRect.bottom() - emuRect.height()/2);
m_statusBar->setRotation(-90);
}
else if (side == Event::Orientation_Right) {
m_gestureStrip->setRotation(90);
m_gestureStrip->setPos(leftCenter.x()-m_gestureStrip->boundingRect().height()/2, leftCenter.y());
//.........这里部分代码省略.........
示例14: allAttrs
//.........这里部分代码省略.........
ta.setRotation( favoriteAngle );
dva.setTextAttributes( ta );
}
// get the size of the label text using a subset of the information going into the final layout
const QString text = formatDataValueText( dva, index, value );
QTextDocument doc;
doc.setDocumentMargin( 0 );
if ( Qt::mightBeRichText( text ) ) {
doc.setHtml( text );
} else {
doc.setPlainText( text );
}
const QFont calculatedFont( dva.textAttributes()
.calculatedFont( plane, KChartEnums::MeasureOrientationMinimum ) );
doc.setDefaultFont( calculatedFont );
const QRectF plainRect = doc.documentLayout()->frameBoundingRect( doc.rootFrame() );
/**
* A few hints on how the positioning of the text frame is done:
*
* Let's assume we have a bar chart, a text for a positive value
* to be drawn, and "North" as attrs.positivePosition().
*
* The reference point (pos) is then set to the top center point
* of a bar. The offset now depends on the alignment:
*
* Top: text is centered horizontally to the bar, bottom of
* text frame starts at top of bar
*
* Bottom: text is centered horizontally to the bar, top of
* text frame starts at top of bar
*
* Center: text is centered horizontally to the bar, center
* line of text frame is same as top of bar
*
* TopLeft: right edge of text frame is horizontal center of
* bar, bottom of text frame is top of bar.
*
* ...
*
* Positive and negative value labels are treated equally, "North"
* also refers to the top of a negative bar, and *not* to the bottom.
*
*
* "NorthEast" likewise refers to the top right edge of the bar,
* "NorthWest" to the top left edge of the bar, and so on.
*
* In other words, attrs.positivePosition() always refers to a
* position of the *bar*, and relPos.alignment() always refers
* to an alignment of the text frame relative to this position.
*/
QTransform transform;
{
// move to the general area where the label should be
QPointF calcPoint = relPos.calculatedPoint( relativeMeasureSize );
transform.translate( calcPoint.x(), calcPoint.y() );
// align the text rect; find out by how many half-widths / half-heights to move.
int dx = -1;
if ( relPos.alignment() & Qt::AlignLeft ) {
dx -= 1;
} else if ( relPos.alignment() & Qt::AlignRight ) {
dx += 1;
}
int dy = -1;
if ( relPos.alignment() & Qt::AlignTop ) {
dy -= 1;
} else if ( relPos.alignment() & Qt::AlignBottom ) {
dy += 1;
}
transform.translate( qreal( dx ) * plainRect.width() * 0.5,
qreal( dy ) * plainRect.height() * 0.5 );
// rotate the text rect around its center
transform.translate( plainRect.center().x(), plainRect.center().y() );
int rotation = dva.textAttributes().rotation();
if ( !isPositive && dva.mirrorNegativeValueTextRotation() ) {
rotation *= -1;
}
transform.rotate( rotation );
transform.translate( -plainRect.center().x(), -plainRect.center().y() );
}
QPainterPath labelArea;
//labelArea.addPolygon( transform.mapToPolygon( plainRect.toRect() ) );
//labelArea.closeSubpath();
// Not doing that because QTransform has a special case for 180° that gives a different than
// usual ordering of the points in the polygon returned by mapToPolygon( const QRect & ).
// We expect a particular ordering in paintDataValueTextsAndMarkers() by using elementAt( 0 ),
// and similar things might happen elsewhere.
labelArea.addPolygon( transform.map( QPolygon( plainRect.toRect(), true ) ) );
// store the label geometry and auxiliary data
cache->paintReplay.append( LabelPaintInfo( it.key(), dva, labelArea,
referencePoint, value >= 0.0, text ) );
}
}
示例15: execute
bool EnhancedPathCommand::execute()
{
/*
* The parameters of the commands are in viewbox coordinates, which have
* to be converted to the shapes coordinate system by calling viewboxToShape
* on the enhanced path the command works on.
* Parameters which resemble angles are angles corresponding to the viewbox
* coordinate system. Those have to be transformed into angles corresponding
* to the normal mathematically coordinate system to be used for the arcTo
* drawing routine. This is done by computing (2*M_PI - angle).
*/
QList<QPointF> points = pointsFromParameters();
const int pointsCount = points.size();
switch (m_command.unicode()) {
// starts new subpath at given position (x y) +
case 'M':
if (!pointsCount)
return false;
m_parent->moveTo(points[0]);
if (pointsCount > 1)
for (int i = 1; i < pointsCount; i++)
m_parent->lineTo(points[i]);
break;
// line from current point (x y) +
case 'L':
foreach(const QPointF &point, points)
m_parent->lineTo(point);
break;
// cubic bezier curve from current point (x1 y1 x2 y2 x y) +
case 'C':
for (int i = 0; i < pointsCount; i+=3)
m_parent->curveTo(points[i], points[i+1], points[i+2]);
break;
// closes the current subpath
case 'Z':
m_parent->close();
break;
// ends the current set of subpaths
case 'N':
// N just ends the complete path
break;
// no fill for current set of subpaths
case 'F':
// TODO implement me
break;
// no stroke for current set of subpaths
case 'S':
// TODO implement me
break;
// segment of an ellipse (x y w h t0 t1) +
case 'T':
// same like T but with implied movement to starting point (x y w h t0 t1) +
case 'U': {
bool lineTo = m_command.unicode() == 'T';
for (int i = 0; i < pointsCount; i+=3) {
const QPointF &radii = points[i+1];
const QPointF &angles = points[i+2] / rad2deg;
// compute the ellipses starting point
QPointF start(radii.x() * cos(angles.x()), -1 * radii.y() * sin(angles.x()));
qreal sweepAngle = degSweepAngle(points[i+2].x(), points[i+2].y(), false);
if (lineTo)
m_parent->lineTo(points[i] + start);
else
m_parent->moveTo(points[i] + start);
m_parent->arcTo(radii.x(), radii.y(), points[i+2].x(), sweepAngle);
}
break;
}
// counter-clockwise arc (x1 y1 x2 y2 x3 y3 x y) +
case 'A':
// the same as A, with implied moveto to the starting point (x1 y1 x2 y2 x3 y3 x y) +
case 'B':
// clockwise arc (x1 y1 x2 y2 x3 y3 x y) +
case 'W':
// the same as W, but implied moveto (x1 y1 x2 y2 x3 y3 x y) +
case 'V': {
bool lineTo = ((m_command.unicode() == 'A') || (m_command.unicode() == 'W'));
bool clockwise = ((m_command.unicode() == 'W') || (m_command.unicode() == 'V'));
for (int i = 0; i < pointsCount; i+=4) {
QRectF bbox = rectFromPoints(points[i], points[i+1]);
QPointF center = bbox.center();
qreal rx = 0.5 * bbox.width();
qreal ry = 0.5 * bbox.height();
if (rx == 0) {
rx = 1;
}
if (ry == 0) {
ry = 1;
}
QPointF startRadialVector = points[i+2] - center;
QPointF endRadialVector = points[i+3] - center;
// convert from ellipse space to unit-circle space
//.........这里部分代码省略.........