aboutsummaryrefslogtreecommitdiff
path: root/lumina-desktop/panel-plugins/userbutton
diff options
context:
space:
mode:
Diffstat (limited to 'lumina-desktop/panel-plugins/userbutton')
-rw-r--r--lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp19
-rw-r--r--lumina-desktop/panel-plugins/userbutton/UserWidget.cpp78
-rw-r--r--lumina-desktop/panel-plugins/userbutton/UserWidget.h1
3 files changed, 72 insertions, 26 deletions
diff --git a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp
index 689bd8eb..ff77121e 100644
--- a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp
+++ b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp
@@ -7,6 +7,7 @@
#include "UserItemWidget.h"
#include <LuminaUtils.h>
+#define TEXTCUTOFF 165
UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, QString type, bool goback) : QFrame(parent){
createWidget();
//Now fill it appropriately
@@ -17,10 +18,10 @@ UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, QString type,
XDGDesktop item = LXDG::loadDesktopFile(itemPath, ok);
if(ok){
icon->setPixmap( LXDG::findIcon(item.icon, "preferences-system-windows-actions").pixmap(32,32) );
- name->setText( this->fontMetrics().elidedText(item.name, Qt::ElideRight, 180) );
+ name->setText( this->fontMetrics().elidedText(item.name, Qt::ElideRight, TEXTCUTOFF) );
}else{
icon->setPixmap( LXDG::findIcon("unknown","").pixmap(32,32) );
- name->setText( this->fontMetrics().elidedText(itemPath.section("/",-1), Qt::ElideRight, 180) );
+ name->setText( this->fontMetrics().elidedText(itemPath.section("/",-1), Qt::ElideRight, TEXTCUTOFF) );
}
}else if(type=="dir"){
if(itemPath.endsWith("/")){ itemPath.chop(1); }
@@ -29,18 +30,22 @@ UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, QString type,
name->setText( tr("Go Back") );
}else{
icon->setPixmap( LXDG::findIcon("folder","").pixmap(32,32) );
- name->setText( this->fontMetrics().elidedText(itemPath.section("/",-1), Qt::ElideRight, 180) );
+ name->setText( this->fontMetrics().elidedText(itemPath.section("/",-1), Qt::ElideRight, TEXTCUTOFF) );
}
}else{
if(itemPath.endsWith("/")){ itemPath.chop(1); }
- if(LUtils::imageExtensions().contains(itemPath.section("/",-1).section(".",-1).toLower()) ){
+ if(QFileInfo(itemPath).isDir()){
+ type = "dir";
+ icon->setPixmap( LXDG::findIcon("folder","").pixmap(32,32) );
+ }else if(LUtils::imageExtensions().contains(itemPath.section("/",-1).section(".",-1).toLower()) ){
icon->setPixmap( QIcon(itemPath).pixmap(32,32) );
}else{
icon->setPixmap( LXDG::findMimeIcon(type).pixmap(32,32) );
}
- name->setText( this->fontMetrics().elidedText(itemPath.section("/",-1), Qt::ElideRight, 180) );
+ name->setText( this->fontMetrics().elidedText(itemPath.section("/",-1), Qt::ElideRight, TEXTCUTOFF) );
}
icon->setWhatsThis(itemPath);
+ if(!goback){ this->setWhatsThis(name->text()); }
isDirectory = (type=="dir"); //save this for later
if(LUtils::isFavorite(itemPath)){
linkPath = itemPath;
@@ -67,7 +72,8 @@ UserItemWidget::UserItemWidget(QWidget *parent, XDGDesktop item) : QFrame(parent
}
//Now fill it appropriately
icon->setPixmap( LXDG::findIcon(item.icon,"preferences-system-windows-actions").pixmap(32,32) );
- name->setText( this->fontMetrics().elidedText(item.name, Qt::ElideRight, 180) );
+ name->setText( this->fontMetrics().elidedText(item.name, Qt::ElideRight, TEXTCUTOFF) );
+ this->setWhatsThis(name->text());
icon->setWhatsThis(item.filePath);
//Now setup the button appropriately
setupButton();
@@ -154,5 +160,4 @@ void UserItemWidget::buttonClicked(){
void UserItemWidget::ItemClicked(){
if(!linkPath.isEmpty()){ emit RunItem(linkPath); }
else{ emit RunItem(icon->whatsThis()); }
-
}
diff --git a/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp b/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp
index 2c85caab..a16e9378 100644
--- a/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp
+++ b/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp
@@ -108,9 +108,37 @@ void UserWidget::ClearScrollArea(QScrollArea *area){
layout->setSpacing(2);
layout->setContentsMargins(3,1,3,1);
layout->setDirection(QBoxLayout::TopToBottom);
+ layout->setAlignment(Qt::AlignTop);
area->widget()->setLayout(layout);
}
+void UserWidget::SortScrollArea(QScrollArea *area){
+ //qDebug() << "Sorting Scroll Area:";
+ //Sort all the items in the scroll area alphabetically
+ QLayout *lay = area->widget()->layout();
+ QStringList items;
+ for(int i=0; i<lay->count(); i++){
+ items << lay->itemAt(i)->widget()->whatsThis();
+ }
+
+ items.sort();
+ //qDebug() << " - Sorted Items:" << items;
+ for(int i=0; i<items.length(); i++){
+ if(items[i].isEmpty()){ continue; }
+ //QLayouts are weird in that they can only add items to the end - need to re-insert almost every item
+ for(int j=0; j<lay->count(); j++){
+ //Find this item
+ if(lay->itemAt(j)->widget()->whatsThis()==items[i]){
+ //Found it - now move it if necessary
+ //qDebug() << "Found Item:" << items[i] << i << j;
+ lay->addItem( lay->takeAt(j) );
+ break;
+ }
+ }
+ }
+
+}
+
QIcon UserWidget::rotateIcon(QIcon ico){
//Rotate the given icon to appear vertical in the tab widget
QPixmap pix = ico.pixmap(32,32);
@@ -131,11 +159,18 @@ void UserWidget::UpdateMenu(){
ui->tool_fav_files->setChecked(false);
cfav = 0; //favorite apps
updateFavItems();
- ui->label_home_dir->setWhatsThis(QDir::homePath());
- updateHome();
+ QString cdir = ui->label_home_dir->whatsThis();
+ if(cdir.isEmpty() || !QFile::exists(cdir) ){
+ //Directory deleted or nothing loaded yet
+ ui->label_home_dir->setWhatsThis(QDir::homePath());
+ QTimer::singleShot(0,this, SLOT(updateHome()) );
+ }else if( lastUpdate < QFileInfo(cdir).lastModified() ){
+ //Directory contents changed - reload it
+ QTimer::singleShot(0,this, SLOT(updateHome()) );
+ }
if(lastUpdate < LSession::handle()->applicationMenu()->lastHashUpdate || lastUpdate.isNull()){
updateAppCategories();
- updateApps();
+ QTimer::singleShot(0,this, SLOT(updateApps()) );
}
lastUpdate = QDateTime::currentDateTime();
}
@@ -214,16 +249,17 @@ void UserWidget::updateFavItems(bool newfilter){
}
ClearScrollArea(ui->scroll_fav);
//qDebug() << " - Sorting Items";
- favitems.sort(); //sort them alphabetically
- //qDebug() << " - Creating Items:" << favitems;
- for(int i=0; i<favitems.length(); i++){
- UserItemWidget *it = new UserItemWidget(ui->scroll_fav->widget(), favitems[i].section("::::",2,50), favitems[i].section("::::",1,1) );
- ui->scroll_fav->widget()->layout()->addWidget(it);
- connect(it, SIGNAL(RunItem(QString)), this, SLOT(LaunchItem(QString)) );
- connect(it, SIGNAL(NewShortcut()), this, SLOT(updateFavItems()) );
- connect(it, SIGNAL(RemovedShortcut()), this, SLOT(updateFavItems()) );
- }
- static_cast<QBoxLayout*>(ui->scroll_fav->widget()->layout())->addStretch();
+ favitems.sort(); //sort them alphabetically
+ //qDebug() << " - Creating Items:" << favitems;
+ for(int i=0; i<favitems.length(); i++){
+ UserItemWidget *it = new UserItemWidget(ui->scroll_fav->widget(), favitems[i].section("::::",2,50), favitems[i].section("::::",1,1) );
+ ui->scroll_fav->widget()->layout()->addWidget(it);
+ connect(it, SIGNAL(RunItem(QString)), this, SLOT(LaunchItem(QString)) );
+ connect(it, SIGNAL(NewShortcut()), this, SLOT(updateFavItems()) );
+ connect(it, SIGNAL(RemovedShortcut()), this, SLOT(updateFavItems()) );
+ QApplication::processEvents(); //keep the UI snappy - might be a number of these
+ }
+ SortScrollArea(ui->scroll_fav);
//qDebug() << " - Done";
}
@@ -263,8 +299,8 @@ void UserWidget::updateApps(){
connect(it, SIGNAL(RunItem(QString)), this, SLOT(LaunchItem(QString)) );
connect(it, SIGNAL(NewShortcut()), this, SLOT(updateFavItems()) );
connect(it, SIGNAL(RemovedShortcut()), this, SLOT(updateFavItems()) );
+ QApplication::processEvents(); //keep the UI snappy - might be a number of these
}
- static_cast<QBoxLayout*>(ui->scroll_apps->widget()->layout())->addStretch();
}
//Home Tab
@@ -285,25 +321,29 @@ void UserWidget::updateHome(){
items << dir;
}
ui->label_home_dir->setToolTip(ui->label_home_dir->whatsThis());
- items << homedir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
+ items << homedir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, QDir::Name | QDir::DirsFirst);
QString type = "dir";
if(homedir.absolutePath() == QDir::homePath()+"/Desktop"){ type.append("-home"); }//internal code
for(int i=0; i<items.length(); i++){
//qDebug() << "New Home subdir:" << homedir.absoluteFilePath(items[i]);
UserItemWidget *it;
if(items[i].startsWith("/")){ it = new UserItemWidget(ui->scroll_home->widget(), items[i], type, true); }
- else{ it = new UserItemWidget(ui->scroll_home->widget(), homedir.absoluteFilePath(items[i]), type, false); }
+ else{ it = new UserItemWidget(ui->scroll_home->widget(), homedir.absoluteFilePath(items[i]), "", false); }
ui->scroll_home->widget()->layout()->addWidget(it);
connect(it, SIGNAL(RunItem(QString)), this, SLOT(slotGoToDir(QString)) );
connect(it, SIGNAL(NewShortcut()), this, SLOT(updateFavItems()) );
connect(it, SIGNAL(RemovedShortcut()), this, SLOT(updateFavItems()) );
+ QApplication::processEvents(); //keep the UI snappy - may be a lot of these to load
}
- static_cast<QBoxLayout*>(ui->scroll_home->widget()->layout())->addStretch();
}
void UserWidget::slotGoToDir(QString dir){
- ui->label_home_dir->setWhatsThis(dir);
- updateHome();
+ if(!QFileInfo(dir).isDir()){
+ LaunchItem(dir);
+ }else{
+ ui->label_home_dir->setWhatsThis(dir);
+ updateHome();
+ }
}
void UserWidget::slotGoHome(){
diff --git a/lumina-desktop/panel-plugins/userbutton/UserWidget.h b/lumina-desktop/panel-plugins/userbutton/UserWidget.h
index 2dce25b4..c2df10bf 100644
--- a/lumina-desktop/panel-plugins/userbutton/UserWidget.h
+++ b/lumina-desktop/panel-plugins/userbutton/UserWidget.h
@@ -47,6 +47,7 @@ private:
QFileInfoList homefiles;
int cfav; //current favorite category
void ClearScrollArea(QScrollArea *area);
+ void SortScrollArea(QScrollArea *area);
QIcon rotateIcon(QIcon);
private slots:
bgstack15