jumpbuttonbar.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00038
00039 JumpButtonBar::JumpButtonBar(QWidget *parent, const char *name)
00040 : QVBox(parent, name)
00041 {
00042
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
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
00073
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
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"
This file is part of the documentation for kdelibs Version 3.1.4.