Qt 4.8
Classes | Namespaces | Macros | Functions | Variables
qmdisubwindow.cpp File Reference
#include "qmdisubwindow_p.h"
#include <QApplication>
#include <QStylePainter>
#include <QVBoxLayout>
#include <QMouseEvent>
#include <QWhatsThis>
#include <QToolTip>
#include <QMainWindow>
#include <QScrollBar>
#include <QDebug>
#include <QScopedValueRollback>
#include <QMacStyle>
#include <QMdiArea>
#include "moc_qmdisubwindow.cpp"
#include "qmdisubwindow.moc"

Go to the source code of this file.

Classes

class  QMdi::ControlLabel
 
class  QMdi::ControllerWidget
 

Namespaces

 QMdi
 

Macros

#define COLOR_GRADIENTACTIVECAPTION   27
 
#define COLOR_GRADIENTINACTIVECAPTION   28
 
#define SPI_GETGRADIENTCAPTIONS   0x1008
 

Functions

static QRgb colorref2qrgb (COLORREF col)
 
static int getMoveDeltaComponent (uint cflags, uint moveFlag, uint resizeFlag, int delta, int maxDelta, int minDelta)
 
static int getResizeDeltaComponent (uint cflags, uint resizeFlag, uint resizeReverseFlag, int delta)
 
static bool isChildOfQMdiSubWindow (const QWidget *child)
 
static bool isChildOfTabbedQMdiArea (const QMdiSubWindow *child)
 
static bool isHoverControl (QStyle::SubControl control)
 
template<typename T >
static ControlElement< T > * ptr (QWidget *widget)
 
QString qt_setWindowTitle_helperHelper (const QString &, const QWidget *)
 Returns a modified window title with the [*] place holder replaced according to the rules described in QWidget::setWindowTitle. More...
 
static void showToolTip (QHelpEvent *helpEvent, QWidget *widget, const QStyleOptionComplex &opt, QStyle::ComplexControl complexControl, QStyle::SubControl subControl)
 

Variables

static const int BoundaryMargin = 5
 
static const QStyle::StandardPixmap ButtonPixmaps []
 
static const Qt::WindowFlags CustomizeWindowFlags
 
static const int NumButtonPixmaps = sizeof(ButtonPixmaps) / sizeof(ButtonPixmaps[0])
 
static const int NumSubControls = sizeof(SubControls) / sizeof(SubControls[0])
 
static const QStyle::SubControl SubControls []
 

Macro Definition Documentation

◆ COLOR_GRADIENTACTIVECAPTION

#define COLOR_GRADIENTACTIVECAPTION   27

◆ COLOR_GRADIENTINACTIVECAPTION

#define COLOR_GRADIENTINACTIVECAPTION   28

◆ SPI_GETGRADIENTCAPTIONS

#define SPI_GETGRADIENTCAPTIONS   0x1008

Function Documentation

◆ colorref2qrgb()

static QRgb colorref2qrgb ( COLORREF  col)
inlinestatic

Definition at line 306 of file qmdisubwindow.cpp.

Referenced by QMdiSubWindowPrivate::desktopPalette().

307 {
308  return qRgb(GetRValue(col),GetGValue(col),GetBValue(col));
309 }
QRgb qRgb(int r, int g, int b)
Returns the ARGB quadruplet (255, {r}, {g}, {b}).
Definition: qrgb.h:69

◆ getMoveDeltaComponent()

static int getMoveDeltaComponent ( uint  cflags,
uint  moveFlag,
uint  resizeFlag,
int  delta,
int  maxDelta,
int  minDelta 
)
inlinestatic

Definition at line 219 of file qmdisubwindow.cpp.

Referenced by QMdiSubWindowPrivate::setNewGeometry().

221 {
222  if (cflags & moveFlag) {
223  if (delta > 0)
224  return (cflags & resizeFlag) ? qMin(delta, maxDelta) : delta;
225  return (cflags & resizeFlag) ? qMax(delta, minDelta) : delta;
226  }
227  return 0;
228 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217

◆ getResizeDeltaComponent()

static int getResizeDeltaComponent ( uint  cflags,
uint  resizeFlag,
uint  resizeReverseFlag,
int  delta 
)
inlinestatic

Definition at line 230 of file qmdisubwindow.cpp.

Referenced by QMdiSubWindowPrivate::setNewGeometry().

232 {
233  if (cflags & resizeFlag) {
234  if (cflags & resizeReverseFlag)
235  return -delta;
236  return delta;
237  }
238  return 0;
239 }

◆ isChildOfQMdiSubWindow()

static bool isChildOfQMdiSubWindow ( const QWidget child)
inlinestatic

Definition at line 241 of file qmdisubwindow.cpp.

Referenced by QMdiSubWindowPrivate::drawTitleBarWhenMaximized().

242 {
243  Q_ASSERT(child);
244  QWidget *parent = child->parentWidget();
245  while (parent) {
246  if (qobject_cast<QMdiSubWindow *>(parent))
247  return true;
248  parent = parent->parentWidget();
249  }
250  return false;
251 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ isChildOfTabbedQMdiArea()

static bool isChildOfTabbedQMdiArea ( const QMdiSubWindow child)
inlinestatic

Definition at line 253 of file qmdisubwindow.cpp.

Referenced by QMdiSubWindowPrivate::drawTitleBarWhenMaximized(), QMdiSubWindow::maximizedButtonsWidget(), QMdiSubWindow::maximizedSystemMenuIconWidget(), QMdiSubWindowPrivate::menuBar(), QMdiSubWindowPrivate::removeButtonsFromMenuBar(), and QMdiSubWindowPrivate::showButtonsInMenuBar().

254 {
255  Q_ASSERT(child);
256  if (QMdiArea *mdiArea = child->mdiArea()) {
257  if (mdiArea->viewMode() == QMdiArea::TabbedView)
258  return true;
259  }
260  return false;
261 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QMdiArea widget provides an area in which MDI windows are displayed.
Definition: qmdiarea.h:59
QMdiArea * mdiArea() const
Returns the area containing this sub-window, or 0 if there is none.

◆ isHoverControl()

static bool isHoverControl ( QStyle::SubControl  control)
inlinestatic

Definition at line 300 of file qmdisubwindow.cpp.

Referenced by QMdiSubWindow::mouseMoveEvent().

301 {
302  return control != QStyle::SC_None && control != QStyle::SC_TitleBarLabel;
303 }

◆ ptr()

template<typename T >
static ControlElement<T>* ptr ( QWidget widget)
inlinestatic

Definition at line 264 of file qmdisubwindow.cpp.

265 {
266  if (widget && widget->qt_metacast("ControlElement")
267  && strcmp(widget->metaObject()->className(), T::staticMetaObject.className()) == 0) {
268  return static_cast<ControlElement<T> *>(widget);
269  }
270  return 0;
271 }
QPointer< QWidget > widget
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ 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 QMdiSubWindowPrivate::getOperation(), and QMdiSubWindowPrivate::updateInternalWindowTitle().

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

◆ showToolTip()

static void showToolTip ( QHelpEvent helpEvent,
QWidget widget,
const QStyleOptionComplex opt,
QStyle::ComplexControl  complexControl,
QStyle::SubControl  subControl 
)
static

Definition at line 313 of file qmdisubwindow.cpp.

Referenced by QMdiSubWindow::event(), QApplication::event(), QMdi::ControlLabel::event(), QMdi::ControllerWidget::event(), and QScriptToolTipProviderInterface::~QScriptToolTipProviderInterface().

315 {
316  Q_ASSERT(helpEvent);
317  Q_ASSERT(helpEvent->type() == QEvent::ToolTip);
318  Q_ASSERT(widget);
319 
320 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
321  // Native Mac windows don't show tool tip.
322  if (qobject_cast<QMacStyle *>(widget->style()))
323  return;
324 #endif
325 
326  // Convert CC_MdiControls to CC_TitleBar. Sub controls of different complex
327  // controls cannot be in the same switch as they might have the same value.
328  if (complexControl == QStyle::CC_MdiControls) {
329  if (subControl == QStyle::SC_MdiMinButton)
330  subControl = QStyle::SC_TitleBarMinButton;
331  else if (subControl == QStyle::SC_MdiCloseButton)
332  subControl = QStyle::SC_TitleBarCloseButton;
333  else if (subControl == QStyle::SC_MdiNormalButton)
334  subControl = QStyle::SC_TitleBarNormalButton;
335  else
336  subControl = QStyle::SC_None;
337  }
338 
339  // Don't change the tooltip for the base widget itself.
340  if (subControl == QStyle::SC_None)
341  return;
342 
343  QString toolTip;
344 
345  switch (subControl) {
347  toolTip = QMdiSubWindow::tr("Minimize");
348  break;
350  toolTip = QMdiSubWindow::tr("Maximize");
351  break;
353  toolTip = QMdiSubWindow::tr("Unshade");
354  break;
356  toolTip = QMdiSubWindow::tr("Shade");
357  break;
359  if (widget->isMaximized() || !qobject_cast<QMdiSubWindow *>(widget))
360  toolTip = QMdiSubWindow::tr("Restore Down");
361  else
362  toolTip = QMdiSubWindow::tr("Restore");
363  break;
365  toolTip = QMdiSubWindow::tr("Close");
366  break;
368  toolTip = QMdiSubWindow::tr("Help");
369  break;
371  toolTip = QMdiSubWindow::tr("Menu");
372  break;
373  default:
374  break;
375  }
376 
377  const QRect rect = widget->style()->subControlRect(complexControl, &opt, subControl, widget);
378  QToolTip::showText(helpEvent->globalPos(), toolTip, widget, rect);
379 }
QPointer< QWidget > widget
virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget=0) const =0
Returns the rectangle containing the specified subControl of the given complex control (with the styl...
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QStyle * style() const
Definition: qwidget.cpp:2742
bool isMaximized() const
Definition: qwidget.cpp:3074
const QPoint & globalPos() const
Returns the mouse cursor position when the event was generated in global coordinates.
Definition: qevent.h:598
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
The QMdiSubWindow class provides a subwindow class for QMdiArea.
Definition: qmdisubwindow.h:60
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtooltip.cpp:497

Variable Documentation

◆ BoundaryMargin

const int BoundaryMargin = 5
static

Definition at line 217 of file qmdisubwindow.cpp.

Referenced by QMdiSubWindowPrivate::setNewGeometry().

◆ ButtonPixmaps

const QStyle::StandardPixmap ButtonPixmaps[]
static

◆ CustomizeWindowFlags

const Qt::WindowFlags CustomizeWindowFlags
static

◆ NumButtonPixmaps

const int NumButtonPixmaps = sizeof(ButtonPixmaps) / sizeof(ButtonPixmaps[0])
static

Definition at line 205 of file qmdisubwindow.cpp.

◆ NumSubControls

const int NumSubControls = sizeof(SubControls) / sizeof(SubControls[0])
static

◆ SubControls

const QStyle::SubControl SubControls[]
static