libkdepim

sendsmsdialog.cpp

00001 /*
00002    This file is part of libkdepim.
00003 
00004    Copyright (C) 2005 Con Hennessy <cp.hennessy@iname.com>
00005                       Tobias Koenig <tokoe@kde.org>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
00021  */
00022 #include <qlabel.h>
00023 #include <qlayout.h>
00024 #include <qtextedit.h>
00025 
00026 #include <klocale.h>
00027 
00028 #include "sendsmsdialog.h"
00029 
00030 SendSMSDialog::SendSMSDialog( const QString &recipientName, QWidget *parent, const char *name )
00031   : KDialogBase( Plain, i18n( "Send SMS" ), Ok | Cancel, Ok, parent, name, true, true )
00032 {
00033   QWidget *page = plainPage();
00034 
00035   QGridLayout *layout = new QGridLayout( page, 3, 3, marginHint(), spacingHint() );
00036 
00037   layout->addWidget( new QLabel( i18n( "Message" ), page ), 0, 0 );
00038 
00039   mMessageLength = new QLabel( "0/160", page );
00040   mMessageLength->setAlignment( Qt::AlignRight );
00041   layout->addWidget( mMessageLength, 0, 2 );
00042 
00043   mText = new QTextEdit( page );
00044   layout->addMultiCellWidget( mText, 1, 1, 0, 2 );
00045 
00046   layout->addWidget( new QLabel( i18n( "Recipient:" ), page ), 2, 0 );
00047   layout->addWidget( new QLabel( recipientName, page ), 2, 2 );
00048 
00049   setButtonText( Ok, i18n( "Send" ) );
00050 
00051   connect( mText, SIGNAL( textChanged() ),
00052            this, SLOT( updateMessageLength() ) );
00053   connect( mText, SIGNAL( textChanged() ),
00054            this, SLOT( updateButtons() ) );
00055 
00056   updateButtons();
00057 
00058   mText->setFocus();
00059 }
00060 
00061 QString SendSMSDialog::text() const
00062 {
00063   return mText->text();
00064 }
00065 
00066 void SendSMSDialog::updateMessageLength()
00067 {
00068   int length = mText->length();
00069 
00070   if( length > 480 )
00071     mMessageLength->setText( QString( "%1/%2 (%3)" ).arg( length ).arg( 500 ).arg( 4 ) );
00072   else if( length > 320 )
00073     mMessageLength->setText( QString( "%1/%2 (%3)" ).arg( length ).arg( 480 ).arg( 3 ) );
00074   else if( length > 160 )
00075     mMessageLength->setText( QString( "%1/%2 (%3)" ).arg( length ).arg( 320 ).arg( 2 ) );
00076   else
00077     mMessageLength->setText( QString( "%1/%2" ).arg( length ).arg( 160 ) );
00078 }
00079 
00080 void SendSMSDialog::updateButtons()
00081 {
00082   enableButton( Ok, mText->length() > 0 );
00083 }
00084 
00085 #include "sendsmsdialog.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys