aboutsummaryrefslogtreecommitdiff
path: root/lumina-desktop/desktop-plugins/desktopview/DeskItem.cpp
blob: 21b1d1f6a3b2c352531e7dfc1370bcfbda10a03d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//===========================================
//  Lumina-DE source code
//  Copyright (c) 2014, Ken Moore
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================
#include "DeskItem.h"

DeskItem::DeskItem(QWidget *parent, QString itempath, int ssize) : QToolButton(parent){
  this->setFixedSize(ssize, ssize);
  this->setWhatsThis(itempath);
  this->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
  this->setAutoRaise(true);
  int txtheight = this->fontMetrics().height() *2;
  this->setIconSize( QSize(ssize-txtheight, ssize-txtheight));
  connect(this, SIGNAL(clicked()), this, SLOT(RunItem()) );
  updateItem();
}

DeskItem::~DeskItem(){
	
}

void DeskItem::updateItem(){
  QFileInfo info(this->whatsThis());
  QIcon ico;
  QString txt;
  if(info.isDir()){
    ico = LXDG::findIcon("folder","");
    txt = info.fileName();
  }else if(info.suffix()=="desktop"){
    bool ok = false;
    XDGDesktop dsk = LXDG::loadDesktopFile(this->whatsThis(), ok);
    if(ok){
      ico = LXDG::findIcon( dsk.icon );
      txt = dsk.name;
    }else{
      ico = LXDG::findIcon("","");
      txt = info.fileName();
    }
  }else{
    ico = LXDG::findIcon("application-x-zerosize","");
    txt = info.fileName();
  }
  this->setIcon(ico);
  //Trim the text size to fit
  txt = this->fontMetrics().elidedText(txt, Qt::ElideRight ,this->width() - 4);
  this->setText(txt);
	
}
bgstack15