File indexing completed on 2022-11-29 14:16:04

0001 /*
0002     Qt item view mouse hover button
0003 
0004     Copyright (C) 2008 Peter Penz <peter dot penz at gmx dot at>
0005     Copyright (C) 2009 Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0006     Copyright (C) 2011 Martin Klapetek <martin dot klapetek at gmail dot com>
0007 
0008     This library is free software; you can redistribute it and/or
0009     modify it under the terms of the GNU Lesser General Public
0010     License as published by the Free Software Foundation; either
0011     version 2.1 of the License, or (at your option) any later version.
0012 
0013     This library is distributed in the hope that it will be useful,
0014     but WITHOUT ANY WARRANTY; without even the implied warranty of
0015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016     Lesser General Public License for more details.
0017 
0018     You should have received a copy of the GNU Lesser General Public
0019     License along with this library; if not, write to the Free Software
0020     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0021 */
0022 
0023 #ifndef CONTACTVIEWHOVERBUTTON_H
0024 #define CONTACTVIEWHOVERBUTTON_H
0025 
0026 // Qt includes
0027 
0028 #include <QAbstractButton>
0029 #include <QAbstractItemView>
0030 
0031 // Local includes
0032 
0033 class QTimeLine;
0034 
0035 class ContactViewHoverButton : public QAbstractButton
0036 {
0037     Q_OBJECT
0038 
0039 public:
0040     ContactViewHoverButton(QAbstractItemView *parentView);
0041     void initIcon();
0042     void reset();
0043     void setIndex(const QModelIndex &index);
0044     QModelIndex index() const;
0045     void setVisible(bool visible);
0046 
0047     /// Reimplement to match the size of your icon
0048     virtual QSize sizeHint() const = 0;
0049 
0050 protected:
0051     void enterEvent(QEvent *event);
0052     void leaveEvent(QEvent *event);
0053     void paintEvent(QPaintEvent *event);
0054 
0055     /// Return your icon here. Will be queried again on toggle.
0056     virtual QPixmap icon() = 0;
0057     /// Optionally update tooltip here. Will be called again on state change.
0058     virtual void updateToolTip();
0059 
0060 protected Q_SLOTS:
0061     void setFadingValue(int value);
0062     void refreshIcon();
0063     void startFading();
0064     void stopFading();
0065 
0066 protected:
0067     QPersistentModelIndex m_index;
0068     bool                  m_isHovered;
0069     int                   m_fadingValue;
0070     QPixmap               m_icon;
0071     QTimeLine            *m_fadingTimeLine;
0072 };
0073 
0074 #endif /* CONTACTVIEWHOVERBUTTON_H */