50QTabWidgetEventFilter::QTabWidgetEventFilter(QTabWidget *parent) :
53 m_actionDeletePage(
new QAction(tr(
"Delete"),
this)),
54 m_actionInsertPage(
new QAction(tr(
"Before Current Page"),
this)),
55 m_actionInsertPageAfter(
new QAction(tr(
"After Current Page"),
this)),
56 m_pagePromotionTaskMenu(
new qdesigner_internal::PromotionTaskMenu(
nullptr, qdesigner_internal::PromotionTaskMenu::ModeSingleWidget,
this))
58 tabBar()->setAcceptDrops(
true);
59 tabBar()->installEventFilter(
this);
61 connect(m_actionInsertPage, &QAction::triggered,
this, &QTabWidgetEventFilter::addPage);
62 connect(m_actionInsertPageAfter, &QAction::triggered,
this, &QTabWidgetEventFilter::addPageAfter);
63 connect(m_actionDeletePage, &QAction::triggered,
this, &QTabWidgetEventFilter::removeCurrentPage);
110bool QTabWidgetEventFilter::eventFilter(QObject *o, QEvent *e)
112 const QEvent::Type type = e->type();
116 case QEvent::MouseButtonDblClick:
117 case QEvent::MouseButtonPress:
118 case QEvent::MouseButtonRelease:
119 case QEvent::MouseMove:
120 case QEvent::DragLeave:
121 case QEvent::DragEnter:
122 case QEvent::DragMove:
132 QDesignerFormWindowInterface *fw = formWindow();
138 case QEvent::MouseButtonDblClick:
140 case QEvent::MouseButtonPress: {
141 QMouseEvent *mev =
static_cast<QMouseEvent*>(e);
142 if (QDesignerFormWindowInterface *fw = formWindow()) {
143 fw->clearSelection();
144 fw->selectWidget(m_tabWidget,
true);
146 if (mev->button() & Qt::LeftButton) {
147 m_mousePressed =
true;
148 m_pressPoint = mev->position().toPoint();
150 QTabBar *tabbar = tabBar();
151 const int count = tabbar->count();
152 for (
int i = 0; i < count; ++i) {
153 if (tabbar->tabRect(i).contains(m_pressPoint)) {
154 if (i != tabbar->currentIndex()) {
155 qdesigner_internal::SetPropertyCommand *cmd =
new qdesigner_internal::SetPropertyCommand(fw);
156 cmd->init(m_tabWidget, u"currentIndex"_s, i);
157 fw->commandHistory()->push(cmd);
165 case QEvent::MouseButtonRelease:
166 m_mousePressed =
false;
169 case QEvent::MouseMove: {
170 QMouseEvent *mouseEvent =
static_cast<QMouseEvent*>(e);
171 if (m_mousePressed && canMove(m_pressPoint, mouseEvent)) {
172 const int index = m_tabWidget->currentIndex();
176 m_mousePressed =
false;
177 QDrag *drg =
new QDrag(m_tabWidget);
178 drg->setMimeData(
new qdesigner_internal::MyMimeData(m_tabWidget));
181 m_dragPage = m_tabWidget->currentWidget();
182 m_dragLabel = m_tabWidget->tabText(index);
183 m_dragIcon = m_tabWidget->tabIcon(index);
184 if (m_dragIcon.isNull()) {
185 QLabel *label =
new QLabel(m_dragLabel);
187 drg->setPixmap(label->grab(QRect(0, 0, -1, -1)));
188 label->deleteLater();
190 drg->setPixmap(m_dragIcon.pixmap(22, 22));
193 m_tabWidget->removeTab(m_dragIndex);
195 const Qt::DropActions dropAction = drg->exec(Qt::MoveAction);
197 if (dropAction == Qt::IgnoreAction) {
199 m_tabWidget->insertTab(m_dragIndex, m_dragPage, m_dragIcon, m_dragLabel);
200 m_tabWidget->setCurrentIndex(m_dragIndex);
204 m_dropIndicator->hide();
208 case QEvent::DragLeave: {
210 m_dropIndicator->hide();
213 case QEvent::DragEnter:
214 case QEvent::DragMove: {
215 QDragMoveEvent *de =
static_cast<QDragMoveEvent*>(e);
216 if (!qdesigner_internal::MyMimeData::fromMyTab(de->mimeData(), m_tabWidget))
219 if (de->proposedAction() == Qt::MoveAction)
220 de->acceptProposedAction();
222 de->setDropAction(Qt::MoveAction);
227 const int index = pageFromPosition(de->position().toPoint(), rect);
229 if (!m_dropIndicator) {
230 m_dropIndicator =
new QWidget(m_tabWidget);
231 QPalette p = m_dropIndicator->palette();
232 p.setColor(m_tabWidget->backgroundRole(), Qt::red);
233 m_dropIndicator->setPalette(p);
237 if (index == m_tabWidget->count())
238 pos = tabBar()->mapToParent(QPoint(rect.x() + rect.width(), rect.y()));
240 pos = tabBar()->mapToParent(QPoint(rect.x(), rect.y()));
242 m_dropIndicator->setGeometry(pos.x(), pos.y() , 3, rect.height());
243 m_dropIndicator->show();
247 QDropEvent *de =
static_cast<QDropEvent*>(e);
248 if (!qdesigner_internal::MyMimeData::fromMyTab(de->mimeData(), m_tabWidget))
250 de->acceptProposedAction();
254 const int newIndex = pageFromPosition(de->position().toPoint(), rect);
256 qdesigner_internal::MoveTabPageCommand *cmd =
new qdesigner_internal::MoveTabPageCommand(fw);
257 m_tabWidget->insertTab(m_dragIndex, m_dragPage, m_dragIcon, m_dragLabel);
258 cmd->init(m_tabWidget, m_dragPage, m_dragIcon, m_dragLabel, m_dragIndex, newIndex);
259 fw->commandHistory()->push(cmd);
328QMenu *QTabWidgetEventFilter::addContextMenuActions(QMenu *popup)
330 QMenu *pageMenu =
nullptr;
331 const int count = m_tabWidget->count();
332 m_actionDeletePage->setEnabled(count);
334 const int currentIndex = m_tabWidget->currentIndex();
335 const QString pageSubMenuLabel = tr(
"Page %1 of %2").arg(currentIndex + 1).arg(count);
336 pageMenu = popup->addMenu(pageSubMenuLabel);
337 pageMenu->addAction(m_actionDeletePage);
339 if (QWidget *page = m_tabWidget->currentWidget ()) {
340 m_pagePromotionTaskMenu->setWidget(page);
341 m_pagePromotionTaskMenu->addActions(QDesignerFormWindowInterface::findFormWindow(m_tabWidget),
342 qdesigner_internal::PromotionTaskMenu::SuppressGlobalEdit,
345 QMenu *insertPageMenu = popup->addMenu(tr(
"Insert Page"));
346 insertPageMenu->addAction(m_actionInsertPageAfter);
347 insertPageMenu->addAction(m_actionInsertPage);
349 QAction *insertPageAction = popup->addAction(tr(
"Insert Page"));
350 connect(insertPageAction, &QAction::triggered,
this, &QTabWidgetEventFilter::addPage);
352 popup->addSeparator();
365QTabWidgetPropertySheet::QTabWidgetPropertySheet(QTabWidget *object, QObject *parent) :
366 QDesignerPropertySheet(object, parent),
369 createFakeProperty(currentTabTextKey, QVariant::fromValue(qdesigner_internal::PropertySheetStringValue()));
370 createFakeProperty(currentTabNameKey, QString());
371 createFakeProperty(currentTabIconKey, QVariant::fromValue(qdesigner_internal::PropertySheetIconValue()));
372 if (formWindowBase())
373 formWindowBase()->addReloadableProperty(
this, indexOf(currentTabIconKey));
374 createFakeProperty(currentTabToolTipKey, QVariant::fromValue(qdesigner_internal::PropertySheetStringValue()));
375 createFakeProperty(currentTabWhatsThisKey, QVariant::fromValue(qdesigner_internal::PropertySheetStringValue()));
377 createFakeProperty(tabMovableKey, QVariant(
false));
392void QTabWidgetPropertySheet::setProperty(
int index,
const QVariant &value)
394 const TabWidgetProperty tabWidgetProperty = tabWidgetPropertyFromName(propertyName(index));
395 if (tabWidgetProperty == PropertyTabWidgetNone) {
396 QDesignerPropertySheet::setProperty(index, value);
401 const int currentIndex = m_tabWidget->currentIndex();
402 QWidget *currentWidget = m_tabWidget->currentWidget();
406 switch (tabWidgetProperty) {
407 case PropertyCurrentTabText:
408 m_tabWidget->setTabText(currentIndex, qvariant_cast<QString>(resolvePropertyValue(index, value)));
409 m_pageToData[currentWidget].text = qvariant_cast<qdesigner_internal::PropertySheetStringValue>(value);
411 case PropertyCurrentTabName:
412 currentWidget->setObjectName(value.toString());
414 case PropertyCurrentTabIcon:
415 m_tabWidget->setTabIcon(currentIndex, qvariant_cast<QIcon>(resolvePropertyValue(index, value)));
416 m_pageToData[currentWidget].icon = qvariant_cast<qdesigner_internal::PropertySheetIconValue>(value);
418 case PropertyCurrentTabToolTip:
419 m_tabWidget->setTabToolTip(currentIndex, qvariant_cast<QString>(resolvePropertyValue(index, value)));
420 m_pageToData[currentWidget].tooltip = qvariant_cast<qdesigner_internal::PropertySheetStringValue>(value);
422 case PropertyCurrentTabWhatsThis:
423 m_tabWidget->setTabWhatsThis(currentIndex, qvariant_cast<QString>(resolvePropertyValue(index, value)));
424 m_pageToData[currentWidget].whatsthis = qvariant_cast<qdesigner_internal::PropertySheetStringValue>(value);
426 case PropertyTabWidgetNone:
438QVariant QTabWidgetPropertySheet::property(
int index)
const
440 const TabWidgetProperty tabWidgetProperty = tabWidgetPropertyFromName(propertyName(index));
441 if (tabWidgetProperty == PropertyTabWidgetNone)
442 return QDesignerPropertySheet::property(index);
445 QWidget *currentWidget = m_tabWidget->currentWidget();
446 if (!currentWidget) {
447 if (tabWidgetProperty == PropertyCurrentTabIcon)
448 return QVariant::fromValue(qdesigner_internal::PropertySheetIconValue());
449 if (tabWidgetProperty == PropertyCurrentTabText)
450 return QVariant::fromValue(qdesigner_internal::PropertySheetStringValue());
451 if (tabWidgetProperty == PropertyCurrentTabToolTip)
452 return QVariant::fromValue(qdesigner_internal::PropertySheetStringValue());
453 if (tabWidgetProperty == PropertyCurrentTabWhatsThis)
454 return QVariant::fromValue(qdesigner_internal::PropertySheetStringValue());
455 return QVariant(QString());
459 switch (tabWidgetProperty) {
460 case PropertyCurrentTabText:
461 return QVariant::fromValue(m_pageToData.value(currentWidget).text);
462 case PropertyCurrentTabName:
463 return currentWidget->objectName();
464 case PropertyCurrentTabIcon:
465 return QVariant::fromValue(m_pageToData.value(currentWidget).icon);
466 case PropertyCurrentTabToolTip:
467 return QVariant::fromValue(m_pageToData.value(currentWidget).tooltip);
468 case PropertyCurrentTabWhatsThis:
469 return QVariant::fromValue(m_pageToData.value(currentWidget).whatsthis);
470 case PropertyTabWidgetNone:
476bool QTabWidgetPropertySheet::reset(
int index)
478 const TabWidgetProperty tabWidgetProperty = tabWidgetPropertyFromName(propertyName(index));
479 if (tabWidgetProperty == PropertyTabWidgetNone)
480 return QDesignerPropertySheet::reset(index);
483 QWidget *currentWidget = m_tabWidget->currentWidget();
488 switch (tabWidgetProperty) {
489 case PropertyCurrentTabName:
490 setProperty(index, QString());
492 case PropertyCurrentTabToolTip:
493 m_pageToData[currentWidget].tooltip = qdesigner_internal::PropertySheetStringValue();
494 setProperty(index, QString());
496 case PropertyCurrentTabWhatsThis:
497 m_pageToData[currentWidget].whatsthis = qdesigner_internal::PropertySheetStringValue();
498 setProperty(index, QString());
500 case PropertyCurrentTabText:
501 m_pageToData[currentWidget].text = qdesigner_internal::PropertySheetStringValue();
502 setProperty(index, QString());
504 case PropertyCurrentTabIcon:
505 m_pageToData[currentWidget].icon = qdesigner_internal::PropertySheetIconValue();
506 setProperty(index, QIcon());
508 case PropertyTabWidgetNone: