diff options
Diffstat (limited to 'src-qt5/desktop-utils/lumina-fm')
-rw-r--r-- | src-qt5/desktop-utils/lumina-fm/BrowserModel.cpp | 208 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-fm/BrowserModel.h | 85 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-fm/widgets/DDListWidgets.h | 34 |
3 files changed, 310 insertions, 17 deletions
diff --git a/src-qt5/desktop-utils/lumina-fm/BrowserModel.cpp b/src-qt5/desktop-utils/lumina-fm/BrowserModel.cpp new file mode 100644 index 00000000..d79da006 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-fm/BrowserModel.cpp @@ -0,0 +1,208 @@ +//=========================================== +// Lumina Desktop source code +// Copyright (c) 2017, Ken Moore & JT Pennington +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "BrowserModel.h" + +BrowserModel::BrowserModel(QObject *parent){ + +} + +BrowserModel::~BrowserModel(){ + +} + +//Virtual overrides +QModelIndex BrowserModel::index(int row, int column, const QModelIndex &parent) const{ + +} + +QModelIndex BrowserModel::parent(const QModelIndex &index) const{ + +} + +// item management +int BrowserModel::rowCount(const QModelIndex &parent) const{ + +} + +bool BrowserModel::insertRows(int row, int count, const QModelIndex &parent){ + +} + +bool BrowserModel::removeRow(int row, const QModelIndex &parent){ + +} + +bool BrowserModel::removeRows(int row, int count, const QModelIndex &parent){ + +} + +int BrowserModel::columnCount(const QModelIndex &parent) const{ + +} + +bool BrowserModel::insertColumns(int column, int count, const QModelIndex &parent){ + +} + +bool BrowserModel::removeColumn(int column, const QModelIndex &parent){ + +} + +bool BrowserModel::removeColumns(int column, int count, const QModelIndex &parent){ + +} + + +//bool BrowserModel::hasChildren(const QModelIndex &parent) const{ + +} + + +// data functions +Qt::ItemFlags BrowserModel::flags(const QModelIndex &index) const{ + +} + +QVariant BrowserModel::data(const QModelIndex &index, int role) const{ + QFileInfo *info = indexToInfo(index); + switch(role){ + case Qt::DisplayRole: + if(index.column()==0){ return QVariant(info->fileName()); } + else if(index.column()==1){ return QVariant(info->fileSize()); } + else if(index.column()==2){ return QVariant(info->mimetype()); } + else if(index.column()==3){ return QVariant(info->lastModified()->toString(Qt::DefaultLocaleShortDate)); } + else if(index.column()==4){ return QVariant(info->created()->toString(Qt::DefaultLocaleShortDate)); } + case Qt::ToolTipRole: + return QVariant(info->absoluteFilePath()); + case Qt::StatusTipRole: + return QVariant(info->absoluteFilePath()); + case Qt::SizeHintRole; + return QVariant(QSize(100,14)); + case Qt::DecorationRole: + return QVariant(LXDG::findIcon(info->iconFile(), "unknown")); + } + return QVariant(); +} + +QVariant BrowserModel::headerData(int section, Qt::Orientation orientation, int role) const{ + if(role == Qt::DisplayRole){ + if(orientation == Qt::Horizontal){ + switch(section){ + case 0: + return QVariant(tr("File Name")); + case 1: + return QVariant("Size"); + case 2: + return QVariant("Type"); + case 3: + return QVariant("Date Modified"); + case 4: + return QVariant("Date Created"); + } + } + } + case Qt::DisplayRole: + return QVariant(tr("File Name"); + /*case Qt::ToolTipRole: + return QVariant("ToolTip"); + case Qt::StatusTipRole: + return QVariant("Status Tip"); + case Qt::SizeHintRole; + return QVariant(QSize(100,14));*/ + case Qt::DecorationRole: + return QVariant("Icon")); + } + return QVariant(); +} + +// data modification functions +bool BrowserModel::setData(const QModelIndex &index, const QVariant &value, int role){ + +} + +bool BrowserModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role){ + +} + + +// drag and drop +//QMimeData* BrowserModel::mimeData(const QModelIndexList &indexes) const{ + +} + +//QStringList BrowserModel::mimeTypes() const{ + +} + +//bool BrowserModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles){ + +} + +//Qt::DropActions BrowserModel::supportedDropActions() const{ + +} + +//bool BrowserModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent){ + +} + +//Special Functions (non virtual replacements) +LFileInfo* BrowserModel::fileInfo(QString name){ + +} + +QString BrowserModel::currentDirectory(){ + return cDir; +} + + +// ============== +// PUBLIC SLOTS +// ============== +void BrowserModel::loadDirectory(QString dir){ + + +} + +void BrowserModel::loadItem(QString itempath){ + LFileInfo *it = new LFileInfo(itempath); + //Determine the row/column that it needs to be + int row, column; + row = 0; + //Now create the index + for(int i=0; i<5; i++){ + QModelIndex index = createIndex(row, i, it); + } +} + + +// ============= +// PRIVATE +// ============= +/*QString BrowserModel::findInHash(QString path){ + QStringList keys = HASH.keys(); + for(int i=0; i<keys.length(); i++){ + if(HASH[keys[i]]->filePath() == path){ return keys[i]; } + } + return ""; +} + +QString BrowserModel::findInHash(QModelIndex index){ + QString id = QString::number(index.row())+"/"+QString::number(index.column()); + if(HASH.contains(id)){ return id; } + return ""; +} + +LFileInfo* BrowserModel::indexToInfo(QString path){ + QString id = findInHash(path); + if(id.isEmpty()){ return 0;} + return HASH[id]; +}*/ + +LFileInfo* BrowserModel::indexToInfo(QModelIndex index){ + return static_cast<LFileInfo*>(index.internalPointer()); +} diff --git a/src-qt5/desktop-utils/lumina-fm/BrowserModel.h b/src-qt5/desktop-utils/lumina-fm/BrowserModel.h new file mode 100644 index 00000000..0968b4d4 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-fm/BrowserModel.h @@ -0,0 +1,85 @@ +//=========================================== +// Lumina Desktop source code +// Copyright (c) 2017, Ken Moore & JT Pennington +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This is the main browsing backend for the file manager +//=========================================== +#ifndef _LUMINA_FM_BROWSER_MODEL_BACKEND_H +#define _LUMINA_FM_BROWSER_MODEL_BACKEND_H + +#include <QAbstractItemModel> +#include <QModelIndex> +#include <QMimeData> +#include <QMap> +#include <QVariant> +#include <QHash> + +#include <LuminaXDG.h> + +class BrowserModel : public QAbstractItemModel { + Q_OBJECT +public: + BrowserModel(QObject *parent = 0); + ~BrowserModel(); + + //Virtual overrides + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &index) const; + + // item management + int rowCount(const QModelIndex &parent = QModelIndex()) const; + bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()); + bool removeRow(int row, const QModelIndex &parent = QModelIndex()); + bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); + + int columnCount(const QModelIndex &parent = QModelIndex()) const; + bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()); + bool removeColumn(int column, const QModelIndex &parent = QModelIndex()); + bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()); + + //bool hasChildren(const QModelIndex &parent = QModelIndex()) const; + + // data functions + Qt::ItemFlags flags(const QModelIndex &index) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + // data modification functions + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); + bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole); + + // drag and drop + //QMimeData* mimeData(const QModelIndexList &indexes) const; + //QStringList mimeTypes() const; + //bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles); + //Qt::DropActions supportedDropActions() const; + //bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); + + //Special Functions (non virtual replacements) + LFileInfo* fileInfo(QString name); + QString currentDirectory(); + +public slots: + void loadDirectory(QString dir=""); + void loadItem(QString item); + +private: + QHash<quintptr, QModelIndex> HASH; //QString: "row/column" + QString cDir; + //simplification functions + /*QString findInHash(QString path); + QString findInHash(QModelIndex index); + LFileInfo* indexToInfo(QString path);*/ + LFileInfo* indexToInfo(QModelIndex index); + +private slots: + +protected: + +signals: + +}; + +#endif + diff --git a/src-qt5/desktop-utils/lumina-fm/widgets/DDListWidgets.h b/src-qt5/desktop-utils/lumina-fm/widgets/DDListWidgets.h index 254362fd..da4131e0 100644 --- a/src-qt5/desktop-utils/lumina-fm/widgets/DDListWidgets.h +++ b/src-qt5/desktop-utils/lumina-fm/widgets/DDListWidgets.h @@ -63,8 +63,8 @@ protected: QList<QListWidgetItem*> items = this->selectedItems(); if(items.length()<1){ return; } QList<QUrl> urilist; - for(int i=0; i<items.length(); i++){ - urilist << QUrl::fromLocalFile(items[i]->whatsThis()); + for(int i=0; i<items.length(); i++){ + urilist << QUrl::fromLocalFile(items[i]->whatsThis()); } //Create the mime data //qDebug() << "Start Drag:" << urilist; @@ -88,7 +88,7 @@ protected: ev->ignore(); } } - + void dragMoveEvent(QDragMoveEvent *ev){ if(ev->mimeData()->hasUrls() && !this->whatsThis().isEmpty() ){ //Change the drop type depending on the data/dir @@ -104,7 +104,7 @@ protected: } this->update(); } - + void dropEvent(QDropEvent *ev){ if(this->whatsThis().isEmpty() || !ev->mimeData()->hasUrls() ){ ev->ignore(); return; } //not supported //qDebug() << "Drop Event:"; @@ -125,7 +125,7 @@ protected: foreach(const QUrl &url, ev->mimeData()->urls()){ const QString filepath = url.toLocalFile(); //If the target file is modifiable, assume a move - otherwise copy - if(QFileInfo(filepath).isWritable() && (filepath.startsWith(home) && dirpath.startsWith(home))){ + if(QFileInfo(filepath).isWritable() && (filepath.startsWith(home) && dirpath.startsWith(home))){ if(filepath.section("/",0,-2)!=dirpath){ files << "cut::::"+filepath; } //don't "cut" a file into the same dir }else{ files << "copy::::"+filepath; } } @@ -133,18 +133,18 @@ protected: if(!files.isEmpty()){ emit DataDropped( dirpath, files ); } this->setCursor(Qt::ArrowCursor); } - + void mouseReleaseEvent(QMouseEvent *ev){ if(ev->button() != Qt::RightButton && ev->button() != Qt::LeftButton){ ev->ignore(); } else{ QListWidget::mouseReleaseEvent(ev); } //pass it along to the widget } void mousePressEvent(QMouseEvent *ev){ if(ev->button() != Qt::RightButton && ev->button() != Qt::LeftButton){ ev->ignore(); } - else{ QListWidget::mousePressEvent(ev); } //pass it along to the widget + else{ QListWidget::mousePressEvent(ev); } //pass it along to the widget } /*void mouseMoveEvent(QMouseEvent *ev){ if(ev->button() != Qt::RightButton && ev->button() != Qt::LeftButton){ ev->ignore(); } - else{ QListWidget::mouseMoveEvent(ev); } //pass it along to the widget + else{ QListWidget::mouseMoveEvent(ev); } //pass it along to the widget }*/ }; @@ -183,8 +183,8 @@ protected: QList<QTreeWidgetItem*> items = this->selectedItems(); if(items.length()<1){ return; } QList<QUrl> urilist; - for(int i=0; i<items.length(); i++){ - urilist << QUrl::fromLocalFile(items[i]->whatsThis(0)); + for(int i=0; i<items.length(); i++){ + urilist << QUrl::fromLocalFile(items[i]->whatsThis(0)); } //Create the mime data QMimeData *mime = new QMimeData; @@ -205,9 +205,9 @@ protected: ev->acceptProposedAction(); //allow this to be dropped here }else{ ev->ignore(); - } + } } - + void dragMoveEvent(QDragMoveEvent *ev){ if(ev->mimeData()->hasUrls() && !this->whatsThis().isEmpty() ){ //Change the drop type depending on the data/dir @@ -219,7 +219,7 @@ protected: ev->ignore(); } } - + void dropEvent(QDropEvent *ev){ if(this->whatsThis().isEmpty() || !ev->mimeData()->hasUrls() ){ ev->ignore(); return; } //not supported ev->accept(); //handled here @@ -239,25 +239,25 @@ protected: foreach(const QUrl &url, ev->mimeData()->urls()){ const QString filepath = url.toLocalFile(); //If the target file is modifiable, assume a move - otherwise copy - if(QFileInfo(filepath).isWritable() && (filepath.startsWith(home) && dirpath.startsWith(home))){ + if(QFileInfo(filepath).isWritable() && (filepath.startsWith(home) && dirpath.startsWith(home))){ if(filepath.section("/",0,-2)!=dirpath){ files << "cut::::"+filepath; } //don't "cut" a file into the same dir }else{ files << "copy::::"+filepath; } } //qDebug() << "Drop Event:" << dirpath; emit DataDropped( dirpath, files ); } - + void mouseReleaseEvent(QMouseEvent *ev){ if(ev->button() != Qt::RightButton && ev->button() != Qt::LeftButton){ ev->ignore(); } else{ QTreeWidget::mouseReleaseEvent(ev); } //pass it along to the widget } void mousePressEvent(QMouseEvent *ev){ if(ev->button() != Qt::RightButton && ev->button() != Qt::LeftButton){ ev->ignore(); } - else{ QTreeWidget::mousePressEvent(ev); } //pass it along to the widget + else{ QTreeWidget::mousePressEvent(ev); } //pass it along to the widget } /*void mouseMoveEvent(QMouseEvent *ev){ if(ev->button() != Qt::RightButton && ev->button() != Qt::LeftButton){ ev->ignore(); } - else{ QTreeWidget::mouseMoveEvent(ev); } //pass it along to the widget + else{ QTreeWidget::mouseMoveEvent(ev); } //pass it along to the widget }*/ }; |