diff --git a/share/qtcreator/gdbmacros/dumper.py b/share/qtcreator/gdbmacros/dumper.py index e48491a088062aff641c4b0ede318f7715c44a61..af7ff85a4b6230b2eaadf459bb378fa14091ba0b 100644 --- a/share/qtcreator/gdbmacros/dumper.py +++ b/share/qtcreator/gdbmacros/dumper.py @@ -1164,7 +1164,7 @@ class Dumper: self.put('{name="<incomplete>",value="",type="",numchild="0"},') def putType(self, type, priority = 0): - # higher priority values override lower ones + # Higher priority values override lower ones. if priority >= self.currentTypePriority: self.currentType = type self.currentTypePriority = priority diff --git a/src/libs/qmljs/qmljs-lib.pri b/src/libs/qmljs/qmljs-lib.pri index f04185efe4bac9fdf71e9ab180cf7662b3a68479..411e108bd3291cd863ee81d16a1bfee0f6596995 100644 --- a/src/libs/qmljs/qmljs-lib.pri +++ b/src/libs/qmljs/qmljs-lib.pri @@ -24,6 +24,7 @@ HEADERS += \ $$PWD/qmljscompletioncontextfinder.h \ $$PWD/qmljscomponentversion.h \ $$PWD/qmljsmodelmanagerinterface.h \ + $$PWD/qmljsicontextpane.h \ $$PWD/qmljspropertyreader.h \ $$PWD/qmljsrewriter.h diff --git a/src/libs/qmljs/qmljsicontextpane.h b/src/libs/qmljs/qmljsicontextpane.h new file mode 100644 index 0000000000000000000000000000000000000000..48da6eaeb1e88134775387b4d1878c5a07533a4c --- /dev/null +++ b/src/libs/qmljs/qmljsicontextpane.h @@ -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 diff --git a/src/plugins/bineditor/bineditor.cpp b/src/plugins/bineditor/bineditor.cpp index 3e98ee0ad41b2b6da76be92a21ee6233945dab8e..0a6dbcfbb226d463434c01cd0f0cb56ce1fb78ff 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 8dfc695be1c7ea7a680e8da6e6627c6aa3b4820d..cea7b8d1684760322896ac66f9811e25de5c9e00 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 af1f3813c1545404f086837ea9e438d593aa67bd..0ab7e69d98a2144f2ed0e08b2714294bdc3503ec 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 2058af703e4056f3a81c948f172dbe9bfd08c761..5b4bf7d35e38fa50e411550f3835d90161be3e3f 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 b4575edbceb9b39687dcc71611922c28decd347a..2bbdf7845334f61655718f26971e188a1d5689af 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 46afd75f2c99d5a8308d697fcf27d3a05c43226f..4c1be6fa9de08a20acac97b4b9737073531e8c0e 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 0cb8b7ea5a7d9a9fb8bf481e1ef2925385c3b1b2..69bb04b72ea6a10c80065c9825da26229536205f 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 3c8ff1ecd6ace1dec10fe42d768c51aec4a038ea..effff7725a0eaa25e7fdfb97abda7baeb2c05fd7 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 6083b28d484f2ffd5908dc02711acb485b2b19ed..91d0cab9514d4b97ee8c3c973c914cadd89d4bc7 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 a5797d11ae704fc60b1414f711abb809f03a5a29..a4f189340081348f36ab0300ab3c1d0e97e3358b 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 52b29fd7465ae763a533d4af157cdb01bac9e413..0a8c00ab88cc0775c8da42dfd76c3fc5bfffcc93 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 0000000000000000000000000000000000000000..6e29f8ab040c872c3a2ff41e1299db25161ea12b --- /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 0000000000000000000000000000000000000000..f4cdb1761a8d1dcddb1e3185a1fc3ee053fbfecb --- /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 0000000000000000000000000000000000000000..c0678983eedec1f6019e4efa54fa2233d0e1daa1 --- /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 0000000000000000000000000000000000000000..1228f1f0601cf280dcd0d99f42c50981f4a55263 --- /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 0000000000000000000000000000000000000000..3ce36088c7e305c2251a702293e9d9d81141c8da --- /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 0000000000000000000000000000000000000000..2116062ce2e3e865cef6aebcacdf24dff09a016a --- /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 0000000000000000000000000000000000000000..38003e53d57399f94c41a5ae7a8bb52e7a41149e --- /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 841ebe481f5e7fd62f56827fa7bcab07a4c44437..f14b03d871ca944a6e434ac02e889609b7b38e30 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 new file mode 100644 index 0000000000000000000000000000000000000000..f2b1ce3b3e711ea228b35d1b8cfca35fb1215a0e Binary files /dev/null and b/src/plugins/qmldesigner/components/resources/images/alignmentbottom-h-icon.png differ diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentbottom-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentbottom-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..d4319c39a8b316d80bfa078f20b5eb1b084b00ee Binary files /dev/null and b/src/plugins/qmldesigner/components/resources/images/alignmentbottom-icon.png differ diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentcenterh-h-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentcenterh-h-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..595e82874851c48bb9e115155ff15e2171b526eb Binary files /dev/null and b/src/plugins/qmldesigner/components/resources/images/alignmentcenterh-h-icon.png differ diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentcenterh-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentcenterh-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..fa80a4f8e34e0f94a9fa837fdcd3f393e10de3e4 Binary files /dev/null and b/src/plugins/qmldesigner/components/resources/images/alignmentcenterh-icon.png differ diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentleft-h-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentleft-h-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..48c05d21687f074897fa8250a219fb7a9db136f4 Binary files /dev/null and b/src/plugins/qmldesigner/components/resources/images/alignmentleft-h-icon.png differ diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentleft-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentleft-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..af91e4173ebcfd2a86c9c356e77fe5a52cb39f52 Binary files /dev/null and b/src/plugins/qmldesigner/components/resources/images/alignmentleft-icon.png differ diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentmiddle-h-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentmiddle-h-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..8c2356b123ba87a227e02f440a29165d7e51776d Binary files /dev/null and b/src/plugins/qmldesigner/components/resources/images/alignmentmiddle-h-icon.png differ diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentmiddle-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentmiddle-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..c620e95bb2f51fbdda6035cb3fbc226fd5883051 Binary files /dev/null and b/src/plugins/qmldesigner/components/resources/images/alignmentmiddle-icon.png differ diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentright-h-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentright-h-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..80fd43912803a05b4665fc2df43ad47cae4d0c6d Binary files /dev/null and b/src/plugins/qmldesigner/components/resources/images/alignmentright-h-icon.png differ diff --git a/src/plugins/qmldesigner/components/resources/images/alignmentright-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmentright-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..068ab27fcf6ba4d6078bdfa3914eef85fc3ed620 Binary files /dev/null and b/src/plugins/qmldesigner/components/resources/images/alignmentright-icon.png differ diff --git a/src/plugins/qmldesigner/components/resources/images/alignmenttop-h-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmenttop-h-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..b600ff350de4a659f108f03b50132434815b7fc0 Binary files /dev/null and b/src/plugins/qmldesigner/components/resources/images/alignmenttop-h-icon.png differ diff --git a/src/plugins/qmldesigner/components/resources/images/alignmenttop-icon.png b/src/plugins/qmldesigner/components/resources/images/alignmenttop-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..d6a6865a7d9a8753dc011442131b14e086742811 Binary files /dev/null and b/src/plugins/qmldesigner/components/resources/images/alignmenttop-icon.png differ diff --git a/src/plugins/qmldesigner/components/resources/images/bold-h-icon.png b/src/plugins/qmldesigner/components/resources/images/bold-h-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..c8d5bbe7dba29e9dad0a2b10884cdcfb0e6205f8 Binary files /dev/null and b/src/plugins/qmldesigner/components/resources/images/bold-h-icon.png differ diff --git a/src/plugins/qmldesigner/components/resources/images/italic-h-icon.png b/src/plugins/qmldesigner/components/resources/images/italic-h-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..8c6eab87bfab5dd93c51339ab357c60082bdfc85 Binary files /dev/null and b/src/plugins/qmldesigner/components/resources/images/italic-h-icon.png differ diff --git a/src/plugins/qmldesigner/components/resources/images/strikeout-h-icon.png b/src/plugins/qmldesigner/components/resources/images/strikeout-h-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..9bcb34c7d935520af2eb22a4cd4815dacc95bd8b Binary files /dev/null and b/src/plugins/qmldesigner/components/resources/images/strikeout-h-icon.png differ diff --git a/src/plugins/qmldesigner/components/resources/images/underline-h-icon.png b/src/plugins/qmldesigner/components/resources/images/underline-h-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..b9600100ff51bd493ed43602070becd98d717b18 Binary files /dev/null and b/src/plugins/qmldesigner/components/resources/images/underline-h-icon.png differ diff --git a/src/plugins/qmldesigner/components/resources/resources.qrc b/src/plugins/qmldesigner/components/resources/resources.qrc index 391240a66ae22f0bb6727f68d1111c031e7275c7..0aaf9e160daa0630e6e98fb2db0dde1dc6280868 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 dbc7341cf553a58dfd41a8286b1867873ca10bf2..fece6159743d6e947f9ac42d834df6466b705065 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 007398bb9377ac801d2f0e6cf7fa0c71eb537286..7b2fccd1c478cb2d352adaba372ac3562ddf98aa 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 0000000000000000000000000000000000000000..701bbab1746178b7da921e08e9ae386484a55256 --- /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 0000000000000000000000000000000000000000..d13d7125e08be4c11479ce47c361c503d88fe1a1 --- /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 d2e14a5bc3d7f19330ee882d3e14db0fee7d64ad..0765a3c9ed828312387b8a16e4da57332a5e4908 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 c35f0ae58bb0e23df13348f2f6c7d05d08f0d684..738a3fc74990085910287f6a9caac2dbe169144c 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 06be937192fc90255c38fe81fd147fda5485f242..e3d5d487e7d7bb54258034bd205c9e7afe72cf7c 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 c0275419dd67f3526c81ecebd39b3aa1fc317034..88ba6dfefacd27c8bac6a49e809b32a9d3967e6f 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 fdd972cb3a451356026586d2d3f99408cf20cdc4..48b3f50b83a37b38d41fbeafdd04b24b9bc1fac3 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 0b4eaf6dc697caec71018c6110ab42b38fb19e8d..bd371334db133284689f2024c8d4fb24f414d2a0 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 97e94fef13211f9e5bc773e48d617abc382b7a26..b0d71bdbe42bdd650ee8f391f143d59fb533e78f 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