Commit 04126b47 authored by Thomas Hartmann's avatar Thomas Hartmann Committed by Marco Bubke

QmlDesigner.PropertyEditor: final cleanup for Qt Quick 2 port

Removing last leftovers from QtQuick 1.

Change-Id: Ifca7ef8792daec458b4bd6fbe68dc4a3a6174fc2
Reviewed-by: default avatarMarco Bubke <marco.bubke@digia.com>
parent 126a077c
/****************************************************************************
**
** Copyright (C) 2014 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 "filewidget.h"
#include <QHBoxLayout>
#include <QFileDialog>
#include <QDirIterator>
#include <QDebug>
#include <model.h>
QT_BEGIN_NAMESPACE
static QString s_lastBrowserPath;
FileWidget::FileWidget(QWidget *parent) : QWidget(parent), m_filter("(*.*)"), m_showComboBox(false), m_lock(false)
{
m_pushButton = new QToolButton(this);
m_pushButton->setFixedWidth(32);
m_lineEdit = new QLineEdit(this);
m_comboBox = new QComboBox(this);
m_comboBox->hide();
QHBoxLayout *layout = new QHBoxLayout(this);
setLayout(layout);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(m_lineEdit);
layout->addWidget(m_comboBox);
m_comboBox->setEditable(true);
layout->addWidget(m_pushButton);
m_pushButton->setText("...");
connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(lineEditChanged()));
connect(m_pushButton, SIGNAL(pressed()), this, SLOT(buttonPressed()));
connect(m_comboBox, SIGNAL(editTextChanged(QString)), this, SLOT(comboBoxChanged()));
}
FileWidget::~FileWidget()
{
}
void FileWidget::setItemNode(const QVariant &itemNode)
{
if (!itemNode.value<QmlDesigner::ModelNode>().isValid() || !QmlDesigner::QmlItemNode(itemNode.value<QmlDesigner::ModelNode>()).hasNodeParent())
return;
m_itemNode = itemNode.value<QmlDesigner::ModelNode>();
setupComboBox();
emit itemNodeChanged();
}
void FileWidget::setShowComboBox(bool show)
{
m_showComboBox = show;
m_comboBox->setVisible(show);
m_lineEdit->setVisible(!show);
}
void FileWidget::lineEditChanged()
{
if (m_lock)
return;
setFileNameStr(m_lineEdit->text());
}
void FileWidget::comboBoxChanged()
{
if (m_lock)
return;
setFileNameStr(m_comboBox->currentText());
}
void FileWidget::buttonPressed()
{
QString modelPath;
if (m_itemNode.isValid())
modelPath = QFileInfo(m_itemNode.modelNode().model()->fileUrl().toLocalFile()).absoluteDir().absolutePath();
m_lastModelPath = modelPath;
bool documentChanged = m_lastModelPath == modelPath;
//First we try the last path this browser widget was opened with
//if the document was not changed
QString path = documentChanged ? QString() : m_currentPath;
//If that one is not valid we try the path for the current file
if (path.isEmpty() && !m_fileName.isEmpty())
path = QFileInfo(modelPath + QLatin1String("/") + m_fileName.toString()).absoluteDir().absolutePath();
//Next we try to fall back to the path any file browser was opened with
if (!QFileInfo(path).exists()) {
path = s_lastBrowserPath;
//The last fallback is to try the path of the document
if (!QFileInfo(path).exists()) {
if (m_itemNode.isValid())
path = modelPath;
}
}
QString newFile = QFileDialog::getOpenFileName(0, tr("Open File"), path, m_filter);
if (!newFile.isEmpty()) {
setFileNameStr(newFile);
m_currentPath = QFileInfo(newFile).absolutePath();
s_lastBrowserPath = m_currentPath;
}
}
void FileWidget::setFileNameStr(const QString &fileName)
{
setFileName(QUrl(fileName));
}
void FileWidget::setFileName(const QUrl &fileName)
{
if (fileName == m_fileName)
return;
m_fileName = fileName;
if (m_lineEdit->text() != fileName.toString()) {
m_lineEdit->setText(fileName.toString());
m_lineEdit->setToolTip(m_fileName.toString());
}
if (m_comboBox->currentText() != fileName.toString()) {
m_comboBox->setEditText(m_fileName.toString());
m_comboBox->setToolTip(m_fileName.toString());
}
emit fileNameChanged(fileName);
}
void FileWidget::setupComboBox()
{
m_lock = true;
m_comboBox->clear();
QDir dir;
if (m_itemNode.isValid())
dir = QFileInfo(m_itemNode.modelNode().model()->fileUrl().toLocalFile()).dir();
else if (m_path.isValid())
dir = QDir(m_path.toLocalFile());
QStringList filterList = m_filter.split(' ');
QDirIterator it(dir.absolutePath(), filterList, QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()) {
QString absolutePath = it.next();
m_comboBox->addItem(dir.relativeFilePath(absolutePath));
}
m_comboBox->setEditText(m_fileName.toString());
m_lock = false;
}
QT_END_NAMESPACE
/****************************************************************************
**
** Copyright (C) 2014 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 FILEWIDGET_H
#define FILEWIDGET_H
#include <QWidget>
#include <QToolButton>
#include <QLineEdit>
#include <QComboBox>
#include <QUrl>
#include <qmlitemnode.h>
QT_BEGIN_NAMESPACE
class FileWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString fileName READ fileName WRITE setFileNameStr NOTIFY fileNameChanged)
Q_PROPERTY(QString filter READ filter WRITE setFilter)
Q_PROPERTY(bool showComboBox READ showComboBox WRITE setShowComboBox)
Q_PROPERTY(QVariant itemNode READ itemNode WRITE setItemNode NOTIFY itemNodeChanged)
Q_PROPERTY(QUrl path READ path WRITE setPath)
public:
FileWidget(QWidget *parent = 0);
~FileWidget();
QVariant itemNode() const { return QVariant::fromValue(m_itemNode.modelNode()); }
void setItemNode(const QVariant &itemNode);
QString fileName() const
{ return m_fileName.toString(); }
void setText(const QString &/*text*/)
{
}
void setPath(const QUrl &url) { m_path = url; setupComboBox(); }
QUrl path() const { return m_path; }
QString text() const
{
return QString();
}
void setFilter(const QString &filter)
{
m_filter = filter;
}
QString filter() const
{
return m_filter;
}
void setShowComboBox(bool show);
bool showComboBox() const
{ return m_showComboBox; }
public slots:
void setFileName(const QUrl &fileName);
void setFileNameStr(const QString &fileName);
void buttonPressed();
void lineEditChanged();
void comboBoxChanged();
signals:
void fileNameChanged(const QUrl &fileName);
void itemNodeChanged();
protected:
private:
void setupComboBox();
QToolButton *m_pushButton;
QLineEdit *m_lineEdit;
QComboBox *m_comboBox;
QUrl m_fileName;
QUrl m_path;
QmlDesigner::QmlItemNode m_itemNode;
QString m_filter;
bool m_showComboBox;
bool m_lock;
QString m_currentPath;
QString m_lastModelPath;
};
QT_END_NAMESPACE
#endif
/****************************************************************************
**
** Copyright (C) 2014 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 "fontwidget.h"
#include <QPushButton>
#include <QLabel>
#include <QHBoxLayout>
#include <QFontDialog>
#include <QComboBox>
namespace QmlDesigner {
FontWidget::FontWidget(QWidget *parent)
: QWidget(parent),
m_label(new QLabel(this)),
m_fontButton(new QPushButton("ABC..", this))
{
QHBoxLayout *horizonalBoxLayout = new QHBoxLayout(this);
horizonalBoxLayout->addWidget(m_label);
horizonalBoxLayout->addWidget(m_fontButton);
m_fontButton->setMinimumHeight(20);
m_fontButton->setCheckable(true);
connect(m_fontButton, SIGNAL(toggled(bool)), SLOT(openFontEditor(bool)));
}
FontWidget::~FontWidget()
{
}
void FontWidget::openFontEditor(bool show)
{
if (show && m_fontDialog.isNull()) {
m_fontDialog = new QFontDialog();
m_fontDialog->setAttribute(Qt::WA_DeleteOnClose);
m_fontDialog->setCurrentFont(m_font);
QComboBox *comboBox = m_fontDialog->findChild<QComboBox*>();
QList<QLabel*> labels = m_fontDialog->findChildren<QLabel*>();
foreach (QLabel *label, labels)
if (label->buddy() == comboBox)
label->hide();
comboBox->hide();
m_fontDialog->show();
connect(m_fontDialog.data(), SIGNAL(accepted()), SLOT(updateFont()));
connect(m_fontDialog.data(), SIGNAL(destroyed(QObject*)), SLOT(resetFontButton()));
} else {
delete m_fontDialog.data();
}
}
void FontWidget::updateFont()
{
QFont font(m_fontDialog->currentFont());
setFamily(font.family());
setItalic(font.italic());
setBold(font.bold());
setFontSize(font.pointSizeF());
emit dataFontChanged();
}
void FontWidget::resetFontButton()
{
m_fontButton->setChecked(false);
}
QString FontWidget::text() const
{
return m_label->text();
}
void FontWidget::setText(const QString &text)
{
m_label->setText(text);
}
QString FontWidget::family() const
{
return m_font.family();
}
void FontWidget::setFamily(const QString &fontFamily)
{
if (fontFamily != m_font.family()) {
m_font.setFamily(fontFamily);
emit familyChanged();
}
}
bool FontWidget::isBold() const
{
return m_font.bold();
}
void FontWidget::setBold(bool isBold)
{
if (m_font.bold() != isBold) {
m_font.setBold(isBold);
emit boldChanged();
}
}
bool FontWidget::isItalic() const
{
return m_font.italic();
}
void FontWidget::setItalic(bool isItalic)
{
if (m_font.italic() != isItalic) {
m_font.setItalic(isItalic);
emit italicChanged();
}
}
QFont FontWidget::font() const
{
return m_font;
}
void FontWidget::setFont(QFont font)
{
if (m_font != font) {
m_font = font;
emit dataFontChanged();
}
}
qreal FontWidget::fontSize() const
{
return m_font.pointSizeF();
}
void FontWidget::setFontSize(qreal size)
{
if (m_font.pointSizeF() != size) {
m_font.setPointSizeF(size);
emit fontSizeChanged();
}
}
void FontWidget::registerDeclarativeTypes() {
qmlRegisterType<QmlDesigner::FontWidget>("Bauhaus",1,0,"FontWidget");
}
} // namespace QmlDesigner
/****************************************************************************
**
** Copyright (C) 2014 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 FONTWIDGET_H
#define FONTWIDGET_H
#include <QWeakPointer>
#include <QWidget>
#include <QtQml>
QT_BEGIN_NAMESPACE
class QLabel;
class QPushButton;
class QFontDialog;
QT_END_NAMESPACE
namespace QmlDesigner {
class FontWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString family READ family WRITE setFamily NOTIFY familyChanged)
Q_PROPERTY(bool bold READ isBold WRITE setBold NOTIFY boldChanged)
Q_PROPERTY(bool italic READ isItalic WRITE setItalic NOTIFY italicChanged)
Q_PROPERTY(qreal fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
Q_PROPERTY(QFont dataFont READ font WRITE setFont NOTIFY dataFontChanged)
public:
FontWidget(QWidget *parent = 0);
~FontWidget();
QString text() const;
void setText(const QString &text);
QString family() const;
void setFamily(const QString &fontFamily);
bool isBold() const;
void setBold(bool isBold);
bool isItalic() const;
void setItalic(bool isItalic);
qreal fontSize() const;
void setFontSize(qreal size);
QFont font() const;
void setFont(QFont size);
static void registerDeclarativeTypes();
signals:
void familyChanged();
void boldChanged();
void italicChanged();
void fontSizeChanged();
void dataFontChanged();
private slots:
void openFontEditor(bool show);
void updateFont();
void resetFontButton();
private: //variables
QFont m_font;
QLabel *m_label;
QPushButton *m_fontButton;
QWeakPointer<QFontDialog> m_fontDialog;
};
} // namespace QmlDesigner
QML_DECLARE_TYPE(QmlDesigner::FontWidget)
#endif // FONTWIDGET_H
/****************************************************************************
**
** Copyright (C) 2014 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 "gradientlineqmladaptor.h"
#include <QMessageBox>
#include <QtQml>
#include <nodeproperty.h>
#include <nodelistproperty.h>
#include <nodemetainfo.h>
#include <abstractview.h>
#include <rewritingexception.h>
#include <variantproperty.h>
namespace QmlDesigner {
GradientLineQmlAdaptor::GradientLineQmlAdaptor(QWidget *parent) :
QmlEditorWidgets::GradientLine(parent)
{
setActive(false);
connect(this, SIGNAL(gradientChanged()), this, SLOT(writeGradient()));
}
void GradientLineQmlAdaptor::setItemNode(const QVariant &itemNode)
{
if (!itemNode.value<ModelNode>().isValid())
return;
m_itemNode = itemNode.value<ModelNode>();
emit itemNodeChanged();
}
static inline QColor normalizeColor(const QColor &color)
{
QColor newColor = QColor(color.name());
newColor.setAlpha(color.alpha());
return newColor;