fad049365f5c18f34c543fe396aec4148aa3735c
[qtmeetings] / src / UserInterface / Components / MeetingRoomCombo.cpp
1 #include "MeetingRoomCombo.h"
2
3 #include <QComboBox>
4 #include <QVBoxLayout>
5 #include "Room.h"
6
7 #include <QtDebug>
8
9 MeetingRoomCombo::MeetingRoomCombo( QList<Room*> aRooms, QWidget *aParent ) :
10                 QWidget( aParent )
11 {
12         iRooms = aRooms;
13         qSort( iRooms.begin(), iRooms.end(), Room::caseInsensitiveLessThan );
14
15         QFont regularTextFont;
16         regularTextFont.setBold( false );
17         regularTextFont.setPointSize( 12 );
18
19         iRoomCombo = new QComboBox( this );
20         for ( int i = 0; i < iRooms.count(); i++ )
21         {
22                 iRoomCombo->addItem( iRooms.at( i )->name() );
23         }
24         iRoomCombo->setFont( regularTextFont );
25         connect( iRoomCombo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setCurrentIndex( int ) ) );
26         connect( iRoomCombo, SIGNAL( currentIndexChanged( const QString & ) ), this, SLOT( setCurrentRoomBy( const QString & ) ) );
27
28         QHBoxLayout *layout = new QHBoxLayout;
29         layout->addWidget( iRoomCombo );
30         layout->setMargin( 0 );
31         setLayout( layout );
32 }
33
34 MeetingRoomCombo::~MeetingRoomCombo()
35 {
36         delete iRoomCombo;
37         iRooms.clear();
38 }
39
40 int MeetingRoomCombo::count()
41 {
42         return iRoomCombo->count();
43 }
44
45 int MeetingRoomCombo::currentIndex()
46 {
47         return iRoomCombo->currentIndex();
48 }
49
50 Room* MeetingRoomCombo::currentRoom()
51 {
52         return currentIndex() >= 0 ? iRooms.at( currentIndex() ) : 0;
53 }
54
55 void MeetingRoomCombo::setCurrentIndex( int aIndex )
56 {
57         if ( 0 <= aIndex && aIndex < count() )
58         {
59                 iRoomCombo->setCurrentIndex( aIndex );
60         }
61         else
62         {
63                 iRoomCombo->setCurrentIndex( -1 );
64         }
65
66         emit currentRoomChanged( currentRoom() );
67         emit currentIndexChanged( currentIndex() );
68 }
69
70 void MeetingRoomCombo::setCurrentRoom( Room *aRoom )
71 {
72         setCurrentIndex( findRoom( aRoom ) );
73 }
74
75 void MeetingRoomCombo::setCurrentRoomBy( const QString &aName )
76 {
77         setCurrentIndex( findRoomBy( aName ) );
78 }
79
80 int MeetingRoomCombo::findRoom( Room *aRoom )
81 {
82         if ( aRoom == 0 )
83         {
84                 qDebug() << "MeetingRoomCombo::findRoom\t-1";
85                 return -1;
86         }
87
88         for ( int i = 0; i < iRooms.count(); i++ )
89         {
90                 if ( aRoom->equals( *( iRooms.at( i ) ) ) )
91                 {
92                         qDebug() << "MeetingRoomCombo::findRoom\t" << i;
93                         return i;
94                 }
95         }
96         qDebug() << "MeetingRoomCombo::findRoom\t-1";
97         return -1;
98 }
99
100 int MeetingRoomCombo::findRoomBy( const QString &aName )
101 {
102         return iRoomCombo->findText( aName );
103 }
104
105
106