diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2013-12-10 12:53:20 +0100 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@digia.com> | 2013-12-10 12:53:20 +0100 |
commit | 9f831dde07cb2411808534e76669b28a1b76e21d (patch) | |
tree | ed6252d64c9a3ab27aa93786272cda1b6008f3c7 /src/libs | |
parent | cdac81f896ef4b052d76f96485a08e6ec13696b8 (diff) | |
parent | ea1a92484ac99057b06130a012164bf9788650e9 (diff) | |
download | qt-creator-9f831dde07cb2411808534e76669b28a1b76e21d.tar.gz |
Merge remote-tracking branch 'origin/master' into wip/clangwip/clang
Change-Id: I8a2c8068a3f2b15034fb1bf6304c9a0f3f0e3c8f
Diffstat (limited to 'src/libs')
21 files changed, 305 insertions, 56 deletions
diff --git a/src/libs/3rdparty/cplusplus/Keywords.cpp b/src/libs/3rdparty/cplusplus/Keywords.cpp index 91c9ffc312..9bce1ff3f8 100644 --- a/src/libs/3rdparty/cplusplus/Keywords.cpp +++ b/src/libs/3rdparty/cplusplus/Keywords.cpp @@ -803,6 +803,17 @@ static inline int classify8(const char *s, LanguageFeatures features) } } } + else if (s[3] == 'h') { + if (s[4] == 'r') { + if (s[5] == 'e') { + if (s[6] == 'a') { + if (s[7] == 'd') { + return T___THREAD; + } + } + } + } + } } } } @@ -1443,6 +1454,31 @@ static inline int classify12(const char *s, LanguageFeatures features) } } } + else if (features.cxx11Enabled && s[0] == 't') { + if (s[1] == 'h') { + if (s[2] == 'r') { + if (s[3] == 'e') { + if (s[4] == 'a') { + if (s[5] == 'd') { + if (s[6] == '_') { + if (s[7] == 'l') { + if (s[8] == 'o') { + if (s[9] == 'c') { + if (s[10] == 'a') { + if (s[11] == 'l') { + return T_THREAD_LOCAL; + } + } + } + } + } + } + } + } + } + } + } + } return T_IDENTIFIER; } diff --git a/src/libs/3rdparty/cplusplus/Lexer.cpp b/src/libs/3rdparty/cplusplus/Lexer.cpp index 6e6e6c2feb..0e0d1f4330 100644 --- a/src/libs/3rdparty/cplusplus/Lexer.cpp +++ b/src/libs/3rdparty/cplusplus/Lexer.cpp @@ -297,7 +297,24 @@ void Lexer::scan_helper(Token *tok) break; case '?': - tok->f.kind = T_QUESTION; + if (_yychar == '?') { + yyinp(); + if (_yychar == '(') { + yyinp(); + tok->f.kind = T_LBRACKET; + } else if (_yychar == ')') { + yyinp(); + tok->f.kind = T_RBRACKET; + } else if (_yychar == '<') { + yyinp(); + tok->f.kind = T_LBRACE; + } else if (_yychar == '>') { + yyinp(); + tok->f.kind = T_RBRACE; + } + } else { + tok->f.kind = T_QUESTION; + } break; case '+': diff --git a/src/libs/3rdparty/cplusplus/Parser.cpp b/src/libs/3rdparty/cplusplus/Parser.cpp index 51e78abe5c..467bf6e694 100644 --- a/src/libs/3rdparty/cplusplus/Parser.cpp +++ b/src/libs/3rdparty/cplusplus/Parser.cpp @@ -3725,7 +3725,10 @@ bool Parser::lookAtStorageClassSpecifier() const case T_EXTERN: case T_MUTABLE: case T_TYPEDEF: + case T___THREAD: return true; + case T_THREAD_LOCAL: + return _languageFeatures.cxx11Enabled; case T_CONSTEXPR: if (_languageFeatures.cxx11Enabled) return true; diff --git a/src/libs/3rdparty/cplusplus/Token.cpp b/src/libs/3rdparty/cplusplus/Token.cpp index ab6d3c0317..1469edea7f 100644 --- a/src/libs/3rdparty/cplusplus/Token.cpp +++ b/src/libs/3rdparty/cplusplus/Token.cpp @@ -57,13 +57,13 @@ const char *token_names[] = { ("nullptr"), ("operator"), ("private"), ("protected"), ("public"), ("register"), ("reinterpret_cast"), ("return"), ("short"), ("signed"), ("sizeof"), ("static"),("static_assert"), - ("static_cast"), ("struct"), ("switch"), ("template"), ("this"), + ("static_cast"), ("struct"), ("switch"), ("template"), ("this"), ("thread_local"), ("throw"), ("true"), ("try"), ("typedef"), ("typeid"), ("typename"), ("union"), ("unsigned"), ("using"), ("virtual"), ("void"), ("volatile"), ("wchar_t"), ("while"), // gnu - ("__attribute__"), ("__typeof__"), + ("__attribute__"), ("__thread"), ("__typeof__"), // objc @keywords ("@catch"), ("@class"), ("@compatibility_alias"), ("@defs"), ("@dynamic"), diff --git a/src/libs/3rdparty/cplusplus/Token.h b/src/libs/3rdparty/cplusplus/Token.h index 6107c52538..58fcee3a48 100644 --- a/src/libs/3rdparty/cplusplus/Token.h +++ b/src/libs/3rdparty/cplusplus/Token.h @@ -173,6 +173,7 @@ enum Kind { T_SWITCH, T_TEMPLATE, T_THIS, + T_THREAD_LOCAL, T_THROW, T_TRUE, T_TRY, @@ -189,6 +190,7 @@ enum Kind { T_WHILE, T___ATTRIBUTE__, + T___THREAD, T___TYPEOF__, // obj c++ @ keywords diff --git a/src/libs/cplusplus/MatchingText.h b/src/libs/cplusplus/MatchingText.h index 5b12d5cc78..32db6df60a 100644 --- a/src/libs/cplusplus/MatchingText.h +++ b/src/libs/cplusplus/MatchingText.h @@ -36,9 +36,6 @@ QT_FORWARD_DECLARE_CLASS(QChar) namespace CPlusPlus { -class BackwardsScanner; -class TokenCache; - class CPLUSPLUS_EXPORT MatchingText { public: diff --git a/src/libs/cplusplus/TypePrettyPrinter.cpp b/src/libs/cplusplus/TypePrettyPrinter.cpp index 6ec363ba92..364edb66af 100644 --- a/src/libs/cplusplus/TypePrettyPrinter.cpp +++ b/src/libs/cplusplus/TypePrettyPrinter.cpp @@ -436,7 +436,7 @@ void TypePrettyPrinter::visit(Function *type) if (_overview->showDefaultArguments) { if (const StringLiteral *initializer = arg->initializer()) { - _text += QLatin1String(" ="); + _text += QLatin1String(" = "); _text += QString::fromUtf8(initializer->chars(), initializer->size()); } } diff --git a/src/libs/qmljs/persistenttrie.cpp b/src/libs/qmljs/persistenttrie.cpp index 74c9593c7d..521d90f31c 100644 --- a/src/libs/qmljs/persistenttrie.cpp +++ b/src/libs/qmljs/persistenttrie.cpp @@ -654,7 +654,7 @@ int matchStrength(const QString &searchStr, const QString &str) { QString::const_iterator i = searchStr.constBegin(), iEnd = searchStr.constEnd(), j = str.constBegin(), jEnd = str.constEnd(); - bool lastWasNotUpper=true, lastWasSpacer=true, lastWasMatch = false; + bool lastWasNotUpper=true, lastWasSpacer=true, lastWasMatch = false, didJump = false; int res = 0; while (i != iEnd && j != jEnd) { bool thisIsUpper = (*j).isUpper(); @@ -667,6 +667,7 @@ int matchStrength(const QString &searchStr, const QString &str) lastWasMatch = true; ++i; } else { + didJump = true; lastWasMatch = false; } ++j; @@ -674,9 +675,11 @@ int matchStrength(const QString &searchStr, const QString &str) lastWasSpacer = !thisIsLetterOrNumber; } if (i != iEnd) - return iEnd - i; + return i - iEnd; if (j == jEnd) ++res; + if (!didJump) + res+=2; return res; } diff --git a/src/libs/qmljs/qmljsimportdependencies.cpp b/src/libs/qmljs/qmljsimportdependencies.cpp index dffcf8ee4b..9dc0e53f54 100644 --- a/src/libs/qmljs/qmljsimportdependencies.cpp +++ b/src/libs/qmljs/qmljsimportdependencies.cpp @@ -314,7 +314,7 @@ int ImportKey::compare(const ImportKey &other) const QString v2 = other.splitPath.at(i); if (v1 < v2) return -1; - if (v2 > v1) + if (v1 > v2) return 1; } if (len1 < len2) @@ -626,7 +626,7 @@ void ImportDependencies::iterateOnCandidateImports( break; default: { - QStringList imp = m_importCache.value(key.flatKey()); + const QStringList imp = m_importCache.value(key.flatKey()); foreach (const QString &cImportName, imp) { CoreImport cImport = coreImport(cImportName); if (vContext.languageIsCompatible(cImport.language)) { @@ -928,4 +928,38 @@ QSet<ImportKey> ImportDependencies::subdirImports( return res; } +void ImportDependencies::checkConsistency() const +{ + QMapIterator<ImportKey, QStringList> j(m_importCache); + while (j.hasNext()) { + j.next(); + foreach (const QString &s, j.value()) { + bool found = false; + foreach (const Export &e, m_coreImports.value(s).possibleExports) + if (e.exportName == j.key()) + found = true; + Q_ASSERT(found); + } + } + QMapIterator<QString,CoreImport> i(m_coreImports); + while (i.hasNext()) { + i.next(); + foreach (const Export &e, i.value().possibleExports) { + if (!m_importCache.value(e.exportName).contains(i.key())) { + qDebug() << e.exportName.toString(); + qDebug() << i.key(); + + QMapIterator<ImportKey, QStringList> j(m_importCache); + while (j.hasNext()) { + j.next(); + qDebug() << j.key().toString() << j.value(); + } + qDebug() << m_importCache.contains(e.exportName); + qDebug() << m_importCache.value(e.exportName); + } + Q_ASSERT(m_importCache.value(e.exportName).contains(i.key())); + } + } +} + } // namespace QmlJS diff --git a/src/libs/qmljs/qmljsimportdependencies.h b/src/libs/qmljs/qmljsimportdependencies.h index fc84f0794f..1e27ef0626 100644 --- a/src/libs/qmljs/qmljsimportdependencies.h +++ b/src/libs/qmljs/qmljsimportdependencies.h @@ -223,6 +223,7 @@ public: QSet<ImportKey> libraryImports(const ViewerContext &viewContext) const; QSet<ImportKey> subdirImports(const ImportKey &baseKey, const ViewerContext &viewContext) const; + void checkConsistency() const; private: void removeImportCacheEntry(const ImportKey &importKey, const QString &importId); diff --git a/src/libs/qmljs/qmljsreformatter.cpp b/src/libs/qmljs/qmljsreformatter.cpp index 9295fcc319..d940cd1c65 100644 --- a/src/libs/qmljs/qmljsreformatter.cpp +++ b/src/libs/qmljs/qmljsreformatter.cpp @@ -139,11 +139,6 @@ protected: Node::accept(node, this); } - void acceptIndented(Node *node) - { - accept(node); - } - void lnAcceptIndented(Node *node) { newLine(); diff --git a/src/libs/qmljs/qmljsstaticanalysismessage.cpp b/src/libs/qmljs/qmljsstaticanalysismessage.cpp index 6f6de15fdc..235639ce32 100644 --- a/src/libs/qmljs/qmljsstaticanalysismessage.cpp +++ b/src/libs/qmljs/qmljsstaticanalysismessage.cpp @@ -210,14 +210,14 @@ StaticAnalysisMessages::StaticAnalysisMessages() tr("%1 elements expected in array value."), 1); newMsg(WarnImperativeCodeNotEditableInVisualDesigner, Error, tr("Imperative code is not supported in the Qt Quick Designer.")); - newMsg(WarnUnsupportedTypeInVisualDesigner, Error, + newMsg(WarnUnsupportedTypeInVisualDesigner, Warning, tr("This type is not supported in the Qt Quick Designer.")); newMsg(WarnReferenceToParentItemNotSupportedByVisualDesigner, Error, tr("Reference to parent item cannot be resolved correctly by the Qt Quick Designer.")); - newMsg(WarnUndefinedValueForVisualDesigner, Error, + newMsg(WarnUndefinedValueForVisualDesigner, Warning, tr("This visual property binding cannot be evaluated in the local context " "and might not show up in Qt Quick Designer as expected.")); - newMsg(WarnStatesOnlyInRootItemForVisualDesigner, Error, + newMsg(WarnStatesOnlyInRootItemForVisualDesigner, Warning, tr("Qt Quick Designer only supports states in the root item.")); newMsg(WarnAboutQtQuick1InsteadQtQuick2, Warning, tr("Using Qt Quick 1 code model instead of Qt Quick 2.")); diff --git a/src/libs/qtcreatorcdbext/containers.cpp b/src/libs/qtcreatorcdbext/containers.cpp index 8fbd64f0a5..3b6f9362dd 100644 --- a/src/libs/qtcreatorcdbext/containers.cpp +++ b/src/libs/qtcreatorcdbext/containers.cpp @@ -203,7 +203,18 @@ int containerSize(KnownType kt, const SymbolGroupValue &v) if (const SymbolGroupValue deque = v[unsigned(0)]) return containerSize(KT_StdDeque, deque); break; + case KT_StdArray: { + std::string::size_type arraySizeStart = v.type().find(','); + if (arraySizeStart != std::string::npos) { + ++arraySizeStart; + std::string::size_type arraySizeEnd = v.type().find('>', arraySizeStart); + if (arraySizeEnd != std::string::npos) + return std::stoi(v.type().substr(arraySizeStart, arraySizeEnd - arraySizeStart)); + } + break; } + } + return -1; } @@ -253,6 +264,22 @@ static inline AbstractSymbolGroupNodePtrVector stdListChildList(SymbolGroupNode return AbstractSymbolGroupNodePtrVector(); } +static inline AbstractSymbolGroupNodePtrVector stdArrayChildList(SymbolGroupNode *n, int count, + const SymbolGroupValueContext &ctx) +{ + AbstractSymbolGroupNodePtrVector rc; + if (SymbolGroupValue elems = SymbolGroupValue(n, ctx)["_Elems"]) { + rc.reserve(count); + for (int i = 0; i < count; ++i) { + if (const SymbolGroupValue value = elems[i]) + rc.push_back(ReferenceSymbolGroupNode::createArrayNode(i, value.node())); + else + break; + } + } + return rc; +} + // QLinkedList<T>: Dummy head node and then a linked list of "n", "t". static inline AbstractSymbolGroupNodePtrVector qLinkedListChildList(SymbolGroupNode *n, int count, const SymbolGroupValueContext &ctx) @@ -1109,6 +1136,8 @@ AbstractSymbolGroupNodePtrVector containerChildren(SymbolGroupNode *node, int ty break; case KT_StdList: return stdListChildList(node, size , ctx); + case KT_StdArray: + return stdArrayChildList(node, size , ctx); case KT_StdDeque: return stdDequeChildList(SymbolGroupValue(node, ctx), size); case KT_StdStack: diff --git a/src/libs/qtcreatorcdbext/knowntype.h b/src/libs/qtcreatorcdbext/knowntype.h index ee609567bc..206f971ebf 100644 --- a/src/libs/qtcreatorcdbext/knowntype.h +++ b/src/libs/qtcreatorcdbext/knowntype.h @@ -72,6 +72,7 @@ enum KnownType KT_QBasicAtomicInt = KT_Qt_Type + KT_HasSimpleDumper + 18, KT_QAtomicInt = KT_Qt_Type + KT_HasSimpleDumper + 19, KT_QStringRef = KT_Qt_Type + KT_HasSimpleDumper + 20, + KT_QTextCursor = KT_Qt_Type + KT_HasSimpleDumper + 21, KT_QObject = KT_Qt_Type + KT_HasSimpleDumper + KT_HasComplexDumper + 20, KT_QWindow = KT_Qt_Type + KT_HasSimpleDumper + KT_HasComplexDumper + 21, KT_QWidget = KT_Qt_Type + KT_HasSimpleDumper + KT_HasComplexDumper + 22, @@ -173,7 +174,8 @@ enum KnownType KT_StdDeque = KT_STL_Type + KT_ContainerType + KT_HasSimpleDumper + 4, KT_StdSet = KT_STL_Type + KT_ContainerType + KT_HasSimpleDumper + 5, KT_StdMap = KT_STL_Type + KT_ContainerType + KT_HasSimpleDumper + 6, - KT_StdMultiMap = KT_STL_Type + KT_ContainerType + KT_HasSimpleDumper + 7 + KT_StdMultiMap = KT_STL_Type + KT_ContainerType + KT_HasSimpleDumper + 7, + KT_StdArray = KT_STL_Type + KT_ContainerType + KT_HasSimpleDumper + 8 }; #endif // KNOWNTYPE_H diff --git a/src/libs/qtcreatorcdbext/symbolgroupvalue.cpp b/src/libs/qtcreatorcdbext/symbolgroupvalue.cpp index 19635c4212..f7d13fa08c 100644 --- a/src/libs/qtcreatorcdbext/symbolgroupvalue.cpp +++ b/src/libs/qtcreatorcdbext/symbolgroupvalue.cpp @@ -1078,6 +1078,8 @@ static KnownType knownClassTypeHelper(const std::string &type, return KT_StdStack; if (!type.compare(hPos, 5, "deque")) return KT_StdDeque; + if (!type.compare(hPos, 5, "array")) + return KT_StdArray; break; case 6: if (!type.compare(hPos, 6, "vector")) @@ -1281,6 +1283,8 @@ static KnownType knownClassTypeHelper(const std::string &type, return KT_QFixedPoint; if (!type.compare(qPos, 11, "QScriptLine")) return KT_QScriptLine; + if (!type.compare(qPos, 11, "QTextCursor")) + return KT_QTextCursor; break; case 12: if (!type.compare(qPos, 12, "QKeySequence")) @@ -2383,6 +2387,18 @@ static inline bool dumpQWindow(const SymbolGroupValue &v, std::wostream &str, vo return true; } +//Dump a QTextCursor +static inline bool dumpQTextCursor(const SymbolGroupValue &v, std::wostream &str) +{ + const unsigned offset = SymbolGroupValue::pointerSize() + SymbolGroupValue::sizeOf("double"); + const ULONG64 posAddr = addressOfQPrivateMember(v, QPDM_qSharedDataPadded, offset); + if (!posAddr) + return false; + const int position = SymbolGroupValue::readIntValue(v.context().dataspaces, posAddr); + str << position; + return true; +} + // Dump a std::string. static bool dumpStd_W_String(const SymbolGroupValue &v, int type, std::wostream &str, MemoryHandle **memoryHandle = 0) @@ -2796,6 +2812,10 @@ unsigned dumpSimpleType(SymbolGroupNode *n, const SymbolGroupValueContext &ctx, case KT_StdWString: rc = dumpStd_W_String(v, kt, str, memoryHandleIn) ? SymbolGroupNode::SimpleDumperOk : SymbolGroupNode::SimpleDumperFailed; break; + case KT_QTextCursor: + rc = dumpQTextCursor(v, str) ? SymbolGroupNode::SimpleDumperOk + : SymbolGroupNode::SimpleDumperFailed; + break; default: break; } diff --git a/src/libs/utils/detailsbutton.cpp b/src/libs/utils/detailsbutton.cpp index 66bf24172e..43fbd74d6e 100644 --- a/src/libs/utils/detailsbutton.cpp +++ b/src/libs/utils/detailsbutton.cpp @@ -37,6 +37,10 @@ #include <QPainter> #include <QStyleOption> +#if QT_VERSION >= 0x050100 +#include <QGuiApplication> +#endif + using namespace Utils; FadingWidget::FadingWidget(QWidget *parent) : @@ -123,12 +127,19 @@ void DetailsButton::paintEvent(QPaintEvent *e) if (!HostOsInfo::isMacHost() && !isDown() && m_fader > 0) p.fillRect(rect().adjusted(1, 1, -2, -2), QColor(255, 255, 255, int(m_fader*180))); + qreal checkedPixmapRatio = 1.0; + qreal uncheckedPixmapRatio = 1.0; +#if QT_VERSION >= 0x050100 + checkedPixmapRatio = m_checkedPixmap.devicePixelRatio(); + uncheckedPixmapRatio = m_uncheckedPixmap.devicePixelRatio(); +#endif + if (isChecked()) { - if (m_checkedPixmap.isNull() || m_checkedPixmap.size() != contentsRect().size()) + if (m_checkedPixmap.isNull() || m_checkedPixmap.size() / checkedPixmapRatio != contentsRect().size()) m_checkedPixmap = cacheRendering(contentsRect().size(), true); p.drawPixmap(contentsRect(), m_checkedPixmap); } else { - if (m_uncheckedPixmap.isNull() || m_uncheckedPixmap.size() != contentsRect().size()) + if (m_uncheckedPixmap.isNull() || m_uncheckedPixmap.size() / uncheckedPixmapRatio != contentsRect().size()) m_uncheckedPixmap = cacheRendering(contentsRect().size(), false); p.drawPixmap(contentsRect(), m_uncheckedPixmap); } @@ -145,7 +156,14 @@ QPixmap DetailsButton::cacheRendering(const QSize &size, bool checked) lg.setCoordinateMode(QGradient::ObjectBoundingMode); lg.setFinalStop(0, 1); - QPixmap pixmap(size); + qreal pixelRatio = 1.0; +#if QT_VERSION >= 0x050100 + pixelRatio = devicePixelRatio(); +#endif + QPixmap pixmap(size * pixelRatio); +#if QT_VERSION >= 0x050100 + pixmap.setDevicePixelRatio(pixelRatio); +#endif pixmap.fill(Qt::transparent); QPainter p(&pixmap); p.setRenderHint(QPainter::Antialiasing, true); diff --git a/src/libs/utils/execmenu.cpp b/src/libs/utils/execmenu.cpp new file mode 100644 index 0000000000..b760132801 --- /dev/null +++ b/src/libs/utils/execmenu.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "execmenu.h" + +#include <QApplication> +#include <QDesktopWidget> +#include <QMenu> +#include <QPoint> +#include <QRect> +#include <QSize> +#include <QWidget> + +namespace Utils { + +/*! + * Opens \a menu at the specified \a widget position. + * This function computes the position where to show the menu, and opens it with + * QMenu::exec(). + */ +QAction *execMenuAtWidget(QMenu *menu, QWidget *widget) +{ + QPoint p; + QRect screen = qApp->desktop()->availableGeometry(widget); + QSize sh = menu->sizeHint(); + QRect rect = widget->rect(); + if (widget->isRightToLeft()) { + if (widget->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) + p = widget->mapToGlobal(rect.bottomRight()); + else + p = widget->mapToGlobal(rect.topRight() - QPoint(0, sh.height())); + p.rx() -= sh.width(); + } else { + if (widget->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) + p = widget->mapToGlobal(rect.bottomLeft()); + else + p = widget->mapToGlobal(rect.topLeft() - QPoint(0, sh.height())); + } + p.rx() = qMax(screen.left(), qMin(p.x(), screen.right() - sh.width())); + p.ry() += 1; + + return menu->exec(p); +} + +} // namespace Utils diff --git a/src/libs/utils/execmenu.h b/src/libs/utils/execmenu.h new file mode 100644 index 0000000000..0a385c2d07 --- /dev/null +++ b/src/libs/utils/execmenu.h @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef EXECMENU_H +#define EXECMENU_H + +#include "utils_global.h" + +QT_BEGIN_NAMESPACE +class QAction; +class QMenu; +class QWidget; +QT_END_NAMESPACE + +namespace Utils { + +QTCREATOR_UTILS_EXPORT QAction *execMenuAtWidget(QMenu *menu, QWidget *widget); + +} // namespace Utils + +#endif // EXECMENU_H diff --git a/src/libs/utils/fancylineedit.cpp b/src/libs/utils/fancylineedit.cpp index d945852698..ed80be0ba0 100644 --- a/src/libs/utils/fancylineedit.cpp +++ b/src/libs/utils/fancylineedit.cpp @@ -27,14 +27,13 @@ ** ****************************************************************************/ +#include "execmenu.h" #include "fancylineedit.h" #include "historycompleter.h" #include "qtcassert.h" #include <QAbstractItemView> -#include <QApplication> #include <QDebug> -#include <QDesktopWidget> #include <QKeyEvent> #include <QMenu> #include <QPainter> @@ -42,35 +41,6 @@ #include <QStyle> /*! - * Opens \a menu at the specified \a widget position. - * This function computes the position where to show the menu, and opens it with - * QMenu::exec(). - */ -static void execMenuAtWidget(QMenu *menu, QWidget *widget) -{ - QPoint p; - QRect screen = qApp->desktop()->availableGeometry(widget); - QSize sh = menu->sizeHint(); - QRect rect = widget->rect(); - if (widget->isRightToLeft()) { - if (widget->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) - p = widget->mapToGlobal(rect.bottomRight()); - else - p = widget->mapToGlobal(rect.topRight() - QPoint(0, sh.height())); - p.rx() -= sh.width(); - } else { - if (widget->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) - p = widget->mapToGlobal(rect.bottomLeft()); - else - p = widget->mapToGlobal(rect.topLeft() - QPoint(0, sh.height())); - } - p.rx() = qMax(screen.left(), qMin(p.x(), screen.right() - sh.width())); - p.ry() += 1; - - menu->exec(p); -} - -/*! \class Utils::FancyLineEdit \brief The FancyLineEdit class is a line edit with an embedded pixmap on diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index 97833eb8e7..2825a5661f 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -86,7 +86,8 @@ SOURCES += $$PWD/environment.cpp \ $$PWD/tooltip/tipcontents.cpp \ $$PWD/unixutils.cpp \ $$PWD/function.cpp \ - $$PWD/ansiescapecodehandler.cpp + $$PWD/ansiescapecodehandler.cpp \ + $$PWD/execmenu.cpp win32 { SOURCES += \ @@ -180,7 +181,8 @@ HEADERS += \ $$PWD/unixutils.h \ $$PWD/qtcoverride.h \ $$PWD/function.h \ - $$PWD/ansiescapecodehandler.h + $$PWD/ansiescapecodehandler.h \ + $$PWD/execmenu.h FORMS += $$PWD/filewizardpage.ui \ $$PWD/projectintropage.ui \ diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs index c40db11a3e..99174d119c 100644 --- a/src/libs/utils/utils.qbs +++ b/src/libs/utils/utils.qbs @@ -64,6 +64,8 @@ QtcLibrary { "environment.h", "environmentmodel.cpp", "environmentmodel.h", + "execmenu.cpp", + "execmenu.h", "faketooltip.cpp", "faketooltip.h", "fancylineedit.cpp", |