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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 00019 As a special exception, permission is given to link this program 00020 with any edition of TQt, and distribute the resulting executable, 00021 without including the source code for TQt in the source distribution. 00022 */ 00023 00024 #ifndef CARDVIEW_H 00025 #define CARDVIEW_H 00026 00027 #include <tqpair.h> 00028 #include <tqpoint.h> 00029 #include <tqptrlist.h> 00030 #include <tqrect.h> 00031 #include <tqscrollview.h> 00032 #include <tqstring.h> 00033 00034 class TQLabel; 00035 class TQMouseEvent; 00036 class TQPainter; 00037 class TQResizeEvent; 00038 00039 class CardView; 00040 class CardViewItemPrivate; 00041 class CardViewPrivate; 00042 class CardViewTip; 00043 00049 class CardViewItem 00050 { 00051 friend class CardView; 00052 00053 public: 00058 typedef TQPair<TQString, TQString> Field; 00059 00068 CardViewItem( CardView *parent, const TQString &caption = TQString() ); 00069 virtual ~CardViewItem(); 00070 00074 const TQString &caption() const; 00075 00081 void setCaption( const TQString &caption ); 00082 00087 virtual void paintCard( TQPainter *p, TQColorGroup &cg ); 00088 00093 virtual void repaintCard(); 00094 00102 void insertField( const TQString &label, const TQString &value ); 00103 00107 void removeField( const TQString &label ); 00108 00112 TQString fieldValue( const TQString &label ) const; 00113 00117 void clearFields(); 00118 00124 CardViewItem *nextItem() const; 00125 00129 bool isSelected() const; 00130 00136 void showFullString( const TQPoint &pos, CardViewTip *tip ); 00137 00143 Field *fieldAt( const TQPoint &itempos ) const; 00144 00145 CardView *cardView() const { return mView; }; 00146 00155 int height( bool allowCache = true ) const; 00156 00157 protected: 00162 void setSelected( bool selected ); 00163 00164 private: 00168 void initialize(); 00169 00176 TQString trimString( const TQString &text, int width, TQFontMetrics &fm ) const; 00177 00178 CardViewItemPrivate *d; 00179 CardView *mView; 00180 }; 00181 00194 class CardView : public TQScrollView 00195 { 00196 friend class CardViewItem; 00197 00198 Q_OBJECT 00199 00200 00201 public: 00205 CardView( TQWidget *parent, const char *name ); 00206 virtual ~CardView(); 00207 00213 void insertItem( CardViewItem *item ); 00214 00219 void takeItem( CardViewItem *item ); 00220 00224 void clear(); 00225 00232 CardViewItem *currentItem() const; 00233 00237 void setCurrentItem( CardViewItem *item ); 00238 00243 CardViewItem *itemAt( const TQPoint &viewPos ) const; 00244 00248 TQRect itemRect( const CardViewItem *item ) const; 00249 00253 void ensureItemVisible( const CardViewItem *item ); 00254 00258 void repaintItem( const CardViewItem *item ); 00259 00260 enum SelectionMode { Single, Multi, Extended, NoSelection }; 00261 00267 void setSelectionMode( SelectionMode mode ); 00268 00272 SelectionMode selectionMode() const; 00273 00278 void setSelected( CardViewItem *item, bool selected ); 00279 00283 void selectAll( bool state ); 00284 00288 bool isSelected( CardViewItem *item ) const; 00289 00295 CardViewItem *selectedItem() const; 00296 00302 CardViewItem *firstItem() const; 00303 00308 CardViewItem *itemAfter( const CardViewItem *item ) const; 00309 00313 int childCount() const; 00314 00324 CardViewItem *findItem( const TQString &text, const TQString &label, 00325 TQt::StringComparisonMode compare = TQt::BeginsWith ) const; 00326 00334 uint columnWidth() const; 00335 00341 void setDrawCardBorder( bool enabled ); 00342 00346 bool drawCardBorder() const; 00347 00354 void setDrawColSeparators( bool enabled ); 00355 00359 bool drawColSeparators() const; 00360 00367 void setDrawFieldLabels( bool enabled ); 00368 00372 bool drawFieldLabels() const; 00373 00378 void setShowEmptyFields( bool show ); 00379 00383 bool showEmptyFields() const; 00384 00394 // Note: I looked for a value in TQStyle::PixelMetric to use, but I could 00395 // not see a useful one. One may turn up in a future version of TQt. 00396 uint itemMargin() const; 00397 00401 void setItemMargin( uint margin ); 00402 00409 // Note: There is no useful TQStyle::PixelMetric to use for this atm. 00410 // An option would be using KDialog::spacingHint(). 00411 uint itemSpacing() const; 00412 00417 void setItemSpacing( uint spacing ); 00418 00422 int itemWidth() const; 00423 00427 void setItemWidth( int width ); 00428 00432 void setHeaderFont( const TQFont &fnt ); 00433 00437 TQFont headerFont() const; 00438 00442 void setFont( const TQFont &fnt ); 00443 00447 void setSeparatorWidth( int width ); 00448 00452 int separatorWidth() const; 00453 00458 void setMaxFieldLines( int howmany ); 00459 00463 int maxFieldLines() const; 00464 00465 signals: 00470 void selectionChanged(); 00471 00477 void selectionChanged( CardViewItem* ); 00478 00482 void clicked( CardViewItem* ); 00483 00489 void executed( CardViewItem* ); 00490 00494 void doubleClicked( CardViewItem* ); 00495 00499 void currentChanged( CardViewItem* ); 00500 00504 void returnPressed( CardViewItem* ); 00505 00509 void contextMenuRequested( CardViewItem*, const TQPoint& ); 00510 00511 protected: 00516 void drawContents( TQPainter *p, int clipx, int clipy, int clipw, int cliph ); 00517 00521 void resizeEvent( TQResizeEvent* ); 00522 00526 void contentsWheelEvent( TQWheelEvent* ); 00527 00531 void setLayoutDirty( bool dirty ); 00532 00538 void calcLayout(); 00539 00540 virtual void contentsMousePressEvent( TQMouseEvent* ); 00541 virtual void contentsMouseMoveEvent( TQMouseEvent* ); 00542 virtual void contentsMouseReleaseEvent( TQMouseEvent* ); 00543 virtual void contentsMouseDoubleClickEvent( TQMouseEvent* ); 00544 00545 virtual void enterEvent( TQEvent* ); 00546 virtual void leaveEvent( TQEvent* ); 00547 00548 virtual void focusInEvent( TQFocusEvent* ); 00549 virtual void focusOutEvent( TQFocusEvent* ); 00550 00551 virtual void keyPressEvent( TQKeyEvent* ); 00552 00558 virtual void startDrag(); 00559 00560 private slots: 00566 void tryShowFullText(); 00567 00568 private: 00575 void drawRubberBands( int pos ); 00576 00577 CardViewPrivate *d; 00578 }; 00579 00580 #endif