Ejemplo n.º 1
0
void DirectoryTree::on_locate_directory(int directory_id)
{
    DirectoryTreeModel *m = dynamic_cast<DirectoryTreeModel*>(model());
    assert(NULL != m);
    QModelIndex index = m->directory_index(directory_id);
    if (index.isValid())
    {
        scrollTo(index);
        selectionModel()->select(index, QItemSelectionModel::ToggleCurrent);
        on_item_selected(index, index);
    }
}
Ejemplo n.º 2
0
void GuiListbox::set_selected_index(int index) {
    int old_index = selected_index;
    int sz = static_cast<int>(entries.size());
    if (index < 0) {
        index = -1;
    }
    if (index >= sz) {
        index = sz - 1;
    }
    selected_index = index;

    if (selected_index != old_index && on_item_selected) {
        if (index >= 0) {
            on_item_selected(this, on_item_selected_data, selected_index);
        }
    }
}
Ejemplo n.º 3
0
DirectoryTree::DirectoryTree(QWidget *parent)
    : QTreeView(parent)
{
    assert(NULL != parent);

    // model
    PkmPlugin *plugin = dynamic_cast<PkmPlugin*>(get_plugin().pointer());
    assert(NULL != plugin);
    DirectoryTreeModel *model = new DirectoryTreeModel(plugin->get_data_source()->get_db(), parent);
    connect(this, SIGNAL(expanded(QModelIndex)), model, SLOT(on_expanded(QModelIndex)));
    connect(this, SIGNAL(collapsed(QModelIndex)), model, SLOT(on_collapsed(QModelIndex)));
    setModel(model);

    // actions
    init_actions();

    // menus
    init_menus();

    // 双击展开而非进入编辑模式
    setExpandsOnDoubleClick(true);
    setAutoExpandDelay(600); // 拖拽时自动展开节点的延时(ms)
    setEditTriggers(EditKeyPressed);
    setMinimumWidth(140);

    // 隐藏首部
    setHeaderHidden(true);

    // 拖拽相关
    setSelectionMode(QAbstractItemView::SingleSelection); // 单选
    setDragEnabled(true); // 允许"拖"
    setAcceptDrops(true); // 允许"放"
    setDropIndicatorShown(true); // ?
    setDragDropMode(QAbstractItemView::DragDrop);
    setDefaultDropAction(Qt::MoveAction);

    // signals
    connect(this, SIGNAL(activated(QModelIndex)), this, SLOT(on_item_activated(QModelIndex)));
    // connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(on_item_activated(QModelIndex)));
    connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(on_item_selected(QModelIndex,QModelIndex)));
    plugin->locate_directory.connect(this, &DirectoryTree::on_locate_directory);
}