summaryrefslogtreecommitdiffstats
path: root/ksquirrel/sq_iconlistbox.cpp
blob: e0ceb3e6a8d270715f9b238c51cfa4bc21c1cd19 (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
/***************************************************************************
                          sq_iconlistbox.cpp  -  description
                             -------------------
    begin                : ??? ??? 19 2004
    copyright            : (C) 2004 by Baryshev Dmitry
    email                : ksquirrel.iv@gmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "sq_iconlistbox.h"
#include "sq_iconlistitem.h"

SQ_IconListBox::SQ_IconListBox(TQWidget *tqparent, const char *name, WFlags f) : KListBox(tqparent, name, f),
    mHeightValid(false), mWidthValid(false)
{
    setHScrollBarMode(TQScrollView::AlwaysOff);
}

void SQ_IconListBox::updateWidth()
{
    if(!mWidthValid)
    {
        int maxWidth = 10, w;

        for(TQListBoxItem *i = item(0); i != 0; i = i->next())
        {
            w = ((SQ_IconListItem *)i)->width(this);
            maxWidth = TQMAX(w, maxWidth);
        }

        for(TQListBoxItem *i = item(0); i != 0; i = i->next())
            ((SQ_IconListItem *)i)->expandMinimumWidth(maxWidth + 30);

        if(verticalScrollBar()->isVisible())
            maxWidth += verticalScrollBar()->tqsizeHint().width();

        setFixedWidth(maxWidth + frameWidth()*2 + 30);
        mWidthValid = true;
    }
}

void SQ_IconListBox::invalidateHeight()
{
    mHeightValid = false;
}

void SQ_IconListBox::invalidateWidth()
{
    mWidthValid = false;
}

void SQ_IconListBox::updateAndInstall(TQObject *o)
{
    invalidateHeight();
    invalidateWidth();
    updateWidth();

    TQFont listFont(font());

    listFont.setBold(true);
    setFont(listFont);
    verticalScrollBar()->installEventFilter(o);
    setCurrentItem(0);
    setSelected(0, true);
}