Merge branch 'master' of https://github.com/laserpants/qt-material-widgets
This commit is contained in:
commit
e2d4ebd560
|
@ -1,10 +1,13 @@
|
|||
#include <QWidget>
|
||||
#include <QPainter>
|
||||
#include <QStylePainter>
|
||||
#include <QStyleOptionButton>
|
||||
#include "checkbox.h"
|
||||
|
||||
Checkbox::Checkbox(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
: QAbstractButton(parent)
|
||||
{
|
||||
setFixedSize(200, 200);
|
||||
}
|
||||
|
||||
Checkbox::~Checkbox()
|
||||
|
@ -13,19 +16,52 @@ Checkbox::~Checkbox()
|
|||
|
||||
void Checkbox::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
QWidget::mousePressEvent(event);
|
||||
QAbstractButton::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void Checkbox::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
QWidget::mouseReleaseEvent(event);
|
||||
QAbstractButton::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void Checkbox::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPainter painter(this);
|
||||
Q_UNUSED(event)
|
||||
|
||||
painter.drawRect(0, 0, 50, 50);
|
||||
QStylePainter p(this);
|
||||
QStyleOptionButton opt;
|
||||
initStyleOption(&opt);
|
||||
p.drawControl(QStyle::CE_CheckBox, opt);
|
||||
|
||||
QWidget::paintEvent(event);
|
||||
p.drawRect(rect().adjusted(0, 0, -1, -1)); // tmp
|
||||
}
|
||||
|
||||
void Checkbox::initStyleOption(QStyleOptionButton *option) const
|
||||
{
|
||||
if (!option)
|
||||
return;
|
||||
//Q_D(const QCheckBox);
|
||||
option->initFrom(this);
|
||||
/*
|
||||
if (d->down)
|
||||
option->state |= QStyle::State_Sunken;
|
||||
if (d->tristate && d->noChange)
|
||||
option->state |= QStyle::State_NoChange;
|
||||
else
|
||||
option->state |= d->checked ? QStyle::State_On : QStyle::State_Off;
|
||||
*/
|
||||
if (testAttribute(Qt::WA_Hover) && underMouse()) {
|
||||
/*
|
||||
if (d->hovering)
|
||||
option->state |= QStyle::State_MouseOver;
|
||||
else
|
||||
option->state &= ~QStyle::State_MouseOver;
|
||||
*/
|
||||
}
|
||||
option->text = "Label label";
|
||||
/*
|
||||
option->text = d->text;
|
||||
option->icon = d->icon;
|
||||
option->iconSize = iconSize();
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#ifndef CHECKBOX_H
|
||||
#define CHECKBOX_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QAbstractButton>
|
||||
|
||||
class Checkbox : public QWidget
|
||||
class QStyleOptionButton;
|
||||
|
||||
class Checkbox : public QAbstractButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -15,6 +17,8 @@ protected:
|
|||
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
void initStyleOption(QStyleOptionButton *option) const;
|
||||
};
|
||||
|
||||
#endif // CHECKBOX_H
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#include <QStylePainter>
|
||||
#include <QStyleOptionButton>
|
||||
#include <QApplication>
|
||||
#include <QEvent>
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
#include "iconbutton.h"
|
||||
#include "../lib/rippleoverlay.h"
|
||||
|
@ -19,8 +17,6 @@ IconButton::IconButton(const QIcon &icon, QWidget *parent)
|
|||
setSizePolicy(policy);
|
||||
|
||||
setGeometryWidget(this);
|
||||
|
||||
setStyle(&Style::instance());
|
||||
}
|
||||
|
||||
IconButton::~IconButton()
|
||||
|
@ -29,13 +25,7 @@ IconButton::~IconButton()
|
|||
|
||||
QSize IconButton::sizeHint() const
|
||||
{
|
||||
QStyleOptionButton option(getStyleOption());
|
||||
|
||||
int w = option.iconSize.width() + 4;
|
||||
int h = option.iconSize.height();
|
||||
|
||||
return (style()->sizeFromContents(QStyle::CT_PushButton, &option, QSize(w, h), this).
|
||||
expandedTo(QApplication::globalStrut()));
|
||||
return iconSize();
|
||||
}
|
||||
|
||||
void IconButton::setGeometryWidget(QWidget *widget)
|
||||
|
@ -52,9 +42,10 @@ void IconButton::paintEvent(QPaintEvent *event)
|
|||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
QStylePainter painter(this);
|
||||
QStyleOptionButton option(getStyleOption());
|
||||
painter.drawControl(QStyle::CE_PushButton, option);
|
||||
QPainter painter(this);
|
||||
const QSize &size = iconSize();
|
||||
QPoint pos(width()/2-size.width()/2, height()/2-size.height()/2);
|
||||
icon().paint(&painter, QRect(pos, size));
|
||||
}
|
||||
|
||||
void IconButton::mousePressEvent(QMouseEvent *event)
|
||||
|
@ -87,18 +78,6 @@ bool IconButton::eventFilter(QObject *obj, QEvent *event)
|
|||
return QAbstractButton::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
QStyleOptionButton IconButton::getStyleOption() const
|
||||
{
|
||||
QStyleOptionButton option;
|
||||
option.initFrom(this);
|
||||
option.features = QStyleOptionButton::Flat;
|
||||
if (isChecked())
|
||||
option.state |= QStyle::State_On;
|
||||
option.icon = icon();
|
||||
option.iconSize = iconSize();
|
||||
return option;
|
||||
}
|
||||
|
||||
void IconButton::updateOverlayGeometry()
|
||||
{
|
||||
if (!_overlay || !_geometryWidget)
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define ICONBUTTON_H
|
||||
|
||||
#include <QAbstractButton>
|
||||
#include <QStyleOptionButton>
|
||||
|
||||
class RippleOverlay;
|
||||
|
||||
|
@ -23,8 +22,6 @@ protected:
|
|||
bool event(QEvent *event) Q_DECL_OVERRIDE;
|
||||
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
QStyleOptionButton getStyleOption() const;
|
||||
|
||||
private:
|
||||
void updateOverlayGeometry();
|
||||
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
#include <QWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QPainter>
|
||||
#include "menu.h"
|
||||
|
||||
MenuItem::MenuItem(QWidget *parent)
|
||||
: FlatButton(parent)
|
||||
{
|
||||
setMinimumHeight(40);
|
||||
//setStyleSheet("text-align: left;");
|
||||
}
|
||||
|
||||
MenuItem::MenuItem(const QString &text, QWidget *parent)
|
||||
: FlatButton(text, parent)
|
||||
{
|
||||
setMinimumHeight(40);
|
||||
//setStyleSheet("text-align: left;");
|
||||
}
|
||||
|
||||
MenuItem::~MenuItem()
|
||||
{
|
||||
}
|
||||
|
||||
Menu::Menu(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
setLayout(layout);
|
||||
|
||||
layout->setMargin(0);
|
||||
layout->setSpacing(0);
|
||||
|
||||
QSizePolicy policy;
|
||||
policy.setHorizontalPolicy(QSizePolicy::Expanding);
|
||||
policy.setVerticalPolicy(QSizePolicy::Maximum);
|
||||
setSizePolicy(policy);
|
||||
}
|
||||
|
||||
Menu::~Menu()
|
||||
{
|
||||
}
|
||||
|
||||
void Menu::addMenuItem(MenuItem *item)
|
||||
{
|
||||
layout()->addWidget(item);
|
||||
}
|
||||
|
||||
void Menu::addMenuItem(const QString &text)
|
||||
{
|
||||
addMenuItem(new MenuItem(text));
|
||||
}
|
||||
|
||||
void Menu::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
painter.fillRect(rect(), Qt::white);
|
||||
painter.drawRect(rect().adjusted(0, 0, -1, -1));
|
||||
|
||||
QWidget::paintEvent(event);
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef MENU_H
|
||||
#define MENU_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "flatbutton.h"
|
||||
|
||||
class MenuItem : public FlatButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MenuItem(QWidget *parent = 0);
|
||||
explicit MenuItem(const QString &text, QWidget *parent = 0);
|
||||
~MenuItem();
|
||||
};
|
||||
|
||||
class Menu : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Menu(QWidget *parent = 0);
|
||||
~Menu();
|
||||
|
||||
void addMenuItem(MenuItem *item);
|
||||
void addMenuItem(const QString &text);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
};
|
||||
|
||||
#endif // MENU_H
|
|
@ -0,0 +1 @@
|
|||
#include "scrollbar.h"
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef SCROLLBAR_H
|
||||
#define SCROLLBAR_H
|
||||
|
||||
#endif // SCROLLBAR_H
|
|
@ -22,8 +22,6 @@ IconButtonExamples::IconButtonExamples(QWidget *parent)
|
|||
);
|
||||
frame->setWidget(view);
|
||||
|
||||
iconButton->setMinimumSize(50, 50);
|
||||
|
||||
layout->addWidget(frame);
|
||||
}
|
||||
{
|
||||
|
@ -40,7 +38,21 @@ IconButtonExamples::IconButtonExamples(QWidget *parent)
|
|||
);
|
||||
frame->setWidget(view);
|
||||
|
||||
iconButton->setMinimumSize(50, 50);
|
||||
layout->addWidget(frame);
|
||||
}
|
||||
{
|
||||
IconButton *iconButton = new IconButton(QIcon("../qt-material-widgets/face.svg"));
|
||||
iconButton->setIconSize(QSize(128, 128));
|
||||
|
||||
ExampleView *view = new ExampleView;
|
||||
view->setWidget(iconButton);
|
||||
|
||||
Frame *frame = new Frame;
|
||||
frame->setCodeSnippet(
|
||||
"IconButton *iconButton = new IconButton(QIcon(\"face.svg\"));\n"
|
||||
"iconButton->setIconSize(QSize(128, 128));\n"
|
||||
);
|
||||
frame->setWidget(view);
|
||||
|
||||
layout->addWidget(frame);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
#include <QLayout>
|
||||
#include <QEvent>
|
||||
#include "menuexamples.h"
|
||||
#include "components/menu.h"
|
||||
#include "exampleview.h"
|
||||
#include "frame.h"
|
||||
|
||||
MenuExamples::MenuExamples(QWidget *parent)
|
||||
: ExampleList(parent)
|
||||
{
|
||||
QLayout *layout = widget()->layout();
|
||||
|
||||
{
|
||||
Menu *menu = new Menu;
|
||||
|
||||
menu->addMenuItem("Maps");
|
||||
menu->addMenuItem("Books");
|
||||
menu->addMenuItem("Flights");
|
||||
menu->addMenuItem("Apps");
|
||||
|
||||
ExampleView *view = new ExampleView;
|
||||
view->setWidget(menu);
|
||||
|
||||
Frame *frame = new Frame;
|
||||
frame->setCodeSnippet(
|
||||
"Menu *menu = new Menu;\n"
|
||||
"\n"
|
||||
"menu->addMenuItem(\"Maps\");\n"
|
||||
"menu->addMenuItem(\"Books\");\n"
|
||||
"menu->addMenuItem(\"Flights\");\n"
|
||||
"menu->addMenuItem(\"Apps\");\n"
|
||||
);
|
||||
frame->setWidget(view);
|
||||
|
||||
layout->addWidget(frame);
|
||||
}
|
||||
}
|
||||
|
||||
MenuExamples::~MenuExamples()
|
||||
{
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef MENUEXAMPLES_H
|
||||
#define MENUEXAMPLES_H
|
||||
|
||||
#include "examplelist.h"
|
||||
|
||||
class MenuExamples : public ExampleList
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MenuExamples(QWidget *parent = 0);
|
||||
~MenuExamples();
|
||||
};
|
||||
|
||||
#endif // MENUEXAMPLES_H
|
6
main.cpp
6
main.cpp
|
@ -1,12 +1,16 @@
|
|||
#include "mainwindow.h"
|
||||
#include <QApplication>
|
||||
#include <QCommonStyle>
|
||||
#include "style.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
||||
//a.setStyle(new Style);
|
||||
// QCommonStyle *style = new QCommonStyle;
|
||||
// a.setStyle(style);
|
||||
|
||||
// a.setStyle(&Style::instance());
|
||||
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "examples/textfieldexamples.h"
|
||||
#include "examples/listexamples.h"
|
||||
#include "examples/avatarexamples.h"
|
||||
#include "examples/menuexamples.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent),
|
||||
|
@ -35,6 +36,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
_textFieldExamples(new TextFieldExamples),
|
||||
_listExamples(new ListExamples),
|
||||
_avatarExamples(new AvatarExamples),
|
||||
_menuExamples(new MenuExamples),
|
||||
_about(new About)
|
||||
{
|
||||
_initWidget();
|
||||
|
@ -74,6 +76,8 @@ void MainWindow::showWidget(QAction *action)
|
|||
_layout->setCurrentWidget(_listExamples);
|
||||
} else if ("Avatar" == text) {
|
||||
_layout->setCurrentWidget(_avatarExamples);
|
||||
} else if ("Menu" == text) {
|
||||
_layout->setCurrentWidget(_menuExamples);
|
||||
} else {
|
||||
_layout->setCurrentWidget(_about);
|
||||
}
|
||||
|
@ -98,6 +102,7 @@ void MainWindow::_initWidget()
|
|||
_layout->addWidget(_textFieldExamples);
|
||||
_layout->addWidget(_listExamples);
|
||||
_layout->addWidget(_avatarExamples);
|
||||
_layout->addWidget(_menuExamples);
|
||||
|
||||
setCentralWidget(widget);
|
||||
}
|
||||
|
@ -124,7 +129,14 @@ void MainWindow::_initMenu() const
|
|||
buttons->addAction("Icon Button");
|
||||
|
||||
components->addAction("Dialog");
|
||||
components->addAction("Menus");
|
||||
|
||||
QMenu *menus = new QMenu("Menus");
|
||||
components->addMenu(menus);
|
||||
|
||||
menus->addAction("Menu");
|
||||
menus->addAction("Icon Menu");
|
||||
menus->addAction("Drop Down Menu");
|
||||
|
||||
components->addAction("List");
|
||||
components->addAction("Slider");
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ class CheckboxExamples;
|
|||
class TextFieldExamples;
|
||||
class ListExamples;
|
||||
class AvatarExamples;
|
||||
class MenuExamples;
|
||||
class QStackedLayout;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
|
@ -48,6 +49,7 @@ private:
|
|||
TextFieldExamples *const _textFieldExamples;
|
||||
ListExamples *const _listExamples;
|
||||
AvatarExamples *const _avatarExamples;
|
||||
MenuExamples *const _menuExamples;
|
||||
About *const _about;
|
||||
};
|
||||
|
||||
|
|
|
@ -45,7 +45,10 @@ SOURCES += main.cpp\
|
|||
examples/textfieldexamples.cpp \
|
||||
examples/listexamples.cpp \
|
||||
components/avatar.cpp \
|
||||
examples/avatarexamples.cpp
|
||||
examples/avatarexamples.cpp \
|
||||
examples/menuexamples.cpp \
|
||||
components/menu.cpp \
|
||||
components/scrollbar.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
style.h \
|
||||
|
@ -84,4 +87,7 @@ HEADERS += mainwindow.h \
|
|||
examples/textfieldexamples.h \
|
||||
examples/listexamples.h \
|
||||
components/avatar.h \
|
||||
examples/avatarexamples.h
|
||||
examples/avatarexamples.h \
|
||||
examples/menuexamples.h \
|
||||
components/menu.h \
|
||||
components/scrollbar.h
|
||||
|
|
14
style.cpp
14
style.cpp
|
@ -7,7 +7,7 @@
|
|||
void Style::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
|
||||
const QWidget *w) const
|
||||
{
|
||||
// qDebug() << pe;
|
||||
qDebug() << pe;
|
||||
|
||||
switch (pe) {
|
||||
case PE_FrameFocusRect:
|
||||
|
@ -15,7 +15,7 @@ void Style::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter
|
|||
p->drawRect(opt->rect.adjusted(0, 0, -1, -1));
|
||||
break;
|
||||
default:
|
||||
QProxyStyle::drawPrimitive(pe, opt, p, w);
|
||||
QCommonStyle::drawPrimitive(pe, opt, p, w);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ void Style::drawControl(ControlElement element, const QStyleOption *opt,
|
|||
break;
|
||||
*/
|
||||
default:
|
||||
QProxyStyle::drawControl(element, opt, p, widget);
|
||||
QCommonStyle::drawControl(element, opt, p, widget);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ QRect Style::subElementRect(SubElement sr, const QStyleOption *opt,
|
|||
}
|
||||
break;
|
||||
default:
|
||||
r = QProxyStyle::subElementRect(sr, opt, widget);
|
||||
r = QCommonStyle::subElementRect(sr, opt, widget);
|
||||
}
|
||||
|
||||
// qDebug() << "r = " << r;
|
||||
|
@ -80,7 +80,7 @@ void Style::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt
|
|||
|
||||
switch (cc) {
|
||||
default:
|
||||
QProxyStyle::drawComplexControl(cc, opt, p, w);
|
||||
QCommonStyle::drawComplexControl(cc, opt, p, w);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ QRect Style::subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, S
|
|||
QRect r;
|
||||
switch (cc) {
|
||||
default:
|
||||
r = QProxyStyle::subControlRect(cc, opt, sc, w);
|
||||
r = QCommonStyle::subControlRect(cc, opt, sc, w);
|
||||
}
|
||||
|
||||
// qDebug() << "r = " << r;
|
||||
|
@ -116,7 +116,7 @@ int Style::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWidget *wi
|
|||
ret = 0;
|
||||
break;
|
||||
default:
|
||||
ret = QProxyStyle::pixelMetric(m, opt, widget);
|
||||
ret = QCommonStyle::pixelMetric(m, opt, widget);
|
||||
}
|
||||
|
||||
// qDebug() << "ret = " << ret;
|
||||
|
|
Loading…
Reference in New Issue