iOS: refactor removeMnemonics(const QString &) to QPlatformTheme
This function is needed across several OS', so refactor it out to a common place. Change-Id: I35b957029c965672739d03cd2db3e87f5bd0acdf Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
This commit is contained in:
parent
c5239ec12d
commit
b63160b079
@ -682,6 +682,41 @@ QString QPlatformTheme::defaultStandardButtonText(int button)
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString QPlatformTheme::removeMnemonics(const QString &original)
|
||||
{
|
||||
QString returnText(original.size(), 0);
|
||||
int finalDest = 0;
|
||||
int currPos = 0;
|
||||
int l = original.length();
|
||||
while (l) {
|
||||
if (original.at(currPos) == QLatin1Char('&')
|
||||
&& (l == 1 || original.at(currPos + 1) != QLatin1Char('&'))) {
|
||||
++currPos;
|
||||
--l;
|
||||
if (l == 0)
|
||||
break;
|
||||
} else if (original.at(currPos) == QLatin1Char('(') && l >= 4 &&
|
||||
original.at(currPos + 1) == QLatin1Char('&') &&
|
||||
original.at(currPos + 2) != QLatin1Char('&') &&
|
||||
original.at(currPos + 3) == QLatin1Char(')')) {
|
||||
/* remove mnemonics its format is "\s*(&X)" */
|
||||
int n = 0;
|
||||
while (finalDest > n && returnText.at(finalDest - n - 1).isSpace())
|
||||
++n;
|
||||
finalDest -= n;
|
||||
currPos += 4;
|
||||
l -= 4;
|
||||
continue;
|
||||
}
|
||||
returnText[finalDest] = original.at(currPos);
|
||||
++currPos;
|
||||
++finalDest;
|
||||
--l;
|
||||
}
|
||||
returnText.truncate(finalDest);
|
||||
return returnText;
|
||||
}
|
||||
|
||||
unsigned QPlatformThemePrivate::currentKeyPlatforms()
|
||||
{
|
||||
const uint keyboardScheme = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::KeyboardScheme).toInt();
|
||||
|
@ -301,6 +301,7 @@ public:
|
||||
|
||||
static QVariant defaultThemeHint(ThemeHint hint);
|
||||
static QString defaultStandardButtonText(int button);
|
||||
static QString removeMnemonics(const QString &original);
|
||||
|
||||
protected:
|
||||
explicit QPlatformTheme(QPlatformThemePrivate *priv);
|
||||
|
@ -31,13 +31,13 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qcocoacolordialoghelper.h"
|
||||
|
||||
#ifndef QT_NO_COLORDIALOG
|
||||
|
||||
#include <QtCore/qdebug.h>
|
||||
#include <QtCore/qtimer.h>
|
||||
#include <qpa/qplatformtheme.h>
|
||||
|
||||
#include "qcocoacolordialoghelper.h"
|
||||
#include "qcocoahelpers.h"
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
@ -52,7 +52,7 @@ static NSButton *macCreateButton(const char *text, NSView *superview)
|
||||
[button setButtonType:NSMomentaryLightButton];
|
||||
[button setBezelStyle:NSRoundedBezelStyle];
|
||||
[button setTitle:(NSString*)(CFStringRef)QCFString(
|
||||
qt_mac_removeMnemonics(QCoreApplication::translate("QDialogButtonBox", text)))];
|
||||
QPlatformTheme::removeMnemonics(QCoreApplication::translate("QDialogButtonBox", text)))];
|
||||
[[button cell] setFont:[NSFont systemFontOfSize:
|
||||
[NSFont systemFontSizeForControlSize:NSRegularControlSize]]];
|
||||
[superview addSubview:button];
|
||||
|
@ -31,6 +31,8 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <qpa/qplatformtheme.h>
|
||||
|
||||
#include "qcocoafiledialoghelper.h"
|
||||
|
||||
#ifndef QT_NO_FILEDIALOG
|
||||
@ -180,7 +182,7 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSOpenSavePanelDelegate);
|
||||
static QString strippedText(QString s)
|
||||
{
|
||||
s.remove( QString::fromLatin1("...") );
|
||||
return qt_mac_removeMnemonics(s).trimmed();
|
||||
return QPlatformTheme::removeMnemonics(s).trimmed();
|
||||
}
|
||||
|
||||
- (NSString *)strip:(const QString &)label
|
||||
|
@ -31,17 +31,17 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qcocoafontdialoghelper.h"
|
||||
|
||||
#ifndef QT_NO_FONTDIALOG
|
||||
|
||||
#include <QtCore/qtimer.h>
|
||||
#include <QtGui/qfontdatabase.h>
|
||||
#include <qpa/qplatformtheme.h>
|
||||
|
||||
#include <private/qfont_p.h>
|
||||
#include <private/qfontengine_p.h>
|
||||
#include <private/qfontengine_coretext_p.h>
|
||||
|
||||
#include "qcocoafontdialoghelper.h"
|
||||
#include "qcocoahelpers.h"
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
@ -72,7 +72,7 @@ static NSButton *macCreateButton(const char *text, NSView *superview)
|
||||
[button setButtonType:NSMomentaryLightButton];
|
||||
[button setBezelStyle:NSRoundedBezelStyle];
|
||||
[button setTitle:(NSString*)(CFStringRef)QCFString(
|
||||
qt_mac_removeMnemonics(QCoreApplication::translate("QDialogButtonBox", text)))];
|
||||
QPlatformTheme::removeMnemonics(QCoreApplication::translate("QDialogButtonBox", text)))];
|
||||
[[button cell] setFont:[NSFont systemFontOfSize:
|
||||
[NSFont systemFontSizeForControlSize:NSRegularControlSize]]];
|
||||
[superview addSubview:button];
|
||||
|
@ -90,7 +90,6 @@ Qt::DropActions qt_mac_mapNSDragOperations(NSDragOperation nsActions);
|
||||
|
||||
// Misc
|
||||
void qt_mac_transformProccessToForegroundApplication();
|
||||
QString qt_mac_removeMnemonics(const QString &original);
|
||||
CGColorSpaceRef qt_mac_genericColorSpace();
|
||||
CGColorSpaceRef qt_mac_displayColorSpace(const QWidget *widget);
|
||||
CGColorSpaceRef qt_mac_colorSpaceForDeviceType(const QPaintDevice *paintDevice);
|
||||
|
@ -31,6 +31,8 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <qpa/qplatformtheme.h>
|
||||
|
||||
#include "qcocoahelpers.h"
|
||||
|
||||
|
||||
@ -485,42 +487,6 @@ void qt_mac_transformProccessToForegroundApplication()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString qt_mac_removeMnemonics(const QString &original)
|
||||
{
|
||||
QString returnText(original.size(), 0);
|
||||
int finalDest = 0;
|
||||
int currPos = 0;
|
||||
int l = original.length();
|
||||
while (l) {
|
||||
if (original.at(currPos) == QLatin1Char('&')
|
||||
&& (l == 1 || original.at(currPos + 1) != QLatin1Char('&'))) {
|
||||
++currPos;
|
||||
--l;
|
||||
if (l == 0)
|
||||
break;
|
||||
} else if (original.at(currPos) == QLatin1Char('(') && l >= 4 &&
|
||||
original.at(currPos + 1) == QLatin1Char('&') &&
|
||||
original.at(currPos + 2) != QLatin1Char('&') &&
|
||||
original.at(currPos + 3) == QLatin1Char(')')) {
|
||||
/* remove mnemonics its format is "\s*(&X)" */
|
||||
int n = 0;
|
||||
while (finalDest > n && returnText.at(finalDest - n - 1).isSpace())
|
||||
++n;
|
||||
finalDest -= n;
|
||||
currPos += 4;
|
||||
l -= 4;
|
||||
continue;
|
||||
}
|
||||
returnText[finalDest] = original.at(currPos);
|
||||
++currPos;
|
||||
++finalDest;
|
||||
--l;
|
||||
}
|
||||
returnText.truncate(finalDest);
|
||||
return returnText;
|
||||
}
|
||||
|
||||
static CGColorSpaceRef m_genericColorSpace = 0;
|
||||
static QHash<CGDirectDisplayID, CGColorSpaceRef> m_displayColorSpaceHash;
|
||||
static bool m_postRoutineRegistered = false;
|
||||
@ -774,7 +740,7 @@ bool qt_mac_execute_apple_script(const QString &script, AEDesc *ret)
|
||||
|
||||
QString qt_mac_removeAmpersandEscapes(QString s)
|
||||
{
|
||||
return qt_mac_removeMnemonics(s).trimmed();
|
||||
return QPlatformTheme::removeMnemonics(s).trimmed();
|
||||
}
|
||||
|
||||
/*! \internal
|
||||
|
@ -31,6 +31,8 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <qpa/qplatformtheme.h>
|
||||
|
||||
#include "qcocoamenuitem.h"
|
||||
|
||||
#include "qcocoamenu.h"
|
||||
@ -316,7 +318,7 @@ NSMenuItem *QCocoaMenuItem::sync()
|
||||
if (accel.count() > 1)
|
||||
text += QLatin1String(" (") + accel.toString(QKeySequence::NativeText) + QLatin1String(")");
|
||||
|
||||
QString finalString = qt_mac_removeMnemonics(text);
|
||||
QString finalString = QPlatformTheme::removeMnemonics(text);
|
||||
bool useAttributedTitle = false;
|
||||
// Cocoa Font and title
|
||||
if (m_font.resolve()) {
|
||||
|
@ -103,8 +103,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
QString qt_mac_removeMnemonics(const QString &original); //implemented in qmacstyle_mac.cpp
|
||||
|
||||
class Q_WIDGETS_EXPORT QMacWindowChangeEvent
|
||||
{
|
||||
private:
|
||||
|
@ -74,9 +74,6 @@ public:
|
||||
bool m_separator;
|
||||
QIOSMenu *m_menu;
|
||||
QKeySequence m_shortcut;
|
||||
|
||||
private:
|
||||
QString removeMnemonics(const QString &original);
|
||||
};
|
||||
|
||||
typedef QList<QIOSMenuItem *> QIOSMenuItemList;
|
||||
|
@ -33,6 +33,7 @@
|
||||
|
||||
#include <qglobal.h>
|
||||
#include <qguiapplication.h>
|
||||
#include <qpa/qplatformtheme.h>
|
||||
|
||||
#include "qiosglobal.h"
|
||||
#include "qiosmenu.h"
|
||||
@ -254,7 +255,7 @@ quintptr QIOSMenuItem::tag() const
|
||||
|
||||
void QIOSMenuItem::setText(const QString &text)
|
||||
{
|
||||
m_text = removeMnemonics(text);
|
||||
m_text = QPlatformTheme::removeMnemonics(text);
|
||||
}
|
||||
|
||||
void QIOSMenuItem::setMenu(QPlatformMenu *menu)
|
||||
@ -287,41 +288,6 @@ void QIOSMenuItem::setEnabled(bool enabled)
|
||||
m_enabled = enabled;
|
||||
}
|
||||
|
||||
QString QIOSMenuItem::removeMnemonics(const QString &original)
|
||||
{
|
||||
// Copied from qcocoahelpers
|
||||
QString returnText(original.size(), 0);
|
||||
int finalDest = 0;
|
||||
int currPos = 0;
|
||||
int l = original.length();
|
||||
while (l) {
|
||||
if (original.at(currPos) == QLatin1Char('&')
|
||||
&& (l == 1 || original.at(currPos + 1) != QLatin1Char('&'))) {
|
||||
++currPos;
|
||||
--l;
|
||||
if (l == 0)
|
||||
break;
|
||||
} else if (original.at(currPos) == QLatin1Char('(') && l >= 4 &&
|
||||
original.at(currPos + 1) == QLatin1Char('&') &&
|
||||
original.at(currPos + 2) != QLatin1Char('&') &&
|
||||
original.at(currPos + 3) == QLatin1Char(')')) {
|
||||
/* remove mnemonics its format is "\s*(&X)" */
|
||||
int n = 0;
|
||||
while (finalDest > n && returnText.at(finalDest - n - 1).isSpace())
|
||||
++n;
|
||||
finalDest -= n;
|
||||
currPos += 4;
|
||||
l -= 4;
|
||||
continue;
|
||||
}
|
||||
returnText[finalDest] = original.at(currPos);
|
||||
++currPos;
|
||||
++finalDest;
|
||||
--l;
|
||||
}
|
||||
returnText.truncate(finalDest);
|
||||
return returnText;
|
||||
}
|
||||
|
||||
QIOSMenu::QIOSMenu()
|
||||
: QPlatformMenu()
|
||||
|
Loading…
x
Reference in New Issue
Block a user