Add state machine for Auto Complete
This commit is contained in:
parent
277669c31d
commit
5aefcce24d
|
@ -42,7 +42,8 @@ SOURCES = \
|
|||
qtmaterialautocomplete.cpp \
|
||||
qtmaterialpaper.cpp \
|
||||
qtmaterialtable.cpp \
|
||||
layouts/qtmaterialsnackbarlayout.cpp
|
||||
layouts/qtmaterialsnackbarlayout.cpp \
|
||||
qtmaterialautocomplete_internal.cpp
|
||||
HEADERS = \
|
||||
qtmaterialavatar_p.h \
|
||||
qtmaterialavatar.h \
|
||||
|
@ -112,6 +113,7 @@ HEADERS = \
|
|||
qtmaterialtable.h \
|
||||
qtmaterialtable_p.h \
|
||||
layouts/qtmaterialsnackbarlayout.h \
|
||||
layouts/qtmaterialsnackbarlayout_p.h
|
||||
layouts/qtmaterialsnackbarlayout_p.h \
|
||||
qtmaterialautocomplete_internal.h
|
||||
RESOURCES += \
|
||||
resources.qrc
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <QtWidgets/QVBoxLayout>
|
||||
#include <QEvent>
|
||||
#include <QTimer>
|
||||
#include <QDebug>
|
||||
#include "qtmaterialautocomplete_internal.h"
|
||||
#include "qtmaterialflatbutton.h"
|
||||
|
||||
/*!
|
||||
|
@ -34,6 +34,7 @@ void QtMaterialAutoCompletePrivate::init()
|
|||
{
|
||||
Q_Q(QtMaterialAutoComplete);
|
||||
|
||||
stateMachine = new QtMaterialAutoCompleteStateMachine(q);
|
||||
menu = new QWidget;
|
||||
menuLayout = new QVBoxLayout;
|
||||
maxWidth = 0;
|
||||
|
@ -53,6 +54,8 @@ void QtMaterialAutoCompletePrivate::init()
|
|||
menuLayout->setSpacing(0);
|
||||
|
||||
QObject::connect(q, SIGNAL(textEdited(QString)), q, SLOT(updateResults(QString)));
|
||||
|
||||
stateMachine->start();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
#include "qtmaterialautocomplete_internal.h"
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
/*!
|
||||
* \class QtMaterialAutoCompleteStateMachine
|
||||
* \internal
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
QtMaterialAutoCompleteStateMachine::QtMaterialAutoCompleteStateMachine(QtMaterialAutoComplete *parent)
|
||||
: QStateMachine(parent),
|
||||
m_autoComplete(parent),
|
||||
m_closedState(new QState),
|
||||
m_openState(new QState),
|
||||
m_closingState(new QState)
|
||||
{
|
||||
Q_ASSERT(parent);
|
||||
|
||||
addState(m_closedState);
|
||||
addState(m_openState);
|
||||
addState(m_closingState);
|
||||
setInitialState(m_closedState);
|
||||
|
||||
QEventTransition *transition;
|
||||
|
||||
//transition = new QEventTransition(parent, QEvent::HoverEnter);
|
||||
//transition->setTargetState(m_focusState);
|
||||
//m_blurState->addTransition(transition);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
QtMaterialAutoCompleteStateMachine::~QtMaterialAutoCompleteStateMachine()
|
||||
{
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef QTMATERIALAUTOCOMPLETESTATEMACHINE_H
|
||||
#define QTMATERIALAUTOCOMPLETESTATEMACHINE_H
|
||||
|
||||
#include <QStateMachine>
|
||||
#include "qtmaterialautocomplete.h"
|
||||
|
||||
class QtMaterialAutoCompleteStateMachine : public QStateMachine
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtMaterialAutoCompleteStateMachine(QtMaterialAutoComplete *parent);
|
||||
~QtMaterialAutoCompleteStateMachine();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QtMaterialAutoCompleteStateMachine)
|
||||
|
||||
QtMaterialAutoComplete *const m_autoComplete;
|
||||
QState *m_closedState;
|
||||
QState *m_openState;
|
||||
QState *m_closingState;
|
||||
};
|
||||
|
||||
#endif // QTMATERIALAUTOCOMPLETESTATEMACHINE_H
|
|
@ -6,6 +6,7 @@
|
|||
class QWidget;
|
||||
class QVBoxLayout;
|
||||
class QtMaterialAutoCompleteOverlay;
|
||||
class QtMaterialAutoCompleteStateMachine;
|
||||
|
||||
class QtMaterialAutoCompletePrivate : public QtMaterialTextFieldPrivate
|
||||
{
|
||||
|
@ -18,6 +19,7 @@ public:
|
|||
|
||||
void init();
|
||||
|
||||
QtMaterialAutoCompleteStateMachine *stateMachine;
|
||||
QWidget *menu;
|
||||
QVBoxLayout *menuLayout;
|
||||
QStringList dataSource;
|
||||
|
|
Loading…
Reference in New Issue