void GripperWidget::drawBackground(QPainter *painter, const QRectF &rect) //draw the scene background { Q_UNUSED(rect); // Shadow QRectF sceneRect = this->sceneRect(); QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height()); QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5); if (rightShadow.intersects(rect) || rightShadow.contains(rect)) painter->fillRect(rightShadow, Qt::darkGray); if (bottomShadow.intersects(rect) || bottomShadow.contains(rect)) painter->fillRect(bottomShadow, Qt::darkGray); // Fill QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight()); gradient.setColorAt(0, Qt::white); gradient.setColorAt(1, Qt::lightGray); painter->fillRect(rect.intersect(sceneRect), gradient); painter->setBrush(Qt::NoBrush); painter->drawRect(sceneRect); painter->setPen(Qt::blue); painter->drawLine(0, GRIPPER_BOTTOM_LINE, GRIPPER_X, GRIPPER_BOTTOM_LINE); painter->drawLine(GRIPPER_LEFT_LINE, 0, GRIPPER_LEFT_LINE, GRIPPER_Y); painter->drawLine(GRIPPER_RIGHT_LINE, 0, GRIPPER_RIGHT_LINE, GRIPPER_Y); painter->setPen(QPen(Qt::green,2)); painter->drawArc(GRIPPER_CENTER_X - GRIPPER_CIRCLE_RADIUS, GRIPPER_CENTER_Y - GRIPPER_CIRCLE_RADIUS, GRIPPER_CIRCLE_RADIUS * 2,GRIPPER_CIRCLE_RADIUS * 2, 0, 360 * 64); }
void KoCreateShapeStrategy::paint(QPainter &painter, const KoViewConverter &converter) { if (m_outline.isEmpty()) KoShapeRubberSelectStrategy::paint(painter, converter); else { painter.save(); painter.setRenderHint(QPainter::Antialiasing, false); QColor selectColor(Qt::blue); // TODO make configurable selectColor.setAlphaF(0.5); QBrush sb(selectColor, Qt::SolidPattern); painter.setPen(QPen(sb, 0)); painter.setBrush(sb); QRectF paintRect = converter.documentToView(selectRect()); qreal xscale = paintRect.width() / m_outlineBoundingRect.width(); qreal yscale = paintRect.height() / m_outlineBoundingRect.height(); QMatrix matrix; matrix.translate(-m_outlineBoundingRect.left(), -m_outlineBoundingRect.top()); matrix.scale(xscale, yscale); painter.translate(paintRect.left(), paintRect.top()); if (painter.hasClipping()) paintRect = paintRect.intersect(painter.clipRegion().boundingRect()); painter.setMatrix(matrix, true); painter.drawPath(m_outline); painter.restore(); } }
//! Wrapper for QPainter::fillRect() void QwtPainter::fillRect( QPainter *painter, const QRectF &rect, const QBrush &brush ) { if ( !rect.isValid() ) return; QRectF clipRect; const bool deviceClipping = isClippingNeeded( painter, clipRect ); /* Performance of Qt4 is horrible for non trivial brushs. Without clipping expect minutes or hours for repainting large rects (might result from zooming) */ if ( deviceClipping ) clipRect &= painter->window(); else clipRect = painter->window(); if ( painter->hasClipping() ) clipRect &= painter->clipRegion().boundingRect(); QRectF r = rect; if ( deviceClipping ) r = r.intersect( clipRect ); if ( r.isValid() ) painter->fillRect( r, brush ); }
void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect) { Q_UNUSED(rect); //return; // Shadow QRectF sceneRect = this->sceneRect(); QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height()); QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5); if (rightShadow.intersects(rect) || rightShadow.contains(rect)) painter->fillRect(rightShadow, Qt::darkGray); if (bottomShadow.intersects(rect) || bottomShadow.contains(rect)) painter->fillRect(bottomShadow, Qt::darkGray); // Fill QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight()); gradient.setColorAt(0, QColor(100,107,126)); gradient.setColorAt(1, QColor(100,107,126)); painter->fillRect(rect.intersect(sceneRect), gradient); //painter->setBrush(Qt::BrushStyle::DiagCrossPattern); painter->drawRect(sceneRect); // Text //QRectF textRect(sceneRect.left() + 4, sceneRect.top() + 4, // sceneRect.width() - 4, sceneRect.height() - 4); //QString message(tr("Click and drag the nodes around, and zoom with the mouse " // "wheel or the '+' and '-' keys")); //QFont font = painter->font(); //font.setBold(true); //font.setPointSize(14); //painter->setFont(font); //painter->setPen(Qt::lightGray); ////painter->drawText(textRect.translated(2, 2), message); //painter->setPen(Qt::black); //painter->drawText(textRect, message); painter->setPen(QColor(135,142,157)); const int gridSize = 25; qreal left = int(rect.left()) - (int(rect.left()) % gridSize); qreal top = int(rect.top()) - (int(rect.top()) % gridSize); QVarLengthArray<QLineF, 100> lines; for (qreal x = left; x < rect.right(); x += gridSize) lines.append(QLineF(x, rect.top(), x, rect.bottom())); for (qreal y = top; y < rect.bottom(); y += gridSize) lines.append(QLineF(rect.left(), y, rect.right(), y)); //qDebug() << lines.size(); painter->drawLines(lines.data(), lines.size()); }
void QGobanView::drawBackground(QPainter *painter, const QRectF &rect) { Q_UNUSED(rect); // Shadow QRectF sceneRect = this->sceneRect(); QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height()); QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5); if (rightShadow.intersects(rect) || rightShadow.contains(rect)) painter->fillRect(rightShadow, Qt::darkGray); if (bottomShadow.intersects(rect) || bottomShadow.contains(rect)) painter->fillRect(bottomShadow, Qt::darkGray); // Fill QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight()); gradient.setColorAt(0, Qt::white); gradient.setColorAt(1, Qt::lightGray); painter->fillRect(rect.intersect(sceneRect), gradient); painter->setBrush(Qt::NoBrush); painter->drawRect(sceneRect); // Lines for(int i=0;i<_size;i++) { painter->drawLine(sceneRect.left()+_margin+i*_spacing,sceneRect.top()+_margin, sceneRect.left()+_margin+i*_spacing,sceneRect.height()-_margin); painter->drawLine(sceneRect.left()+_margin,sceneRect.top()+_margin+i*_spacing, sceneRect.width()-_margin,sceneRect.top()+_margin+i*_spacing); } //Stars int size=(int)(_spacing*0.1); //Always mark the center painter->setBrush(Qt::SolidPattern); painter->drawEllipse(QPoint(sceneRect.left()+_margin+(_size-1)/2*_spacing, sceneRect.top()+_margin+(_size-1)/2*_spacing),size,size); if(_size>=13) { //Mark the corners painter->drawEllipse(QPoint(sceneRect.left()+_margin+3*_spacing, sceneRect.top()+_margin+3*_spacing),size,size); painter->drawEllipse(QPoint(sceneRect.left()+_margin+(_size-4)*_spacing, sceneRect.top()+_margin+3*_spacing),size,size); painter->drawEllipse(QPoint(sceneRect.left()+_margin+(_size-4)*_spacing, sceneRect.top()+_margin+(_size-4)*_spacing),size,size); painter->drawEllipse(QPoint(sceneRect.left()+_margin+3*_spacing, sceneRect.top()+_margin+(_size-4)*_spacing),size,size); } if(_size==19) { //Mark the middle painter->drawEllipse(QPoint(sceneRect.left()+_margin+(_size-1)/2*_spacing, sceneRect.top()+_margin+3*_spacing),size,size); painter->drawEllipse(QPoint(sceneRect.left()+_margin+(_size-1)/2*_spacing, sceneRect.top()+_margin+(_size-4)*_spacing),size,size); painter->drawEllipse(QPoint(sceneRect.left()+_margin+(_size-4)*_spacing, sceneRect.top()+_margin+(_size-1)/2*_spacing),size,size); painter->drawEllipse(QPoint(sceneRect.left()+_margin+3*_spacing, sceneRect.top()+_margin+(_size-1)/2*_spacing),size,size); } }
void PokemonBox::drawBackground(QPainter *painter, const QRectF &rect) { QGraphicsView::drawBackground(painter, rect); if (currentPoke != -1) { QPointF selBGPos = calculatePos(currentPoke, selBg.size()); QRectF intersection = rect.intersect(QRectF(selBGPos, selBg.size())); QRectF srcRect = QRectF(std::max(qreal(0), intersection.x()-selBGPos.x()), std::max(qreal(0), intersection.y()-selBGPos.y()), selBg.width(), selBg.height()); painter->drawPixmap(intersection, selBg, srcRect); } }
/*!\func * * \param * - * - * \return */ void GraphBody::drawBackground(QPainter *painter, const QRectF &rect) { Q_UNUSED(rect); LOG(LOG_DEBUG, QString(__FUNCTION__) + " <" + QString::number(__LINE__) + ">"); // Fill return; QLinearGradient gradient(rect.topLeft(), rect.bottomRight()); gradient.setColorAt(0, Qt::white); gradient.setColorAt(1, Qt::lightGray); painter->fillRect(rect.intersect(rect), gradient); painter->setBrush(Qt::NoBrush); painter->drawRect(rect); }
void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect) { Q_UNUSED(rect); // Shadow QRectF sceneRect = this->sceneRect(); // Fill QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight()); gradient.setColorAt(0, startBackgroundGradient); gradient.setColorAt(1, endBackgroundGradient); painter->fillRect(rect.intersect(sceneRect), gradient); painter->setBrush(Qt::NoBrush); //painter->drawRect(sceneRect); }
//! [6] void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect) { Q_UNUSED(rect); // Shadow QRectF sceneRect = this->sceneRect(); QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height()); QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5); if (rightShadow.intersects(rect) || rightShadow.contains(rect)) painter->fillRect(rightShadow, Qt::darkGray); if (bottomShadow.intersects(rect) || bottomShadow.contains(rect)) painter->fillRect(bottomShadow, Qt::darkGray); // Fill QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight()); gradient.setColorAt(0, Qt::white); gradient.setColorAt(1, Qt::lightGray); painter->fillRect(rect.intersect(sceneRect), gradient); painter->setBrush(Qt::NoBrush); painter->drawRect(sceneRect); #if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5) // Text QRectF textRect(sceneRect.left() + 4, sceneRect.top() + 4, sceneRect.width() - 4, sceneRect.height() - 4); QString message(tr("Click and drag the nodes around, and zoom with the mouse " "wheel or the '+' and '-' keys")); QFont font = painter->font(); font.setBold(true); font.setPointSize(14); painter->setFont(font); painter->setPen(Qt::lightGray); painter->drawText(textRect.translated(2, 2), message); painter->setPen(Qt::black); painter->drawText(textRect, message); #endif }
QList<KWViewMode::ViewMap> KWViewModeNormal::mapExposedRects(const QRectF &viewRect, KoViewConverter *viewConverter) const { QList<ViewMap> answer; if (!viewConverter) return answer; #if 1 if (m_pageTops.isEmpty()) return answer; KWPage page = m_pageManager->begin(); const int pageOffset = page.pageNumber(); // Perform a binary search for page-index using our m_pageTops cache. int begin = 0; int end = m_pageTops.count() - 1; int index = 0; const qreal value = viewConverter->viewToDocument(viewRect.topLeft()).y(); if (m_pageTops.value(end) <= value) { // check extremes. Only end is needed since begin is zero. begin = end; index = end; } while (end - begin > 1) { index = begin + (end - begin) / 2; qreal diff = m_pageTops.value(index) - value; if (diff < 0) begin = index; else if (diff > 0) end = index; else break; } // index is now the number of the first possible page that can // contain the viewRect. The next step is to find the // corresponding Page. Since we have no way to get to the Nth // page directly we have to enumerate them from the beginning. // // We use 1 since we might hit a pagespread in the binary search, // so start one page early. while (index > 1) { page = page.next(); --index; } // From here we loop through some more pages after the found one // and see if they intersect with the page in question. When we // have two pages in row that don't intersect we break the loop. qreal offsetX = 0.0; int emptyPages = 0; for(; page.isValid(); page = page.next()) { Q_ASSERT_X(page.pageNumber()-pageOffset < m_pageTops.count(), __FUNCTION__, QString("Pagemanager has more pages than viewmode (%1>%2 with pageOffset=%3 and pageNumber=%4 and pageCount=%5). Make sure you add pages via the document!") .arg(page.pageNumber()-pageOffset).arg(m_pageTops.count()) .arg(pageOffset).arg(page.pageNumber()).arg(m_pageManager->pageCount()).toLocal8Bit()); // Some invariants const QRectF pageRect = page.rect(); const qreal offsetY = m_pageTops[page.pageNumber() - pageOffset] - pageRect.top(); bool pageIntersects = false; // 1. First handle the page itself. const QRectF zoomedPage = viewConverter->documentToView(pageRect); ViewMap vm; vm.page = page; //kDebug(32003) <<"page" << page.pageNumber(); vm.distance = viewConverter->documentToView(QPointF(offsetX, offsetY)); const QRectF targetPage(zoomedPage.x() + vm.distance.x(), zoomedPage.y() + vm.distance.y(), zoomedPage.width(), zoomedPage.height()); QRectF intersection = targetPage.intersect(viewRect); if (! intersection.isEmpty()) { intersection.moveTopLeft(intersection.topLeft() - vm.distance); vm.clipRect = intersection.toRect(); answer.append(vm); pageIntersects = true; } // 2. Then handle the annotation area if annotations are active. // // The reason we don't do them together with the page // itself is because the pages have a gap between them, but // the annotation area should be unbroken. // // NOTE: 'annotation' below means the annotation area. // // FIXME: We should only do this if the annotation area is // actually shown. How can we inside the KWViewMode // know if annotations are active? if (1 /* annotations are shown */) { const QRectF annotationRect = pageRect.adjusted(page.width(), 0, KWCanvasBase::AnnotationAreaWidth, GAP); const QRectF zoomedAnnotation = viewConverter->documentToView(annotationRect); ViewMap vm2; vm2.page = page; vm2.distance = viewConverter->documentToView(QPointF(offsetX, offsetY)); const QRectF targetAnnotation(zoomedAnnotation.x() + vm2.distance.x(), zoomedAnnotation.y() + vm2.distance.y(), zoomedAnnotation.width(), zoomedAnnotation.height()); intersection = targetAnnotation.intersect(viewRect); if (! intersection.isEmpty()) { intersection.moveTopLeft(intersection.topLeft() - vm2.distance); vm2.clipRect = intersection.toRect(); answer.append(vm2); pageIntersects = true; } } // Record whether this page had an intersection with the view rect. if (pageIntersects) { emptyPages = 0; } else { ++emptyPages; } if (emptyPages > 2) // Since we show at max 2 pages side by side this is an easy rule break; if (m_pageSpreadMode) { if (page.pageSide() == KWPage::Left) offsetX = page.width() + GAP; else offsetX = 0.0; } } #else KWPage page = m_pageManager->begin(); Q_ASSERT(page.isValid()); qreal offsetX = 0.0; const int pageOffset = page.pageNumber(); for(; page.isValid(); page = page.next()) { const QRectF pageRect = page.rect(); const QRectF zoomedPage = viewConverter->documentToView(pageRect); ViewMap vm; vm.page = page; const qreal offsetY = m_pageTops[page.pageNumber() - pageOffset] - pageRect.top(); vm.distance = viewConverter->documentToView(QPointF(offsetX, offsetY)); #if 0 const QRectF targetPage(zoomedPage.x() + vm.distance.x(), zoomedPage.y() + vm.distance.y(), zoomedPage.width() , zoomedPage.height()); QRectF intersection = targetPage.intersect(viewRect); if (! intersection.isEmpty()) { intersection.moveTopLeft(intersection.topLeft() - vm.distance); vm.clipRect = intersection.toRect(); answer.append(vm); } #else const QRectF targetPage(zoomedPage.x() + vm.distance.x(), zoomedPage.y() + vm.distance.y(), zoomedPage.width() , zoomedPage.height()); vm.clipRect = targetPage.toRect(); answer.append(vm); #endif } #endif return answer; }
QList<KWViewMode::ViewMap> KWViewModeNormal::mapExposedRects(const QRectF &viewRect, KoViewConverter *viewConverter) const { QList<ViewMap> answer; if (!viewConverter) return answer; #if 1 if (m_pageTops.isEmpty()) return answer; KWPage page = m_pageManager->begin(); qreal offsetX = 0.0; const int pageOffset = page.pageNumber(); int begin = 0; int end = m_pageTops.count() - 1; int index = 0; const qreal value = viewConverter->viewToDocument(viewRect.topLeft()).y(); if (m_pageTops.value(end) <= value) { // check extremes. Only end is needed since begin is zero. begin = end; index = end; } while (end - begin > 1) { // binary search for page-index using our m_pageTops cache. index = begin + (end - begin) / 2; qreal diff = m_pageTops.value(index) - value; if (diff < 0) begin = index; else if (diff > 0) end = index; else break; } while (index > 1) { // 1 since we might hit a pagespread in the binary search, so start one page early page = page.next(); --index; } int emptyPages = 0; for(; page.isValid(); page = page.next()) { Q_ASSERT_X(page.pageNumber()-pageOffset < m_pageTops.count(), __FUNCTION__, QString("Pagemanager has more pages than viewmode (%1>%2 with pageOffset=%3 and pageNumber=%4 and pageCount=%5). Make sure you add pages via the document!") .arg(page.pageNumber()-pageOffset).arg(m_pageTops.count()).arg(pageOffset).arg(page.pageNumber()).arg(m_pageManager->pageCount()).toLocal8Bit()); const QRectF pageRect = page.rect(); const QRectF zoomedPage = viewConverter->documentToView(pageRect); ViewMap vm; vm.page = page; //kDebug(32003) <<"page" << page.pageNumber(); const qreal offsetY = m_pageTops[page.pageNumber() - pageOffset] - pageRect.top(); vm.distance = viewConverter->documentToView(QPointF(offsetX, offsetY)); const QRectF targetPage(zoomedPage.x() + vm.distance.x(), zoomedPage.y() + vm.distance.y(), zoomedPage.width() , zoomedPage.height()); QRectF intersection = targetPage.intersect(viewRect); if (! intersection.isEmpty()) { intersection.moveTopLeft(intersection.topLeft() - vm.distance); vm.clipRect = intersection.toRect(); answer.append(vm); emptyPages = 0; } else { emptyPages++; } if (emptyPages > 2) // Since we show at max 2 pages side by side this is an easy rule break; if (m_pageSpreadMode) { if (page.pageSide() == KWPage::Left) offsetX = page.width() + GAP; else offsetX = 0.0; } } #else KWPage page = m_pageManager->begin(); Q_ASSERT(page.isValid()); qreal offsetX = 0.0; const int pageOffset = page.pageNumber(); for(; page.isValid(); page = page.next()) { const QRectF pageRect = page.rect(); const QRectF zoomedPage = viewConverter->documentToView(pageRect); ViewMap vm; vm.page = page; const qreal offsetY = m_pageTops[page.pageNumber() - pageOffset] - pageRect.top(); vm.distance = viewConverter->documentToView(QPointF(offsetX, offsetY)); #if 0 const QRectF targetPage(zoomedPage.x() + vm.distance.x(), zoomedPage.y() + vm.distance.y(), zoomedPage.width() , zoomedPage.height()); QRectF intersection = targetPage.intersect(viewRect); if (! intersection.isEmpty()) { intersection.moveTopLeft(intersection.topLeft() - vm.distance); vm.clipRect = intersection.toRect(); answer.append(vm); } #else const QRectF targetPage(zoomedPage.x() + vm.distance.x(), zoomedPage.y() + vm.distance.y(), zoomedPage.width() , zoomedPage.height()); vm.clipRect = targetPage.toRect(); answer.append(vm); #endif } #endif return answer; }
QList<KWViewMode::ViewMap> KWViewModeNormal::clipRectToDocument(const QRect &viewRect) const { QList<ViewMap> answer; if (m_pageTops.isEmpty()) return answer; KWPage page = m_pageManager->begin(); qreal offsetX = 0.0; const int pageOffset = page.pageNumber(); int begin = 0; int end = m_pageTops.count() - 1; int index = 0; const qreal value = m_viewConverter->viewToDocument(viewRect.topLeft()).y(); if (m_pageTops.value(end) <= value) { // check extremes. Only end is needed since begin is zero. begin = end; index = end; } while (end - begin > 1) { // binary search for page-index using our m_pageTops cache. index = begin + (end - begin) / 2; qreal diff = m_pageTops.value(index) - value; if (diff < 0) begin = index; else if (diff > 0) end = index; else break; } while (index > 1) { // 1 since we might hit a pagespread in the binary search, so start one page early page = page.next(); --index; if (page.pageSide() == KWPage::PageSpread) --index; } int emptyPages = 0; while (page.isValid()) { #ifndef NDEBUG if (page.pageNumber() - pageOffset >= m_pageTops.count()) { kWarning(32003) << "ERROR; pagemanager has more pages than viewmode (" << m_pageManager->pageCount() << ">" << m_pageTops.count() << "). Make sure you add pages via the document!"; break; } #endif const QRectF pageRect = page.rect(); const QRectF zoomedPage = m_viewConverter->documentToView(pageRect); ViewMap vm; vm.page = page; //kDebug(32003) <<"page" << page.pageNumber(); const qreal offsetY = m_pageTops[page.pageNumber() - pageOffset] - pageRect.top(); vm.distance = m_viewConverter->documentToView(QPointF(offsetX, offsetY)); const QRectF targetPage(zoomedPage.x() + vm.distance.x(), zoomedPage.y() + vm.distance.y(), zoomedPage.width() , zoomedPage.height()); QRectF intersection = targetPage.intersect(viewRect); if (! intersection.isEmpty()) { intersection.moveTopLeft(intersection.topLeft() - vm.distance); vm.clipRect = intersection.toRect(); answer.append(vm); emptyPages = 0; } else { emptyPages++; } if (emptyPages > 2) // Since we show at max 2 pages side by side this is an easy rule break; if (m_pageSpreadMode) { if (page.pageSide() == KWPage::Left) offsetX = page.width() + GAP; else offsetX = 0.0; } page = page.next(); } return answer; }