Merge remote branch 'origin/2.0'

Conflicts:
	share/qtcreator/gdbmacros/dumper.py
	src/libs/qmljs/qmljs-lib.pri
	src/plugins/fakevim/fakevimhandler.cpp
This commit is contained in:
con
2010-07-06 15:34:50 +02:00
50 changed files with 1838 additions and 119 deletions

View File

@@ -1164,7 +1164,7 @@ class Dumper:
self.put('{name="<incomplete>",value="",type="",numchild="0"},') self.put('{name="<incomplete>",value="",type="",numchild="0"},')
def putType(self, type, priority = 0): def putType(self, type, priority = 0):
# higher priority values override lower ones # Higher priority values override lower ones.
if priority >= self.currentTypePriority: if priority >= self.currentTypePriority:
self.currentType = type self.currentType = type
self.currentTypePriority = priority self.currentTypePriority = priority

View File

@@ -24,6 +24,7 @@ HEADERS += \
$$PWD/qmljscompletioncontextfinder.h \ $$PWD/qmljscompletioncontextfinder.h \
$$PWD/qmljscomponentversion.h \ $$PWD/qmljscomponentversion.h \
$$PWD/qmljsmodelmanagerinterface.h \ $$PWD/qmljsmodelmanagerinterface.h \
$$PWD/qmljsicontextpane.h \
$$PWD/qmljspropertyreader.h \ $$PWD/qmljspropertyreader.h \
$$PWD/qmljsrewriter.h $$PWD/qmljsrewriter.h

View File

@@ -0,0 +1,32 @@
#ifndef QMLJSICONTEXTPANE_H
#define QMLJSICONTEXTPANE_H
#include <QObject>
#include "qmljs_global.h"
#include <qmljs/parser/qmljsastfwd_p.h>
#include <qmljs/qmljsdocument.h>
namespace TextEditor {
class BaseTextEditorEditable;
} //TextEditor
namespace QmlJS {
class QMLJS_EXPORT IContextPane : public QObject
{
Q_OBJECT
public:
IContextPane(QObject *parent = 0) : QObject(parent) {}
virtual ~IContextPane() {}
virtual void apply(TextEditor::BaseTextEditorEditable *editor, Document::Ptr doc, AST::Node *node, bool update) = 0;
virtual void setEnabled(bool) = 0;
};
} // namespace QmlJS
#endif // QMLJSICONTEXTPANE_H

View File

@@ -40,10 +40,12 @@
#include <QtGui/QAction> #include <QtGui/QAction>
#include <QtGui/QClipboard> #include <QtGui/QClipboard>
#include <QtGui/QFontMetrics> #include <QtGui/QFontMetrics>
#include <QtGui/QHelpEvent>
#include <QtGui/QMenu> #include <QtGui/QMenu>
#include <QtGui/QMessageBox> #include <QtGui/QMessageBox>
#include <QtGui/QPainter> #include <QtGui/QPainter>
#include <QtGui/QScrollBar> #include <QtGui/QScrollBar>
#include <QtGui/QToolTip>
#include <QtGui/QWheelEvent> #include <QtGui/QWheelEvent>
using namespace BINEditor; using namespace BINEditor;
@@ -1030,7 +1032,64 @@ bool BinEditor::event(QEvent *e) {
break; break;
default:; default:;
} }
} else if (e->type() == QEvent::ToolTip) {
bool hide = true;
int selStart = selectionStart();
int selEnd = selectionEnd();
int byteCount = selEnd - selStart;
if (byteCount <= 0) {
selStart = m_cursorPosition;
selEnd = selStart + 1;
byteCount = 1;
}
if (byteCount <= 8) {
const QPoint &startPoint = offsetToPos(selStart);
const QPoint &endPoint = offsetToPos(selEnd);
const QPoint expandedEndPoint
= QPoint(endPoint.x(), endPoint.y() + m_lineHeight);
const QRect selRect(startPoint, expandedEndPoint);
const QHelpEvent * const helpEvent = static_cast<QHelpEvent *>(e);
const QPoint &mousePos = helpEvent->pos();
if (selRect.contains(mousePos)) {
quint64 beValue, leValue;
asIntegers(selStart, byteCount, beValue, leValue);
QString leSigned;
QString beSigned;
switch (byteCount) {
case 8: case 7: case 6: case 5:
leSigned = QString::number(static_cast<qint64>(leValue));
beSigned = QString::number(static_cast<qint64>(beValue));
break;
case 4: case 3:
leSigned = QString::number(static_cast<qint32>(leValue));
beSigned = QString::number(static_cast<qint32>(beValue));
break;
case 2:
leSigned = QString::number(static_cast<qint16>(leValue));
beSigned = QString::number(static_cast<qint16>(beValue));
break;
case 1:
leSigned = QString::number(static_cast<qint8>(leValue));
beSigned = QString::number(static_cast<qint8>(beValue));
break;
}
hide = false;
QToolTip::showText(helpEvent->globalPos(),
tr("Decimal unsigned value (little endian): %1\n"
"Decimal unsigned value (big endian): %2\n"
"Decimal signed value (little endian): %3\n"
"Decimal signed value (big endian): %4")
.arg(QString::number(leValue))
.arg(QString::number(beValue))
.arg(leSigned).arg(beSigned));
}
}
if (hide)
QToolTip::hideText();
e->accept();
return true;
} }
return QAbstractScrollArea::event(e); return QAbstractScrollArea::event(e);
} }
@@ -1271,13 +1330,7 @@ void BinEditor::contextMenuEvent(QContextMenuEvent *event)
quint64 beAddress = 0; quint64 beAddress = 0;
quint64 leAddress = 0; quint64 leAddress = 0;
if (byteCount <= 8) { if (byteCount <= 8) {
const QByteArray &data = dataMid(selStart, byteCount); asIntegers(selStart, byteCount, beAddress, leAddress);
for (int pos = 0; pos < byteCount; ++pos) {
const quint64 val = static_cast<quint64>(data.at(pos)) & 0xff;
beAddress += val << (pos * 8);
leAddress += val << ((byteCount - pos - 1) * 8);
}
setupJumpToMenuAction(&contextMenu, &jumpToBeAddressHere, setupJumpToMenuAction(&contextMenu, &jumpToBeAddressHere,
&jumpToBeAddressNewWindow, beAddress); &jumpToBeAddressNewWindow, beAddress);
@@ -1335,3 +1388,22 @@ void BinEditor::setNewWindowRequestAllowed()
{ {
m_canRequestNewWindow = true; m_canRequestNewWindow = true;
} }
QPoint BinEditor::offsetToPos(int offset)
{
const int x = m_labelWidth + (offset % 16) * m_columnWidth;
const int y = (offset / 16) * m_lineHeight;
return QPoint(x, y);
}
void BinEditor::asIntegers(int offset, int count, quint64 &beValue,
quint64 &leValue)
{
beValue = leValue = 0;
const QByteArray &data = dataMid(offset, count);
for (int pos = 0; pos < count; ++pos) {
const quint64 val = static_cast<quint64>(data.at(pos)) & 0xff;
beValue += val << (pos * 8);
leValue += val << ((count - pos - 1) * 8);
}
}

View File

@@ -169,6 +169,9 @@ private:
QByteArray dataMid(int from, int length) const; QByteArray dataMid(int from, int length) const;
QByteArray blockData(int block) const; QByteArray blockData(int block) const;
QPoint offsetToPos(int offset);
void asIntegers(int offset, int count, quint64 &beValue, quint64 &leValue);
int m_unmodifiedState; int m_unmodifiedState;
int m_readOnly; int m_readOnly;
int m_margin; int m_margin;

View File

@@ -129,8 +129,8 @@ bool FormEditorStack::removeFormWindowEditor(Core::IEditor *xmlEditor)
const int i = indexOf(xmlEditor); const int i = indexOf(xmlEditor);
if (i == -1) // Fail silently as this is invoked for all editors. if (i == -1) // Fail silently as this is invoked for all editors.
return false; return false;
removeWidget(m_formEditors[i].widgetHost->widget()); removeWidget(m_formEditors[i].widgetHost);
delete m_formEditors[i].widgetHost; m_formEditors[i].widgetHost->deleteLater();
m_formEditors.removeAt(i); m_formEditors.removeAt(i);
return true; return true;
} }

View File

@@ -36,6 +36,7 @@
#include <QtGui/QMainWindow> #include <QtGui/QMainWindow>
#include <QtGui/QStringListModel> #include <QtGui/QStringListModel>
#include <QtGui/QCompleter> #include <QtGui/QCompleter>
#include <QtGui/QKeyEvent>
using namespace Find; using namespace Find;
using namespace Find::Internal; using namespace Find::Internal;
@@ -56,6 +57,7 @@ FindToolWindow::FindToolWindow(FindPlugin *plugin)
connect(m_ui.searchTerm, SIGNAL(textChanged(QString)), this, SLOT(updateButtonStates())); connect(m_ui.searchTerm, SIGNAL(textChanged(QString)), this, SLOT(updateButtonStates()));
m_findCompleter->setModel(m_plugin->findCompletionModel()); m_findCompleter->setModel(m_plugin->findCompletionModel());
m_ui.searchTerm->setCompleter(m_findCompleter); m_ui.searchTerm->setCompleter(m_findCompleter);
m_ui.searchTerm->installEventFilter(this);
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
layout->setMargin(0); layout->setMargin(0);
layout->setSpacing(0); layout->setSpacing(0);
@@ -68,6 +70,17 @@ FindToolWindow::~FindToolWindow()
qDeleteAll(m_configWidgets); qDeleteAll(m_configWidgets);
} }
bool FindToolWindow::eventFilter(QObject *obj, QEvent *event)
{
if (obj == m_ui.searchTerm && event->type() == QEvent::KeyPress) {
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
if (ke->key() == Qt::Key_Down) {
m_findCompleter->complete();
}
}
return QDialog::eventFilter(obj, event);
}
void FindToolWindow::updateButtonStates() void FindToolWindow::updateButtonStates()
{ {
bool enabled = !m_ui.searchTerm->text().isEmpty() bool enabled = !m_ui.searchTerm->text().isEmpty()

View File

@@ -57,6 +57,9 @@ public:
void readSettings(); void readSettings();
void writeSettings(); void writeSettings();
protected:
bool eventFilter(QObject *obj, QEvent *event);
private slots: private slots:
void search(); void search();
void replace(); void replace();

View File

@@ -45,6 +45,7 @@
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QProcess> #include <QtCore/QProcess>
#include <QtCore/QSize>
#include <QtGui/QFileSystemModel> #include <QtGui/QFileSystemModel>
#include <QtGui/QVBoxLayout> #include <QtGui/QVBoxLayout>
#include <QtGui/QToolButton> #include <QtGui/QToolButton>
@@ -143,6 +144,7 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent)
#endif #endif
m_fileSystemModel->setFilter(filters); m_fileSystemModel->setFilter(filters);
m_filterModel->setSourceModel(m_fileSystemModel); m_filterModel->setSourceModel(m_fileSystemModel);
m_listView->setIconSize(QSize(16,16));
m_listView->setModel(m_filterModel); m_listView->setModel(m_filterModel);
m_listView->setFrameStyle(QFrame::NoFrame); m_listView->setFrameStyle(QFrame::NoFrame);
m_listView->setAttribute(Qt::WA_MacShowFocusRect, false); m_listView->setAttribute(Qt::WA_MacShowFocusRect, false);

View File

@@ -63,26 +63,24 @@ void OutputFormatter::setPlainTextEdit(QPlainTextEdit *plainText)
void OutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr) void OutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr)
{ {
gotoEnd(); append(text, onStdErr ? StdErrFormat : StdOutFormat);
if (onStdErr)
setFormat(StdErrFormat);
else
setFormat(StdOutFormat);
plainTextEdit()->insertPlainText(text);
} }
void OutputFormatter::appendMessage(const QString &text, bool isError) void OutputFormatter::appendMessage(const QString &text, bool isError)
{ {
gotoEnd(); append(text, isError ? ErrorMessageFormat : NormalMessageFormat);
}
if (isError) void OutputFormatter::append(const QString &text, Format format)
setFormat(ErrorMessageFormat); {
else append(text, m_formats[format]);
setFormat(NormalMessageFormat); }
plainTextEdit()->insertPlainText(text); void OutputFormatter::append(const QString &text, const QTextCharFormat &format)
{
QTextCursor cursor(m_plainTextEdit->document());
cursor.movePosition(QTextCursor::End);
cursor.insertText(text, format);
} }
void OutputFormatter::mousePressEvent(QMouseEvent * /*e*/) void OutputFormatter::mousePressEvent(QMouseEvent * /*e*/)
@@ -119,14 +117,3 @@ void OutputFormatter::initFormats()
m_formats[StdErrFormat].setFont(font); m_formats[StdErrFormat].setFont(font);
m_formats[StdErrFormat].setForeground(QColor(200, 0, 0)); m_formats[StdErrFormat].setForeground(QColor(200, 0, 0));
} }
void OutputFormatter::setFormat(Format theFormat) const
{
if (m_formats)
plainTextEdit()->setCurrentCharFormat(m_formats[theFormat]);
}
void OutputFormatter::gotoEnd() const
{
plainTextEdit()->moveCursor(QTextCursor::End);
}

View File

@@ -70,9 +70,8 @@ protected:
}; };
void initFormats(); void initFormats();
void setFormat(Format theFormat) const; void append(const QString &text, Format format);
void append(const QString &text, const QTextCharFormat &format);
void gotoEnd() const;
private: private:
QPlainTextEdit *m_plainTextEdit; QPlainTextEdit *m_plainTextEdit;

View File

@@ -507,14 +507,16 @@ void OutputWindow::appendApplicationOutputInline(const QString &out, bool onStdE
void OutputWindow::appendMessage(const QString &out, bool isError) void OutputWindow::appendMessage(const QString &out, bool isError)
{ {
setMaximumBlockCount(MaxBlockCount); setMaximumBlockCount(MaxBlockCount);
const bool atBottom = isScrollbarAtBottom();
m_formatter->appendMessage(doNewlineEnfocement(out), isError); m_formatter->appendMessage(doNewlineEnfocement(out), isError);
if (atBottom)
scrollToBottom();
enableUndoRedo(); enableUndoRedo();
} }
bool OutputWindow::isScrollbarAtBottom() const bool OutputWindow::isScrollbarAtBottom() const
{ {
return blockBoundingRect(document()->lastBlock()).bottom() + contentOffset().y() return verticalScrollBar()->value() == verticalScrollBar()->maximum();
<= viewport()->rect().bottom();
} }
void OutputWindow::scrollToBottom() void OutputWindow::scrollToBottom()

View File

@@ -124,28 +124,29 @@ void ColorButton::paintEvent(QPaintEvent *event)
else else
p.setBrush(Qt::transparent); p.setBrush(Qt::transparent);
p.setPen(QColor(0x444444)); if (color.value() > 80)
p.drawRect(r.translated(1, 1)); p.setPen(QColor(0x444444));
p.setPen(QColor(0x101010)); else
p.drawRect(r); p.setPen(QColor(0x9e9e9e));
p.setPen(QColor(255, 255, 255, 40)); p.drawRect(r.translated(1, 1));
p.drawRect(r.adjusted(1, 1, -1, -1));
p.setRenderHint(QPainter::Antialiasing, true); if (m_showArrow) {
QVector<QPointF> points; p.setRenderHint(QPainter::Antialiasing, true);
if (isChecked()) { QVector<QPointF> points;
points.append(QPointF(2, 3)); if (isChecked()) {
points.append(QPointF(8, 3)); points.append(QPointF(2, 3));
points.append(QPointF(5, 9)); points.append(QPointF(8, 3));
} else { points.append(QPointF(5, 9));
points.append(QPointF(8, 6)); } else {
points.append(QPointF(2, 9)); points.append(QPointF(8, 6));
points.append(QPointF(2, 3)); points.append(QPointF(2, 9));
points.append(QPointF(2, 3));
}
p.translate(0.5, 0.5);
p.setBrush(QColor(0xaaaaaa));
p.setPen(QColor(0x444444));
p.drawPolygon(points);
} }
p.translate(0.5, 0.5);
p.setBrush(QColor(0xaaaaaa));
p.setPen(QColor(0x444444));
p.drawPolygon(points);
} }
@@ -189,24 +190,19 @@ void HueControl::paintEvent(QPaintEvent *event)
} }
} }
p.setPen(QColor(0x404040)); //p.setPen(QColor(0x404040));
p.drawRect(QRect(1, 1, width() - 1, height() - 1).adjusted(10, 5, -20, -5)); //p.drawRect(QRect(1, 1, width() - 1, height() - 1).adjusted(10, 5, -20, -5));
p.drawPixmap(10, 5, m_cache); p.drawPixmap(0, 5, m_cache);
QVector<QPointF> points; QVector<QPointF> points;
int y = m_color.hueF() * 120 + 5; int y = m_color.hueF() * 120 + 5;
points.append(QPointF(15, y)); points.append(QPointF(5, y));
points.append(QPointF(25, y + 5)); points.append(QPointF(15, y + 5));
points.append(QPointF(25, y - 5)); points.append(QPointF(15, y - 5));
p.setBrush(Qt::NoBrush);
p.setPen(QColor(0x101010));
p.drawRect(QRect(0, 0, width() - 1, height() - 1).adjusted(10, 5, -20, -5));
p.setPen(QColor(255, 255, 255, 60));
p.drawRect(QRect(1, 1, width() - 3, height() - 3).adjusted(10, 5, -20, -5));
p.setRenderHint(QPainter::Antialiasing, true); p.setRenderHint(QPainter::Antialiasing, true);
p.translate(0.5, 1.5); p.translate(0.5, 1.5);
@@ -364,15 +360,6 @@ void ColorBox::paintEvent(QPaintEvent *event)
chacheP.drawPoint(x ,y); chacheP.drawPoint(x ,y);
} }
} }
p.setBrush(Qt::NoBrush);
p.setPen(QColor(0x505050));
QRect r(0, 0, width() -1, height() - 1);
p.drawRect(r.adjusted(6, 6, -2, -2));
p.setPen(QColor(0x404040));
p.drawRect(r.adjusted(5, 5, -3, -3));
p.setPen(QColor(0x101010));
p.drawRect(r.adjusted(4, 4, -4, -4));
p.drawPixmap(5, 5, m_cache); p.drawPixmap(5, 5, m_cache);
int x = clamp(m_color.hsvSaturationF() * 120, 0, 119) + 5; int x = clamp(m_color.hsvSaturationF() * 120, 0, 119) + 5;
@@ -384,8 +371,6 @@ void ColorBox::paintEvent(QPaintEvent *event)
p.drawLine(x, 5, x, y-1); p.drawLine(x, 5, x, y-1);
p.drawLine(x, y+1, x, height()-7); p.drawLine(x, y+1, x, height()-7);
p.setPen(QColor(255, 255, 255, 60));
p.drawRect(r.adjusted(5, 5, -5, -5));
} }
void ColorBox::mousePressEvent(QMouseEvent *e) void ColorBox::mousePressEvent(QMouseEvent *e)
@@ -775,33 +760,59 @@ BauhausColorDialog::BauhausColorDialog(QWidget *parent) : QFrame(parent )
m_hueControl = new HueControl(this); m_hueControl = new HueControl(this);
m_colorBox = new ColorBox(this); m_colorBox = new ColorBox(this);
QWidget *colorFrameWidget = new QWidget(this);
QVBoxLayout* vBox = new QVBoxLayout(colorFrameWidget);
colorFrameWidget->setLayout(vBox);
vBox->setSpacing(0);
vBox->setMargin(0);
vBox->setContentsMargins(0,5,0,28);
m_beforeColorWidget = new QFrame(colorFrameWidget);
m_beforeColorWidget->setFixedSize(30, 18);
m_beforeColorWidget->setAutoFillBackground(true);
//m_beforeColorWidget->setFrameShape(QFrame::StyledPanel);
m_currentColorWidget = new QFrame(colorFrameWidget);
m_currentColorWidget->setFixedSize(30, 18);
m_currentColorWidget->setAutoFillBackground(true);
//m_currentColorWidget->setFrameShape(QFrame::StyledPanel);
vBox->addWidget(m_beforeColorWidget);
vBox->addWidget(m_currentColorWidget);
m_rSpinBox = new QDoubleSpinBox(this); m_rSpinBox = new QDoubleSpinBox(this);
m_gSpinBox = new QDoubleSpinBox(this); m_gSpinBox = new QDoubleSpinBox(this);
m_bSpinBox = new QDoubleSpinBox(this); m_bSpinBox = new QDoubleSpinBox(this);
m_alphaSpinBox = new QDoubleSpinBox(this); m_alphaSpinBox = new QDoubleSpinBox(this);
QGridLayout *gridLayout = new QGridLayout(this); QGridLayout *gridLayout = new QGridLayout(this);
gridLayout->setSpacing(4);
gridLayout->setVerticalSpacing(4);
gridLayout->setMargin(4);
setLayout(gridLayout); setLayout(gridLayout);
gridLayout->addWidget(m_colorBox, 0, 0, 4, 1); gridLayout->addWidget(m_colorBox, 0, 0, 4, 1);
gridLayout->addWidget(m_hueControl, 0, 1, 4, 1); gridLayout->addWidget(m_hueControl, 0, 1, 4, 1);
gridLayout->addWidget(new QLabel("R", this), 0, 2, 1, 1); gridLayout->addWidget(colorFrameWidget, 0, 2, 2, 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(new QLabel("R", this), 0, 3, 1, 1);
gridLayout->addWidget(m_bSpinBox, 2, 3, 1, 1); gridLayout->addWidget(new QLabel("G", this), 1, 3, 1, 1);
gridLayout->addWidget(m_alphaSpinBox, 3, 3, 1, 1); gridLayout->addWidget(new QLabel("B", this), 2, 3, 1, 1);
gridLayout->addWidget(new QLabel("A", this), 3, 3, 1, 1);
gridLayout->addWidget(m_rSpinBox, 0, 4, 1, 1);
gridLayout->addWidget(m_gSpinBox, 1, 4, 1, 1);
gridLayout->addWidget(m_bSpinBox, 2, 4, 1, 1);
gridLayout->addWidget(m_alphaSpinBox, 3, 4, 1, 1);
QDialogButtonBox *buttonBox = new QDialogButtonBox(this); QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel); QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
QPushButton *applyButton = buttonBox->addButton(QDialogButtonBox::Apply); QPushButton *applyButton = buttonBox->addButton(QDialogButtonBox::Apply);
gridLayout->addWidget(buttonBox, 4, 0, 2, 1); gridLayout->addWidget(buttonBox, 4, 0, 1, 2);
resize(sizeHint()); resize(sizeHint());
@@ -828,6 +839,14 @@ BauhausColorDialog::BauhausColorDialog(QWidget *parent) : QFrame(parent )
} }
void BauhausColorDialog::setupColor(const QColor &color)
{
QPalette pal = m_beforeColorWidget->palette();
pal.setColor(QPalette::Background, color);
m_beforeColorWidget->setPalette(pal);
setColor(color);
}
void BauhausColorDialog::spinBoxChanged() void BauhausColorDialog::spinBoxChanged()
{ {
if (m_blockUpdate) if (m_blockUpdate)
@@ -857,6 +876,9 @@ void BauhausColorDialog::setupWidgets()
m_gSpinBox->setValue(m_color.greenF()); m_gSpinBox->setValue(m_color.greenF());
m_bSpinBox->setValue(m_color.blueF()); m_bSpinBox->setValue(m_color.blueF());
m_colorBox->setColor(m_color); m_colorBox->setColor(m_color);
QPalette pal = m_currentColorWidget->palette();
pal.setColor(QPalette::Background, m_color);
m_currentColorWidget->setPalette(pal);
m_blockUpdate = false; m_blockUpdate = false;
} }

View File

@@ -55,14 +55,17 @@ Q_OBJECT
Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged) Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
Q_PROPERTY(bool noColor READ noColor WRITE setNoColor) Q_PROPERTY(bool noColor READ noColor WRITE setNoColor)
Q_PROPERTY(bool showArrow READ showArrow WRITE setShowArrow)
public: public:
ColorButton(QWidget *parent = 0) : QToolButton (parent), m_colorString("#ffffff"), m_noColor(false) {} ColorButton(QWidget *parent = 0) : QToolButton (parent), m_colorString("#ffffff"), m_noColor(false), m_showArrow(true) {}
void setColor(const QString &colorStr); void setColor(const QString &colorStr);
QString color() const { return m_colorString; } QString color() const { return m_colorString; }
bool noColor() const { return m_noColor; } bool noColor() const { return m_noColor; }
void setNoColor(bool f) { m_noColor = f; update(); } void setNoColor(bool f) { m_noColor = f; update(); }
bool showArrow() const { return m_showArrow; }
void setShowArrow(bool b) { m_showArrow = b; }
signals: signals:
void colorChanged(); void colorChanged();
@@ -72,6 +75,7 @@ protected:
private: private:
QString m_colorString; QString m_colorString;
bool m_noColor; bool m_noColor;
bool m_showArrow;
}; };
class ColorBox : public QWidget class ColorBox : public QWidget
@@ -138,7 +142,7 @@ public:
HueControl(QWidget *parent = 0) : QWidget(parent), m_color(Qt::white), m_mousePressed(false) HueControl(QWidget *parent = 0) : QWidget(parent), m_color(Qt::white), m_mousePressed(false)
{ {
setFixedWidth(40); setFixedWidth(28);
setFixedHeight(130); setFixedHeight(130);
} }
@@ -227,6 +231,9 @@ public:
BauhausColorDialog(QWidget *parent = 0); BauhausColorDialog(QWidget *parent = 0);
QColor color() const { return m_color; } QColor color() const { return m_color; }
void setupColor(const QColor &color);
void setColor(const QColor &color) void setColor(const QColor &color)
{ {
if (color == m_color) if (color == m_color)
@@ -265,7 +272,9 @@ signals:
protected: protected:
void setupWidgets(); void setupWidgets();
private: private:
QFrame *m_beforeColorWidget;
QFrame *m_currentColorWidget;
ColorBox *m_colorBox; ColorBox *m_colorBox;
HueControl *m_hueControl; HueControl *m_hueControl;

View File

@@ -0,0 +1,418 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ContextPaneTextWidget</class>
<widget class="QWidget" name="ContextPaneTextWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>230</width>
<height>100</height>
</rect>
</property>
<property name="windowTitle">
<string>Text</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="horizontalSpacing">
<number>4</number>
</property>
<property name="verticalSpacing">
<number>2</number>
</property>
<property name="margin">
<number>2</number>
</property>
<item row="0" column="0" colspan="4">
<widget class="QFontComboBox" name="fontComboBox">
<property name="maximumSize">
<size>
<width>120</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="boldButton">
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="italicButton">
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="underlineButton">
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="strikeoutButton">
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="4" colspan="3">
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="leftAlignmentButton">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="centerHAlignmentButton">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="rightAlignmentButton">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="styleLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Style</string>
</property>
</widget>
</item>
<item row="2" column="4" colspan="3">
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="topAlignmentButton">
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="centerVAlignmentButton">
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="bottomAlignmentButton">
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="0" column="6">
<widget class="QmlDesigner::FontSizeSpinBox" name="fontSizeSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="styleComboBox">
<property name="maximumSize">
<size>
<width>70</width>
<height>16777215</height>
</size>
</property>
<item>
<property name="text">
<string>Normal</string>
</property>
</item>
<item>
<property name="text">
<string>Outline</string>
</property>
</item>
<item>
<property name="text">
<string>Raised</string>
</property>
</item>
<item>
<property name="text">
<string>Sunken</string>
</property>
</item>
</widget>
</item>
<item row="2" column="2">
<widget class="QmlDesigner::ColorButton" name="textColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>22</horstretch>
<verstretch>22</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="5">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="4">
<widget class="QmlDesigner::ColorButton" name="colorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>22</horstretch>
<verstretch>22</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QmlDesigner::ColorButton</class>
<extends>QToolButton</extends>
<header location="global">colorwidget.h</header>
</customwidget>
<customwidget>
<class>QmlDesigner::FontSizeSpinBox</class>
<extends>QSpinBox</extends>
<header location="global">fontsizespinbox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,345 @@
#include "contextpanetextwidget.h"
#include "contextpanewidget.h"
#include "ui_contextpanetext.h"
#include <qmljs/qmljspropertyreader.h>
#include <QTimerEvent>
namespace QmlDesigner {
ContextPaneTextWidget::ContextPaneTextWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::ContextPaneTextWidget),
m_fontSizeTimer(-1)
{
ui->setupUi(this);
ui->boldButton->setIcon(QIcon(QLatin1String(":/qmldesigner/images/bold-h-icon.png")));
ui->italicButton->setIcon(QIcon(QLatin1String(":/qmldesigner/images/italic-h-icon.png")));
ui->underlineButton->setIcon(QIcon(QLatin1String(":/qmldesigner/images/underline-h-icon.png")));
ui->strikeoutButton->setIcon(QIcon(QLatin1String(":/qmldesigner/images/strikeout-h-icon.png")));
ui->leftAlignmentButton->setIcon(QIcon(QLatin1String(":/qmldesigner/images/alignmentleft-h-icon.png")));
ui->centerHAlignmentButton->setIcon(QIcon(QLatin1String(":/qmldesigner/images/alignmentcenterh-h-icon.png")));
ui->rightAlignmentButton->setIcon(QIcon(QLatin1String(":/qmldesigner/images/alignmentright-h-icon.png")));
ui->centerVAlignmentButton->setIcon(QIcon(QLatin1String(":/qmldesigner/images/alignmentmiddle-h-icon.png")));
ui->bottomAlignmentButton->setIcon(QIcon(QLatin1String(":/qmldesigner/images/alignmentbottom-h-icon.png")));
ui->topAlignmentButton->setIcon(QIcon(QLatin1String(":/qmldesigner/images/alignmenttop-h-icon.png")));
ui->colorButton->setShowArrow(false);
ui->textColorButton->setShowArrow(false);
connect(ui->colorButton, SIGNAL(toggled(bool)), this, SLOT(onColorButtonToggled(bool)));
connect(ui->textColorButton, SIGNAL(toggled(bool)), this, SLOT(onTextColorButtonToggled(bool)));
ContextPaneWidget *parentContextWidget = qobject_cast<ContextPaneWidget*>(parentWidget());
connect(parentContextWidget->colorDialog(), SIGNAL(accepted(QColor)), this, SLOT(onColorDialogApplied(QColor)));
connect(parentContextWidget->colorDialog(), SIGNAL(rejected()), this, SLOT(onColorDialogCancled()));
connect(ui->fontSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(onFontSizeChanged(int)));
connect(ui->fontSizeSpinBox, SIGNAL(formatChanged()), this, SLOT(onFontFormatChanged()));
connect(ui->boldButton, SIGNAL(toggled(bool)), this, SLOT(onBoldCheckedChanged(bool)));
connect(ui->italicButton, SIGNAL(toggled(bool)), this, SLOT(onItalicCheckedChanged(bool)));
connect(ui->underlineButton, SIGNAL(toggled(bool)), this, SLOT(onUnderlineCheckedChanged(bool)));
connect(ui->strikeoutButton, SIGNAL(toggled(bool)), this, SLOT(onStrikeoutCheckedChanged(bool)));
connect(ui->fontComboBox, SIGNAL(currentFontChanged(QFont)), this, SLOT(onCurrentFontChanged(QFont)));
connect(ui->centerHAlignmentButton, SIGNAL(toggled(bool)), this, SLOT(onHorizontalAlignmentChanged()));
connect(ui->leftAlignmentButton, SIGNAL(toggled(bool)), this, SLOT(onHorizontalAlignmentChanged()));
connect(ui->rightAlignmentButton, SIGNAL(toggled(bool)), this, SLOT(onHorizontalAlignmentChanged()));
connect(ui->centerVAlignmentButton, SIGNAL(toggled(bool)), this, SLOT(onVerticalAlignmentChanged()));
connect(ui->topAlignmentButton, SIGNAL(toggled(bool)), this, SLOT(onVerticalAlignmentChanged()));
connect(ui->bottomAlignmentButton, SIGNAL(toggled(bool)), this, SLOT(onVerticalAlignmentChanged()));
connect(ui->styleComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(onStyleComboBoxChanged(QString)));
}
void ContextPaneTextWidget::setProperties(QmlJS::PropertyReader *propertyReader)
{
if (propertyReader->hasProperty(QLatin1String("font.pointSize"))) {
ui->fontSizeSpinBox->setValue(propertyReader->readProperty(QLatin1String("font.pointSize")).toInt());
ui->fontSizeSpinBox->setIsPointSize(true);
} else if (!propertyReader->hasProperty(QLatin1String("font.pixelSize"))) {
ui->fontSizeSpinBox->setValue(8);
ui->fontSizeSpinBox->setIsPointSize(true);
if (m_fontSizeTimer > 0) {
killTimer(m_fontSizeTimer);
m_fontSizeTimer = -1;
}
}
if (propertyReader->hasProperty(QLatin1String("font.pixelSize"))) {
ui->fontSizeSpinBox->setValue(propertyReader->readProperty(QLatin1String("font.pixelSize")).toInt());
ui->fontSizeSpinBox->setIsPixelSize(true);
}
if (propertyReader->hasProperty(QLatin1String("font.bold"))) {
ui->boldButton->setChecked(propertyReader->readProperty(QLatin1String("font.bold")).toBool());
} else {
ui->boldButton->setChecked(false);
}
if (propertyReader->hasProperty(QLatin1String("font.italic"))) {
ui->italicButton->setChecked(propertyReader->readProperty(QLatin1String("font.italic")).toBool());
} else {
ui->italicButton->setChecked(false);
}
if (propertyReader->hasProperty(QLatin1String("font.underline"))) {
ui->underlineButton->setChecked(propertyReader->readProperty(QLatin1String("font.underline")).toBool());
} else {
ui->underlineButton->setChecked(false);
}
if (propertyReader->hasProperty(QLatin1String("font.strikeout"))) {
ui->strikeoutButton->setChecked(propertyReader->readProperty(QLatin1String("font.strikeout")).toBool());
} else {
ui->strikeoutButton->setChecked(false);
}
if (propertyReader->hasProperty(QLatin1String("color"))) {
ui->colorButton->setColor(propertyReader->readProperty("color").toString());
} else {
ui->colorButton->setColor(QLatin1String("black"));
}
if (propertyReader->hasProperty(QLatin1String("styleColor"))) {
ui->textColorButton->setColor(propertyReader->readProperty("styleColor").toString());
} else {
ui->textColorButton->setColor(QLatin1String("black"));
}
if (propertyReader->hasProperty(QLatin1String("font.family"))) {
QString familyName = propertyReader->readProperty(QLatin1String("font.family")).toString();
QFont font;
font.setFamily(familyName);
ui->fontComboBox->setCurrentFont(font);
}
if (propertyReader->hasProperty(QLatin1String("horizontalAlignment"))) {
QString alignment = propertyReader->readProperty(QLatin1String("horizontalAlignment")).toString();
ui->leftAlignmentButton->setChecked(true);
if (alignment == QLatin1String("Text.AlignHCenter") || alignment == "AlignHCenter")
ui->centerHAlignmentButton->setChecked(true);
else if (alignment == QLatin1String("Text.AlignRight") || alignment == QLatin1String("AlignRight"))
ui->rightAlignmentButton->setChecked(true);
} else {
ui->leftAlignmentButton->setChecked(true);
}
if (propertyReader->hasProperty(QLatin1String("verticalAlignment"))) {
QString alignment = propertyReader->readProperty(QLatin1String("verticalAlignment")).toString();
ui->bottomAlignmentButton->setChecked(true);
if (alignment == QLatin1String("Text.AlignVCenter") || alignment == QLatin1String("AlignVCenter"))
ui->centerVAlignmentButton->setChecked(true);
else if (alignment == QLatin1String("Text.AlignTop") || alignment == QLatin1String("AlignTop"))
ui->topAlignmentButton->setChecked(true);
} else {
ui->topAlignmentButton->setChecked(true);
}
if (propertyReader->hasProperty(QLatin1String("style"))) {
QString style = propertyReader->readProperty(QLatin1String("style")).toString();
ui->styleComboBox->setCurrentIndex(0);
if (style == QLatin1String("Text.Outline") || style == QLatin1String("Outline"))
ui->styleComboBox->setCurrentIndex(1);
if (style == QLatin1String("Text.Raised") || style == QLatin1String("Raised"))
ui->styleComboBox->setCurrentIndex(2);
else if (style == QLatin1String("Text.Sunken") || style == QLatin1String("Sunken"))
ui->styleComboBox->setCurrentIndex(3);
} else {
ui->styleComboBox->setCurrentIndex(0);
}
}
void ContextPaneTextWidget::setVerticalAlignmentVisible(bool b)
{
ui->centerVAlignmentButton->setEnabled(b);
ui->topAlignmentButton->setEnabled(b);
ui->bottomAlignmentButton->setEnabled(b);
}
void ContextPaneTextWidget::setStyleVisible(bool b)
{
ui->styleComboBox->setEnabled(b);
ui->styleLabel->setEnabled(b);
ui->textColorButton->setEnabled(b);
}
void ContextPaneTextWidget::onTextColorButtonToggled(bool flag)
{
ContextPaneWidget *parentContextWidget = qobject_cast<ContextPaneWidget*>(parentWidget());
if (flag)
ui->colorButton->setChecked(false);
QPoint p = mapToGlobal(ui->textColorButton->pos());
parentContextWidget->colorDialog()->setupColor(ui->textColorButton->color());
p = parentContextWidget->colorDialog()->parentWidget()->mapFromGlobal(p);
parentContextWidget->onShowColorDialog(flag, p);
}
void ContextPaneTextWidget::onColorButtonToggled(bool flag)
{
if (flag)
ui->textColorButton->setChecked(false);
ContextPaneWidget *parentContextWidget = qobject_cast<ContextPaneWidget*>(parentWidget());
QPoint p = mapToGlobal(ui->colorButton->pos());
parentContextWidget->colorDialog()->setupColor(ui->colorButton->color());
p = parentContextWidget->colorDialog()->parentWidget()->mapFromGlobal(p);
parentContextWidget->onShowColorDialog(flag, p);
}
void ContextPaneTextWidget::onColorDialogApplied(const QColor &)
{
ContextPaneWidget *parentContextWidget = qobject_cast<ContextPaneWidget*>(parentWidget());
parentContextWidget->onShowColorDialog(false, QPoint());
if (ui->textColorButton->isChecked())
emit propertyChanged(QLatin1String("styleColor"),parentContextWidget->colorDialog()->color());; //write back color
if (ui->colorButton->isChecked())
emit propertyChanged(QLatin1String("color"),parentContextWidget->colorDialog()->color());; //write back color
ui->textColorButton->setChecked(false);
ui->colorButton->setChecked(false);
}
void ContextPaneTextWidget::onColorDialogCancled()
{
ContextPaneWidget *parentContextWidget = qobject_cast<ContextPaneWidget*>(parentWidget());
parentContextWidget->onShowColorDialog(false, QPoint());
ui->colorButton->setChecked(false);
ui->colorButton->setChecked(false);
}
void ContextPaneTextWidget::onFontSizeChanged(int)
{
if (m_fontSizeTimer)
killTimer(m_fontSizeTimer);
m_fontSizeTimer = startTimer(200);
}
void ContextPaneTextWidget::onFontFormatChanged()
{
int size = ui->fontSizeSpinBox->value();
if (ui->fontSizeSpinBox->isPointSize()) {
emit removeAndChangeProperty(QLatin1String("font.pixelSize"), QLatin1String("font.pointSize"), size);
} else {
emit removeAndChangeProperty(QLatin1String("font.pointSize"), QLatin1String("font.pixelSize"), size);
}
}
void ContextPaneTextWidget::onBoldCheckedChanged(bool value)
{
if (value)
emit propertyChanged(QLatin1String("font.bold"), value);
else
emit removeProperty(QLatin1String("font.bold"));
}
void ContextPaneTextWidget::onItalicCheckedChanged(bool value)
{
if (value)
emit propertyChanged(QLatin1String("font.italic"), value);
else
emit removeProperty(QLatin1String("font.italic"));
}
void ContextPaneTextWidget::onUnderlineCheckedChanged(bool value)
{
if (value)
emit propertyChanged(QLatin1String("font.underline"), value);
else
emit removeProperty(QLatin1String("font.underline"));
}
void ContextPaneTextWidget::onStrikeoutCheckedChanged(bool value)
{
if (value)
emit propertyChanged(QLatin1String("font.strikeout"), value);
else
emit removeProperty(QLatin1String("font.strikeout"));
}
void ContextPaneTextWidget::onCurrentFontChanged(const QFont &font)
{
font.family();
emit propertyChanged(QLatin1String("font.family"), QVariant(QString('\"') + font.family() + QString('\"')));
}
void ContextPaneTextWidget::onHorizontalAlignmentChanged()
{
QString alignment;
if (ui->centerHAlignmentButton->isChecked())
alignment = QLatin1String("Text.AlignHCenter");
else if (ui->leftAlignmentButton->isChecked())
alignment = QLatin1String("Text.AlignLeft");
else if (ui->rightAlignmentButton->isChecked())
alignment = QLatin1String("Text.AlignRight");
if (m_horizontalAlignment != alignment) {
m_horizontalAlignment = alignment;
if (alignment == QLatin1String("Text.AlignLeft"))
emit removeProperty(QLatin1String("horizontalAlignment"));
else
emit propertyChanged(QLatin1String("horizontalAlignment"), alignment);
}
}
void ContextPaneTextWidget::onStyleComboBoxChanged(const QString &style)
{
if (style == QLatin1String("Normal"))
emit removeProperty(QLatin1String("style"));
else
emit propertyChanged(QLatin1String("style"), QVariant(QLatin1String("Text.") + style));
}
void ContextPaneTextWidget::onVerticalAlignmentChanged()
{
QString alignment;
if (ui->centerVAlignmentButton->isChecked())
alignment = QLatin1String("Text.AlignVCenter");
else if (ui->topAlignmentButton->isChecked())
alignment = QLatin1String("Text.AlignTop");
else if (ui->bottomAlignmentButton->isChecked())
alignment = QLatin1String("Text.AlignBottom");
if (m_verticalAlignment != alignment) {
m_verticalAlignment = alignment;
if (alignment == QLatin1String("Text.AlignBottom"))
emit removeProperty(QLatin1String("verticalAlignment"));
else
emit propertyChanged(QLatin1String("verticalAlignment"), alignment);
}
}
ContextPaneTextWidget::~ContextPaneTextWidget()
{
delete ui;
}
void ContextPaneTextWidget::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void ContextPaneTextWidget::timerEvent(QTimerEvent *event)
{
if (event->timerId() == m_fontSizeTimer) {
killTimer(m_fontSizeTimer);
m_fontSizeTimer = -1;
int value = ui->fontSizeSpinBox->value();
if (ui->fontSizeSpinBox->isPointSize())
emit propertyChanged(QLatin1String("font.pointSize"), value);
else
emit propertyChanged(QLatin1String("font.pixelSize"), value);
}
}
} //QmlDesigner

View File

@@ -0,0 +1,67 @@
#ifndef CONTEXTPANETEXTWIDGET_H
#define CONTEXTPANETEXTWIDGET_H
#include <QWidget>
#include <QVariant>
QT_BEGIN_NAMESPACE
namespace Ui {
class ContextPaneTextWidget;
}
QT_END_NAMESPACE
namespace QmlJS {
class PropertyReader;
}
namespace QmlDesigner {
class BauhausColorDialog;
class ContextPaneTextWidget : public QWidget
{
Q_OBJECT
public:
explicit ContextPaneTextWidget(QWidget *parent = 0);
~ContextPaneTextWidget();
void setProperties(QmlJS::PropertyReader *propertyReader);
void setVerticalAlignmentVisible(bool);
void setStyleVisible(bool);
public slots:
void onTextColorButtonToggled(bool);
void onColorButtonToggled(bool);
void onColorDialogApplied(const QColor &color);
void onColorDialogCancled();
void onFontSizeChanged(int value);
void onFontFormatChanged();
void onBoldCheckedChanged(bool value);
void onItalicCheckedChanged(bool value);
void onUnderlineCheckedChanged(bool value);
void onStrikeoutCheckedChanged(bool value);
void onCurrentFontChanged(const QFont &font);
void onHorizontalAlignmentChanged();
void onVerticalAlignmentChanged();
void onStyleComboBoxChanged(const QString &style);
signals:
void propertyChanged(const QString &, const QVariant &);
void removeProperty(const QString &);
void removeAndChangeProperty(const QString &, const QString &, const QVariant &);
protected:
void changeEvent(QEvent *e);
void timerEvent(QTimerEvent *event);
private:
Ui::ContextPaneTextWidget *ui;
QString m_verticalAlignment;
QString m_horizontalAlignment;
int m_fontSizeTimer;
};
} //QmlDesigner
#endif // CONTEXTPANETEXTWIDGET_H

View File

@@ -0,0 +1,215 @@
#include "contextpanewidget.h"
#include <coreplugin/icore.h>
#include <QFontComboBox>
#include <QComboBox>
#include <QSpinBox>
#include <QToolButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QMouseEvent>
#include <QGridLayout>
#include <QToolButton>
#include <QAction>
#include <qmldesignerplugin.h>
#include "colorwidget.h"
#include "contextpanetextwidget.h"
namespace QmlDesigner {
ContextPaneWidget::ContextPaneWidget(QWidget *parent) : QFrame(parent), m_currentWidget(0), m_xPos(-1)
{
setFrameStyle(QFrame::NoFrame);
setFrameShape(QFrame::StyledPanel);
setFrameShadow(QFrame::Sunken);
m_oldPos = QPoint(-1, -1);
m_dropShadowEffect = new QGraphicsDropShadowEffect;
m_dropShadowEffect->setBlurRadius(6);
m_dropShadowEffect->setOffset(2, 2);
setGraphicsEffect(m_dropShadowEffect);
QGridLayout *layout = new QGridLayout(this);
layout->setMargin(2);
layout->setContentsMargins(2, 4, 2, 2);
QToolButton *toolButton = new QToolButton(this);
QIcon icon(style()->standardIcon(QStyle::SP_DockWidgetCloseButton));
toolButton->setIcon(icon);
toolButton->setToolButtonStyle(Qt::ToolButtonIconOnly);
toolButton->setFixedSize(icon.availableSizes().first() + QSize(4, 4));
connect(toolButton, SIGNAL(clicked()), this, SLOT(onTogglePane()));
layout->addWidget(toolButton, 0, 0, 1, 1);
colorDialog();
QWidget *fontWidget = createFontWidget();
m_currentWidget = fontWidget;
layout->addWidget(fontWidget, 0, 1, 2, 1);
setAutoFillBackground(true);
setContextMenuPolicy(Qt::ActionsContextMenu);
QAction *disableAction = new QAction(tr("Disable permanently"), this);
addAction(disableAction);
connect(disableAction, SIGNAL(triggered()), this, SLOT(onDisable()));
}
ContextPaneWidget::~ContextPaneWidget()
{
//if the pane was never activated the widget is not in a widget tree
if (!m_bauhausColorDialog.isNull())
delete m_bauhausColorDialog.data();
m_bauhausColorDialog.clear();
}
void ContextPaneWidget::activate(const QPoint &pos, const QPoint &alternative)
{
//uncheck all color buttons
foreach (ColorButton *colorButton, findChildren<ColorButton*>()) {
colorButton->setChecked(false);
}
resize(sizeHint());
show();
rePosition(pos, alternative);
raise();
}
void ContextPaneWidget::rePosition(const QPoint &position, const QPoint &alternative)
{
if (position.y() > 0)
move(position);
else
move(alternative);
if (m_xPos > 0)
move(m_xPos, pos().y());
}
void ContextPaneWidget::deactivate()
{
hide();
if (m_bauhausColorDialog)
m_bauhausColorDialog->hide();
}
BauhausColorDialog *ContextPaneWidget::colorDialog()
{
if (m_bauhausColorDialog.isNull()) {
m_bauhausColorDialog = new BauhausColorDialog(parentWidget());
m_bauhausColorDialog->hide();
}
return m_bauhausColorDialog.data();
}
void ContextPaneWidget::setProperties(::QmlJS::PropertyReader *propertyReader)
{
ContextPaneTextWidget *textWidget = qobject_cast<ContextPaneTextWidget*>(m_currentWidget);
if (textWidget)
textWidget->setProperties(propertyReader);
}
bool ContextPaneWidget::setType(const QString &typeName)
{
if (typeName.contains("Text")) {
m_currentWidget = m_textWidget;
m_textWidget->show();
m_textWidget->setStyleVisible(true);
m_textWidget->setVerticalAlignmentVisible(true);
if (typeName.contains("TextInput")) {
m_textWidget->setVerticalAlignmentVisible(false);
m_textWidget->setStyleVisible(false);
} else if (typeName.contains("TextEdit")) {
m_textWidget->setStyleVisible(false);
}
return true;
}
m_textWidget->hide();
return false;
}
void ContextPaneWidget::onTogglePane()
{
if (!m_currentWidget)
return;
deactivate();
}
void ContextPaneWidget::onShowColorDialog(bool checked, const QPoint &p)
{
if (checked) {
colorDialog()->setParent(parentWidget());
colorDialog()->move(p);
colorDialog()->show();
colorDialog()->raise();
} else {
colorDialog()->hide();
}
}
void ContextPaneWidget::mousePressEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton) {
m_oldPos = event->globalPos();
m_opacityEffect = new QGraphicsOpacityEffect;
setGraphicsEffect(m_opacityEffect);
event->accept();
}
QFrame::mousePressEvent(event);
}
void ContextPaneWidget::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
m_oldPos = QPoint(-1, -1);
m_dropShadowEffect = new QGraphicsDropShadowEffect;
m_dropShadowEffect->setBlurRadius(6);
m_dropShadowEffect->setOffset(2, 2);
setGraphicsEffect(m_dropShadowEffect);
}
QFrame::mouseReleaseEvent(event);
}
void ContextPaneWidget::mouseMoveEvent(QMouseEvent * event)
{
if (event->buttons() && Qt::LeftButton) {
if (m_oldPos != QPoint(-1, -1)) {
QPoint diff = event->globalPos() - m_oldPos;
move(pos() + diff);
if (m_bauhausColorDialog)
m_bauhausColorDialog->move(m_bauhausColorDialog->pos() + diff);
m_xPos = pos().x();
} else {
m_opacityEffect = new QGraphicsOpacityEffect;
setGraphicsEffect(m_opacityEffect);
}
m_oldPos = event->globalPos();
event->accept();
}
}
void ContextPaneWidget::onDisable()
{
DesignerSettings designerSettings = Internal::BauhausPlugin::pluginInstance()->settings();
designerSettings.enableContextPane = false;
Internal::BauhausPlugin::pluginInstance()->setSettings(designerSettings);
hide();
colorDialog()->hide();
}
QWidget* ContextPaneWidget::createFontWidget()
{
m_textWidget = new ContextPaneTextWidget(this);
connect(m_textWidget, SIGNAL(propertyChanged(QString,QVariant)), this, SIGNAL(propertyChanged(QString,QVariant)));
connect(m_textWidget, SIGNAL(removeProperty(QString)), this, SIGNAL(removeProperty(QString)));
connect(m_textWidget, SIGNAL(removeAndChangeProperty(QString,QString,QVariant)), this, SIGNAL(removeAndChangeProperty(QString,QString,QVariant)));
return m_textWidget;
}
} //QmlDesigner

View File

@@ -0,0 +1,64 @@
#ifndef CONTEXTPANEWIDGET_H
#define CONTEXTPANEWIDGET_H
#include <QFrame>
#include <QVariant>
#include <QGraphicsEffect>
#include <QWeakPointer>
namespace QmlJS {
class PropertyReader;
}
namespace QmlDesigner {
class BauhausColorDialog;
class ContextPaneTextWidget;
class ContextPaneWidget : public QFrame
{
Q_OBJECT
public:
explicit ContextPaneWidget(QWidget *parent = 0);
~ContextPaneWidget();
void activate(const QPoint &pos, const QPoint &alternative);
void rePosition(const QPoint &pos, const QPoint &alternative);
void deactivate();
BauhausColorDialog *colorDialog();
void setProperties(QmlJS::PropertyReader *propertyReader);
bool setType(const QString &typeName);
QWidget* currentWidget() const { return m_currentWidget; }
public slots:
void onTogglePane();
void onShowColorDialog(bool, const QPoint &);
signals:
void propertyChanged(const QString &, const QVariant &);
void removeProperty(const QString &);
void removeAndChangeProperty(const QString &, const QString &, const QVariant &);
private slots:
void onDisable();
protected:
QWidget *createFontWidget();
void mousePressEvent(QMouseEvent * event);
void mouseReleaseEvent(QMouseEvent * event);
void mouseMoveEvent(QMouseEvent * event);
private:
QWidget *m_currentWidget;
ContextPaneTextWidget *m_textWidget;
QPoint m_oldPos;
QGraphicsDropShadowEffect *m_dropShadowEffect;
QGraphicsOpacityEffect *m_opacityEffect;
QWeakPointer<BauhausColorDialog> m_bauhausColorDialog;
QString m_colorName;
int m_xPos;
};
} //QmlDesigner
#endif // CONTEXTPANEWIDGET_H

View File

@@ -0,0 +1,73 @@
#include "fontsizespinbox.h"
#include <QLineEdit>
#include <QRegExpValidator>
namespace QmlDesigner {
FontSizeSpinBox::FontSizeSpinBox(QWidget *parent) :
QAbstractSpinBox(parent), m_isPointSize(true), m_value(0)
{
connect(this, SIGNAL(editingFinished()), this, SLOT(onEditingFinished()));
}
void FontSizeSpinBox::stepBy(int steps)
{
setValue(value() + steps);
}
void FontSizeSpinBox::clear ()
{
setValue(1);
}
void FontSizeSpinBox::setValue (int val)
{
if (m_value == val)
return;
m_value = val;
setText();
emit valueChanged(val);
}
QAbstractSpinBox::StepEnabled FontSizeSpinBox::stepEnabled() const
{
if (value() > 1)
return (StepUpEnabled | StepDownEnabled);
else
return StepUpEnabled;
}
void FontSizeSpinBox::setText()
{
QString text = QString::number(m_value);
if (isPointSize())
text.append(" pt");
else
text.append(" px");
lineEdit()->setText(text);
}
void FontSizeSpinBox::onEditingFinished()
{
QString str = lineEdit()->text();
if (str.contains("px")) {
setIsPixelSize(true);
str.remove("px");
setValue(str.toInt());
} else {
setIsPointSize(true);
str.remove("pt");
setValue(str.toInt());
}
}
QValidator::State FontSizeSpinBox::validate (QString &input, int &p) const
{
QRegExp rx("\\d+\\s*(px|pt)");
QRegExpValidator v(rx, 0);
return v.validate(input, p);
}
} //QmlDesigner

View File

@@ -0,0 +1,70 @@
#ifndef FONTSIZESPINBOX_H
#define FONTSIZESPINBOX_H
#include <QAbstractSpinBox>
namespace QmlDesigner {
class FontSizeSpinBox : public QAbstractSpinBox
{
Q_OBJECT
Q_PROPERTY(bool isPixelSize READ isPixelSize WRITE setIsPixelSize NOTIFY formatChanged)
Q_PROPERTY(bool isPointSize READ isPointSize WRITE setIsPointSize NOTIFY formatChanged)
Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
public:
explicit FontSizeSpinBox(QWidget *parent = 0);
bool isPixelSize() { return !m_isPointSize; }
bool isPointSize() { return m_isPointSize; }
void stepBy(int steps);
QValidator::State validate (QString &input, int &pos) const;
int value() const { return m_value; }
signals:
void formatChanged();
void valueChanged(int);
public slots:
void setIsPointSize(bool b)
{
if (isPointSize() == b)
return;
m_isPointSize = b;
setText();
emit formatChanged();
}
void setIsPixelSize(bool b)
{
if (isPixelSize() == b)
return;
m_isPointSize = !b;
setText();
emit formatChanged();
}
void clear();
void setValue (int val);
protected:
StepEnabled stepEnabled() const;
private slots:
void onEditingFinished();
void setText();
private:
bool m_isPointSize;
int m_value;
};
} //QmlDesigner
#endif // FONTSIZESPINBOX_H

View File

@@ -19,7 +19,10 @@ SOURCES += propertyeditor.cpp \
siblingcombobox.cpp \ siblingcombobox.cpp \
propertyeditortransaction.cpp \ propertyeditortransaction.cpp \
propertyeditorcontextobject.cpp \ propertyeditorcontextobject.cpp \
declarativewidgetview.cpp declarativewidgetview.cpp \
contextpanewidget.cpp \
contextpanetextwidget.cpp \
fontsizespinbox.cpp
HEADERS += propertyeditor.h \ HEADERS += propertyeditor.h \
qmlanchorbindingproxy.h \ qmlanchorbindingproxy.h \
@@ -40,7 +43,11 @@ HEADERS += propertyeditor.h \
propertyeditortransaction.h \ propertyeditortransaction.h \
designerpropertymap.h \ designerpropertymap.h \
propertyeditorcontextobject.h \ propertyeditorcontextobject.h \
declarativewidgetview.h declarativewidgetview.h \
contextpanewidget.h \
contextpanetextwidget.h \
fontsizespinbox.h
QT += declarative QT += declarative
RESOURCES += propertyeditor.qrc RESOURCES += propertyeditor.qrc
FORMS += behaviordialog.ui FORMS += behaviordialog.ui \
contextpanetext.ui

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 367 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

View File

@@ -102,6 +102,22 @@
<file>images/button-pressed-right.png</file> <file>images/button-pressed-right.png</file>
<file>images/button-normal-left.png</file> <file>images/button-normal-left.png</file>
<file>images/button-normal-middle.png</file> <file>images/button-normal-middle.png</file>
<file>images/button-normal-right.png</file> <file>images/button-normal-right.png</file>
<file>images/alignmentbottom-h-icon.png</file>
<file>images/alignmentbottom-icon.png</file>
<file>images/alignmentcenterh-h-icon.png</file>
<file>images/alignmentcenterh-icon.png</file>
<file>images/alignmentleft-h-icon.png</file>
<file>images/alignmentleft-icon.png</file>
<file>images/alignmentmiddle-h-icon.png</file>
<file>images/alignmentmiddle-icon.png</file>
<file>images/alignmentright-h-icon.png</file>
<file>images/alignmentright-icon.png</file>
<file>images/alignmenttop-h-icon.png</file>
<file>images/alignmenttop-icon.png</file>
<file>images/underline-h-icon.png</file>
<file>images/strikeout-h-icon.png</file>
<file>images/italic-h-icon.png</file>
<file>images/bold-h-icon.png</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@@ -51,6 +51,8 @@ void DesignerSettings::fromSettings(QSettings *settings)
QLatin1String(QmlDesigner::Constants::QML_ITEMSPACING_KEY), QVariant(0)).toInt(); QLatin1String(QmlDesigner::Constants::QML_ITEMSPACING_KEY), QVariant(0)).toInt();
snapMargin = settings->value( snapMargin = settings->value(
QLatin1String(QmlDesigner::Constants::QML_SNAPMARGIN_KEY), QVariant(0)).toInt(); QLatin1String(QmlDesigner::Constants::QML_SNAPMARGIN_KEY), QVariant(0)).toInt();
enableContextPane = settings->value(
QLatin1String(QmlDesigner::Constants::QML_CONTEXTPANE_KEY), QVariant(0)).toBool();
settings->endGroup(); settings->endGroup();
settings->endGroup(); settings->endGroup();
@@ -63,6 +65,7 @@ void DesignerSettings::toSettings(QSettings *settings) const
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_OPENDESIGNMODE_SETTINGS_KEY), openDesignMode); settings->setValue(QLatin1String(QmlDesigner::Constants::QML_OPENDESIGNMODE_SETTINGS_KEY), openDesignMode);
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_ITEMSPACING_KEY), itemSpacing); settings->setValue(QLatin1String(QmlDesigner::Constants::QML_ITEMSPACING_KEY), itemSpacing);
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_SNAPMARGIN_KEY), snapMargin); settings->setValue(QLatin1String(QmlDesigner::Constants::QML_SNAPMARGIN_KEY), snapMargin);
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_CONTEXTPANE_KEY), enableContextPane);
settings->endGroup(); settings->endGroup();
settings->endGroup(); settings->endGroup();
@@ -72,6 +75,7 @@ bool DesignerSettings::equals(const DesignerSettings &other) const
{ {
return openDesignMode == other.openDesignMode return openDesignMode == other.openDesignMode
&& snapMargin == other.snapMargin && snapMargin == other.snapMargin
&& itemSpacing == other.itemSpacing; && itemSpacing == other.itemSpacing
&& enableContextPane == other.enableContextPane;
} }

View File

@@ -50,6 +50,7 @@ public:
bool openDesignMode; bool openDesignMode;
int itemSpacing; int itemSpacing;
int snapMargin; int snapMargin;
bool enableContextPane;
}; };
inline bool operator==(const DesignerSettings &s1, const DesignerSettings &s2) inline bool operator==(const DesignerSettings &s1, const DesignerSettings &s2)

View File

@@ -0,0 +1,225 @@
#include "qmlcontextpane.h"
#include <contextpanewidget.h>
#include <qmldesignerplugin.h>
#include <utils/changeset.h>
#include <qmljs/parser/qmljsast_p.h>
#include <qmljs/qmljsdocument.h>
#include <qmljs/qmljspropertyreader.h>
#include <qmljs/qmljsrewriter.h>
#include <qmljs/qmljsindenter.h>
#include <texteditor/basetexteditor.h>
#include <texteditor/tabsettings.h>
#include <colorwidget.h>
using namespace QmlJS;
using namespace AST;
namespace QmlDesigner {
static inline QString textAt(const Document* doc,
const SourceLocation &from,
const SourceLocation &to)
{
return doc->source().mid(from.offset, to.end() - from.begin());
}
QmlContextPane::QmlContextPane(QObject *parent) : ::QmlJS::IContextPane(parent), m_blockWriting(false)
{
m_node = 0;
ContextPaneWidget();
m_propertyOrder
<< QLatin1String("id")
<< QLatin1String("name")
<< QLatin1String("target")
<< QLatin1String("property")
<< QLatin1String("x")
<< QLatin1String("y")
<< QLatin1String("width")
<< QLatin1String("height")
<< QLatin1String("position")
<< QLatin1String("color")
<< QLatin1String("radius")
<< QLatin1String("text")
<< QLatin1String("font.family")
<< QLatin1String("font.bold")
<< QLatin1String("font.italic")
<< QLatin1String("font.underline")
<< QLatin1String("font.strikeout")
<< QString::null
<< QLatin1String("states")
<< QLatin1String("transitions")
;
}
QmlContextPane::~QmlContextPane()
{
//if the pane was never activated the widget is not in a widget tree
if (!m_widget.isNull())
delete m_widget.data();
m_widget.clear();
}
void QmlContextPane::apply(TextEditor::BaseTextEditorEditable *editor, Document::Ptr doc, Node *node, bool update)
{
if (!Internal::BauhausPlugin::pluginInstance()->settings().enableContextPane)
return;
setEnabled(doc->isParsedCorrectly());
m_editor = editor;
contextWidget()->setParent(editor->widget()->parentWidget());
contextWidget()->colorDialog()->setParent(editor->widget()->parentWidget());
if (UiObjectDefinition *objectMember = cast<UiObjectDefinition*>(node)) {
QString name = objectMember->qualifiedTypeNameId->name->asString();
if (name.contains("Text")) {
m_node = 0;
PropertyReader propertyReader(doc.data(), objectMember->initializer);
QTextCursor tc(editor->editor()->document());
const quint32 offset = objectMember->firstSourceLocation().offset;
const quint32 end = objectMember->lastSourceLocation().end();
QString name = objectMember->qualifiedTypeNameId->name->asString();
tc.setPosition(offset);
QPoint p1 = editor->editor()->mapToParent(editor->editor()->viewport()->mapToParent(editor->editor()->cursorRect(tc).topLeft()) - QPoint(0, contextWidget()->height() + 10));
tc.setPosition(end);
QPoint p2 = editor->editor()->mapToParent(editor->editor()->viewport()->mapToParent(editor->editor()->cursorRect(tc).bottomLeft()) + QPoint(0, 10));
p2.setX(p1.x());
if (!update)
contextWidget()->activate(p1 , p2);
else
contextWidget()->rePosition(p1 , p2);
m_blockWriting = true;
contextWidget()->setType(name);
contextWidget()->setProperties(&propertyReader);
m_blockWriting = false;
m_doc = doc;
m_node = node;
} else {
contextWidget()->setParent(0);
contextWidget()->hide();
contextWidget()->colorDialog()->hide();
}
} else {
contextWidget()->setParent(0);
contextWidget()->hide();
contextWidget()->colorDialog()->hide();
}
}
void QmlContextPane::setProperty(const QString &propertyName, const QVariant &value)
{
QString stringValue = value.toString();
if (value.type() == QVariant::Color)
stringValue = QChar('\"') + value.toString() + QChar('\"');
if (UiObjectDefinition *objectMember = cast<UiObjectDefinition*>(m_node)) {
Utils::ChangeSet changeSet;
Rewriter rewriter(m_doc->source(), &changeSet, m_propertyOrder);
int line = 1;
PropertyReader propertyReader(m_doc.data(), objectMember->initializer);
if (propertyReader.hasProperty(propertyName)) {
rewriter.changeProperty(objectMember->initializer, propertyName, stringValue, Rewriter::ScriptBinding);
} else {
rewriter.addBinding(objectMember->initializer, propertyName, stringValue, Rewriter::ScriptBinding);
int column;
m_editor->convertPosition(changeSet.operationList().first().pos1, &line, &column); //get line
}
QTextCursor tc(m_editor->editor()->document());
int cursorPostion = tc.position();
tc.beginEditBlock();
changeSet.apply(&tc);
if (line > 0) {
TextEditor::TabSettings ts = m_editor->editor()->tabSettings();
QmlJSIndenter indenter;
indenter.setTabSize(ts.m_tabSize);
indenter.setIndentSize(ts.m_indentSize);
QTextBlock start = m_editor->editor()->document()->findBlockByLineNumber(line);
QTextBlock end = m_editor->editor()->document()->findBlockByLineNumber(line);
const int indent = indenter.indentForBottomLine(m_editor->editor()->document()->begin(), end.next(), QChar::Null);
ts.indentLine(start, indent);
}
tc.endEditBlock();
tc.setPosition(cursorPostion);
}
}
void QmlContextPane::removeProperty(const QString &propertyName)
{
if (UiObjectDefinition *objectMember = cast<UiObjectDefinition*>(m_node)) {
PropertyReader propertyReader(m_doc.data(), objectMember->initializer);
if (propertyReader.hasProperty(propertyName)) {
Utils::ChangeSet changeSet;
Rewriter rewriter(m_doc->source(), &changeSet, m_propertyOrder);
rewriter.removeProperty(objectMember->initializer, propertyName);
QTextCursor tc(m_editor->editor()->document());
changeSet.apply(&tc);
}
}
}
void QmlContextPane::setEnabled(bool b)
{
if (m_widget)
m_widget->currentWidget()->setEnabled(b);
}
void QmlContextPane::onPropertyChanged(const QString &name, const QVariant &value)
{
if (m_blockWriting)
return;
if (!m_doc)
return;
setProperty(name, value);
m_doc.clear(); //the document is outdated
}
void QmlContextPane::onPropertyRemovedAndChange(const QString &remove, const QString &change, const QVariant &value)
{
if (m_blockWriting)
return;
if (!m_doc)
return;
setProperty(change, value);
removeProperty(remove);
m_doc.clear(); //the document is outdated
}
ContextPaneWidget* QmlContextPane::contextWidget()
{
if (m_widget.isNull()) { //lazily recreate widget
m_widget = new ContextPaneWidget;
connect(m_widget.data(), SIGNAL(propertyChanged(QString,QVariant)), this, SLOT(onPropertyChanged(QString,QVariant)));
connect(m_widget.data(), SIGNAL(removeProperty(QString)), this, SLOT(onPropertyRemoved(QString)));
connect(m_widget.data(), SIGNAL(removeAndChangeProperty(QString,QString,QVariant)), this, SLOT(onPropertyRemovedAndChange(QString,QString,QVariant)));
}
return m_widget.data();
}
void QmlContextPane::onPropertyRemoved(const QString &propertyName)
{
if (m_blockWriting)
return;
if (!m_doc)
return;
removeProperty(propertyName);
m_doc.clear(); //the document is outdated
}
} //QmlDesigner

View File

@@ -0,0 +1,52 @@
#ifndef QMLCONTEXTPANE_H
#define QMLCONTEXTPANE_H
#include <QLabel>
#include <QToolBar>
#include <QPushButton>
#include <QToolButton>
#include <QGridLayout>
#include <QGroupBox>
#include <QVariant>
#include <QGraphicsDropShadowEffect>
#include <QWeakPointer>
#include <qmljs/qmljsicontextpane.h>
namespace TextEditor {
class BaseTextEditorEditable;
}
namespace QmlDesigner {
class ContextPaneWidget;
class QmlContextPane : public QmlJS::IContextPane
{
Q_OBJECT
public:
QmlContextPane(QObject *parent = 0);
~QmlContextPane();
void apply(TextEditor::BaseTextEditorEditable *editor, QmlJS::Document::Ptr doc, QmlJS::AST::Node *node, bool update);
void setProperty(const QString &propertyName, const QVariant &value);
void removeProperty(const QString &propertyName);
void setEnabled(bool);
public slots:
void onPropertyChanged(const QString &, const QVariant &);
void onPropertyRemoved(const QString &);
void onPropertyRemovedAndChange(const QString &, const QString &, const QVariant &);
private:
ContextPaneWidget* contextWidget();
QWeakPointer<ContextPaneWidget> m_widget;
QmlJS::Document::Ptr m_doc;
QmlJS::AST::Node *m_node;
TextEditor::BaseTextEditorEditable *m_editor;
bool m_blockWriting;
QStringList m_propertyOrder;
};
} //QmlDesigner
#endif // QMLCONTEXTPANE_H

View File

@@ -61,6 +61,7 @@ const char * const QML_DESIGNER_SETTINGS_GROUP = "Designer";
const char * const QML_OPENDESIGNMODE_SETTINGS_KEY = "OpenDesignMode"; const char * const QML_OPENDESIGNMODE_SETTINGS_KEY = "OpenDesignMode";
const char * const QML_ITEMSPACING_KEY = "ItemSpacing"; const char * const QML_ITEMSPACING_KEY = "ItemSpacing";
const char * const QML_SNAPMARGIN_KEY = "SnapMargin"; const char * const QML_SNAPMARGIN_KEY = "SnapMargin";
const char * const QML_CONTEXTPANE_KEY = "ContextPaneEnabled";
enum { QML_OPENDESIGNMODE_DEFAULT = 0 }; // 0 for text mode, 1 for design mode enum { QML_OPENDESIGNMODE_DEFAULT = 0 }; // 0 for text mode, 1 for design mode
const char * const SETTINGS_CATEGORY_QML_ICON = ":/core/images/category_qml.png"; const char * const SETTINGS_CATEGORY_QML_ICON = ":/core/images/category_qml.png";

View File

@@ -34,6 +34,8 @@
#include "designmodewidget.h" #include "designmodewidget.h"
#include "settingspage.h" #include "settingspage.h"
#include "designmodecontext.h" #include "designmodecontext.h"
#include "qmlcontextpane.h"
#include <qmljseditor/qmljseditorconstants.h> #include <qmljseditor/qmljseditorconstants.h>
@@ -145,6 +147,8 @@ bool BauhausPlugin::initialize(const QStringList & /*arguments*/, QString *error
m_settings.fromSettings(core->settings()); m_settings.fromSettings(core->settings());
addAutoReleasedObject(new QmlContextPane);
error_message->clear(); error_message->clear();
return true; return true;

View File

@@ -23,14 +23,18 @@ HEADERS += qmldesignerconstants.h \
designersettings.h \ designersettings.h \
settingspage.h \ settingspage.h \
designmodecontext.h \ designmodecontext.h \
styledoutputpaneplaceholder.h styledoutputpaneplaceholder.h \
qmlcontextpane.h
SOURCES += qmldesignerplugin.cpp \ SOURCES += qmldesignerplugin.cpp \
designmodewidget.cpp \ designmodewidget.cpp \
application.cpp \ application.cpp \
designersettings.cpp \ designersettings.cpp \
settingspage.cpp \ settingspage.cpp \
designmodecontext.cpp \ designmodecontext.cpp \
styledoutputpaneplaceholder.cpp styledoutputpaneplaceholder.cpp \
qmlcontextpane.cpp
FORMS += settingspage.ui FORMS += settingspage.ui
OTHER_FILES += QmlDesigner.pluginspec OTHER_FILES += QmlDesigner.pluginspec

View File

@@ -49,6 +49,7 @@ DesignerSettings SettingsPageWidget::settings() const
DesignerSettings ds; DesignerSettings ds;
ds.itemSpacing = m_ui.spinItemSpacing->value(); ds.itemSpacing = m_ui.spinItemSpacing->value();
ds.snapMargin = m_ui.spinSnapMargin->value(); ds.snapMargin = m_ui.spinSnapMargin->value();
ds.enableContextPane = m_ui.textEditHelperCheckBox->isChecked();
return ds; return ds;
} }
@@ -56,6 +57,7 @@ void SettingsPageWidget::setSettings(const DesignerSettings &s)
{ {
m_ui.spinItemSpacing->setValue(s.itemSpacing); m_ui.spinItemSpacing->setValue(s.itemSpacing);
m_ui.spinSnapMargin->setValue(s.snapMargin); m_ui.spinSnapMargin->setValue(s.snapMargin);
m_ui.textEditHelperCheckBox->setChecked(s.enableContextPane);
} }
QString SettingsPageWidget::searchKeywords() const QString SettingsPageWidget::searchKeywords() const

View File

@@ -13,8 +13,8 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout">
<item row="2" column="0"> <item row="0" column="0">
<widget class="QGroupBox" name="groupBox_3"> <widget class="QGroupBox" name="groupBox_3">
<property name="title"> <property name="title">
<string>Snapping</string> <string>Snapping</string>
@@ -98,7 +98,23 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="1" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Text Editor Helper</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="textEditHelperCheckBox">
<property name="text">
<string>enable</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>

View File

@@ -46,15 +46,7 @@ QmlOutputFormatter::QmlOutputFormatter(QObject *parent)
void QmlOutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr) void QmlOutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr)
{ {
gotoEnd(); QTextCharFormat linkFormat;
if (onStdErr)
setFormat(StdErrFormat);
else
setFormat(StdOutFormat);
QTextCharFormat normalFormat = plainTextEdit()->currentCharFormat();
QTextCharFormat linkFormat = normalFormat;
linkFormat.setForeground(plainTextEdit()->palette().link().color()); linkFormat.setForeground(plainTextEdit()->palette().link().color());
linkFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline); linkFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
linkFormat.setAnchor(true); linkFormat.setAnchor(true);
@@ -64,17 +56,15 @@ void QmlOutputFormatter::appendApplicationOutput(const QString &text, bool onStd
while (m_qmlError.indexIn(text, index) != -1) { while (m_qmlError.indexIn(text, index) != -1) {
const int matchPos = m_qmlError.pos(1); const int matchPos = m_qmlError.pos(1);
const QString leader = text.mid(index, matchPos - index); const QString leader = text.mid(index, matchPos - index);
plainTextEdit()->insertPlainText(leader); append(leader, onStdErr ? StdErrFormat : StdOutFormat);
const QString matched = m_qmlError.cap(1); const QString matched = m_qmlError.cap(1);
linkFormat.setAnchorHref(matched); linkFormat.setAnchorHref(matched);
plainTextEdit()->setCurrentCharFormat(linkFormat); append(matched, linkFormat);
plainTextEdit()->insertPlainText(matched);
plainTextEdit()->setCurrentCharFormat(normalFormat);
index = matchPos + m_qmlError.matchedLength() - 1; index = matchPos + m_qmlError.matchedLength() - 1;
} }
plainTextEdit()->insertPlainText(text.mid(index)); append(text.mid(index), onStdErr ? StdErrFormat : StdOutFormat);
} }
void QmlOutputFormatter::mousePressEvent(QMouseEvent * /*e*/) void QmlOutputFormatter::mousePressEvent(QMouseEvent * /*e*/)

View File

@@ -316,7 +316,7 @@ struct InternalNode
#endif #endif
QStringListIterator it(parts); QStringListIterator it(parts);
InternalNode *currentNode = this; InternalNode *currentNode = this;
QString path = (isRelative ? projectDir : ""); QString path = (isRelative ? projectDirWithSeparator : "");
while (it.hasNext()) { while (it.hasNext()) {
const QString &key = it.next(); const QString &key = it.next();
if (it.hasNext()) { // key is directory if (it.hasNext()) { // key is directory