43 #include <private/qt_cocoa_helpers_mac_p.h> 44 #include <private/qbackingstore_p.h> 45 #include <private/qmainwindowlayout_p.h> 49 #ifdef QT_MAC_USE_COCOA 53 QUnifiedToolbarSurface::QUnifiedToolbarSurface(
QWidget *
widget)
57 d_ptr->inSetGeometry =
false;
62 QUnifiedToolbarSurface::~QUnifiedToolbarSurface()
70 return &d_ptr->image->image;
73 void QUnifiedToolbarSurface::recursiveRedirect(
QObject *
object,
QWidget *parent_toolbar,
const QPoint &offset)
82 widget->d_func()->unifiedSurface =
this;
83 widget->d_func()->isInUnifiedToolbar =
true;
84 widget->d_func()->toolbar_offset = offset;
85 widget->d_func()->toolbar_ancestor = parent_toolbar;
87 for (
int i = 0; i <
object->children().size(); ++i) {
88 recursiveRedirect(object->
children().
at(i), parent_toolbar, offset);
98 recursiveRedirect(toolbar, toolbar, offset);
102 void QUnifiedToolbarSurface::recursiveRemoval(
QObject *
object)
112 widget->d_func()->unifiedSurface = 0;
113 widget->d_func()->isInUnifiedToolbar =
false;
114 widget->d_func()->toolbar_offset =
QPoint();
115 widget->d_func()->toolbar_ancestor = 0;
118 for (
int i = 0; i <
object->children().size(); ++i) {
124 void QUnifiedToolbarSurface::removeToolbar(
QToolBar *toolbar)
126 recursiveRemoval(toolbar);
129 void QUnifiedToolbarSurface::setGeometry(
const QRect &rect)
132 Q_D(QUnifiedToolbarSurface);
133 d->inSetGeometry =
true;
134 if (
d->image == 0 ||
d->image->width() < rect.
width() ||
d->image->height() < rect.
height())
136 d->inSetGeometry =
false;
141 void QUnifiedToolbarSurface::beginPaint(
const QRegion &rgn)
148 p.fillRect(*
it, blank);
152 void QUnifiedToolbarSurface::updateToolbarOffset(
QWidget *widget)
156 mlayout->updateUnifiedToolbarOffset();
169 Q_D(QUnifiedToolbarSurface);
174 if (widget->d_func()->flushRequested)
175 qt_mac_setNeedsDisplay(widget);
180 Q_D(QUnifiedToolbarSurface);
182 int width = geometry().width();
185 width =
qMax(
d->image->width(), width);
186 height =
qMax(
d->image->height(), height);
189 if (width == 0 || height == 0) {
197 d->image =
new QNativeImage(width, height, format,
false, widget);
199 if (oldImage &&
d->inSetGeometry && hasStaticContents()) {
202 uchar *dst =
d->image->image.bits();
205 const int dstBytesPerLine =
d->image->image.bytesPerLine();
208 QRegion staticRegion(staticContents());
212 const QRect *srcRect = rects.constData();
215 int numRectsLeft = rects.
size();
218 const int dy = srcRect->
y();
221 const uchar *s = src + dy * srcBytesPerLine + bytesOffset;
222 uchar *
d = dst + dy * dstBytesPerLine + bytesOffset;
225 int numScanLinesLeft = srcRect->
height();
227 ::memcpy(d, s, numBytes);
228 d += dstBytesPerLine;
229 s += srcBytesPerLine;
230 }
while (--numScanLinesLeft);
233 }
while (--numRectsLeft);
241 Q_D(QUnifiedToolbarSurface);
245 void QUnifiedToolbarSurface::renderToolbar(
QWidget *widget,
bool forceFlush)
247 QWidget *toolbar = widget->d_func()->toolbar_ancestor;
249 updateToolbarOffset(toolbar);
251 QRegion beginPaintRegion(beginPaintRect);
253 beginPaint(beginPaintRegion);
255 toolbar->d_func()->flushRequested =
true;
263 #endif // QT_MAC_USE_COCOA The QPainter class performs low-level painting on widgets and other paint devices.
The QColor class provides colors based on RGB, HSV or CMYK values.
Format
The following image formats are available in Qt.
#define QT_END_NAMESPACE
This macro expands to.
QPointer< QWidget > widget
#define it(className, varName)
static int bytesPerPixel(QImage::Format format)
virtual void setGeometry(const QRect &rect)
Sets the currently allocated area to be the given rect.
int width() const
Returns the width of the rectangle.
int bytesPerLine() const
Returns the number of bytes per image scanline.
int height() const
Returns the height of the rectangle.
T * qobject_cast(QObject *object)
The QObject class is the base class of all Qt objects.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
#define QT_BEGIN_NAMESPACE
This macro expands to.
QSize size() const
Returns the size of the rectangle.
const T & at(int i) const
Returns the item at index position i in the list.
The QImage class provides a hardware-independent image representation that allows direct access to th...
The QRegion class specifies a clip region for a painter.
int depth() const
Returns the depth of the image.
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
int width() const
Returns the width of the image.
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
int y() const
Returns the y-coordinate of the rectangle's top edge.
int x() const
Returns the x-coordinate of the rectangle's left edge.
The QPoint class defines a point in the plane using integer precision.
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
The QRect class defines a rectangle in the plane using integer precision.
const QObjectList & children() const
Returns a list of child objects.
int height() const
Returns the height of the image.
Q_CORE_EXPORT QTextStream & flush(QTextStream &s)
The QSize class defines the size of a two-dimensional object using integer point precision.
int x() const
Returns the x coordinate of this point.
struct CGContext * CGContextRef
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
QTextStream & flush(QTextStream &stream)
Calls QTextStream::flush() on stream and returns stream.