scide: implement selectionLength for openDocument
[supercollider.git] / QtCollider / widgets / QcTreeWidget.h
blob26bfc31f6176096c477a9b6e6c4bf0f715413265
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
40 public:
42 class Item : public QTreeWidgetItem
44 public:
45 enum { Type = QTreeWidgetItem::UserType };
46 Item()
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 * );
55 bool operator< ( const QTreeWidgetItem & other ) const;
56 private:
57 SafePtr<Item> _safePtr;
60 typedef SafePtr<Item> ItemPtr;
62 Q_OBJECT
63 Q_PROPERTY( VariantList columns READ columns WRITE setColumns )
64 Q_PROPERTY( QcTreeWidget::ItemPtr currentItem READ currentItem WRITE setCurrentItem );
66 public:
68 Q_INVOKABLE QcTreeWidget::ItemPtr item( const QcTreeWidget::ItemPtr & parent, int index );
69 Q_INVOKABLE QcTreeWidget::ItemPtr parentItem( const QcTreeWidget::ItemPtr & );
70 Q_INVOKABLE int indexOfItem( const QcTreeWidget::ItemPtr & );
72 Q_INVOKABLE QcTreeWidget::ItemPtr addItem
73 ( const QcTreeWidget::ItemPtr & parent, const VariantList & data );
75 Q_INVOKABLE QcTreeWidget::ItemPtr insertItem
76 ( const QcTreeWidget::ItemPtr & parent, int index, const VariantList & data );
78 Q_INVOKABLE void removeItem( const QcTreeWidget::ItemPtr & );
80 Q_INVOKABLE VariantList strings( const QcTreeWidget::ItemPtr & );
81 Q_INVOKABLE void setText( const QcTreeWidget::ItemPtr &, int column, const QString & );
82 Q_INVOKABLE void setColor( const QcTreeWidget::ItemPtr &, int column, const QColor & );
83 Q_INVOKABLE void setTextColor( const QcTreeWidget::ItemPtr &, int column, const QColor & );
85 Q_INVOKABLE QWidget * itemWidget( const QcTreeWidget::ItemPtr &, int column );
86 Q_INVOKABLE void setItemWidget( const QcTreeWidget::ItemPtr &, int column, QObjectProxy * );
87 Q_INVOKABLE void removeItemWidget( const QcTreeWidget::ItemPtr &, int column );
89 Q_INVOKABLE void sort( int column, bool descending );
91 Q_SIGNALS:
93 void action();
94 void itemPressedAction();
95 void currentItemChanged();
97 public:
99 QcTreeWidget();
101 ItemPtr currentItem() const;
102 void setCurrentItem( const ItemPtr & );
104 VariantList columns() const;
105 void setColumns( const VariantList & );
107 protected:
109 virtual void keyPressEvent( QKeyEvent * );
111 private:
113 QTreeWidgetItem * _itemOnPress;
114 bool _emitAction;
117 Q_DECLARE_METATYPE( QcTreeWidget::ItemPtr );
119 #endif