/* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. */ #include #include #include #include #include #include #include #include #include #include "fileview.h" #include "messagedialog.h" FileView::FileView(QWidget *parent) : QTreeView(parent) { setRootIsDecorated(false); mMarkDialog = new MessageDialog(tr("Enter pattern to mark"), this); connect(mMarkDialog, SIGNAL(accepted()), this, SLOT(doMark())); } void FileView::markFiles(){ mMarkDialog->show(); } void FileView::unmarkFiles(){ selectionModel()->clearSelection(); } void FileView::doMark(){ int rowCount = model()->rowCount(rootIndex()); QString sRegex = mMarkDialog->text(); if(rowCount && !sRegex.isEmpty()){ QRegExp re(sRegex); QSortFilterProxyModel *proxy = static_cast(model()); QDirModel *model = static_cast(proxy->sourceModel()); for(int i = 0; i < rowCount; ++i){ QModelIndex cur = rootIndex().child(i, 0); QModelIndex sCur = proxy->mapToSource(cur); if(model->isDir(sCur)){ continue; } if(re.indexIn(cur.data().toString()) != -1){ selectionModel()->select(cur, QItemSelectionModel::Select | QItemSelectionModel::Rows); } } } } void FileView::contextMenuEvent(QContextMenuEvent *e){ QMenu contextMenu(this); int ctr(0); foreach(QAction *a, actions()){ contextMenu.addAction(a); if(false){ contextMenu.addSeparator(); } ++ctr; } contextMenu.exec(e->globalPos()); } void FileView::keyPressEvent(QKeyEvent *e){ switch(e->key()){ case Qt::Key_Backspace: emit upDir(); e->accept(); break; default: QTreeView::keyPressEvent(e); } } void FileView::resizeEvent(QResizeEvent *e){ if(e->size().width() != e->oldSize().width()){ int width = e->size().width(); int c1width = width / 2; // * 2; setColumnWidth(0, c1width); } }