summaryrefslogtreecommitdiffstats
path: root/src/designer/src/lib/shared/qdesigner_menubar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/designer/src/lib/shared/qdesigner_menubar.cpp')
-rw-r--r--src/designer/src/lib/shared/qdesigner_menubar.cpp112
1 files changed, 47 insertions, 65 deletions
diff --git a/src/designer/src/lib/shared/qdesigner_menubar.cpp b/src/designer/src/lib/shared/qdesigner_menubar.cpp
index 51bab619e..7b442ed31 100644
--- a/src/designer/src/lib/shared/qdesigner_menubar.cpp
+++ b/src/designer/src/lib/shared/qdesigner_menubar.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Designer of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "qdesigner_menubar_p.h"
#include "qdesigner_menu_p.h"
@@ -52,13 +27,11 @@
#include <QtGui/qpainter.h>
#include <QtGui/qevent.h>
-Q_DECLARE_METATYPE(QAction*)
-
QT_BEGIN_NAMESPACE
-using ActionList = QList<QAction *>;
+using namespace Qt::StringLiterals;
-using namespace qdesigner_internal;
+using ActionList = QList<QAction *>;
namespace qdesigner_internal
{
@@ -77,9 +50,9 @@ SpecialMenuAction::~SpecialMenuAction() = default;
/////////////////////////////////////////////////////////////////////////////////////////////////////////
QDesignerMenuBar::QDesignerMenuBar(QWidget *parent) :
QMenuBar(parent),
- m_addMenu(new SpecialMenuAction(this)),
+ m_addMenu(new qdesigner_internal::SpecialMenuAction(this)),
m_editor(new QLineEdit(this)),
- m_promotionTaskMenu(new PromotionTaskMenu(this, PromotionTaskMenu::ModeSingleWidget, this))
+ m_promotionTaskMenu(new qdesigner_internal::PromotionTaskMenu(this, qdesigner_internal::PromotionTaskMenu::ModeSingleWidget, this))
{
setContextMenuPolicy(Qt::DefaultContextMenu);
@@ -94,7 +67,7 @@ QDesignerMenuBar::QDesignerMenuBar(QWidget *parent) :
italic.setItalic(true);
m_addMenu->setFont(italic);
- m_editor->setObjectName(QStringLiteral("__qt__passive_editor"));
+ m_editor->setObjectName(u"__qt__passive_editor"_s);
m_editor->hide();
m_editor->installEventFilter(this);
installEventFilter(this);
@@ -110,7 +83,7 @@ void QDesignerMenuBar::paintEvent(QPaintEvent *event)
const auto &actionList = actions();
for (QAction *a : actionList) {
- if (qobject_cast<SpecialMenuAction*>(a)) {
+ if (qobject_cast<qdesigner_internal::SpecialMenuAction*>(a)) {
const QRect g = actionGeometry(a);
QLinearGradient lg(g.left(), g.top(), g.left(), g.bottom());
lg.setColorAt(0.0, Qt::transparent);
@@ -223,7 +196,7 @@ bool QDesignerMenuBar::handleKeyPressEvent(QWidget *, QKeyEvent *e)
break;
case Qt::Key_PageDown:
- m_currentIndex = actions().count() - 1;
+ m_currentIndex = actions().size() - 1;
break;
case Qt::Key_Enter:
@@ -287,6 +260,8 @@ bool QDesignerMenuBar::handleKeyPressEvent(QWidget *, QKeyEvent *e)
void QDesignerMenuBar::startDrag(const QPoint &pos)
{
+ using namespace qdesigner_internal;
+
const int index = findAction(pos);
if (m_currentIndex == -1 || index >= realActionCount())
return;
@@ -294,7 +269,7 @@ void QDesignerMenuBar::startDrag(const QPoint &pos)
QAction *action = safeActionAt(index);
QDesignerFormWindowInterface *fw = formWindow();
- RemoveActionFromCommand *cmd = new RemoveActionFromCommand(fw);
+ auto *cmd = new qdesigner_internal::RemoveActionFromCommand(fw);
cmd->init(this, action, actions().at(index + 1));
fw->commandHistory()->push(cmd);
@@ -310,7 +285,7 @@ void QDesignerMenuBar::startDrag(const QPoint &pos)
m_currentIndex = -1;
if (drag->exec(Qt::MoveAction) == Qt::IgnoreAction) {
- InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw);
+ auto *cmd = new qdesigner_internal::InsertActionIntoCommand(fw);
cmd->init(this, action, safeActionAt(index));
fw->commandHistory()->push(cmd);
@@ -365,7 +340,7 @@ bool QDesignerMenuBar::handleMouseMoveEvent(QWidget *, QMouseEvent *event)
return true;
const int index = actionIndexAt(this, m_startPosition, Qt::Horizontal);
- if (index < actions().count()) {
+ if (index < actions().size()) {
hideMenu(index);
update();
}
@@ -378,6 +353,8 @@ bool QDesignerMenuBar::handleMouseMoveEvent(QWidget *, QMouseEvent *event)
ActionList QDesignerMenuBar::contextMenuActions()
{
+ using namespace qdesigner_internal;
+
ActionList rc;
if (QAction *action = safeActionAt(m_currentIndex)) {
if (!qobject_cast<SpecialMenuAction*>(action)) {
@@ -412,9 +389,8 @@ bool QDesignerMenuBar::handleContextMenuEvent(QWidget *, QContextMenuEvent *even
QMenu menu;
const ActionList al = contextMenuActions();
- const ActionList::const_iterator acend = al.constEnd();
- for (ActionList::const_iterator it = al.constBegin(); it != acend; ++it)
- menu.addAction(*it);
+ for (auto *a : al)
+ menu.addAction(a);
menu.exec(event->globalPos());
return true;
}
@@ -425,7 +401,7 @@ void QDesignerMenuBar::slotRemoveMenuBar()
QDesignerFormWindowInterface *fw = formWindow();
- DeleteMenuBarCommand *cmd = new DeleteMenuBarCommand(fw);
+ auto *cmd = new qdesigner_internal::DeleteMenuBarCommand(fw);
cmd->init(this);
fw->commandHistory()->push(cmd);
}
@@ -444,6 +420,8 @@ void QDesignerMenuBar::enterEditMode()
void QDesignerMenuBar::leaveEditMode(LeaveEditMode mode)
{
+ using namespace qdesigner_internal;
+
m_editor->releaseKeyboard();
if (mode == Default)
@@ -462,20 +440,20 @@ void QDesignerMenuBar::leaveEditMode(LeaveEditMode mode)
fw->beginCommand(QApplication::translate("Command", "Change Title"));
} else {
fw->beginCommand(QApplication::translate("Command", "Insert Menu"));
- const QString niceObjectName = ActionEditor::actionTextToName(m_editor->text(), QStringLiteral("menu"));
- QMenu *menu = qobject_cast<QMenu*>(fw->core()->widgetFactory()->createWidget(QStringLiteral("QMenu"), this));
+ const QString niceObjectName = ActionEditor::actionTextToName(m_editor->text(), u"menu"_s);
+ QMenu *menu = qobject_cast<QMenu*>(fw->core()->widgetFactory()->createWidget(u"QMenu"_s, this));
fw->core()->widgetFactory()->initialize(menu);
menu->setObjectName(niceObjectName);
menu->setTitle(tr("Menu"));
fw->ensureUniqueObjectName(menu);
action = menu->menuAction();
- AddMenuActionCommand *cmd = new AddMenuActionCommand(fw);
+ auto *cmd = new qdesigner_internal::AddMenuActionCommand(fw);
cmd->init(action, m_addMenu, this, this);
fw->commandHistory()->push(cmd);
}
- SetPropertyCommand *cmd = new SetPropertyCommand(fw);
- cmd->init(action, QStringLiteral("text"), m_editor->text());
+ auto *cmd = new qdesigner_internal::SetPropertyCommand(fw);
+ cmd->init(action, u"text"_s, m_editor->text());
fw->commandHistory()->push(cmd);
fw->endCommand();
}
@@ -503,7 +481,7 @@ void QDesignerMenuBar::showLineEdit()
m_editor->selectAll();
m_editor->setGeometry(actionGeometry(action));
m_editor->show();
- qApp->setActiveWindow(m_editor);
+ m_editor->activateWindow();
m_editor->setFocus();
m_editor->grabKeyboard();
}
@@ -585,7 +563,7 @@ void QDesignerMenuBar::adjustIndicator(const QPoint &pos)
QDesignerMenuBar::ActionDragCheck QDesignerMenuBar::checkAction(QAction *action) const
{
// action belongs to another form
- if (!action || !Utils::isObjectAncestorOf(formWindow()->mainContainer(), action))
+ if (!action || !qdesigner_internal::Utils::isObjectAncestorOf(formWindow()->mainContainer(), action))
return NoActionDrag;
if (!action->menu())
@@ -603,7 +581,7 @@ QDesignerMenuBar::ActionDragCheck QDesignerMenuBar::checkAction(QAction *action)
void QDesignerMenuBar::dragEnterEvent(QDragEnterEvent *event)
{
- const ActionRepositoryMimeData *d = qobject_cast<const ActionRepositoryMimeData*>(event->mimeData());
+ auto *d = qobject_cast<const qdesigner_internal::ActionRepositoryMimeData*>(event->mimeData());
if (!d || d->actionList().isEmpty()) {
event->ignore();
return;
@@ -628,7 +606,7 @@ void QDesignerMenuBar::dragEnterEvent(QDragEnterEvent *event)
void QDesignerMenuBar::dragMoveEvent(QDragMoveEvent *event)
{
- const ActionRepositoryMimeData *d = qobject_cast<const ActionRepositoryMimeData*>(event->mimeData());
+ auto *d = qobject_cast<const qdesigner_internal::ActionRepositoryMimeData*>(event->mimeData());
if (!d || d->actionList().isEmpty()) {
event->ignore();
return;
@@ -661,16 +639,16 @@ void QDesignerMenuBar::dropEvent(QDropEvent *event)
{
m_dragging = false;
- if (const ActionRepositoryMimeData *d = qobject_cast<const ActionRepositoryMimeData*>(event->mimeData())) {
+ if (auto *d = qobject_cast<const qdesigner_internal::ActionRepositoryMimeData*>(event->mimeData())) {
QAction *action = d->actionList().first();
if (checkAction(action) == AcceptActionDrag) {
event->acceptProposedAction();
int index = findAction(event->position().toPoint());
- index = qMin(index, actions().count() - 1);
+ index = qMin(index, actions().size() - 1);
QDesignerFormWindowInterface *fw = formWindow();
- InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw);
+ auto *cmd = new qdesigner_internal::InsertActionIntoCommand(fw);
cmd->init(this, action, safeActionAt(index));
fw->commandHistory()->push(cmd);
@@ -705,7 +683,7 @@ QDesignerActionProviderExtension *QDesignerMenuBar::actionProvider()
QAction *QDesignerMenuBar::currentAction() const
{
- if (m_currentIndex < 0 || m_currentIndex >= actions().count())
+ if (m_currentIndex < 0 || m_currentIndex >= actions().size())
return nullptr;
return safeActionAt(m_currentIndex);
@@ -713,7 +691,7 @@ QAction *QDesignerMenuBar::currentAction() const
int QDesignerMenuBar::realActionCount() const
{
- return actions().count() - 1; // 1 fake actions
+ return actions().size() - 1; // 1 fake actions
}
bool QDesignerMenuBar::dragging() const
@@ -753,7 +731,7 @@ void QDesignerMenuBar::movePrevious(bool ctrl)
void QDesignerMenuBar::moveNext(bool ctrl)
{
const bool swapped = ctrl && swapActions(m_currentIndex + 1, m_currentIndex);
- const int newIndex = qMin(actions().count() - 1, m_currentIndex + 1);
+ const int newIndex = qMin(actions().size() - 1, m_currentIndex + 1);
if (swapped || newIndex != m_currentIndex) {
m_currentIndex = newIndex;
updateCurrentAction(!ctrl);
@@ -802,14 +780,14 @@ void QDesignerMenuBar::deleteMenu()
void QDesignerMenuBar::deleteMenuAction(QAction *action)
{
- if (action && !qobject_cast<SpecialMenuAction*>(action)) {
+ if (action && !qobject_cast<qdesigner_internal::SpecialMenuAction*>(action)) {
const int pos = actions().indexOf(action);
QAction *action_before = nullptr;
if (pos != -1)
action_before = safeActionAt(pos + 1);
QDesignerFormWindowInterface *fw = formWindow();
- RemoveMenuActionCommand *cmd = new RemoveMenuActionCommand(fw);
+ auto *cmd = new qdesigner_internal::RemoveMenuActionCommand(fw);
cmd->init(action, action_before, this, this);
fw->commandHistory()->push(cmd);
}
@@ -858,7 +836,7 @@ void QDesignerMenuBar::showMenu(int index)
QAction *QDesignerMenuBar::safeActionAt(int index) const
{
- if (index < 0 || index >= actions().count())
+ if (index < 0 || index >= actions().size())
return nullptr;
return actions().at(index);
@@ -866,6 +844,8 @@ QAction *QDesignerMenuBar::safeActionAt(int index) const
bool QDesignerMenuBar::swapActions(int a, int b)
{
+ using namespace qdesigner_internal;
+
const int left = qMin(a, b);
int right = qMax(a, b);
@@ -888,21 +868,21 @@ bool QDesignerMenuBar::swapActions(int a, int b)
QAction *action_b_before = safeActionAt(right + 1);
QDesignerFormWindowInterface *fw = formWindow();
- RemoveActionFromCommand *cmd1 = new RemoveActionFromCommand(fw);
+ auto *cmd1 = new qdesigner_internal::RemoveActionFromCommand(fw);
cmd1->init(this, action_b, action_b_before, false);
fw->commandHistory()->push(cmd1);
QAction *action_a_before = safeActionAt(left + 1);
- InsertActionIntoCommand *cmd2 = new InsertActionIntoCommand(fw);
+ auto *cmd2 = new qdesigner_internal::InsertActionIntoCommand(fw);
cmd2->init(this, action_b, action_a_before, false);
fw->commandHistory()->push(cmd2);
- RemoveActionFromCommand *cmd3 = new RemoveActionFromCommand(fw);
+ auto *cmd3 = new qdesigner_internal::RemoveActionFromCommand(fw);
cmd3->init(this, action_a, action_b, false);
fw->commandHistory()->push(cmd3);
- InsertActionIntoCommand *cmd4 = new InsertActionIntoCommand(fw);
+ auto *cmd4 = new qdesigner_internal::InsertActionIntoCommand(fw);
cmd4->init(this, action_a, action_b_before, true);
fw->commandHistory()->push(cmd4);
@@ -923,6 +903,8 @@ void QDesignerMenuBar::keyReleaseEvent(QKeyEvent *event)
void QDesignerMenuBar::updateCurrentAction(bool selectAction)
{
+ using namespace qdesigner_internal;
+
update();
if (!selectAction)