10#include <QtDesigner/abstractformwindow.h>
11#include <QtDesigner/abstractformeditor.h>
12#include <QtDesigner/propertysheet.h>
13#include <QtDesigner/abstractpropertyeditor.h>
14#include <QtDesigner/abstractformwindowmanager.h>
15#include <QtDesigner/taskmenu.h>
16#include <QtDesigner/qextensionmanager.h>
18#include <QtWidgets/qfiledialog.h>
19#include <QtWidgets/qmessagebox.h>
20#include <QtWidgets/qpushbutton.h>
21#include <QtWidgets/qboxlayout.h>
23#include <QtGui/qaction.h>
24#include <QtGui/qevent.h>
25#include <QtGui/qundostack.h>
27#include <QtCore/qfile.h>
28#include <QtCore/qregularexpression.h>
32using namespace Qt::StringLiterals;
35 : QWidget(parent, flags),
37 m_workbench(workbench),
38 m_action(
new QAction(
this))
42 setMaximumSize(0xFFF, 0xFFF);
43 QDesignerFormEditorInterface *core = workbench
->core();
46 m_editor->setParent(
this);
48 m_editor = core->formWindowManager()->createFormWindow(
this);
51 auto *l =
new QVBoxLayout(
this);
52 l->setContentsMargins(QMargins());
53 l->addWidget(m_editor);
55 m_action->setCheckable(
true);
57 connect(m_editor->commandHistory(), &QUndoStack::indexChanged,
this, &QDesignerFormWindow::updateChanged);
58 connect(m_editor.data(), &QDesignerFormWindowInterface::geometryChanged,
76 case QEvent::WindowTitleChange:
77 m_action->setText(windowTitle().remove(
"[*]"_L1));
79 case QEvent::WindowIconChange:
80 m_action->setIcon(windowIcon());
82 case QEvent::WindowStateChange: {
83 const auto *wsce =
static_cast<
const QWindowStateChangeEvent *>(e);
84 const bool wasMinimized = Qt::WindowMinimized & wsce->oldState();
85 const bool isMinimizedNow = isMinimized();
86 if (wasMinimized != isMinimizedNow )
87 emit minimizationStateChanged(m_editor, isMinimizedNow);
93 QWidget::changeEvent(e);
98 const QPoint point(0, 0);
101 if (QWidget *mainContainer = m_editor->mainContainer())
102 return QRect(point, mainContainer->size());
104 return QRect(point, sizeHint());
120 if (!m_windowTitleInitialized) {
121 m_windowTitleInitialized =
true;
123 connect(m_editor.data(), &QDesignerFormWindowInterface::fileNameChanged,
124 this, &QDesignerFormWindow::updateWindowTitle);
125 updateWindowTitle(m_editor->fileName());
134 const int totalWindows = m_workbench->formWindowCount();
142 static const QRegularExpression rx(u"untitled( (\\d+))?\\[\\*\\]$"_s);
143 Q_ASSERT(rx.isValid());
144 for (
int i = 0; i < totalWindows; ++i) {
147 const QString title = m_workbench->formWindow(i)->windowTitle();
148 const QRegularExpressionMatch match = rx.match(title);
149 if (match.hasMatch()) {
150 if (maxUntitled == 0)
152 if (match.lastCapturedIndex() >= 2) {
153 const auto numberCapture = match.capturedView(2);
154 if (!numberCapture.isEmpty())
155 maxUntitled = qMax(numberCapture.toInt(), maxUntitled);
165 if (!m_windowTitleInitialized) {
166 m_windowTitleInitialized =
true;
168 connect(m_editor.data(), &QDesignerFormWindowInterface::fileNameChanged,
169 this, &QDesignerFormWindow::updateWindowTitle);
172 QString fileNameTitle;
173 if (fileName.isEmpty()) {
174 fileNameTitle +=
"untitled"_L1;
175 if (
const int maxUntitled = getNumberOfUntitledWindows()) {
176 fileNameTitle += u' ' + QString::number(maxUntitled + 1);
179 fileNameTitle = QFileInfo(fileName).fileName();
182 if (
const QWidget *mc = m_editor->mainContainer()) {
183 setWindowIcon(mc->windowIcon());
184 setWindowTitle(tr(
"%1 - %2[*]").arg(mc->windowTitle(), fileNameTitle));
186 setWindowTitle(fileNameTitle);
192 if (m_editor->isDirty()) {
194 QMessageBox box(QMessageBox::Information, tr(
"Save Form?"),
195 tr(
"Do you want to save the changes to this document before closing?"),
196 QMessageBox::Discard | QMessageBox::Cancel | QMessageBox::Save, m_editor);
197 box.setInformativeText(tr(
"If you don't save, your changes will be lost."));
198 box.setWindowModality(Qt::WindowModal);
199 static_cast<QPushButton *>(box.button(QMessageBox::Save))->setDefault(
true);
201 switch (box.exec()) {
202 case QMessageBox::Save: {
205 m_editor->setDirty(!ok);
208 case QMessageBox::Discard:
209 m_editor->setDirty(
false);
212 case QMessageBox::Cancel:
223 setWindowModified(m_editor->isDirty());
224 updateWindowTitle(m_editor->fileName());
231 m_editor->setDirty(
true);
232 setWindowModified(
true);
235 m_initialized =
true;
236 QWidget::resizeEvent(rev);
244 const QDesignerFormEditorInterface *core = m_editor->core();
245 QObject *object = core->propertyEditor()->object();
246 if (object ==
nullptr || !object->isWidgetType())
248 static const QString geometryProperty = u"geometry"_s;
249 const QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), object);
250 const int geometryIndex = sheet->indexOf(geometryProperty);
251 if (geometryIndex == -1)
253 core->propertyEditor()->setPropertyValue(geometryProperty, sheet->property(geometryIndex));
bool saveForm(QDesignerFormWindowInterface *fw)
QDesignerFormEditorInterface * core() const
void removeFormWindow(QDesignerFormWindow *formWindow)
Combined button and popup list for selecting options.