kaddressbook

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 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 <qpair.h>
00028 #include <qpoint.h>
00029 #include <qptrlist.h>
00030 #include <qrect.h>
00031 #include <qscrollview.h>
00032 #include <qstring.h>
00033 
00034 class QLabel;
00035 class QMouseEvent;
00036 class QPainter;
00037 class QResizeEvent;
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 QPair<QString, QString> Field;
00059 
00068     CardViewItem( CardView *parent, const QString &caption = QString() );
00069     virtual ~CardViewItem();
00070 
00074     const QString &caption() const;
00075 
00081     void setCaption( const QString &caption );
00082 
00087     virtual void paintCard( QPainter *p, QColorGroup &cg );
00088 
00093     virtual void repaintCard();
00094 
00102     void insertField( const QString &label, const QString &value );
00103 
00107     void removeField( const QString &label );
00108 
00112     QString fieldValue( const QString &label ) const;
00113 
00117     void clearFields();
00118 
00124     CardViewItem *nextItem() const;
00125 
00129     bool isSelected() const;
00130 
00136     void showFullString( const QPoint &pos, CardViewTip *tip );
00137 
00143     Field *fieldAt( const QPoint &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     QString trimString( const QString &text, int width, QFontMetrics &fm ) const;
00177 
00178     CardViewItemPrivate *d;
00179     CardView *mView;
00180 };
00181 
00194 class CardView : public QScrollView
00195 {
00196   friend class CardViewItem;
00197 
00198   Q_OBJECT
00199 
00200   public:
00204     CardView( QWidget *parent, const char *name );
00205     virtual ~CardView();
00206 
00212     void insertItem( CardViewItem *item );
00213 
00218     void takeItem( CardViewItem *item );
00219 
00223     void clear();
00224 
00231     CardViewItem *currentItem() const;
00232 
00236     void setCurrentItem( CardViewItem *item );
00237 
00242     CardViewItem *itemAt( const QPoint &viewPos ) const;
00243 
00247     QRect itemRect( const CardViewItem *item ) const;
00248 
00252     void ensureItemVisible( const CardViewItem *item );
00253 
00257     void repaintItem( const CardViewItem *item );
00258 
00259     enum SelectionMode { Single, Multi, Extended, NoSelection };
00260 
00266     void setSelectionMode( SelectionMode mode );
00267 
00271     SelectionMode selectionMode() const;
00272 
00277     void setSelected( CardViewItem *item, bool selected );
00278 
00282     void selectAll( bool state );
00283 
00287     bool isSelected( CardViewItem *item ) const;
00288 
00294     CardViewItem *selectedItem() const;
00295 
00301     CardViewItem *firstItem() const;
00302 
00307     CardViewItem *itemAfter( const CardViewItem *item ) const;
00308 
00312     int childCount() const;
00313 
00323     CardViewItem *findItem( const QString &text, const QString &label,
00324                             Qt::StringComparisonMode compare = Qt::BeginsWith ) const;
00325 
00333     uint columnWidth() const;
00334 
00340     void setDrawCardBorder( bool enabled );
00341 
00345     bool drawCardBorder() const;
00346 
00353     void setDrawColSeparators( bool enabled );
00354 
00358     bool drawColSeparators() const;
00359 
00366     void setDrawFieldLabels( bool enabled );
00367 
00371     bool drawFieldLabels() const;
00372 
00377     void setShowEmptyFields( bool show );
00378 
00382     bool showEmptyFields() const;
00383 
00393     // Note: I looked for a value in QStyle::PixelMetric to use, but I could
00394     // not see a useful one. One may turn up in a future version of Qt.
00395     uint itemMargin() const;
00396 
00400     void setItemMargin( uint margin );
00401 
00408     // Note: There is no useful QStyle::PixelMetric to use for this atm.
00409     // An option would be using KDialog::spacingHint().
00410     uint itemSpacing() const;
00411 
00416     void setItemSpacing( uint spacing );
00417 
00421     int itemWidth() const;
00422 
00426     void setItemWidth( int width );
00427 
00431     void setHeaderFont( const QFont &fnt );
00432 
00436     QFont headerFont() const;
00437 
00441     void setFont( const QFont &fnt );
00442 
00446     void setSeparatorWidth( int width );
00447 
00451     int separatorWidth() const;
00452 
00457     void setMaxFieldLines( int howmany );
00458 
00462     int maxFieldLines() const;
00463 
00464   signals:
00469     void selectionChanged();
00470 
00476     void selectionChanged( CardViewItem* );
00477 
00481     void clicked( CardViewItem* );
00482 
00488     void executed( CardViewItem* );
00489 
00493     void doubleClicked( CardViewItem* );
00494 
00498     void currentChanged( CardViewItem* );
00499 
00503     void returnPressed( CardViewItem* );
00504 
00508     void contextMenuRequested( CardViewItem*, const QPoint& );
00509 
00510   protected:
00515     void drawContents( QPainter *p, int clipx, int clipy, int clipw, int cliph );
00516 
00520     void resizeEvent( QResizeEvent* );
00521 
00525     void contentsWheelEvent( QWheelEvent* );
00526 
00530     void setLayoutDirty( bool dirty );
00531 
00537     void calcLayout();
00538 
00539     virtual void contentsMousePressEvent( QMouseEvent* );
00540     virtual void contentsMouseMoveEvent( QMouseEvent* );
00541     virtual void contentsMouseReleaseEvent( QMouseEvent* );
00542     virtual void contentsMouseDoubleClickEvent( QMouseEvent* );
00543 
00544     virtual void enterEvent( QEvent* );
00545     virtual void leaveEvent( QEvent* );
00546 
00547     virtual void focusInEvent( QFocusEvent* );
00548     virtual void focusOutEvent( QFocusEvent* );
00549 
00550     virtual void keyPressEvent( QKeyEvent* );
00551 
00557     virtual void startDrag();
00558 
00559   private slots:
00565     void tryShowFullText();
00566 
00567   private:
00574     void drawRubberBands( int pos );
00575 
00576     CardViewPrivate *d;
00577 };
00578 
00579 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys