Commit 92654942 authored by con's avatar con
Browse files

Merge remote branch 'origin/2.0'

Conflicts:
	src/libs/qmljs/qmljs-lib.pri
	src/plugins/debugger/gdb/gdbengine.cpp
	src/plugins/debugger/gdb/gdbengine.h
	src/plugins/qmldesigner/components/itemlibrary/itemlibrary.cpp
parents 6dc4a039 9ab9f9d3
......@@ -24,6 +24,7 @@ HEADERS += \
$$PWD/qmljscompletioncontextfinder.h \
$$PWD/qmljscomponentversion.h \
$$PWD/qmljsmodelmanagerinterface.h \
$$PWD/qmljspropertyreader.h \
$$PWD/qmljsrewriter.h
SOURCES += \
......@@ -39,6 +40,7 @@ SOURCES += \
$$PWD/qmljscompletioncontextfinder.cpp \
$$PWD/qmljscomponentversion.cpp \
$$PWD/qmljsmodelmanagerinterface.cpp \
$$PWD/qmljspropertyreader.cpp \
$$PWD/qmljsrewriter.cpp
OTHER_FILES += \
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "qmljspropertyreader.h"
#include "qmljsdocument.h"
#include <qmljs/parser/qmljsast_p.h>
namespace QmlJS {
using namespace AST;
namespace {
static inline QString deEscape(const QString &value)
{
QString result = value;
result.replace(QLatin1String("\\\\"), QLatin1String("\\"));
result.replace(QLatin1String("\\\""), QLatin1String("\""));
result.replace(QLatin1String("\\\t"), QLatin1String("\t"));
result.replace(QLatin1String("\\\r"), QLatin1String("\r"));
result.replace(QLatin1String("\\\n"), QLatin1String("\n"));
return result;
}
static inline QString stripQuotes(const QString &str)
{
if ((str.startsWith(QLatin1Char('"')) && str.endsWith(QLatin1Char('"')))
|| (str.startsWith(QLatin1Char('\'')) && str.endsWith(QLatin1Char('\''))))
return str.mid(1, str.length() - 2);
return str;
}
static bool isLiteralValue(ExpressionNode *expr)
{
if (cast<NumericLiteral*>(expr))
return true;
else if (cast<StringLiteral*>(expr))
return true;
else if (UnaryPlusExpression *plusExpr = cast<UnaryPlusExpression*>(expr))
return isLiteralValue(plusExpr->expression);
else if (UnaryMinusExpression *minusExpr = cast<UnaryMinusExpression*>(expr))
return isLiteralValue(minusExpr->expression);
else if (cast<TrueLiteral*>(expr))
return true;
else if (cast<FalseLiteral*>(expr))
return true;
else
return false;
}
static inline bool isLiteralValue(UiScriptBinding *script)
{
if (!script || !script->statement)
return false;
ExpressionStatement *exprStmt = cast<ExpressionStatement *>(script->statement);
if (exprStmt)
return isLiteralValue(exprStmt->expression);
else
return false;
}
static inline QString textAt(const Document* doc,
const SourceLocation &from,
const SourceLocation &to)
{
return doc->source().mid(from.offset, to.end() - from.begin());
}
static inline int propertyType(const QString &typeName)
{
if (typeName == QLatin1String("bool"))
return QMetaType::type("bool");
else if (typeName == QLatin1String("color"))
return QMetaType::type("QColor");
else if (typeName == QLatin1String("date"))
return QMetaType::type("QDate");
else if (typeName == QLatin1String("int"))
return QMetaType::type("int");
else if (typeName == QLatin1String("real"))
return QMetaType::type("double");
else if (typeName == QLatin1String("double"))
return QMetaType::type("double");
else if (typeName == QLatin1String("string"))
return QMetaType::type("QString");
else if (typeName == QLatin1String("url"))
return QMetaType::type("QUrl");
else if (typeName == QLatin1String("variant"))
return QMetaType::type("QVariant");
else
return -1;
}
static inline QString flatten(UiQualifiedId *qualifiedId)
{
QString result;
for (UiQualifiedId *iter = qualifiedId; iter; iter = iter->next) {
if (!iter->name)
continue;
if (!result.isEmpty())
result.append(QLatin1Char('.'));
result.append(iter->name->asString());
}
return result;
}
static bool isEnum(AST::Statement *ast);
bool isEnum(AST::ExpressionNode *ast)
{
if (!ast)
return false;
if (FieldMemberExpression *memberExpr = cast<AST::FieldMemberExpression*>(ast))
return isEnum(memberExpr->base);
else if (cast<IdentifierExpression*>(ast))
return true;
else
return false;
}
bool isEnum(AST::ExpressionStatement *ast)
{
if (!ast)
return false;
if (FieldMemberExpression *memberExpr = cast<AST::FieldMemberExpression*>(ast->expression))
return isEnum(memberExpr->base);
else if (cast<IdentifierExpression*>(ast->expression))
return true;
else
return false;
}
static bool isEnum(AST::Statement *ast)
{
if (!ast)
return false;
if (ExpressionStatement *exprStmt = cast<ExpressionStatement*>(ast)) {
return isEnum(exprStmt->expression);
}
return false;
}
} // anonymous namespace
PropertyReader::PropertyReader(Document *doc, AST::UiObjectInitializer *ast)
{
for (UiObjectMemberList *members = ast->members; members; members = members->next) {
UiObjectMember *member = members->member;
if (UiScriptBinding *property = AST::cast<UiScriptBinding *>(member)) {
if (!property->qualifiedId)
continue; // better safe than sorry.
const QString propertyName = flatten(property->qualifiedId);
const QString astValue = textAt(doc,
property->statement->firstSourceLocation(),
property->statement->lastSourceLocation());
if (isLiteralValue(property)) {
m_properties.insert(propertyName, QVariant(deEscape(stripQuotes(astValue))));
} else if (isEnum(property->statement)) { //enum
m_properties.insert(propertyName, QVariant(astValue));
}
} else if (UiObjectDefinition *objectDefinition = cast<UiObjectDefinition *>(member)) { //font { bold: true }
const QString propertyName = objectDefinition->qualifiedTypeNameId->name->asString();
if (!propertyName.isEmpty() && !propertyName.at(0).isUpper()) {
for (UiObjectMemberList *iter = objectDefinition->initializer->members; iter; iter = iter->next) {
UiObjectMember *objectMember = iter->member;
if (UiScriptBinding *property = cast<UiScriptBinding *>(objectMember)) {
const QString propertyNamePart2 = flatten(property->qualifiedId);
const QString astValue = textAt(doc,
property->statement->firstSourceLocation(),
property->statement->lastSourceLocation());
if (isLiteralValue(property)) {
m_properties.insert(propertyName + '.' + propertyNamePart2, QVariant(deEscape(stripQuotes(astValue))));
} else if (isEnum(property->statement)) { //enum
m_properties.insert(propertyName + '.' + propertyNamePart2, QVariant(astValue));
}
}
}
}
}
}
}
} //QmlJS
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef QMLJSPROPERTYREADER_H
#define QMLJSPROPERTYREADER_H
#include <qmljs/qmljs_global.h>
#include <qmljs/parser/qmljsastfwd_p.h>
#include <QHash>
#include <QVariant>
#include <QString>
#include <QStringList>
namespace QmlJS {
class Document;
class QMLJS_EXPORT PropertyReader
{
public:
PropertyReader(Document *doc, AST::UiObjectInitializer *ast);
bool hasProperty(const QString &propertyName) const
{ return m_properties.contains(propertyName); }
QVariant readProperty(const QString &propertyName) const
{
if (hasProperty(propertyName))
return m_properties.value(propertyName);
else
return QVariant();
}
QStringList properties() const
{ return m_properties.keys(); }
private:
QHash<QString, QVariant> m_properties;
};
} //QmlJS
#endif // QMLJSPROPERTYREADER_H
......@@ -46,19 +46,25 @@ QTCREATOR_UTILS_EXPORT Utils::ReloadPromptAnswer
if (modified)
msg = QCoreApplication::translate("Utils::reloadPrompt",
"The unsaved file %1 has been changed outside Qt Creator. Do you want to reload it and discard your changes?").arg(QDir::toNativeSeparators(fileName));
"The unsaved file <i>%1</i> has been changed outside Qt Creator. Do you want to reload it and discard your changes?");
else
msg = QCoreApplication::translate("Utils::reloadPrompt",
"The file %1 has changed outside Qt Creator. Do you want to reload it?").arg(QDir::toNativeSeparators(fileName));
return reloadPrompt(title, msg, parent);
"The file <i>%1</i> has changed outside Qt Creator. Do you want to reload it?");
msg = msg.arg(QFileInfo(fileName).fileName());
return reloadPrompt(title, msg, QDir::toNativeSeparators(fileName), parent);
}
QTCREATOR_UTILS_EXPORT Utils::ReloadPromptAnswer
Utils::reloadPrompt(const QString &title, const QString &prompt, QWidget *parent)
Utils::reloadPrompt(const QString &title, const QString &prompt, const QString &details, QWidget *parent)
{
switch (QMessageBox::question(parent, title, prompt,
QMessageBox::Yes|QMessageBox::YesToAll|QMessageBox::No|QMessageBox::NoToAll,
QMessageBox::YesToAll)) {
QMessageBox msg(parent);
msg.setStandardButtons(QMessageBox::Yes|QMessageBox::YesToAll|QMessageBox::No|QMessageBox::NoToAll);
msg.setDefaultButton(QMessageBox::YesToAll);
msg.setWindowTitle(title);
msg.setText(prompt);
msg.setDetailedText(details);
switch (msg.exec()) {
case QMessageBox::Yes:
return ReloadCurrent;
case QMessageBox::YesToAll:
......
......@@ -42,7 +42,7 @@ namespace Utils {
enum ReloadPromptAnswer { ReloadCurrent, ReloadAll, ReloadSkipCurrent, ReloadNone };
QTCREATOR_UTILS_EXPORT ReloadPromptAnswer reloadPrompt(const QString &fileName, bool modified, QWidget *parent);
QTCREATOR_UTILS_EXPORT ReloadPromptAnswer reloadPrompt(const QString &title, const QString &prompt, QWidget *parent);
QTCREATOR_UTILS_EXPORT ReloadPromptAnswer reloadPrompt(const QString &title, const QString &prompt, const QString &details, QWidget *parent);
enum FileDeletedPromptAnswer { FileDeletedClose, FileDeletedSaveAs, FileDeletedSave };
......
......@@ -185,7 +185,6 @@ ItemLibrary::ItemLibrary(QWidget *parent) :
lineEditLayout->addWidget(m_d->m_lineEdit, 1, 1, 1, 1);
lineEditLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Fixed, QSizePolicy::Fixed), 1, 2);
connect(m_d->m_lineEdit, SIGNAL(filterChanged(QString)), this, SLOT(setSearchFilter(QString)));
connect(m_d->m_lineEdit, SIGNAL(buttonClicked(Utils::FancyLineEdit::Side)), this, SLOT(clearLineEditFocus()));
m_d->m_stackedWidget = new QStackedWidget(this);
m_d->m_stackedWidget->addWidget(m_d->m_itemsView);
......@@ -286,11 +285,6 @@ void ItemLibrary::updateSearch()
setSearchFilter(m_d->m_lineEdit->text());
}
void ItemLibrary::clearLineEditFocus()
{
m_d->m_lineEdit->clearFocus();
}
void ItemLibrary::setResourcePath(const QString &resourcePath)
{
if (m_d->m_resourcesView->model() == m_d->m_resourcesDirModel)
......
......@@ -54,7 +54,6 @@ public Q_SLOTS:
void setSearchFilter(const QString &searchFilter);
void updateModel();
void updateSearch();
void clearLineEditFocus();
void setResourcePath(const QString &resourcePath);
......
......@@ -43,6 +43,11 @@
#include <QToolButton>
#include <QGradient>
#include <QPainter>
#include <QDoubleSpinBox>
#include <QGridLayout>
#include <QPushButton>
#include <QDialogButtonBox>
#include <QGraphicsEffect>
static inline int clamp(int x, int lower, int upper)
{
......@@ -151,7 +156,7 @@ void HueControl::setCurrent(int y)
m_color.setHsv((y * 359)/120, m_color.hsvSaturation(), m_color.value());
m_color.setAlpha(oldAlpha);
update(); // redraw pointer
emit hueChanged();
emit hueChanged(m_color.hsvHue());
}
void HueControl::setHue(int newHue)
......@@ -160,7 +165,7 @@ void HueControl::setHue(int newHue)
return;
m_color.setHsv(newHue, m_color.hsvSaturation(), m_color.value());
update();
emit hueChanged();
emit hueChanged(m_color.hsvHue());
}
void HueControl::paintEvent(QPaintEvent *event)
......@@ -754,4 +759,105 @@ void GradientLine::setCurrentIndex(int i)
update();
}
BauhausColorDialog::BauhausColorDialog(QWidget *parent) : QFrame(parent )
{
setFrameStyle(QFrame::NoFrame);
setFrameShape(QFrame::StyledPanel);
setFrameShadow(QFrame::Sunken);
QGraphicsDropShadowEffect *dropShadowEffect = new QGraphicsDropShadowEffect;
dropShadowEffect->setBlurRadius(6);
dropShadowEffect->setOffset(2, 2);
setGraphicsEffect(dropShadowEffect);
setAutoFillBackground(true);
m_hueControl = new HueControl(this);
m_colorBox = new ColorBox(this);
m_rSpinBox = new QDoubleSpinBox(this);
m_gSpinBox = new QDoubleSpinBox(this);
m_bSpinBox = new QDoubleSpinBox(this);
m_alphaSpinBox = new QDoubleSpinBox(this);
QGridLayout *gridLayout = new QGridLayout(this);
setLayout(gridLayout);
gridLayout->addWidget(m_colorBox, 0, 0, 4, 1);
gridLayout->addWidget(m_hueControl, 0, 1, 4, 1);
gridLayout->addWidget(new QLabel("R", this), 0, 2, 1, 1);
gridLayout->addWidget(new QLabel("G", this), 1, 2, 1, 1);
gridLayout->addWidget(new QLabel("B", this), 2, 2, 1, 1);
gridLayout->addWidget(new QLabel("A", this), 3, 2, 1, 1);
gridLayout->addWidget(m_rSpinBox, 0, 3, 1, 1);
gridLayout->addWidget(m_gSpinBox, 1, 3, 1, 1);
gridLayout->addWidget(m_bSpinBox, 2, 3, 1, 1);
gridLayout->addWidget(m_alphaSpinBox, 3, 3, 1, 1);
QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
QPushButton *applyButton = buttonBox->addButton(QDialogButtonBox::Apply);
gridLayout->addWidget(buttonBox, 4, 0, 2, 1);
resize(sizeHint());
connect(m_colorBox, SIGNAL(colorChanged()), this, SLOT(onColorBoxChanged()));
connect(m_alphaSpinBox, SIGNAL(valueChanged(double)), this, SLOT(spinBoxChanged()));
connect(m_rSpinBox, SIGNAL(valueChanged(double)), this, SLOT(spinBoxChanged()));
connect(m_gSpinBox, SIGNAL(valueChanged(double)), this, SLOT(spinBoxChanged()));
connect(m_bSpinBox, SIGNAL(valueChanged(double)), this, SLOT(spinBoxChanged()));
connect(m_hueControl, SIGNAL(hueChanged(int)), this, SLOT(onHueChanged(int)));
connect(applyButton, SIGNAL(pressed()), this, SLOT(onAccept()));
connect(cancelButton, SIGNAL(pressed()), this, SIGNAL(rejected()));
m_alphaSpinBox->setMaximum(1);
m_rSpinBox->setMaximum(1);
m_gSpinBox->setMaximum(1);
m_bSpinBox->setMaximum(1);
m_alphaSpinBox->setSingleStep(0.1);
m_rSpinBox->setSingleStep(0.1);
m_gSpinBox->setSingleStep(0.1);
m_bSpinBox->setSingleStep(0.1);
m_blockUpdate = false;
}
void BauhausColorDialog::spinBoxChanged()
{
if (m_blockUpdate)
return;
QColor newColor;
newColor.setAlphaF(m_alphaSpinBox->value());
newColor.setRedF(m_rSpinBox->value());
newColor.setGreenF(m_gSpinBox->value());
newColor.setBlueF(m_bSpinBox->value());
setColor(newColor);
}
void BauhausColorDialog::onColorBoxChanged()
{
if (m_blockUpdate)
return;
setColor(m_colorBox->color());
}
void BauhausColorDialog::setupWidgets()
{
m_blockUpdate = true;
m_hueControl->setHue(m_color.hsvHue());
m_alphaSpinBox->setValue(m_color.alphaF());
m_rSpinBox->setValue(m_color.redF());
m_gSpinBox->setValue(m_color.greenF());
m_bSpinBox->setValue(m_color.blueF());
m_colorBox->setColor(m_color);
m_blockUpdate = false;
}
}
......@@ -39,10 +39,12 @@
#include <qdeclarative.h>
#include <propertyeditorvalue.h>
#include <qmlitemnode.h>
#include <QDialog>
QT_BEGIN_NAMESPACE
class QtColorButton;
class QToolButton;
class QDoubleSpinBox;
QT_END_NAMESPACE
namespace QmlDesigner {
......@@ -144,7 +146,7 @@ public:
int hue() const { return m_color.hsvHue(); }
signals:
void hueChanged();
void hueChanged(int hue);
protected:
void paintEvent(QPaintEvent *);
......@@ -215,6 +217,68 @@ private:
bool m_dragOff;
};
class BauhausColorDialog : public QFrame {
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
public:
BauhausColorDialog(QWidget *parent = 0);
QColor color() const { return m_color; }
void setColor(const QColor &color)
{
if (color == m_color)
return;
m_color = color;
setupWidgets();
emit colorChanged();
}
public slots:
void changeColor(const QColor &color) { setColor(color); }
void spinBoxChanged();
void onColorBoxChanged();
void onHueChanged(int newHue)
{
if (m_blockUpdate)
return;
if (m_color.hsvHue() == newHue)
return;
m_color.setHsv(newHue, m_color.hsvSaturation(), m_color.value());
setupWidgets();
emit colorChanged();
}
void onAccept()
{
emit accepted(m_color);
}
signals:
void colorChanged();
void accepted(const QColor &color);
void rejected();
protected:
void setupWidgets();
private:
ColorBox *m_colorBox;
HueControl *m_hueControl;