User interface update
[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.setStyleHint( QFont::Helvetica );
17         regularTextFont.setBold( true );
18         regularTextFont.setPixelSize( 18 );
19
20         iRoomCombo = new QComboBox( this );
21         for ( int i = 0; i < iRooms.count(); i++ )
22         {
23                 iRoomCombo->addItem( iRooms.at( i )->name() );
24         }
25         iRoomCombo->setFont( regularTextFont );
26         iRoomCombo->setFixedHeight( 46 );
27         connect( iRoomCombo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setCurrentIndex( int ) ) );
28         connect( iRoomCombo, SIGNAL( currentIndexChanged( const QString & ) ), this, SLOT( setCurrentRoomBy( const QString & ) ) );
29
30         QHBoxLayout *layout = new QHBoxLayout;
31         layout->addWidget( iRoomCombo );
32         layout->setMargin( 0 );
33         setLayout( layout );
34 }
35
36 MeetingRoomCombo::~MeetingRoomCombo()
37 {
38         delete iRoomCombo;
39         iRooms.clear();
40 }
41
42 int MeetingRoomCombo::count()
43 {
44         return iRoomCombo->count();
45 }
46
47 int MeetingRoomCombo::currentIndex()
48 {
49         return iRoomCombo->currentIndex();
50 }
51
52 Room* MeetingRoomCombo::currentRoom()
53 {
54         return currentIndex() >= 0 ? iRooms.at( currentIndex() ) : 0;
55 }
56
57 void MeetingRoomCombo::setCurrentIndex( int aIndex )
58 {
59         if ( 0 <= aIndex && aIndex < count() )
60         {
61                 iRoomCombo->setCurrentIndex( aIndex );
62         }
63         else
64         {
65                 iRoomCombo->setCurrentIndex( -1 );
66         }
67
68         emit currentRoomChanged( currentRoom() );
69         emit currentIndexChanged( currentIndex() );
70 }
71
72 void MeetingRoomCombo::setCurrentRoom( Room *aRoom )
73 {
74         setCurrentIndex( findRoom( aRoom ) );
75 }
76
77 void MeetingRoomCombo::setCurrentRoomBy( const QString &aName )
78 {
79         setCurrentIndex( findRoomBy( aName ) );
80 }
81
82 int MeetingRoomCombo::findRoom( Room *aRoom )
83 {
84         if ( aRoom == 0 )
85         {
86                 qDebug() << "MeetingRoomCombo::findRoom\t-1";
87                 return -1;
88         }
89
90         for ( int i = 0; i < iRooms.count(); i++ )
91         {
92                 if ( aRoom->equals( *( iRooms.at( i ) ) ) )
93                 {
94                         qDebug() << "MeetingRoomCombo::findRoom\t" << i;
95                         return i;
96                 }
97         }
98         qDebug() << "MeetingRoomCombo::findRoom\t-1";
99         return -1;
100 }
101
102 int MeetingRoomCombo::findRoomBy( const QString &aName )
103 {
104         return iRoomCombo->findText( aName );
105 }
106
107
108