示例#1
0
FolderModel::FolderModel(QObject *parent) : QSortFilterProxyModel(parent),
    m_dirWatch(nullptr),
    m_dragInProgress(false),
    m_previewGenerator(0),
    m_viewAdapter(0),
    m_actionCollection(this),
    m_newMenu(0),
    m_fileItemActions(0),
    m_usedByContainment(false),
    m_locked(true),
    m_sortMode(0),
    m_sortDesc(false),
    m_sortDirsFirst(true),
    m_parseDesktopFiles(false),
    m_previews(false),
    m_filterMode(NoFilter),
    m_filterPatternMatchAll(true)
{
    DirLister *dirLister = new DirLister(this);
    dirLister->setDelayedMimeTypes(true);
    dirLister->setAutoErrorHandlingEnabled(false, 0);
    connect(dirLister, &DirLister::error, this, &FolderModel::dirListFailed);
    connect(dirLister, &KCoreDirLister::itemsDeleted, this, &FolderModel::evictFromIsDirCache);

    m_dirModel = new KDirModel(this);
    m_dirModel->setDirLister(dirLister);
    m_dirModel->setDropsAllowed(KDirModel::DropOnDirectory | KDirModel::DropOnLocalExecutable);

    m_selectionModel = new QItemSelectionModel(this, this);
    connect(m_selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
            this, SLOT(selectionChanged(QItemSelection,QItemSelection)));

    setSourceModel(m_dirModel);

    setSortLocaleAware(true);
    setFilterCaseSensitivity(Qt::CaseInsensitive);
    setDynamicSortFilter(true);

    sort(m_sortMode, m_sortDesc ? Qt::DescendingOrder : Qt::AscendingOrder);

    setSupportedDragActions(Qt::CopyAction | Qt::MoveAction | Qt::LinkAction);

    createActions();
}
示例#2
0
void PopupView::init()
{
    if (m_model) {
        return;
    }

    m_scene = new QGraphicsScene(this);
    m_view = new QGraphicsView(m_scene, this);
    m_view->setFrameShape(QFrame::NoFrame);
    m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    m_view->viewport()->setAutoFillBackground(false);
    m_view->setGeometry(contentsRect());
    m_view->show();

    DirLister *lister = new DirLister(this);
    lister->setDelayedMimeTypes(true);
    lister->setAutoErrorHandlingEnabled(false, 0);
    lister->openUrl(m_url);

    m_dirModel = new KDirModel(this);
    m_dirModel->setDropsAllowed(KDirModel::DropOnDirectory | KDirModel::DropOnLocalExecutable);
    m_dirModel->setDirLister(lister);

    m_model = new ProxyModel(this);
    m_model->setSourceModel(m_dirModel);
    m_model->setSortLocaleAware(m_parentViewModel->isSortLocaleAware());
    m_model->setParseDesktopFiles(m_parentViewModel->parseDesktopFiles());
    m_model->setFilterMode(m_parentViewModel->ProxyModel::NoFilter);
    m_model->setDynamicSortFilter(true);

    if (!m_parentViewModel->dynamicSortFilter()) {
        m_model->setSortDirectoriesFirst(true);
        m_model->sort(int(KDirModel::Name), Qt::AscendingOrder);
    } else {
        m_model->setSortDirectoriesFirst(m_parentViewModel->sortDirectoriesFirst());
        m_model->sort(m_parentViewModel->sortColumn(), m_parentViewModel->sortOrder());
    }

    m_delegate = new KFileItemDelegate(this);
    m_selectionModel = new QItemSelectionModel(m_model, this);

    m_iconView = new IconView(0);
    m_iconView->setModel(m_model);
    m_iconView->setItemDelegate(m_delegate);
    m_iconView->setSelectionModel(m_selectionModel);
    m_iconView->setFont(m_parentView->font());
    m_iconView->setPalette(palette());
    m_iconView->setDrawShadows(m_parentView->drawShadows());
    m_iconView->setIconSize(m_parentView->iconSize());
    m_iconView->setGridSize(m_parentView->gridSize());
    m_iconView->setTextLineCount(m_parentView->textLineCount());
    m_iconView->setWordWrap(m_parentView->wordWrap());
    m_iconView->setIconsMoveable(false);
    m_iconView->setClickToViewFolders(false);
    m_iconView->setShowSelectionMarker(m_parentView->showSelectionMarker());

    connect(m_iconView, SIGNAL(activated(QModelIndex)), SLOT(activated(QModelIndex)));
    connect(m_iconView, SIGNAL(contextMenuRequest(QWidget*,QPoint)), SLOT(contextMenuRequest(QWidget*,QPoint)));
    connect(m_iconView, SIGNAL(busy(bool)), SLOT(setBusy(bool)));
    connect(m_iconView, SIGNAL(popupViewClosed()), SLOT(maybeClose()));

    FolderViewAdapter *adapter = new FolderViewAdapter(m_iconView);
    m_previewGenerator = new KFilePreviewGenerator(adapter, m_model);
    m_previewGenerator->setPreviewShown(m_showPreview);
    m_previewGenerator->setEnabledPlugins(m_previewPlugins);

    m_iconView->setGeometry(contentsRect());
    m_iconView->show();

    m_scene->addItem(m_iconView);
    setBusy(true);
}