Remove Menu Item
This commit is contained in:
parent
e42d36307f
commit
5cd3a0bdf6
|
@ -30,8 +30,6 @@ SOURCES = \
|
|||
qtmaterialtextfield.cpp \
|
||||
qtmaterialtabs_internal.cpp \
|
||||
qtmaterialtabs.cpp \
|
||||
qtmaterialmenuitem_internal.cpp \
|
||||
qtmaterialmenuitem.cpp \
|
||||
qtmaterialscrollbar_internal.cpp \
|
||||
qtmaterialscrollbar.cpp
|
||||
HEADERS = \
|
||||
|
@ -82,9 +80,6 @@ HEADERS = \
|
|||
qtmaterialtabs_internal.h \
|
||||
qtmaterialtabs_p.h \
|
||||
qtmaterialtabs.h \
|
||||
qtmaterialmenuitem_internal.h \
|
||||
qtmaterialmenuitem_p.h \
|
||||
qtmaterialmenuitem.h \
|
||||
qtmaterialscrollbar_internal.h \
|
||||
qtmaterialscrollbar_p.h \
|
||||
qtmaterialscrollbar.h
|
||||
|
|
|
@ -1,115 +0,0 @@
|
|||
#include "qtmaterialmenuitem.h"
|
||||
#include "qtmaterialmenuitem_p.h"
|
||||
#include <QPainter>
|
||||
#include "qtmaterialmenuitem_internal.h"
|
||||
#include "lib/qtmaterialstyle.h"
|
||||
|
||||
/*!
|
||||
* \class QtMaterialMenuItemPrivate
|
||||
* \internal
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
QtMaterialMenuItemPrivate::QtMaterialMenuItemPrivate(QtMaterialMenuItem *q)
|
||||
: QtMaterialFlatButtonPrivate(q)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
QtMaterialMenuItemPrivate::~QtMaterialMenuItemPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
void QtMaterialMenuItemPrivate::init()
|
||||
{
|
||||
Q_Q(QtMaterialMenuItem);
|
||||
|
||||
highlighted = false;
|
||||
|
||||
QFont font(q->font());
|
||||
font.setCapitalization(QFont::MixedCase);
|
||||
font.setPointSize(11);
|
||||
font.setStyleName("Regular");
|
||||
q->setFont(font);
|
||||
|
||||
q->setOverlayStyle(Material::GrayOverlay);
|
||||
q->setForegroundColor(QtMaterialStyle::instance().themeColor("text"));
|
||||
q->setCornerRadius(0);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \class QtMaterialMenuItem
|
||||
*/
|
||||
|
||||
QtMaterialMenuItem::QtMaterialMenuItem(QWidget *parent)
|
||||
: QtMaterialFlatButton(*new QtMaterialMenuItemPrivate(this), parent)
|
||||
{
|
||||
d_func()->init();
|
||||
}
|
||||
|
||||
QtMaterialMenuItem::~QtMaterialMenuItem()
|
||||
{
|
||||
}
|
||||
|
||||
void QtMaterialMenuItem::setHighlighted(bool value)
|
||||
{
|
||||
Q_D(QtMaterialMenuItem);
|
||||
|
||||
d->highlighted = value;
|
||||
}
|
||||
|
||||
bool QtMaterialMenuItem::isHighlighted() const
|
||||
{
|
||||
Q_D(const QtMaterialMenuItem);
|
||||
|
||||
return d->highlighted;
|
||||
}
|
||||
|
||||
void QtMaterialMenuItem::paintForeground(QPainter *painter)
|
||||
{
|
||||
if (isEnabled()) {
|
||||
painter->setPen(foregroundColor());
|
||||
} else {
|
||||
painter->setPen(disabledForegroundColor());
|
||||
}
|
||||
|
||||
QRect r(rect());
|
||||
|
||||
if (icon().isNull()) {
|
||||
painter->drawText(r.marginsRemoved(QMargins(14, 0, 14, 0)),
|
||||
Qt::AlignVCenter | Qt::AlignLeft,
|
||||
text());
|
||||
return;
|
||||
}
|
||||
|
||||
QSize textSize(fontMetrics().size(Qt::TextSingleLine, text()));
|
||||
QSize base(size()-textSize);
|
||||
|
||||
const int iw = iconSize().width() + IconPadding;
|
||||
|
||||
QRect textGeometry(QPoint(14, base.height()/2), textSize);
|
||||
QRect iconGeometry(QPoint(14, (height()-iconSize().height())/2), iconSize());
|
||||
|
||||
if (Material::LeftIcon == iconPlacement()) {
|
||||
textGeometry.translate(iw, 0);
|
||||
} else {
|
||||
iconGeometry.translate(textSize.width() + IconPadding, 0);
|
||||
}
|
||||
|
||||
painter->drawText(textGeometry,
|
||||
Qt::AlignVCenter | Qt::AlignLeft,
|
||||
text());
|
||||
|
||||
QPixmap pixmap = icon().pixmap(iconSize());
|
||||
QPainter icon(&pixmap);
|
||||
icon.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
||||
icon.fillRect(pixmap.rect(), painter->pen().color());
|
||||
painter->drawPixmap(iconGeometry, pixmap);
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
#ifndef QTMATERIALMENUITEM_H
|
||||
#define QTMATERIALMENUITEM_H
|
||||
|
||||
#include "qtmaterialflatbutton.h"
|
||||
|
||||
class QtMaterialMenuItemPrivate;
|
||||
|
||||
class QtMaterialMenuItem : public QtMaterialFlatButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QtMaterialMenuItem(QWidget *parent = 0);
|
||||
~QtMaterialMenuItem();
|
||||
|
||||
void setHighlighted(bool value);
|
||||
bool isHighlighted() const;
|
||||
|
||||
protected:
|
||||
void paintForeground(QPainter *painter) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QtMaterialMenuItem)
|
||||
Q_DECLARE_PRIVATE(QtMaterialMenuItem)
|
||||
};
|
||||
|
||||
#endif // QTMATERIALMENUITEM_H
|
|
@ -1,50 +0,0 @@
|
|||
#include "qtmaterialmenuitem_internal.h"
|
||||
#include <QSignalTransition>
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
/*!
|
||||
* \class QtMaterialMenuItemStateMachine
|
||||
* \internal
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
QtMaterialMenuItemStateMachine::QtMaterialMenuItemStateMachine(QtMaterialMenuItem *menuItem)
|
||||
: QStateMachine(menuItem),
|
||||
m_menuItem(menuItem),
|
||||
m_defaultState(new QState),
|
||||
m_highlightedState(new QState)
|
||||
{
|
||||
Q_ASSERT(menuItem);
|
||||
|
||||
addState(m_defaultState);
|
||||
addState(m_highlightedState);
|
||||
|
||||
setInitialState(m_defaultState);
|
||||
|
||||
QSignalTransition *transition;
|
||||
|
||||
transition = new QSignalTransition(this, SIGNAL(highlight()));
|
||||
transition->setTargetState(m_highlightedState);
|
||||
m_defaultState->addTransition(transition);
|
||||
|
||||
transition = new QSignalTransition(this, SIGNAL(unhighlight()));
|
||||
transition->setTargetState(m_defaultState);
|
||||
m_highlightedState->addTransition(transition);
|
||||
|
||||
QPropertyAnimation *animation;
|
||||
|
||||
animation = new QPropertyAnimation(this);
|
||||
animation->setTargetObject(this);
|
||||
animation->setPropertyName("foregroundColor");
|
||||
animation->setDuration(160);
|
||||
addDefaultAnimation(animation);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
QtMaterialMenuItemStateMachine::~QtMaterialMenuItemStateMachine()
|
||||
{
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
#ifndef QTMATERIALMENUITEM_INTERNAL_H
|
||||
#define QTMATERIALMENUITEM_INTERNAL_H
|
||||
|
||||
#include <QStateMachine>
|
||||
#include <QColor>
|
||||
#include "qtmaterialmenuitem.h"
|
||||
|
||||
class QtMaterialMenuItem;
|
||||
|
||||
class QtMaterialMenuItemStateMachine : public QStateMachine
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QColor foregroundColor READ foregroundColor WRITE setForegroundColor)
|
||||
|
||||
public:
|
||||
explicit QtMaterialMenuItemStateMachine(QtMaterialMenuItem *menuItem);
|
||||
~QtMaterialMenuItemStateMachine();
|
||||
|
||||
inline void setForegroundColor(const QColor &color);
|
||||
inline QColor foregroundColor() const;
|
||||
|
||||
signals:
|
||||
void highlight();
|
||||
void unhighlight();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QtMaterialMenuItemStateMachine)
|
||||
|
||||
QtMaterialMenuItem *const m_menuItem;
|
||||
QState *const m_defaultState;
|
||||
QState *const m_highlightedState;
|
||||
QColor m_foregroundColor;
|
||||
};
|
||||
|
||||
inline void QtMaterialMenuItemStateMachine::setForegroundColor(const QColor &color)
|
||||
{
|
||||
m_foregroundColor = color;
|
||||
m_menuItem->update();
|
||||
}
|
||||
|
||||
inline QColor QtMaterialMenuItemStateMachine::foregroundColor() const
|
||||
{
|
||||
return m_foregroundColor;
|
||||
}
|
||||
|
||||
#endif // QTMATERIALMENUITEM_INTERNAL_H
|
|
@ -1,23 +0,0 @@
|
|||
#ifndef QTMATERIALMENUITEM_P_H
|
||||
#define QTMATERIALMENUITEM_P_H
|
||||
|
||||
#include "qtmaterialflatbutton_p.h"
|
||||
|
||||
class QtMaterialMenuItem;
|
||||
class QtMaterialMenuItemStateMachine;
|
||||
|
||||
class QtMaterialMenuItemPrivate : public QtMaterialFlatButtonPrivate
|
||||
{
|
||||
Q_DISABLE_COPY(QtMaterialMenuItemPrivate)
|
||||
Q_DECLARE_PUBLIC(QtMaterialMenuItem)
|
||||
|
||||
public:
|
||||
QtMaterialMenuItemPrivate(QtMaterialMenuItem *q);
|
||||
~QtMaterialMenuItemPrivate();
|
||||
|
||||
void init();
|
||||
|
||||
bool highlighted;
|
||||
};
|
||||
|
||||
#endif // QTMATERIALMENUITEM_P_H
|
Loading…
Reference in New Issue