| 21 | #include <QPushButton> |
| 22 | |
| 23 | ToolTreeView::ToolTreeView(QWidget* parent) |
| 24 | : QTreeView(parent) |
| 25 | { |
| 26 | setDragDropMode(QAbstractItemView::InternalMove); |
| 27 | setDefaultDropAction(Qt::MoveAction); |
| 28 | setAlternatingRowColors(true); |
| 29 | setAnimated(true); |
| 30 | |
| 31 | m_model = new ToolModel(this); |
| 32 | setModel(m_model); |
| 33 | connect(selectionModel(), &QItemSelectionModel::selectionChanged, this, &ToolTreeView::updateActions); |
| 34 | header()->setSectionResizeMode(QHeaderView::ResizeToContents); |
| 35 | header()->setSectionResizeMode(1, QHeaderView::Stretch); |
| 36 | setMinimumWidth(400); |
| 37 | { |
| 38 | setIconSize(QSize(24, 24)); |
| 39 | const int w = indentation(); |
| 40 | const int h = rowHeight(model()->index(0, 0, QModelIndex())); |
| 41 | QImage i(w, h, QImage::Format_ARGB32); |
| 42 | QPainter p(&i); |
| 43 | p.setPen(QColor(128, 128, 128)); |
| 44 | // │ |
| 45 | i.fill(Qt::transparent); |
| 46 | p.drawLine(w >> 1, /**/ 0, w >> 1, /**/ h); |
| 47 | i.save("settings/vline.png", "PNG"); |
| 48 | // ├─ |
| 49 | p.drawLine(w >> 1, h >> 1, /**/ w, h >> 1); |
| 50 | i.save("settings/branch-more.png", "PNG"); |
| 51 | // └─ |
| 52 | i.fill(Qt::transparent); |
| 53 | p.drawLine(w >> 1, /**/ 0, w >> 1, h >> 1); |
| 54 | p.drawLine(w >> 1, h >> 1, /**/ w, h >> 1); |
| 55 | i.save("settings/branch-end.png", "PNG"); |
| 56 | QFile file(":/qtreeviewstylesheet/QTreeView.qss"); |
| 57 | file.open(QFile::ReadOnly); |
| 58 | setStyleSheet(file.readAll()); |
| 59 | header()->setMinimumHeight(h); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | void ToolTreeView::newGroup() |
| 64 | { |