1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef NEWFORMWIDGET_H
5#define NEWFORMWIDGET_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "shared_global_p.h"
19#include "deviceprofile_p.h"
20
21#include <QtDesigner/abstractnewformwidget.h>
22
23#include <QtWidgets/qwidget.h>
24
25#include <QtGui/qpixmap.h>
26
27#include <QtCore/qlist.h>
28#include <QtCore/qmap.h>
29#include <QtCore/qpair.h>
30#include <QtCore/qstringlist.h>
31
32QT_BEGIN_NAMESPACE
33
34class QIODevice;
35class QTreeWidgetItem;
36
37namespace qdesigner_internal {
38
39namespace Ui {
40 class NewFormWidget;
41}
42
43class QDESIGNER_SHARED_EXPORT NewFormWidget : public QDesignerNewFormWidgetInterface
44{
45 Q_OBJECT
46 Q_DISABLE_COPY_MOVE(NewFormWidget)
47
48public:
49 using DeviceProfileList = QList<qdesigner_internal::DeviceProfile>;
50
51 explicit NewFormWidget(QDesignerFormEditorInterface *core, QWidget *parentWidget);
52 ~NewFormWidget() override;
53
54 bool hasCurrentTemplate() const override;
55 QString currentTemplate(QString *errorMessage = nullptr) override;
56
57 // Convenience for implementing file dialogs with preview
58 static QImage grabForm(QDesignerFormEditorInterface *core,
59 QIODevice &file,
60 const QString &workingDir,
61 const qdesigner_internal::DeviceProfile &dp);
62
63private slots:
64 void treeWidgetItemActivated(QTreeWidgetItem *item);
65 void treeWidgetCurrentItemChanged(QTreeWidgetItem *current);
66 void treeWidgetItemPressed(QTreeWidgetItem *item);
67 void slotDeviceProfileIndexChanged(int idx);
68
69private:
70 QPixmap formPreviewPixmap(const QString &fileName) const;
71 QPixmap formPreviewPixmap(QIODevice &file, const QString &workingDir = QString()) const;
72 QPixmap formPreviewPixmap(const QTreeWidgetItem *item);
73
74 void loadFrom(const QString &path, bool resourceFile, const QString &uiExtension,
75 const QString &selectedItem, QTreeWidgetItem *&selectedItemFound);
76 void loadFrom(const QString &title, const QStringList &nameList,
77 const QString &selectedItem, QTreeWidgetItem *&selectedItemFound);
78
79private:
80 QString itemToTemplate(const QTreeWidgetItem *item, QString *errorMessage) const;
81 QString currentTemplateI(QString *ptrToErrorMessage);
82
83 QSize templateSize() const;
84 void setTemplateSize(const QSize &s);
85 int profileComboIndex() const;
86 qdesigner_internal::DeviceProfile currentDeviceProfile() const;
87 bool showCurrentItemPixmap();
88
89 // Pixmap cache (item, profile combo index)
90 using ItemPixmapCacheKey = QPair<const QTreeWidgetItem *, int>;
91 using ItemPixmapCache = QMap<ItemPixmapCacheKey, QPixmap>;
92 ItemPixmapCache m_itemPixmapCache;
93
94 QDesignerFormEditorInterface *m_core;
95 Ui::NewFormWidget *m_ui;
96 QTreeWidgetItem *m_currentItem;
97 QTreeWidgetItem *m_acceptedItem;
98 DeviceProfileList m_deviceProfiles;
99};
100
101}
102
103QT_END_NAMESPACE
104
105#endif // NEWFORMWIDGET_H
106

source code of qttools/src/designer/src/lib/shared/newformwidget_p.h