Qt 4.8
Classes | Macros | Functions | Variables
qwidget.cpp File Reference
#include "qapplication.h"
#include "qapplication_p.h"
#include "qbrush.h"
#include "qcursor.h"
#include "qdesktopwidget.h"
#include "qevent.h"
#include "qhash.h"
#include "qlayout.h"
#include "qmenu.h"
#include "qmetaobject.h"
#include "qpixmap.h"
#include "qpointer.h"
#include "qstack.h"
#include "qstyle.h"
#include "qstylefactory.h"
#include "qvariant.h"
#include "qwidget.h"
#include "qstyleoption.h"
#include "qaccessible.h"
#include "qt_windows.h"
#include "qt_mac_p.h"
#include "qt_cocoa_helpers_mac_p.h"
#include "qmainwindow.h"
#include "qtoolbar.h"
#include <private/qmainwindowlayout_p.h>
#include "qwsdisplay_qws.h"
#include "qwsmanager_qws.h"
#include "qpaintengine.h"
#include "private/qwindowsurface_qws_p.h"
#include "qpainter.h"
#include "qtooltip.h"
#include "qwhatsthis.h"
#include "qdebug.h"
#include "private/qstylesheetstyle_p.h"
#include "private/qstyle_p.h"
#include "private/qinputcontext_p.h"
#include "qfileinfo.h"
#include "private/qsoftkeymanager_p.h"
#include <private/qwininputcontext_p.h>
#include <private/qpaintengine_x11_p.h>
#include "qx11info_x11.h"
#include <private/qgraphicseffect_p.h>
#include <private/qwindowsurface_p.h>
#include <private/qbackingstore_p.h>
#include <private/qpaintengine_mac_p.h>
#include <private/qpaintengine_raster_p.h>
#include "qwidget_p.h"
#include "qaction_p.h"
#include "qlayout_p.h"
#include "QtGui/qgraphicsproxywidget.h"
#include "QtGui/qgraphicsscene.h"
#include "private/qgraphicsproxywidget_p.h"
#include "QtGui/qabstractscrollarea.h"
#include "private/qabstractscrollarea_p.h"
#include "private/qevent_p.h"
#include "private/qgraphicssystem_p.h"
#include "private/qgesturemanager_p.h"
#include "moc_qwidget.cpp"

Go to the source code of this file.

Classes

class  QDummyWindowSurface
 
struct  QWidgetExceptionCleaner
 

Macros

#define QT_NO_PAINT_DEBUG
 

Functions

static QString constructWindowTitleFromFilePath (const QString &filePath)
 
static void fillRegion (QPainter *painter, const QRegion &rgn, const QBrush &brush)
 
static bool hasBackingStoreSupport ()
 
static bool qRectIntersects (const QRect &r1, const QRect &r2)
 
QRegion qt_dirtyRegion (QWidget *widget)
 
Q_GUI_EXPORT QWidgetDataqt_qwidget_data (QWidget *widget)
 
bool qt_sendSpontaneousEvent (QObject *, QEvent *)
 
QString qt_setWindowTitle_helperHelper (const QString &title, const QWidget *widget)
 Returns a modified window title with the [*] place holder replaced according to the rules described in QWidget::setWindowTitle. More...
 
Q_GUI_EXPORT QWidgetPrivateqt_widget_private (QWidget *widget)
 
Q_GUI_EXPORT void qt_x11_set_global_double_buffer (bool enable)
 
static void setAttribute_internal (Qt::WidgetAttribute attribute, bool on, QWidgetData *data, QWidgetPrivate *d)
 
void setDisabledStyle (QWidget *w, bool setStyle)
 

Variables

QPointer< QWidgetqt_button_down
 
QDesktopWidgetqt_desktopWidget
 

Macro Definition Documentation

◆ QT_NO_PAINT_DEBUG

#define QT_NO_PAINT_DEBUG

Definition at line 179 of file qwidget.cpp.

Function Documentation

◆ constructWindowTitleFromFilePath()

static QString constructWindowTitleFromFilePath ( const QString filePath)
static

Definition at line 6185 of file qwidget.cpp.

6186 {
6187  QFileInfo fi(filePath);
6188  QString windowTitle = fi.fileName() + QLatin1String("[*]");
6189 #ifndef Q_WS_MAC
6191  if (!appName.isEmpty())
6192  windowTitle += QLatin1Char(' ') + QChar(0x2014) + QLatin1Char(' ') + appName;
6193 #endif
6194  return windowTitle;
6195 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QString appName
static QString applicationName()
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ fillRegion()

static void fillRegion ( QPainter painter,
const QRegion rgn,
const QBrush brush 
)
inlinestatic

Definition at line 2392 of file qwidget.cpp.

Referenced by QWidgetPrivate::paintBackground(), and QVGPaintEngine::vgPrivate().

2393 {
2394  Q_ASSERT(painter);
2395 
2396  if (brush.style() == Qt::TexturePattern) {
2397 #ifdef Q_WS_MAC
2398  // Optimize pattern filling on mac by using HITheme directly
2399  // when filling with the standard widget background.
2400  // Defined in qmacstyle_mac.cpp
2401  extern void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush);
2402  qt_mac_fill_background(painter, rgn, brush);
2403 #else
2404 #if !defined(QT_NO_STYLE_S60)
2405  // Defined in qs60style.cpp
2406  extern bool qt_s60_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush);
2407  if (!qt_s60_fill_background(painter, rgn, brush))
2408 #endif // !defined(QT_NO_STYLE_S60)
2409  {
2410  const QRect rect(rgn.boundingRect());
2411  painter->setClipRegion(rgn);
2412  painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft());
2413  }
2414 #endif // Q_WS_MAC
2415 
2416  } else if (brush.gradient()
2418  painter->save();
2419  painter->setClipRegion(rgn);
2420  painter->fillRect(0, 0, painter->device()->width(), painter->device()->height(), brush);
2421  painter->restore();
2422  } else {
2423  const QVector<QRect> &rects = rgn.rects();
2424  for (int i = 0; i < rects.size(); ++i)
2425  painter->fillRect(rects.at(i), brush);
2426  }
2427 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or 0 if the painter is not acti...
Definition: qpainter.cpp:1530
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
CoordinateMode coordinateMode() const
Returns the coordinate mode of this gradient.
Definition: qbrush.cpp:1563
int height() const
Definition: qpaintdevice.h:92
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
int width() const
Definition: qpaintdevice.h:91
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
QPixmap texture() const
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set...
Definition: qbrush.cpp:785
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
void drawTiledPixmap(const QRectF &rect, const QPixmap &pm, const QPointF &offset=QPointF())
Draws a tiled pixmap, inside the given rectangle with its origin at the given position.
Definition: qpainter.cpp:7146
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
void setClipRegion(const QRegion &, Qt::ClipOperation op=Qt::ReplaceClip)
Sets the clip region to the given region using the specified clip operation.
Definition: qpainter.cpp:2917
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ hasBackingStoreSupport()

static bool hasBackingStoreSupport ( )
inlinestatic

Definition at line 169 of file qwidget.cpp.

Referenced by QWidget::create(), QWidget::repaint(), and QWidget::update().

170 {
171 #ifdef Q_WS_MAC
173 #else
174  return true;
175 #endif
176 }
static QGraphicsSystem * graphicsSystem()

◆ qRectIntersects()

static bool qRectIntersects ( const QRect r1,
const QRect r2 
)
inlinestatic

Definition at line 163 of file qwidget.cpp.

Referenced by QWidgetPrivate::clipRegion(), QWidgetPrivate::isOverlapped(), QWidgetPrivate::paintSiblingsRecursive(), and QWidgetPrivate::subtractOpaqueSiblings().

164 {
165  return (qMax(r1.left(), r2.left()) <= qMin(r1.right(), r2.right()) &&
166  qMax(r1.top(), r2.top()) <= qMin(r1.bottom(), r2.bottom()));
167 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246

◆ qt_dirtyRegion()

QRegion qt_dirtyRegion ( QWidget widget)

Definition at line 1111 of file qwidget.cpp.

Referenced by QWidgetBackingStore::hasStaticContents(), and QETWidget::translatePaintEvent().

1112 {
1113  if (!widget)
1114  return QRegion();
1115 
1117  if (!bs)
1118  return QRegion();
1119 
1120  return bs->dirtyRegion(widget);
1121 }
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
Q_GUI_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
Definition: qwidget.cpp:12920
QRegion dirtyRegion(QWidget *widget=0) const
Returns the region (in top-level coordinates) that needs repaint and/or flush.
QWidgetBackingStore * maybeBackingStore() const
Definition: qwidget_p.h:1036

◆ qt_qwidget_data()

Q_GUI_EXPORT QWidgetData* qt_qwidget_data ( QWidget widget)

◆ qt_sendSpontaneousEvent()

bool qt_sendSpontaneousEvent ( QObject ,
QEvent  
)

Definition at line 5779 of file qapplication.cpp.

5780 {
5782 }
EventRef event
static bool sendSpontaneousEvent(QObject *receiver, QEvent *event)

◆ qt_setWindowTitle_helperHelper()

QString qt_setWindowTitle_helperHelper ( const QString title,
const QWidget widget 
)

Returns a modified window title with the [*] place holder replaced according to the rules described in QWidget::setWindowTitle.

This function assumes that "[*]" can be quoted by another "[*]", so it will replace two place holders by one and a single last one by either "*" or nothing depending on the modified flag.

Warning
This function is not part of the public interface.

Definition at line 6240 of file qwidget.cpp.

Referenced by QDockWidget::changeEvent(), QMdiSubWindowPrivate::getOperation(), QAccessibleWidget::indexOfChild(), QDockWidgetPrivate::init(), QWorkspaceTitleBar::isTool(), QDecorationDefault::paintButton(), QWorkspaceTitleBar::paintEvent(), QWidgetPrivate::setWindowIconText_helper(), QWidgetPrivate::setWindowTitle_helper(), tabTextFor(), QAccessibleWidget::text(), QMdiSubWindowPrivate::updateInternalWindowTitle(), and QDecorationDefault::windowTitleFor().

6241 {
6242  Q_ASSERT(widget);
6243 
6244 #ifdef QT_EVAL
6245  extern QString qt_eval_adapt_window_title(const QString &title);
6246  QString cap = qt_eval_adapt_window_title(title);
6247 #else
6248  QString cap = title;
6249 #endif
6250 
6251  if (cap.isEmpty())
6252  return cap;
6253 
6254  QLatin1String placeHolder("[*]");
6255  int placeHolderLength = 3; // QLatin1String doesn't have length()
6256 
6257  int index = cap.indexOf(placeHolder);
6258 
6259  // here the magic begins
6260  while (index != -1) {
6261  index += placeHolderLength;
6262  int count = 1;
6263  while (cap.indexOf(placeHolder, index) == index) {
6264  ++count;
6265  index += placeHolderLength;
6266  }
6267 
6268  if (count%2) { // odd number of [*] -> replace last one
6269  int lastIndex = cap.lastIndexOf(placeHolder, index - 1);
6270  if (widget->isWindowModified()
6271  && widget->style()->styleHint(QStyle::SH_TitleBar_ModifyNotification, 0, widget))
6272  cap.replace(lastIndex, 3, QWidget::tr("*"));
6273  else
6274  cap.remove(lastIndex, 3);
6275  }
6276 
6277  index = cap.indexOf(placeHolder, index);
6278  }
6279 
6280  cap.replace(QLatin1String("[*][*]"), placeHolder);
6281 
6282  return cap;
6283 }
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QStyle * style() const
Definition: qwidget.cpp:2742
bool isWindowModified() const
Definition: qwidget.cpp:11554
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
quint16 index
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867

◆ qt_widget_private()

Q_GUI_EXPORT QWidgetPrivate* qt_widget_private ( QWidget widget)

◆ qt_x11_set_global_double_buffer()

Q_GUI_EXPORT void qt_x11_set_global_double_buffer ( bool  enable)

Definition at line 153 of file qwidget.cpp.

154 {
155  qt_enable_backingstore = enable;
156 }

◆ setAttribute_internal()

static void setAttribute_internal ( Qt::WidgetAttribute  attribute,
bool  on,
QWidgetData data,
QWidgetPrivate d 
)
static
Warning
This function is not part of the public interface.

This just sets the corresponding attribute bit to 1 or 0

Definition at line 11063 of file qwidget.cpp.

Referenced by QWidget::setAttribute().

11065 {
11066  if (attribute < int(8*sizeof(uint))) {
11067  if (on)
11068  data->widget_attributes |= (1<<attribute);
11069  else
11070  data->widget_attributes &= ~(1<<attribute);
11071  } else {
11072  const int x = attribute - 8*sizeof(uint);
11073  const int int_off = x / (8*sizeof(uint));
11074  if (on)
11075  d->high_attributes[int_off] |= (1<<(x-(int_off*8*sizeof(uint))));
11076  else
11077  d->high_attributes[int_off] &= ~(1<<(x-(int_off*8*sizeof(uint))));
11078  }
11079 }
uint widget_attributes
Definition: qwidget.h:118
unsigned int uint
Definition: qglobal.h:996
uint high_attributes[4]
Definition: qwidget_p.h:767

◆ setDisabledStyle()

void setDisabledStyle ( QWidget w,
bool  setStyle 
)
inline

Definition at line 8586 of file qwidget.cpp.

Referenced by QWidget::event().

8587 {
8588  // set/reset WS_DISABLED style.
8589  if(w && w->isWindow() && w->isVisible() && w->isEnabled()) {
8590  LONG dwStyle = GetWindowLong(w->winId(), GWL_STYLE);
8591  LONG newStyle = dwStyle;
8592  if (setStyle)
8593  newStyle |= WS_DISABLED;
8594  else
8595  newStyle &= ~WS_DISABLED;
8596  if (newStyle != dwStyle) {
8597  SetWindowLong(w->winId(), GWL_STYLE, newStyle);
8598  // we might need to repaint in some situations (eg. menu)
8599  w->repaint();
8600  }
8601  }
8602 }
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
bool isVisible() const
Definition: qwidget.h:1005
bool isEnabled() const
Definition: qwidget.h:948
void repaint()
Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the ...
Definition: qwidget.cpp:10761
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557

Variable Documentation

◆ qt_button_down

QPointer<QWidget> qt_button_down

Definition at line 188 of file qapplication_mac.mm.

Referenced by QWidgetPrivate::paintBackground().

◆ qt_desktopWidget

QDesktopWidget* qt_desktopWidget

Definition at line 560 of file qapplication.cpp.

Referenced by QApplication::desktop(), and QApplication::~QApplication().