2019-02-14 12:18:16 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vmodifierkey.h
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 14 2, 2019
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentina project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2019 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2019-02-14 12:18:16 +01:00
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
#ifndef VMODIFIERKEY_H
|
|
|
|
#define VMODIFIERKEY_H
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A class that helps to deal efficiently with platform and localization issues
|
|
|
|
* of modifier keys.
|
|
|
|
*
|
|
|
|
* It is based on QKeySequence::toString(QKeySequence::NativeText) which provides
|
|
|
|
* localization and deals with swapping Ctrl and Cmd on Mac OS X. In contrast
|
|
|
|
* to QKeySequence, VModifierKey has an implicit operator for casting to QString,
|
|
|
|
* and it removes the trailing '+' from pseudo key sequences which consist of
|
|
|
|
* modifier keys only. Static methods provide efficient translations of the
|
|
|
|
* pure modifier keys.
|
|
|
|
*
|
|
|
|
* For true QKeySequences, call QKeySequence::toString(QKeySequence::NativeText)
|
|
|
|
* directly.
|
|
|
|
*
|
|
|
|
* On Windows and Linux, the keys will be displayed as word ("Shift" etc.).
|
|
|
|
* On OS X, the keys will be displayed as graphical symbols ("⇧", i.e.
|
|
|
|
* Unicode character U+21E7, etc.).
|
|
|
|
*
|
|
|
|
* Synopsis:
|
|
|
|
*
|
|
|
|
* QString text = tr("%1+Click to add a point.").arg(VModifierKey::control());
|
|
|
|
* QString more = tr("%1+Click to select a point.").arg(VModifierKey(Qt::ALT + Qt::ShiftModifier));
|
|
|
|
*
|
|
|
|
* // BUT:
|
|
|
|
* QString help = help_action.shortcut().toString(QKeySequence::NativeText);
|
|
|
|
*/
|
|
|
|
|
|
|
|
class VModifierKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** Constructs a new VModifierKey for the given combination of KeyboardModifiers. */
|
|
|
|
explicit VModifierKey(Qt::KeyboardModifiers keys);
|
|
|
|
|
|
|
|
/** Constructs a new VModifierKey for the given key. */
|
|
|
|
explicit VModifierKey(Qt::Key key);
|
|
|
|
|
|
|
|
/** Returns a string representation for user interface purposes.
|
|
|
|
*
|
|
|
|
* This operator is intented to be used for implicit type casts. */
|
2023-10-23 15:57:22 +02:00
|
|
|
operator QString() const; // NOLINT(google-explicit-constructor)
|
2019-02-14 12:18:16 +01:00
|
|
|
|
|
|
|
/** Returns a shared Alt modifier key. */
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto Alt() -> const VModifierKey &;
|
2019-02-14 12:18:16 +01:00
|
|
|
|
|
|
|
/** Returns a shared Control modifier key. */
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto Control() -> const VModifierKey &;
|
2019-02-14 12:18:16 +01:00
|
|
|
|
|
|
|
/** Returns a shared Control+Shift modifier key. */
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto ControlShift() -> const VModifierKey &;
|
2019-02-14 12:18:16 +01:00
|
|
|
|
|
|
|
/** Returns a shared Meta modifier key. */
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto Meta() -> const VModifierKey &;
|
2019-02-14 12:18:16 +01:00
|
|
|
|
|
|
|
/** Returns a shared Shift modifier key. */
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto Shift() -> const VModifierKey &;
|
2019-02-14 12:18:16 +01:00
|
|
|
|
|
|
|
/** Returns a shared Space key. */
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto Space() -> const VModifierKey &;
|
2019-02-14 12:18:16 +01:00
|
|
|
|
|
|
|
/** Returns a shared Return key. */
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto ReturnKey() -> const VModifierKey &;
|
2019-02-14 12:18:16 +01:00
|
|
|
|
|
|
|
/** Returns a shared Enter key. */
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto EnterKey() -> const VModifierKey &;
|
2019-02-14 12:18:16 +01:00
|
|
|
|
|
|
|
/** Returns a shared Backspace key. */
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto Backspace() -> const VModifierKey &;
|
2019-02-14 12:18:16 +01:00
|
|
|
|
|
|
|
/** Returns a shared Escape modifier key. */
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto Escape() -> const VModifierKey &;
|
2019-02-14 12:18:16 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/** Constructs a new VModifierKey for the given key. */
|
|
|
|
explicit VModifierKey(int key);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/** The native text (localized, adapted to the system). */
|
|
|
|
QString m_nativeText;
|
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline VModifierKey::operator QString() const
|
|
|
|
{
|
|
|
|
return m_nativeText;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // VMODIFIERKEY_H
|