summaryrefslogtreecommitdiffstats
path: root/src/library/stardelegate.h
blob: 999c65e2ffc1459814e7ebb9b5f8b2d427e629aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/***************************************************************************
                           stardelegate.h
                              -------------------
     copyright            : (C) 2010 Tobias Rafreider
     copyright            : (C) 2009 Nokia Corporation

***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/


#ifndef STARDELEGATE_H
#define STARDELEGATE_H

#include "library/tableitemdelegate.h"

class StarDelegate : public TableItemDelegate {
    Q_OBJECT
  public:
    StarDelegate(QTableView* pTrackTable);

    // reimplemented from QItemDelegate and is called whenever the view needs to
    // repaint an item
    void paintItem(QPainter* painter, const QStyleOptionViewItem& option,
               const QModelIndex& index) const;

    // returns an item's preferred size
    QSize sizeHint(const QStyleOptionViewItem& option,
                   const QModelIndex& index) const;

    // called when the user starts editing an item
    QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
                          const QModelIndex& index) const;

    // called when an editor is created to initialize it with data from the
    // model
    void setEditorData(QWidget* editor, const QModelIndex& index) const;

    // called when editing is finished, to commit data from the editor to the
    // model
    void setModelData(QWidget* editor, QAbstractItemModel* model,
                      const QModelIndex& index) const;

  private slots:
    void commitAndCloseEditor();
    void cellEntered(const QModelIndex& index);

  private:
    QTableView* m_pTableView;
    QPersistentModelIndex m_currentEditedCellIndex;
    bool m_isOneCellInEditMode;
};

#endif