summaryrefslogtreecommitdiffstats
path: root/ksysv/kscroller.h
blob: bc59b69b5c086b3d385192df46c1352402318b96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// (c) 2000 Peter Putzer
#ifndef KSCROLLER_H
#define KSCROLLER_H

#include <tqframe.h>

class TQScrollBar;

/**
 * A window that automatically enables scrollbars
 * if it's smaller than the content.
 *
 * @author Peter Putzer <putzer@kde.org>
 * @version $Id$
 */
class KScroller : public TQFrame
{
  TQ_OBJECT
  

public:
  /**
   * Constructor.
   *
   * @param parent the parent of this widget (passed on as ususal).
   * @param name the name of this widget (as above).
   */
  KScroller (TQWidget* parent = 0L, const char* name = 0L);

  /** 
   * Destructor.
   */
  virtual ~KScroller ();

  /**
   * @return the vertical scrollbar.
   */
  inline TQScrollBar* verticalScrollBar () { return mVertical; }

  /**
   * @return the horizontal scrollbar.
   */
  inline TQScrollBar* horizontalScrollBar () { return mHorizontal; }

  /**
   * @return the current content, or 0L if none set.
   */
  inline TQWidget* content () { return mContent; }

  /**
   * @return the current corner widget, or 0L if none set.
   */
  TQWidget* cornerWidget ();

public slots:
  /**
   * Sets the content. Ownership is transfered to the scroller, any
   * previously set content will be deleted!
   * 
   * @param content has to be a child of the KScroller.
   */
  void setContent (TQWidget* content);

  /**
   * Sets the corner widget (the small widget that's located where the vertical and horizontal scrollbars
   * allmost meet).
   *
   * @param corner has to be a child of the KScroller.
   */
  void setCornerWidget (TQWidget* corner);

  /**
   * Update the scrollbars. Call whenever you change the contents minimumSize.
   */
  void updateScrollBars ();

protected:
  /**
   * Reimplemented for internal reasons, the API is not affected.
   */
  virtual void resizeEvent (TQResizeEvent*);

  /**
   * Reimplemented for internal reasons, the API is not affected.
   */
  virtual TQSize sizeHint() const;

  /**
   * Reimplemented for internal reasons, the API is not affected.
   */
  virtual TQSize minimumSizeHint() const;


private slots:
  /**
   * Scroll vertically.
   *
   * @param value is the new slider value.
   */
  void scrollVertical (int value);

  /**
   * Scroll horizontally.
   *
   * @param value is the new slider value.
   */
  void scrollHorizontal (int value);

private:
  /**
   * Set up the horizontal scrollbar.
   *
   * @param cw is the width of the content.
   * @param ch is the height of the content.
   * @param w is the width of the scroller.
   * @param h is the height of the scroller.
   */
  void setupHorizontal (int cw, int ch, int w, int h);

  /**
   * Set up the vertical scrollbar
   *
   * @param cw is the width of the content.
   * @param ch is the height of the content.
   * @param w is the width of the scroller.
   * @param h is the height of the scroller.
   */
  void setupVertical (int cw, int ch, int w, int h);

  /**
   * Set up the corner widget.
   *
   * @param w is the width of the scroller.
   * @param h is the height of the scroller.
   */
  void setupCornerWidget (int w, int h);

  class KScrollerPrivate;
  KScrollerPrivate* d;

  TQScrollBar* mVertical;
  TQScrollBar* mHorizontal;
  TQWidget* mCornerWidget;

  TQWidget* mContent;
  
  int mVerticalOld;
  int mHorizontalOld;
};

#endif // KSCROLLER_H