diff options
author | con <qtc-committer@nokia.com> | 2010-07-06 15:34:50 +0200 |
---|---|---|
committer | con <qtc-committer@nokia.com> | 2010-07-06 15:34:50 +0200 |
commit | 1a2a4f6387e890d6564eac5644bb26bfe6985d2c (patch) | |
tree | 1bbbc92c4f458ca878489d2e84cbc6fa8839b504 /src/plugins | |
parent | 7feed7318b3ca52d56cb6eb8f11233f32bdcae09 (diff) | |
parent | 15047f8816716af0794da4164daa3e007175a78a (diff) | |
download | qt-creator-1a2a4f6387e890d6564eac5644bb26bfe6985d2c.tar.gz |
Merge remote branch 'origin/2.0'
Conflicts:
share/qtcreator/gdbmacros/dumper.py
src/libs/qmljs/qmljs-lib.pri
src/plugins/fakevim/fakevimhandler.cpp
Diffstat (limited to 'src/plugins')
47 files changed, 1804 insertions, 118 deletions
diff --git a/src/plugins/bineditor/bineditor.cpp b/src/plugins/bineditor/bineditor.cpp index 3e98ee0ad4..0a6dbcfbb2 100644 --- a/src/plugins/bineditor/bineditor.cpp +++ b/src/plugins/bineditor/bineditor.cpp @@ -40,10 +40,12 @@ #include <QtGui/QAction> #include <QtGui/QClipboard> #include <QtGui/QFontMetrics> +#include <QtGui/QHelpEvent> #include <QtGui/QMenu> #include <QtGui/QMessageBox> #include <QtGui/QPainter> #include <QtGui/QScrollBar> +#include <QtGui/QToolTip> #include <QtGui/QWheelEvent> using namespace BINEditor; @@ -1030,7 +1032,64 @@ bool BinEditor::event(QEvent *e) { break; 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); } @@ -1271,13 +1330,7 @@ void BinEditor::contextMenuEvent(QContextMenuEvent *event) quint64 beAddress = 0; quint64 leAddress = 0; if (byteCount <= 8) { - const QByteArray &data = dataMid(selStart, byteCount); - 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); - } - + asIntegers(selStart, byteCount, beAddress, leAddress); setupJumpToMenuAction(&contextMenu, &jumpToBeAddressHere, &jumpToBeAddressNewWindow, beAddress); @@ -1335,3 +1388,22 @@ void BinEditor::setNewWindowRequestAllowed() { 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); + } +} diff --git a/src/plugins/bineditor/bineditor.h b/src/plugins/bineditor/bineditor.h index 8dfc695be1..cea7b8d168 100644 --- a/src/plugins/bineditor/bineditor.h +++ b/src/plugins/bineditor/bineditor.h @@ -169,6 +169,9 @@ private: QByteArray dataMid(int from, int length) 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_readOnly; int m_margin; diff --git a/src/plugins/designer/formeditorstack.cpp b/src/plugins/designer/formeditorstack.cpp index af1f3813c1..0ab7e69d98 100644 --- a/src/plugins/designer/formeditorstack.cpp +++ b/src/plugins/designer/formeditorstack.cpp @@ -129,8 +129,8 @@ bool FormEditorStack::removeFormWindowEditor(Core::IEditor *xmlEditor) const int i = indexOf(xmlEditor); if (i == -1) // Fail silently as this is invoked for all editors. return false; - removeWidget(m_formEditors[i].widgetHost->widget()); - delete m_formEditors[i].widgetHost; + removeWidget(m_formEditors[i].widgetHost); + m_formEditors[i].widgetHost->deleteLater(); m_formEditors.removeAt(i); return true; } diff --git a/src/plugins/find/findtoolwindow.cpp b/src/plugins/find/findtoolwindow.cpp index 2058af703e..5b4bf7d35e 100644 --- a/src/plugins/find/findtoolwindow.cpp +++ b/src/plugins/find/findtoolwindow.cpp @@ -36,6 +36,7 @@ #include <QtGui/QMainWindow> #include <QtGui/QStringListModel> #include <QtGui/QCompleter> +#include <QtGui/QKeyEvent> using namespace Find; using namespace Find::Internal; @@ -56,6 +57,7 @@ FindToolWindow::FindToolWindow(FindPlugin *plugin) connect(m_ui.searchTerm, SIGNAL(textChanged(QString)), this, SLOT(updateButtonStates())); m_findCompleter->setModel(m_plugin->findCompletionModel()); m_ui.searchTerm->setCompleter(m_findCompleter); + m_ui.searchTerm->installEventFilter(this); QVBoxLayout *layout = new QVBoxLayout; layout->setMargin(0); layout->setSpacing(0); @@ -68,6 +70,17 @@ FindToolWindow::~FindToolWindow() 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() { bool enabled = !m_ui.searchTerm->text().isEmpty() diff --git a/src/plugins/find/findtoolwindow.h b/src/plugins/find/findtoolwindow.h index b4575edbce..2bbdf78453 100644 --- a/src/plugins/find/findtoolwindow.h +++ b/src/plugins/find/findtoolwindow.h @@ -57,6 +57,9 @@ public: void readSettings(); void writeSettings(); +protected: + bool eventFilter(QObject *obj, QEvent *event); + private slots: void search(); void replace(); diff --git a/src/plugins/projectexplorer/foldernavigationwidget.cpp b/src/plugins/projectexplorer/foldernavigationwidget.cpp index 46afd75f2c..4c1be6fa9d 100644 --- a/src/plugins/projectexplorer/foldernavigationwidget.cpp +++ b/src/plugins/projectexplorer/foldernavigationwidget.cpp @@ -45,6 +45,7 @@ #include <QtCore/QDebug> #include <QtCore/QProcess> +#include <QtCore/QSize> #include <QtGui/QFileSystemModel> #include <QtGui/QVBoxLayout> #include <QtGui/QToolButton> @@ -143,6 +144,7 @@ FolderNavigationWidget::FolderNavigationWidget(QWidget *parent) #endif m_fileSystemModel->setFilter(filters); m_filterModel->setSourceModel(m_fileSystemModel); + m_listView->setIconSize(QSize(16,16)); m_listView->setModel(m_filterModel); m_listView->setFrameStyle(QFrame::NoFrame); m_listView->setAttribute(Qt::WA_MacShowFocusRect, false); diff --git a/src/plugins/projectexplorer/outputformatter.cpp b/src/plugins/projectexplorer/outputformatter.cpp index 0cb8b7ea5a..69bb04b72e 100644 --- a/src/plugins/projectexplorer/outputformatter.cpp +++ b/src/plugins/projectexplorer/outputformatter.cpp @@ -63,26 +63,24 @@ void OutputFormatter::setPlainTextEdit(QPlainTextEdit *plainText) void OutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr) { - gotoEnd(); - - if (onStdErr) - setFormat(StdErrFormat); - else - setFormat(StdOutFormat); - - plainTextEdit()->insertPlainText(text); + append(text, onStdErr ? StdErrFormat : StdOutFormat); } void OutputFormatter::appendMessage(const QString &text, bool isError) { - gotoEnd(); + append(text, isError ? ErrorMessageFormat : NormalMessageFormat); +} - if (isError) - setFormat(ErrorMessageFormat); - else - setFormat(NormalMessageFormat); +void OutputFormatter::append(const QString &text, Format format) +{ + append(text, m_formats[format]); +} - 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*/) @@ -119,14 +117,3 @@ void OutputFormatter::initFormats() m_formats[StdErrFormat].setFont(font); 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); -} diff --git a/src/plugins/projectexplorer/outputformatter.h b/src/plugins/projectexplorer/outputformatter.h index 3c8ff1ecd6..effff7725a 100644 --- a/src/plugins/projectexplorer/outputformatter.h +++ b/src/plugins/projectexplorer/outputformatter.h @@ -70,9 +70,8 @@ protected: }; void initFormats(); - void setFormat(Format theFormat) const; - - void gotoEnd() const; + void append(const QString &text, Format format); + void append(const QString &text, const QTextCharFormat &format); private: QPlainTextEdit *m_plainTextEdit; diff --git a/src/plugins/projectexplorer/outputwindow.cpp b/src/plugins/projectexplorer/outputwindow.cpp index 6083b28d48..91d0cab951 100644 --- a/src/plugins/projectexplorer/outputwindow.cpp +++ b/src/plugins/projectexplorer/outputwindow.cpp @@ -507,14 +507,16 @@ void OutputWindow::appendApplicationOutputInline(const QString &out, bool onStdE void OutputWindow::appendMessage(const QString &out, bool isError) { setMaximumBlockCount(MaxBlockCount); + const bool atBottom = isScrollbarAtBottom(); m_formatter->appendMessage(doNewlineEnfocement(out), isError); + if (atBottom) + scrollToBottom(); enableUndoRedo(); } bool OutputWindow::isScrollbarAtBottom() const { - return blockBoundingRect(document()->lastBlock()).bottom() + contentOffset().y() - <= viewport()->rect().bottom(); + return verticalScrollBar()->value() == verticalScrollBar()->maximum(); } void OutputWindow::scrollToBottom() diff --git a/src/plugins/qmldesigner/components/propertyeditor/colorwidget.cpp b/src/plugins/qmldesigner/components/propertyeditor/colorwidget.cpp index a5797d11ae..a4f1893400 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/colorwidget.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/colorwidget.cpp @@ -124,28 +124,29 @@ void ColorButton::paintEvent(QPaintEvent *event) else p.setBrush(Qt::transparent); - p.setPen(QColor(0x444444)); - p.drawRect(r.translated(1, 1)); - p.setPen(QColor(0x101010)); - p.drawRect(r); - p.setPen(QColor(255, 255, 255, 40)); - p.drawRect(r.adjusted(1, 1, -1, -1)); + if (color.value() > 80) + p.setPen(QColor(0x444444)); + else + p.setPen(QColor(0x9e9e9e)); + p.drawRect(r.translated(1, 1)); - p.setRenderHint(QPainter::Antialiasing, true); - QVector<QPointF> points; - if (isChecked()) { - points.append(QPointF(2, 3)); - points.append(QPointF(8, 3)); - points.append(QPointF(5, 9)); - } else { - points.append(QPointF(8, 6)); - points.append(QPointF(2, 9)); - points.append(QPointF(2, 3)); + if (m_showArrow) { + p.setRenderHint(QPainter::Antialiasing, true); + QVector<QPointF> points; + if (isChecked()) { + points.append(QPointF(2, 3)); + points.append(QPointF(8, 3)); + points.append(QPointF(5, 9)); + } else { + points.append(QPointF(8, 6)); + 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.drawRect(QRect(1, 1, width() - 1, height() - 1).adjusted(10, 5, -20, -5)); + //p.setPen(QColor(0x404040)); + //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; int y = m_color.hueF() * 120 + 5; - points.append(QPointF(15, y)); - points.append(QPointF(25, y + 5)); - points.append(QPointF(25, y - 5)); + points.append(QPointF(5, y)); + points.append(QPointF(15, 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.translate(0.5, 1.5); @@ -364,15 +360,6 @@ void ColorBox::paintEvent(QPaintEvent *event) 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); 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, 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) @@ -775,33 +760,59 @@ BauhausColorDialog::BauhausColorDialog(QWidget *parent) : QFrame(parent ) m_hueControl = new HueControl(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_gSpinBox = new QDoubleSpinBox(this); m_bSpinBox = new QDoubleSpinBox(this); m_alphaSpinBox = new QDoubleSpinBox(this); QGridLayout *gridLayout = new QGridLayout(this); + gridLayout->setSpacing(4); + gridLayout->setVerticalSpacing(4); + gridLayout->setMargin(4); setLayout(gridLayout); gridLayout->addWidget(m_colorBox, 0, 0, 4, 1); gridLayout->addWidget(m_hueControl, 0, 1, 4, 1); - gridLayout->addWidget(new QLabel("R", this), 0, 2, 1, 1); - gridLayout->addWidget(new QLabel("G", this), 1, 2, 1, 1); - gridLayout->addWidget(new QLabel("B", this), 2, 2, 1, 1); - gridLayout->addWidget(new QLabel("A", this), 3, 2, 1, 1); + gridLayout->addWidget(colorFrameWidget, 0, 2, 2, 1); + + + gridLayout->addWidget(new QLabel("R", this), 0, 3, 1, 1); + gridLayout->addWidget(new QLabel("G", this), 1, 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, 3, 1, 1); - gridLayout->addWidget(m_gSpinBox, 1, 3, 1, 1); - gridLayout->addWidget(m_bSpinBox, 2, 3, 1, 1); - gridLayout->addWidget(m_alphaSpinBox, 3, 3, 1, 1); + 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); QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel); QPushButton *applyButton = buttonBox->addButton(QDialogButtonBox::Apply); - gridLayout->addWidget(buttonBox, 4, 0, 2, 1); + gridLayout->addWidget(buttonBox, 4, 0, 1, 2); 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() { if (m_blockUpdate) @@ -857,6 +876,9 @@ void BauhausColorDialog::setupWidgets() m_gSpinBox->setValue(m_color.greenF()); m_bSpinBox->setValue(m_color.blueF()); m_colorBox->setColor(m_color); + QPalette pal = m_currentColorWidget->palette(); + pal.setColor(QPalette::Background, m_color); + m_currentColorWidget->setPalette(pal); m_blockUpdate = false; } diff --git a/src/plugins/qmldesigner/components/propertyeditor/colorwidget.h b/src/plugins/qmldesigner/components/propertyeditor/colorwidget.h index 52b29fd746..0a8c00ab88 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/colorwidget.h +++ b/src/plugins/qmldesigner/components/propertyeditor/colorwidget.h @@ -55,14 +55,17 @@ Q_OBJECT Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged) Q_PROPERTY(bool noColor READ noColor WRITE setNoColor) +Q_PROPERTY(bool showArrow READ showArrow WRITE setShowArrow) 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); QString color() const { return m_colorString; } bool noColor() const { return m_noColor; } void setNoColor(bool f) { m_noColor = f; update(); } + bool showArrow() const { return m_showArrow; } + void setShowArrow(bool b) { m_showArrow = b; } signals: void colorChanged(); @@ -72,6 +75,7 @@ protected: private: QString m_colorString; bool m_noColor; + bool m_showArrow; }; class ColorBox : public QWidget @@ -138,7 +142,7 @@ public: HueControl(QWidget *parent = 0) : QWidget(parent), m_color(Qt::white), m_mousePressed(false) { - setFixedWidth(40); + setFixedWidth(28); setFixedHeight(130); } @@ -227,6 +231,9 @@ public: BauhausColorDialog(QWidget *parent = 0); QColor color() const { return m_color; } + + void setupColor(const QColor &color); + void setColor(const QColor &color) { if (color == m_color) @@ -265,7 +272,9 @@ signals: protected: void setupWidgets(); -private: +private: + QFrame *m_beforeColorWidget; + QFrame *m_currentColorWidget; ColorBox *m_colorBox; HueControl *m_hueControl; diff --git a/src/plugins/qmldesigner/components/propertyeditor/contextpanetext.ui b/src/plugins/qmldesigner/components/propertyeditor/contextpanetext.ui new file mode 100644 index 0000000000..6e29f8ab04 --- /dev/null +++ b/src/plugins/qmldesigner/components/propertyeditor/contextpanetext.ui @@ -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> diff --git a/src/plugins/qmldesigner/components/propertyeditor/contextpanetextwidget.cpp b/src/plugins/qmldesigner/components/propertyeditor/contextpanetextwidget.cpp new file mode 100644 index 0000000000..f4cdb1761a --- /dev/null +++ b/src/plugins/qmldesigner/components/propertyeditor/contextpanetextwidget.cpp @@ -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 diff --git a/src/plugins/qmldesigner/components/propertyeditor/contextpanetextwidget.h b/src/plugins/qmldesigner/components/propertyeditor/contextpanetextwidget.h new file mode 100644 index 0000000000..c0678983ee --- /dev/null +++ b/src/plugins/qmldesigner/components/propertyeditor/contextpanetextwidget.h @@ -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 diff --git a/src/plugins/qmldesigner/components/propertyeditor/contextpanewidget.cpp b/src/plugins/qmldesigner/components/propertyeditor/contextpanewidget.cpp new file mode 100644 index 0000000000..1228f1f060 --- /dev/null +++ b/src/plugins/qmldesigner/components/propertyeditor/contextpanewidget.cpp @@ -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 + + diff --git a/src/plugins/qmldesigner/components/propertyeditor/contextpanewidget.h b/src/plugins/qmldesigner/components/propertyeditor/contextpanewidget.h new file mode 100644 index 0000000000..3ce36088c7 --- /dev/null +++ b/src/plugins/qmldesigner/components/propertyeditor/contextpanewidget.h @@ -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 diff --git a/src/plugins/qmldesigner/components/propertyeditor/fontsizespinbox.cpp b/src/plugins/qmldesigner/components/propertyeditor/fontsizespinbox.cpp new file mode 100644 index 0000000000..2116062ce2 --- /dev/null +++ b/src/plugins/qmldesigner/components/propertyeditor/fontsizespinbox.cpp @@ -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 diff --git a/src/plugins/qmldesigner/components/propertyeditor/fontsizespinbox.h b/src/plugins/qmldesigner/components/propertyeditor/fontsizespinbox.h new file mode 100644 index 0000000000..38003e53d5 --- /dev/null +++ b/src/plugins/qmldesigner/components/propertyeditor/fontsizespinbox.h @@ -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 diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.pri b/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.pri index 841ebe481f..f14b03d871 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.pri +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.pri @@ -19,7 +19,10 @@ SOURCES += propertyeditor.cpp \ siblingcombobox.cpp \ propertyeditortransaction.cpp \ propertyeditorcontextobject.cpp \ - declarativewidgetview.cpp + declarativewidgetview.cpp \ + contextpanewidget.cpp \ + contextpanetextwidget.cpp \ + fontsizespinbox.cpp HEADERS += propertyeditor.h \ qmlanchorbindingproxy.h \ @@ -40,7 +43,11 @@ HEADERS += propertyeditor.h \ propertyeditortransaction.h \ designerpropertymap.h \ propertyeditorcontextobject.h \ - declarativewidgetview.h + declarativewidgetview.h \ + contextpanewidget.h \ + contextpanetextwidget.h \ + fontsizespinbox.h QT += declarative RESOURCES += propertyeditor.qrc -FORMS += behaviordialog.ui +FORMS += behaviordialog.ui \ + contextpanetext.ui diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentbottom-h-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentbottom-h-icon.png Binary files differnew file mode 100644 index 0000000000..f2b1ce3b3e --- /dev/null +++ b/src/plugins/qmldesigner/components/resources/images/alignmentbottom-h-icon.png diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentbottom-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentbottom-icon.png Binary files differnew file mode 100644 index 0000000000..d4319c39a8 --- /dev/null +++ b/src/plugins/qmldesigner/components/resources/images/alignmentbottom-icon.png diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentcenterh-h-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentcenterh-h-icon.png Binary files differnew file mode 100644 index 0000000000..595e828748 --- /dev/null +++ b/src/plugins/qmldesigner/components/resources/images/alignmentcenterh-h-icon.png diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentcenterh-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentcenterh-icon.png Binary files differnew file mode 100644 index 0000000000..fa80a4f8e3 --- /dev/null +++ b/src/plugins/qmldesigner/components/resources/images/alignmentcenterh-icon.png diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentleft-h-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentleft-h-icon.png Binary files differnew file mode 100644 index 0000000000..48c05d2168 --- /dev/null +++ b/src/plugins/qmldesigner/components/resources/images/alignmentleft-h-icon.png diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentleft-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentleft-icon.png Binary files differnew file mode 100644 index 0000000000..af91e4173e --- /dev/null +++ b/src/plugins/qmldesigner/components/resources/images/alignmentleft-icon.png diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentmiddle-h-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentmiddle-h-icon.png Binary files differnew file mode 100644 index 0000000000..8c2356b123 --- /dev/null +++ b/src/plugins/qmldesigner/components/resources/images/alignmentmiddle-h-icon.png diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentmiddle-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentmiddle-icon.png Binary files differnew file mode 100644 index 0000000000..c620e95bb2 --- /dev/null +++ b/src/plugins/qmldesigner/components/resources/images/alignmentmiddle-icon.png diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentright-h-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentright-h-icon.png Binary files differnew file mode 100644 index 0000000000..80fd439128 --- /dev/null +++ b/src/plugins/qmldesigner/components/resources/images/alignmentright-h-icon.png diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentright-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentright-icon.png Binary files differnew file mode 100644 index 0000000000..068ab27fcf --- /dev/null +++ b/src/plugins/qmldesigner/components/resources/images/alignmentright-icon.png diff --git a/src/plugins/qmldesigner/components/resources/images/alignmenttop-h-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmenttop-h-icon.png Binary files differnew file mode 100644 index 0000000000..b600ff350d --- /dev/null +++ b/src/plugins/qmldesigner/components/resources/images/alignmenttop-h-icon.png diff --git a/src/plugins/qmldesigner/components/resources/images/alignmenttop-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmenttop-icon.png Binary files differnew file mode 100644 index 0000000000..d6a6865a7d --- /dev/null +++ b/src/plugins/qmldesigner/components/resources/images/alignmenttop-icon.png diff --git a/src/plugins/qmldesigner/components/resources/images/bold-h-icon.png b/src/plugins/qmldesigner/components/resources/images/bold-h-icon.png Binary files differnew file mode 100644 index 0000000000..c8d5bbe7db --- /dev/null +++ b/src/plugins/qmldesigner/components/resources/images/bold-h-icon.png diff --git a/src/plugins/qmldesigner/components/resources/images/italic-h-icon.png b/src/plugins/qmldesigner/components/resources/images/italic-h-icon.png Binary files differnew file mode 100644 index 0000000000..8c6eab87bf --- /dev/null +++ b/src/plugins/qmldesigner/components/resources/images/italic-h-icon.png diff --git a/src/plugins/qmldesigner/components/resources/images/strikeout-h-icon.png b/src/plugins/qmldesigner/components/resources/images/strikeout-h-icon.png Binary files differnew file mode 100644 index 0000000000..9bcb34c7d9 --- /dev/null +++ b/src/plugins/qmldesigner/components/resources/images/strikeout-h-icon.png diff --git a/src/plugins/qmldesigner/components/resources/images/underline-h-icon.png b/src/plugins/qmldesigner/components/resources/images/underline-h-icon.png Binary files differnew file mode 100644 index 0000000000..b9600100ff --- /dev/null +++ b/src/plugins/qmldesigner/components/resources/images/underline-h-icon.png diff --git a/src/plugins/qmldesigner/components/resources/resources.qrc b/src/plugins/qmldesigner/components/resources/resources.qrc index 391240a66a..0aaf9e160d 100644 --- a/src/plugins/qmldesigner/components/resources/resources.qrc +++ b/src/plugins/qmldesigner/components/resources/resources.qrc @@ -102,6 +102,22 @@ <file>images/button-pressed-right.png</file> <file>images/button-normal-left.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> </RCC> diff --git a/src/plugins/qmldesigner/designersettings.cpp b/src/plugins/qmldesigner/designersettings.cpp index dbc7341cf5..fece615974 100644 --- a/src/plugins/qmldesigner/designersettings.cpp +++ b/src/plugins/qmldesigner/designersettings.cpp @@ -51,6 +51,8 @@ void DesignerSettings::fromSettings(QSettings *settings) QLatin1String(QmlDesigner::Constants::QML_ITEMSPACING_KEY), QVariant(0)).toInt(); snapMargin = settings->value( 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(); @@ -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_ITEMSPACING_KEY), itemSpacing); settings->setValue(QLatin1String(QmlDesigner::Constants::QML_SNAPMARGIN_KEY), snapMargin); + settings->setValue(QLatin1String(QmlDesigner::Constants::QML_CONTEXTPANE_KEY), enableContextPane); settings->endGroup(); settings->endGroup(); @@ -72,6 +75,7 @@ bool DesignerSettings::equals(const DesignerSettings &other) const { return openDesignMode == other.openDesignMode && snapMargin == other.snapMargin - && itemSpacing == other.itemSpacing; + && itemSpacing == other.itemSpacing + && enableContextPane == other.enableContextPane; } diff --git a/src/plugins/qmldesigner/designersettings.h b/src/plugins/qmldesigner/designersettings.h index 007398bb93..7b2fccd1c4 100644 --- a/src/plugins/qmldesigner/designersettings.h +++ b/src/plugins/qmldesigner/designersettings.h @@ -50,6 +50,7 @@ public: bool openDesignMode; int itemSpacing; int snapMargin; + bool enableContextPane; }; inline bool operator==(const DesignerSettings &s1, const DesignerSettings &s2) diff --git a/src/plugins/qmldesigner/qmlcontextpane.cpp b/src/plugins/qmldesigner/qmlcontextpane.cpp new file mode 100644 index 0000000000..701bbab174 --- /dev/null +++ b/src/plugins/qmldesigner/qmlcontextpane.cpp @@ -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 diff --git a/src/plugins/qmldesigner/qmlcontextpane.h b/src/plugins/qmldesigner/qmlcontextpane.h new file mode 100644 index 0000000000..d13d7125e0 --- /dev/null +++ b/src/plugins/qmldesigner/qmlcontextpane.h @@ -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 diff --git a/src/plugins/qmldesigner/qmldesignerconstants.h b/src/plugins/qmldesigner/qmldesignerconstants.h index d2e14a5bc3..0765a3c9ed 100644 --- a/src/plugins/qmldesigner/qmldesignerconstants.h +++ b/src/plugins/qmldesigner/qmldesignerconstants.h @@ -61,6 +61,7 @@ const char * const QML_DESIGNER_SETTINGS_GROUP = "Designer"; const char * const QML_OPENDESIGNMODE_SETTINGS_KEY = "OpenDesignMode"; const char * const QML_ITEMSPACING_KEY = "ItemSpacing"; 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 const char * const SETTINGS_CATEGORY_QML_ICON = ":/core/images/category_qml.png"; diff --git a/src/plugins/qmldesigner/qmldesignerplugin.cpp b/src/plugins/qmldesigner/qmldesignerplugin.cpp index c35f0ae58b..738a3fc749 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.cpp +++ b/src/plugins/qmldesigner/qmldesignerplugin.cpp @@ -34,6 +34,8 @@ #include "designmodewidget.h" #include "settingspage.h" #include "designmodecontext.h" +#include "qmlcontextpane.h" + #include <qmljseditor/qmljseditorconstants.h> @@ -145,6 +147,8 @@ bool BauhausPlugin::initialize(const QStringList & /*arguments*/, QString *error m_settings.fromSettings(core->settings()); + addAutoReleasedObject(new QmlContextPane); + error_message->clear(); return true; diff --git a/src/plugins/qmldesigner/qmldesignerplugin.pro b/src/plugins/qmldesigner/qmldesignerplugin.pro index 06be937192..e3d5d487e7 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.pro +++ b/src/plugins/qmldesigner/qmldesignerplugin.pro @@ -23,14 +23,18 @@ HEADERS += qmldesignerconstants.h \ designersettings.h \ settingspage.h \ designmodecontext.h \ - styledoutputpaneplaceholder.h + styledoutputpaneplaceholder.h \ + qmlcontextpane.h + SOURCES += qmldesignerplugin.cpp \ designmodewidget.cpp \ application.cpp \ designersettings.cpp \ settingspage.cpp \ designmodecontext.cpp \ - styledoutputpaneplaceholder.cpp + styledoutputpaneplaceholder.cpp \ + qmlcontextpane.cpp + FORMS += settingspage.ui OTHER_FILES += QmlDesigner.pluginspec diff --git a/src/plugins/qmldesigner/settingspage.cpp b/src/plugins/qmldesigner/settingspage.cpp index c0275419dd..88ba6dfefa 100644 --- a/src/plugins/qmldesigner/settingspage.cpp +++ b/src/plugins/qmldesigner/settingspage.cpp @@ -49,6 +49,7 @@ DesignerSettings SettingsPageWidget::settings() const DesignerSettings ds; ds.itemSpacing = m_ui.spinItemSpacing->value(); ds.snapMargin = m_ui.spinSnapMargin->value(); + ds.enableContextPane = m_ui.textEditHelperCheckBox->isChecked(); return ds; } @@ -56,6 +57,7 @@ void SettingsPageWidget::setSettings(const DesignerSettings &s) { m_ui.spinItemSpacing->setValue(s.itemSpacing); m_ui.spinSnapMargin->setValue(s.snapMargin); + m_ui.textEditHelperCheckBox->setChecked(s.enableContextPane); } QString SettingsPageWidget::searchKeywords() const diff --git a/src/plugins/qmldesigner/settingspage.ui b/src/plugins/qmldesigner/settingspage.ui index fdd972cb3a..48b3f50b83 100644 --- a/src/plugins/qmldesigner/settingspage.ui +++ b/src/plugins/qmldesigner/settingspage.ui @@ -13,8 +13,8 @@ <property name="windowTitle"> <string>Form</string> </property> - <layout class="QGridLayout" name="gridLayout_2"> - <item row="2" column="0"> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> <widget class="QGroupBox" name="groupBox_3"> <property name="title"> <string>Snapping</string> @@ -98,7 +98,23 @@ </layout> </widget> </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"> <property name="orientation"> <enum>Qt::Vertical</enum> diff --git a/src/plugins/qmlprojectmanager/qmloutputformatter.cpp b/src/plugins/qmlprojectmanager/qmloutputformatter.cpp index 0b4eaf6dc6..bd371334db 100644 --- a/src/plugins/qmlprojectmanager/qmloutputformatter.cpp +++ b/src/plugins/qmlprojectmanager/qmloutputformatter.cpp @@ -46,15 +46,7 @@ QmlOutputFormatter::QmlOutputFormatter(QObject *parent) void QmlOutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr) { - gotoEnd(); - - if (onStdErr) - setFormat(StdErrFormat); - else - setFormat(StdOutFormat); - - QTextCharFormat normalFormat = plainTextEdit()->currentCharFormat(); - QTextCharFormat linkFormat = normalFormat; + QTextCharFormat linkFormat; linkFormat.setForeground(plainTextEdit()->palette().link().color()); linkFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline); linkFormat.setAnchor(true); @@ -64,17 +56,15 @@ void QmlOutputFormatter::appendApplicationOutput(const QString &text, bool onStd while (m_qmlError.indexIn(text, index) != -1) { const int matchPos = m_qmlError.pos(1); const QString leader = text.mid(index, matchPos - index); - plainTextEdit()->insertPlainText(leader); + append(leader, onStdErr ? StdErrFormat : StdOutFormat); const QString matched = m_qmlError.cap(1); linkFormat.setAnchorHref(matched); - plainTextEdit()->setCurrentCharFormat(linkFormat); - plainTextEdit()->insertPlainText(matched); - plainTextEdit()->setCurrentCharFormat(normalFormat); + append(matched, linkFormat); index = matchPos + m_qmlError.matchedLength() - 1; } - plainTextEdit()->insertPlainText(text.mid(index)); + append(text.mid(index), onStdErr ? StdErrFormat : StdOutFormat); } void QmlOutputFormatter::mousePressEvent(QMouseEvent * /*e*/) diff --git a/src/plugins/qt4projectmanager/qt4nodes.cpp b/src/plugins/qt4projectmanager/qt4nodes.cpp index 97e94fef13..b0d71bdbe4 100644 --- a/src/plugins/qt4projectmanager/qt4nodes.cpp +++ b/src/plugins/qt4projectmanager/qt4nodes.cpp @@ -316,7 +316,7 @@ struct InternalNode #endif QStringListIterator it(parts); InternalNode *currentNode = this; - QString path = (isRelative ? projectDir : ""); + QString path = (isRelative ? projectDirWithSeparator : ""); while (it.hasNext()) { const QString &key = it.next(); if (it.hasNext()) { // key is directory |