forked from qt-creator/qt-creator
QmlDesigner.propertyEditor: adding new widgets
This commit is contained in:
@@ -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>
|
||||
@@ -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
|
||||
@@ -0,0 +1,65 @@
|
||||
#ifndef CONTEXTPANETEXTWIDGET_H
|
||||
#define CONTEXTPANETEXTWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QVariant>
|
||||
|
||||
namespace Ui {
|
||||
class ContextPaneTextWidget;
|
||||
}
|
||||
|
||||
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
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user