summaryrefslogtreecommitdiffstats
path: root/sidebar/listboxlink.cpp
blob: 47adb8814dde8e085450410e42eb3813072e7fb1 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

#include <kiconloader.h>
#include "listboxlink.h"
#include <qpainter.h>
#include <qbitmap.h>
#include "eject.xbm"
#include "lock.xbm"

static QBitmap eject = QBitmap( eject_width, eject_height, eject_bits, true );
static QBitmap locked = QBitmap( lock_width, lock_height, lock_bits, true );

ListBoxLink::ListBoxLink( const QString & icon, uint size, const QString & title, const QString & url): QListBoxPixmap(KGlobal::iconLoader()->loadIcon(icon, KIcon::Desktop, size), title),url_(url),icon_(icon)
{
}

ListBoxLink::ListBoxLink( const QPixmap & pixmap, const QString & title, const QString & url) : QListBoxPixmap(pixmap, title), url_(url), icon_(0)
{
}

ListBoxLink::ListBoxLink(ListBoxLink & link) : QListBoxPixmap(*link.pixmap(), link.text()), url_(link.URL()), icon_(link.icon())
{
}

ListBoxLink::~ListBoxLink()
{
}

void ListBoxLink::setURL(const QString & url)
{
   url_ = url;
}

void ListBoxLink::setIcon(const QString & icon)
{
   icon_ = icon;
}

int ListBoxLink::height ( const QListBox * lb ) const
{
   return (QListBoxPixmap::height ( lb ) + 4);
}

ListBoxDevice::ListBoxDevice(const QString & icon, uint size, const QString & title, const QString & url, const QString & name, const QString & mountPoint, bool mounted, bool ejectable, bool removable, int id) : ListBoxLink(icon, size, title, url), name_(name), mountPoint_(mountPoint), mounted_(mounted), ejectable_(ejectable), removable_(removable),id_(id)
{
   if (!eject.mask())
      eject.setMask(eject);
   if (!locked.mask())
      locked.setMask(locked);
}

ListBoxDevice::ListBoxDevice(const QPixmap & pixmap, const QString & title, const QString & url, const QString & name, const QString & mountPoint, bool mounted, bool ejectable, bool removable, int id) : ListBoxLink(pixmap, title, url), name_(name), mountPoint_(mountPoint), mounted_(mounted), ejectable_(ejectable), removable_(removable),id_(id)
{
   if (!eject.mask())
      eject.setMask(eject);
   if (!locked.mask())
      locked.setMask(locked);
}

int ListBoxDevice::width ( const QListBox * lb ) const
{
   if (ejectable_ && mounted_ && lb)
      return lb->width();
   return ListBoxLink::width(lb);
}

void ListBoxDevice::paint( QPainter * p )
{
   if ((ejectable_ || removable_) && mounted_)
   {
      p->save();
      ListBoxLink::paint(p);
      p->setBrush(isSelected()?listBox()->colorGroup().highlightedText():listBox()->colorGroup().text());
      p->drawPixmap(listBox()->width()-22, 11, ejectable_?eject:locked);
      p->restore();
   }
   else
      ListBoxLink::paint(p);
}