##// END OF EJS Templates
Added HTML support for various text items...
Added HTML support for various text items - HTML tags can now be used in chart titles, legends, and labels - '\n' does no longer cause line break in multi-line text items. HTML tag <br/> can be used for line break now. - Setting pen for axis titles and labels is deprecated - When setting brush for titles and labels, only the color is relevant - Logic for identifying label format specifiers was improved, so adding additional information to labels via label format string is now more viable. Task-number: QTRD-1912 Change-Id: I8fa56df56fd656e2a3e427eff4abf3481435eec7 Reviewed-by: Mika Salmela <mika.salmela@digia.com>

File last commit:

r2539:74f3dbde7a75
r2539:74f3dbde7a75
Show More
legendmarkeritem.cpp
181 lines | 4.6 KiB | text/x-c | CppLexer
/ src / legend / legendmarkeritem.cpp
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 /****************************************************************************
**
Miikka Heikkinen
Fixed the copyright year 2012 -> 2013
r2432 ** Copyright (C) 2013 Digia Plc
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 ** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the Qt Commercial Charts Add-on.
**
** $QT_BEGIN_LICENSE$
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QPainter>
#include <QGraphicsSceneEvent>
Miikka Heikkinen
Added HTML support for various text items...
r2539 #include <QGraphicsTextItem>
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164
sauimone
Legend can now handle clicked and do scrolling
r2183 #include "qlegend.h"
#include "qlegend_p.h"
#include "qlegendmarker.h"
sauimone
refactoring
r2167 #include "qlegendmarker_p.h"
sauimone
Legend can now handle clicked and do scrolling
r2183 #include "legendmarkeritem_p.h"
Miikka Heikkinen
Added HTML support for various text items...
r2539 #include "chartpresenter_p.h"
sauimone
refactoring
r2167
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 QTCOMMERCIALCHART_BEGIN_NAMESPACE
sauimone
refactoring
r2167 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) :
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 QGraphicsObject(parent),
sauimone
refactoring
r2167 m_marker(marker),
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 m_markerRect(0,0,10.0,10.0),
sauimone
commenting out usage of old marker implementation from legend. Legend now uses new markers.
r2170 m_boundingRect(0,0,0,0),
Miikka Heikkinen
Added HTML support for various text items...
r2539 m_textItem(new QGraphicsTextItem(this)),
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 m_rectItem(new QGraphicsRectItem(this)),
m_margin(4),
sauimone
Kinetic scrolling is back for legend
r2189 m_space(4),
sauimone
legendmarker hover signal test and fix
r2210 m_hovering(false),
sauimone
Kinetic scrolling is back for legend
r2189 m_pressPos(0, 0)
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 {
m_rectItem->setRect(m_markerRect);
Jani Honkonen
Fix deprecation errors from Qt5
r2241 setAcceptHoverEvents(true);
sauimone
legendmarker hover signal test and fix
r2210 }
LegendMarkerItem::~LegendMarkerItem()
{
if (m_hovering) {
emit m_marker->q_ptr->hovered(false);
}
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 }
void LegendMarkerItem::setPen(const QPen &pen)
{
m_rectItem->setPen(pen);
}
QPen LegendMarkerItem::pen() const
{
return m_rectItem->pen();
}
void LegendMarkerItem::setBrush(const QBrush &brush)
{
m_rectItem->setBrush(brush);
}
QBrush LegendMarkerItem::brush() const
{
return m_rectItem->brush();
}
void LegendMarkerItem::setFont(const QFont &font)
{
m_textItem->setFont(font);
QFontMetrics fn(font);
m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2);
updateGeometry();
}
QFont LegendMarkerItem::font() const
{
return m_textItem->font();
}
void LegendMarkerItem::setLabel(const QString label)
{
sauimone
tidying up legend marker code. Added QBarLegendMarker
r2174 m_label = label;
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 updateGeometry();
}
QString LegendMarkerItem::label() const
{
sauimone
tidying up legend marker code. Added QBarLegendMarker
r2174 return m_label;
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 }
void LegendMarkerItem::setLabelBrush(const QBrush &brush)
{
Miikka Heikkinen
Added HTML support for various text items...
r2539 m_textItem->setDefaultTextColor(brush.color());
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 }
QBrush LegendMarkerItem::labelBrush() const
{
Miikka Heikkinen
Added HTML support for various text items...
r2539 return QBrush(m_textItem->defaultTextColor());
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 }
sauimone
optional series parameter to markers function. code style fixes
r2193 void LegendMarkerItem::setGeometry(const QRectF &rect)
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 {
int width = rect.width();
Miikka Heikkinen
Added HTML support for various text items...
r2539 qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
QRectF truncatedRect;
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164
Miikka Heikkinen
Added HTML support for various text items...
r2539 m_textItem->setHtml(ChartPresenter::truncatedText(m_font, m_label, qreal(0.0), width - x, Qt::Horizontal, truncatedRect));
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164
Miikka Heikkinen
Added HTML support for various text items...
r2539 qreal y = qMax(m_markerRect.height() + 2 * m_margin, truncatedRect.height() + 2 * m_margin);
const QRectF &textRect = m_textItem->boundingRect();
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164
Miikka Heikkinen
Added HTML support for various text items...
r2539 m_textItem->setPos(x - m_margin, y / 2 - textRect.height() / 2);
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 m_rectItem->setRect(m_markerRect);
Miikka Heikkinen
Added HTML support for various text items...
r2539 m_rectItem->setPos(m_margin, y / 2 - m_markerRect.height() / 2);
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164
prepareGeometryChange();
Miikka Heikkinen
Added HTML support for various text items...
r2539 m_boundingRect = QRectF(0, 0, x + textRect.width() + m_margin, y);
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 }
sauimone
layout work started
r2168 QRectF LegendMarkerItem::boundingRect() const
{
return m_boundingRect;
}
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
Q_UNUSED(painter)
}
QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
{
Q_UNUSED(constraint)
QFontMetrics fn(m_textItem->font());
QSizeF sh;
switch (which) {
case Qt::MinimumSize:
sh = QSizeF(fn.boundingRect("...").width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
break;
case Qt::PreferredSize:
sauimone
tidying up legend marker code. Added QBarLegendMarker
r2174 sh = QSizeF(fn.boundingRect(m_label).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 break;
default:
break;
}
return sh;
}
sauimone
legendmarker hover signal test and fix
r2210 void LegendMarkerItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
m_hovering = true;
emit m_marker->q_ptr->hovered(true);
}
void LegendMarkerItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
m_hovering = false;
emit m_marker->q_ptr->hovered(false);
}
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 #include "moc_legendmarkeritem_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE