Exemplo n.º 1
0
void AbstractPlot::init(){
	graphicsItem()->setFlag(QGraphicsItem::ItemIsMovable, true);
	graphicsItem()->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
	graphicsItem()->setFlag(QGraphicsItem::ItemIsSelectable, true);
	graphicsItem()->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
    graphicsItem()->setFlag(QGraphicsItem::ItemIsFocusable, true);
}
Exemplo n.º 2
0
void CartesianPlotLegend::init(){
	Q_D(CartesianPlotLegend);

	KConfig config;
	KConfigGroup group = config.group( "CartesianPlotLegend" );

	d->labelFont = group.readEntry("LabelsFont", QFont());
	d->labelFont.setPixelSize( Worksheet::convertToSceneUnits( 10, Worksheet::Point ) );

	d->labelColor = Qt::black;
	d->labelColumnMajor = true;
	d->lineSymbolWidth = group.readEntry("LineSymbolWidth", Worksheet::convertToSceneUnits(1, Worksheet::Centimeter));
	d->rowCount = 0;
	d->columnCount = 0;

	d->position.horizontalPosition = CartesianPlotLegend::hPositionRight;
	d->position.verticalPosition = CartesianPlotLegend::vPositionBottom;

	//Title
 	d->title = new TextLabel(this->name(), TextLabel::PlotLegendTitle);
	d->title->setText(this->name());
	addChild(d->title);
	d->title->setHidden(true);
	d->title->setParentGraphicsItem(graphicsItem());
	d->title->graphicsItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
	connect(d->title, SIGNAL(changed()), this, SLOT(retransform()));

	//Background
	d->backgroundType = (PlotArea::BackgroundType) group.readEntry("BackgroundType", (int) PlotArea::Color);
	d->backgroundColorStyle = (PlotArea::BackgroundColorStyle) group.readEntry("BackgroundColorStyle", (int) PlotArea::SingleColor);
	d->backgroundImageStyle = (PlotArea::BackgroundImageStyle) group.readEntry("BackgroundImageStyle", (int) PlotArea::Scaled);
	d->backgroundBrushStyle = (Qt::BrushStyle) group.readEntry("BackgroundBrushStyle", (int) Qt::SolidPattern);
	d->backgroundFileName = group.readEntry("BackgroundFileName", QString());
	d->backgroundFirstColor = group.readEntry("BackgroundFirstColor", QColor(Qt::white));
	d->backgroundSecondColor = group.readEntry("BackgroundSecondColor", QColor(Qt::black));
	d->backgroundOpacity = group.readEntry("BackgroundOpacity", 1.0);

	//Border
	d->borderPen = QPen(group.readEntry("BorderColor", QColor(Qt::black)),
										 group.readEntry("BorderWidth", Worksheet::convertToSceneUnits(1.0, Worksheet::Point)),
										 (Qt::PenStyle) group.readEntry("BorderStyle", (int)Qt::SolidLine));
	d->borderCornerRadius = group.readEntry("BorderCornerRadius", 0.0);
	d->borderOpacity = group.readEntry("BorderOpacity", 1.0);

	//Layout
	d->layoutTopMargin =  group.readEntry("LayoutTopMargin", Worksheet::convertToSceneUnits(0.2, Worksheet::Centimeter));
	d->layoutBottomMargin = group.readEntry("LayoutBottomMargin", Worksheet::convertToSceneUnits(0.2, Worksheet::Centimeter));
	d->layoutLeftMargin = group.readEntry("LayoutLeftMargin", Worksheet::convertToSceneUnits(0.2, Worksheet::Centimeter));
	d->layoutRightMargin = group.readEntry("LayoutRightMargin", Worksheet::convertToSceneUnits(0.2, Worksheet::Centimeter));
	d->layoutVerticalSpacing = group.readEntry("LayoutVerticalSpacing", Worksheet::convertToSceneUnits(0.1, Worksheet::Centimeter));
	d->layoutHorizontalSpacing = group.readEntry("LayoutHorizontalSpacing", Worksheet::convertToSceneUnits(0.1, Worksheet::Centimeter));
	d->layoutColumnCount = group.readEntry("LayoutColumnCount", 1);

	graphicsItem()->setFlag(QGraphicsItem::ItemIsSelectable, true);
	graphicsItem()->setFlag(QGraphicsItem::ItemIsMovable);
	graphicsItem()->setFlag(QGraphicsItem::ItemSendsGeometryChanges);

	this->initActions();
}
Exemplo n.º 3
0
void QGraphicsCompleter::showPopup(const QRect& rect)
{
    Qt::LayoutDirection dir = Qt::LeftToRight;
    const int maxVisibleItems = 7;
    QPointF pos;
    int rh, w;

    const QRect screen = p_proxyPopup->scene()->views().at(0)->viewport()->geometry();
    QAbstractItemView *popup = static_cast<QAbstractItemView *>(p_proxyPopup->widget());

    int h = (popup->sizeHintForRow(0) * qMin(maxVisibleItems, popup->model()->rowCount()) + 3) + 3;
    QScrollBar *hsb = popup->horizontalScrollBar();
    if (hsb && hsb->isVisible())
        h += popup->horizontalScrollBar()->sizeHint().height();

    if (rect.isValid()) {
        rh = rect.height();
        w = rect.width();
        pos = rect.bottomLeft();
    } else {
        rh = graphicsItem()->boundingRect().height();
        pos = graphicsItem()->mapRectToScene(
                graphicsItem()->boundingRect()).bottomLeft();
        w = popup->width();
    }

    if (w > screen.width())
        w = screen.width();
    if ((pos.x() + w) > (screen.x() + screen.width()))
        pos.setX(screen.x() + screen.width() - w);
    if (pos.x() < screen.x())
        pos.setX(screen.x());

    int top = pos.y() - rh - screen.top() + 2;
    int bottom = screen.bottom() - pos.y();
    h = qMax(h, popup->minimumHeight());
    if (h > bottom) {
        h = qMin(qMax(top, bottom), h);

        if (top > bottom)
            pos.setY(pos.y() - h - rh+ 2);
    }

    popup->setGeometry(pos.x(), pos.y(), w, h+5);
    p_proxyPopup->update();

    if (!p_proxyPopup->isVisible())
        p_proxyPopup->show();

}
Exemplo n.º 4
0
int RectTool::cursorPressEvent(CanvasCursorEvent *event)
{
	if (d->mode != NoOperation)
		return 0;
	
	// pass event to the graphics item
	
	auto item = graphicsItem()->scene()->itemAt(event->viewPos, QTransform());
	if (item && item != d->frameItem)
	{
		event->ignore();
		return 0;
	}
	
	d->updateManager->setEnabled(true);
	
	d->clickedLayer = layerScene()->rootLayer()->descendantAt(event->data.pos.toQPoint(), handleRadius);
	d->clickedWithShift = event->modifiers() & Qt::ShiftModifier;
	
	if (d->selectingMode == SelectImmediately)
	{
		// select immediately the clicked layer
		selectLayer(d->clickedLayer, d->clickedWithShift);
	}
	else
	{
		// the clicked layer is already selected, selection is unchanged and current is set to the clicked layer
		if (layerScene()->selection().contains(d->clickedLayer))
		{
			layerScene()->setCurrent(d->clickedLayer);
		}
		// clear selection to insert a new layer
		else
		{
			layerScene()->setSelection({});
		}
	}
	
	// decide mode
	
	// if already layers are selected and a layer is clicked, mode will be Dragging
	if (d->selectedLayerInfos.size() && d->clickedLayer)
		d->mode = Dragging;
	// if no layer is selected or no layer is clicked, go to Inserting mode if addingType is not NoAdding
	else if (d->addingType != NoAdding)
		d->mode = Inserting;
	
	// there is nothing to do
	if (d->mode == NoOperation)
		return 0;
	
	// save drag origin
	d->dragDistanceEnough = false;
	d->dragStartPos = event->data.pos;

	return 0;
}
Exemplo n.º 5
0
void RectTool::addHandle(int handleTypes, qreal zValue)
{
	auto handle = new RectHandleItem(handleTypes, graphicsItem());
	
	handle->setVisible(true);
	handle->setZValue(zValue);
	d->handles << handle;
	
	handle->setOnHandleMoved(std::bind(&RectTool::onHandleMoved, this, std::placeholders::_1, std::placeholders::_2));
	handle->setOnHandleMoveFinished(std::bind(&RectTool::onHandleMoveFinished, this));
}
Exemplo n.º 6
0
QDomNode WbNewItem::serializeToSvg(QDomDocument *doc) {
	if(!graphicsItem()) {
		return QDomDocumentFragment();
	}

	// Generate the SVG using QSvgGenerator
	QBuffer buffer;

	QSvgGenerator generator;
	generator.setOutputDevice(&buffer);

	QPainter painter;
	QStyleOptionGraphicsItem options;
	painter.begin(&generator);
	graphicsItem()->paint(&painter, &options);
	painter.end();

	// qDebug("Serialized SVG doc:");
	// qDebug(buffer.buffer());

	// Parse the children of the new root <svg/> from the buffer to a document fragment
	// also add an 'id' attribute to each of the children
	doc->setContent(buffer.buffer());
	QDomDocumentFragment fragment = doc->createDocumentFragment();

	for(QDomNode n = doc->documentElement().lastChild(); !n.isNull(); n = n.previousSibling()) {
		// skip <title/>, <desc/>, and <defs/>
		if(n.isElement() &&
			!(n.nodeName() == "title"
				|| n.nodeName() == "desc"
				|| n.nodeName() == "defs")) {
			n.toElement().setAttribute("id", "e" + SxeSession::generateUUID());
			fragment.insertBefore(n, QDomNode());
		}
	}

	return fragment;
}
Exemplo n.º 7
0
/*!
    Returns a pixmap with the source painted into it.

    The \a system specifies which coordinate system to be used for the source.
    The optional \a offset parameter returns the offset where the pixmap should
    be painted at using the current painter.

    The \a mode determines how much of the effect the pixmap will contain.
    By default, the pixmap will contain the whole effect.

    The returned pixmap is bound to the current painter's device rectangle when
    \a system is Qt::DeviceCoordinates.

    \sa QGraphicsEffect::draw(), boundingRect()
*/
QPixmap QGraphicsEffectSource::pixmap(Qt::CoordinateSystem system, QPoint *offset, QGraphicsEffect::PixmapPadMode mode) const
{
    Q_D(const QGraphicsEffectSource);

    // Shortcut, no cache for childless pixmap items...
    const QGraphicsItem *item = graphicsItem();
    if (system == Qt::LogicalCoordinates && mode == QGraphicsEffect::NoPad && item && isPixmap()) {
        const QGraphicsPixmapItem *pixmapItem = static_cast<const QGraphicsPixmapItem *>(item);
        if (offset)
            *offset = pixmapItem->offset().toPoint();
        return pixmapItem->pixmap();
    }

    if (system == Qt::DeviceCoordinates && item
        && !static_cast<const QGraphicsItemEffectSourcePrivate *>(d_func())->info) {
        qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context");
        return QPixmap();
    }

    QPixmap pm;
    if (item && d->m_cachedSystem == system && d->m_cachedMode == mode)
        QPixmapCache::find(d->m_cacheKey, &pm);

    if (pm.isNull()) {
        pm = d->pixmap(system, &d->m_cachedOffset, mode);
        d->m_cachedSystem = system;
        d->m_cachedMode = mode;

        d->invalidateCache();
        d->m_cacheKey = QPixmapCache::insert(pm);
    }

    if (offset)
        *offset = d->m_cachedOffset;

    return pm;
}
Exemplo n.º 8
0
 inline QGraphicsRectItem *rectItem() {
     return static_cast<QGraphicsRectItem *>(graphicsItem());
 }