Badge moved to md.
This commit is contained in:
parent
49778ebc24
commit
168ac029bf
|
@ -3,6 +3,9 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include "lib/qtmaterialstyle.h"
|
#include "lib/qtmaterialstyle.h"
|
||||||
|
|
||||||
|
namespace md
|
||||||
|
{
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \class QtMaterialBadgePrivate
|
* \class QtMaterialBadgePrivate
|
||||||
* \internal
|
* \internal
|
||||||
|
@ -11,7 +14,7 @@
|
||||||
/*!
|
/*!
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
QtMaterialBadgePrivate::QtMaterialBadgePrivate(QtMaterialBadge *q)
|
BadgePrivate::BadgePrivate(Badge *q)
|
||||||
: q_ptr(q)
|
: q_ptr(q)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -19,16 +22,16 @@ QtMaterialBadgePrivate::QtMaterialBadgePrivate(QtMaterialBadge *q)
|
||||||
/*!
|
/*!
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
QtMaterialBadgePrivate::~QtMaterialBadgePrivate()
|
BadgePrivate::~BadgePrivate()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
void QtMaterialBadgePrivate::init()
|
void BadgePrivate::init()
|
||||||
{
|
{
|
||||||
Q_Q(QtMaterialBadge);
|
Q_Q(Badge);
|
||||||
|
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
|
@ -49,38 +52,38 @@ void QtMaterialBadgePrivate::init()
|
||||||
* \class QtMaterialBadge
|
* \class QtMaterialBadge
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QtMaterialBadge::QtMaterialBadge(QWidget *parent)
|
Badge::Badge(QWidget *parent)
|
||||||
: QtMaterialOverlayWidget(parent),
|
: OverlayWidget(parent),
|
||||||
d_ptr(new QtMaterialBadgePrivate(this))
|
d_ptr(new BadgePrivate(this))
|
||||||
{
|
{
|
||||||
d_func()->init();
|
d_func()->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialBadge::QtMaterialBadge(const QIcon &icon, QWidget *parent)
|
Badge::Badge(const QIcon &icon, QWidget *parent)
|
||||||
: QtMaterialOverlayWidget(parent),
|
: OverlayWidget(parent),
|
||||||
d_ptr(new QtMaterialBadgePrivate(this))
|
d_ptr(new BadgePrivate(this))
|
||||||
{
|
{
|
||||||
d_func()->init();
|
d_func()->init();
|
||||||
|
|
||||||
setIcon(icon);
|
setIcon(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialBadge::QtMaterialBadge(const QString &text, QWidget *parent)
|
Badge::Badge(const QString &text, QWidget *parent)
|
||||||
: QtMaterialOverlayWidget(parent),
|
: OverlayWidget(parent),
|
||||||
d_ptr(new QtMaterialBadgePrivate(this))
|
d_ptr(new BadgePrivate(this))
|
||||||
{
|
{
|
||||||
d_func()->init();
|
d_func()->init();
|
||||||
|
|
||||||
setText(text);
|
setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialBadge::~QtMaterialBadge()
|
Badge::~Badge()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialBadge::setUseThemeColors(bool value)
|
void Badge::setUseThemeColors(bool value)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialBadge);
|
Q_D(Badge);
|
||||||
|
|
||||||
if (d->useThemeColors == value) {
|
if (d->useThemeColors == value) {
|
||||||
return;
|
return;
|
||||||
|
@ -90,16 +93,16 @@ void QtMaterialBadge::setUseThemeColors(bool value)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QtMaterialBadge::useThemeColors() const
|
bool Badge::useThemeColors() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialBadge);
|
Q_D(const Badge);
|
||||||
|
|
||||||
return d->useThemeColors;
|
return d->useThemeColors;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialBadge::setTextColor(const QColor &color)
|
void Badge::setTextColor(const QColor &color)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialBadge);
|
Q_D(Badge);
|
||||||
|
|
||||||
d->textColor = color;
|
d->textColor = color;
|
||||||
|
|
||||||
|
@ -107,20 +110,20 @@ void QtMaterialBadge::setTextColor(const QColor &color)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor QtMaterialBadge::textColor() const
|
QColor Badge::textColor() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialBadge);
|
Q_D(const Badge);
|
||||||
|
|
||||||
if (d->useThemeColors || !d->textColor.isValid()) {
|
if (d->useThemeColors || !d->textColor.isValid()) {
|
||||||
return QtMaterialStyle::instance().themeColor("canvas");
|
return Style::instance().themeColor("canvas");
|
||||||
} else {
|
} else {
|
||||||
return d->textColor;
|
return d->textColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialBadge::setBackgroundColor(const QColor &color)
|
void Badge::setBackgroundColor(const QColor &color)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialBadge);
|
Q_D(Badge);
|
||||||
|
|
||||||
d->backgroundColor = color;
|
d->backgroundColor = color;
|
||||||
|
|
||||||
|
@ -128,64 +131,64 @@ void QtMaterialBadge::setBackgroundColor(const QColor &color)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor QtMaterialBadge::backgroundColor() const
|
QColor Badge::backgroundColor() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialBadge);
|
Q_D(const Badge);
|
||||||
|
|
||||||
if (d->useThemeColors || !d->backgroundColor.isValid()) {
|
if (d->useThemeColors || !d->backgroundColor.isValid()) {
|
||||||
return QtMaterialStyle::instance().themeColor("accent1");
|
return Style::instance().themeColor("accent1");
|
||||||
} else {
|
} else {
|
||||||
return d->backgroundColor;
|
return d->backgroundColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialBadge::setRelativePosition(const QPointF &pos)
|
void Badge::setRelativePosition(const QPointF &pos)
|
||||||
{
|
{
|
||||||
setRelativePosition(pos.x(), pos.y());
|
setRelativePosition(pos.x(), pos.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialBadge::setRelativePosition(qreal x, qreal y)
|
void Badge::setRelativePosition(qreal x, qreal y)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialBadge);
|
Q_D(Badge);
|
||||||
|
|
||||||
d->x = x;
|
d->x = x;
|
||||||
d->y = y;
|
d->y = y;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF QtMaterialBadge::relativePosition() const
|
QPointF Badge::relativePosition() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialBadge);
|
Q_D(const Badge);
|
||||||
|
|
||||||
return QPointF(d->x, d->y);
|
return QPointF(d->x, d->y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialBadge::setRelativeXPosition(qreal x)
|
void Badge::setRelativeXPosition(qreal x)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialBadge);
|
Q_D(Badge);
|
||||||
|
|
||||||
d->x = x;
|
d->x = x;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal QtMaterialBadge::relativeXPosition() const
|
qreal Badge::relativeXPosition() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialBadge);
|
Q_D(const Badge);
|
||||||
|
|
||||||
return d->x;
|
return d->x;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialBadge::setRelativeYPosition(qreal y)
|
void Badge::setRelativeYPosition(qreal y)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialBadge);
|
Q_D(Badge);
|
||||||
|
|
||||||
d->y = y;
|
d->y = y;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal QtMaterialBadge::relativeYPosition() const
|
qreal Badge::relativeYPosition() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialBadge);
|
Q_D(const Badge);
|
||||||
|
|
||||||
return d->y;
|
return d->y;
|
||||||
}
|
}
|
||||||
|
@ -193,30 +196,30 @@ qreal QtMaterialBadge::relativeYPosition() const
|
||||||
/*!
|
/*!
|
||||||
* \reimp
|
* \reimp
|
||||||
*/
|
*/
|
||||||
QSize QtMaterialBadge::sizeHint() const
|
QSize Badge::sizeHint() const
|
||||||
{
|
{
|
||||||
const int s = getDiameter();
|
const int s = getDiameter();
|
||||||
return QSize(s+4, s+4);
|
return QSize(s+4, s+4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialBadge::setIcon(const QIcon &icon)
|
void Badge::setIcon(const QIcon &icon)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialBadge);
|
Q_D(Badge);
|
||||||
|
|
||||||
d->icon = icon;
|
d->icon = icon;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon QtMaterialBadge::icon() const
|
QIcon Badge::icon() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialBadge);
|
Q_D(const Badge);
|
||||||
|
|
||||||
return d->icon;
|
return d->icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialBadge::setText(const QString &text)
|
void Badge::setText(const QString &text)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialBadge);
|
Q_D(Badge);
|
||||||
|
|
||||||
d->text = text;
|
d->text = text;
|
||||||
|
|
||||||
|
@ -229,9 +232,9 @@ void QtMaterialBadge::setText(const QString &text)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QtMaterialBadge::text() const
|
QString Badge::text() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialBadge);
|
Q_D(const Badge);
|
||||||
|
|
||||||
return d->text;
|
return d->text;
|
||||||
}
|
}
|
||||||
|
@ -239,11 +242,11 @@ QString QtMaterialBadge::text() const
|
||||||
/*!
|
/*!
|
||||||
* \reimp
|
* \reimp
|
||||||
*/
|
*/
|
||||||
void QtMaterialBadge::paintEvent(QPaintEvent *event)
|
void Badge::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
Q_D(QtMaterialBadge);
|
Q_D(Badge);
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
@ -253,7 +256,7 @@ void QtMaterialBadge::paintEvent(QPaintEvent *event)
|
||||||
QBrush brush;
|
QBrush brush;
|
||||||
brush.setStyle(Qt::SolidPattern);
|
brush.setStyle(Qt::SolidPattern);
|
||||||
brush.setColor(isEnabled() ? backgroundColor()
|
brush.setColor(isEnabled() ? backgroundColor()
|
||||||
: QtMaterialStyle::instance().themeColor("disabled"));
|
: Style::instance().themeColor("disabled"));
|
||||||
painter.setBrush(brush);
|
painter.setBrush(brush);
|
||||||
painter.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
|
|
||||||
|
@ -282,9 +285,9 @@ void QtMaterialBadge::paintEvent(QPaintEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int QtMaterialBadge::getDiameter() const
|
int Badge::getDiameter() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialBadge);
|
Q_D(const Badge);
|
||||||
|
|
||||||
if (d->icon.isNull()) {
|
if (d->icon.isNull()) {
|
||||||
return qMax(d->size.width(), d->size.height()) + d->padding;
|
return qMax(d->size.width(), d->size.height()) + d->padding;
|
||||||
|
@ -292,3 +295,5 @@ int QtMaterialBadge::getDiameter() const
|
||||||
return 24;
|
return 24;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -2,10 +2,12 @@
|
||||||
#define QTMATERIALBADGE_H
|
#define QTMATERIALBADGE_H
|
||||||
|
|
||||||
#include "lib/qtmaterialoverlaywidget.h"
|
#include "lib/qtmaterialoverlaywidget.h"
|
||||||
|
namespace md
|
||||||
|
{
|
||||||
|
|
||||||
class QtMaterialBadgePrivate;
|
class BadgePrivate;
|
||||||
|
|
||||||
class QtMaterialBadge : public QtMaterialOverlayWidget
|
class Badge : public OverlayWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -14,10 +16,10 @@ class QtMaterialBadge : public QtMaterialOverlayWidget
|
||||||
Q_PROPERTY(QPointF relativePosition WRITE setRelativePosition READ relativePosition)
|
Q_PROPERTY(QPointF relativePosition WRITE setRelativePosition READ relativePosition)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QtMaterialBadge(QWidget *parent = 0);
|
explicit Badge(QWidget *parent = 0);
|
||||||
explicit QtMaterialBadge(const QIcon &icon, QWidget *parent = 0);
|
explicit Badge(const QIcon &icon, QWidget *parent = 0);
|
||||||
explicit QtMaterialBadge(const QString &text, QWidget *parent = 0);
|
explicit Badge(const QString &text, QWidget *parent = 0);
|
||||||
~QtMaterialBadge();
|
~Badge();
|
||||||
|
|
||||||
void setUseThemeColors(bool value);
|
void setUseThemeColors(bool value);
|
||||||
bool useThemeColors() const;
|
bool useThemeColors() const;
|
||||||
|
@ -51,11 +53,13 @@ protected:
|
||||||
|
|
||||||
int getDiameter() const;
|
int getDiameter() const;
|
||||||
|
|
||||||
const QScopedPointer<QtMaterialBadgePrivate> d_ptr;
|
const QScopedPointer<BadgePrivate> d_ptr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(QtMaterialBadge)
|
Q_DISABLE_COPY(Badge)
|
||||||
Q_DECLARE_PRIVATE(QtMaterialBadge)
|
Q_DECLARE_PRIVATE(Badge)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QTMATERIALBADGE_H
|
#endif // QTMATERIALBADGE_H
|
||||||
|
|
|
@ -6,20 +6,22 @@
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
|
||||||
class QtMaterialBadge;
|
namespace md
|
||||||
|
|
||||||
class QtMaterialBadgePrivate
|
|
||||||
{
|
{
|
||||||
Q_DISABLE_COPY(QtMaterialBadgePrivate)
|
class Badge;
|
||||||
Q_DECLARE_PUBLIC(QtMaterialBadge)
|
|
||||||
|
class BadgePrivate
|
||||||
|
{
|
||||||
|
Q_DISABLE_COPY(BadgePrivate)
|
||||||
|
Q_DECLARE_PUBLIC(Badge)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QtMaterialBadgePrivate(QtMaterialBadge *q);
|
BadgePrivate(Badge *q);
|
||||||
~QtMaterialBadgePrivate();
|
~BadgePrivate();
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
QtMaterialBadge *const q_ptr;
|
Badge *const q_ptr;
|
||||||
QString text;
|
QString text;
|
||||||
QColor textColor;
|
QColor textColor;
|
||||||
QColor backgroundColor;
|
QColor backgroundColor;
|
||||||
|
@ -30,5 +32,6 @@ public:
|
||||||
int padding;
|
int padding;
|
||||||
bool useThemeColors;
|
bool useThemeColors;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QTMATERIALBADGE_P_H
|
#endif // QTMATERIALBADGE_P_H
|
||||||
|
|
Loading…
Reference in New Issue