6#include <metadatabase_p.h>
7#include <qdesigner_command_p.h>
8#include <qdesigner_utils_p.h>
9#include <qlayout_widget_p.h>
10#include <orderdialog_p.h>
12#include <QtDesigner/qextensionmanager.h>
13#include <QtDesigner/abstractformwindow.h>
14#include <QtDesigner/abstractformwindowcursor.h>
15#include <QtDesigner/abstractformeditor.h>
16#include <QtDesigner/abstractwidgetfactory.h>
17#include <QtDesigner/propertysheet.h>
19#include <QtGui/qpainter.h>
20#include <QtGui/qevent.h>
21#include <QtWidgets/qmenu.h>
22#include <QtWidgets/qapplication.h>
24Q_DECLARE_METATYPE(QWidgetList)
28using namespace Qt::StringLiterals;
31 enum { VBOX_MARGIN = 1, HBOX_MARGIN = 4, BG_ALPHA = 32 };
36 return QRect(r.x(), r.y(), r.width() - 1, r.height() - 1);
45 m_undo_stack(form->commandHistory()),
46 m_font_metrics(font()),
50 connect(form, &QDesignerFormWindowInterface::widgetRemoved,
this, &TabOrderEditor::widgetRemoved);
52 QFont tabFont = font();
53 tabFont.setPointSize(tabFont.pointSize()*2);
54 tabFont.setBold(
true);
56 m_font_metrics = QFontMetrics(tabFont);
57 setAttribute(Qt::WA_MouseTracking,
true);
67 if (background == m_bg_widget) {
71 m_bg_widget = background;
77 if (m_bg_widget ==
nullptr) {
93 QWidget::showEvent(e);
99 if (index < 0 || index >= m_tab_order_list.size())
102 const QWidget *w = m_tab_order_list.at(index);
103 const QString text = QString::number(index + 1);
105 const QPoint tl = mapFromGlobal(w->mapToGlobal(w->rect().topLeft()));
106 const QSize size = m_font_metrics.size(Qt::TextSingleLine, text);
107 QRect r(tl - QPoint(size.width(), size.height())/2, size);
108 r = QRect(r.left() - HBOX_MARGIN, r.top() - VBOX_MARGIN,
109 r.width() + HBOX_MARGIN*2, r.height() + VBOX_MARGIN*2);
116 while (widget && widget->parentWidget()) {
117 if (!widget->isVisibleTo(widget->parentWidget()))
120 widget = widget->parentWidget();
129 p.setClipRegion(e->region());
131 int cur = m_current_index - 1;
132 if (!m_beginning && cur < 0)
133 cur = m_tab_order_list.size() - 1;
135 for (qsizetype i = 0; i < m_tab_order_list.size(); ++i) {
136 QWidget *widget = m_tab_order_list.at(i);
140 const QRect r = indicatorRect(i);
142 QColor c = Qt::darkGreen;
148 c.setAlpha(BG_ALPHA);
150 p.drawRect(fixRect(r));
153 p.drawText(r, QString::number(i + 1), QTextOption(Qt::AlignCenter));
159 if (qobject_cast<QLayoutWidget*>(w)
160 || w == formWindow()->mainContainer()
168 QExtensionManager *ext = formWindow()->core()->extensionManager();
170 const int index = sheet->indexOf(u"focusPolicy"_s);
173 Qt::FocusPolicy q = (Qt::FocusPolicy) Utils::valueOf(sheet->property(index), &ok);
174 return !ok || !(q & Qt::TabFocus);
183 m_tab_order_list.clear();
185 QDesignerFormEditorInterface *core =
formWindow()->core();
188 m_tab_order_list = item->tabOrder();
192 for (qsizetype i = 0; i < m_tab_order_list.size(); ) {
193 QWidget *w = m_tab_order_list.at(i);
194 if (!formWindow()->mainContainer()->isAncestorOf(w) || skipWidget(w))
195 m_tab_order_list.removeAt(i);
201 QWidgetList childQueue;
203 while (!childQueue.isEmpty()) {
204 QWidget *child = childQueue.takeFirst();
205 childQueue += qvariant_cast<QWidgetList>(child->property(
"_q_widgetOrder"));
207 if (skipWidget(child))
210 if (!m_tab_order_list.contains(child))
211 m_tab_order_list.append(child);
215 QDesignerFormWindowCursorInterface *cursor = formWindow()->cursor();
216 for (
int i = 0; i < cursor->widgetCount(); ++i) {
218 QWidget *widget = cursor->widget(i);
219 if (skipWidget(widget))
222 if (!m_tab_order_list.contains(widget))
223 m_tab_order_list.append(widget);
226 m_indicator_region = QRegion();
227 for (qsizetype i = 0; i < m_tab_order_list.size(); ++i) {
228 if (m_tab_order_list.at(i)->isVisible())
229 m_indicator_region |= indicatorRect(i);
232 if (m_current_index >= m_tab_order_list.size())
233 m_current_index = m_tab_order_list.size() - 1;
234 if (m_current_index < 0)
242 if (m_indicator_region.contains(e->position().toPoint()))
243 setCursor(Qt::PointingHandCursor);
245 setCursor(QCursor());
251 int target_index = -1;
252 for (qsizetype i = 0; i < m_tab_order_list.size(); ++i) {
253 if (!m_tab_order_list.at(i)->isVisible())
255 if (indicatorRect(i).contains(pos)) {
268 if (!m_indicator_region.contains(e->position().toPoint())) {
269 if (
QWidget *child = m_bg_widget->childAt(e->position().toPoint())) {
270 QDesignerFormEditorInterface *core = m_form_window->core();
271 if (core->widgetFactory()->isPassiveInteractor(child)) {
273 QMouseEvent event(QEvent::MouseButtonPress,
274 child->mapFromGlobal(e->globalPosition().toPoint()),
275 e->globalPosition().toPoint(), e->button(), e->buttons(),
278 qApp->sendEvent(child, &event);
280 QMouseEvent event2(QEvent::MouseButtonRelease,
281 child->mapFromGlobal(e->globalPosition().toPoint()),
282 e->globalPosition().toPoint(), e->button(), e->buttons(),
285 qApp->sendEvent(child, &event2);
293 if (e->button() != Qt::LeftButton)
296 const int target_index = widgetIndexAt(e->position().toPoint());
297 if (target_index == -1)
302 if (e->modifiers() & Qt::ControlModifier) {
303 m_current_index = target_index + 1;
304 if (m_current_index >= m_tab_order_list.size())
310 if (m_current_index == -1)
313 m_tab_order_list.swapItemsAt(target_index, m_current_index);
316 if (m_current_index == m_tab_order_list.size())
319 TabOrderCommand *cmd =
new TabOrderCommand(formWindow());
320 cmd->init(m_tab_order_list);
321 formWindow()->commandHistory()->push(cmd);
327 const int target_index = widgetIndexAt(e->pos());
328 QAction *setIndex = menu.addAction(tr(
"Start from Here"));
329 setIndex->setEnabled(target_index >= 0);
331 QAction *resetIndex = menu.addAction(tr(
"Restart"));
333 QAction *showDialog = menu.addAction(tr(
"Tab Order List..."));
334 showDialog->setEnabled(m_tab_order_list.size() > 1);
336 QAction *result = menu.exec(e->globalPos());
337 if (result == resetIndex) {
341 }
else if (result == setIndex) {
343 m_current_index = target_index + 1;
344 if (m_current_index >= m_tab_order_list.size())
347 }
else if (result == showDialog) {
348 showTabOrderDialog();
354 if (e->button() != Qt::LeftButton)
357 const int target_index = widgetIndexAt(e->position().toPoint());
358 if (target_index >= 0)
369 QWidget::resizeEvent(e);
374 if (m_tab_order_list.size() < 2)
377 dlg.setWindowTitle(tr(
"Tab Order List"));
378 dlg.setDescription(tr(
"Tab Order"));
379 dlg.setFormat(OrderDialog::TabOrderFormat);
380 dlg.setPageList(m_tab_order_list);
382 if (dlg.exec() == QDialog::Rejected)
385 const QWidgetList newOrder = dlg.pageList();
386 if (newOrder == m_tab_order_list)
389 m_tab_order_list = newOrder;
390 TabOrderCommand *cmd =
new TabOrderCommand(formWindow());
391 cmd->init(m_tab_order_list);
392 formWindow()->commandHistory()->push(cmd);
void contextMenuEvent(QContextMenuEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive widget context men...
void mouseDoubleClickEvent(QMouseEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse double click...
QDesignerFormWindowInterface * formWindow() const
void mousePressEvent(QMouseEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
void showEvent(QShowEvent *e) override
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
void paintEvent(QPaintEvent *e) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
void resizeEvent(QResizeEvent *e) override
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
void mouseMoveEvent(QMouseEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
Auxiliary methods to store/retrieve settings.
static bool isWidgetVisible(QWidget *widget)
static QRect fixRect(QRect r)