1 /************************************************************************
3 * Copyright 2011 Jakob Leben (jakob.leben@gmail.com)
5 * This file is part of SuperCollider Qt GUI.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ************************************************************************/
22 #ifndef QC_TREE_WIDGET_H
23 #define QC_TREE_WIDGET_H
25 #include "../Common.h"
26 #include "../QObjectProxy.h"
27 #include "../safeptr.hpp"
29 #include <VMGlobals.h>
30 #include <PyrObject.h>
32 #include <QTreeWidget>
33 #include <QTreeWidgetItem>
34 #include <QApplication>
36 using namespace QtCollider
;
38 class QcTreeWidget
: public QTreeWidget
42 class Item
: public QTreeWidgetItem
45 enum { Type
= QTreeWidgetItem::UserType
};
47 : QTreeWidgetItem( Item::Type
), _safePtr(this) {}
48 Item( const QStringList
& strings
)
49 : QTreeWidgetItem( strings
, Item::Type
), _safePtr(this) {}
50 ~Item() { _safePtr
.invalidate(); }
51 SafePtr
<Item
> safePtr() const { return _safePtr
; }
52 static SafePtr
<Item
> safePtr( QTreeWidgetItem
* );
53 static void initialize( VMGlobals
*, PyrObject
*, const SafePtr
<Item
> & );
54 static int finalize( VMGlobals
*, PyrObject
* );
56 SafePtr
<Item
> _safePtr
;
59 typedef SafePtr
<Item
> ItemPtr
;
62 Q_PROPERTY( VariantList columns READ columns WRITE setColumns
)
63 Q_PROPERTY( QcTreeWidget::ItemPtr currentItem READ currentItem WRITE setCurrentItem
);
67 Q_INVOKABLE
QcTreeWidget::ItemPtr
item( const QcTreeWidget::ItemPtr
& parent
, int index
);
68 Q_INVOKABLE
QcTreeWidget::ItemPtr
parentItem( const QcTreeWidget::ItemPtr
& );
69 Q_INVOKABLE
int indexOfItem( const QcTreeWidget::ItemPtr
& );
71 Q_INVOKABLE
QcTreeWidget::ItemPtr addItem
72 ( const QcTreeWidget::ItemPtr
& parent
, const VariantList
& data
);
74 Q_INVOKABLE
QcTreeWidget::ItemPtr insertItem
75 ( const QcTreeWidget::ItemPtr
& parent
, int index
, const VariantList
& data
);
77 Q_INVOKABLE
void removeItem( const QcTreeWidget::ItemPtr
& );
79 Q_INVOKABLE VariantList
strings( const QcTreeWidget::ItemPtr
& );
80 Q_INVOKABLE
void setText( const QcTreeWidget::ItemPtr
&, int column
, const QString
& );
81 Q_INVOKABLE
void setColor( const QcTreeWidget::ItemPtr
&, int column
, const QColor
& );
82 Q_INVOKABLE
void setTextColor( const QcTreeWidget::ItemPtr
&, int column
, const QColor
& );
84 Q_INVOKABLE QWidget
* itemWidget( const QcTreeWidget::ItemPtr
&, int column
);
85 Q_INVOKABLE
void setItemWidget( const QcTreeWidget::ItemPtr
&, int column
, QObjectProxy
* );
86 Q_INVOKABLE
void removeItemWidget( const QcTreeWidget::ItemPtr
&, int column
);
88 Q_INVOKABLE
void sort( int column
, bool descending
);
93 void itemPressedAction();
94 void currentItemChanged();
100 ItemPtr
currentItem() const;
101 void setCurrentItem( const ItemPtr
& );
103 VariantList
columns() const;
104 void setColumns( const VariantList
& );
108 QTreeWidgetItem
* _itemOnPress
;
112 Q_DECLARE_METATYPE( QcTreeWidget::ItemPtr
);