1 /*************************************************************************** 2 rkaccordiontable - description 3 ------------------- 4 begin : Fri Oct 24 2015 5 copyright : (C) 2015 by Thomas Friedrichsmeier 6 email : thomas.friedrichsmeier@kdemail.net 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #ifndef RKACCORDIONTABLE_H 19 #define RKACCORDIONTABLE_H 20 21 #include <QWidget> 22 #include <QTreeView> 23 24 class RKAccordionDummyModel; 25 26 class RKAccordionTable : public QTreeView { 27 Q_OBJECT 28 public: 29 explicit RKAccordionTable (QWidget *parent); 30 ~RKAccordionTable (); 31 editorWidget()32 QWidget *editorWidget () const { return editor_widget; }; 33 34 void setModel (QAbstractItemModel *model) override; 35 void setShowAddRemoveButtons (bool show); 36 37 QSize sizeHint () const override; // reimplemented to assure a proper size for the content 38 public slots: 39 void rowExpanded (QModelIndex row); 40 void rowClicked (QModelIndex row); 41 void updateWidget (); 42 void removeClicked (); 43 void activateRow (int row); 44 signals: 45 void activated (int row); 46 void addRow (int where); 47 void removeRow (int which); 48 protected: 49 void resizeEvent (QResizeEvent* event) override; // reimplemented to make the current content widget stretch / shrink 50 void currentChanged (const QModelIndex& current, const QModelIndex& previous) override; 51 void mousePressEvent (QMouseEvent* event) override; 52 void drawRow (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override; 53 private: 54 QSize sizeHintWithoutEditor () const; 55 int rowOfButton (QObject *button) const; 56 bool show_add_remove_buttons; 57 QWidget *editor_widget; 58 QWidget *editor_widget_container; 59 RKAccordionDummyModel *pmodel; 60 bool handling_a_click; 61 }; 62 63 #endif 64