9#include <QtDesigner/abstractformwindow.h>
10#include <QtDesigner/abstractformeditor.h>
11#include <QtDesigner/propertysheet.h>
12#include <QtDesigner/abstractpropertyeditor.h>
13#include <QtDesigner/abstractformwindowmanager.h>
14#include <QtDesigner/taskmenu.h>
15#include <QtDesigner/qextensionmanager.h>
17#include <QtWidgets/qfiledialog.h>
18#include <QtWidgets/qmessagebox.h>
19#include <QtWidgets/qpushbutton.h>
20#include <QtWidgets/qboxlayout.h>
22#include <QtGui/qaction.h>
23#include <QtGui/qevent.h>
24#include <QtGui/qundostack.h>
26#include <QtCore/qfile.h>
27#include <QtCore/qregularexpression.h>
31using namespace Qt::StringLiterals;
34 : QWidget(parent, flags),
36 m_workbench(workbench),
37 m_action(
new QAction(
this))
41 setMaximumSize(0xFFF, 0xFFF);
42 QDesignerFormEditorInterface *core = workbench
->core();
45 m_editor->setParent(
this);
47 m_editor = core->formWindowManager()->createFormWindow(
this);
50 QVBoxLayout *l =
new QVBoxLayout(
this);
51 l->setContentsMargins(QMargins());
52 l->addWidget(m_editor);
54 m_action->setCheckable(
true);
56 connect(m_editor->commandHistory(), &QUndoStack::indexChanged,
this, &QDesignerFormWindow::updateChanged);
57 connect(m_editor.data(), &QDesignerFormWindowInterface::geometryChanged,
58 this, &QDesignerFormWindow::slotGeometryChanged);
75 case QEvent::WindowTitleChange:
76 m_action->setText(windowTitle().remove(
"[*]"_L1));
78 case QEvent::WindowIconChange:
79 m_action->setIcon(windowIcon());
81 case QEvent::WindowStateChange: {
82 const QWindowStateChangeEvent *wsce =
static_cast<
const QWindowStateChangeEvent *>(e);
83 const bool wasMinimized = Qt::WindowMinimized & wsce->oldState();
84 const bool isMinimizedNow = isMinimized();
85 if (wasMinimized != isMinimizedNow )
86 emit minimizationStateChanged(m_editor, isMinimizedNow);
92 QWidget::changeEvent(e);
97 const QPoint point(0, 0);
100 if (QWidget *mainContainer = m_editor->mainContainer())
101 return QRect(point, mainContainer->size());
103 return QRect(point, sizeHint());
119 if (!m_windowTitleInitialized) {
120 m_windowTitleInitialized =
true;
122 connect(m_editor.data(), &QDesignerFormWindowInterface::fileNameChanged,
123 this, &QDesignerFormWindow::updateWindowTitle);
124 updateWindowTitle(m_editor->fileName());
133 const int totalWindows = m_workbench->formWindowCount();
141 static const QRegularExpression rx(u"untitled( (\\d+))?\\[\\*\\]$"_s);
142 Q_ASSERT(rx.isValid());
143 for (
int i = 0; i < totalWindows; ++i) {
146 const QString title = m_workbench->formWindow(i)->windowTitle();
147 const QRegularExpressionMatch match = rx.match(title);
148 if (match.hasMatch()) {
149 if (maxUntitled == 0)
151 if (match.lastCapturedIndex() >= 2) {
152 const auto numberCapture = match.capturedView(2);
153 if (!numberCapture.isEmpty())
154 maxUntitled = qMax(numberCapture.toInt(), maxUntitled);
164 if (!m_windowTitleInitialized) {
165 m_windowTitleInitialized =
true;
167 connect(m_editor.data(), &QDesignerFormWindowInterface::fileNameChanged,
168 this, &QDesignerFormWindow::updateWindowTitle);
171 QString fileNameTitle;
172 if (fileName.isEmpty()) {
173 fileNameTitle +=
"untitled"_L1;
174 if (
const int maxUntitled = getNumberOfUntitledWindows()) {
175 fileNameTitle += u' ' + QString::number(maxUntitled + 1);
178 fileNameTitle = QFileInfo(fileName).fileName();
181 if (
const QWidget *mc = m_editor->mainContainer()) {
182 setWindowIcon(mc->windowIcon());
183 setWindowTitle(tr(
"%1 - %2[*]").arg(mc->windowTitle(), fileNameTitle));
185 setWindowTitle(fileNameTitle);
191 if (m_editor->isDirty()) {
193 QMessageBox box(QMessageBox::Information, tr(
"Save Form?"),
194 tr(
"Do you want to save the changes to this document before closing?"),
195 QMessageBox::Discard | QMessageBox::Cancel | QMessageBox::Save, m_editor);
196 box.setInformativeText(tr(
"If you don't save, your changes will be lost."));
197 box.setWindowModality(Qt::WindowModal);
198 static_cast<QPushButton *>(box.button(QMessageBox::Save))->setDefault(
true);
200 switch (box.exec()) {
201 case QMessageBox::Save: {
202 bool ok = workbench()->saveForm(m_editor);
204 m_editor->setDirty(!ok);
207 case QMessageBox::Discard:
208 m_editor->setDirty(
false);
211 case QMessageBox::Cancel:
222 setWindowModified(m_editor->isDirty());
223 updateWindowTitle(m_editor->fileName());
230 m_editor->setDirty(
true);
231 setWindowModified(
true);
234 m_initialized =
true;
235 QWidget::resizeEvent(rev);
243 const QDesignerFormEditorInterface *core = m_editor->core();
244 QObject *object = core->propertyEditor()->object();
245 if (object ==
nullptr || !object->isWidgetType())
247 static const QString geometryProperty = u"geometry"_s;
248 const QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), object);
249 const int geometryIndex = sheet->indexOf(geometryProperty);
250 if (geometryIndex == -1)
252 core->propertyEditor()->setPropertyValue(geometryProperty, sheet->property(geometryIndex));
QDesignerFormEditorInterface * core() const
void removeFormWindow(QDesignerFormWindow *formWindow)
Combined button and popup list for selecting options.