Qt 4.8
qdecoration_qws.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qdecoration_qws.h"
43 
44 #include "qapplication.h"
45 #include "qdrawutil.h"
46 #include "qpainter.h"
47 #include "qregion.h"
48 #include "qwhatsthis.h"
49 
50 #include "qmenu.h"
51 #include "private/qwidget_p.h"
52 #include "qwsmanager_qws.h"
53 
55 
236 int QDecoration::regionAt(const QWidget *w, const QPoint &point)
237 {
238  int regions[] = {
239  TopLeft, Top, TopRight, Left, Right, BottomLeft, Bottom, BottomRight, // Borders first
240  Menu, Title, Help, Minimize, Normalize, Maximize, Close, // then buttons
241  None
242  };
243 
244 // char *regions_str[] = {
245 // "TopLeft", "Top", "TopRight", "Left", "Right", "BottomLeft", "Bottom", "BottomRight",
246 // "Menu", "Title", "Help", "Minimize", "Normalize", "Maximize", "Close",
247 // "None"
248 // };
249 
250  // First check to see if within all regions at all
251  QRegion reg = region(w, w->geometry(), All);
252  if (!reg.contains(point)) {
253  return None;
254  }
255 
256  int i = 0;
257  while (regions[i]) {
258  reg = region(w, w->geometry(), regions[i]);
259  if (reg.contains(point)) {
260 // qDebug("In region %s", regions_str[i]);
261  return regions[i];
262  }
263  ++i;
264  }
265  return None;
266 }
267 
268 #ifndef QT_NO_MENU
269 
277 {
278  QDecorationAction *act = new QDecorationAction(QLatin1String("Restore"),
279  menu, Maximize);
280  act->setEnabled(widget->windowState() & Qt::WindowMaximized);
281  menu->addAction(act);
282  act = new QDecorationAction(QLatin1String("Move"), menu, Move);
283  act->setEnabled(!(widget->windowState() & Qt::WindowMaximized));
284  menu->addAction(act);
285  menu->addAction(new QDecorationAction(QLatin1String("Size"), menu, Resize));
286  act = new QDecorationAction(QLatin1String("Minimize"), menu, Minimize);
287  menu->addAction(act);
288  act = new QDecorationAction(QLatin1String("Maximize"), menu, Maximize);
289  act->setDisabled(widget->windowState() & Qt::WindowMaximized);
290  menu->addAction(act);
291  menu->addSeparator();
292  menu->addAction(new QDecorationAction(QLatin1String("Close"), menu, Close));
293 }
294 
303 {
304  QDecorationAction *decAction = static_cast<QDecorationAction *>(action);
305  regionClicked(widget, decAction->reg);
306 }
307 #endif // QT_NO_MENU
308 
323 {
324  switch(reg) {
325  case Move:
326  startMove(widget);
327  break;
328  case Resize:
329  startResize(widget);
330  break;
331  case Help:
332 #ifndef QT_NO_WHATSTHIS
335  else
337 #endif
338  break;
339  case Close:
340  widget->close();
341  break;
342  case Normalize:
343  widget->showNormal();
344  break;
345  case Maximize:
346  if (widget->windowState() & Qt::WindowMaximized)
347  widget->showNormal();
348  else
349  widget->showMaximized();
350  break;
351  }
352 }
353 
369 {
370  switch(reg)
371  {
372  case Title: {
373  if (widget->windowState() & Qt::WindowMaximized)
374  widget->showNormal();
375  else
376  widget->showMaximized();
377  break;
378  }
379  }
380 }
381 
388 {
389 #ifdef QT_NO_QWS_MANAGER
390  Q_UNUSED(widget);
391 #else
392  QWSManager *manager = widget->d_func()->topData()->qwsManager;
393  if (manager)
394  manager->startMove();
395 #endif
396 }
397 
404 {
405 #ifdef QT_NO_QWS_MANAGER
406  Q_UNUSED(widget);
407 #else
408  QWSManager *manager = widget->d_func()->topData()->qwsManager;
409  if (manager)
410  manager->startResize();
411 #endif
412 }
413 
414 
void showMaximized()
Shows the widget maximized.
Definition: qwidget.cpp:3218
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
Qt::WindowStates windowState() const
Returns the current window state.
Definition: qwidget.cpp:3086
virtual int regionAt(const QWidget *w, const QPoint &point)
Returns the type of the first region of the specified top level widget containing the given point...
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void setDisabled(bool b)
This is a convenience function for the enabled property, that is useful for signals–slots connection...
Definition: qaction.h:223
static void startMove(QWidget *widget)
Starts to move the given top level widget by making its Title region active and grabbing the mouse in...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenu.cpp:1453
void showNormal()
Restores the widget after it has been maximized or minimized.
Definition: qwidget.cpp:3250
void setEnabled(bool)
Definition: qaction.cpp:1192
virtual QRegion region(const QWidget *w, const QRect &rect, int decorationRegion=All)=0
Implement this function to return the region specified by decorationRegion for the given top level wi...
virtual void buildSysMenu(QWidget *widget, QMenu *menu)
Builds the system menu for the given top level widget, adding Restore, Move, Size, Minimize, Maximize and Close actions to the given menu.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static void startResize(QWidget *widget)
Starts to resize the given top level widget by making its BottomRight region active and grabbing the ...
QAction * addSeparator()
This convenience function creates a new separator action, i.e.
Definition: qmenu.cpp:1583
bool contains(const QPoint &p) const
Returns true if the region contains the point p; otherwise returns false.
Definition: qregion.cpp:4104
virtual void regionDoubleClicked(QWidget *widget, int region)
Handles the event that the specified region in the given top level widget is activated by a double cl...
static bool inWhatsThisMode()
Returns true if the user interface is in "What&#39;s This?" mode; otherwise returns false.
Definition: qwhatsthis.cpp:648
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
virtual void regionClicked(QWidget *widget, int region)
Handles the event that the specified region in the given top level widget is activated by a single cl...
bool close()
Closes this widget.
Definition: qwidget.cpp:8305
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition: qwidget.h:158
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
static void enterWhatsThisMode()
This function switches the user interface into "What&#39;s This?" mode.
Definition: qwhatsthis.cpp:633
static void leaveWhatsThisMode()
If the user interface is in "What&#39;s This?" mode, this function switches back to normal mode; otherwis...
Definition: qwhatsthis.cpp:662
void menuTriggered(QWidget *widget, QAction *action)
This function is called whenever an action in a top level widget&#39;s menu is triggered, and simply calls the regionClicked() function passing the widget and action parameters as arguments.