Commit 4388f16a authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.propertyEditor: adding new widgets

parent 18faa88f
<?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>
#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);
}