diff options
Diffstat (limited to 'src-qt5/desktop-utils/lumina-fm/widgets')
-rw-r--r-- | src-qt5/desktop-utils/lumina-fm/widgets/DDListWidgets.h | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/src-qt5/desktop-utils/lumina-fm/widgets/DDListWidgets.h b/src-qt5/desktop-utils/lumina-fm/widgets/DDListWidgets.h index e7dfb4d1..8049600e 100644 --- a/src-qt5/desktop-utils/lumina-fm/widgets/DDListWidgets.h +++ b/src-qt5/desktop-utils/lumina-fm/widgets/DDListWidgets.h @@ -44,14 +44,20 @@ public: this->setFlow(QListView::TopToBottom); this->setWrapping(true); this->setMouseTracking(true); - //this->setSortingEnabled(true); //This sorts *only* by name - type is not preserved + this->setSortingEnabled(true); //This sorts *only* by name - type is not preserved } ~DDListWidget(){} signals: void DataDropped(QString, QStringList); //Dir path, List of commands - + void GotFocus(); + protected: + void focusInEvent(QFocusEvent *ev){ + QListWidget::focusInEvent(ev); + emit GotFocus(); + } + void startDrag(Qt::DropActions act){ QList<QListWidgetItem*> items = this->selectedItems(); if(items.length()<1){ return; } @@ -157,8 +163,13 @@ public: signals: void DataDropped(QString, QStringList); //Dir path, List of commands - + void GotFocus(); + protected: + void focusInEvent(QFocusEvent *ev){ + QTreeWidget::focusInEvent(ev); + emit GotFocus(); + } void startDrag(Qt::DropActions act){ QList<QTreeWidgetItem*> items = this->selectedItems(); if(items.length()<1){ return; } @@ -261,10 +272,10 @@ public: inline virtual bool operator<(const QTreeWidgetItem &tmp) const { int column = this->treeWidget()->sortColumn(); // We are in date text - if(column == 3 || column == 4) + if(column == 3 || column == 4){ return this->whatsThis(column) < tmp.whatsThis(column); // We are in size text - else if(column == 1) { + }else if(column == 1) { QString text = this->text(column); QString text_tmp = tmp.text(column); double filesize, filesize_tmp; @@ -280,9 +291,29 @@ public: else filesize_tmp = LUtils::DisplaySizeToBytes(text_tmp); return filesize < filesize_tmp; + + //Name column - still sort by type too (folders first) + }else if(column == 0 && (this->text(2).isEmpty() || tmp.text(2).isEmpty()) ){ + if(this->text(2) != tmp.text(2)){ return this->text(2).isEmpty(); } } // In other cases, we trust base class implementation return QTreeWidgetItem::operator<(tmp); } }; + +//Item override for sorting purposes of list widget items +class CQListWidgetItem : public QListWidgetItem { +public: + CQListWidgetItem(const QIcon &icon, const QString &text, QListWidget *parent = Q_NULLPTR) : QListWidgetItem(icon,text,parent) {} + virtual ~CQListWidgetItem() {} + inline virtual bool operator<(const QListWidgetItem &tmp) const { + QString type = this->data(Qt::UserRole).toString(); + QString tmptype = tmp.data(Qt::UserRole).toString(); + //Sort by type first + if(type!=tmptype){ return (QString::compare(type,tmptype)<0); } + //Then sort by name using the normal rules + return QListWidgetItem::operator<(tmp); + } +}; + #endif |