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 "previewframe.h"
30#include "previewwidget.h"
31
32#include <QtCore/qcoreapplication.h>
33#include <QtCore/qdebug.h>
34#include <QtGui/qpainter.h>
35#include <QtWidgets/qmdiarea.h>
36#include <QtWidgets/qmdisubwindow.h>
37#include <QtGui/qevent.h>
38
39QT_BEGIN_NAMESPACE
40
41namespace qdesigner_internal {
42
43 class PreviewMdiArea: public QMdiArea {
44 public:
45 PreviewMdiArea(QWidget *parent = nullptr) : QMdiArea(parent) {}
46 protected:
47 bool viewportEvent(QEvent *event) override;
48 };
49
50 bool PreviewMdiArea::viewportEvent (QEvent * event) {
51 if (event->type() != QEvent::Paint)
52 return QMdiArea::viewportEvent (event);
53 QWidget *paintWidget = viewport();
54 QPainter p(paintWidget);
55 p.fillRect(rect(), color: paintWidget->palette().color(cr: backgroundRole()).darker());
56 p.setPen(QPen(Qt::white));
57 //: Palette editor background
58 p.drawText(x: 0, y: height() / 2, w: width(), h: height(), flags: Qt::AlignHCenter,
59 str: QCoreApplication::translate(context: "qdesigner_internal::PreviewMdiArea", key: "The moose in the noose\nate the goose who was loose."));
60 return true;
61 }
62
63PreviewFrame::PreviewFrame(QWidget *parent) :
64 QFrame(parent),
65 m_mdiArea(new PreviewMdiArea(this))
66{
67 m_mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
68 m_mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
69 setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
70 setLineWidth(1);
71
72 QVBoxLayout *vbox = new QVBoxLayout(this);
73 vbox->setContentsMargins(QMargins());
74 vbox->addWidget(m_mdiArea);
75
76 setMinimumSize(ensureMdiSubWindow()->minimumSizeHint());
77}
78
79void PreviewFrame::setPreviewPalette(const QPalette &pal)
80{
81 ensureMdiSubWindow()->setPalette(pal);
82}
83
84void PreviewFrame::setSubWindowActive(bool active)
85{
86 m_mdiArea->setActiveSubWindow (active ? ensureMdiSubWindow() : nullptr);
87}
88
89QMdiSubWindow *PreviewFrame::ensureMdiSubWindow()
90{
91 if (!m_mdiSubWindow) {
92 PreviewWidget *previewWidget = new PreviewWidget(m_mdiArea);
93 m_mdiSubWindow = m_mdiArea->addSubWindow(widget: previewWidget, flags: Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint);
94 m_mdiSubWindow->move(ax: 10,ay: 10);
95 m_mdiSubWindow->showMaximized();
96 }
97
98 const Qt::WindowStates state = m_mdiSubWindow->windowState();
99 if (state & Qt::WindowMinimized)
100 m_mdiSubWindow->setWindowState(state & ~Qt::WindowMinimized);
101
102 return m_mdiSubWindow;
103}
104}
105
106QT_END_NAMESPACE
107

source code of qttools/src/designer/src/components/propertyeditor/previewframe.cpp