Add state machine for Auto Complete
This commit is contained in:
parent
277669c31d
commit
5aefcce24d
|
@ -42,7 +42,8 @@ SOURCES = \
|
||||||
qtmaterialautocomplete.cpp \
|
qtmaterialautocomplete.cpp \
|
||||||
qtmaterialpaper.cpp \
|
qtmaterialpaper.cpp \
|
||||||
qtmaterialtable.cpp \
|
qtmaterialtable.cpp \
|
||||||
layouts/qtmaterialsnackbarlayout.cpp
|
layouts/qtmaterialsnackbarlayout.cpp \
|
||||||
|
qtmaterialautocomplete_internal.cpp
|
||||||
HEADERS = \
|
HEADERS = \
|
||||||
qtmaterialavatar_p.h \
|
qtmaterialavatar_p.h \
|
||||||
qtmaterialavatar.h \
|
qtmaterialavatar.h \
|
||||||
|
@ -112,6 +113,7 @@ HEADERS = \
|
||||||
qtmaterialtable.h \
|
qtmaterialtable.h \
|
||||||
qtmaterialtable_p.h \
|
qtmaterialtable_p.h \
|
||||||
layouts/qtmaterialsnackbarlayout.h \
|
layouts/qtmaterialsnackbarlayout.h \
|
||||||
layouts/qtmaterialsnackbarlayout_p.h
|
layouts/qtmaterialsnackbarlayout_p.h \
|
||||||
|
qtmaterialautocomplete_internal.h
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
resources.qrc
|
resources.qrc
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <QtWidgets/QVBoxLayout>
|
#include <QtWidgets/QVBoxLayout>
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QDebug>
|
#include "qtmaterialautocomplete_internal.h"
|
||||||
#include "qtmaterialflatbutton.h"
|
#include "qtmaterialflatbutton.h"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -34,9 +34,10 @@ void QtMaterialAutoCompletePrivate::init()
|
||||||
{
|
{
|
||||||
Q_Q(QtMaterialAutoComplete);
|
Q_Q(QtMaterialAutoComplete);
|
||||||
|
|
||||||
menu = new QWidget;
|
stateMachine = new QtMaterialAutoCompleteStateMachine(q);
|
||||||
menuLayout = new QVBoxLayout;
|
menu = new QWidget;
|
||||||
maxWidth = 0;
|
menuLayout = new QVBoxLayout;
|
||||||
|
maxWidth = 0;
|
||||||
|
|
||||||
menu->setParent(q->parentWidget());
|
menu->setParent(q->parentWidget());
|
||||||
|
|
||||||
|
@ -53,6 +54,8 @@ void QtMaterialAutoCompletePrivate::init()
|
||||||
menuLayout->setSpacing(0);
|
menuLayout->setSpacing(0);
|
||||||
|
|
||||||
QObject::connect(q, SIGNAL(textEdited(QString)), q, SLOT(updateResults(QString)));
|
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 QWidget;
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
class QtMaterialAutoCompleteOverlay;
|
class QtMaterialAutoCompleteOverlay;
|
||||||
|
class QtMaterialAutoCompleteStateMachine;
|
||||||
|
|
||||||
class QtMaterialAutoCompletePrivate : public QtMaterialTextFieldPrivate
|
class QtMaterialAutoCompletePrivate : public QtMaterialTextFieldPrivate
|
||||||
{
|
{
|
||||||
|
@ -18,10 +19,11 @@ public:
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
QWidget *menu;
|
QtMaterialAutoCompleteStateMachine *stateMachine;
|
||||||
QVBoxLayout *menuLayout;
|
QWidget *menu;
|
||||||
QStringList dataSource;
|
QVBoxLayout *menuLayout;
|
||||||
int maxWidth;
|
QStringList dataSource;
|
||||||
|
int maxWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QTMATERIALAUTOCOMPLETE_P_H
|
#endif // QTMATERIALAUTOCOMPLETE_P_H
|
||||||
|
|
Loading…
Reference in New Issue