1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Designer of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include "qdesigner_widget_p.h"
30#include "formwindowbase_p.h"
31#include "grid_p.h"
32
33#include <QtDesigner/abstractformwindow.h>
34#include <QtGui/qpainter.h>
35#include <QtWidgets/qstyle.h>
36#include <QtWidgets/qstyleoption.h>
37#include <QtGui/qevent.h>
38
39QT_BEGIN_NAMESPACE
40
41/* QDesignerDialog / QDesignerWidget are used to paint a grid on QDialog and QWidget main containers
42 * and container extension pages.
43 * The paint routines work as follows:
44 * We need to clean the background here (to make the parent grid disappear in case we are a container page
45 * and to make palette background settings take effect),
46 * which would normally break style sheets with background settings.
47 * So, we manually make the style paint after cleaning. On top comes the grid
48 * In addition, this code works around
49 * the QStyleSheetStyle setting Qt::WA_StyledBackground to false for subclasses of QWidget.
50 */
51
52QDesignerDialog::QDesignerDialog(QDesignerFormWindowInterface *fw, QWidget *parent) :
53 QDialog(parent),
54 m_formWindow(qobject_cast<qdesigner_internal::FormWindowBase*>(object: fw))
55{
56}
57
58void QDesignerDialog::paintEvent(QPaintEvent *e)
59{
60 QPainter p(this);
61 QStyleOption opt;
62 opt.initFrom(w: this);
63 p.fillRect(e->rect(), palette().brush(cr: backgroundRole()));
64 style()->drawPrimitive(pe: QStyle::PE_Widget, opt: &opt, p: &p, w: this);
65 if (m_formWindow && m_formWindow->gridVisible())
66 m_formWindow->designerGrid().paint(p, widget: this, e);
67}
68
69QDesignerWidget::QDesignerWidget(QDesignerFormWindowInterface* formWindow, QWidget *parent) :
70 QWidget(parent),
71 m_formWindow(qobject_cast<qdesigner_internal::FormWindowBase*>(object: formWindow))
72{
73}
74
75QDesignerWidget::~QDesignerWidget() = default;
76
77QDesignerFormWindowInterface* QDesignerWidget::formWindow() const
78{
79 return m_formWindow;
80}
81
82void QDesignerWidget::paintEvent(QPaintEvent *e)
83{
84 QPainter p(this);
85 QStyleOption opt;
86 opt.initFrom(w: this);
87 p.fillRect(e->rect(), palette().brush(cr: backgroundRole()));
88 style()->drawPrimitive(pe: QStyle::PE_Widget, opt: &opt, p: &p, w: this);
89 if (m_formWindow && m_formWindow->gridVisible())
90 m_formWindow->designerGrid().paint(p, widget: this, e);
91}
92
93QT_END_NAMESPACE
94

source code of qttools/src/designer/src/lib/shared/qdesigner_widget.cpp