0
0
mirror of https://github.com/fralx/LimeReport.git synced 2025-10-06 04:38:21 +03:00
This commit is contained in:
Sergey Popovichev
2016-02-17 10:18:19 +03:00
parent 1e8f2f79c7
commit 81d855f52c
59 changed files with 1180 additions and 1647 deletions

View File

@@ -38,7 +38,7 @@
#include "lrtextitempropertyeditor.h"
ButtonLineEditor::ButtonLineEditor(const QString &propertyName, QWidget *parent) :
QWidget(parent), m_overButton(false), m_editor(0), m_propertyName(propertyName)
QWidget(parent), m_overButton(false), m_propertyName(propertyName)
{
m_lineEdit = new QLineEdit(this);
m_lineEdit->installEventFilter(this);
@@ -58,25 +58,17 @@ ButtonLineEditor::ButtonLineEditor(const QString &propertyName, QWidget *parent)
//connect(m_lineEdit,SIGNAL(editingFinished()),this,SLOT(lineEditEditingFinished()));
}
ButtonLineEditor::~ButtonLineEditor()
{
if (m_editor) {
delete m_editor;
m_editor = 0;
}
}
ButtonLineEditor::~ButtonLineEditor(){}
void ButtonLineEditor::editButtonClicked()
{
if (!m_editor){
m_editor = new TextItemPropertyEditor(QApplication::activeWindow());
m_editor->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, m_editor->size(), QApplication::desktop()->availableGeometry()));
m_editor->setWindowTitle(m_propertyName);
m_editor->setText(m_lineEdit->text());
connect(m_editor,SIGNAL(accepted()),this,SLOT(editingByEditorFinished()));
m_editor->exec();
} else m_editor->exec();
TextItemPropertyEditor* editor = new TextItemPropertyEditor(QApplication::activeWindow());
editor->setAttribute(Qt::WA_DeleteOnClose);
editor->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, editor->size(), QApplication::desktop()->availableGeometry()));
editor->setWindowTitle(m_propertyName);
editor->setText(m_lineEdit->text());
connect(editor,SIGNAL(accepted()),this,SLOT(editingByEditorFinished()));
editor->exec();
}
void ButtonLineEditor::setText(const QString &value){

View File

@@ -50,13 +50,14 @@ public:
signals:
void editingFinished();
public slots:
void editButtonClicked();
virtual void editButtonClicked();
void editingByEditorFinished();
protected:
QString propertyName(){return m_propertyName;}
private:
QLineEdit* m_lineEdit;
QToolButton* m_buttonEdit;
bool m_overButton;
TextItemPropertyEditor *m_editor;
QString m_propertyName;
private:
bool eventFilter(QObject *, QEvent *);

View File

@@ -31,14 +31,20 @@
#include <QHBoxLayout>
#include <QColorDialog>
#include <QPaintEvent>
#include <QPainter>
ColorEditor::ColorEditor(QWidget *parent) :
QWidget(parent)
QWidget(parent), m_buttonPressed(false)
{
//m_button = new QPushButton(this);
m_colorIndicator = new ColorIndicator(this);
m_colorIndicator->setColor(m_color);
m_button = new QToolButton(this);
m_button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
m_button->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
m_button->setText("...");
m_button->installEventFilter(this);
QHBoxLayout* layout = new QHBoxLayout(this);
layout->addWidget(m_colorIndicator);
layout->addWidget(m_button);
layout->setSpacing(0);
layout->setContentsMargins(1,1,1,1);
@@ -51,22 +57,72 @@ ColorEditor::ColorEditor(QWidget *parent) :
void ColorEditor::setColor(const QColor &value)
{
m_color=value;
m_colorIndicator->setColor(m_color);
}
void ColorEditor::showEvent(QShowEvent *)
bool ColorEditor::eventFilter(QObject *obj, QEvent *event)
{
QPixmap pixmap(m_button->width()-8,m_button->height()-8);
pixmap.fill(m_color);
m_button->setIcon(QIcon(pixmap));
m_button->setIconSize(QSize(m_button->width()-8,m_button->height()-8));
if (obj == m_button){
if (event->type() == QEvent::FocusOut && !m_buttonPressed){
QFocusEvent* focusEvent = dynamic_cast<QFocusEvent*>(event);
if (focusEvent && focusEvent->reason()!=Qt::MouseFocusReason){
setFocusToParent();
emit(editingFinished());
}
return false;
}
}
return false;
}
void ColorEditor::setFocusToParent(){
if (parentWidget())
parentWidget()->setFocus();
}
void ColorEditor::slotClicked()
{
m_buttonPressed = true;
QColorDialog* dialog = new QColorDialog(this);
dialog->setCurrentColor(m_color);
if (dialog->exec()) m_color=dialog->currentColor();
delete dialog;
setFocusToParent();
emit(editingFinished());
}
void ColorIndicator::paintEvent(QPaintEvent* event)
{
QPainter painter(this);
painter.save();
painter.setBrush(m_color);
painter.setPen(Qt::gray);
QRect rect = event->rect().adjusted(3,3,-4,-4);
rect.setWidth(rect.height());
painter.setRenderHint(QPainter::Antialiasing);
painter.drawEllipse(rect);
painter.restore();
}
ColorIndicator::ColorIndicator(QWidget *parent)
:QWidget(parent), m_color(Qt::white){
setAttribute(Qt::WA_StaticContents);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
setFocusPolicy(Qt::NoFocus);
}
QColor ColorIndicator::color() const
{
return m_color;
}
void ColorIndicator::setColor(const QColor &color)
{
m_color = color;
}
QSize ColorIndicator::sizeHint() const
{
return QSize(20,20);
}

View File

@@ -34,6 +34,19 @@
#include <QPushButton>
#include <QToolButton>
class ColorIndicator : public QWidget{
Q_OBJECT
public:
ColorIndicator(QWidget* parent = 0);
QColor color() const;
void setColor(const QColor &color);
QSize sizeHint() const;
protected:
void paintEvent(QPaintEvent *event);
private:
QColor m_color;
};
class ColorEditor : public QWidget
{
Q_OBJECT
@@ -42,15 +55,18 @@ public:
QColor color(){return m_color;}
void setColor(const QColor& value);
protected:
void showEvent(QShowEvent *);
bool eventFilter(QObject *obj, QEvent *event);
private:
void setFocusToParent();
signals:
void editingFinished();
private slots:
void slotClicked();
private:
QColor m_color;
// QPushButton* m_button;
QToolButton* m_button;
ColorIndicator* m_colorIndicator;
bool m_buttonPressed;
};
#endif // LRCOLOREDITOR_H

View File

@@ -58,7 +58,6 @@ void QObjectPropertyModel::initModel()
connect(item,SIGNAL(destroyed(QObject*)),this,SLOT(slotObjectDestroyed(QObject*)));
addObjectProperties(m_object->metaObject(), m_object, &m_objects);
}
//reset();
endResetModel();
}
@@ -79,11 +78,10 @@ void QObjectPropertyModel::setMultiObjects(QList<QObject *>* list)
if (m_object!=list->at(0)){
m_object=list->at(0);
list->removeAt(0);
foreach(QObject* item, *list)
m_objects.append(item);
initModel();
}
foreach(QObject* item, *list)
m_objects.append(item);
initModel();
}
void QObjectPropertyModel::slotObjectDestroyed(QObject *obj)

View File

@@ -142,6 +142,15 @@ void ObjectPropItem::slotPropertyObjectName(const QString &oldValue, const QStri
}
#endif
void ObjectPropItem::setValueToObject(const QString &propertyName, QVariant propertyValue)
{
object()->setProperty(propertyName.toLatin1(),propertyValue);
foreach (QObject* item, *objects()) {
if (item->metaObject()->indexOfProperty(propertyName.toLatin1())!=-1)
item->setProperty(propertyName.toLatin1(), propertyValue);
}
}
ObjectPropItem * ObjectPropItem::findChild(const QString &name)
{
foreach(ObjectPropItem* item,m_childItems){

View File

@@ -99,10 +99,12 @@ namespace LimeReport{
private:
bool m_valid;
void invalidate(){m_object=0; m_valid = false; m_name = ""; m_value=QVariant(), m_isClass=false;}
protected:
void beginChangeValue(){ m_changingValue = true; }
void endChangeValue(){ m_changingValue = false; }
bool isValueChanging(){ return m_changingValue; }
void setValueToObject(const QString& propertyName, QVariant propertyValue);
private:
QObject* m_object;
ObjectsList m_objects;

View File

@@ -64,7 +64,7 @@ void BoolPropItem::setPropertyEditorData(QWidget *propertyEditor, const QModelIn
void BoolPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index)
{
model->setData(index,qobject_cast<CheckBoxEditor*>(propertyEditor)->isChecked());
object()->setProperty(propertyName().toLatin1(),propertyValue());
setValueToObject(propertyName(),propertyValue());
}
bool BoolPropItem::paint(QPainter *painter, const QStyleOptionViewItemV4 &option, const QModelIndex &index)

View File

@@ -51,18 +51,28 @@ void ColorPropItem::setPropertyEditorData(QWidget *propertyEditor, const QModelI
void ColorPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index)
{
model->setData(index,qobject_cast<ColorEditor*>(propertyEditor)->color());
object()->setProperty(propertyName().toLatin1(),propertyValue());
setValueToObject(propertyName(),propertyValue());
}
bool ColorPropItem::paint(QPainter *painter, const QStyleOptionViewItemV4 &option, const QModelIndex &index)
{
if (index.column()==1){
painter->save();
QPen pen;
if (option.state & QStyle::State_Selected){
pen.setColor(option.palette.brightText().color());
pen.setWidth(2);
painter->setPen(pen);
}else
pen.setColor(Qt::gray);
painter->setPen(pen);
painter->setBrush(propertyValue().value<QColor>());
painter->setPen(Qt::gray);
QRect rect = option.rect.adjusted(4,4,-4,-6);
rect.setWidth(rect.height());
painter->drawRect(rect);
painter->setRenderHint(QPainter::Antialiasing);
painter->drawEllipse(rect);
painter->restore();
return true;
} else return false;

View File

@@ -0,0 +1,38 @@
#include "lrcontentpropitem.h"
#include "lrtextitem.h"
#include "editors/lrbuttonlineeditor.h"
#include "items/lrtextitemeditor.h"
#include <QApplication>
namespace{
LimeReport::ObjectPropItem * createContentPropItem(
QObject *object, LimeReport::ObjectPropItem::ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& data, LimeReport::ObjectPropItem* parent, bool readonly)
{
return new LimeReport::ContentPropItem(object, objects, name, displayName, data, parent, readonly);
}
bool registredContentProp = LimeReport::ObjectPropFactory::instance().registerCreator(LimeReport::APropIdent("content","LimeReport::TextItem"),QObject::tr("content"),createContentPropItem);
} // namespace
namespace LimeReport {
QWidget *ContentPropItem::createProperyEditor(QWidget *parent) const
{
return new ContentEditor(object(), object()->objectName()+"."+displayName(), parent);
}
void ContentEditor::editButtonClicked()
{
QDialog* dialog = new QDialog(QApplication::activeWindow());
dialog->setLayout(new QVBoxLayout());
dialog->layout()->setContentsMargins(1,1,1,1);
dialog->setAttribute(Qt::WA_DeleteOnClose);
//dialog->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, dialog->size(), QApplication::desktop()->availableGeometry()));
dialog->setWindowTitle(propertyName());
QWidget* editor = dynamic_cast<BaseDesignIntf*>(m_object)->defaultEditor();
dialog->layout()->addWidget(editor);
connect(editor,SIGNAL(destroyed()),dialog,SLOT(close()));
connect(editor,SIGNAL(destroyed()),this,SIGNAL(editingFinished()));
dialog->exec();
}
} //namespace LimeReport

View File

@@ -0,0 +1,31 @@
#ifndef CONTENTPROPITEM_H
#define CONTENTPROPITEM_H
#include "lrstringpropitem.h"
#include "objectinspector/editors/lrbuttonlineeditor.h"
namespace LimeReport {
class ContentEditor : public ButtonLineEditor{
Q_OBJECT
public:
explicit ContentEditor(QObject* object, const QString& propertyName,QWidget *parent = 0)
:ButtonLineEditor(propertyName,parent), m_object(object){}
public slots:
void editButtonClicked();
private:
QObject* m_object;
};
class ContentPropItem : public StringPropItem{
Q_OBJECT
public:
ContentPropItem():StringPropItem(){}
ContentPropItem(QObject* object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value, ObjectPropItem* parent, bool readonly)
:StringPropItem(object, objects, name, displayName, value, parent, readonly){}
QWidget* createProperyEditor(QWidget *parent) const;
};
} // namespace LimeReport
#endif // CONTENTPROPITEM_H

View File

@@ -69,7 +69,7 @@ void EnumPropItem::slotEnumChanged(const QString &text)
{
if ( nameByType(object()->property(propertyName().toLatin1()).toInt())!=text){
beginChangeValue();
object()->setProperty(propertyName().toLatin1(),typeByName(text));
setValueToObject(propertyName(),typeByName(text));
setPropertyValue(typeByName(text));
endChangeValue();
}
@@ -83,7 +83,7 @@ void EnumPropItem::setPropertyEditorData(QWidget *propertyEditor, const QModelIn
void EnumPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index)
{
object()->setProperty(propertyName().toLatin1(),typeByName(qobject_cast<ComboBoxEditor*>(propertyEditor)->text()));
setValueToObject(propertyName(),typeByName(qobject_cast<ComboBoxEditor*>(propertyEditor)->text()));
model->setData(index,object()->property(propertyName().toLatin1()));
}

View File

@@ -132,7 +132,7 @@ void FlagPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *mod
int flags = object()->property(parent()->propertyName().toLatin1()).toInt();
if (value) flags=flags | valueByName(displayName());
else if (flags&valueByName(displayName())) flags=flags ^ valueByName(displayName());
object()->setProperty(parent()->propertyName().toLatin1(),flags);
setValueToObject(propertyName(),propertyValue());
parent()->setPropertyValue(flags);
}

View File

@@ -84,7 +84,7 @@ void FontPropItem::setPropertyEditorData(QWidget* propertyEditor, const QModelIn
void FontPropItem::setModelData(QWidget* propertyEditor, QAbstractItemModel* model, const QModelIndex &index)
{
model->setData(index,qobject_cast<FontEditor*>(propertyEditor)->fontValue());
object()->setProperty(propertyName().toLatin1(),propertyValue());
setValueToObject(propertyName(),propertyValue());
}
void FontPropItem::setPropertyValue(QVariant value)
@@ -127,9 +127,10 @@ void FontFamilyPropItem::setPropertyEditorData(QWidget *propertyEditor, const QM
void FontFamilyPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index)
{
QFont font = qobject_cast<QFontComboBox*>(propertyEditor)->currentFont();
QFont font = object()->property(parent()->propertyName().toLatin1()).value<QFont>();
font.setFamily(qobject_cast<QFontComboBox*>(propertyEditor)->currentFont().family());
model->setData(index,font);
object()->setProperty(parent()->propertyName().toLatin1(),font);
setValueToObject(parent()->propertyName(),font);
}
void FontAttribPropItem::setModelData(QWidget *propertyEditor , QAbstractItemModel *model, const QModelIndex &index)
@@ -145,7 +146,7 @@ void FontAttribPropItem::setModelData(QWidget *propertyEditor , QAbstractItemMod
if (propertyName()=="underline"){
font.setUnderline(propertyValue().toBool());
}
object()->setProperty(parent()->propertyName().toLatin1(),font);
setValueToObject(parent()->propertyName(),font);
}
void FontPointSizePropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index)
@@ -153,7 +154,7 @@ void FontPointSizePropItem::setModelData(QWidget *propertyEditor, QAbstractItemM
model->setData(index,qobject_cast<QSpinBox*>(propertyEditor)->value());
QFont font = object()->property(parent()->propertyName().toLatin1()).value<QFont>();
font.setPointSize(propertyValue().toInt());
object()->setProperty(parent()->propertyName().toLatin1(),font);
setValueToObject(parent()->propertyName(),font);
}
}

View File

@@ -60,6 +60,11 @@ void IntPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *mode
{
model->setData(index,qobject_cast<QSpinBox*>(propertyEditor)->value());
object()->setProperty(propertyName().toLatin1(),propertyValue());
foreach(QObject* item, *objects()){
if (item->metaObject()->indexOfProperty(propertyName().toLatin1())!=-1){
item->setProperty(propertyName().toLatin1(),propertyValue());
}
}
}
} // namespace LimeReport

View File

@@ -61,7 +61,8 @@ void QRealPropItem::setPropertyEditorData(QWidget *propertyEditor, const QModelI
void QRealPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index)
{
model->setData(index,qobject_cast<QDoubleSpinBox*>(propertyEditor)->value());
object()->setProperty(propertyName().toLatin1(),propertyValue());
//object()->setProperty(propertyName().toLatin1(),propertyValue());
setValueToObject(propertyName(),propertyValue());
}
}