kaddressbook Library API Documentation

jumpbuttonbar.cpp

00001 /*                                                                      
00002     This file is part of KAddressBook.                                  
00003     Copyright (c) 2002 Mike Pilone <mpilone@slac.com>                   
00004                                                                         
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or   
00008     (at your option) any later version.                                 
00009                                                                         
00010     This program is distributed in the hope that it will be useful,     
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of      
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the        
00013     GNU General Public License for more details.                        
00014                                                                         
00015     You should have received a copy of the GNU General Public License   
00016     along with this program; if not, write to the Free Software         
00017     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.           
00018                                                                         
00019     As a special exception, permission is given to link this program    
00020     with any edition of Qt, and distribute the resulting executable,    
00021     without including the source code for Qt in the source distribution.
00022 */                                                                      
00023 
00024 #include "jumpbuttonbar.h"
00025 
00026 #include <qstring.h>
00027 #include <qevent.h>
00028 #include <qpushbutton.h>
00029 #include <qscrollview.h>
00030 #include <qlayout.h>
00031 
00032 #include <klocale.h>
00033 #include <kglobal.h>
00034 #include <kiconloader.h>
00035 
00037 // JumpButtonBar
00038 
00039 JumpButtonBar::JumpButtonBar(QWidget *parent, const char *name)
00040   : QVBox(parent, name)
00041 {
00042   // I don't think this is i18n approved, but I am not sure.
00043   int base = (int)'a';
00044   int end = (int)'z';
00045   QPushButton *b;
00046   QString letter;
00047   
00048   mUpButton = new QPushButton(this);
00049   mUpButton->setPixmap(KGlobal::iconLoader()->loadIcon("up", KIcon::Small));
00050   connect(mUpButton, SIGNAL(clicked()), this, SLOT(upClicked()));
00051   
00052   mScrollView = new QScrollView(this, "mScrollView");
00053   mScrollView->setVScrollBarMode(QScrollView::AlwaysOff);
00054   mScrollView->setHScrollBarMode(QScrollView::AlwaysOff);
00055   
00056   // Number button
00057   QVBox *vBox = new QVBox(mScrollView->viewport());
00058   mScrollView->addChild(vBox);
00059   
00060   b = new QPushButton("0,1,2", vBox, "0");
00061   connect(b, SIGNAL(clicked()), this, SLOT(letterClicked()));
00062   
00063   for (int i = base; i <= end; i++)
00064   {
00065     letter = (char)i;
00066     b = new QPushButton(letter, vBox, letter.latin1());
00067     connect(b, SIGNAL(clicked()), this, SLOT(letterClicked()));
00068   }
00069   
00070   vBox->setFixedSize(vBox->sizeHint());
00071   
00072   // There has to be a better way of setting the preferred size of the 
00073   // scroll view. Hmmm.
00074   mScrollView->setFixedWidth(vBox->sizeHint().width() + 3);
00075   
00076   mDownButton = new QPushButton(this);
00077   mDownButton->setPixmap(KGlobal::iconLoader()->loadIcon("down", KIcon::Small));
00078   connect(mDownButton, SIGNAL(clicked()), this, SLOT(downClicked()));
00079   
00080   // insert a spacer widget to use the rest of the space
00081   (void) new QWidget(this, "spacer");
00082 }
00083 
00084 JumpButtonBar::~JumpButtonBar()
00085 {
00086 }
00087     
00088 void JumpButtonBar::upClicked()
00089 {
00090   mScrollView->scrollBy(0, -25);
00091   
00092   updateArrowButtons();
00093 }
00094 
00095 void JumpButtonBar::downClicked()
00096 {
00097   mScrollView->scrollBy(0, 25);
00098   
00099   updateArrowButtons();
00100 }
00101 
00102 void JumpButtonBar::letterClicked()
00103 {
00104   QString name = sender()->name();
00105   if (!name.isEmpty())
00106     emit jumpToLetter(QChar(name[0]));
00107 }
00108 
00109 void JumpButtonBar::updateArrowButtons()
00110 {
00111   QScrollBar *bar = mScrollView->verticalScrollBar();
00112   mUpButton->setEnabled(bar->value() > bar->minValue());
00113   mDownButton->setEnabled(bar->value() < bar->maxValue());
00114 }
00115 
00116 void JumpButtonBar::resizeEvent(QResizeEvent *e)
00117 {
00118   QVBox::resizeEvent(e);
00119   
00120   updateArrowButtons();
00121 }
00122 
00123 void JumpButtonBar::show()
00124 {
00125   QVBox::show();
00126   
00127   updateArrowButtons();
00128 }
00129 
00130 #include "jumpbuttonbar.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:37 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001