FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
qwidget_utils.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (30 Mar. 2015)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #pragma once
17 
18 #include "gui.h"
19 #include <QtCore/QPair>
20 #include <QtCore/QPoint>
21 #include <QMessageBox>
22 
23 class QAbstractScrollArea;
24 class QDialog;
25 class QMenu;
26 class QWidget;
27 
28 namespace qtgui {
29 
31 {
32 public:
33  template<typename PARENT_WIDGET>
34  static PARENT_WIDGET* findFirstParentWidget(QWidget* widget);
35 
36  template<typename PARENT_WIDGET>
37  static PARENT_WIDGET* findLastParentWidget(QWidget* widget);
38 
39  static void wrapWidgetInDialog(QWidget* widget, QDialog* dialog);
40  static void addContentsWidget(
41  QWidget* containerWidget, QWidget* contentsWidget);
42 
43  static QPoint globalPos(const QWidget* widget, Qt::Corner widgetCorner);
44  static void moveWidgetRightTo(QWidget* widget, const QWidget* nextTo);
45  static void moveWidgetLeftTo(QWidget* widget, const QWidget* nextTo);
46 
47  static QPair<int, int> horizAndVertScrollValue(const QAbstractScrollArea* area);
48  static void setHorizAndVertScrollValue(
49  QAbstractScrollArea* area, const QPair<int, int>& values);
50 
51  static void asyncDialogExec(QDialog* dialog);
52  static void asyncMenuExec(QMenu* menu, const QPoint& pos = QCursor::pos());
53  static QMessageBox* asyncMsgBoxInfo(
54  QWidget* parent,
55  const QString& title,
56  const QString& text,
57  QMessageBox::StandardButtons buttons = QMessageBox::Ok);
58  static QMessageBox* asyncMsgBoxWarning(
59  QWidget* parent,
60  const QString& title,
61  const QString& text,
62  QMessageBox::StandardButtons buttons = QMessageBox::Ok);
63  static QMessageBox* asyncMsgBoxCritical(
64  QWidget* parent,
65  const QString& title,
66  const QString& text,
67  QMessageBox::StandardButtons buttons = QMessageBox::Ok);
68 };
69 
70 } // namespace qtgui
71 
72 // --
73 // -- Implementation
74 // --
75 
76 // QtWidgets
77 #include <QWidget>
78 
79 namespace qtgui {
80 
82 template<typename PARENT_WIDGET>
83 PARENT_WIDGET* QWidgetUtils::findFirstParentWidget(QWidget* widget)
84 {
85  PARENT_WIDGET* foundParentWidget = NULL;
86  QWidget* iteratorWidget = widget;
87  while (iteratorWidget != NULL && foundParentWidget == NULL) {
88  iteratorWidget = iteratorWidget->parentWidget();
89  foundParentWidget = qobject_cast<PARENT_WIDGET*>(iteratorWidget);
90  }
91  return foundParentWidget;
92 }
93 
95 template<typename PARENT_WIDGET>
96 PARENT_WIDGET* QWidgetUtils::findLastParentWidget(QWidget* widget)
97 {
98  PARENT_WIDGET* foundParentWidget = NULL;
99  QWidget* iteratorWidget = widget;
100  while (iteratorWidget != NULL) {
101  iteratorWidget = iteratorWidget->parentWidget();
102  PARENT_WIDGET* currParentWidget = qobject_cast<PARENT_WIDGET*>(iteratorWidget);
103  if (currParentWidget != NULL)
104  foundParentWidget = currParentWidget;
105  }
106  return foundParentWidget;
107 }
108 
109 } // namespace qtgui
Provides a collection of tools around QWidget.
Definition: qwidget_utils.h:30
Definition: abstract_length_editor.cpp:20
static PARENT_WIDGET * findFirstParentWidget(QWidget *widget)
Searches up in the direct parents of widget the first ancestor being of type PARENT_WIDGET.
Definition: qwidget_utils.h:83
static PARENT_WIDGET * findLastParentWidget(QWidget *widget)
Searches up in the direct parents of widget the last ancestor being of type PARENT_WIDGET.
Definition: qwidget_utils.h:96
#define QTTOOLS_GUI_EXPORT
Definition: gui.h:27