Files
qglengine/widgets/treewidget_p.h
2022-12-14 14:14:44 +03:00

61 lines
1.8 KiB
C++

/*
QGL SceneTree
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TREEWIDGET_H
#define TREEWIDGET_H
#include <QDebug>
#include <QDropEvent>
#include <QStyledItemDelegate>
#include <QTimer>
#include <QTreeWidget>
class InternalMoveTreeWidget: public QTreeWidget {
Q_OBJECT
public:
InternalMoveTreeWidget(QWidget * parent = 0): QTreeWidget(parent) {}
protected:
virtual void dropEvent(QDropEvent * e) {
QList<QTreeWidgetItem *> sil = selectedItems();
if (sil.isEmpty()) return;
QTreeWidget::dropEvent(e);
foreach(QTreeWidgetItem * ti, sil) {
QTreeWidgetItem * ti_p = ti->parent();
if (!ti_p) ti_p = invisibleRootItem();
int ti_ppos = ti_p->indexOfChild(ti);
emit itemMoved(ti, ti_p, ti_ppos);
}
}
signals:
void itemMoved(QTreeWidgetItem * item, QTreeWidgetItem * new_parent, int new_index);
};
class NoEditDelegate: public QStyledItemDelegate {
public:
NoEditDelegate(QObject * parent = 0): QStyledItemDelegate(parent) {}
virtual QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const {
return nullptr;
}
};
#endif // TREEWIDGET_H