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
116
117
118
119
120
121
122
123
124
125
126
127
|
/*
*
* $Id: k3bwritingmodewidget.cpp 554512 2006-06-24 07:25:39Z trueg $
* Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org>
*
* This file is part of the K3b project.
* Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
*
* 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.
* See the file "COPYING" for the exact licensing terms.
*/
#include "k3bintmapcombobox.h"
#include <tqwhatsthis.h>
#include <tqmap.h>
#include <tqvaluevector.h>
class K3bIntMapComboBox::Private
{
public:
TQMap<int, int> valueIndexMap;
TQMap<int, TQPair<int, TQString> > indexValueDescriptionMap;
TQString topWhatsThis;
TQString bottomWhatsThis;
};
K3bIntMapComboBox::K3bIntMapComboBox( TQWidget* tqparent, const char* name )
: KComboBox( tqparent, name )
{
d = new Private;
connect( this, TQT_SIGNAL(highlighted(int)),
this, TQT_SLOT(slotItemHighlighted(int)) );
connect( this, TQT_SIGNAL(activated(int)),
this, TQT_SLOT(slotItemActivated(int)) );
}
K3bIntMapComboBox::~K3bIntMapComboBox()
{
delete d;
}
int K3bIntMapComboBox::selectedValue() const
{
if( (int)d->indexValueDescriptionMap.count() > KComboBox::currentItem() )
return d->indexValueDescriptionMap[KComboBox::currentItem()].first;
else
return 0;
}
void K3bIntMapComboBox::setSelectedValue( int value )
{
if( d->valueIndexMap.contains( value ) )
KComboBox::setCurrentItem( d->valueIndexMap[value] );
}
void K3bIntMapComboBox::clear()
{
d->valueIndexMap.clear();
d->indexValueDescriptionMap.clear();
KComboBox::clear();
}
bool K3bIntMapComboBox::insertItem( int value, const TQString& text, const TQString& description, int index )
{
if( d->valueIndexMap.contains( value ) )
return false;
// FIXME: allow inserition at any index
index = KComboBox::count();
d->valueIndexMap[value] = index;
d->indexValueDescriptionMap[index] = tqMakePair<int, TQString>( value, description );
KComboBox::insertItem( text );
updateWhatsThis();
return true;
}
void K3bIntMapComboBox::updateWhatsThis()
{
TQString ws( d->topWhatsThis );
for( unsigned int i = 0; i < d->indexValueDescriptionMap.count(); ++i ) {
ws += "<p><b>" + KComboBox::text( i ) + "</b><br>";
ws += d->indexValueDescriptionMap[i].second;
}
ws += "<p>" + d->bottomWhatsThis;
TQWhatsThis::add( this, ws );
}
void K3bIntMapComboBox::slotItemHighlighted( int index )
{
emit valueHighlighted( d->indexValueDescriptionMap[index].first );
}
void K3bIntMapComboBox::slotItemActivated( int index )
{
emit valueChanged( d->indexValueDescriptionMap[index].first );
}
void K3bIntMapComboBox::addGlobalWhatsThisText( const TQString& top, const TQString& bottom )
{
d->topWhatsThis = top;
d->bottomWhatsThis = bottom;
updateWhatsThis();
}
#include "k3bintmapcombobox.moc"
|