File indexing completed on 2024-04-28 08:49:42

0001 /* This file is part of the KDE project
0002 
0003    Copyright (C) 2006 Dario Massarin <nekkar@libero.it>
0004    Copyright (C) 2007 by Javier Goday <jgoday@gmail.com>
0005    Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net>
0006 
0007    This program is free software; you can redistribute it and/or
0008    modify it under the terms of the GNU General Public
0009    License as published by the Free Software Foundation; either
0010    version 2 of the License, or (at your option) any later version.
0011 */
0012 
0013 #ifndef TRANSFERSVIEWDELEGATE_H
0014 #define TRANSFERSVIEWDELEGATE_H
0015 
0016 #include <KExtendableItemDelegate>
0017 
0018 #include <QModelIndex>
0019 #include <QToolButton>
0020 
0021 class QHBoxLayout;
0022 class QButtonGroup;
0023 
0024 class TransfersViewDelegate;
0025 
0026 class GroupStatusButton : public QToolButton
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     GroupStatusButton(const QModelIndex &index, QWidget *parent);
0032 
0033 protected:
0034     void checkStateSet() override;
0035     void enterEvent(QEnterEvent *event) override;
0036     void leaveEvent(QEvent *event) override;
0037     void paintEvent(QPaintEvent *event) override;
0038     void timerEvent(QTimerEvent *event) override;
0039 
0040 private:
0041     enum { None, Selecting, Deselecting, Blinking, BlinkingExiting } m_status;
0042     QModelIndex m_index;
0043 
0044     int m_timerId;
0045     int m_iconSize;
0046 
0047     float m_gradientId;
0048 };
0049 
0050 class GroupStatusEditor : public QWidget
0051 {
0052     Q_OBJECT
0053 
0054 public:
0055     GroupStatusEditor(const QModelIndex &index, QWidget *parent);
0056 
0057     void setRunning(bool running);
0058     bool isRunning();
0059 
0060 private Q_SLOTS:
0061     void slotStatusChanged();
0062 
0063 Q_SIGNALS:
0064     void changedStatus(GroupStatusEditor *editor);
0065 
0066 private:
0067     QModelIndex m_index;
0068 
0069     QHBoxLayout *m_layout;
0070 
0071     QButtonGroup *m_btGroup;
0072     GroupStatusButton *m_startBt;
0073     GroupStatusButton *m_stopBt;
0074 };
0075 
0076 /**
0077  * The BasicTransfersViewDelegate handles the setting of the status of a group
0078  */
0079 class BasicTransfersViewDelegate : public KExtendableItemDelegate
0080 {
0081     Q_OBJECT
0082 
0083 public:
0084     BasicTransfersViewDelegate(QAbstractItemView *parent);
0085 
0086     QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0087     void setEditorData(QWidget *editor, const QModelIndex &index) const override;
0088     void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
0089 
0090 private Q_SLOTS:
0091     virtual void slotGroupStatusChanged(GroupStatusEditor *editor);
0092 };
0093 
0094 class TransfersViewDelegate : public BasicTransfersViewDelegate
0095 {
0096     Q_OBJECT
0097 
0098 public:
0099     TransfersViewDelegate(QAbstractItemView *parent);
0100 
0101     void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0102 
0103     void drawFocus(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect) const;
0104 
0105     QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0106 
0107     bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override;
0108 };
0109 
0110 #endif