#include #include "ButtonItem.h" #include "GridLayoutItem.h" #include "ModeItem.h" namespace QuickKeyboard { ModeItem::ModeItem(QQuickItem *parent): QQuickItem(parent), m_layout(0) { setVisible(false); setLayout(new GridLayoutItem()); } ModeItem::~ModeItem() { } LayoutItem *ModeItem::layout() const { return m_layout; } void ModeItem::setLayout(LayoutItem *layout) { if (m_layout == layout) { return; } if (m_layout) { m_layout->setParentItem(0); delete m_layout; } if (layout) { layout->setParentItem(this); for (ButtonItem *button : m_buttons) { m_layout->addButton(button); } layout->property("anchors").value()->setProperty("fill", QVariant::fromValue(this)); } m_layout = layout; } QQmlListProperty ModeItem::buttons() { return QQmlListProperty( this, &m_buttons, &ModeItem::buttons_append, &ModeItem::buttons_count, &ModeItem::buttons_at, &ModeItem::buttons_clear ); } void ModeItem::buttons_append(QQmlListProperty *property, ButtonItem *button) { ModeItem *that = static_cast(property->object); button->setParentItem(that); that->m_buttons.append(button); if (that->m_layout) { that->m_layout->addButton(button); } QObject::connect(button, SIGNAL(symbolTriggered(const QString &)), that, SIGNAL(symbolTriggered(const QString &))); QObject::connect(button, SIGNAL(triggered()), that, SLOT(setModifiersInactive())); } int ModeItem::buttons_count(QQmlListProperty *property) { ModeItem *that = static_cast(property->object); return that->m_buttons.count(); } ButtonItem *ModeItem::buttons_at(QQmlListProperty *property, int idx) { ModeItem *that = static_cast(property->object); return that->m_buttons.value(idx, 0); } void ModeItem::buttons_clear(QQmlListProperty *property) { ModeItem *that = static_cast(property->object); if (that->m_layout) { that->m_layout->clearButtons(); } for (ButtonItem *button : that->m_buttons) { QObject::disconnect(button, SIGNAL(symbolTriggered(const QString &)), that, SIGNAL(symbolTriggered(const QString &))); QObject::disconnect(button, SIGNAL(triggered()), that, SLOT(setModifiersInactive())); button->setParentItem(0); } that->m_buttons.clear(); } void ModeItem::itemChange(ItemChange change, const ItemChangeData &value) { QQuickItem::itemChange(change, value); if (change == QQuickItem::ItemVisibleHasChanged && !isVisible()) { setModifiersInactive(); } } void ModeItem::setModifiersInactive() { for (ButtonItem *button : m_buttons) { if (button->isModifier()) { button->setActive(false); } } } } /* QuickKeyboard */