/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. #ifndef TOMAHAWK_BREADCRUMB_H
  19. #define TOMAHAWK_BREADCRUMB_H
  20. #include <QWidget>
  21. #include <QModelIndex>
  22. class QHBoxLayout;
  23. class QAbstractItemModel;
  24. namespace Tomahawk {
  25. class BreadcrumbButton;
  26. /**
  27. * A breadcrumb widget for Tomahawk's needs.
  28. *
  29. * This breadcrumb operates on a QAIM. It uses a KBreadcrumbSelectionModel to manage the visible
  30. * breadcrumb selection.
  31. * This breadcrumb always expands fully to the deepest child.
  32. * Selections are remembered when switching to/from in parent nodes
  33. * Items that have a DefaultRole set will automatically select the default unless the user has
  34. * made a previous selection, which is saved in the UserSelection role
  35. */
  36. //HACK: I'm exporting this, so I can move view pages to libtomahawk-widgets one by one
  37. //TODO: In the end this class should go there too (and be made private again?)
  38. #include "../DllMacro.h"
  39. class DLLEXPORT Breadcrumb : public QWidget
  40. {
  41. Q_OBJECT
  42. public:
  43. enum ExtraRoles {
  44. DefaultRole = Qt::UserRole + 1,
  45. UserSelectedRole = Qt::UserRole + 2,
  46. ChartIdRole = Qt::UserRole + 3,
  47. ChartExpireRole = Qt::UserRole + 4
  48. };
  49. explicit Breadcrumb( QWidget* parent = 0, Qt::WindowFlags f = 0 );
  50. virtual ~Breadcrumb();
  51. void setModel( QAbstractItemModel* model );
  52. QAbstractItemModel* model() const { return m_model; }
  53. void setRootIcon( const QPixmap& pm );
  54. protected:
  55. virtual void paintEvent( QPaintEvent* );
  56. signals:
  57. void activateIndex( const QModelIndex& idx );
  58. private slots:
  59. void breadcrumbComboChanged( const QModelIndex& );
  60. private:
  61. // Takes an index in the selection model to update from (updates from that to all children)
  62. void updateButtons( const QModelIndex& fromIndex );
  63. QAbstractItemModel* m_model;
  64. QPixmap m_rootIcon;
  65. QHBoxLayout* m_buttonlayout;
  66. QList<BreadcrumbButton*> m_buttons;
  67. };
  68. }
  69. #endif // TOMAHAWK_BREADCRUMB_H