summaryrefslogtreecommitdiffstats
path: root/src/combobutton.cpp
blob: 64a84d7f4cf4fd7ccda3155f8eca49220fa52db8 (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

#include "combobutton.h"

#include <tqlayout.h>
#include <tqstring.h>
#include <tqpixmap.h>
#include <tqstyle.h>
#include <kpushbutton.h>
#include <kcombobox.h>

ComboButton::ComboButton( TQWidget *tqparent, const char *name )
    : TQWidget( tqparent, name )
{
    m_increaseHeight = 0;

    TQGridLayout *grid = new TQGridLayout( this, 1, 1 );

    m_box = new KComboBox(this);
    grid->addWidget(m_box,0,0);

    connect( m_box, TQT_SIGNAL(activated(int)),
             this, TQT_SLOT(boxActivated(int))
           );

    m_button = new KPushButton( TQString(), this, "pushbutton" );
    grid->addWidget( m_button, 0, 0 );

    connect( m_button, TQT_SIGNAL(clicked()),
             this, TQT_SLOT(buttonClicked())
           );

    m_sizeMode = Max;

    balanceSize();
}

ComboButton::~ComboButton()
{
}

void ComboButton::balanceSize()
{
    int width;

    if( m_sizeMode == Max )
        width = m_box->tqsizeHint().width()-17;
    else
        width = m_button->tqsizeHint().width();

    int height = ( m_box->tqsizeHint().height() > m_button->tqsizeHint().height() ) ? m_box->tqsizeHint().height() : m_button->tqsizeHint().height();

    m_box->setFixedSize( width+17, height+m_increaseHeight );
    m_button->setFixedSize( width, height+m_increaseHeight );
}

void ComboButton::repaintButton()
{
    m_button->setText( m_box->currentText() );
    if(m_box->pixmap( m_box->currentItem()) )
        m_button->setIconSet( *m_box->pixmap(m_box->currentItem()) );
    balanceSize();
}

void ComboButton::insertItem( const TQString &text, int index )
{
    m_box->insertItem( text, index );
    repaintButton();
}

void ComboButton::insertItem( const TQPixmap &pixmap, const TQString &text, int index )
{
    m_box->insertItem( pixmap, text, index );
    repaintButton();
}

void ComboButton::increaseHeight( int height )
{
    m_increaseHeight = height;
    balanceSize();
}

void ComboButton::boxActivated( int index )
{
    repaintButton();
    emit clicked( index );
}

void ComboButton::buttonClicked()
{
    emit clicked( m_box->currentItem() );
}

void ComboButton::setSizeMode( int mode )
{
    m_sizeMode = mode;
    balanceSize();
}

int ComboButton::sizeMode()
{
    return m_sizeMode;
}

void ComboButton::setFont( const TQFont& font )
{
    m_button->setFont( font );
    m_box->setFont( font );
}

TQFont ComboButton::font()
{
    return m_button->font();
}