Files
qt-creator/src/libs/utils/proxyaction.h
Eike Ziller 3c5650e514 Add macOS touch bar support
Introduce a generic Utils::TouchBar that implements a touch bar for
macOS based on QAction. Touch bars can be nested, and one is set to be
the application's top level touch bar.

Also add an ActionContainer for the touch bar. That allows us to manage
the layout of the touch bar the same way we do with menus.

Since the touch bar is an input device with very limited space, a
command in the touch bar needs to be specifically styled for the touch
bar by setting either touchBarText or touchBarIcon (or both).

Touch bars can be nested by nesting the ActionContainers. A nested touch
bar ActionContainer needs to specify an icon and/or text to show in the
touch bar button that opens that sub-bar.

Commands are only shown in the touch bar if they are valid within the
current context.

Implementation-wise we cannot use the standard NSPopoverTouchBarItem for
nesting touch bar levels. We cannot hide items in the touch bar, because
hidden items still take up space in the touch bar. So we need to rebuild
the touch bar regularly. Since the items we show are very dynamic, every
time the items in the toplevel bar change because of a context change,
any opened sub-level touch bar closes. That is why we maintain a stack of
touch bar levels ourselves, replacing the main touch bar with the current
level, and managing opening and closing the levels manually.

This patch adds buttons for Help, Bookmarks, Header/Source, Follow
(Symbol), Decl/Def, and a sub-bar for the debugger actions.

Fixes: QTCREATORBUG-21263
Change-Id: Ib63e610f21a993f1d324fe23c83a7f2224f434ac
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
2019-01-15 14:33:56 +00:00

84 lines
2.5 KiB
C++

/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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.
**
****************************************************************************/
#pragma once
#include "utils_global.h"
#include <QPointer>
#include <QAction>
namespace Utils {
class QTCREATOR_UTILS_EXPORT ProxyAction : public QAction
{
Q_OBJECT
public:
enum Attribute {
Hide = 0x01,
UpdateText = 0x02,
UpdateIcon = 0x04
};
Q_DECLARE_FLAGS(Attributes, Attribute)
explicit ProxyAction(QObject *parent = nullptr);
void initialize(QAction *action);
void setAction(QAction *action);
QAction *action() const;
bool shortcutVisibleInToolTip() const;
void setShortcutVisibleInToolTip(bool visible);
void setAttribute(Attribute attribute);
void removeAttribute(Attribute attribute);
bool hasAttribute(Attribute attribute);
static QString stringWithAppendedShortcut(const QString &str, const QKeySequence &shortcut);
static ProxyAction *proxyActionWithIcon(QAction *original, const QIcon &newIcon);
signals:
void currentActionChanged(QAction *action);
private:
void actionChanged();
void updateState();
void updateToolTipWithKeySequence();
void disconnectAction();
void connectAction();
void update(QAction *action, bool initialize);
QPointer<QAction> m_action;
Attributes m_attributes;
bool m_showShortcut = false;
QString m_toolTip;
bool m_block = false;
};
} // namespace Utils
Q_DECLARE_OPERATORS_FOR_FLAGS(Utils::ProxyAction::Attributes)