Esempio n. 1
0
    virtual bool lessThan( const QModelIndex & left, const QModelIndex & right ) const
    {
        QFileSystemModel *model = static_cast<QFileSystemModel*>(this->sourceModel());
        QFileInfo l = model->fileInfo(left);
        QFileInfo r = model->fileInfo(right);
        if (l.isDir() && r.isFile()) {
            return true;
        } else if (l.isFile() && r.isDir()) {
            return false;
        }
#ifdef Q_OS_WIN
        if (l.filePath().length() <= 3 || r.filePath().length() <= 3) {
            return l.filePath().at(0) < r.filePath().at(0);
        }
#endif
        return (l.fileName().compare(r.fileName(),Qt::CaseInsensitive) < 0);
    }
Esempio n. 2
0
	virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const
	{
		QFileSystemModel *fsm = qobject_cast<QFileSystemModel*>(sourceModel());
		bool asc = (sortOrder() == Qt::AscendingOrder ? true : false) ;

		QFileInfo leftFileInfo  = fsm->fileInfo(left);
		QFileInfo rightFileInfo = fsm->fileInfo(right);

		// If Dot move in the beginning
		if (sourceModel()->data(left).toString() == ".")
			return asc;
		if (sourceModel()->data(right).toString() == ".")
			return !asc;

		// If DotAndDot move in the beginning
		if (sourceModel()->data(left).toString() == "..")
			return asc;
		if (sourceModel()->data(right).toString() == "..")
			return !asc;

		// Move dirs upper
		if (!leftFileInfo.isDir() && rightFileInfo.isDir())
			return !asc;
		if (leftFileInfo.isDir() && !rightFileInfo.isDir())
			return asc;


		/*If sorting by Size (Take real size, not Display one 10<2)*/
		if ((sortColumn()==1) && (!leftFileInfo.isDir() && !rightFileInfo.isDir())) {
			if (leftFileInfo.size() < rightFileInfo.size())
				return true;
			if (leftFileInfo.size() > rightFileInfo.size())
				return false;
		}
		/*If sorting by Date Modified (Take real date, not Display one 01-10-2014<02-01-1980)*/
		if (sortColumn()==3) {
			if (leftFileInfo.lastModified() < rightFileInfo.lastModified())
				return true;
			if (leftFileInfo.lastModified() > rightFileInfo.lastModified())
				return false;
		}
		//Columns found here:https://qt.gitorious.org/qt/qt/source/9e8abb63ba4609887d988ee15ba6daee0b01380e:src/gui/dialogs/qfilesystemmodel.cpp

		return QSortFilterProxyModel::lessThan(left, right);
	}
Esempio n. 3
0
void MainWindow::fileBrowserItemDblClicked(const QModelIndex& index)
{
    QFileSystemModel *fsModel = qobject_cast<QFileSystemModel*>(treeView->model());
    _lastFileBrowserItem = fsModel->fileInfo(index).absoluteFilePath();

	QFileInfo fileInfo(_lastFileBrowserItem);

	if (fileInfo.exists() && fileInfo.isFile())
		openFile(_lastFileBrowserItem);
}
Esempio n. 4
0
bool ListModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
    if (sortColumn() == 0) {
        QFileSystemModel *fsm = qobject_cast<QFileSystemModel*>(sourceModel());
        bool asc = sortOrder() == Qt::AscendingOrder ? true : false;

        QFileInfo leftFileInfo  = fsm->fileInfo(left);
        QFileInfo rightFileInfo = fsm->fileInfo(right);

        if (sourceModel()->data(left).toString() == "..")
            return asc;
        if (sourceModel()->data(right).toString() == "..")
            return !asc;

        if (!leftFileInfo.isDir() && rightFileInfo.isDir()) {
            return !asc;
        }
        if (leftFileInfo.isDir() && !rightFileInfo.isDir()) {
            return asc;
        }
    }

    return QSortFilterProxyModel::lessThan(left, right);
}
void ItemLibraryTreeView::activateItem( const QModelIndex & /*index*/)
{
    QMimeData *mimeData = model()->mimeData(selectedIndexes());
    if (!mimeData)
        return;

    QString name;
    QFileSystemModel *fileSystemModel = qobject_cast<QFileSystemModel*>(model());
    Q_ASSERT(fileSystemModel);
    QFileInfo fileInfo = fileSystemModel->fileInfo(selectedIndexes().front());
    QPixmap pixmap(fileInfo.absoluteFilePath());
    if (!pixmap.isNull()) {
        name = "image^" + fileInfo.absoluteFilePath();
        emit itemActivated(name);
    }
}
// We need to implement startDrag ourselves since we cannot
// otherwise influence drag pixmap and hotspot in the standard
// implementation.
void ItemLibraryTreeView::startDrag(Qt::DropActions /* supportedActions */)
{
    if (debug)
        qDebug() << Q_FUNC_INFO;
    QMimeData *mimeData = model()->mimeData(selectedIndexes());
    if (!mimeData)
        return;

    QFileSystemModel *fileSystemModel = qobject_cast<QFileSystemModel*>(model());
    Q_ASSERT(fileSystemModel);
    QFileInfo fileInfo = fileSystemModel->fileInfo(selectedIndexes().front());
    QPixmap pixmap(fileInfo.absoluteFilePath());
    if (!pixmap.isNull()) {
        QDrag *drag = new QDrag(this);
        drag->setPixmap(QIcon(pixmap).pixmap(128, 128));
        QMimeData *mimeData = new QMimeData;
        mimeData->setData("application/vnd.bauhaus.libraryresource", fileInfo.absoluteFilePath().toUtf8());
        drag->setMimeData(mimeData);
        drag->exec();
    }
}
Esempio n. 7
0
void FileInfoWidget::slotSelectionChanged(const QItemSelection&, const QItemSelection&)
{
    Page* pPage = dynamic_cast<Page*>(parent());
    if (pPage)
    {
        QFileSystemModel* pModel = dynamic_cast<QFileSystemModel*>(pPage->mpFileList->model());
        if (pModel)
        {
            QFileInfo info = pModel->fileInfo(pPage->mpFileList->currentIndex());
            if (info.isFile() && qPrintable(info.absoluteFilePath()))
            {
                QPixmap pixmap(info.absoluteFilePath());
                double dScale = pixmap.width() > pixmap.height() ? (double)imageSize.width() / pixmap.width() : (double)imageSize.height() / pixmap.height();
                dScale *= 0.9;
                mpImage->setPixmap(pixmap.scaled(pixmap.width() * dScale, pixmap.height() * dScale));
            }
            else mpImage->setPixmap(transparentImage);

            mpAbsolutePath->setText(QString("File Path: %1").arg(info.absoluteFilePath()));
            mpPermissions->setText(QString("Permissions: %1").arg(info.permissions(), 0, 16));
            mpSize->setText(QString("Size: %1").arg(info.size()));
        }
    }
}
Esempio n. 8
0
void TagEditor::searchOnline(){

    QModelIndexList indexes = TreeView->selectionModel()->selectedRows(0);

    if(indexes.size()==0){
        QMessageBox msgBox;
        msgBox.setText("No rows selected");
        msgBox.exec();
        return;
    }

    QModelIndex index = indexes[0];
    QFileSystemModel *m = (QFileSystemModel *)TreeView->model();
    bool isdir = m->isDir(index);

    QString query;
    QList<QFileInfo> info;
    QList<TagItem*> items;
    if(isdir){
        //folder/album
        QString folder = m->filePath(index);
        info = Global::getDirContent( folder, extensions, subfolders );
    }else{
        for(int i=0;i<indexes.size();i++){
            info.append( m->fileInfo( indexes[i] ) );
        }
    }
    if(info.size()==0){
        QMessageBox msgBox;
        msgBox.setText("Empty folder...");
        msgBox.exec();
        return;
    }

    for(int i=0;i<info.size();i++){
        items.append(new TagItem(info[i].absoluteFilePath()));
    }

    SearchDialog d( items, this );
    //d.setModal(false);
    d.exec();
    /*
	if( d.exec()>=0 ){
		//save settings anyway
		//settings = d.getSettings();
	}
	*/

    //delete tag data from these files if they exist in TreeWidget_, since the tag data now might get changed
    for(int i=0;i<TreeWidget_->topLevelItemCount();i++){
        if( info.size()==0 ){
            break;
        }
        TagItem *item = (TagItem*)TreeWidget_->topLevelItem(i);
        for(int j=0;j<info.size();j++){
            if( item->data(0,TreeWidget::FULLFILE)==info.at(j).absoluteFilePath() ){
                item->clearTags();
                info.removeAt( j );
                break;
            }
        }
    }

}
Esempio n. 9
0
void MainWindow::fileBrowserItemClicked(const QModelIndex& index)
{
    QFileSystemModel *fsModel = qobject_cast<QFileSystemModel*>(treeView->model());
    _lastFileBrowserItem = fsModel->fileInfo(index).absoluteFilePath();
}