PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 36ms app.codeStats 0ms

/src/libtomahawk/widgets/Breadcrumb.h

http://github.com/tomahawk-player/tomahawk
C Header | 88 lines | 39 code | 19 blank | 30 comment | 0 complexity | 4f50c1453553277d10fac3c35ea9aea5 MD5 | raw file
 1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 2 *
 3 *   Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
 4 *
 5 *   Tomahawk is free software: you can redistribute it and/or modify
 6 *   it under the terms of the GNU General Public License as published by
 7 *   the Free Software Foundation, either version 3 of the License, or
 8 *   (at your option) any later version.
 9 *
10 *   Tomahawk is distributed in the hope that it will be useful,
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *   GNU General Public License for more details.
14 *
15 *   You should have received a copy of the GNU General Public License
16 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef TOMAHAWK_BREADCRUMB_H
20#define TOMAHAWK_BREADCRUMB_H
21
22#include <QWidget>
23#include <QModelIndex>
24
25class QHBoxLayout;
26class QAbstractItemModel;
27
28namespace Tomahawk {
29
30class BreadcrumbButton;
31
32/**
33 * A breadcrumb widget for Tomahawk's needs.
34 *
35 * This breadcrumb operates on a QAIM. It uses a KBreadcrumbSelectionModel to manage the visible
36 *  breadcrumb selection.
37 * This breadcrumb always expands fully to the deepest child.
38 * Selections are remembered when switching to/from in parent nodes
39 * Items that have a DefaultRole set will automatically select the default unless the user has
40 *  made a previous selection, which is saved in the UserSelection role
41 */
42
43//HACK: I'm exporting this, so I can move view pages to libtomahawk-widgets one by one
44//TODO: In the end this class should go there too (and be made private again?)
45#include "../DllMacro.h"
46class DLLEXPORT Breadcrumb : public QWidget
47{
48    Q_OBJECT
49public:
50    enum ExtraRoles {
51        DefaultRole = Qt::UserRole + 1,
52        UserSelectedRole = Qt::UserRole + 2,
53        ChartIdRole = Qt::UserRole + 3,
54        ChartExpireRole = Qt::UserRole + 4
55    };
56
57    explicit Breadcrumb( QWidget* parent = 0, Qt::WindowFlags f = 0 );
58    virtual ~Breadcrumb();
59
60    void setModel( QAbstractItemModel* model );
61    QAbstractItemModel* model() const { return m_model; }
62
63    void setRootIcon( const QPixmap& pm );
64
65protected:
66    virtual void paintEvent( QPaintEvent* );
67
68signals:
69    void activateIndex( const QModelIndex& idx );
70
71private slots:
72    void breadcrumbComboChanged( const QModelIndex& );
73
74private:
75    // Takes an index in the selection model to update from (updates from that to all children)
76    void updateButtons( const QModelIndex& fromIndex );
77
78    QAbstractItemModel* m_model;
79    QPixmap m_rootIcon;
80
81    QHBoxLayout* m_buttonlayout;
82    QList<BreadcrumbButton*> m_buttons;
83};
84
85}
86
87#endif // TOMAHAWK_BREADCRUMB_H
88