summaryrefslogtreecommitdiffstats
path: root/yakuake/src/skin_list_item.cpp
blob: 7fadf5fc03cfa7bf674bc48d9c8e01aac6605830 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
*/

/*
  Copyright (C) 2007 Eike Hein <hein@kde.org>
*/


#include "skin_list_item.h"

#include <tqsimplerichtext.h>
#include <tqrect.h>
#include <tqpainter.h>
#include <tqpixmap.h>
#include <palette.h>

#include <kglobalsettings.h>
#include <klocale.h>


SkinListItem::SkinListItem(KListView* parent, const TQString& fancy_name,
    const TQString& author, const TQPixmap& icon, const TQString& name, const TQString& dir)
    : KListViewItem(parent, fancy_name)
{
    setName(name);
    setAuthor(author);
    setDir(dir);

    TQString fancy_author = i18n("by %1").arg(author);
    TQString text = TQString("<qt><b>%1</b><br>%2</qt>").arg(fancy_name).arg(fancy_author);

    item_text = new TQSimpleRichText(text, listView()->font());
    item_text->adjustSize();

    setPixmap(0, icon);

}

SkinListItem::~SkinListItem()
{
}

void SkinListItem::setName(const TQString& name)
{
    skin_name = name;
}

TQString SkinListItem::name()
{
    return skin_name;
}

void SkinListItem::setAuthor(const TQString& author)
{
    skin_author = author;
}

TQString SkinListItem::author()
{
    return skin_author;
}

void SkinListItem::setDir(const TQString& dir)
{
    skin_dir = dir;
}

TQString SkinListItem::dir()
{
    return skin_dir;
}

void SkinListItem::setup()
{
    widthChanged();

    item_text->setDefaultFont(listView()->font());
    item_text->setWidth(listView()->columnWidth(0));
    int text_height = item_text->height()+(MARGIN*2);

    if (text_height < 32)
        setHeight(32+(MARGIN*2));
    else
        setHeight(text_height);
}

void SkinListItem::paintCell(TQPainter* p, const TQColorGroup& /* cg */, int /* column */, int width, int /* align */)
{
    if (width <= 0) return;

    TQColor textColor = isSelected() ? KGlobalSettings::highlightedTextColor() : KGlobalSettings::textColor();
    TQColor background = isSelected() ? KGlobalSettings::highlightColor() : listView()->paletteBackgroundColor();

    TQColorGroup colors;
    colors.setColor(TQColorGroup::Foreground, textColor);
    colors.setColor(TQColorGroup::Text, textColor);
    colors.setColor(TQColorGroup::Background, background);
    colors.setColor(TQColorGroup::Base, background);

    p->fillRect(0, 0, width, height(), background);


    if (pixmap(0))
    {
        int y = (height() - 32) / 2;
        p->drawPixmap(MARGIN, y, *pixmap(0));
    }

    item_text->setWidth(width);
    item_text->draw(p, MARGIN+32+MARGIN+MARGIN, MARGIN, TQRect(0, 0, width-MARGIN-32-MARGIN, height()), colors);
}