source: trunk/src/kernel/qinternal_p.h@ 154

Last change on this file since 154 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 5.6 KB
Line 
1/****************************************************************************
2** $Id: qinternal_p.h 2 2005-11-16 15:49:26Z dmik $
3**
4** Definition of some shared interal classes
5**
6** Created : 010427
7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the kernel module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#ifndef QINTERNAL_P_H
39#define QINTERNAL_P_H
40
41//
42// W A R N I N G
43// -------------
44//
45// This file is not part of the Qt API. It exists for the convenience
46// of a number of Qt sources files. This header file may change from
47// version to version without notice, or even be removed.
48//
49// We mean it.
50//
51//
52#ifndef QT_H
53#include "qnamespace.h"
54#include "qrect.h"
55#include "qptrlist.h"
56#include "qcstring.h"
57#include "qiodevice.h"
58#endif // QT_H
59
60class QWidget;
61class QPainter;
62class QPixmap;
63
64class Q_EXPORT QSharedDoubleBuffer
65{
66public:
67 enum DoubleBufferFlags {
68 NoFlags = 0x00,
69 InitBG = 0x01,
70 Force = 0x02,
71 Default = InitBG | Force
72 };
73 typedef uint DBFlags;
74
75 QSharedDoubleBuffer( DBFlags f = Default );
76 QSharedDoubleBuffer( QWidget* widget,
77 int x = 0, int y = 0, int w = -1, int h = -1,
78 DBFlags f = Default );
79 QSharedDoubleBuffer( QPainter* painter,
80 int x = 0, int y = 0, int w = -1, int h = -1,
81 DBFlags f = Default );
82 QSharedDoubleBuffer( QWidget *widget, const QRect &r, DBFlags f = Default );
83 QSharedDoubleBuffer( QPainter *painter, const QRect &r, DBFlags f = Default );
84 ~QSharedDoubleBuffer();
85
86 bool begin( QWidget* widget, int x = 0, int y = 0, int w = -1, int h = -1 );
87 bool begin( QPainter* painter, int x = 0, int y = 0, int w = -1, int h = -1);
88 bool begin( QWidget* widget, const QRect &r );
89 bool begin( QPainter* painter, const QRect &r );
90 bool end();
91
92 QPainter* painter() const;
93
94 bool isActive() const;
95 bool isBuffered() const;
96 void flush();
97
98 static bool isDisabled() { return !dblbufr; }
99 static void setDisabled( bool off ) { dblbufr = !off; }
100
101 static void cleanup();
102
103private:
104 enum DoubleBufferState {
105 Active = 0x0100,
106 BufferActive = 0x0200,
107 ExternalPainter = 0x0400
108 };
109 typedef uint DBState;
110
111 QPixmap *getPixmap();
112 void releasePixmap();
113
114 QWidget *wid;
115 int rx, ry, rw, rh;
116 DBFlags flags;
117 DBState state;
118
119 QPainter *p, *external_p;
120 QPixmap *pix;
121
122 static bool dblbufr;
123};
124
125inline bool QSharedDoubleBuffer::begin( QWidget* widget, const QRect &r )
126{ return begin( widget, r.x(), r.y(), r.width(), r.height() ); }
127
128inline bool QSharedDoubleBuffer::begin( QPainter *painter, const QRect &r )
129{ return begin( painter, r.x(), r.y(), r.width(), r.height() ); }
130
131inline QPainter* QSharedDoubleBuffer::painter() const
132{ return p; }
133
134inline bool QSharedDoubleBuffer::isActive() const
135{ return ( state & Active ); }
136
137inline bool QSharedDoubleBuffer::isBuffered() const
138{ return ( state & BufferActive ); }
139
140
141class QVirtualDestructor {
142public:
143 virtual ~QVirtualDestructor() {}
144};
145
146template <class T>
147class QAutoDeleter : public QVirtualDestructor {
148public:
149 QAutoDeleter( T* p ) : ptr( p ) {}
150 ~QAutoDeleter() { delete ptr; }
151 T* data() const { return ptr; }
152private:
153 T* ptr;
154};
155
156template <class T>
157T* qAutoDeleterData( QAutoDeleter<T>* ad )
158{
159 if ( !ad )
160 return 0;
161 return ad->data();
162}
163
164template <class T>
165QAutoDeleter<T>* qAutoDeleter( T* p )
166{
167 return new QAutoDeleter<T>( p );
168}
169
170class Q_EXPORT QMembuf
171{
172public:
173 QMembuf();
174 ~QMembuf();
175
176 void append( QByteArray *ba );
177 void clear();
178
179 bool consumeBytes( Q_ULONG nbytes, char *sink );
180 QByteArray readAll();
181 bool scanNewline( QByteArray *store );
182 bool canReadLine() const;
183
184 int ungetch( int ch );
185
186 QIODevice::Offset size() const;
187
188private:
189
190 QPtrList<QByteArray> *buf;
191 QIODevice::Offset _size;
192 QIODevice::Offset _index;
193};
194
195inline void QMembuf::append( QByteArray *ba )
196{ buf->append( ba ); _size += ba->size(); }
197
198inline void QMembuf::clear()
199{ buf->clear(); _size=0; _index=0; }
200
201inline QByteArray QMembuf::readAll()
202{ QByteArray ba(_size); consumeBytes(_size,ba.data()); return ba; }
203
204inline bool QMembuf::canReadLine() const
205{ return ((QMembuf*)this)->scanNewline( 0 ); }
206
207inline QIODevice::Offset QMembuf::size() const
208{ return _size; }
209
210#endif // QINTERNAL_P_H
Note: See TracBrowser for help on using the repository browser.