kaddressbook

cardview.h
1 /*
2  This file is part of KAddressBook.
3  Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19  As a special exception, permission is given to link this program
20  with any edition of TQt, and distribute the resulting executable,
21  without including the source code for TQt in the source distribution.
22 */
23 
24 #ifndef CARDVIEW_H
25 #define CARDVIEW_H
26 
27 #include <tqpair.h>
28 #include <tqpoint.h>
29 #include <tqptrlist.h>
30 #include <tqrect.h>
31 #include <tqscrollview.h>
32 #include <tqstring.h>
33 
34 class TQLabel;
35 class TQMouseEvent;
36 class TQPainter;
37 class TQResizeEvent;
38 
39 class CardView;
40 class CardViewItemPrivate;
41 class CardViewPrivate;
42 class CardViewTip;
43 
50 {
51  friend class CardView;
52 
53  public:
58  typedef TQPair<TQString, TQString> Field;
59 
68  CardViewItem( CardView *parent, const TQString &caption = TQString() );
69  virtual ~CardViewItem();
70 
74  const TQString &caption() const;
75 
81  void setCaption( const TQString &caption );
82 
87  virtual void paintCard( TQPainter *p, TQColorGroup &cg );
88 
93  virtual void repaintCard();
94 
102  void insertField( const TQString &label, const TQString &value );
103 
107  void removeField( const TQString &label );
108 
112  TQString fieldValue( const TQString &label ) const;
113 
117  void clearFields();
118 
124  CardViewItem *nextItem() const;
125 
129  bool isSelected() const;
130 
136  void showFullString( const TQPoint &pos, CardViewTip *tip );
137 
143  Field *fieldAt( const TQPoint &itempos ) const;
144 
145  CardView *cardView() const { return mView; };
146 
155  int height( bool allowCache = true ) const;
156 
157  protected:
162  void setSelected( bool selected );
163 
164  private:
168  void initialize();
169 
176  TQString trimString( const TQString &text, int width, TQFontMetrics &fm ) const;
177 
178  CardViewItemPrivate *d;
179  CardView *mView;
180 };
181 
194 class CardView : public TQScrollView
195 {
196  friend class CardViewItem;
197 
198  TQ_OBJECT
199 
200 
201  public:
205  CardView( TQWidget *parent, const char *name );
206  virtual ~CardView();
207 
213  void insertItem( CardViewItem *item );
214 
219  void takeItem( CardViewItem *item );
220 
224  void clear();
225 
232  CardViewItem *currentItem() const;
233 
237  void setCurrentItem( CardViewItem *item );
238 
243  CardViewItem *itemAt( const TQPoint &viewPos ) const;
244 
248  TQRect itemRect( const CardViewItem *item ) const;
249 
253  void ensureItemVisible( const CardViewItem *item );
254 
258  void repaintItem( const CardViewItem *item );
259 
260  enum SelectionMode { Single, Multi, Extended, NoSelection };
261 
267  void setSelectionMode( SelectionMode mode );
268 
272  SelectionMode selectionMode() const;
273 
278  void setSelected( CardViewItem *item, bool selected );
279 
283  void selectAll( bool state );
284 
288  bool isSelected( CardViewItem *item ) const;
289 
295  CardViewItem *selectedItem() const;
296 
302  CardViewItem *firstItem() const;
303 
308  CardViewItem *itemAfter( const CardViewItem *item ) const;
309 
313  int childCount() const;
314 
324  CardViewItem *findItem( const TQString &text, const TQString &label,
325  TQt::StringComparisonMode compare = TQt::BeginsWith ) const;
326 
334  uint columnWidth() const;
335 
341  void setDrawCardBorder( bool enabled );
342 
346  bool drawCardBorder() const;
347 
354  void setDrawColSeparators( bool enabled );
355 
359  bool drawColSeparators() const;
360 
367  void setDrawFieldLabels( bool enabled );
368 
372  bool drawFieldLabels() const;
373 
378  void setShowEmptyFields( bool show );
379 
383  bool showEmptyFields() const;
384 
394  // Note: I looked for a value in TQStyle::PixelMetric to use, but I could
395  // not see a useful one. One may turn up in a future version of TQt.
396  uint itemMargin() const;
397 
401  void setItemMargin( uint margin );
402 
409  // Note: There is no useful TQStyle::PixelMetric to use for this atm.
410  // An option would be using KDialog::spacingHint().
411  uint itemSpacing() const;
412 
417  void setItemSpacing( uint spacing );
418 
422  int itemWidth() const;
423 
427  void setItemWidth( int width );
428 
432  void setHeaderFont( const TQFont &fnt );
433 
437  TQFont headerFont() const;
438 
442  void setFont( const TQFont &fnt );
443 
447  void setSeparatorWidth( int width );
448 
452  int separatorWidth() const;
453 
458  void setMaxFieldLines( int howmany );
459 
463  int maxFieldLines() const;
464 
465  signals:
471 
478 
483 
490 
495 
500 
505 
509  void contextMenuRequested( CardViewItem*, const TQPoint& );
510 
511  protected:
516  void drawContents( TQPainter *p, int clipx, int clipy, int clipw, int cliph );
517 
521  void resizeEvent( TQResizeEvent* );
522 
526  void contentsWheelEvent( TQWheelEvent* );
527 
531  void setLayoutDirty( bool dirty );
532 
538  void calcLayout();
539 
540  virtual void contentsMousePressEvent( TQMouseEvent* );
541  virtual void contentsMouseMoveEvent( TQMouseEvent* );
542  virtual void contentsMouseReleaseEvent( TQMouseEvent* );
543  virtual void contentsMouseDoubleClickEvent( TQMouseEvent* );
544 
545  virtual void enterEvent( TQEvent* );
546  virtual void leaveEvent( TQEvent* );
547 
548  virtual void focusInEvent( TQFocusEvent* );
549  virtual void focusOutEvent( TQFocusEvent* );
550 
551  virtual void keyPressEvent( TQKeyEvent* );
552 
558  virtual void startDrag();
559 
560  private slots:
566  void tryShowFullText();
567 
568  private:
575  void drawRubberBands( int pos );
576 
577  CardViewPrivate *d;
578 };
579 
580 #endif
Represents a single card (item) in the card view.
Definition: cardview.h:50
void removeField(const TQString &label)
Removes the field with label label from the card.
Definition: cardview.cpp:390
const TQString & caption() const
Definition: cardview.cpp:326
virtual void paintCard(TQPainter *p, TQColorGroup &cg)
Paints the card using the given painter and color group.
Definition: cardview.cpp:225
CardViewItem * nextItem() const
Definition: cardview.cpp:441
void clearFields()
Removes all the fields from this card.
Definition: cardview.cpp:409
void setSelected(bool selected)
Sets the card as selected.
Definition: cardview.cpp:373
void setCaption(const TQString &caption)
Sets the caption of the card.
Definition: cardview.cpp:457
void showFullString(const TQPoint &pos, CardViewTip *tip)
Called by the parent card view when the mouse has been resting for a certain amount of time.
Definition: cardview.cpp:474
virtual void repaintCard()
Repaints the card.
Definition: cardview.cpp:451
CardViewItem(CardView *parent, const TQString &caption=TQString())
Constructor.
Definition: cardview.cpp:195
TQPair< TQString, TQString > Field
A single field in the card view.
Definition: cardview.h:58
bool isSelected() const
Definition: cardview.cpp:368
int height(bool allowCache=true) const
Definition: cardview.cpp:332
TQString fieldValue(const TQString &label) const
Definition: cardview.cpp:463
void insertField(const TQString &label, const TQString &value)
Adds a field to the card.
Definition: cardview.cpp:378
Field * fieldAt(const TQPoint &itempos) const
Definition: cardview.cpp:549
The CardView is a method of displaying data in cards.
Definition: cardview.h:195
void returnPressed(CardViewItem *)
Emitted when the return key is pressed in an item.
void setDrawColSeparators(bool enabled)
Sets if the column separator should be drawn.
Definition: cardview.cpp:1412
CardViewItem * itemAt(const TQPoint &viewPos) const
Definition: cardview.cpp:667
void setDrawCardBorder(bool enabled)
Sets if the border around a card should be draw.
Definition: cardview.cpp:1399
int separatorWidth() const
Definition: cardview.cpp:1541
void setShowEmptyFields(bool show)
Sets if fields with no value should be drawn (of cause the label only, but it allows for embedded edi...
Definition: cardview.cpp:1438
CardViewItem * itemAfter(const CardViewItem *item) const
Definition: cardview.cpp:954
void setItemSpacing(uint spacing)
Sets the item spacing.
Definition: cardview.cpp:979
void currentChanged(CardViewItem *)
Emitted when the current item changes.
bool drawColSeparators() const
Definition: cardview.cpp:1420
void clear()
Clears the view and deletes all card view items.
Definition: cardview.cpp:624
void setMaxFieldLines(int howmany)
Sets the maximum number of lines to display pr field.
Definition: cardview.cpp:1557
void ensureItemVisible(const CardViewItem *item)
Ensures that the given item is in the viewable area of the widget.
Definition: cardview.cpp:689
void contextMenuRequested(CardViewItem *, const TQPoint &)
Emitted when the context menu is requested in some way.
void setSelectionMode(SelectionMode mode)
Sets the selection mode.
Definition: cardview.cpp:700
CardViewItem * firstItem() const
Definition: cardview.cpp:797
CardViewItem * currentItem() const
Definition: cardview.cpp:631
CardViewItem * findItem(const TQString &text, const TQString &label, TQt::StringComparisonMode compare=TQt::BeginsWith) const
Attempts to find the first item matching the params.
Definition: cardview.cpp:807
void setFont(const TQFont &fnt)
Reimplementation from TQWidget.
Definition: cardview.cpp:1534
TQFont headerFont() const
Definition: cardview.cpp:1529
CardViewItem * selectedItem() const
Definition: cardview.cpp:785
TQRect itemRect(const CardViewItem *item) const
Definition: cardview.cpp:684
void setCurrentItem(CardViewItem *item)
Sets the CardViewItem item to the current item in the view.
Definition: cardview.cpp:639
bool isSelected(CardViewItem *item) const
Definition: cardview.cpp:780
void doubleClicked(CardViewItem *)
Emitted whenever the user double clicks on an item.
void executed(CardViewItem *)
Emitted whenever the user 'executes' an item.
void drawContents(TQPainter *p, int clipx, int clipy, int clipw, int cliph)
Determines which cards intersect that region and tells them to paint themselves.
Definition: cardview.cpp:837
uint columnWidth() const
Returns the amounts of pixels required for one column.
Definition: cardview.cpp:830
void calcLayout()
Does the math based on the bounding rect of the cards to properly lay the cards out on the screen.
Definition: cardview.cpp:894
void contentsWheelEvent(TQWheelEvent *)
Changes the direction the canvas scolls.
Definition: cardview.cpp:1386
void setHeaderFont(const TQFont &fnt)
Sets the header font.
Definition: cardview.cpp:1522
void setSeparatorWidth(int width)
Sets the column separator width.
Definition: cardview.cpp:1546
int maxFieldLines() const
Definition: cardview.cpp:1552
void takeItem(CardViewItem *item)
Takes the item from the view.
Definition: cardview.cpp:615
void setItemMargin(uint margin)
Sets the internal item margin.
Definition: cardview.cpp:965
void setDrawFieldLabels(bool enabled)
Sets if the field labels should be drawn.
Definition: cardview.cpp:1425
void selectAll(bool state)
Selects or deselects all items.
Definition: cardview.cpp:712
uint itemMargin() const
Definition: cardview.cpp:960
bool drawCardBorder() const
Definition: cardview.cpp:1407
void setLayoutDirty(bool dirty)
Sets the layout to dirty and calls for a repaint.
Definition: cardview.cpp:1391
void insertItem(CardViewItem *item)
Inserts the item into the card view.
Definition: cardview.cpp:609
void selectionChanged()
Emitted whenever the selection changes.
void clicked(CardViewItem *)
This method is emitted whenever an item is clicked.
void repaintItem(const CardViewItem *item)
Repaints the given item.
Definition: cardview.cpp:695
void setItemWidth(int width)
Sets the width made available to card items.
Definition: cardview.cpp:1511
void selectionChanged(CardViewItem *)
Same as above method, only it carries the item that was selected.
uint itemSpacing() const
Definition: cardview.cpp:974
void resizeEvent(TQResizeEvent *)
Sets the layout to dirty and repaints.
Definition: cardview.cpp:887
bool drawFieldLabels() const
Definition: cardview.cpp:1433
int childCount() const
Definition: cardview.cpp:802
SelectionMode selectionMode() const
Definition: cardview.cpp:707
int itemWidth() const
Definition: cardview.cpp:1506
bool showEmptyFields() const
Definition: cardview.cpp:1446
void setSelected(CardViewItem *item, bool selected)
Selects or deselects the given item.
Definition: cardview.cpp:737
CardView(TQWidget *parent, const char *name)
Constructor.
Definition: cardview.cpp:572
virtual void startDrag()
Overload this method to be told when a drag should be started.
Definition: cardview.cpp:1451