kaddressbook Library API Documentation

cardview.h

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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 #ifndef CARDVIEW_H 00025 #define CARDVIEW_H 00026 00027 #include <qscrollview.h> 00028 #include <qptrlist.h> 00029 #include <qstring.h> 00030 #include <qrect.h> 00031 #include <qpair.h> 00032 #include <qpoint.h> 00033 00034 class QLabel; 00035 class QPainter; 00036 class QResizeEvent; 00037 class QMouseEvent; 00038 class CardView; 00039 class CardViewPrivate; 00040 class CardViewItemPrivate; 00041 class CardViewTip; 00042 00047 class CardViewItem 00048 { 00049 friend class CardView; 00050 00051 public: 00055 typedef QPair<QString, QString> Field; 00056 00064 CardViewItem(CardView *parent, QString caption = QString::null); 00065 virtual ~CardViewItem(); 00066 00070 const QString &caption() const; 00071 00076 void setCaption(const QString &caption); 00077 00081 virtual void paintCard(QPainter *p, QColorGroup &cg); 00082 00086 virtual void repaintCard(); 00087 00094 void insertField(const QString &label, const QString &value); 00095 00098 void removeField(const QString &label); 00099 00102 QString fieldValue(const QString &label); 00103 00106 void clearFields(); 00107 00112 CardViewItem *nextItem(); 00113 00116 bool isSelected() const; 00117 00122 void showFullString( const QPoint &pos, CardViewTip *tip ); 00123 00128 Field *fieldAt( const QPoint &itempos ) const; 00129 00130 CardView *cardView() { return mView; }; 00131 00139 int height( bool allowCache=true ) const; 00140 00141 protected: 00145 void setSelected(bool selected); 00146 00147 private: 00150 void initialize(); 00151 00157 QString trimString(const QString &text, int width, QFontMetrics &fm); 00158 00159 CardViewItemPrivate *d; 00160 CardView *mView; 00161 }; 00162 00174 class CardView : public QScrollView 00175 { 00176 friend class CardViewItem; 00177 00178 Q_OBJECT 00179 00180 public: 00183 CardView(QWidget *parent, const char *name); 00184 virtual ~CardView(); 00185 00190 void insertItem(CardViewItem *item); 00191 00195 void takeItem(CardViewItem *item); 00196 00199 void clear(); 00200 00206 CardViewItem *currentItem(); 00207 00210 void setCurrentItem( CardViewItem *item ); 00211 00215 CardViewItem *itemAt(const QPoint &viewPos); 00216 00219 QRect itemRect(const CardViewItem *item); 00220 00223 void ensureItemVisible(const CardViewItem *item); 00224 00227 void repaintItem(const CardViewItem *item); 00228 00229 enum SelectionMode { Single, Multi, Extended, NoSelection }; 00230 00235 void setSelectionMode(SelectionMode mode); 00236 00239 SelectionMode selectionMode() const; 00240 00244 void setSelected(CardViewItem *item, bool selected); 00245 00248 void selectAll(bool state); 00249 00252 bool isSelected(CardViewItem *item) const; 00253 00258 CardViewItem *selectedItem() const; 00259 00264 CardViewItem *firstItem() const; 00265 00269 CardViewItem *itemAfter(CardViewItem *item); 00270 00273 int childCount() const; 00274 00283 CardViewItem *findItem(const QString &text, const QString &label, 00284 Qt::StringComparisonMode compare = Qt::BeginsWith); 00285 00292 uint columnWidth(); 00293 00298 void setDrawCardBorder(bool enabled); 00299 00302 bool drawCardBorder() const; 00303 00309 void setDrawColSeparators(bool enabled); 00310 00313 bool drawColSeparators() const; 00314 00320 void setDrawFieldLabels(bool enabled); 00321 00324 bool drawFieldLabels() const; 00325 00329 void setShowEmptyFields(bool show); 00330 00333 bool showEmptyFields() const; 00334 00345 uint itemMargin(); 00346 00349 void setItemMargin( uint margin ); 00350 00359 uint itemSpacing(); 00360 00364 void setItemSpacing( uint spacing ); 00365 00367 int itemWidth() const; 00368 00370 void setItemWidth( int width ); 00371 00373 void setHeaderFont( const QFont &fnt ); 00374 00376 QFont headerFont() const; 00377 00379 void setFont( const QFont &fnt ); 00380 00382 void setSeparatorWidth( int width ); 00383 00385 int separatorWidth(); 00386 00390 void setMaxFieldLines( int howmany ); 00391 00393 int maxFieldLines() const; 00394 00395 signals: 00399 void selectionChanged(); 00400 00405 void selectionChanged(CardViewItem *); 00406 00409 void clicked(CardViewItem *); 00410 00415 void executed(CardViewItem *); 00416 00419 void doubleClicked(CardViewItem *); 00420 00423 void currentChanged( CardViewItem * ); 00424 00427 void returnPressed( CardViewItem * ); 00428 00431 void contextMenuRequested( CardViewItem*, const QPoint& ); 00432 00433 protected: 00437 void drawContents(QPainter *p, int clipx, int clipy, int clipw, int cliph); 00438 00441 void resizeEvent(QResizeEvent *e); 00442 00445 void contentsWheelEvent(QWheelEvent *e); 00446 00449 void setLayoutDirty(bool dirty); 00450 00455 void calcLayout(); 00456 00457 // virtual void mousePressEvent(QMouseEvent *e); 00458 // virtual void mouseReleaseEvent(QMouseEvent *e); 00459 // virtual void mouseMoveEvent(QMouseEvent *e); 00460 00461 virtual void contentsMousePressEvent(QMouseEvent *e); 00462 virtual void contentsMouseMoveEvent(QMouseEvent *e); 00463 virtual void contentsMouseReleaseEvent(QMouseEvent *e); 00464 virtual void contentsMouseDoubleClickEvent(QMouseEvent *e); 00465 00466 virtual void enterEvent( QEvent * ); 00467 virtual void leaveEvent( QEvent * ); 00468 00469 virtual void focusInEvent( QFocusEvent * ); 00470 virtual void focusOutEvent( QFocusEvent * ); 00471 00472 virtual void keyPressEvent( QKeyEvent * ); 00473 00478 virtual void startDrag(); 00479 00480 private slots: 00485 void tryShowFullText(); 00486 00487 private: 00493 void drawRubberBands( int pos ); 00494 00495 CardViewPrivate *d; 00496 }; 00497 00498 #endif
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:51:11 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003