Esempio n. 1
0
FolderChooser::FolderChooser(const QString & start_folder,QWidget *parent) : QDialog(parent), ui(new Ui::FolderChooser) {
    ui->setupUi(this);

    QFileSystemModel *model = new QFileSystemModel(ui->folderView);
    model->setFilter(QDir::Dirs|QDir::Drives|QDir::NoDotAndDotDot);
    ui->folderView->setModel(model);
    QModelIndex root_index = model->setRootPath(start_folder);
    if (root_index.isValid()) {
        QItemSelection selection(root_index,model->index(root_index.row(),model->columnCount()-1,root_index.parent()));
        ui->folderView->selectionModel()->select(selection,QItemSelectionModel::ClearAndSelect);
        ui->folderView->scrollTo(root_index);
        ui->folderView->expand(root_index);
    }

    connect(ui->folderView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),this,SLOT(selectionChanged()));

#if QT_VERSION >= 0x050000
    ui->folderView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
#else
    ui->folderView->header()->setResizeMode(0, QHeaderView::ResizeToContents);
#endif

    ui->folderView->header()->hideSection(1);
    ui->folderView->header()->hideSection(2);
    ui->folderView->header()->hideSection(3);

    selectionChanged();
}
Esempio n. 2
0
QWidget* MainWidget::createTreeWidget()
{
    QFileSystemModel *fModel = new QFileSystemModel;
    fModel->setRootPath("");
    fModel->setFilter(QDir::Dirs | QDir::NoDotAndDotDot);

    tView = new QTreeView;
    tView->setStyleSheet("QTreeView{border:0;}");
    tView->setModel(fModel);
    tView->setAnimated(false);
    tView->setHeaderHidden(true);
    for(int i=1; i<fModel->columnCount(); i++){
        tView->setColumnHidden(i, true);
    }
    connect(tView,SIGNAL(clicked(QModelIndex)),this,SLOT(slotTreeItemClicked(QModelIndex)));
    return tView;
}
Esempio n. 3
0
QObject* FileSystemTab::component(Jerboa::Plugin::ComponentType type, QObject* parent)
{
	switch(type)
	{
		case Jerboa::Plugin::WidgetUsedWithPlaylist:
			{
				QFileSystemModel* model = new FileSystemModelWithToolTip(parent);
				model->setRootPath("/");
				model->setFilter(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs);
				model->setNameFilterDisables(false);

				QStringList musicGlobs;
				musicGlobs
					<< "*.aac"
					<< "*.aiff"
					<< "*.ape"
					<< "*.au"
					<< "*.cdda"
					<< "*.flac"
					<< "*.m4a"
					<< "*.mp3"
					<< "*.oga"
					<< "*.ogg"
					<< "*.ogm"
					<< "*.wav"
					<< "*.wma"
				;
				model->setNameFilters(musicGlobs);

				QTreeView* view = new QTreeView(qobject_cast<QWidget*>(parent));
				view->setWindowTitle("Files");
				view->setModel(model);
				view->setHeaderHidden(true);
				for(int i = 1; i < model->columnCount(); ++i)
				{
					view->setColumnHidden(i, true);
				}

				QString path = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);

				if(path.isEmpty() || !QDir(path).exists())
				{
					path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
				}

				const QModelIndex index(model->index(QSettings().value("collection/directory", path).toString()));
				for(QModelIndex iterator(index); iterator.isValid(); iterator = iterator.parent())
				{
					view->setExpanded(iterator, true);
				}

				view->setDragDropMode(QAbstractItemView::DragOnly);
				view->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
				view->setSelectionMode(QAbstractItemView::ExtendedSelection);

				connect(
					view,
					SIGNAL(doubleClicked(QModelIndex)),
					this,
					SLOT(addPathToPlaylist(QModelIndex))
				);

				QTimer* timer = new QTimer(this);
				connect(
					timer,
					SIGNAL(timeout()),
					this,
					SLOT(scrollToSelection())
				);
				timer->setSingleShot(true);
				timer->start(1000);

				m_view = view;
				return view;
			}
		default:
			return Jerboa::Plugin::component(type, parent);
	}
}