void MScenePrivate::showFpsCounter(QPainter *painter, float fps) { Q_Q(MScene); QString display = QString("FPS: %1").arg((int)(fps + 0.5f)); /* Draw a simple FPS counter in the lower right corner */ static QRectF fpsRect(0, 0, FpsBoxSize.width(), FpsBoxSize.height()); if (!q->views().isEmpty()) { MApplicationWindow *window = qobject_cast<MApplicationWindow *>(q->views().at(0)); if (window) { if (manager && manager->orientation() == M::Portrait) fpsRect.moveTo(QPointF(window->visibleSceneSize().height() - FpsBoxSize.width(), window->visibleSceneSize().width() - FpsBoxSize.height())); else fpsRect.moveTo(QPointF(window->visibleSceneSize().width() - FpsBoxSize.width(), window->visibleSceneSize().height() - FpsBoxSize.height())); } } painter->fillRect(fpsRect, fpsBackgroundBrush); painter->setPen(FpsTextColor); painter->setFont(FpsFont); painter->drawText(fpsRect, Qt::AlignCenter, display); }
ResizeCommand *ResizeCommand::create(const NodeElement * const element , const QRectF &newContents, const QPointF &newPos , const QRectF &oldContents, const QPointF &oldPos) { QRectF newContentsAndPos = newContents; newContentsAndPos.moveTo(newPos); QRectF oldContentsAndPos = oldContents; oldContentsAndPos.moveTo(oldPos); return new ResizeCommand(dynamic_cast<EditorViewScene *>(element->scene()) , element->id(), oldContentsAndPos, newContentsAndPos); }
void FormText::clearFormat() { QTextCursor c = textCursor(); if( c.hasSelection() ) { QTextCharFormat fmt = c.charFormat(); fmt.setFontUnderline( false ); fmt.setFontItalic( false ); fmt.setFontWeight( QFont::Normal ); fmt.setFontPointSize( 10 ); textCursor().setCharFormat( fmt ); } else { QFont f = font(); f.setUnderline( false ); f.setItalic( false ); f.setWeight( QFont::Normal ); f.setPointSize( 10.0 ); setFont( f ); } QRectF r = boundingRect(); r.moveTo( pos() ); d->m_proxy->setRect( r ); }
void FormText::underline( bool on ) { QTextCursor c = textCursor(); if( c.hasSelection() ) { if( c.position() != c.selectionEnd() ) c.setPosition( c.selectionEnd() ); QTextCharFormat fmt = c.charFormat(); fmt.setFontUnderline( on ); textCursor().setCharFormat( fmt ); } else { QFont f = font(); f.setUnderline( on ); setFont( f ); } QRectF r = boundingRect(); r.moveTo( pos() ); d->m_proxy->setRect( r ); }
/*! \internal */ void QGraphicsProxyWidgetPrivate::updateProxyGeometryFromWidget() { Q_Q(QGraphicsProxyWidget); if (!widget) return; QRectF widgetGeometry = widget->geometry(); QWidget *parentWidget = widget->parentWidget(); if (widget->isWindow()) { QGraphicsProxyWidget *proxyParent = 0; if (parentWidget && (proxyParent = qobject_cast<QGraphicsProxyWidget *>(q->parentWidget()))) { // Nested window proxy (e.g., combobox popup), map widget to the // parent widget's global coordinates, and map that to the parent // proxy's child coordinates. widgetGeometry.moveTo(proxyParent->subWidgetRect(parentWidget).topLeft() + parentWidget->mapFromGlobal(widget->pos())); } } // Adjust to size hint if the widget has never been resized. if (!widget->size().isValid()) widgetGeometry.setSize(widget->sizeHint()); // Assign new geometry. posChangeMode = QGraphicsProxyWidgetPrivate::WidgetToProxyMode; sizeChangeMode = QGraphicsProxyWidgetPrivate::WidgetToProxyMode; q->setGeometry(widgetGeometry); posChangeMode = QGraphicsProxyWidgetPrivate::NoMode; sizeChangeMode = QGraphicsProxyWidgetPrivate::NoMode; }
bool ShaderNodeUI::containsSceneSpace(const QPointF& point) const { QRectF localRect = boundingRect(); localRect.moveTo(pos().x(), pos().y()); return localRect.contains(point); }
void ChatNode::addTeteToMinMax(Tete* tete, float* min_x, float* min_y, float* max_x, float* max_y) { //return; if(tete == NULL) return; if(tete->tete_node() == NULL) return; QRectF local_bound = tete->tete_node()->boundingRect(); QRectF bound = local_bound; bound.moveTo(tete->tete_node()->pos()); bound.translate(-local_bound.width()/2,-local_bound.height()/2); //std::cerr << bound.topLeft().y() << " " << *min_y << std::endl; if(bound.topLeft().x() < *min_x) *min_x = bound.topLeft().x(); if(bound.topLeft().y() < *min_y) *min_y = bound.topLeft().y(); if(bound.bottomRight().x() > *max_x) *max_x = bound.bottomRight().x(); if(bound.bottomRight().y() > *max_y) *max_y = bound.bottomRight().y(); }
void ChatNode::updateAllTetesRect(){ std::vector<Tete*> tetes = chat_->tetes(); if(tetes.empty()){ all_tetes_rect_ = QRectF(-1, -1, 2, 2); return; } TeteNode* first_node = NULL; // Find the first non-null node for(unsigned int i = 0u; first_node == NULL; i++){ first_node = tetes[i]->tete_node(); } QRectF local_bound = first_node->boundingRect(); QRectF bound = local_bound; bound.moveTo(first_node->pos()); // Translate more due to text bound.translate(-local_bound.width()/2,-local_bound.height()/2); float min_x = bound.topLeft().x(); float min_y = bound.topLeft().y(); float max_x = bound.bottomRight().x(); float max_y = bound.bottomRight().y(); for(std::vector<Tete*>::const_iterator it = tetes.begin(); it != tetes.end(); ++it){ addTeteToMinMax(*it, &min_x, &min_y, &max_x, &max_y); } all_tetes_rect_ = QRectF(QPointF(min_x, min_y), QPointF(max_x, max_y)).normalized(); }
QRectF KWidget::rectToScene() const { QRectF rt = rect(); QPointF pt = mapToScene(rt.topLeft()); rt.moveTo(pt); return rt; }
void AnchorIndicatorGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * /* option */, QWidget * /* widget */) { painter->save(); QPen linePen(QColor(0, 0, 0, 150)); linePen.setDashPattern(QVector<double>() << 3. << 2.); painter->setPen(linePen); painter->drawLine(m_startPoint, m_firstControlPoint); painter->drawLine(m_firstControlPoint, m_secondControlPoint); painter->drawLine(m_secondControlPoint, m_endPoint); linePen.setColor(QColor(255, 255, 255, 150)); linePen.setDashPattern(QVector<double>() << 2. << 3.); linePen.setDashOffset(2.); painter->setPen(linePen); painter->drawLine(m_startPoint, m_firstControlPoint); painter->drawLine(m_firstControlPoint, m_secondControlPoint); painter->drawLine(m_secondControlPoint, m_endPoint); static QRectF bumpRectangle(0., 0., 8., 8.); painter->setPen(QPen(QColor(0, 255 , 0), 2)); painter->drawLine(m_sourceAnchorLineFirstPoint, m_sourceAnchorLineSecondPoint); bumpRectangle.moveTo(m_startPoint.x() - 4., m_startPoint.y() - 4.); painter->setBrush(painter->pen().color()); painter->setRenderHint(QPainter::Antialiasing, true); painter->drawChord(bumpRectangle, startAngleForAnchorLine(m_sourceAnchorLineType), 180 * 16); painter->setRenderHint(QPainter::Antialiasing, false); painter->setPen(QPen(QColor(0, 0 , 255), 2)); painter->drawLine(m_targetAnchorLineFirstPoint, m_targetAnchorLineSecondPoint); bumpRectangle.moveTo(m_endPoint.x() - 4., m_endPoint.y() - 4.); painter->setBrush(painter->pen().color()); painter->setRenderHint(QPainter::Antialiasing, true); painter->drawChord(bumpRectangle, startAngleForAnchorLine(m_targetAnchorLineType), 180 * 16); painter->setRenderHint(QPainter::Antialiasing, false); painter->restore(); }
QRectF Label::suffixRect() const { const QRectF thisRect = QGraphicsTextItem::boundingRect(); QRectF textRect = this->textRect(mProperties.suffix()); const qreal x = thisRect.right(); const qreal y = thisRect.top() + (thisRect.height() - textRect.height()) / 2; textRect.moveTo(x, y); return textRect; }
QRectF KWidget::rectToView() const { QGraphicsView *gview = view(); QRectF rt = rect(); QPointF pt = mapToScene(rt.topLeft()); QPoint vpt = gview->mapFromScene(pt); rt.moveTo(vpt); return rt; }
void Simulation::tick() { qreal elapsed_secs = m_time.elapsed() * 1000.0; Q_FOREACH(QGraphicsItem* item, childItems()) { Particle* p = qobject_cast<Particle*>(item); if (p != 0) { p->move(elapsed_secs); QRectF bounds = p->boundingRect(); bounds.moveTo(p->pos()); qDebug() << "Scheduling update for" << bounds; update(bounds); } }
void ResizeHandler::resize(QRectF newContents, QPointF newPos, bool needResizeParent) const { newContents.moveTo(0, 0); sortChildrenIfNeeded(); gripeIfMinimizesToChildrenContainer(newContents); if (!mTargetNode->isFolded()) { resizeAccordingToChildren(newContents, newPos); } normalizeSize(newContents); newContents.moveTo(newPos); mTargetNode->setGeometry(newContents); mTargetNode->storeGeometry(); mTargetNode->setPos(newPos); if (needResizeParent) { resizeParent(); } mTargetNode->updateLabels(); }
NodeElement *CopyHandler::clone(bool toCursorPos, bool searchForParents) { EditorViewScene *evscene = dynamic_cast<EditorViewScene *>(mNode.scene()); qReal::Id typeId = mNode.id().type(); qReal::Id resultId = evscene->createElement(typeId.toString(), QPointF(), searchForParents); NodeElement *result = dynamic_cast<NodeElement *>(evscene->getElem(resultId)); copyProperties(*result, mNode); copyChildren(*result, mNode); QRectF contents = mNode.contentsRect(); if (toCursorPos) { contents.moveTo(evscene->getMousePos()); result->setGeometry(contents); result->storeGeometry(); } else { contents.moveTo(mNode.pos()); result->setGeometry(contents); } return result; }
void QgsStatusBarCoordinatesWidget::dizzy() { if ( !mMapCanvas ) { return; } // constants should go to options so that people can customize them to their taste int d = 10; // max. translational dizziness offset int r = 4; // max. rotational dizzines angle QRectF rect = mMapCanvas->sceneRect(); if ( rect.x() < -d || rect.x() > d || rect.y() < -d || rect.y() > d ) return; // do not affect panning rect.moveTo(( qrand() % ( 2 * d ) ) - d, ( qrand() % ( 2 * d ) ) - d ); mMapCanvas->setSceneRect( rect ); QTransform matrix; matrix.rotate(( qrand() % ( 2 * r ) ) - r ); mMapCanvas->setTransform( matrix ); }
void FormText::lessFontSize() { QTextCursor c = textCursor(); if( c.hasSelection() ) { if( c.position() != c.selectionEnd() ) c.setPosition( c.selectionEnd() ); QTextCharFormat fmt = c.charFormat(); qreal s = fmt.fontPointSize(); s -= 1.0; if( s < 5.0 ) s = 5.0; fmt.setFontPointSize( s ); textCursor().setCharFormat( fmt ); } else { QFont f = font(); qreal s = f.pointSize(); s -= 1.0; if( s < 5.0 ) s = 5.0; f.setPointSize( s ); setFont( f ); } QRectF r = boundingRect(); r.moveTo( pos() ); d->m_proxy->setRect( r ); }
void CCJKShapeLine::Paint(QPainter * painter) { CJK_D(CCJKShapeLine); BeginPaint(painter); painter->drawLine(d->line); if (!d->sText.isEmpty()) { QPointF tmpPoint = d->line.pointAt(0.5); QFontMetrics fontMetrics(d->font); QRectF txtRect = fontMetrics.boundingRect(d->sText); txtRect.moveTo(tmpPoint); txtRect.translate(-txtRect.width() / 2, -txtRect.height() / 2); QPen tmpPen = d->pen; tmpPen.setColor(d->textColor); painter->setPen(tmpPen); painter->drawText(txtRect, d->sText); } DrawArrow(painter, d->line); EndPaint(painter); }
void CodeAtlas::UIItemModel::drawText( QPainter* painter, const QString& txt, const QFont& font, const QPointF& basePoint, unsigned alignFlag /*= Qt::AlignHCenter | Qt::AlignTop*/ ) { QFontMetricsF metrics(font); QRectF rect = metrics.boundingRect(txt); rect.moveTo(basePoint); float w = rect.width(); float h = rect.height(); float tx = 0.f, ty = 0.f; if (alignFlag & Qt::AlignRight) tx = -w; else if (alignFlag & Qt::AlignHCenter) tx = -w*0.5; if (alignFlag & Qt::AlignBottom) ty = -h; else if (alignFlag & Qt::AlignVCenter) ty = -h*0.5; rect.translate(tx, ty); painter->drawText(rect, Qt::AlignCenter, txt); }
void TeteNode::updateFrameRect(){ // First set the initial min max values to this object's bounding // box QRectF local_bound = boundingRect(); QRectF bound = local_bound; bound.moveTo(pos()); bound.translate(-local_bound.width()/2,-local_bound.height()/2); float start_min_x, start_min_y, start_max_x, start_max_y; float min_x = start_min_x = bound.topLeft().x();//frame_rect_.topLeft().x(); float min_y = start_min_y = bound.topLeft().y();//frame_rect_.topLeft().y(); float max_x = start_max_x = bound.bottomRight().x();//frame_rect_.bottomRight().x(); float max_y = start_max_y = bound.bottomRight().y();//frame_rect_.bottomRight().y(); std::vector<Link*> links = tete_->links(); Tete* other_node; // Should this be a const_iterator? for(std::vector<Link*>::const_iterator it = links.begin(); it != links.end(); ++it){ if((*it)->node_1() == tete_) other_node = (*it)->node_2(); else other_node = (*it)->node_1(); addTeteToMinMax(other_node, min_x, min_y, max_x, max_y); } // If nothing was added to one side, double the frame on that side, // so that the center node is more or less guaranteed to be centered. if(min_x == start_min_x) min_x -= (max_x - min_x); if(min_y == start_min_y) min_y -= (max_y - min_y); if(max_x == start_max_x) max_x += (max_x - min_x); if(max_y == start_max_y) max_y += (max_y - min_y); frame_rect_ = QRectF(QPointF(min_x, min_y), QPointF(max_x, max_y)).normalized(); }
void GanttPrintingDialog::printPage( int page, QPainter &painter ) { kDebug(planDbg())<<"page:"<<page<<"first"<<documentFirstPage()<<"last:"<<documentLastPage(); QRectF sourceRect = m_sceneRect; int p = page - documentFirstPage(); QRectF pageRect = printer().pageRect(); pageRect.moveTo( 0, 0 ); bool singlePage = m_gantt->m_printOptions.singlePage; int vert = singlePage ? 0 : p / m_horPages; int hor = singlePage ? 0 : p % m_horPages; if ( ! singlePage && documentLastPage() > documentFirstPage() ) { // print on multiple pages, so calculate rects to print qreal hh = vert == 0 ? m_headerHeight : 0; qreal ho = vert > 0 ? m_headerHeight : 0; sourceRect = QRectF( sourceRect.x() + ( pageRect.width() * hor ), sourceRect.y() + ( ( pageRect.height() * vert ) - ho ), pageRect.width(), pageRect.height() - hh ); kDebug(planDbg())<<p<<hor<<vert<<sourceRect; } painter.setClipRect( pageRect.adjusted( -1.0, -1.0, 1.0, 1.0 ) ); // QT5TODO // m_gantt->print( &painter, pageRect, sourceRect, hor == 0 && m_gantt->m_printOptions.printRowLabels, vert == 0 ); }
void NodeElement::initRenderedDiagram() { if (!mIsExpanded || mLogicalAssistApi.logicalRepoApi().outgoingExplosion(logicalId()) == Id()) { return; } EditorViewScene *evScene = dynamic_cast<EditorViewScene *>(scene()); if (!evScene) { return; } const Id diagram = mLogicalAssistApi.logicalRepoApi().outgoingExplosion(logicalId()); const Id graphicalDiagram = mGraphicalAssistApi.graphicalIdsByLogicalId(diagram)[0]; EditorView view(evScene->models(), evScene->controller(), evScene->customizer(), graphicalDiagram); view.mutableScene().setNeedDrawGrid(false); view.mutableMvIface().configure(mGraphicalAssistApi, mLogicalAssistApi, mModels.exploser()); view.mutableMvIface().setModel(evScene->models().graphicalModel()); view.mutableMvIface().setLogicalModel(evScene->models().logicalModel()); view.mutableMvIface().setRootIndex(mGraphicalAssistApi.indexById(graphicalDiagram)); QRectF sceneRect = view.editorViewScene().itemsBoundingRect(); QImage image(sceneRect.size().toSize(), QImage::Format_RGB32); QPainter painter(&image); QBrush brush(Qt::SolidPattern); brush.setColor(Qt::white); painter.setBrush(brush); painter.setPen(QPen(Qt::white)); painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing); sceneRect.moveTo(QPointF()); painter.drawRect(sceneRect); view.mutableScene().render(&painter); mRenderedDiagram = image; }
void Annotations::adjust( QRectF& rc, Qt::Alignment align ) const { int xoffs(0), yoffs(0); if ( align & Qt::AlignLeft ) { xoffs = 0; } else if ( align & Qt::AlignHCenter ) { xoffs = -rc.width() / 2; } else if ( align & Qt::AlignRight ) { xoffs = -rc.width(); } if ( align & Qt::AlignTop ) { yoffs = 0; } else if ( align & Qt::AlignVCenter ) { yoffs = -rc.height() / 2; } else if ( align & Qt::AlignBottom ) { yoffs = -rc.height(); } rc.moveTo( rc.x() + xoffs, rc.y() + yoffs ); rc.adjust( 1, 1, 1, 1 ); }
QRectF KItemListViewLayouter::itemRect(int index) const { const_cast<KItemListViewLayouter*>(this)->doLayout(); if (index < 0 || index >= m_itemInfos.count()) { return QRectF(); } if (m_scrollOrientation == Qt::Horizontal) { // Rotate the logical direction which is always vertical by 90° // to get the physical horizontal direction const QRectF& b = m_itemInfos[index].rect; QRectF bounds(b.y(), b.x(), b.height(), b.width()); QPointF pos = bounds.topLeft(); pos.rx() -= m_scrollOffset; bounds.moveTo(pos); return bounds; } QRectF bounds = m_itemInfos[index].rect; bounds.moveTo(bounds.topLeft() - QPointF(m_itemOffset, m_scrollOffset)); return bounds; }
bool ExpandCommand::execute() { NodeElementCommand::execute(); delete mResizeCommand; mResizeCommand = new ResizeCommand(mScene, mNode->id()); mResizeCommand->startTracking(); QRectF newContents = mNode->contentsRect(); if (!mNode->isExpanded()) { newContents.setWidth(2 * newContents.width()); newContents.setHeight(2 * newContents.height()); } else { newContents.setWidth(newContents.width() / 2); newContents.setHeight(newContents.height() / 2); } newContents.moveTo(mNode->pos()); mNode->setGeometry(newContents); changeExpanded(); mNode->resize(); mResizeCommand->stopTracking(); mResizeCommand->redo(); return true; }
QRectF MovableRectangle::_moveRect(Direction dir){ QRectF r = this->rect->rect(); int boardHeight = this->world->height(); int boardWidth = this->world->width(); switch(dir){ case Up: r.moveTo(r.x(),r.y()-velocity); if(r.y() < 0){ r.moveTo(r.x(),0); this->direction = PhysicsUtils::reverseDirection(this->direction); } break; case Down: r.moveTo(r.x(),r.y()+velocity); if( (r.y() + r.height()) > boardHeight){ r.moveTo(r.x(),boardHeight-r.height()-1); this->direction = PhysicsUtils::reverseDirection(this->direction); } break; case Left: r.moveTo(r.x()-velocity,r.y()); if(r.x()-velocity < 0){ r.moveTo(0,r.y()); this->direction = PhysicsUtils::reverseDirection(this->direction); } break; case Right: r.moveTo(r.x()+velocity,r.y()); if( (r.x() + r.width()) > boardWidth){ r.moveTo(boardWidth - r.width()-1,r.y()); this->direction = PhysicsUtils::reverseDirection(this->direction); } break; } return r; }
bool TraceGraphPoint::snapPointToOthers(QPointF* i_newPoint) const { LOG_DEBUG("snapPointToOthers"); bool hasSnapped = false; QGraphicsScene* aScene = scene(); if (!aScene) { return hasSnapped; } // create a bounding box rectanle at the scene location of the object QRectF sceneRect = boundingRect(); sceneRect.moveTo(scenePos()); sceneRect.adjust(-2 * TraceGraphPoint::m_searchDistance, -2 * TraceGraphPoint::m_searchDistance, 2 * TraceGraphPoint::m_searchDistance, 2 * TraceGraphPoint::m_searchDistance); int distance; for (QGraphicsItem* item : scene()->items(sceneRect, Qt::IntersectsItemBoundingRect)) { if (item->type() != TraceGraphPoint::Type) { LOG_DEBUG("Found an item which is not a point"); continue; } LOG_DEBUG("Found a point"); if (parentItem() == item->parentItem()) { LOG_DEBUG("Found me or a sibbling"); continue; } distance = ((m_startPointAtMouseDown + *i_newPoint) - item->scenePos()).manhattanLength(); if (distance <= TraceGraphPoint::m_searchDistance) { LOG_DEBUG("old point is: " << i_newPoint->x() << ", " << i_newPoint->y()); *i_newPoint = item->scenePos() - m_startPointAtMouseDown; LOG_DEBUG("new point is: " << i_newPoint->x() << ", " << i_newPoint->y()); hasSnapped = true; LOG_DEBUG("Found a companion!"); break; } } return hasSnapped; }
void TeteNode::addTeteToMinMax(Tete* tete, float& min_x, float& min_y, float& max_x, float& max_y) { //return; if(tete == NULL) return; if(tete->tete_node() == NULL) return; QRectF local_bound = tete->tete_node()->boundingRect(); QRectF bound = local_bound; bound.moveTo(tete->tete_node()->pos()); bound.translate(-local_bound.width()/2,-local_bound.height()/2); if(bound.topLeft().x() < min_x) min_x = bound.topLeft().x(); if(bound.topLeft().y() < min_y) min_y = bound.topLeft().y(); if(bound.bottomRight().x() > max_x) max_x = bound.bottomRight().x(); if(bound.bottomRight().y() > max_y) max_y = bound.bottomRight().y(); }
void SingleCellViewGraphPanelPlotWidget::drawCoordinates(QPainter *pPainter, const QPointF &pCoordinates, const QColor &pBackgroundColor, const QColor &pForegroundColor, const Location &pLocation, const bool &pCanMoveLocation) { // Retrieve the size of coordinates as they will appear on the screen, // which means using the same font as the one used for the axes pPainter->setFont(axisFont(QwtPlot::xBottom)); QString coords = QString("(%1, %2)").arg(QString::number(pCoordinates.x()), QString::number(pCoordinates.y())); QRect desktopGeometry = qApp->desktop()->availableGeometry(); QRectF coordsRect = pPainter->boundingRect(QRectF(0.0, 0.0, desktopGeometry.width(), desktopGeometry.height()), coords); // Determine where the coordinates and its background should be drawn QPoint coordinates = QPoint(canvasMap(QwtPlot::xBottom).transform(pCoordinates.x()), canvasMap(QwtPlot::yLeft).transform(pCoordinates.y())); switch (pLocation) { case TopLeft: coordsRect.moveTo(coordinates.x()-coordsRect.right()-1, coordinates.y()-coordsRect.bottom()-1); break; case TopRight: coordsRect.moveTo(coordinates.x()+2, coordinates.y()-coordsRect.bottom()-1); break; case BottomLeft: coordsRect.moveTo(coordinates.x()-coordsRect.right()-1, coordinates.y()+2); break; case BottomRight: coordsRect.moveTo(coordinates.x()+2, coordinates.y()+2); break; } if (pCanMoveLocation) { if (coordsRect.top() < 0) coordsRect.moveTop(coordinates.y()+2); if (coordsRect.left() < 0) coordsRect.moveLeft(coordinates.x()+2); if (coordsRect.bottom() > plotLayout()->canvasRect().height()) coordsRect.moveTop(coordinates.y()-coordsRect.height()-1); if (coordsRect.right() > plotLayout()->canvasRect().width()) coordsRect.moveLeft(coordinates.x()-coordsRect.width()-1); } // Draw a filled rectangle to act as the background of the coordinates // we are to show pPainter->fillRect(coordsRect, pBackgroundColor); // Draw the text for the coordinates, using a white pen QPen pen = pPainter->pen(); pen.setColor(pForegroundColor); pPainter->setPen(pen); pPainter->drawText(coordsRect, coords); }
void PanelAppletOverlay::mouseMoveEvent(QMouseEvent *event) { if (!m_layout || !m_applet) { //kDebug() << "no layout"; return; } const int margin = 9; if (m_applet->inherits("PanelSpacer")) { if (m_applet->formFactor() == Plasma::Horizontal) { if (event->pos().x() < margin || event->pos().x() > m_applet->size().width() - margin) { setCursor(Qt::SizeHorCursor); } else { setCursor(Qt::ArrowCursor); } } else if (m_applet->formFactor() == Plasma::Vertical) { if (event->pos().y() < margin || event->pos().y() > m_applet->size().height() - margin) { setCursor(Qt::SizeVerCursor); } else { setCursor(Qt::ArrowCursor); } } } if (!m_clickDrag && !(event->buttons() & Qt::LeftButton)) { //kDebug() << "no left button and we aren't click dragging"; return; } Plasma::FormFactor f = m_applet->formFactor(); if (!m_applet->inherits("PanelSpacer") && (((f != Plasma::Horizontal && f != Plasma::Vertical) && rect().intersects(m_applet->rect().toRect())) || ((f == Plasma::Horizontal || f == Plasma::Vertical) && !rect().contains(event->globalPos()))) ) { Plasma::View *view = Plasma::View::topLevelViewAt(event->globalPos()); //kDebug() << "checking view" << view << m_applet->view(); if (!view) { view = dynamic_cast<Plasma::View*>(parent()); } if (!view) { return; } if (view != m_applet->view() && (event->buttons() & Qt::LeftButton)) { Plasma::Containment *c = view->containment(); if (!c) { return; } syncOrientation(); syncGeometry(); if (m_spacer) { if (m_layout) { m_layout->removeItem(m_spacer); } m_spacer->deleteLater(); m_spacer = 0; } QPointF pos = c->view()->mapFromGlobal(event->globalPos()); QRectF g = m_applet->geometry(); pos += QPoint(m_offset, m_offset); g.moveTo(pos); m_applet->setGeometry(g); m_layout = 0; c->addApplet(m_applet, pos, true); m_applet->flushPendingConstraintsEvents(); m_applet->setPos(pos); releaseMouse(); emit moved(this); return; } } else if (m_applet->inherits("PanelSpacer") && m_dragAction != Move) { if (m_applet->formFactor() == Plasma::Horizontal) { if (m_dragAction == LeftResize) { int fixedWidth = m_applet->size().width()+(m_lastGlobalPos.x() - event->globalPos().x()); m_applet->setPos(m_applet->pos().x()-(fixedWidth-m_applet->size().width()), m_applet->pos().y()); m_applet->setMinimumWidth(fixedWidth); m_applet->setMaximumWidth(fixedWidth); } else if (m_dragAction == RightResize) { int fixedWidth = m_applet->size().width()-(m_lastGlobalPos.x() - event->globalPos().x()); m_applet->setMinimumWidth(fixedWidth); m_applet->setMaximumWidth(fixedWidth); } } else if (m_applet->formFactor() == Plasma::Vertical) { if (m_dragAction == LeftResize) { int fixedHeight = m_applet->size().height()+(m_lastGlobalPos.y() - event->globalPos().y()); m_applet->setPos(m_applet->pos().x(), m_applet->pos().y()-(fixedHeight-m_applet->size().height())); m_applet->setMinimumHeight(fixedHeight); m_applet->setMaximumHeight(fixedHeight); } else if (m_dragAction == RightResize) { int fixedHeight = m_applet->size().height()-(m_lastGlobalPos.y() - event->globalPos().y()); m_applet->setMinimumHeight(fixedHeight); m_applet->setMaximumHeight(fixedHeight); } } m_lastGlobalPos = event->globalPos(); return; } if (!m_spacer) { m_spacer = new AppletMoveSpacer(m_applet); m_spacer->setMinimumSize(m_applet->geometry().size()); m_spacer->setMaximumSize(m_applet->geometry().size()); if (m_layout) { m_layout->removeItem(m_applet); m_layout->insertItem(m_index, m_spacer); } } QPoint p = mapToParent(event->pos()); QRectF g = m_applet->geometry(); //kDebug() << p << g << "<-- movin'?"; if (m_orientation == Qt::Horizontal) { g.moveLeft(p.x() + m_offset); } else { g.moveTop(p.y() + m_offset); } m_applet->setGeometry(g); //FIXME: assumption on how panel containment works, presence of a non applet spacer in last position (if they were swapped would be impossible to save and restore) if ((m_index > 0 && m_layout->itemAt(m_index - 1)) || m_index == 0) { const bool prevIsApplet = dynamic_cast<Plasma::Applet*>(m_layout->itemAt(m_index - 1)) != 0; const bool nextIsApplet = dynamic_cast<Plasma::Applet*>(m_layout->itemAt(m_index + 1)) != 0; QPointF mousePos = event->pos() + g.topLeft(); // swap items if we pass completely over the next/previous item or cross // more than halfway across it, whichever comes first if (m_orientation == Qt::Horizontal) { //kDebug() << prevIsApplet << m_prevGeom << g << nextIsApplet << m_nextGeom; if (QApplication::layoutDirection() == Qt::RightToLeft) { if (prevIsApplet && m_prevGeom.isValid() && mousePos.x() >= m_prevGeom.right()) { swapWithPrevious(); } else if (nextIsApplet && m_nextGeom.isValid() && mousePos.x() <= m_nextGeom.left()) { swapWithNext(); } } else if (prevIsApplet && m_prevGeom.isValid() && mousePos.x() <= m_prevGeom.left()) { swapWithPrevious(); } else if (nextIsApplet && m_nextGeom.isValid() && mousePos.x() >= m_nextGeom.right()) { swapWithNext(); } } else if (prevIsApplet && m_prevGeom.isValid() && mousePos.y() <= m_prevGeom.top()) { swapWithPrevious(); } else if (nextIsApplet && m_nextGeom.isValid() && mousePos.y() >= m_nextGeom.bottom()) { swapWithNext(); } } m_lastGlobalPos = event->globalPos(); //kDebug() << "================================="; }