00001 /********************************************************************** 00002 ** Copyright (C) 2000 Trolltech AS. All rights reserved. 00003 ** 00004 ** This file is part of Qt Palmtop Environment. 00005 ** 00006 ** This file may be distributed and/or modified under the terms of the 00007 ** GNU General Public License version 2 as published by the Free Software 00008 ** Foundation and appearing in the file LICENSE.GPL included in the 00009 ** packaging of this file. 00010 ** 00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00013 ** 00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00015 ** 00016 ** Contact info@trolltech.com if any conditions of this licensing are 00017 ** not clear to you. 00018 ** 00019 **********************************************************************/ 00020 00021 #include "ablabel.h" 00022 00023 #include <opie2/odebug.h> 00024 00025 AbLabel::AbLabel( QWidget *parent, const char *name ): 00026 QTextView( parent, name ), 00027 m_empty( false ) 00028 { 00029 } 00030 00031 AbLabel::~AbLabel() 00032 { 00033 } 00034 00035 void AbLabel::setContacts( const Opie::OPimContactAccess::List& viewList ) 00036 { 00037 m_viewList = viewList; 00038 if (m_viewList.count() != 0){ 00039 m_empty = false; 00040 m_itCurContact = m_viewList.begin(); 00041 sync(); 00042 }else{ 00043 // m_itCurContact.clear(); 00044 m_empty = true; 00045 setText( "" ); 00046 } 00047 } 00048 00049 int AbLabel::currentEntry_UID() 00050 { 00051 Opie::OPimContact contact = currentEntry(); 00052 00053 if ( contact.isEmpty() ) 00054 return 0; 00055 else 00056 return ( contact.uid() ); 00057 } 00058 00059 Opie::OPimContact AbLabel::currentEntry() 00060 { 00061 if ( ! m_empty ) 00062 return ( *m_itCurContact ); 00063 else 00064 return Opie::OPimContact(); 00065 } 00066 00067 00068 bool AbLabel::selectContact( int UID ) 00069 { 00070 00071 for ( uint r = 0; r < m_viewList.count(); ++r ) { 00072 if ( m_viewList.uidAt( r ) == UID ){ 00073 m_itCurContact.setCurrent( r ); 00074 break; 00075 } 00076 } 00077 00078 sync(); 00079 00080 return true; 00081 } 00082 00083 00084 00085 void AbLabel::sync() 00086 { 00087 QString text = (*m_itCurContact).toRichText(); 00088 setText( text ); 00089 } 00090 00091 void AbLabel::keyPressEvent( QKeyEvent *e ) 00092 { 00093 00094 // Commonly handled keys 00095 if ( !m_empty ){ 00096 switch( e->key() ) { 00097 case Qt::Key_Left: 00098 odebug << "Left.." << oendl; 00099 case Qt::Key_Right: 00100 odebug << "Right.." << oendl; 00101 case Qt::Key_F33: 00102 odebug << "OK.." << oendl; 00103 emit signalOkPressed(); 00104 break; 00105 case Qt::Key_Up: 00106 odebug << "Up.." << oendl; 00107 if ( ( visibleHeight() < contentsHeight() ) && 00108 ( verticalScrollBar()->value() > verticalScrollBar()->minValue() ) ) 00109 scrollBy( 0, -(visibleHeight()-20) ); 00110 else { 00111 --m_itCurContact; 00112 if ( *m_itCurContact != Opie::OPimContact() ) 00113 sync(); 00114 else 00115 m_itCurContact = m_viewList.end(); 00116 } 00117 00118 break; 00119 case Qt::Key_Down: 00120 odebug << "Down.." << oendl; 00121 // odebug << "Visible: " << visibleHeight() << ", content: " << contentHeight() << oendl; 00122 // odebug << "Value: " << verticalScrollBar()->value() 00123 // << ", barMaxValue: " << verticalScrollBar()->maxValue() << oendl; 00124 if ( ( visibleHeight() < contentsHeight() ) && 00125 ( verticalScrollBar()->value() < verticalScrollBar()->maxValue() ) ) 00126 scrollBy( 0, visibleHeight()-20 ); 00127 else { 00128 ++m_itCurContact; 00129 if ( *m_itCurContact != Opie::OPimContact() ) 00130 sync(); 00131 else 00132 m_itCurContact = m_viewList.begin(); 00133 } 00134 break; 00135 case Qt::Key_Return: // fall through 00136 case Qt::Key_Space: // fall through 00137 case Qt::Key_Enter: // we want to switch back 00138 emit signalOkPressed(); 00139 break; 00140 default: break; 00141 } 00142 } 00143 00144 }
1.4.2