libyui-qt  2.49.2
YQLogView.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQLogView.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef YQLogView_h
27 #define YQLogView_h
28 
29 #include <QFrame>
30 #include <QTextEdit>
31 
32 #include <yui/YLogView.h>
33 
34 class YQWidgetCaption;
35 class MyTextEdit;
36 
37 
38 
39 class YQLogView : public QFrame, public YLogView
40 {
41  Q_OBJECT
42 
43 public:
44 
45  /**
46  * Constructor
47  **/
48  YQLogView( YWidget * parent,
49  const std::string & label,
50  int visibleLines,
51  int maxLines );
52 
53  /**
54  * Destructor.
55  **/
56  virtual ~YQLogView();
57 
58 protected:
59  /**
60  * Display the part of the log text that should be displayed.
61  * 'text' contains the last 'visibleLines()' lines.
62  * This is called whenever the log text changes. Note that the text might
63  * also be empty, in which case the displayed log text should be cleared.
64  *
65  * Implemented from YLogView.
66  **/
67  virtual void displayLogText( const std::string & text );
68 
69 public:
70 
71  /**
72  * Set the label (the caption above the log text).
73  *
74  * Reimplemented from YLogView.
75  **/
76  virtual void setLabel( const std::string & label );
77 
78  /**
79  * Set enabled/disabled state.
80  *
81  * Reimplemented from YWidget.
82  **/
83  virtual void setEnabled( bool enabled );
84 
85  /**
86  * Preferred width of the widget.
87  *
88  * Reimplemented from YWidget.
89  **/
90  virtual int preferredWidth();
91 
92  /**
93  * Preferred height of the widget.
94  *
95  * Reimplemented from YWidget.
96  **/
97  virtual int preferredHeight();
98 
99  /**
100  * Set the new size of the widget.
101  *
102  * Reimplemented from YWidget.
103  **/
104  virtual void setSize( int newWidth, int newHeight );
105 
106  /**
107  * Accept the keyboard focus.
108  **/
109  virtual bool setKeyboardFocus();
110 
111 
112 protected:
113 
114  YQWidgetCaption * _caption;
115  MyTextEdit * _qt_text;
116  QString _lastText;
117 
118 private slots:
119  void slotResize();
120 
121 };
122 
123 
124 // We need a resize event in order to set the cursor to the last line
125 // for the auto-scroll feature
126 class MyTextEdit : public QTextEdit
127 {
128  Q_OBJECT
129  public:
130  MyTextEdit( QWidget* parent ) : QTextEdit (parent) {}
131 
132  protected:
133  void resizeEvent ( QResizeEvent * event )
134  { emit resized();
135  QTextEdit::resizeEvent(event);
136  }
137 
138  signals:
139  void resized();
140 
141 };
142 
143 
144 #endif // YQLogView_h
virtual void displayLogText(const std::string &text)
Display the part of the log text that should be displayed.
Definition: YQLogView.cc:81
YQLogView(YWidget *parent, const std::string &label, int visibleLines, int maxLines)
Constructor.
Definition: YQLogView.cc:41
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQLogView.cc:137
virtual bool setKeyboardFocus()
Accept the keyboard focus.
Definition: YQLogView.cc:179
virtual void setLabel(const std::string &label)
Set the label (the caption above the log text).
Definition: YQLogView.cc:119
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Definition: YQLogView.cc:128
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQLogView.cc:144
virtual ~YQLogView()
Destructor.
Definition: YQLogView.cc:74
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQLogView.cc:172
Helper class for captions (labels) above a widget: Takes care of hiding itself when its text is empty...