*/
virtual QPixmap createDragPixmap(const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr);
+ /**
+ * Starts an animation that makes clear that the item will be activated soon.
+ * @param timeUntilActivation time in milliseconds until the item will activate
+ */
+ virtual void startActivateSoonAnimation(int timeUntilActivation);
+
Q_SIGNALS:
void roleEditingCanceled(int index, const QByteArray &role, const QVariant &value);
void roleEditingFinished(int index, const QByteArray &role, const QVariant &value);
#include <QGraphicsView>
#include <QPixmapCache>
#include <QStyleOption>
+#include <QVariantAnimation>
// #define KSTANDARDITEMLISTWIDGET_DEBUG
return clippedPixmap;
}
+void KStandardItemListWidget::startActivateSoonAnimation(int timeUntilActivation)
+{
+ if (m_activateSoonAnimation) {
+ m_activateSoonAnimation->stop(); // automatically DeleteWhenStopped
+ }
+
+ m_activateSoonAnimation = new QVariantAnimation{this};
+ m_activateSoonAnimation->setStartValue(0.0);
+ m_activateSoonAnimation->setEndValue(1.0);
+ m_activateSoonAnimation->setDuration(timeUntilActivation);
+
+ const QVariant originalIconName{data()["iconName"]};
+ connect(m_activateSoonAnimation, &QVariantAnimation::valueChanged, this, [originalIconName, this](const QVariant &value) {
+ auto progress = value.toFloat();
+
+ QVariant wantedIconName;
+ if (progress < 0.333) {
+ wantedIconName = "folder-open";
+ } else if (progress < 0.666) {
+ wantedIconName = originalIconName;
+ } else {
+ wantedIconName = "folder-open";
+ }
+
+ QHash<QByteArray, QVariant> itemData{data()};
+ if (itemData["iconName"] != wantedIconName) {
+ itemData.insert("iconName", wantedIconName);
+ setData(itemData);
+ invalidateIconCache();
+ }
+ });
+
+ connect(m_activateSoonAnimation, &QObject::destroyed, this, [originalIconName, this]() {
+ QHash<QByteArray, QVariant> itemData{data()};
+ if (itemData["iconName"] == "folder-open") {
+ itemData.insert("iconName", originalIconName);
+ setData(itemData);
+ invalidateIconCache();
+ }
+ });
+
+ m_activateSoonAnimation->start(QAbstractAnimation::DeleteWhenStopped);
+}
+
KItemListWidgetInformant *KStandardItemListWidget::createInformant()
{
return new KStandardItemListWidgetInformant();
void KStandardItemListWidget::hoveredChanged(bool hovered)
{
- Q_UNUSED(hovered)
+ if (!hovered && m_activateSoonAnimation) {
+ m_activateSoonAnimation->stop(); // automatically DeleteWhenStopped
+ }
m_dirtyLayout = true;
}
class KItemListRoleEditor;
class KItemListStyleOption;
class KItemListView;
+class QVariantAnimation;
/**
* @brief standard implementation of the ItemList widget informant for use with KStandardItemListView and KStandardItemModel.
QRectF expansionToggleRect() const override;
QRectF selectionToggleRect() const override;
QPixmap createDragPixmap(const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
+ /** @see KItemListWidget::startActivateSoonAnimation() */
+ void startActivateSoonAnimation(int timeUntilActivation) override;
static KItemListWidgetInformant *createInformant();
KItemListRoleEditor *m_roleEditor;
KItemListRoleEditor *m_oldRoleEditor;
+ /** @see startActivateSoonAnimation() */
+ QPointer<QVariantAnimation> m_activateSoonAnimation;
+
friend class KStandardItemListWidgetInformant; // Accesses private static methods to be able to
// share a common layout calculation
};