##// END OF EJS Templates
Merge remote-tracking branch 'origin/5.7' into dev...
Merge remote-tracking branch 'origin/5.7' into dev Change-Id: I86dec1064d79704214e885681449ca347b193d66

File last commit:

r2864:47032ec192b3
r2895:e9a2e2a5e9c0 merge
Show More
legendmarkeritem.cpp
215 lines | 6.2 KiB | text/x-c | CppLexer
/ src / charts / legend / legendmarkeritem.cpp
Miikka Heikkinen
Updated license...
r2854 /****************************************************************************
Titta Heikkala
Updated license headers...
r2845 **
Miikka Heikkinen
Updated license...
r2854 ** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
Titta Heikkala
Updated license headers...
r2845 **
Miikka Heikkinen
Updated license...
r2854 ** This file is part of the Qt Charts module of the Qt Toolkit.
Titta Heikkala
Updated license headers...
r2845 **
Miikka Heikkinen
Updated license...
r2854 ** $QT_BEGIN_LICENSE:GPL$
Titta Heikkala
Updated license headers...
r2845 ** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
Miikka Heikkinen
Updated license...
r2854 ** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
Titta Heikkala
Updated license headers...
r2845 **
** $QT_END_LICENSE$
**
Miikka Heikkinen
Updated license...
r2854 ****************************************************************************/
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164
Titta Heikkala
Fix include syntax...
r2714 #include <QtGui/QPainter>
#include <QtWidgets/QGraphicsSceneEvent>
#include <QtWidgets/QGraphicsTextItem>
#include <QtGui/QTextDocument>
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164
Titta Heikkala
Fix include syntax...
r2714 #include <QtCharts/QLegend>
#include <private/qlegend_p.h>
#include <QtCharts/QLegendMarker>
#include <private/qlegendmarker_p.h>
#include <private/legendmarkeritem_p.h>
#include <private/chartpresenter_p.h>
sauimone
refactoring
r2167
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_BEGIN_NAMESPACE
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164
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)),
Miikka Heikkinen
Fix text item margins...
r2592 m_margin(3),
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);
Miikka Heikkinen
Fix text item margins...
r2592 m_textItem->document()->setDocumentMargin(ChartPresenter::textMargin());
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 {
Miikka Heikkinen
Fix legend markers truncation...
r2544 qreal 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;
Andy Shaw
Add support for showing tooltips when the legend text is truncated...
r2864 const QString html = ChartPresenter::truncatedText(m_textItem->font(), m_label, qreal(0.0),
width - x, rect.height(), truncatedRect);
m_textItem->setHtml(html);
if (m_marker->m_legend->showToolTips() && html != m_label)
m_textItem->setToolTip(m_label);
else
m_textItem->setToolTip(QString());
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164
Titta Heikkala
Fix multiline alignment...
r2607 m_textItem->setTextWidth(truncatedRect.width());
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
Fix text item margins...
r2592 // The textMargin adjustments to position are done to make default case rects less blurry with anti-aliasing
m_rectItem->setPos(m_margin - ChartPresenter::textMargin(), y / 2.0 - m_markerRect.height() / 2.0 + ChartPresenter::textMargin());
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)
QSizeF sh;
Miikka Heikkinen
Fix legend markers truncation...
r2544 switch (which) {
case Qt::MinimumSize: {
Titta Heikkala
Qt Charts project file structure change...
r2712 QRectF labelRect = ChartPresenter::textBoundingRect(m_textItem->font(),
QStringLiteral("..."));
Miikka Heikkinen
Fix legend markers truncation...
r2544 sh = QSizeF(labelRect.width() + (2.0 * m_margin) + m_space + m_markerRect.width(),
qMax(m_markerRect.height(), labelRect.height()) + (2.0 * m_margin));
break;
}
case Qt::PreferredSize: {
QRectF labelRect = ChartPresenter::textBoundingRect(m_textItem->font(), m_label);
sh = QSizeF(labelRect.width() + (2.0 * m_margin) + m_space + m_markerRect.width(),
qMax(m_markerRect.height(), labelRect.height()) + (2.0 * m_margin));
break;
}
default:
break;
}
return sh;
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 }
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);
}
Andy Shaw
Add support for showing tooltips when the legend text is truncated...
r2864 QString LegendMarkerItem::displayedLabel() const
{
return m_textItem->toHtml();
}
void LegendMarkerItem::setToolTip(const QString &tip)
{
m_textItem->setToolTip(tip);
}
sauimone
legendmarker hover signal test and fix
r2210
sauimone
added LegendMarkerItem. Updated new legend example to test clicked of LegendMarker
r2164 #include "moc_legendmarkeritem_p.cpp"
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_END_NAMESPACE