Improve localization of modifier keys.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-02-14 13:18:16 +02:00
parent 43a914781f
commit 9b1cdb1848
14 changed files with 305 additions and 45 deletions

View File

@ -40,6 +40,7 @@
#include "../vmisc/vsettings.h"
#include "../vmisc/def.h"
#include "../vmisc/qxtcsvmodel.h"
#include "../vmisc/vmodifierkey.h"
#include "undocommands/renamepp.h"
#include "core/vtooloptionspropertybrowser.h"
#include "options.h"
@ -113,10 +114,6 @@ namespace
{
Q_GLOBAL_STATIC_WITH_ARGS(const QString, autosavePrefix, (QLatin1String(".autosave")))
// String below need for getting translation for key Ctrl
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strQShortcut, (QLatin1String("QShortcut"))) // Context
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strCtrl, (QLatin1String("Ctrl"))) // String
//---------------------------------------------------------------------------------------------------------------------
QVector<DetailForLayout> SortDetailsForLayout(const QHash<quint32, VPiece> *allDetails,
const QString &nameRegex = QString())
@ -1021,7 +1018,8 @@ void MainWindow::ToolPiecePath(bool checked)
{
ToolSelectAllDrawObjects();
SetToolButton<DialogPiecePath>(checked, Tool::PiecePath, QStringLiteral("://cursor/path_cursor.png"),
tr("Select path objects, <b>Shift</b> - reverse direction curve"),
tr("Select path objects, <b>%1</b> - reverse direction curve")
.arg(VModifierKey::Shift()),
&MainWindow::ClosedDialogPiecePath);
}
@ -1136,8 +1134,8 @@ void MainWindow::ToolGroup(bool checked)
{
ToolSelectGroupObjects();
const QString tooltip = tr("Select one or more objects, hold <b>%1</b> - for multiple selection, "
"<b>Enter</b> - finish creation")
.arg(QCoreApplication::translate(strQShortcut->toUtf8().constData(), strCtrl->toUtf8().constData()));
"<b>%2</b> - finish creation")
.arg(VModifierKey::Control(), VModifierKey::EnterKey());
SetToolButton<DialogGroup>(checked, Tool::Group, QStringLiteral(":/cursor/group_plus_cursor.png"), tooltip,
&MainWindow::ClosedDialogGroup);
}
@ -1147,8 +1145,8 @@ void MainWindow::ToolRotation(bool checked)
{
ToolSelectOperationObjects();
const QString tooltip = tr("Select one or more objects, hold <b>%1</b> - for multiple selection, "
"<b>Enter</b> - confirm selection")
.arg(QCoreApplication::translate(strQShortcut->toUtf8().constData(), strCtrl->toUtf8().constData()));
"<b>%2</b> - confirm selection")
.arg(VModifierKey::Control(), VModifierKey::EnterKey());
SetToolButtonWithApply<DialogRotation>(checked, Tool::Rotation, QStringLiteral(":/cursor/rotation_cursor.png"),
tooltip, &MainWindow::ClosedDrawDialogWithApply<VToolRotation>,
&MainWindow::ApplyDrawDialog<VToolRotation>);
@ -1159,8 +1157,8 @@ void MainWindow::ToolFlippingByLine(bool checked)
{
ToolSelectOperationObjects();
const QString tooltip = tr("Select one or more objects, hold <b>%1</b> - for multiple selection, "
"<b>Enter</b> - confirm selection")
.arg(QCoreApplication::translate(strQShortcut->toUtf8().constData(), strCtrl->toUtf8().constData()));
"<b>%2</b> - confirm selection")
.arg(VModifierKey::Control(), VModifierKey::EnterKey());
SetToolButtonWithApply<DialogFlippingByLine>(checked, Tool::FlippingByLine, ":/cursor/flipping_line_cursor.png",
tooltip, &MainWindow::ClosedDrawDialogWithApply<VToolFlippingByLine>,
&MainWindow::ApplyDrawDialog<VToolFlippingByLine>);
@ -1171,8 +1169,8 @@ void MainWindow::ToolFlippingByAxis(bool checked)
{
ToolSelectOperationObjects();
const QString tooltip = tr("Select one or more objects, hold <b>%1</b> - for multiple selection, "
"<b>Enter</b> - confirm selection")
.arg(QCoreApplication::translate(strQShortcut->toUtf8().constData(), strCtrl->toUtf8().constData()));
"<b>%2</b> - confirm selection")
.arg(VModifierKey::Control(), VModifierKey::EnterKey());
SetToolButtonWithApply<DialogFlippingByAxis>(checked, Tool::FlippingByAxis, ":/cursor/flipping_axis_cursor.png",
tooltip, &MainWindow::ClosedDrawDialogWithApply<VToolFlippingByAxis>,
&MainWindow::ApplyDrawDialog<VToolFlippingByAxis>);
@ -1183,8 +1181,8 @@ void MainWindow::ToolMove(bool checked)
{
ToolSelectOperationObjects();
const QString tooltip = tr("Select one or more objects, hold <b>%1</b> - for multiple selection, "
"<b>Enter</b> - confirm selection")
.arg(QCoreApplication::translate(strQShortcut->toUtf8().constData(), strCtrl->toUtf8().constData()));
"<b>%2</b> - confirm selection")
.arg(VModifierKey::Control(), VModifierKey::EnterKey());
SetToolButtonWithApply<DialogMove>(checked, Tool::Move, ":/cursor/move_cursor.png", tooltip,
&MainWindow::ClosedDrawDialogWithApply<VToolMove>,
&MainWindow::ApplyDrawDialog<VToolMove>);

View File

@ -12,7 +12,8 @@ SOURCES += \
$$PWD/qxtcsvmodel.cpp \
$$PWD/vtablesearch.cpp \
$$PWD/dialogs/dialogexporttocsv.cpp \
$$PWD/literals.cpp
$$PWD/literals.cpp \
$$PWD/vmodifierkey.cpp
*msvc*:SOURCES += $$PWD/stable.cpp
@ -40,7 +41,8 @@ HEADERS += \
$$PWD/testvapplication.h \
$$PWD/literals.h \
$$PWD/qt_dispatch/qt_dispatch.h \
$$PWD/vdatastreamenum.h
$$PWD/vdatastreamenum.h \
$$PWD/vmodifierkey.h
# Qt's versions
# 5.2.0, 5.2.1

View File

@ -0,0 +1,124 @@
/************************************************************************
**
** @file vmodifierkey.cpp
** @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
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** 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/>.
**
*************************************************************************/
#include "vmodifierkey.h"
#include <QKeySequence>
//---------------------------------------------------------------------------------------------------------------------
VModifierKey::VModifierKey(int key)
: m_nativeText(QKeySequence(static_cast<int>(key)).toString(QKeySequence::NativeText))
{
if (m_nativeText.endsWith(QLatin1Char('+')))
{
m_nativeText.chop(1);
}
}
//---------------------------------------------------------------------------------------------------------------------
VModifierKey::VModifierKey(Qt::KeyboardModifiers keys)
: VModifierKey(static_cast<int>(keys))
{
// nothing else
}
//---------------------------------------------------------------------------------------------------------------------
VModifierKey::VModifierKey(Qt::Key key)
: VModifierKey(static_cast<int>(key))
{
// nothing else
}
//---------------------------------------------------------------------------------------------------------------------
const VModifierKey& VModifierKey::Alt()
{
static const VModifierKey key(Qt::AltModifier);
return key;
}
//---------------------------------------------------------------------------------------------------------------------
const VModifierKey& VModifierKey::Control()
{
static const VModifierKey key(Qt::ControlModifier);
return key;
}
//---------------------------------------------------------------------------------------------------------------------
const VModifierKey& VModifierKey::ControlShift()
{
static const VModifierKey key(Qt::ControlModifier | Qt::ShiftModifier);
return key;
}
//---------------------------------------------------------------------------------------------------------------------
const VModifierKey& VModifierKey::Meta()
{
static const VModifierKey key(Qt::MetaModifier);
return key;
}
//---------------------------------------------------------------------------------------------------------------------
const VModifierKey& VModifierKey::Shift()
{
static const VModifierKey key(Qt::ShiftModifier);
return key;
}
//---------------------------------------------------------------------------------------------------------------------
const VModifierKey& VModifierKey::Space()
{
static const VModifierKey key(Qt::Key_Space);
return key;
}
//---------------------------------------------------------------------------------------------------------------------
const VModifierKey& VModifierKey::ReturnKey()
{
static const VModifierKey key(Qt::Key_Return);
return key;
}
//---------------------------------------------------------------------------------------------------------------------
const VModifierKey &VModifierKey::EnterKey()
{
static const VModifierKey key(Qt::Key_Enter);
return key;
}
//---------------------------------------------------------------------------------------------------------------------
const VModifierKey& VModifierKey::Backspace()
{
static const VModifierKey key(Qt::Key_Backspace);
return key;
}
//---------------------------------------------------------------------------------------------------------------------
const VModifierKey& VModifierKey::Escape()
{
static const VModifierKey key(Qt::Key_Escape);
return key;
}

View File

@ -0,0 +1,119 @@
/************************************************************************
**
** @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
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** 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. */
operator QString() const;
/** Returns a shared Alt modifier key. */
static const VModifierKey& Alt();
/** Returns a shared Control modifier key. */
static const VModifierKey& Control();
/** Returns a shared Control+Shift modifier key. */
static const VModifierKey& ControlShift();
/** Returns a shared Meta modifier key. */
static const VModifierKey& Meta();
/** Returns a shared Shift modifier key. */
static const VModifierKey& Shift();
/** Returns a shared Space key. */
static const VModifierKey& Space();
/** Returns a shared Return key. */
static const VModifierKey& ReturnKey();
/** Returns a shared Enter key. */
static const VModifierKey& EnterKey();
/** Returns a shared Backspace key. */
static const VModifierKey& Backspace();
/** Returns a shared Escape modifier key. */
static const VModifierKey& Escape();
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

View File

@ -33,6 +33,7 @@
#include "../../../tools/vabstracttool.h"
#include "../../../tools/vtoolseamallowance.h"
#include "../../support/dialogeditwrongformula.h"
#include "../vmisc/vmodifierkey.h"
#include <QMenu>
#include <QTimer>
@ -171,8 +172,9 @@ void DialogPiecePath::ChosenObject(quint32 id, const SceneObject &type)
if (p.CountNodes() == 1)
{
emit ToolTip(tr("Select main path objects, <b>Shift</b> - reverse direction curve, "
"<b>Enter</b> - finish creation"));
emit ToolTip(tr("Select main path objects, <b>%1</b> - reverse direction curve, "
"<b>%2</b> - finish creation")
.arg(VModifierKey::Shift(), VModifierKey::EnterKey()));
if (not qApp->getCurrentScene()->items().contains(visPath))
{

View File

@ -49,6 +49,7 @@
#include "../../../tools/vtoolseamallowance.h"
#include "../vgeometry/vplacelabelitem.h"
#include "../../dialogtoolbox.h"
#include "../vmisc/vmodifierkey.h"
#include <QMenu>
#include <QTimer>
@ -430,8 +431,9 @@ void DialogSeamAllowance::ChosenObject(quint32 id, const SceneObject &type)
if (p.GetPath().CountNodes() == 1)
{
emit ToolTip(tr("Select main path objects clockwise, <b>Shift</b> - reverse direction curve, "
"<b>Enter</b> - finish creation"));
emit ToolTip(tr("Select main path objects clockwise, <b>%1</b> - reverse direction curve, "
"<b>%2</b> - finish creation")
.arg(VModifierKey::Shift(), VModifierKey::EnterKey()));
if (not qApp->getCurrentScene()->items().contains(visPath))
{

View File

@ -41,6 +41,7 @@
#include "../ifc/xml/vdomdocument.h"
#include "../vmisc/diagnostic.h"
#include "../vmisc/vmodifierkey.h"
#include "../vgeometry/vabstractcurve.h"
#include "../vgeometry/varc.h"
#include "../vgeometry/vcubicbezier.h"
@ -172,26 +173,22 @@ void VisToolMove::RefreshGeometry()
static const QString prefix = UnitsToStr(qApp->patternUnit(), true);
if (qFuzzyIsNull(length))
{
Visualization::toolTip = tr("Length = %1%2, angle = %3°, <b>Shift</b> - sticking angle, "
Visualization::toolTip = tr("Length = %1%2, angle = %3°, <b>%4</b> - sticking angle, "
"<b>Mouse click</b> - finish selecting a position")
.arg(qApp->TrVars()->FormulaToUser(QString::number(qApp->fromPixel(tempLength)),
qApp->Settings()->GetOsSeparator()), prefix)
.arg(tempAngle);
.arg(tempAngle)
.arg(VModifierKey::Shift());
}
else
{
// String below need for getting translation for key Ctrl
// Translation comes from Qt library. Use variables to prevent adding to our translation files.
const QString strQShortcut = QStringLiteral("QShortcut"); // Context
const QString strCtrl = QStringLiteral("Ctrl"); // String
Visualization::toolTip = tr("Length = %1%2, angle = %3°, rotation angle = %4°, <b>Shift</b> - sticking angle, "
"<b>%5</b> - change rotation origin point, <b>Mouse click</b> - finish creating")
Visualization::toolTip = tr("Length = %1%2, angle = %3°, rotation angle = %4°, <b>%5</b> - sticking angle, "
"<b>%6</b> - change rotation origin point, <b>Mouse click</b> - finish creating")
.arg(qApp->TrVars()->FormulaToUser(QString::number(qApp->fromPixel(tempLength)),
qApp->Settings()->GetOsSeparator()), prefix)
.arg(tempAngle)
.arg(tempRoationAngle)
.arg(QCoreApplication::translate(strQShortcut.toUtf8().constData(), strCtrl.toUtf8().constData()));
.arg(VModifierKey::Shift(), VModifierKey::Control());
}
CreateMovedRotatedObjects(iPoint, iCurve, tempLength, tempAngle, tempRoationAngle, origin);

View File

@ -40,6 +40,7 @@
#include <new>
#include "../vmisc/diagnostic.h"
#include "../vmisc/vmodifierkey.h"
#include "../vgeometry/vabstractcurve.h"
#include "../vgeometry/varc.h"
#include "../vgeometry/vcubicbezier.h"
@ -119,8 +120,10 @@ void VisToolRotation::RefreshGeometry()
VArc arc(*origin, ScaledRadius(SceneScale(qApp->getCurrentScene()))*2, 0, tempAngle);
DrawPath(angleArc, arc.GetPath(), supportColor2, Qt::SolidLine, Qt::RoundCap);
Visualization::toolTip = tr("Rotating angle = %1°, <b>Shift</b> - sticking angle, "
"<b>Mouse click</b> - finish creation").arg(tempAngle);
Visualization::toolTip = tr("Rotating angle = %1°, <b>%2</b> - sticking angle, "
"<b>Mouse click</b> - finish creation")
.arg(tempAngle)
.arg(VModifierKey::Shift());
}
int iPoint = -1;

View File

@ -45,6 +45,7 @@
#include "../vpatterndb/vcontainer.h"
#include "../visualization.h"
#include "visline.h"
#include "../vmisc/vmodifierkey.h"
//---------------------------------------------------------------------------------------------------------------------
VisToolCurveIntersectAxis::VisToolCurveIntersectAxis(const VContainer *data, QGraphicsItem *parent)
@ -90,9 +91,10 @@ void VisToolCurveIntersectAxis::RefreshGeometry()
DrawPoint(point, p, mainColor);
Visualization::toolTip = tr("<b>Intersection curve and axis</b>: angle = %1°; <b>Shift</b> - "
"sticking angle, <b>Enter</b> - finish creation")
.arg(this->line().angle());
Visualization::toolTip = tr("<b>Intersection curve and axis</b>: angle = %1°; <b>%2</b> - "
"sticking angle, <b>%3</b> - finish creation")
.arg(this->line().angle())
.arg(VModifierKey::Shift(), VModifierKey::EnterKey());
}
}
}

View File

@ -41,6 +41,7 @@
#include "../vgeometry/vpointf.h"
#include "../vmisc/vabstractapplication.h"
#include "../vmisc/vcommonsettings.h"
#include "../vmisc/vmodifierkey.h"
#include "../vpatterndb/vcontainer.h"
#include "../visualization.h"
#include "visline.h"
@ -80,10 +81,11 @@ void VisToolEndLine::RefreshGeometry()
DrawLine(this, line, mainColor, lineStyle);
static const QString prefix = UnitsToStr(qApp->patternUnit(), true);
Visualization::toolTip = tr("<b>Point at distance and angle</b>: angle = %1°, length = %2%3; "
"<b>Shift</b> - sticking angle, <b>Enter</b> - finish creation")
"<b>%4</b> - sticking angle, <b>%5</b> - finish creation")
.arg(this->line().angle())
.arg(qApp->TrVars()->FormulaToUser(QString::number(qApp->fromPixel(this->line().length())),
qApp->Settings()->GetOsSeparator()), prefix);
qApp->Settings()->GetOsSeparator()),
prefix, VModifierKey::Shift(), VModifierKey::EnterKey());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -42,6 +42,7 @@
#include "../vpatterndb/vcontainer.h"
#include "../visualization.h"
#include "visline.h"
#include "../vmisc/vmodifierkey.h"
//---------------------------------------------------------------------------------------------------------------------
VisToolLineIntersectAxis::VisToolLineIntersectAxis(const VContainer *data, QGraphicsItem *parent)
@ -102,9 +103,10 @@ void VisToolLineIntersectAxis::RefreshGeometry()
DrawPoint(point, p, mainColor);
ShowIntersection(axis_line, base_line);
Visualization::toolTip = tr("<b>Intersection line and axis</b>: angle = %1°; <b>Shift</b> - "
"sticking angle, <b>Enter</b> - finish creation")
.arg(this->line().angle());
Visualization::toolTip = tr("<b>Intersection line and axis</b>: angle = %1°; <b>%2</b> - "
"sticking angle, <b>%3</b> - finish creation")
.arg(this->line().angle())
.arg(VModifierKey::Shift(), VModifierKey::EnterKey());
}
}
}

View File

@ -42,6 +42,7 @@
#include "../visualization.h"
#include "vispath.h"
#include "../vwidgets/scalesceneitems.h"
#include "../vmisc/vmodifierkey.h"
//---------------------------------------------------------------------------------------------------------------------
VisToolCubicBezierPath::VisToolCubicBezierPath(const VContainer *data, QGraphicsItem *parent)
@ -286,7 +287,8 @@ void VisToolCubicBezierPath::RefreshToolTip()
else if (size - VCubicBezierPath::SubSplPointsCount(countSubSpl) == 0)
{
Visualization::toolTip = tr("<b>Curved path</b>: select seven or more points, "
"<b>Enter</b> - finish creation");
"<b>%1</b> - finish creation")
.arg(VModifierKey::EnterKey());
}
else
{

View File

@ -44,6 +44,7 @@
#include "../vwidgets/scalesceneitems.h"
#include "../visualization.h"
#include "vispath.h"
#include "../vmisc/vmodifierkey.h"
const int EMPTY_ANGLE = -1;
@ -170,7 +171,8 @@ void VisToolSpline::RefreshGeometry()
VSpline spline(*first, *second, angle1, angle2, kAsm1, kAsm2, kCurve);
spline.SetApproximationScale(m_approximationScale);
DrawPath(this, spline.GetPath(), spline.DirectionArrows(), mainColor, lineStyle, Qt::RoundCap);
Visualization::toolTip = tr("Use <b>Shift</b> for sticking angle!");
Visualization::toolTip = tr("Use <b>%1</b> for sticking angle!")
.arg(VModifierKey::Shift());
emit ToolTip(Visualization::toolTip);
}
}

View File

@ -45,6 +45,7 @@
#include "../vwidgets/scalesceneitems.h"
#include "../visualization.h"
#include "vispath.h"
#include "../vmisc/vmodifierkey.h"
//---------------------------------------------------------------------------------------------------------------------
VisToolSplinePath::VisToolSplinePath(const VContainer *data, QGraphicsItem *parent)
@ -115,11 +116,13 @@ void VisToolSplinePath::RefreshGeometry()
else
{
Visualization::toolTip = tr("<b>Curved path</b>: select three or more points, "
"<b>Enter</b> - finish creation");
"<b>%1</b> - finish creation")
.arg(VModifierKey::EnterKey());
}
if (mode == Mode::Show)
{
Visualization::toolTip = tr("Use <b>Shift</b> for sticking angle!");
Visualization::toolTip = tr("Use <b>%1</b> for sticking angle!")
.arg(VModifierKey::Shift());
emit ToolTip(Visualization::toolTip);
}
}