Permalink
Browse files

quick_control: add activating animation

Change-Id: Ibacad955e669761862ec8a55ae27d7a424b7d1a6
  • Loading branch information...
sbwtw committed Feb 23, 2017
1 parent 498eb85 commit 12f0b08d8001899f15ccda9094e9f1de955aa06e
@@ -4,6 +4,7 @@
#include <QPainter>
#include <QDebug>
#include <QJsonObject>
#include <QDateTime>
WifiListDelegate::WifiListDelegate(QObject *parent)
: QAbstractItemDelegate(parent),
@@ -56,16 +57,23 @@ void WifiListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
painter->drawPixmap(x, y, m_securityPixmap);
}
// draw actived icon
const bool isActived = index.data(WifiListModel::ItemIsActiveRole).toBool();
if (isActived)
const int icon_x = option.rect.right() - 16 - 10;
const bool isActivating = index.data(WifiListModel::ItemIsActivatingRole).toBool();
if (isActivating)
{
const int x = option.rect.right() - 16 - 10;
if (isHovered)
painter->drawPixmap(x, y, QPixmap(":/frame/themes/dark/icons/remove.png"));
else
painter->drawPixmap(x, y, QPixmap(":/frame/themes/dark/icons/select.png"));
const quint64 index = QDateTime::currentMSecsSinceEpoch() / 20;
const QString pix = QString(":/frame/themes/dark/icons/spinner14/Spinner%1.png").arg((index % 91) + 1, 2, 10, QChar('0'));
painter->drawPixmap(icon_x, y + 1, QPixmap(pix));
} else {
// draw actived icon
const bool isActived = index.data(WifiListModel::ItemIsActiveRole).toBool();
if (isActived)
{
if (isHovered)
painter->drawPixmap(icon_x, y, QPixmap(":/frame/themes/dark/icons/remove.png"));
else
painter->drawPixmap(icon_x, y, QPixmap(":/frame/themes/dark/icons/select.png"));
}
}
}
}
@@ -12,8 +12,13 @@ using dcc::network::WirelessDevice;
WifiListModel::WifiListModel(NetworkModel *model, QObject *parent)
: QAbstractListModel(parent),
m_networkModel(model)
m_networkModel(model),
m_refershTimer(new QTimer(this))
{
m_refershTimer->setSingleShot(false);
m_refershTimer->setInterval(1000 / 60);
connect(m_refershTimer, &QTimer::timeout, this, &WifiListModel::refershActivatingIndex);
connect(m_networkModel, &NetworkModel::connectionListChanged, [this] { emit layoutChanged(); });
connect(m_networkModel, &NetworkModel::deviceEnableChanged, [this] { emit layoutChanged(); });
connect(m_networkModel, &NetworkModel::deviceListChanged, this, &WifiListModel::onDeviceListChanged);
@@ -64,6 +69,8 @@ QVariant WifiListModel::data(const QModelIndex &index, int role) const
return info.info == nullptr;
case ItemIsActiveRole:
return info.info && static_cast<const WirelessDevice *>(info.device)->activeApName() == info.info->value("Ssid").toString();
case ItemIsActivatingRole:
return m_refershTimer->isActive() && index == m_activatingIndex;
case ItemDevicePathRole:
return info.device->path();
case ItemApPathRole:
@@ -86,6 +93,16 @@ void WifiListModel::setCurrentHovered(const QModelIndex &index)
emit dataChanged(m_currentIndex, m_currentIndex);
}
void WifiListModel::setCurrentActivating(const QModelIndex &index)
{
const QModelIndex oldIndex = m_activatingIndex;
m_activatingIndex = index;
emit dataChanged(oldIndex, oldIndex);
emit dataChanged(m_activatingIndex, m_activatingIndex);
}
int WifiListModel::indexOf(dcc::network::WirelessDevice * const dev) const
{
int pos = 0;
@@ -168,7 +185,9 @@ void WifiListModel::onDeviceListChanged(const QList<NetworkDevice *> &devices)
m_apInfoList.insert(d, QList<QJsonObject>());
connect(d, &WirelessDevice::activeApChanged, this, &WifiListModel::refershActivatingIndex);
connect(d, &WirelessDevice::apAdded, this, &WifiListModel::onDeviceApAdded);
connect(d, static_cast<void (WirelessDevice::*)(const NetworkDevice::DeviceStatus) const>(&WirelessDevice::statusChanged), this, &WifiListModel::onDeviceStateChanged);
connect(d, &WirelessDevice::apRemoved, d, [=](const QString &ssid) { onDeviceApRemoved(d, ssid); });
emit requestDeviceApList(d->path());
@@ -216,3 +235,17 @@ void WifiListModel::onDeviceApRemoved(dcc::network::WirelessDevice *dev, const Q
}
}
}
void WifiListModel::onDeviceStateChanged(const NetworkDevice::DeviceStatus &stat)
{
// WirelessDevice *dev = static_cast<WirelessDevice *>(sender());
if (stat >= NetworkDevice::Prepare && stat < NetworkDevice::Activated)
m_refershTimer->start();
else
m_refershTimer->stop();
}
void WifiListModel::refershActivatingIndex()
{
emit dataChanged(m_activatingIndex, m_activatingIndex);
}
@@ -6,6 +6,7 @@
#include "network/wirelessdevice.h"
#include <QAbstractListModel>
#include <QTimer>
struct ItemInfo
{
@@ -25,6 +26,7 @@ class WifiListModel : public QAbstractListModel
ItemIsHeaderRole,
ItemInfoRole,
ItemIsActiveRole,
ItemIsActivatingRole,
ItemApPathRole,
ItemDevicePathRole,
ItemUuidRole,
@@ -37,6 +39,7 @@ class WifiListModel : public QAbstractListModel
public slots:
void setCurrentHovered(const QModelIndex &index);
void setCurrentActivating(const QModelIndex &index);
signals:
void requestDeviceApList(const QString &devPath) const;
@@ -49,11 +52,17 @@ public slots:
void onDeviceListChanged(const QList<dcc::network::NetworkDevice *> &devices);
void onDeviceApAdded(const QJsonObject &info);
void onDeviceApRemoved(dcc::network::WirelessDevice *dev, const QString &ssid);
void onDeviceStateChanged(const dcc::network::NetworkDevice::DeviceStatus &stat);
void refershActivatingIndex();
private:
dcc::network::NetworkModel *m_networkModel;
QModelIndex m_currentIndex;
QModelIndex m_activatingIndex;
QTimer *m_refershTimer;
QMap<dcc::network::WirelessDevice *, QList<QJsonObject>> m_apInfoList;
};
@@ -30,6 +30,7 @@ WifiPage::WifiPage(NetworkModel *model, QWidget *parent)
connect(listModel, &WifiListModel::requestDeviceApList, this, &WifiPage::requestDeviceApList);
connect(listView, &BasicListView::entered, listModel, &WifiListModel::setCurrentHovered);
connect(listView, &BasicListView::clicked, listModel, &WifiListModel::setCurrentActivating);
connect(listView, &BasicListView::clicked, this, &WifiPage::onItemClicked);
}

0 comments on commit 12f0b08

Please sign in to comment.