Change to subforder project model.
147
limereport/items/editors/lrfonteditorwidget.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "lrfonteditorwidget.h"
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
FontEditorWidget::FontEditorWidget(ReportDesignWidget *reportEditor, const QString &title, QWidget *parent)
|
||||
: ItemEditorWidget(reportEditor,title,parent), m_ignoreSlots(false) {
|
||||
initEditor();
|
||||
}
|
||||
|
||||
FontEditorWidget::FontEditorWidget(ReportDesignWidget *reportEditor, QWidget *parent)
|
||||
:ItemEditorWidget(reportEditor,parent), m_ignoreSlots(false) {
|
||||
initEditor();
|
||||
}
|
||||
|
||||
void FontEditorWidget::setItemEvent(BaseDesignIntf* item)
|
||||
{
|
||||
|
||||
QVariant font=item->property("font");
|
||||
if (font.isValid()){
|
||||
updateValues(font.value<QFont>());
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FontEditorWidget::initEditor()
|
||||
{
|
||||
setIconSize(QSize(24,24));
|
||||
setAllowedAreas(Qt::TopToolBarArea);
|
||||
setFloatable(false);
|
||||
|
||||
m_fontNameEditor = new QFontComboBox(this);
|
||||
m_fontNameEditor->setFontFilters(QFontComboBox::AllFonts);
|
||||
connect(m_fontNameEditor,SIGNAL(currentFontChanged(QFont)),this,SLOT(slotFontChanged(QFont)));
|
||||
addWidget(m_fontNameEditor);
|
||||
|
||||
m_fontSizeModel.setStringList(QStringList()<<"6"<<"7"<<"8"<<"9"<<"10"<<"11"<<"12"<<"14"<<"16"<<"18"<<"20"<<"24"<<"28"<<"30"<<"36"<<"48"<<"64"<<"72");
|
||||
m_fontSizeEditor = new QComboBox(this);
|
||||
m_fontSizeEditor->setModel(&m_fontSizeModel);
|
||||
m_fontSizeEditor->setEditable(true);
|
||||
connect(m_fontSizeEditor,SIGNAL(currentIndexChanged(QString)),this,SLOT(slotFontSizeChanged(QString)));
|
||||
addWidget(m_fontSizeEditor);
|
||||
|
||||
addSeparator();
|
||||
setEnabled(false);
|
||||
|
||||
m_fontBold = new QAction(tr("Font bold"),this);
|
||||
m_fontBold->setIcon(QIcon(":/report/images/textBold"));
|
||||
m_fontBold->setCheckable(true);
|
||||
connect(m_fontBold,SIGNAL(toggled(bool)),this,SLOT(slotFontAttribsChanged(bool)));
|
||||
addAction(m_fontBold);
|
||||
|
||||
m_fontItalic = new QAction(tr("Font Italic"),this);
|
||||
m_fontItalic->setIcon(QIcon(":/report/images/textItalic"));
|
||||
m_fontItalic->setCheckable(true);
|
||||
connect(m_fontItalic,SIGNAL(toggled(bool)),this,SLOT(slotFontAttribsChanged(bool)));
|
||||
addAction(m_fontItalic);
|
||||
|
||||
m_fontUnderline = new QAction(tr("Font Underline"),this);
|
||||
m_fontUnderline->setIcon(QIcon(":/report/images/textUnderline"));
|
||||
m_fontUnderline->setCheckable(true);
|
||||
connect(m_fontUnderline,SIGNAL(toggled(bool)),this,SLOT(slotFontAttribsChanged(bool)));
|
||||
addAction(m_fontUnderline);
|
||||
|
||||
if (reportEditor()){
|
||||
connect(reportEditor(),SIGNAL(itemPropertyChanged(QString,QString,QVariant,QVariant)),
|
||||
this,SLOT(slotPropertyChanged(QString,QString,QVariant,QVariant)));
|
||||
}
|
||||
}
|
||||
|
||||
void FontEditorWidget::updateValues(const QFont& font)
|
||||
{
|
||||
m_ignoreSlots=true;
|
||||
m_fontNameEditor->setCurrentFont(font);
|
||||
m_fontSizeEditor->setEditText(QString::number(font.pointSize()));
|
||||
m_fontBold->setChecked(font.bold());
|
||||
m_fontItalic->setChecked(font.italic());
|
||||
m_fontUnderline->setChecked(font.underline());
|
||||
m_ignoreSlots=false;
|
||||
}
|
||||
|
||||
|
||||
void FontEditorWidget::slotFontChanged(const QFont &font)
|
||||
{
|
||||
if (reportEditor() && !m_ignoreSlots) reportEditor()->setFont(font);
|
||||
}
|
||||
|
||||
void FontEditorWidget::slotFontSizeChanged(const QString &value)
|
||||
{
|
||||
if (reportEditor() && !m_ignoreSlots){
|
||||
QFont resFont(m_fontNameEditor->currentFont());
|
||||
resFont.setPointSize(value.toInt());
|
||||
reportEditor()->setFont(resFont);
|
||||
}
|
||||
}
|
||||
|
||||
void FontEditorWidget::slotFontAttribsChanged(bool)
|
||||
{
|
||||
if (reportEditor()&& !m_ignoreSlots){
|
||||
QFont resFont(m_fontNameEditor->currentFont());
|
||||
resFont.setBold(m_fontBold->isChecked());
|
||||
resFont.setItalic(m_fontItalic->isChecked());
|
||||
resFont.setUnderline(m_fontUnderline->isChecked());
|
||||
reportEditor()->setFont(resFont);
|
||||
}
|
||||
}
|
||||
|
||||
void FontEditorWidget::slotPropertyChanged(const QString &objectName, const QString &property, const QVariant& oldValue, const QVariant& newValue)
|
||||
{
|
||||
Q_UNUSED(oldValue)
|
||||
Q_UNUSED(newValue)
|
||||
if (item()&&(item()->objectName()==objectName)&&(property=="font")){
|
||||
updateValues(item()->property("font").value<QFont>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} //namespace LimeReport
|
73
limereport/items/editors/lrfonteditorwidget.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRFONTEDITORWIDGET_H
|
||||
#define LRFONTEDITORWIDGET_H
|
||||
|
||||
#include <QToolBar>
|
||||
#include <QFontComboBox>
|
||||
#include <QStringListModel>
|
||||
#include <QAction>
|
||||
|
||||
#include "lrreportdesignwidget.h"
|
||||
#include "lritemeditorwidget.h"
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
class FontEditorWidget :public ItemEditorWidget{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FontEditorWidget(ReportDesignWidget* reportEditor, const QString &title, QWidget *parent = 0);
|
||||
explicit FontEditorWidget(ReportDesignWidget* reportEditor, QWidget *parent = 0);
|
||||
protected:
|
||||
void setItemEvent(BaseDesignIntf *item);
|
||||
private slots:
|
||||
void slotFontChanged(const QFont& font);
|
||||
void slotFontSizeChanged(const QString& value);
|
||||
void slotFontAttribsChanged(bool);
|
||||
void slotPropertyChanged(const QString& objectName, const QString& property, const QVariant &oldValue, const QVariant &newValue);
|
||||
private:
|
||||
void initEditor();
|
||||
void updateValues(const QFont &font);
|
||||
|
||||
QFontComboBox* m_fontNameEditor;
|
||||
QComboBox* m_fontSizeEditor;
|
||||
QStringListModel m_fontSizeModel;
|
||||
|
||||
QAction* m_fontBold;
|
||||
QAction* m_fontItalic;
|
||||
QAction* m_fontUnderline;
|
||||
|
||||
bool m_ignoreSlots;
|
||||
|
||||
};
|
||||
|
||||
} //namespace LimeReport
|
||||
|
||||
#endif // LRFONTEDITORWIDGET_H
|
91
limereport/items/editors/lritemeditorwidget.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "lritemeditorwidget.h"
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
ItemEditorWidget::ItemEditorWidget(ReportDesignWidget* reportEditor, const QString& title, QWidget* parent)
|
||||
:QToolBar(title,parent), m_reportEditor(reportEditor), m_item(0), m_page(0)
|
||||
{
|
||||
}
|
||||
|
||||
ItemEditorWidget::ItemEditorWidget(ReportDesignWidget* reportEditor, QWidget* parent)
|
||||
:QToolBar(parent), m_reportEditor(reportEditor), m_item(0), m_page(0)
|
||||
{
|
||||
}
|
||||
|
||||
ItemEditorWidget::ItemEditorWidget(PageDesignIntf* page, const QString& title, QWidget* parent)
|
||||
:QToolBar(title,parent), m_reportEditor(0), m_item(0), m_page(page)
|
||||
{
|
||||
}
|
||||
|
||||
ItemEditorWidget::ItemEditorWidget(PageDesignIntf* page, QWidget* parent)
|
||||
:QToolBar(parent), m_reportEditor(0), m_item(0), m_page(page)
|
||||
{
|
||||
}
|
||||
|
||||
void ItemEditorWidget::setItem(BaseDesignIntf* item)
|
||||
{
|
||||
if (m_item!=item){
|
||||
if (m_item) m_item->disconnect(this);
|
||||
m_item=item;
|
||||
connect(m_item,SIGNAL(destroyed(QObject*)),this,SLOT(slotItemDestroyed(QObject*)));
|
||||
connect(m_item,SIGNAL(propertyChanged(QString,QVariant,QVariant)),
|
||||
this,SLOT(slotPropertyChanged(QString,QVariant,QVariant)));
|
||||
setEnabled(false);
|
||||
setItemEvent(item);
|
||||
}
|
||||
}
|
||||
|
||||
void ItemEditorWidget::properyChangedEvent(const QString& propertName, const QVariant& oldValue, const QVariant& newValue)
|
||||
{
|
||||
Q_UNUSED(propertName)
|
||||
Q_UNUSED(oldValue)
|
||||
Q_UNUSED(newValue)
|
||||
}
|
||||
|
||||
void ItemEditorWidget::slotItemDestroyed(QObject* item)
|
||||
{
|
||||
if (item==m_item) {
|
||||
m_item = 0;
|
||||
setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void ItemEditorWidget::slotPropertyChanged(const QString& propertName, const QVariant& oldValue, const QVariant& newValue)
|
||||
{
|
||||
properyChangedEvent(propertName,oldValue,newValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
65
limereport/items/editors/lritemeditorwidget.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRITEMEDITORWIDGET_H
|
||||
#define LRITEMEDITORWIDGET_H
|
||||
|
||||
#include <QToolBar>
|
||||
#include "lrreportdesignwidget.h"
|
||||
|
||||
namespace LimeReport {
|
||||
|
||||
class ItemEditorWidget : public QToolBar
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ItemEditorWidget(ReportDesignWidget* reportEditor, const QString &title, QWidget *parent = 0);
|
||||
explicit ItemEditorWidget(ReportDesignWidget* reportEditor, QWidget *parent = 0);
|
||||
explicit ItemEditorWidget(PageDesignIntf* page, const QString &title, QWidget *parent = 0);
|
||||
explicit ItemEditorWidget(PageDesignIntf* page, QWidget *parent = 0);
|
||||
|
||||
void setItem(BaseDesignIntf *item);
|
||||
void setReportEditor(ReportDesignWidget* editor){m_reportEditor = editor;}
|
||||
protected:
|
||||
virtual void setItemEvent(BaseDesignIntf*){}
|
||||
virtual void properyChangedEvent(const QString& propertName, const QVariant& oldValue, const QVariant& newValue);
|
||||
BaseDesignIntf* item(){return m_item;}
|
||||
ReportDesignWidget* reportEditor(){return m_reportEditor;}
|
||||
PageDesignIntf* page(){return m_page;}
|
||||
private slots:
|
||||
void slotItemDestroyed(QObject* item);
|
||||
void slotPropertyChanged(const QString& propertName, const QVariant& oldValue, const QVariant& newValue);
|
||||
private:
|
||||
ReportDesignWidget* m_reportEditor;
|
||||
BaseDesignIntf* m_item;
|
||||
PageDesignIntf* m_page;
|
||||
};
|
||||
|
||||
} // namespace LimeReport
|
||||
#endif // LRITEMEDITORWIDGET_H
|
171
limereport/items/editors/lritemsaligneditorwidget.cpp
Normal file
@@ -0,0 +1,171 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "lritemsaligneditorwidget.h"
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
ItemsAlignmentEditorWidget::ItemsAlignmentEditorWidget(LimeReport::ReportDesignWidget* reportEditor, const QString& title, QWidget* parent)
|
||||
:QToolBar(title,parent), m_reportEditor(reportEditor), m_page(0)
|
||||
{
|
||||
initEditor();
|
||||
}
|
||||
|
||||
ItemsAlignmentEditorWidget::ItemsAlignmentEditorWidget(ReportDesignWidget* reportEditor, QWidget* parent)
|
||||
:QToolBar(parent), m_reportEditor(reportEditor), m_page(0)
|
||||
{
|
||||
initEditor();
|
||||
}
|
||||
|
||||
ItemsAlignmentEditorWidget::ItemsAlignmentEditorWidget(PageDesignIntf* page, const QString& title, QWidget* parent)
|
||||
:QToolBar(title,parent), m_reportEditor(0), m_page(page)
|
||||
{
|
||||
initEditor();
|
||||
}
|
||||
|
||||
ItemsAlignmentEditorWidget::ItemsAlignmentEditorWidget(PageDesignIntf* page, QWidget* parent)
|
||||
:QToolBar(parent), m_reportEditor(0), m_page(page)
|
||||
{
|
||||
initEditor();
|
||||
}
|
||||
|
||||
void ItemsAlignmentEditorWidget::slotBrinToFront()
|
||||
{
|
||||
if (m_reportEditor) m_reportEditor->brinToFront();
|
||||
if (m_page) m_page->bringToFront();
|
||||
}
|
||||
|
||||
void ItemsAlignmentEditorWidget::slotSendToBack()
|
||||
{
|
||||
if (m_reportEditor) m_reportEditor->sendToBack();
|
||||
if (m_page) m_page->sendToBack();
|
||||
}
|
||||
|
||||
void ItemsAlignmentEditorWidget::slotAlignToLeft()
|
||||
{
|
||||
if (m_reportEditor) m_reportEditor->alignToLeft();
|
||||
if (m_page) m_page->alignToLeft();
|
||||
}
|
||||
|
||||
void ItemsAlignmentEditorWidget::slotAlignToRight()
|
||||
{
|
||||
if (m_reportEditor) m_reportEditor->alignToRight();
|
||||
if (m_page) m_page->alignToRigth();
|
||||
}
|
||||
|
||||
void ItemsAlignmentEditorWidget::slotAlignToVCenter()
|
||||
{
|
||||
if (m_reportEditor) m_reportEditor->alignToVCenter();
|
||||
if (m_page) m_page->alignToVCenter();
|
||||
}
|
||||
|
||||
void ItemsAlignmentEditorWidget::slotAlignToTop()
|
||||
{
|
||||
if (m_reportEditor) m_reportEditor->alignToTop();
|
||||
if (m_page) m_page->alignToTop();
|
||||
}
|
||||
|
||||
void ItemsAlignmentEditorWidget::slotAlignToBottom()
|
||||
{
|
||||
if (m_reportEditor) m_reportEditor->alignToBottom();
|
||||
if (m_page) m_page->alignToBottom();
|
||||
}
|
||||
|
||||
void ItemsAlignmentEditorWidget::slotAlignToHCenter()
|
||||
{
|
||||
if (m_reportEditor) m_reportEditor->alignToHCenter();
|
||||
if (m_page) m_page->alignToHCenter();
|
||||
}
|
||||
|
||||
void ItemsAlignmentEditorWidget::slotSameHeight()
|
||||
{
|
||||
if (m_reportEditor) m_reportEditor->sameHeight();
|
||||
if (m_page) m_page->sameHeight();
|
||||
}
|
||||
|
||||
void ItemsAlignmentEditorWidget::slotSameWidth()
|
||||
{
|
||||
if (m_reportEditor) m_reportEditor->sameWidth();
|
||||
if (m_page) m_page->sameWidth();
|
||||
}
|
||||
|
||||
void ItemsAlignmentEditorWidget::initEditor()
|
||||
{
|
||||
m_bringToFront = new QAction(tr("Bring to top"),this);
|
||||
m_bringToFront->setIcon(QIcon(":/report/images/bringToTop"));
|
||||
connect(m_bringToFront,SIGNAL(triggered()),this,SLOT(slotBrinToFront()));
|
||||
addAction(m_bringToFront);
|
||||
|
||||
m_sendToBack = new QAction(tr("Send to back"),this);
|
||||
m_sendToBack->setIcon(QIcon(":/report/images/sendToBack"));
|
||||
connect(m_sendToBack,SIGNAL(triggered()),this,SLOT(slotSendToBack()));
|
||||
addAction(m_sendToBack);
|
||||
|
||||
m_alignToLeft = new QAction(tr("Align to left"),this);
|
||||
m_alignToLeft->setIcon(QIcon(":/report/images/alignToLeft"));
|
||||
connect(m_alignToLeft,SIGNAL(triggered()),this,SLOT(slotAlignToLeft()));
|
||||
addAction(m_alignToLeft);
|
||||
|
||||
m_alignToRight = new QAction(tr("Align to right"),this);
|
||||
m_alignToRight->setIcon(QIcon(":/report/images/alignToRight"));
|
||||
connect(m_alignToRight,SIGNAL(triggered()),this,SLOT(slotAlignToRight()));
|
||||
addAction(m_alignToRight);
|
||||
|
||||
m_alignToVCenter = new QAction(tr("Align to vertical center"),this);
|
||||
m_alignToVCenter->setIcon(QIcon(":/report/images/alignToVCenter"));
|
||||
connect(m_alignToVCenter,SIGNAL(triggered()),this,SLOT(slotAlignToVCenter()));
|
||||
addAction(m_alignToVCenter);
|
||||
|
||||
m_alignToTop = new QAction(tr("Align to top"),this);
|
||||
m_alignToTop->setIcon(QIcon(":/report/images/alignToTop"));
|
||||
connect(m_alignToTop,SIGNAL(triggered()),this,SLOT(slotAlignToTop()));
|
||||
addAction(m_alignToTop);
|
||||
|
||||
m_alignToBottom = new QAction(tr("Align to bottom"),this);
|
||||
m_alignToBottom->setIcon(QIcon(":/report/images/alignToBottom"));
|
||||
connect(m_alignToBottom,SIGNAL(triggered()),this,SLOT(slotAlignToBottom()));
|
||||
addAction(m_alignToBottom);
|
||||
|
||||
m_alignToHCenter = new QAction(tr("Align to horizontal center"),this);
|
||||
m_alignToHCenter->setIcon(QIcon(":/report/images/alignToHCenter"));
|
||||
connect(m_alignToHCenter,SIGNAL(triggered()),this,SLOT(slotAlignToHCenter()));
|
||||
addAction(m_alignToHCenter);
|
||||
|
||||
m_sameHeight = new QAction(tr("Set same height"),this);
|
||||
m_sameHeight->setIcon(QIcon(":/report/images/sameHeight"));
|
||||
connect(m_sameHeight,SIGNAL(triggered()),this,SLOT(slotSameHeight()));
|
||||
addAction(m_sameHeight);
|
||||
|
||||
m_sameWidth = new QAction(tr("Set same width"),this);
|
||||
m_sameWidth->setIcon(QIcon(":/report/images/sameWidth"));
|
||||
connect(m_sameWidth,SIGNAL(triggered()),this,SLOT(slotSameWidth()));
|
||||
addAction(m_sameWidth);
|
||||
}
|
||||
|
||||
} //namespace LimeReport
|
77
limereport/items/editors/lritemsaligneditorwidget.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRITEMSALIGNEDITORWIDGET_H
|
||||
#define LRITEMSALIGNEDITORWIDGET_H
|
||||
|
||||
#include "lrreportdesignwidget.h"
|
||||
#include <QToolBar>
|
||||
#include <QAction>
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
class ItemsAlignmentEditorWidget : public QToolBar
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ItemsAlignmentEditorWidget(ReportDesignWidget* reportEditor, const QString &title, QWidget *parent = 0);
|
||||
explicit ItemsAlignmentEditorWidget(ReportDesignWidget* reportEditor, QWidget *parent = 0);
|
||||
explicit ItemsAlignmentEditorWidget(PageDesignIntf* page, const QString &title, QWidget *parent = 0);
|
||||
explicit ItemsAlignmentEditorWidget(PageDesignIntf* page, QWidget *parent = 0);
|
||||
private slots:
|
||||
void slotBrinToFront();
|
||||
void slotSendToBack();
|
||||
void slotAlignToLeft();
|
||||
void slotAlignToRight();
|
||||
void slotAlignToVCenter();
|
||||
void slotAlignToTop();
|
||||
void slotAlignToBottom();
|
||||
void slotAlignToHCenter();
|
||||
void slotSameHeight();
|
||||
void slotSameWidth();
|
||||
private:
|
||||
void initEditor();
|
||||
ReportDesignWidget* m_reportEditor;
|
||||
PageDesignIntf* m_page;
|
||||
|
||||
QAction* m_bringToFront;
|
||||
QAction* m_sendToBack;
|
||||
QAction* m_alignToLeft;
|
||||
QAction* m_alignToRight;
|
||||
QAction* m_alignToVCenter;
|
||||
QAction* m_alignToTop;
|
||||
QAction* m_alignToBottom;
|
||||
QAction* m_alignToHCenter;
|
||||
QAction* m_sameHeight;
|
||||
QAction* m_sameWidth;
|
||||
};
|
||||
|
||||
} //namespace LimeReport
|
||||
|
||||
#endif // LRITEMSALIGNEDITORWIDGET_H
|
154
limereport/items/editors/lritemsborderseditorwidget.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "lritemsborderseditorwidget.h"
|
||||
#include <QAction>
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
ItemsBordersEditorWidget::ItemsBordersEditorWidget(ReportDesignWidget* reportEditor, const QString& title, QWidget* parent)
|
||||
: ItemEditorWidget(reportEditor,title,parent), m_changing(false)
|
||||
{
|
||||
initEditor();
|
||||
}
|
||||
|
||||
ItemsBordersEditorWidget::ItemsBordersEditorWidget(ReportDesignWidget* reportEditor, QWidget* parent)
|
||||
: ItemEditorWidget(reportEditor,parent), m_changing(false)
|
||||
{
|
||||
initEditor();
|
||||
}
|
||||
|
||||
void ItemsBordersEditorWidget::setItemEvent(BaseDesignIntf* item)
|
||||
{
|
||||
QVariant borders=item->property("borders");
|
||||
if (borders.isValid()){
|
||||
updateValues((BaseDesignIntf::BorderLines)borders.toInt());
|
||||
setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void ItemsBordersEditorWidget::properyChangedEvent(const QString& property, const QVariant& oldValue, const QVariant& newValue)
|
||||
{
|
||||
Q_UNUSED(oldValue)
|
||||
if (property == "borders"){
|
||||
m_changing = true;
|
||||
updateValues((BaseDesignIntf::BorderLines)newValue.toInt());
|
||||
m_changing = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ItemsBordersEditorWidget::noBordesClicked()
|
||||
{
|
||||
if (reportEditor())
|
||||
reportEditor()->setBorders(0);
|
||||
updateValues(0);
|
||||
}
|
||||
|
||||
void ItemsBordersEditorWidget::allBordesClicked()
|
||||
{
|
||||
int borders = BaseDesignIntf::LeftLine |
|
||||
BaseDesignIntf::RightLine |
|
||||
BaseDesignIntf::TopLine |
|
||||
BaseDesignIntf::BottomLine;
|
||||
|
||||
updateValues((BaseDesignIntf::BorderLines)borders);
|
||||
if (reportEditor())
|
||||
reportEditor()->setBorders((BaseDesignIntf::BorderLines)borders);
|
||||
}
|
||||
|
||||
void ItemsBordersEditorWidget::buttonClicked(bool)
|
||||
{
|
||||
if (!m_changing&&reportEditor())
|
||||
reportEditor()->setBorders(createBorders());
|
||||
}
|
||||
|
||||
void ItemsBordersEditorWidget::initEditor()
|
||||
{
|
||||
|
||||
m_topLine = new QAction(tr("Top line"),this);
|
||||
m_topLine->setIcon(QIcon(":/report/images/topLine"));
|
||||
m_topLine->setCheckable(true);
|
||||
connect(m_topLine,SIGNAL(toggled(bool)),this,SLOT(buttonClicked(bool)));
|
||||
addAction(m_topLine);
|
||||
|
||||
m_bottomLine = new QAction(tr("Bottom line"),this);
|
||||
m_bottomLine->setIcon(QIcon(":/report/images/bottomLine"));
|
||||
m_bottomLine->setCheckable(true);
|
||||
connect(m_bottomLine,SIGNAL(toggled(bool)),this,SLOT(buttonClicked(bool)));
|
||||
addAction(m_bottomLine);
|
||||
|
||||
m_leftLine = new QAction(tr("Left line"),this);
|
||||
m_leftLine->setIcon(QIcon(":/report/images/leftLine"));
|
||||
m_leftLine->setCheckable(true);
|
||||
connect(m_leftLine,SIGNAL(toggled(bool)),this,SLOT(buttonClicked(bool)));
|
||||
addAction(m_leftLine);
|
||||
|
||||
m_rightLine = new QAction(tr("Right line"),this);
|
||||
m_rightLine->setIcon(QIcon(":/report/images/rightLine"));
|
||||
m_rightLine->setCheckable(true);
|
||||
connect(m_rightLine,SIGNAL(toggled(bool)),this,SLOT(buttonClicked(bool)));
|
||||
addAction(m_rightLine);
|
||||
|
||||
addSeparator();
|
||||
|
||||
m_noLines = new QAction(tr("No borders"),this);
|
||||
m_noLines->setIcon(QIcon(":/report/images/noLines"));
|
||||
connect(m_noLines,SIGNAL(triggered()),this,SLOT(noBordesClicked()));
|
||||
addAction(m_noLines);
|
||||
|
||||
m_allLines = new QAction(tr("All borders"),this);
|
||||
m_allLines->setIcon(QIcon(":/report/images/allLines"));
|
||||
connect(m_allLines,SIGNAL(triggered()),this,SLOT(allBordesClicked()));
|
||||
addAction(m_allLines);
|
||||
|
||||
setEnabled(false);
|
||||
|
||||
}
|
||||
|
||||
void ItemsBordersEditorWidget::updateValues(BaseDesignIntf::BorderLines borders)
|
||||
{
|
||||
m_changing = true;
|
||||
m_topLine->setChecked(borders&BaseDesignIntf::TopLine);
|
||||
m_bottomLine->setChecked(borders&BaseDesignIntf::BottomLine);
|
||||
m_leftLine->setChecked(borders&BaseDesignIntf::LeftLine);
|
||||
m_rightLine->setChecked(borders&BaseDesignIntf::RightLine);
|
||||
m_changing = false;
|
||||
}
|
||||
|
||||
BaseDesignIntf::BorderLines ItemsBordersEditorWidget::createBorders()
|
||||
{
|
||||
int borders = 0;
|
||||
borders += (m_topLine->isChecked())?BaseDesignIntf::TopLine:0;
|
||||
borders += (m_bottomLine->isChecked())?BaseDesignIntf::BottomLine:0;
|
||||
borders += (m_leftLine->isChecked())?BaseDesignIntf::LeftLine:0;
|
||||
borders += (m_rightLine->isChecked())?BaseDesignIntf::RightLine:0;
|
||||
return (BaseDesignIntf::BorderLines)borders;
|
||||
}
|
||||
|
||||
} //namespace LimeReport
|
67
limereport/items/editors/lritemsborderseditorwidget.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRITEMSBORDERSEDITORWIDGET_H
|
||||
#define LRITEMSBORDERSEDITORWIDGET_H
|
||||
|
||||
#include <QToolBar>
|
||||
#include "lrreportdesignwidget.h"
|
||||
#include "lritemeditorwidget.h"
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
class ItemsBordersEditorWidget : public ItemEditorWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ItemsBordersEditorWidget(ReportDesignWidget* reportEditor, const QString &title, QWidget *parent = 0);
|
||||
explicit ItemsBordersEditorWidget(ReportDesignWidget* reportEditor, QWidget *parent = 0);
|
||||
private slots:
|
||||
void noBordesClicked();
|
||||
void allBordesClicked();
|
||||
void buttonClicked(bool);
|
||||
protected:
|
||||
void setItemEvent(BaseDesignIntf *item);
|
||||
void properyChangedEvent(const QString &property, const QVariant &oldValue, const QVariant &newValue);
|
||||
private:
|
||||
void initEditor();
|
||||
void updateValues(BaseDesignIntf::BorderLines borders);
|
||||
BaseDesignIntf::BorderLines createBorders();
|
||||
QAction* m_noLines;
|
||||
QAction* m_leftLine;
|
||||
QAction* m_rightLine;
|
||||
QAction* m_topLine;
|
||||
QAction* m_bottomLine;
|
||||
QAction* m_allLines;
|
||||
bool m_changing;
|
||||
};
|
||||
|
||||
}//namespace LimeReport
|
||||
|
||||
#endif // LRITEMSBORDERSEDITORWIDGET_H
|
204
limereport/items/editors/lrtextalignmenteditorwidget.cpp
Normal file
@@ -0,0 +1,204 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "lrtextalignmenteditorwidget.h"
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
TextAlignmentEditorWidget::TextAlignmentEditorWidget(ReportDesignWidget *reportEditor, const QString &title, QWidget *parent)
|
||||
:ItemEditorWidget(reportEditor,title,parent), m_textAttibutesIsChanging(false)
|
||||
{
|
||||
initEditor();
|
||||
}
|
||||
|
||||
TextAlignmentEditorWidget::TextAlignmentEditorWidget(ReportDesignWidget *reportEditor, QWidget *parent)
|
||||
:ItemEditorWidget(reportEditor,parent), m_textAttibutesIsChanging(false)
|
||||
{
|
||||
initEditor();
|
||||
}
|
||||
|
||||
TextAlignmentEditorWidget::TextAlignmentEditorWidget(PageDesignIntf* page, const QString& title, QWidget* parent)
|
||||
:ItemEditorWidget(page,title,parent), m_textAttibutesIsChanging(false)
|
||||
{
|
||||
initEditor();
|
||||
}
|
||||
|
||||
TextAlignmentEditorWidget::TextAlignmentEditorWidget(PageDesignIntf* page, QWidget* parent)
|
||||
:ItemEditorWidget(page,parent), m_textAttibutesIsChanging(false)
|
||||
{
|
||||
initEditor();
|
||||
}
|
||||
|
||||
void TextAlignmentEditorWidget::setItemEvent(BaseDesignIntf *item)
|
||||
{
|
||||
QVariant align=item->property("alignment");
|
||||
if (align.isValid()){
|
||||
updateValues(Qt::Alignment(align.value<int>()));
|
||||
setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void TextAlignmentEditorWidget::initEditor()
|
||||
{
|
||||
m_textAliginLeft = new QAction(tr("Text align left"),this);
|
||||
m_textAliginLeft->setIcon(QIcon(":/report/images/textAlignHLeft"));
|
||||
m_textAliginLeft->setCheckable(true);
|
||||
connect(m_textAliginLeft,SIGNAL(toggled(bool)),this,SLOT(slotTextHAttribsChanged(bool)));
|
||||
addAction(m_textAliginLeft);
|
||||
|
||||
m_textAliginHCenter = new QAction(tr("Text align center"),this);
|
||||
m_textAliginHCenter->setIcon(QIcon(":/report/images/textAlignHCenter"));
|
||||
m_textAliginHCenter->setCheckable(true);
|
||||
connect(m_textAliginHCenter,SIGNAL(toggled(bool)),this,SLOT(slotTextHAttribsChanged(bool)));
|
||||
addAction(m_textAliginHCenter);
|
||||
|
||||
m_textAliginRight = new QAction(tr("Text align right"),this);
|
||||
m_textAliginRight->setIcon(QIcon(":/report/images/textAlignHRight"));
|
||||
m_textAliginRight->setCheckable(true);
|
||||
connect(m_textAliginRight,SIGNAL(toggled(bool)),this,SLOT(slotTextHAttribsChanged(bool)));
|
||||
addAction(m_textAliginRight);
|
||||
|
||||
m_textAliginJustify = new QAction(tr("Text align justify"),this);
|
||||
m_textAliginJustify->setIcon(QIcon(":/report/images/textAlignHJustify"));
|
||||
m_textAliginJustify->setCheckable(true);
|
||||
connect(m_textAliginJustify,SIGNAL(toggled(bool)),this,SLOT(slotTextHAttribsChanged(bool)));
|
||||
addAction(m_textAliginJustify);
|
||||
|
||||
addSeparator();
|
||||
|
||||
m_textAliginTop = new QAction(tr("Text align top"),this);
|
||||
m_textAliginTop->setIcon(QIcon(":/report/images/textAlignVTop"));
|
||||
m_textAliginTop->setCheckable(true);
|
||||
connect(m_textAliginTop,SIGNAL(toggled(bool)),this,SLOT(slotTextVAttribsChanged(bool)));
|
||||
addAction(m_textAliginTop);
|
||||
|
||||
m_textAliginVCenter = new QAction(tr("Text align center"),this);
|
||||
m_textAliginVCenter->setIcon(QIcon(":/report/images/textAlignVCenter"));
|
||||
m_textAliginVCenter->setCheckable(true);
|
||||
connect(m_textAliginVCenter,SIGNAL(toggled(bool)),this,SLOT(slotTextVAttribsChanged(bool)));
|
||||
addAction(m_textAliginVCenter);
|
||||
|
||||
m_textAliginBottom = new QAction(tr("Text align bottom"),this);
|
||||
m_textAliginBottom->setIcon(QIcon(":/report/images/textAlignVBottom"));
|
||||
m_textAliginBottom->setCheckable(true);
|
||||
connect(m_textAliginBottom,SIGNAL(toggled(bool)),this,SLOT(slotTextVAttribsChanged(bool)));
|
||||
addAction(m_textAliginBottom);
|
||||
|
||||
if (reportEditor()){
|
||||
connect(reportEditor(),SIGNAL(itemPropertyChanged(QString,QString,QVariant,QVariant)),
|
||||
this,SLOT(slotPropertyChanged(QString,QString,QVariant,QVariant)));
|
||||
}
|
||||
if (page()){
|
||||
connect(page(),SIGNAL(itemPropertyChanged(QString,QString,QVariant,QVariant)),
|
||||
this,SLOT(slotPropertyChanged(QString,QString,QVariant,QVariant)));
|
||||
}
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
void TextAlignmentEditorWidget::updateValues(const Qt::Alignment &align)
|
||||
{
|
||||
m_textAttibutesIsChanging=true;
|
||||
m_textAliginLeft->setChecked((align & Qt::AlignLeft)==Qt::AlignLeft);
|
||||
m_textAliginRight->setChecked((align & Qt::AlignRight)==Qt::AlignRight);
|
||||
m_textAliginHCenter->setChecked((align & Qt::AlignHCenter)==Qt::AlignHCenter);
|
||||
m_textAliginJustify->setChecked((align & Qt::AlignJustify)==Qt::AlignJustify);
|
||||
m_textAliginTop->setChecked((align & Qt::AlignTop)==Qt::AlignTop);
|
||||
m_textAliginVCenter->setChecked((align & Qt::AlignVCenter)==Qt::AlignVCenter);
|
||||
m_textAliginBottom->setChecked((align & Qt::AlignBottom)==Qt::AlignBottom);
|
||||
m_textAttibutesIsChanging=false;
|
||||
}
|
||||
|
||||
Qt::Alignment TextAlignmentEditorWidget::createAlignment()
|
||||
{
|
||||
Qt::Alignment align = 0 ;
|
||||
if (m_textAliginLeft->isChecked()) align |= Qt::AlignLeft;
|
||||
if (m_textAliginHCenter->isChecked()) align |= Qt::AlignHCenter;
|
||||
if (m_textAliginRight->isChecked()) align |= Qt::AlignRight;
|
||||
if (m_textAliginJustify->isChecked()) align |= Qt::AlignJustify;
|
||||
if (m_textAliginTop->isChecked()) align |= Qt::AlignTop;
|
||||
if (m_textAliginVCenter->isChecked()) align |= Qt::AlignVCenter;
|
||||
if (m_textAliginBottom->isChecked()) align |= Qt::AlignBottom;
|
||||
return align;
|
||||
}
|
||||
|
||||
void TextAlignmentEditorWidget::slotTextHAttribsChanged(bool)
|
||||
{
|
||||
if (m_textAttibutesIsChanging) return;
|
||||
m_textAttibutesIsChanging = true;
|
||||
|
||||
m_textAliginLeft->setChecked(sender()==m_textAliginLeft);
|
||||
m_textAliginHCenter->setChecked(sender()==m_textAliginHCenter);
|
||||
m_textAliginRight->setChecked(sender()==m_textAliginRight);
|
||||
m_textAliginJustify->setChecked(sender()==m_textAliginJustify);
|
||||
|
||||
int flag = 0;
|
||||
if (sender()==m_textAliginLeft) flag |= Qt::AlignLeft;
|
||||
if (sender()==m_textAliginHCenter) flag |= Qt::AlignHCenter;
|
||||
if (sender()==m_textAliginRight) flag |= Qt::AlignRight;
|
||||
if (sender()==m_textAliginJustify) flag |= Qt::AlignJustify;
|
||||
|
||||
if (reportEditor()) reportEditor()->setTextAlign(true,Qt::AlignmentFlag(flag));
|
||||
if (page()) {
|
||||
//page()->setTextAlign(createAlignment());
|
||||
page()->changeSelectedGrpoupTextAlignPropperty(true,Qt::AlignmentFlag(flag));
|
||||
}
|
||||
m_textAttibutesIsChanging = false;
|
||||
}
|
||||
|
||||
void TextAlignmentEditorWidget::slotTextVAttribsChanged(bool)
|
||||
{
|
||||
if (m_textAttibutesIsChanging) return;
|
||||
m_textAttibutesIsChanging = true;
|
||||
|
||||
m_textAliginTop->setChecked(sender()==m_textAliginTop);
|
||||
m_textAliginVCenter->setChecked(sender()==m_textAliginVCenter);
|
||||
m_textAliginBottom->setChecked(sender()==m_textAliginBottom);
|
||||
|
||||
int flag = 0;
|
||||
if (sender()==m_textAliginTop) flag |= Qt::AlignTop;
|
||||
if (sender()==m_textAliginVCenter) flag |= Qt::AlignVCenter;
|
||||
if (sender()==m_textAliginBottom) flag |= Qt::AlignBottom;
|
||||
|
||||
if (reportEditor()) reportEditor()->setTextAlign(false,Qt::AlignmentFlag(flag));
|
||||
if (page()) page()->changeSelectedGrpoupTextAlignPropperty(false,Qt::AlignmentFlag(flag) );
|
||||
m_textAttibutesIsChanging = false;
|
||||
}
|
||||
|
||||
void TextAlignmentEditorWidget::slotPropertyChanged(const QString &objectName, const QString &property, const QVariant &oldValue, const QVariant &newValue)
|
||||
{
|
||||
Q_UNUSED(oldValue)
|
||||
Q_UNUSED(newValue)
|
||||
|
||||
if (item()&&(item()->objectName()==objectName)&&(property=="alignment")){
|
||||
updateValues(Qt::Alignment(item()->property("alignment").value<int>()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} //namespace LimeReport
|
73
limereport/items/editors/lrtextalignmenteditorwidget.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRTEXTALIGNMENTEDITORWIDGET_H
|
||||
#define LRTEXTALIGNMENTEDITORWIDGET_H
|
||||
|
||||
#include "lrreportdesignwidget.h"
|
||||
#include "lritemeditorwidget.h"
|
||||
#include <QToolBar>
|
||||
#include <QAction>
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
class TextAlignmentEditorWidget:public ItemEditorWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TextAlignmentEditorWidget(ReportDesignWidget* reportEditor, const QString &title, QWidget *parent = 0);
|
||||
explicit TextAlignmentEditorWidget(ReportDesignWidget* reportEditor, QWidget *parent = 0);
|
||||
explicit TextAlignmentEditorWidget(PageDesignIntf* page, const QString &title, QWidget *parent = 0);
|
||||
explicit TextAlignmentEditorWidget(PageDesignIntf* page, QWidget *parent = 0);
|
||||
protected:
|
||||
void setItemEvent(BaseDesignIntf *item);
|
||||
private:
|
||||
void initEditor();
|
||||
void updateValues(const Qt::Alignment& align);
|
||||
Qt::Alignment createAlignment();
|
||||
private slots:
|
||||
void slotTextHAttribsChanged(bool);
|
||||
void slotTextVAttribsChanged(bool);
|
||||
void slotPropertyChanged(const QString& objectName, const QString& property, const QVariant &oldValue, const QVariant &newValue);
|
||||
private:
|
||||
bool m_textAttibutesIsChanging;
|
||||
|
||||
QAction* m_textAliginLeft;
|
||||
QAction* m_textAliginRight;
|
||||
QAction* m_textAliginHCenter;
|
||||
QAction* m_textAliginJustify;
|
||||
QAction* m_textAliginTop;
|
||||
QAction* m_textAliginBottom;
|
||||
QAction* m_textAliginVCenter;
|
||||
|
||||
};
|
||||
|
||||
} //namespace LimeReport
|
||||
|
||||
#endif // LRTEXTALIGNMENTEDITORWIDGET_H
|
BIN
limereport/items/images/DataBand.png
Normal file
After Width: | Height: | Size: 204 B |
BIN
limereport/items/images/DataBand16.png
Normal file
After Width: | Height: | Size: 158 B |
BIN
limereport/items/images/GroupFooter16.png
Normal file
After Width: | Height: | Size: 149 B |
BIN
limereport/items/images/GroupHeader16.png
Normal file
After Width: | Height: | Size: 159 B |
BIN
limereport/items/images/PageFooter.png
Normal file
After Width: | Height: | Size: 192 B |
BIN
limereport/items/images/PageFooter16.png
Normal file
After Width: | Height: | Size: 149 B |
BIN
limereport/items/images/PageHeader.png
Normal file
After Width: | Height: | Size: 184 B |
BIN
limereport/items/images/PageHeader16.png
Normal file
After Width: | Height: | Size: 158 B |
BIN
limereport/items/images/ReportFooter.png
Normal file
After Width: | Height: | Size: 193 B |
BIN
limereport/items/images/ReportFooter16.png
Normal file
After Width: | Height: | Size: 149 B |
BIN
limereport/items/images/ReportHeader.png
Normal file
After Width: | Height: | Size: 185 B |
BIN
limereport/items/images/ReportHeader16.png
Normal file
After Width: | Height: | Size: 159 B |
BIN
limereport/items/images/ReportPage.png
Normal file
After Width: | Height: | Size: 182 B |
BIN
limereport/items/images/ReportPage16.png
Normal file
After Width: | Height: | Size: 143 B |
BIN
limereport/items/images/SubDetailBand16.png
Normal file
After Width: | Height: | Size: 158 B |
BIN
limereport/items/images/SubDetailFooterBand16.png
Normal file
After Width: | Height: | Size: 149 B |
BIN
limereport/items/images/SubDetailHeaderBand16.png
Normal file
After Width: | Height: | Size: 154 B |
BIN
limereport/items/images/addBand1.png
Normal file
After Width: | Height: | Size: 640 B |
BIN
limereport/items/images/barcode2.png
Normal file
After Width: | Height: | Size: 229 B |
BIN
limereport/items/images/hlayout.png
Normal file
After Width: | Height: | Size: 444 B |
BIN
limereport/items/images/hlayuot_3_24.png
Normal file
After Width: | Height: | Size: 430 B |
BIN
limereport/items/images/imageItem.png
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
limereport/items/images/imageItem1.png
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
limereport/items/images/imageItem2.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
limereport/items/images/insert-text.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
limereport/items/images/insert-text_2.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
limereport/items/images/insert-text_3.png
Normal file
After Width: | Height: | Size: 593 B |
BIN
limereport/items/images/insert-text_5.png
Normal file
After Width: | Height: | Size: 598 B |
BIN
limereport/items/images/settings.png
Normal file
After Width: | Height: | Size: 509 B |
BIN
limereport/items/images/settings2.png
Normal file
After Width: | Height: | Size: 878 B |
BIN
limereport/items/images/shape2.png
Normal file
After Width: | Height: | Size: 538 B |
BIN
limereport/items/images/shape4.png
Normal file
After Width: | Height: | Size: 636 B |
BIN
limereport/items/images/shape5.png
Normal file
After Width: | Height: | Size: 662 B |
37
limereport/items/items.qrc
Normal file
@@ -0,0 +1,37 @@
|
||||
<RCC>
|
||||
<qresource prefix="/items">
|
||||
<file>images/insert-text.png</file>
|
||||
<file alias="BarcodeItem">images/barcode2.png</file>
|
||||
<file>images/imageItem.png</file>
|
||||
<file>images/shape2.png</file>
|
||||
<file>images/shape4.png</file>
|
||||
<file>images/insert-text_2.png</file>
|
||||
<file>images/insert-text_3.png</file>
|
||||
<file>images/hlayout.png</file>
|
||||
<file alias="TextItem">images/insert-text_5.png</file>
|
||||
<file alias="ShapeItem">images/shape5.png</file>
|
||||
<file>images/imageItem1.png</file>
|
||||
<file alias="ImageItem">images/imageItem2.png</file>
|
||||
<file>images/settings.png</file>
|
||||
<file>images/settings2.png</file>
|
||||
<file alias="HorizontalLayout">images/hlayuot_3_24.png</file>
|
||||
<file alias="Band">images/addBand1.png</file>
|
||||
<file>images/DataBand.png</file>
|
||||
<file>images/PageHeader.png</file>
|
||||
<file>images/PageFooter.png</file>
|
||||
<file>images/ReportHeader.png</file>
|
||||
<file>images/ReportFooter.png</file>
|
||||
<file>images/ReportPage.png</file>
|
||||
<file alias="PageFooter">images/PageFooter16.png</file>
|
||||
<file alias="PageHeader">images/PageHeader16.png</file>
|
||||
<file alias="ReportFooter">images/ReportFooter16.png</file>
|
||||
<file alias="ReportHeader">images/ReportHeader16.png</file>
|
||||
<file alias="SubDetailBand">images/SubDetailBand16.png</file>
|
||||
<file alias="SubDetailFooterBand">images/SubDetailFooterBand16.png</file>
|
||||
<file alias="SubDetailHeaderBand">images/SubDetailHeaderBand16.png</file>
|
||||
<file alias="DataBand">images/DataBand16.png</file>
|
||||
<file alias="GroupBandFooter">images/GroupFooter16.png</file>
|
||||
<file alias="GroupBandHeader">images/GroupHeader16.png</file>
|
||||
<file alias="PageItemDesignIntf">images/ReportPage16.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
165
limereport/items/lralignpropitem.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "lralignpropitem.h"
|
||||
#include "objectinspector/propertyItems/lrenumpropitem.h"
|
||||
#include "objectinspector/editors/lrcomboboxeditor.h"
|
||||
#include "lrtextitem.h"
|
||||
|
||||
namespace{
|
||||
LimeReport::ObjectPropItem * createAlignItem(
|
||||
QObject *object, LimeReport::ObjectPropItem::ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& data, LimeReport::ObjectPropItem* parent, bool readonly
|
||||
){
|
||||
return new LimeReport::AlignmentPropItem(object, objects, name, displayName, data, parent, readonly);
|
||||
}
|
||||
|
||||
bool registred = LimeReport::ObjectPropFactory::instance().registerCreator(
|
||||
LimeReport::APropIdent("alignment","LimeReport::TextItem"),
|
||||
QObject::tr("alignment"),
|
||||
createAlignItem
|
||||
);
|
||||
}
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
QString AlignmentPropItem::associateValue(int value, const AlignMap* map) const
|
||||
{
|
||||
QString result;
|
||||
QMap<QString,Qt::Alignment>::const_iterator it = map->constBegin();
|
||||
for(;it!= map->constEnd();++it){
|
||||
if ((value & it.value())) {
|
||||
if (result.isEmpty()) result+=it.key();
|
||||
else result=result+" | "+it.key();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
AlignmentPropItem::AlignmentPropItem(QObject *object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value, ObjectPropItem *parent, bool readonly)
|
||||
:ObjectPropItem(object, objects, name,displayName,value,parent,readonly)
|
||||
{
|
||||
|
||||
m_horizMap.insert(tr("Left"),Qt::AlignLeft);
|
||||
m_horizMap.insert(tr("Right"),Qt::AlignRight);
|
||||
m_horizMap.insert(tr("Center"),Qt::AlignHCenter);
|
||||
m_horizMap.insert(tr("Justify"),Qt::AlignJustify);
|
||||
|
||||
m_vertMap.insert(tr("Top"),Qt::AlignTop);
|
||||
m_vertMap.insert(tr("Center"),Qt::AlignVCenter);
|
||||
m_vertMap.insert(tr("Botom"),Qt::AlignBottom);
|
||||
|
||||
m_horizEditor = new AlignmentItemEditor(object, objects, name,tr("horizontal"),value.toInt(),this,false,m_horizMap);
|
||||
m_vertEditor = new AlignmentItemEditor(object, objects, name,tr("vertical"), value.toInt(),this,false,m_vertMap);
|
||||
|
||||
this->appendItem(m_horizEditor);
|
||||
this->appendItem(m_vertEditor);
|
||||
}
|
||||
|
||||
QString AlignmentPropItem::displayValue() const
|
||||
{
|
||||
return associateValue(propertyValue().toInt(),&m_horizMap)+" | "+
|
||||
associateValue(propertyValue().toInt(),&m_vertMap);
|
||||
}
|
||||
|
||||
void AlignmentPropItem::setPropertyValue(QVariant value)
|
||||
{
|
||||
m_horizEditor->setPropertyValue(value);
|
||||
m_vertEditor->setPropertyValue(value);
|
||||
ObjectPropItem::setPropertyValue(value);
|
||||
}
|
||||
|
||||
AlignmentItemEditor::AlignmentItemEditor(QObject *object, ObjectsList* objects, const QString &name, const QString &displayName, const QVariant &value, ObjectPropItem *parent,
|
||||
bool readonly, AlignMap acceptableValues)
|
||||
:ObjectPropItem(object, objects, name, displayName, value, parent, readonly),m_acceptableValues(acceptableValues)
|
||||
{
|
||||
if (! extractAcceptableValue(value.toInt()).isEmpty())
|
||||
setPropertyValue(extractAcceptableValue(value.toInt())[0]);
|
||||
else setPropertyValue(0);
|
||||
}
|
||||
|
||||
void AlignmentItemEditor::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index)
|
||||
{
|
||||
int flags = object()->property(propertyName().toLatin1()).toInt();
|
||||
int align = m_acceptableValues.value(qobject_cast<ComboBoxEditor*>(propertyEditor)->text());
|
||||
flags=clearAcceptableValues(flags) | align;
|
||||
object()->setProperty(propertyName().toLatin1(),flags);
|
||||
foreach(QObject* item,*objects()){item->setProperty(propertyName().toLatin1(),flags);}
|
||||
parent()->setPropertyValue(flags);
|
||||
model->setData(index,align);
|
||||
}
|
||||
|
||||
QVector<int> AlignmentItemEditor::extractAcceptableValue(int flags)
|
||||
{
|
||||
QVector<int> result;
|
||||
AlignMap::const_iterator it = m_acceptableValues.constBegin();
|
||||
for (;it != m_acceptableValues.constEnd();++it)
|
||||
{
|
||||
if (flags & it.value()) result<<it.value();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int AlignmentItemEditor::clearAcceptableValues(int flags)
|
||||
{
|
||||
AlignMap::const_iterator it = m_acceptableValues.constBegin();
|
||||
for (;it != m_acceptableValues.constEnd();++it)
|
||||
{
|
||||
if (flags & it.value())
|
||||
flags=flags^it.value();
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
QWidget *AlignmentItemEditor::createProperyEditor(QWidget *parent) const
|
||||
{
|
||||
ComboBoxEditor *editor = new ComboBoxEditor(parent);
|
||||
QStringList enumValues;
|
||||
enumValues<<m_acceptableValues.keys();
|
||||
editor->addItems(enumValues);
|
||||
return editor;
|
||||
}
|
||||
|
||||
void AlignmentItemEditor::setPropertyEditorData(QWidget *propertyEditor, const QModelIndex &) const
|
||||
{
|
||||
ComboBoxEditor *editor=qobject_cast<ComboBoxEditor *>(propertyEditor);
|
||||
editor->setTextValue(m_acceptableValues.key(Qt::Alignment(propertyValue().toInt())));
|
||||
}
|
||||
|
||||
QString AlignmentItemEditor::displayValue() const
|
||||
{
|
||||
return m_acceptableValues.key(Qt::Alignment(propertyValue().toInt()));
|
||||
}
|
||||
|
||||
void AlignmentItemEditor::setPropertyValue(QVariant value)
|
||||
{
|
||||
ObjectPropItem::setPropertyValue(extractAcceptableValue(value.toInt())[0]);
|
||||
}
|
||||
|
||||
}
|
80
limereport/items/lralignpropitem.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRALIGNPROPITEM_H
|
||||
#define LRALIGNPROPITEM_H
|
||||
|
||||
#include "lrobjectpropitem.h"
|
||||
#include "objectinspector/propertyItems/lrenumpropitem.h"
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
typedef QMap<QString,Qt::Alignment> AlignMap;
|
||||
|
||||
class AlignmentItemEditor;
|
||||
|
||||
class AlignmentPropItem : public ObjectPropItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AlignmentPropItem():ObjectPropItem(){}
|
||||
AlignmentPropItem(QObject *object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value, ObjectPropItem* parent, bool readonly=true);
|
||||
QString displayValue() const;
|
||||
void setPropertyValue(QVariant value);
|
||||
private:
|
||||
AlignMap m_vertMap;
|
||||
AlignMap m_horizMap;
|
||||
AlignmentItemEditor* m_horizEditor;
|
||||
AlignmentItemEditor* m_vertEditor;
|
||||
QString associateValue(int value, const AlignMap *map) const;
|
||||
};
|
||||
|
||||
class AlignmentItemEditor : public ObjectPropItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AlignmentItemEditor():ObjectPropItem(){}
|
||||
AlignmentItemEditor(QObject* object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value, ObjectPropItem* parent, bool readonly,
|
||||
AlignMap acceptableValues);
|
||||
void setModelData(QWidget * propertyEditor, QAbstractItemModel * model, const QModelIndex & index);
|
||||
void setPropertyEditorData(QWidget * propertyEditor, const QModelIndex &) const;
|
||||
QWidget* createProperyEditor(QWidget *parent) const;
|
||||
QString displayValue() const;
|
||||
void setPropertyValue(QVariant value);
|
||||
protected:
|
||||
QVector<int> extractAcceptableValue(int flags);
|
||||
int clearAcceptableValues(int flags);
|
||||
AlignMap acceptableValues() const {return m_acceptableValues;}
|
||||
private:
|
||||
AlignMap m_acceptableValues;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
#endif // LRALIGNPROPITEM_H
|
249
limereport/items/lrbarcodeitem.cpp
Normal file
@@ -0,0 +1,249 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "lrbarcodeitem.h"
|
||||
#include "lrdesignelementsfactory.h"
|
||||
#include "qzint.h"
|
||||
#include "lrglobal.h"
|
||||
|
||||
namespace{
|
||||
|
||||
const QString xmlTag = "BarcodeItem";
|
||||
|
||||
LimeReport::BaseDesignIntf * createBarcodeItem(QObject* owner, LimeReport::BaseDesignIntf* parent){
|
||||
return new LimeReport::BarcodeItem(owner,parent);
|
||||
}
|
||||
bool registred = LimeReport::DesignElementsFactory::instance().registerCreator(xmlTag, LimeReport::ItemAttribs(QObject::tr("Barcode Item"),"Item"), createBarcodeItem);
|
||||
|
||||
}
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
BarcodeItem::BarcodeItem(QObject* owner,QGraphicsItem* parent)
|
||||
: ContentItemDesignIntf(xmlTag,owner,parent),m_designTestValue("1"), m_barcodeType(CODE128),
|
||||
m_foregroundColor(Qt::black), m_backgroundColor(Qt::white), m_whitespace(10), m_angle(Angle0),
|
||||
m_barcodeWidth(0), m_securityLevel(0), m_pdf417CodeWords(928)
|
||||
{}
|
||||
|
||||
BarcodeItem::~BarcodeItem()
|
||||
{}
|
||||
|
||||
BaseDesignIntf *BarcodeItem::createSameTypeItem(QObject *owner, QGraphicsItem *parent)
|
||||
{
|
||||
return new BarcodeItem(owner,parent);
|
||||
}
|
||||
|
||||
void BarcodeItem::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
ppainter->save();
|
||||
Zint::QZint bc;
|
||||
if (itemMode() & DesignMode) bc.setText(m_designTestValue);
|
||||
else bc.setText(m_content);
|
||||
bc.setSymbol(m_barcodeType);
|
||||
bc.setWhitespace(m_whitespace);
|
||||
bc.setFgColor(m_foregroundColor);
|
||||
bc.setBgColor(m_backgroundColor);
|
||||
bc.setWidth(m_barcodeWidth);
|
||||
bc.setSecurityLevel(m_securityLevel);
|
||||
bc.setPdf417CodeWords(m_pdf417CodeWords);
|
||||
|
||||
if (isSelected()) ppainter->setOpacity(Const::SELECTION_OPACITY);
|
||||
|
||||
QRectF bcRect;
|
||||
|
||||
switch (m_angle) {
|
||||
case Angle0:
|
||||
bcRect = rect();
|
||||
break;
|
||||
case Angle90:
|
||||
ppainter->translate(width(),0);
|
||||
ppainter->rotate(90);
|
||||
bcRect = QRectF(0,0,height(),width());
|
||||
break;
|
||||
case Angle180:
|
||||
bcRect = rect();
|
||||
ppainter->translate(width(),height());
|
||||
ppainter->rotate(180);
|
||||
break;
|
||||
case Angle270:
|
||||
ppainter->translate(0,height());
|
||||
ppainter->rotate(270);
|
||||
bcRect = QRectF(0,0,height(),width());
|
||||
break;
|
||||
}
|
||||
|
||||
bc.render(*ppainter,bcRect,Zint::QZint::KeepAspectRatio);
|
||||
ppainter->restore();
|
||||
ItemDesignIntf::paint(ppainter,option,widget);
|
||||
}
|
||||
|
||||
void BarcodeItem::setContent(const QString &content)
|
||||
{
|
||||
if (m_content!=content){
|
||||
QString oldValue = m_content;
|
||||
m_content=content;
|
||||
update();
|
||||
notify("content",oldValue,m_content);
|
||||
}
|
||||
}
|
||||
|
||||
void BarcodeItem::setBarcodeType(BarcodeItem::BarcodeType value)
|
||||
{
|
||||
if (m_barcodeType!=value){
|
||||
BarcodeType oldValue = m_barcodeType;
|
||||
m_barcodeType = value;
|
||||
update();
|
||||
notify("barcodeType",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
void BarcodeItem::setDesignTestValue(QString value)
|
||||
{
|
||||
if (m_designTestValue!=value){
|
||||
QString oldValue = m_designTestValue;
|
||||
m_designTestValue=value;
|
||||
update();
|
||||
notify("testValue",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
void BarcodeItem::setForegroundColor(QColor value)
|
||||
{
|
||||
if (m_foregroundColor != value){
|
||||
QColor oldValue = m_foregroundColor;
|
||||
m_foregroundColor=value;
|
||||
update();
|
||||
notify("foregroundColor",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
void BarcodeItem::setBackgroundColor(QColor value)
|
||||
{
|
||||
if (m_backgroundColor != value){
|
||||
QColor oldValue = m_backgroundColor;
|
||||
m_backgroundColor=value;
|
||||
update();
|
||||
notify("backgroundColor",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
void BarcodeItem::setWhitespace(int value)
|
||||
{
|
||||
if (m_whitespace != value){
|
||||
int oldValue = m_whitespace;
|
||||
m_whitespace = value;
|
||||
update();
|
||||
notify("whitespace",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
BarcodeItem::AngleType BarcodeItem::angle() const
|
||||
{
|
||||
return m_angle;
|
||||
}
|
||||
|
||||
void BarcodeItem::setAngle(const AngleType &angle)
|
||||
{
|
||||
if (m_angle!=angle){
|
||||
AngleType oldValue = m_angle;
|
||||
m_angle = angle;
|
||||
if (!isLoading()){
|
||||
update();
|
||||
notify("angle",oldValue,angle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int BarcodeItem::barcodeWidth() const
|
||||
{
|
||||
return m_barcodeWidth;
|
||||
}
|
||||
|
||||
void BarcodeItem::setBarcodeWidth(int barcodeWidth)
|
||||
{
|
||||
if (m_barcodeWidth != barcodeWidth){
|
||||
int oldValue = m_barcodeWidth;
|
||||
m_barcodeWidth = barcodeWidth;
|
||||
if (!isLoading()){
|
||||
update();
|
||||
notify("barcodeWidth",oldValue,m_barcodeWidth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int BarcodeItem::securityLevel() const
|
||||
{
|
||||
return m_securityLevel;
|
||||
}
|
||||
|
||||
void BarcodeItem::setSecurityLevel(int securityLevel)
|
||||
{
|
||||
if (m_securityLevel != securityLevel){
|
||||
int oldValue = m_securityLevel;
|
||||
m_securityLevel = securityLevel;
|
||||
if (!isLoading()){
|
||||
update();
|
||||
notify("securityLevel",oldValue,m_securityLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int BarcodeItem::pdf417CodeWords() const
|
||||
{
|
||||
return m_pdf417CodeWords;
|
||||
}
|
||||
|
||||
void BarcodeItem::setPdf417CodeWords(int pdf417CodeWords)
|
||||
{
|
||||
if (m_pdf417CodeWords != pdf417CodeWords){
|
||||
int oldValue = m_pdf417CodeWords;
|
||||
m_pdf417CodeWords = pdf417CodeWords;
|
||||
if (!isLoading()){
|
||||
update();
|
||||
notify("pdf417CodeWords",oldValue,m_pdf417CodeWords);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BarcodeItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight)
|
||||
{
|
||||
switch(pass){
|
||||
case FirstPass:
|
||||
setContent(expandUserVariables(content(),pass,NoEscapeSymbols, dataManager));
|
||||
setContent(expandDataFields(content(), NoEscapeSymbols, dataManager));
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
BaseDesignIntf::updateItemSize(dataManager, pass, maxHeight);
|
||||
}
|
||||
|
||||
bool BarcodeItem::isNeedUpdateSize(RenderPass pass) const
|
||||
{return (pass==FirstPass)?true:false;}
|
||||
|
||||
}
|
173
limereport/items/lrbarcodeitem.h
Normal file
@@ -0,0 +1,173 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRBARCODEITEM_H
|
||||
#define LRBARCODEITEM_H
|
||||
#include "lritemdesignintf.h"
|
||||
#include <qzint.h>
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
class BarcodeItem : public LimeReport::ContentItemDesignIntf {
|
||||
Q_OBJECT
|
||||
Q_ENUMS(BarcodeType)
|
||||
Q_ENUMS(AngleType)
|
||||
Q_PROPERTY(QString content READ content WRITE setContent)
|
||||
Q_PROPERTY(BarcodeType barcodeType READ barcodeType WRITE setBarcodeType )
|
||||
Q_PROPERTY(QString testValue READ designTestValue WRITE setDesignTestValue)
|
||||
Q_PROPERTY(QColor foregroundColor READ foregroundColor WRITE setForegroundColor)
|
||||
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
|
||||
Q_PROPERTY(int whitespace READ whitespace WRITE setWhitespace)
|
||||
Q_PROPERTY(AngleType angle READ angle WRITE setAngle)
|
||||
Q_PROPERTY(int barcodeWidth READ barcodeWidth WRITE setBarcodeWidth)
|
||||
Q_PROPERTY(int securityLevel READ securityLevel WRITE setSecurityLevel)
|
||||
Q_PROPERTY(int pdf417CodeWords READ pdf417CodeWords WRITE setPdf417CodeWords)
|
||||
public:
|
||||
// enum BarcodeType {QRCODE=58,CODE128=20,DATAMATRIX=71,MAXICODE=57,MICROPDF417=84};
|
||||
// enum BarcodeType {CODE_11=1,C25MATRIX=2,QRCODE=58,CODE128=20,DATAMATRIX=71,MAXICODE=57,MICROPDF417=84,
|
||||
// EAN=13,PDF417=55, TELEPEN_NUM=87,ITF14=89, KIX=90, MICROQR=97,
|
||||
// EAN14=72,CHANNEL=140,CODEONE=141,GRIDMATRIX=142};
|
||||
enum BarcodeType {
|
||||
CODE11 =1,
|
||||
C25MATRIX =2,
|
||||
C25INTER =3,
|
||||
C25IATA =4,
|
||||
C25LOGIC =6,
|
||||
C25IND =7,
|
||||
CODE39 =8,
|
||||
EXCODE39 =9,
|
||||
EANX =13,
|
||||
EAN128 =16,
|
||||
CODABAR =18,
|
||||
CODE128 =20,
|
||||
DPLEIT =21,
|
||||
DPIDENT =22,
|
||||
CODE16K =23,
|
||||
CODE93 =25,
|
||||
FLAT =28,
|
||||
RSS14 =29,
|
||||
RSS_LTD =30,
|
||||
RSS_EXP =31,
|
||||
TELEPEN =32,
|
||||
UPCA =34,
|
||||
UPCE =37,
|
||||
POSTNET =40,
|
||||
MSI_PLESSEY =47,
|
||||
FIM =49,
|
||||
LOGMARS =50,
|
||||
PHARMA =51,
|
||||
PZN =52,
|
||||
PHARMA_TWO =53,
|
||||
PDF417 =55,
|
||||
PDF417TRUNC =56,
|
||||
MAXICODE =57,
|
||||
QRCODE =58,
|
||||
CODE128B =60,
|
||||
AUSPOST =63,
|
||||
AUSREPLY =66,
|
||||
AUSROUTE =67,
|
||||
AUSREDIRECT =68,
|
||||
ISBNX =69,
|
||||
RM4SCC =70,
|
||||
DATAMATRIX =71,
|
||||
ITF14 =72,
|
||||
CODABLOCKF =74,
|
||||
NVE18 =75,
|
||||
KOREAPOST =77,
|
||||
RSS14STACK =79,
|
||||
RSS14STACK_OMNI =80,
|
||||
RSS_EXPSTACK =81,
|
||||
PLANET =82,
|
||||
MICROPDF417 =84,
|
||||
ONECODE =85,
|
||||
PLESSEY =86,
|
||||
KIX =90,
|
||||
AZTEC =92,
|
||||
DAFT =93,
|
||||
ITALYPOST =94,
|
||||
DPD =96,
|
||||
MICROQR =97,
|
||||
TELEPEN_NUM =128,
|
||||
CODE32 =129,
|
||||
EANX_CC =130,
|
||||
EAN128_CC =131,
|
||||
RSS14_CC =132,
|
||||
RSS_LTD_CC =133,
|
||||
RSS_EXP_CC =134,
|
||||
UPCA_CC =135,
|
||||
UPCE_CC =136,
|
||||
RSS14STACK_CC =137,
|
||||
RSS14_OMNI_CC =138,
|
||||
RSS_EXPSTACK_CC =139
|
||||
|
||||
};
|
||||
enum AngleType{Angle0,Angle90,Angle180,Angle270};
|
||||
BarcodeItem(QObject *owner, QGraphicsItem *parent);
|
||||
~BarcodeItem();
|
||||
virtual BaseDesignIntf* createSameTypeItem(QObject *owner, QGraphicsItem *parent);
|
||||
virtual void paint(QPainter *ppainter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
virtual void updateItemSize(DataSourceManager *dataManager, RenderPass pass, int maxHeight);
|
||||
virtual bool isNeedUpdateSize(RenderPass pass) const;
|
||||
void setContent(const QString& content);
|
||||
QString content() const {return m_content;}
|
||||
void setBarcodeType(BarcodeType value);
|
||||
BarcodeType barcodeType(){return m_barcodeType;}
|
||||
void setDesignTestValue(QString value);
|
||||
QString designTestValue(){return m_designTestValue;}
|
||||
QColor foregroundColor(){return m_foregroundColor;}
|
||||
void setForegroundColor(QColor value);
|
||||
QColor backgroundColor(){return m_backgroundColor;}
|
||||
void setBackgroundColor(QColor value);
|
||||
int whitespace(){return m_whitespace;}
|
||||
void setWhitespace(int value);
|
||||
AngleType angle() const;
|
||||
void setAngle(const AngleType &angle);
|
||||
int barcodeWidth() const;
|
||||
void setBarcodeWidth(int barcodeWidth);
|
||||
int securityLevel() const;
|
||||
void setSecurityLevel(int securityLevel);
|
||||
int pdf417CodeWords() const;
|
||||
void setPdf417CodeWords(int pdf417CodeWords);
|
||||
|
||||
private:
|
||||
Zint::QZint m_bc;
|
||||
QString m_content;
|
||||
QString m_designTestValue;
|
||||
BarcodeType m_barcodeType;
|
||||
QColor m_foregroundColor;
|
||||
QColor m_backgroundColor;
|
||||
int m_whitespace;
|
||||
AngleType m_angle;
|
||||
int m_barcodeWidth;
|
||||
int m_securityLevel;
|
||||
int m_pdf417CodeWords;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // LRBARCODEITEM_H
|
521
limereport/items/lrhorizontallayout.cpp
Normal file
@@ -0,0 +1,521 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "lrhorizontallayout.h"
|
||||
#include "lrdesignelementsfactory.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QObject>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
|
||||
#include "lrbasedesignintf.h"
|
||||
|
||||
const QString xmlTag = "HLayout";
|
||||
|
||||
namespace {
|
||||
|
||||
LimeReport::BaseDesignIntf *createHLayout(QObject *owner, LimeReport::BaseDesignIntf *parent)
|
||||
{
|
||||
return new LimeReport::HorizontalLayout(owner, parent);
|
||||
}
|
||||
bool registred = LimeReport::DesignElementsFactory::instance().registerCreator(
|
||||
xmlTag,
|
||||
LimeReport::ItemAttribs(QObject::tr("HLayout"), LimeReport::Const::bandTAG),
|
||||
createHLayout
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
namespace LimeReport {
|
||||
|
||||
bool lessThen(BaseDesignIntf *c1, BaseDesignIntf* c2){
|
||||
return c1->pos().x()<c2->pos().x();
|
||||
}
|
||||
|
||||
|
||||
HorizontalLayout::HorizontalLayout(QObject *owner, QGraphicsItem *parent)
|
||||
: LayoutDesignIntf(xmlTag, owner, parent),m_isRelocating(false),m_layoutType(Layout)
|
||||
{
|
||||
setPosibleResizeDirectionFlags(ResizeBottom);
|
||||
m_layoutMarker = new LayoutMarker(this);
|
||||
m_layoutMarker->setParentItem(this);
|
||||
m_layoutMarker->setColor(Qt::red);
|
||||
m_layoutMarker->setHeight(height());
|
||||
m_layoutMarker->setZValue(1);
|
||||
}
|
||||
|
||||
HorizontalLayout::~HorizontalLayout()
|
||||
{
|
||||
if (m_layoutMarker) {
|
||||
delete m_layoutMarker; m_layoutMarker=0;
|
||||
}
|
||||
}
|
||||
|
||||
BaseDesignIntf *HorizontalLayout::createSameTypeItem(QObject *owner, QGraphicsItem *parent)
|
||||
{
|
||||
return new LimeReport::HorizontalLayout(owner, parent);
|
||||
}
|
||||
|
||||
void HorizontalLayout::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
// if ((itemMode() & LayoutEditMode) || isSelected()){
|
||||
// setChildVisibility(false);
|
||||
// }
|
||||
}
|
||||
|
||||
void HorizontalLayout::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
// setChildVisibility(true);
|
||||
}
|
||||
|
||||
void HorizontalLayout::geometryChangedEvent(QRectF newRect, QRectF )
|
||||
{
|
||||
m_layoutMarker->setHeight(newRect.height());
|
||||
relocateChildren();
|
||||
if (m_layoutType == Table && !m_isRelocating){
|
||||
divideSpace();
|
||||
}
|
||||
}
|
||||
|
||||
void HorizontalLayout::setChildVisibility(bool value){
|
||||
foreach(QGraphicsItem* child,childItems()){
|
||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(child);
|
||||
if(item)
|
||||
item->setVisible(value);
|
||||
}
|
||||
}
|
||||
|
||||
int HorizontalLayout::childrenCount()
|
||||
{
|
||||
return m_children.size();
|
||||
}
|
||||
|
||||
void HorizontalLayout::initMode(BaseDesignIntf::ItemMode mode)
|
||||
{
|
||||
BaseDesignIntf::initMode(mode);
|
||||
if ((mode==PreviewMode)||(mode==PrintMode)){
|
||||
m_layoutMarker->setVisible(false);
|
||||
} else {
|
||||
m_layoutMarker->setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
bool HorizontalLayout::canBeSplitted(int height) const
|
||||
{
|
||||
foreach(QGraphicsItem* qgItem,childItems()){
|
||||
BaseDesignIntf* item=dynamic_cast<BaseDesignIntf*>(qgItem);
|
||||
if (item)
|
||||
if (!item->canBeSplitted(height-item->pos().y())) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
BaseDesignIntf *HorizontalLayout::cloneUpperPart(int height, QObject *owner, QGraphicsItem *parent)
|
||||
{
|
||||
HorizontalLayout* upperPart = dynamic_cast<HorizontalLayout*>(createSameTypeItem(owner,parent));
|
||||
upperPart->initFromItem(this);
|
||||
qreal maxHeight = 0;
|
||||
foreach(BaseDesignIntf* item,childBaseItems()){
|
||||
|
||||
if ((item->geometry().top()<height) && (item->geometry().bottom()>height)){
|
||||
int sliceHeight = height-item->geometry().top();
|
||||
if (item->canBeSplitted(sliceHeight)){
|
||||
BaseDesignIntf* slicedPart = item->cloneUpperPart(sliceHeight,upperPart,upperPart);
|
||||
if (maxHeight<slicedPart->height()) maxHeight = slicedPart->height();
|
||||
} else {
|
||||
item->cloneEmpty(sliceHeight,upperPart,upperPart);
|
||||
item->setPos(item->pos().x(),item->pos().y()+((height+1)-item->geometry().top()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach(BaseDesignIntf* item, upperPart->childBaseItems()){
|
||||
item->setHeight((maxHeight<height)?maxHeight:height);
|
||||
}
|
||||
upperPart->setHeight(height);
|
||||
|
||||
return upperPart;
|
||||
}
|
||||
|
||||
BaseDesignIntf *HorizontalLayout::cloneBottomPart(int height, QObject *owner, QGraphicsItem *parent)
|
||||
{
|
||||
qreal maxHeight = 0;
|
||||
HorizontalLayout* bottomPart = dynamic_cast<HorizontalLayout*>(createSameTypeItem(owner,parent));
|
||||
bottomPart->initFromItem(this);
|
||||
foreach(BaseDesignIntf* item,childBaseItems()){
|
||||
if ((item->geometry().top()<height) && (item->geometry().bottom()>height)){
|
||||
BaseDesignIntf* tmpItem=item->cloneBottomPart(height,bottomPart,bottomPart);
|
||||
tmpItem->setPos(tmpItem->pos().x(),0);
|
||||
if (maxHeight<tmpItem->height())
|
||||
maxHeight = tmpItem->height();
|
||||
}
|
||||
}
|
||||
|
||||
if (!bottomPart->isEmpty()){
|
||||
foreach (BaseDesignIntf* item, bottomPart->childBaseItems()) {
|
||||
item->setHeight(maxHeight);
|
||||
}
|
||||
bottomPart->setHeight(maxHeight);
|
||||
}
|
||||
return bottomPart;
|
||||
}
|
||||
|
||||
void HorizontalLayout::setItemAlign(const BaseDesignIntf::ItemAlign &itemAlign)
|
||||
{
|
||||
if (itemAlign == ParentWidthItemAlign)
|
||||
setLayoutType(Table);
|
||||
BaseDesignIntf::setItemAlign(itemAlign);
|
||||
}
|
||||
|
||||
void HorizontalLayout::restoreChild(BaseDesignIntf* item){
|
||||
if (m_children.contains(item)) return;
|
||||
|
||||
m_isRelocating=true;
|
||||
foreach (BaseDesignIntf* child, childBaseItems()) {
|
||||
if (child->pos()==item->pos()){
|
||||
int index = m_children.indexOf(child)-1;
|
||||
m_children.insert(index,item);
|
||||
child->setPos(item->pos().x()+item->width(),0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
connect(item,SIGNAL(destroyed(QObject*)),this,SLOT(slotOnChildDestroy(QObject*)));
|
||||
connect(item,SIGNAL(geometryChanged(QObject*,QRectF,QRectF)),
|
||||
this,SLOT(slotOnChildGeometryChanged(QObject*,QRectF,QRectF)));
|
||||
connect(item, SIGNAL(itemAlignChanged(BaseDesignIntf*,ItemAlign,ItemAlign)),
|
||||
this, SLOT(slotOnChildItemAlignChanged(BaseDesignIntf*,ItemAlign,ItemAlign)));
|
||||
|
||||
item->setFixedPos(true);
|
||||
item->setPosibleResizeDirectionFlags(ResizeRight | ResizeBottom);
|
||||
item->setParent(this);
|
||||
item->setParentItem(this);
|
||||
|
||||
updateLayoutSize();
|
||||
m_isRelocating=false;
|
||||
}
|
||||
|
||||
bool HorizontalLayout::isEmpty() const
|
||||
{
|
||||
bool isEmpty = true;
|
||||
bool allItemsIsText = true;
|
||||
foreach (QGraphicsItem* qgItem, childItems()) {
|
||||
ContentItemDesignIntf* item = dynamic_cast<ContentItemDesignIntf*>(qgItem);
|
||||
if (item && !item->content().isEmpty()) isEmpty = false;
|
||||
if (!item && dynamic_cast<BaseDesignIntf*>(qgItem))
|
||||
allItemsIsText = false;
|
||||
}
|
||||
return (isEmpty && allItemsIsText);
|
||||
}
|
||||
|
||||
void HorizontalLayout::addChild(BaseDesignIntf *item, bool updateSize)
|
||||
{
|
||||
if (m_children.count() > 0)
|
||||
item->setPos(m_children.last()->pos().x() + m_children.last()->width(), 0);
|
||||
else
|
||||
item->setPos(0, 0);
|
||||
|
||||
m_children.append(item);
|
||||
item->setParentItem(this);
|
||||
item->setParent(this);
|
||||
item->setFixedPos(true);
|
||||
item->setPosibleResizeDirectionFlags(ResizeRight | ResizeBottom);
|
||||
|
||||
connect(item,SIGNAL(destroyed(QObject*)),this,SLOT(slotOnChildDestroy(QObject*)));
|
||||
connect(item,SIGNAL(geometryChanged(QObject*,QRectF,QRectF)),this,SLOT(slotOnChildGeometryChanged(QObject*,QRectF,QRectF)));
|
||||
|
||||
if (updateSize){
|
||||
relocateChildren();
|
||||
updateLayoutSize();
|
||||
}
|
||||
}
|
||||
|
||||
void HorizontalLayout::collectionLoadFinished(const QString &collectionName)
|
||||
{
|
||||
ItemDesignIntf::collectionLoadFinished(collectionName);
|
||||
if (collectionName.compare("children",Qt::CaseInsensitive)==0){
|
||||
#ifdef HAVE_QT5
|
||||
foreach(QObject* obj,children()){
|
||||
#else
|
||||
foreach(QObject* obj,QObject::children()){
|
||||
#endif
|
||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(obj);
|
||||
if (item) {
|
||||
addChild(item,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HorizontalLayout::objectLoadFinished()
|
||||
{
|
||||
m_layoutMarker->setHeight(height());
|
||||
LayoutDesignIntf::objectLoadFinished();
|
||||
}
|
||||
|
||||
void HorizontalLayout::updateLayoutSize()
|
||||
{
|
||||
int w = 0;
|
||||
qreal h = 0;
|
||||
foreach(BaseDesignIntf* item, m_children){
|
||||
if (h<item->height()) h=item->height();
|
||||
w+=item->width();
|
||||
}
|
||||
if (h>0) setHeight(h);
|
||||
setWidth(w);
|
||||
}
|
||||
|
||||
void HorizontalLayout::relocateChildren()
|
||||
{
|
||||
if (m_children.count()<childItems().size()-1){
|
||||
m_children.clear();
|
||||
foreach (BaseDesignIntf* item, childBaseItems()) {
|
||||
m_children.append(item);
|
||||
}
|
||||
}
|
||||
qSort(m_children.begin(),m_children.end(),lessThen);
|
||||
qreal curX = 0;
|
||||
m_isRelocating = true;
|
||||
foreach (BaseDesignIntf* item, m_children) {
|
||||
item->setPos(curX,0);
|
||||
curX+=item->width();
|
||||
item->setHeight(height());
|
||||
}
|
||||
m_isRelocating = false;
|
||||
}
|
||||
|
||||
void HorizontalLayout::beforeDelete()
|
||||
{
|
||||
m_children.clear();
|
||||
#ifdef HAVE_QT5
|
||||
foreach (QObject *item, children()) {
|
||||
#else
|
||||
foreach (QObject *item, QObject::children()) {
|
||||
#endif
|
||||
BaseDesignIntf *bdItem = dynamic_cast<BaseDesignIntf*>(item);
|
||||
if (bdItem) {
|
||||
bdItem->setParentItem(parentItem());
|
||||
bdItem->setParent(parent());
|
||||
bdItem->setVisible(true);
|
||||
bdItem->setPos(mapToParent(bdItem->pos()));
|
||||
bdItem->setFixedPos(false);
|
||||
bdItem->setPosibleResizeDirectionFlags(AllDirections);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HorizontalLayout::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight)
|
||||
{
|
||||
m_isRelocating=true;
|
||||
ItemDesignIntf::updateItemSize(dataManager, pass, maxHeight);
|
||||
foreach(QGraphicsItem *child, childItems()){
|
||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(child);
|
||||
if (item) item->updateItemSize(dataManager, pass, maxHeight);
|
||||
}
|
||||
updateLayoutSize();
|
||||
relocateChildren();
|
||||
m_isRelocating=false;
|
||||
BaseDesignIntf::updateItemSize(dataManager, pass, maxHeight);
|
||||
}
|
||||
|
||||
bool HorizontalLayout::isNeedUpdateSize(RenderPass pass) const
|
||||
{
|
||||
foreach (QGraphicsItem *child, childItems()) {
|
||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(child);
|
||||
if (item && item->isNeedUpdateSize(pass))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void HorizontalLayout::childAddedEvent(BaseDesignIntf *child)
|
||||
{
|
||||
addChild(child,false);
|
||||
}
|
||||
|
||||
void HorizontalLayout::slotOnChildDestroy(QObject* child)
|
||||
{
|
||||
m_children.removeAll(static_cast<BaseDesignIntf*>(child));
|
||||
if (m_children.count()<2){
|
||||
beforeDelete();
|
||||
// deleteLater();
|
||||
} else {
|
||||
relocateChildren();
|
||||
updateLayoutSize();
|
||||
}
|
||||
}
|
||||
|
||||
BaseDesignIntf* HorizontalLayout::findNext(BaseDesignIntf* item){
|
||||
if (m_children.count()<childItems().size()-1){
|
||||
m_children.clear();
|
||||
foreach (BaseDesignIntf* item, childBaseItems()) {
|
||||
m_children.append(item);
|
||||
}
|
||||
}
|
||||
qSort(m_children.begin(),m_children.end(),lessThen);
|
||||
for (int i=0; i<m_children.count();++i){
|
||||
if (m_children[i]==item && m_children.size()>i+1){ return m_children[i+1];}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BaseDesignIntf* HorizontalLayout::findPrior(BaseDesignIntf* item){
|
||||
if (m_children.count()<childItems().size()-1){
|
||||
m_children.clear();
|
||||
foreach (BaseDesignIntf* item, childBaseItems()) {
|
||||
m_children.append(item);
|
||||
}
|
||||
}
|
||||
qSort(m_children.begin(),m_children.end(),lessThen);
|
||||
for (int i=0; i<m_children.count();++i){
|
||||
if (m_children[i]==item && i!=0){ return m_children[i-1];}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HorizontalLayout::divideSpace(){
|
||||
m_isRelocating = true;
|
||||
qreal itemsSumSize = 0;
|
||||
foreach(BaseDesignIntf* item, m_children){
|
||||
itemsSumSize += item->width();
|
||||
}
|
||||
qreal delta = (width() - itemsSumSize)/m_children.size();
|
||||
for (int i=0; i<m_children.size(); ++i){
|
||||
m_children[i]->setWidth(m_children[i]->width()+(delta));
|
||||
if ((i+1)<m_children.size())
|
||||
m_children[i+1]->setPos(m_children[i+1]->pos().x()+delta*(i+1),m_children[i+1]->pos().y());
|
||||
}
|
||||
m_isRelocating = false;
|
||||
}
|
||||
void HorizontalLayout::slotOnChildGeometryChanged(QObject *item, QRectF newGeometry, QRectF oldGeometry)
|
||||
{
|
||||
if (!m_isRelocating){
|
||||
setHeight(newGeometry.height());
|
||||
if (m_layoutType == Layout){
|
||||
relocateChildren();
|
||||
updateLayoutSize();
|
||||
} else {
|
||||
m_isRelocating = true;
|
||||
qreal delta = newGeometry.width()-oldGeometry.width();
|
||||
BaseDesignIntf* resizingItem = findNext(dynamic_cast<BaseDesignIntf*>(item));
|
||||
if (resizingItem) {
|
||||
resizingItem->setWidth(resizingItem->width()-delta);
|
||||
resizingItem->setPos(resizingItem->pos().x()+delta,resizingItem->pos().y());
|
||||
}
|
||||
updateLayoutSize();
|
||||
m_isRelocating = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HorizontalLayout::slotOnChildItemAlignChanged(BaseDesignIntf *item, const BaseDesignIntf::ItemAlign &, const BaseDesignIntf::ItemAlign&)
|
||||
{
|
||||
item->setPosibleResizeDirectionFlags(ResizeBottom | ResizeRight);
|
||||
}
|
||||
|
||||
HorizontalLayout::LayoutType HorizontalLayout::layoutType() const
|
||||
{
|
||||
return m_layoutType;
|
||||
}
|
||||
|
||||
void HorizontalLayout::setLayoutType(const LayoutType &layoutType)
|
||||
{
|
||||
if (m_layoutType != layoutType){
|
||||
LayoutType oldValue = m_layoutType;
|
||||
m_layoutType = layoutType;
|
||||
notify("layoutType",oldValue,layoutType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LayoutMarker::LayoutMarker(HorizontalLayout *layout, QGraphicsItem *parent)
|
||||
:QGraphicsItem(parent), m_rect(0,0,30,30), m_color(Qt::red), m_layout(layout){
|
||||
setFlag(QGraphicsItem::ItemIsMovable);
|
||||
}
|
||||
|
||||
void LayoutMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
|
||||
{
|
||||
painter->save();
|
||||
painter->setOpacity(Const::LAYOUT_MARKER_OPACITY);
|
||||
painter->fillRect(boundingRect(),m_color);
|
||||
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
qreal size = (boundingRect().width()<boundingRect().height()) ? boundingRect().width() : boundingRect().height();
|
||||
|
||||
if (m_layout->isSelected()){
|
||||
painter->setOpacity(1);
|
||||
QRectF r = QRectF(0,0,size,size);
|
||||
painter->setBrush(Qt::white);
|
||||
painter->setPen(Qt::white);
|
||||
painter->drawEllipse(r.adjusted(5,5,-5,-5));
|
||||
painter->setBrush(m_color);
|
||||
painter->drawEllipse(r.adjusted(7,7,-7,-7));
|
||||
}
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void LayoutMarker::setHeight(qreal height)
|
||||
{
|
||||
if (m_rect.height()!=height){
|
||||
prepareGeometryChange();
|
||||
m_rect.setHeight(height);
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutMarker::setWidth(qreal width)
|
||||
{
|
||||
if (m_rect.width()!=width){
|
||||
prepareGeometryChange();
|
||||
m_rect.setWidth(width);
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutMarker::setColor(QColor color)
|
||||
{
|
||||
if (m_color!=color){
|
||||
m_color = color;
|
||||
update(boundingRect());
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutMarker::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button()==Qt::LeftButton) {
|
||||
if (!(event->modifiers() & Qt::ControlModifier))
|
||||
m_layout->scene()->clearSelection();
|
||||
m_layout->setSelected(true);
|
||||
//m_layout->setChildVisibility(false);
|
||||
update(0,0,boundingRect().width(),boundingRect().width());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace LimeReport
|
112
limereport/items/lrhorizontallayout.h
Normal file
@@ -0,0 +1,112 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRHORIZONTALLAYOUT_H
|
||||
#define LRHORIZONTALLAYOUT_H
|
||||
#include "lritemdesignintf.h"
|
||||
|
||||
namespace LimeReport
|
||||
{
|
||||
|
||||
class HorizontalLayout;
|
||||
|
||||
class LayoutMarker : public QGraphicsItem{
|
||||
public:
|
||||
explicit LayoutMarker(HorizontalLayout* layout, QGraphicsItem *parent=0);
|
||||
virtual QRectF boundingRect() const{return m_rect;}
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
|
||||
void setHeight(qreal height);
|
||||
void setWidth(qreal width);
|
||||
void setColor(QColor color);
|
||||
qreal width(){return m_rect.width();}
|
||||
qreal height(){return m_rect.height();}
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
private:
|
||||
QRectF m_rect;
|
||||
QColor m_color;
|
||||
HorizontalLayout* m_layout;
|
||||
};
|
||||
|
||||
class HorizontalLayout : public LayoutDesignIntf
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(LayoutType)
|
||||
Q_PROPERTY(LayoutType layoutType READ layoutType WRITE setLayoutType)
|
||||
public:
|
||||
friend class LayoutMarker;
|
||||
enum LayoutType{Layout,Table};
|
||||
HorizontalLayout(QObject *owner = 0, QGraphicsItem *parent = 0);
|
||||
~HorizontalLayout();
|
||||
BaseDesignIntf *createSameTypeItem(QObject *owner = 0, QGraphicsItem *parent = 0);
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||
void geometryChangedEvent(QRectF newRect, QRectF);
|
||||
void addChild(BaseDesignIntf *item,bool updateSize=true);
|
||||
friend class BaseDesignIntf;
|
||||
void restoreChild(BaseDesignIntf *item);
|
||||
bool isEmpty() const;
|
||||
LayoutType layoutType() const;
|
||||
void setLayoutType(const LayoutType &layoutType);
|
||||
protected:
|
||||
void collectionLoadFinished(const QString &collectionName);
|
||||
void objectLoadFinished();
|
||||
void updateLayoutSize();
|
||||
void relocateChildren();
|
||||
BaseDesignIntf *findNext(BaseDesignIntf *item);
|
||||
BaseDesignIntf *findPrior(BaseDesignIntf *item);
|
||||
void beforeDelete();
|
||||
void updateItemSize(DataSourceManager *dataManager, RenderPass pass, int maxHeight);
|
||||
bool isNeedUpdateSize(RenderPass pass) const;
|
||||
void childAddedEvent(BaseDesignIntf *child);
|
||||
void setChildVisibility(bool value);
|
||||
int childrenCount();
|
||||
void initMode(ItemMode mode);
|
||||
|
||||
bool canBeSplitted(int height) const;
|
||||
BaseDesignIntf* cloneUpperPart(int height, QObject* owner=0, QGraphicsItem* parent=0);
|
||||
BaseDesignIntf* cloneBottomPart(int height, QObject *owner=0, QGraphicsItem *parent=0);
|
||||
|
||||
void setItemAlign(const ItemAlign &itemAlign);
|
||||
private slots:
|
||||
void slotOnChildDestroy(QObject *child);
|
||||
void slotOnChildGeometryChanged(QObject*item, QRectF newGeometry, QRectF oldGeometry);
|
||||
void slotOnChildItemAlignChanged(BaseDesignIntf* item, const ItemAlign&, const ItemAlign&);
|
||||
//void slotOnPosChanged(QObject*, QPointF newPos, QPointF );
|
||||
private:
|
||||
void divideSpace();
|
||||
private:
|
||||
QList<BaseDesignIntf *> m_children;
|
||||
bool m_isRelocating;
|
||||
LayoutMarker* m_layoutMarker;
|
||||
LayoutType m_layoutType;
|
||||
};
|
||||
|
||||
} //namespace LimeReport
|
||||
#endif // LRHORIZONTALLAYOUT_H
|
261
limereport/items/lrimageitem.cpp
Normal file
@@ -0,0 +1,261 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "lrimageitem.h"
|
||||
#include "lrdesignelementsfactory.h"
|
||||
#include "lrglobal.h"
|
||||
#include "lrdatasourcemanager.h"
|
||||
|
||||
namespace{
|
||||
|
||||
const QString xmlTag = "ImageItem";
|
||||
|
||||
LimeReport::BaseDesignIntf * createImageItem(QObject* owner, LimeReport::BaseDesignIntf* parent){
|
||||
return new LimeReport::ImageItem(owner,parent);
|
||||
}
|
||||
bool registred = LimeReport::DesignElementsFactory::instance().registerCreator(
|
||||
xmlTag, LimeReport::ItemAttribs(QObject::tr("Image Item"),"Item"), createImageItem
|
||||
);
|
||||
}
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
ImageItem::ImageItem(QObject* owner,QGraphicsItem* parent)
|
||||
:ItemDesignIntf(xmlTag,owner,parent),m_autoSize(false), m_scale(true), m_keepAspectRatio(true), m_center(true){}
|
||||
|
||||
BaseDesignIntf *ImageItem::createSameTypeItem(QObject *owner, QGraphicsItem *parent)
|
||||
{
|
||||
return new ImageItem(owner,parent);
|
||||
}
|
||||
|
||||
void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight)
|
||||
{
|
||||
if (!m_datasource.isEmpty() && !m_field.isEmpty() && m_picture.isNull()){
|
||||
IDataSource* ds = dataManager->dataSource(m_datasource);
|
||||
if (ds) {
|
||||
QVariant data = ds->data(m_field);
|
||||
if (data.isValid()){
|
||||
if (data.type()==QVariant::Image){
|
||||
m_picture = data.value<QImage>();
|
||||
} else
|
||||
m_picture.loadFromData(data.toByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_autoSize){
|
||||
setWidth(m_picture.width());
|
||||
setHeight(m_picture.height());
|
||||
}
|
||||
BaseDesignIntf::updateItemSize(dataManager, pass, maxHeight);
|
||||
}
|
||||
|
||||
bool ImageItem::isNeedUpdateSize(RenderPass) const
|
||||
{
|
||||
return m_picture.isNull() || m_autoSize;
|
||||
}
|
||||
|
||||
qreal ImageItem::minHeight() const{
|
||||
if (!m_picture.isNull() && autoSize())
|
||||
{
|
||||
return m_picture.height();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool ImageItem::center() const
|
||||
{
|
||||
return m_center;
|
||||
}
|
||||
|
||||
void ImageItem::setCenter(bool center)
|
||||
{
|
||||
if (m_center != center){
|
||||
m_center = center;
|
||||
update();
|
||||
notify("center",!center,center);
|
||||
}
|
||||
}
|
||||
|
||||
bool ImageItem::keepAspectRatio() const
|
||||
{
|
||||
return m_keepAspectRatio;
|
||||
}
|
||||
|
||||
void ImageItem::setKeepAspectRatio(bool keepAspectRatio)
|
||||
{
|
||||
if (m_keepAspectRatio != keepAspectRatio){
|
||||
m_keepAspectRatio = keepAspectRatio;
|
||||
update();
|
||||
notify("keepAspectRatio",!keepAspectRatio,keepAspectRatio);
|
||||
}
|
||||
}
|
||||
|
||||
bool ImageItem::scale() const
|
||||
{
|
||||
return m_scale;
|
||||
}
|
||||
|
||||
void ImageItem::setScale(bool scale)
|
||||
{
|
||||
if (m_scale != scale){
|
||||
m_scale = scale;
|
||||
update();
|
||||
notify("scale",!scale,scale);
|
||||
}
|
||||
}
|
||||
bool ImageItem::autoSize() const
|
||||
{
|
||||
return m_autoSize;
|
||||
}
|
||||
|
||||
void ImageItem::setAutoSize(bool autoSize)
|
||||
{
|
||||
if (m_autoSize != autoSize){
|
||||
m_autoSize = autoSize;
|
||||
if (m_autoSize && !m_picture.isNull()){
|
||||
setWidth(image().width());
|
||||
setHeight(image().height());
|
||||
setPosibleResizeDirectionFlags(Fixed);
|
||||
} else {
|
||||
setPosibleResizeDirectionFlags(AllDirections);
|
||||
}
|
||||
update();
|
||||
notify("autoSize",!autoSize,autoSize);
|
||||
}
|
||||
}
|
||||
|
||||
QString ImageItem::field() const
|
||||
{
|
||||
return m_field;
|
||||
}
|
||||
|
||||
void ImageItem::setField(const QString &field)
|
||||
{
|
||||
if (m_field != field){
|
||||
QString oldValue = m_field;
|
||||
m_field = field;
|
||||
update();
|
||||
notify("field",oldValue,field);
|
||||
}
|
||||
}
|
||||
|
||||
QString ImageItem::datasource() const
|
||||
{
|
||||
return m_datasource;
|
||||
}
|
||||
|
||||
void ImageItem::setDatasource(const QString &datasource)
|
||||
{
|
||||
if (m_datasource != datasource){
|
||||
QString oldValue = m_datasource;
|
||||
m_datasource = datasource;
|
||||
update();
|
||||
notify("datasource",oldValue,datasource);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ImageItem::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
ppainter->save();
|
||||
if (isSelected()) ppainter->setOpacity(Const::SELECTION_OPACITY);
|
||||
else ppainter->setOpacity(qreal(opacity())/100);
|
||||
|
||||
QPointF point = rect().topLeft();
|
||||
QImage img;
|
||||
|
||||
if (m_scale && !image().isNull()){
|
||||
img = image().scaled(rect().width(), rect().height(), keepAspectRatio() ? Qt::KeepAspectRatio : Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
} else {
|
||||
img = image();
|
||||
}
|
||||
|
||||
qreal shiftHeight = rect().height() - img.height();
|
||||
qreal shiftWidth = rect().width() - img.width();
|
||||
|
||||
if (m_center){
|
||||
if (shiftHeight<0 || shiftWidth<0){
|
||||
qreal cutX = 0;
|
||||
qreal cutY = 0;
|
||||
qreal cutWidth = img.width();
|
||||
qreal cutHeigth = img.height();
|
||||
|
||||
if (shiftWidth > 0){
|
||||
point.setX(point.x()+shiftWidth/2);
|
||||
} else {
|
||||
cutX = abs(shiftWidth/2);
|
||||
cutWidth += shiftWidth;
|
||||
}
|
||||
|
||||
if (shiftHeight > 0){
|
||||
point.setY(point.x()+shiftHeight/2);
|
||||
} else {
|
||||
cutY = abs(shiftHeight/2);
|
||||
cutHeigth += shiftHeight;
|
||||
}
|
||||
|
||||
img = img.copy(cutX,cutY,cutWidth,cutHeigth);
|
||||
} else {
|
||||
point.setX(point.x()+shiftWidth/2);
|
||||
point.setY(point.y()+shiftHeight/2);
|
||||
}
|
||||
}
|
||||
|
||||
if (img.isNull() && itemMode()==DesignMode){
|
||||
QString text;
|
||||
ppainter->setFont(transformToSceneFont(QFont("Arial",10)));
|
||||
if (!datasource().isEmpty() && !field().isEmpty())
|
||||
text = datasource()+"."+field();
|
||||
else text = tr("Image");
|
||||
ppainter->drawText(rect().adjusted(4,4,-4,-4), Qt::AlignCenter, text );
|
||||
} else {
|
||||
ppainter->drawImage(point,img);
|
||||
}
|
||||
ItemDesignIntf::paint(ppainter,option,widget);
|
||||
ppainter->restore();
|
||||
}
|
||||
|
||||
void ImageItem::setImage(QImage value)
|
||||
{
|
||||
if (m_picture!=value){
|
||||
QImage oldValue = m_picture;
|
||||
m_picture=value;
|
||||
if (m_autoSize){
|
||||
setWidth(m_picture.width());
|
||||
setHeight(m_picture.height());
|
||||
}
|
||||
update();
|
||||
notify("image",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
86
limereport/items/lrimageitem.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRIMAGEITEM_H
|
||||
#define LRIMAGEITEM_H
|
||||
#include "lritemdesignintf.h"
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
class ImageItem : public LimeReport::ItemDesignIntf
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QImage image READ image WRITE setImage)
|
||||
Q_PROPERTY(int opacity READ opacity WRITE setOpacity)
|
||||
Q_PROPERTY(QString datasource READ datasource WRITE setDatasource)
|
||||
Q_PROPERTY(QString field READ field WRITE setField)
|
||||
Q_PROPERTY(bool autoSize READ autoSize WRITE setAutoSize)
|
||||
Q_PROPERTY(bool scale READ scale WRITE setScale)
|
||||
Q_PROPERTY(bool keepAspectRatio READ keepAspectRatio WRITE setKeepAspectRatio)
|
||||
Q_PROPERTY(bool center READ center WRITE setCenter)
|
||||
public:
|
||||
ImageItem(QObject *owner, QGraphicsItem *parent);
|
||||
virtual void paint(QPainter *ppainter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
void setImage(QImage value);
|
||||
QImage image(){return m_picture;}
|
||||
void setContent(const QString &value){m_content=value;}
|
||||
QString datasource() const;
|
||||
void setDatasource(const QString &datasource);
|
||||
QString field() const;
|
||||
void setField(const QString &field);
|
||||
|
||||
bool autoSize() const;
|
||||
void setAutoSize(bool autoSize);
|
||||
bool scale() const;
|
||||
void setScale(bool scale);
|
||||
bool keepAspectRatio() const;
|
||||
void setKeepAspectRatio(bool keepAspectRatio);
|
||||
bool center() const;
|
||||
void setCenter(bool center);
|
||||
|
||||
qreal minHeight() const;
|
||||
|
||||
protected:
|
||||
BaseDesignIntf* createSameTypeItem(QObject *owner, QGraphicsItem *parent);
|
||||
void updateItemSize(DataSourceManager *dataManager, RenderPass pass, int maxHeight);
|
||||
bool isNeedUpdateSize(RenderPass) const;
|
||||
bool drawDesignBorders() const {return m_picture.isNull();}
|
||||
private:
|
||||
QImage m_picture;
|
||||
QString m_content;
|
||||
QString m_datasource;
|
||||
QString m_field;
|
||||
bool m_autoSize;
|
||||
bool m_scale;
|
||||
bool m_keepAspectRatio;
|
||||
bool m_center;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // LRIMAGEITEM_H
|
210
limereport/items/lrshapeitem.cpp
Normal file
@@ -0,0 +1,210 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "lrshapeitem.h"
|
||||
#include "lrdesignelementsfactory.h"
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include <QPainter>
|
||||
|
||||
namespace{
|
||||
|
||||
const QString xmlTag = "ShapeItem";
|
||||
|
||||
LimeReport::BaseDesignIntf * createShapeItem(QObject* owner, LimeReport::BaseDesignIntf* parent){
|
||||
return new LimeReport::ShapeItem(owner,parent);
|
||||
}
|
||||
bool registred = LimeReport::DesignElementsFactory::instance().registerCreator(
|
||||
xmlTag, LimeReport::ItemAttribs(QObject::tr("Shape Item"),"Item"), createShapeItem
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
ShapeItem::ShapeItem(QObject *owner, QGraphicsItem *parent)
|
||||
:ItemDesignIntf(xmlTag,owner,parent),
|
||||
m_shape(HorizontalLine),
|
||||
m_shapeColor(Qt::black),
|
||||
m_shapeBrushColor(Qt::black),
|
||||
m_shapeBrushType(Qt::NoBrush),
|
||||
m_lineWidth(1),
|
||||
m_penStyle(Qt::SolidLine),
|
||||
m_opacity(100),
|
||||
m_cornerRadius(0)
|
||||
{
|
||||
}
|
||||
|
||||
void ShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
painter->save();
|
||||
|
||||
QPen pen(m_shapeColor);
|
||||
pen.setWidthF(m_lineWidth);
|
||||
pen.setStyle(m_penStyle);
|
||||
painter->setPen(pen);
|
||||
QBrush brush(m_shapeBrushColor,m_shapeBrushType);
|
||||
|
||||
painter->setBrush(brush);
|
||||
painter->setBackground(QBrush(Qt::NoBrush));
|
||||
painter->setOpacity(qreal(m_opacity)/100);
|
||||
|
||||
switch (m_shape){
|
||||
case HorizontalLine:
|
||||
painter->drawLine(0,rect().height()/2,rect().right(),rect().height()/2);
|
||||
break;
|
||||
case VerticalLine:
|
||||
painter->drawLine(rect().width()/2,0,rect().width()/2,rect().height());
|
||||
break;
|
||||
case Ellipse:
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
painter->drawEllipse(rect());
|
||||
break;
|
||||
case Rectangle:
|
||||
if (m_cornerRadius!=0){
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
painter->drawRoundedRect(rect(),m_cornerRadius,m_cornerRadius);
|
||||
} else {
|
||||
painter->drawRect(rect());
|
||||
}
|
||||
break;
|
||||
}
|
||||
painter->restore();
|
||||
ItemDesignIntf::paint(painter,option,widget);
|
||||
|
||||
}
|
||||
|
||||
void ShapeItem::setShapeColor(QColor value)
|
||||
{
|
||||
if ((value!=m_shapeColor)){
|
||||
QColor oldValue = m_shapeColor;
|
||||
m_shapeColor=value;
|
||||
update();
|
||||
notify("shapeColor",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
void ShapeItem::setShapeBrushColor(QColor value)
|
||||
{
|
||||
if (value!=m_shapeBrushColor){
|
||||
QColor oldValue = m_shapeBrushColor;
|
||||
m_shapeBrushColor=value;
|
||||
update();
|
||||
notify("shapeBrushColor",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
void ShapeItem::setShapeBrushType(Qt::BrushStyle value)
|
||||
{
|
||||
if (m_shapeBrushType!=value){
|
||||
Qt::BrushStyle oldValue = m_shapeBrushType;
|
||||
m_shapeBrushType=value;
|
||||
update(rect());
|
||||
notify("shapeBrush",QBrush(oldValue),QBrush(value));
|
||||
}
|
||||
}
|
||||
|
||||
void ShapeItem::setShapeType(ShapeItem::ShapeType value)
|
||||
{
|
||||
if (m_shape!=value){
|
||||
ShapeType oldValue = m_shape;
|
||||
m_shape=value;
|
||||
update();
|
||||
notify("shape",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
void ShapeItem::setLineWidth(qreal value)
|
||||
{
|
||||
if (m_lineWidth!=value){
|
||||
qreal oldValue = m_lineWidth;
|
||||
m_lineWidth=value;
|
||||
update();
|
||||
notify("lineWidth",oldValue,value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Qt::PenStyle ShapeItem::penStyle() const
|
||||
{
|
||||
return m_penStyle;
|
||||
}
|
||||
|
||||
void ShapeItem::setPenStyle(const Qt::PenStyle &value)
|
||||
{
|
||||
if (m_penStyle!=value){
|
||||
Qt::PenStyle oldValue = m_penStyle;
|
||||
m_penStyle = value;
|
||||
update();
|
||||
notify("penStyle",(int)oldValue,(int)value);
|
||||
}
|
||||
}
|
||||
|
||||
BaseDesignIntf *ShapeItem::createSameTypeItem(QObject *owner, QGraphicsItem *parent)
|
||||
{
|
||||
return new ShapeItem(owner,parent);
|
||||
}
|
||||
|
||||
int ShapeItem::cornerRadius() const
|
||||
{
|
||||
return m_cornerRadius;
|
||||
}
|
||||
|
||||
void ShapeItem::setCornerRadius(int borderRadius)
|
||||
{
|
||||
if (m_cornerRadius != borderRadius){
|
||||
int oldValue = m_cornerRadius;
|
||||
m_cornerRadius = borderRadius;
|
||||
update();
|
||||
notify("cornerRadius",oldValue,m_cornerRadius);
|
||||
}
|
||||
}
|
||||
int ShapeItem::opacity() const
|
||||
{
|
||||
return m_opacity;
|
||||
}
|
||||
|
||||
void ShapeItem::setOpacity(int opacity)
|
||||
{
|
||||
if (m_opacity!=opacity){
|
||||
if (opacity < 0) {
|
||||
m_opacity = 0;
|
||||
}
|
||||
else if (opacity > 100) {
|
||||
m_opacity = 100;
|
||||
}
|
||||
else {
|
||||
m_opacity = opacity;
|
||||
}
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
84
limereport/items/lrshapeitem.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRSHAPEITEM_H
|
||||
#define LRSHAPEITEM_H
|
||||
#include "lritemdesignintf.h"
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
class ShapeItem: public LimeReport::ItemDesignIntf
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(ShapeType)
|
||||
Q_PROPERTY(ShapeType shape READ shapeType WRITE setShapeType)
|
||||
Q_PROPERTY(QColor shapeColor READ shapeColor WRITE setShapeColor)
|
||||
Q_PROPERTY(QColor shapeBrushColor READ shapeBrushColor WRITE setShapeBrushColor)
|
||||
Q_PROPERTY(Qt::BrushStyle shapeBrush READ shapeBrushType WRITE setShapeBrushType)
|
||||
Q_PROPERTY(qreal lineWidth READ lineWidth WRITE setLineWidth)
|
||||
Q_PROPERTY(Qt::PenStyle penStyle READ penStyle WRITE setPenStyle)
|
||||
Q_PROPERTY(int opacity READ opacity WRITE setOpacity)
|
||||
Q_PROPERTY(int cornerRadius READ cornerRadius WRITE setCornerRadius)
|
||||
public:
|
||||
enum ShapeType{HorizontalLine,VerticalLine,Ellipse,Rectangle};
|
||||
ShapeItem(QObject *owner, QGraphicsItem *parent);
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
void setShapeColor(QColor value);
|
||||
QColor shapeColor() const {return m_shapeColor;}
|
||||
void setShapeBrushColor(QColor value);
|
||||
QColor shapeBrushColor() const {return m_shapeBrushColor;}
|
||||
void setShapeBrushType(Qt::BrushStyle value);
|
||||
Qt::BrushStyle shapeBrushType() const {return m_shapeBrushType;}
|
||||
void setShapeType(ShapeType value);
|
||||
ShapeType shapeType() const {return m_shape;}
|
||||
void setLineWidth(qreal value);
|
||||
qreal lineWidth() const {return m_lineWidth;}
|
||||
Qt::PenStyle penStyle() const;
|
||||
void setPenStyle(const Qt::PenStyle &value);
|
||||
int opacity() const;
|
||||
void setOpacity(int opacity);
|
||||
int cornerRadius() const;
|
||||
void setCornerRadius(int cornerRadius);
|
||||
|
||||
protected:
|
||||
BaseDesignIntf* createSameTypeItem(QObject *owner, QGraphicsItem *parent);
|
||||
bool drawDesignBorders() const {return false;}
|
||||
private:
|
||||
ShapeType m_shape;
|
||||
QColor m_shapeColor;
|
||||
QColor m_shapeBrushColor;
|
||||
Qt::BrushStyle m_shapeBrushType;
|
||||
qreal m_lineWidth;
|
||||
Qt::PenStyle m_penStyle;
|
||||
int m_opacity;
|
||||
int m_cornerRadius;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // LRSHAPEITEM_H
|
239
limereport/items/lrsimpletagparser.cpp
Normal file
@@ -0,0 +1,239 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "lrsimpletagparser.h"
|
||||
#include <QRegExp>
|
||||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
void HtmlContext::fillTagVector(QString html)
|
||||
{
|
||||
QRegExp rx("<[^<]*>");
|
||||
QString buff=html;
|
||||
int curPos=0;
|
||||
while(buff.contains(rx)){
|
||||
int pos=rx.indexIn(buff);
|
||||
curPos+=pos;
|
||||
buff=buff.right(buff.length()-pos);
|
||||
if (rx.cap().at(1)!='/'){
|
||||
int initPos=curPos;
|
||||
parseTag(m_tags,buff,initPos);
|
||||
}
|
||||
buff=buff.right(buff.length()-rx.matchedLength());
|
||||
}
|
||||
}
|
||||
|
||||
QString HtmlContext::parseTag(QVector<Tag *> &storage, QString text, int &curPos, bool createTag)
|
||||
{
|
||||
QRegExp rx("<[^<]*>");
|
||||
int pos=rx.indexIn(text);
|
||||
int begPos=pos+curPos;
|
||||
QString buff=text.right(text.length()-(pos+rx.matchedLength()));
|
||||
|
||||
QString tagName=rx.cap(0);
|
||||
tagName.remove('<');
|
||||
tagName.remove('>');
|
||||
|
||||
while (buff.contains(rx)){
|
||||
int pos=rx.indexIn(buff);
|
||||
buff=buff.right(buff.length()-pos);
|
||||
curPos+=pos;
|
||||
if (extractWord(rx.cap(0),1).compare(extractWord(tagName,1),Qt::CaseInsensitive)==0){
|
||||
if (rx.cap(0).at(1)=='/'){
|
||||
if (createTag) storage.append(new Tag(tagName,begPos,curPos));
|
||||
return buff.right(buff.length()-rx.matchedLength());
|
||||
} else {
|
||||
buff=parseTag(storage,buff,curPos,false);
|
||||
|
||||
}
|
||||
} else {
|
||||
buff=buff.right(buff.length()-rx.matchedLength());
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void HtmlContext::parseSymbs(QString text)
|
||||
{
|
||||
|
||||
QRegExp rx("<[^<]*[^/]>");
|
||||
while (text.contains(rx)){
|
||||
int pos=rx.indexIn(text);
|
||||
if (rx.cap().compare("<br>",Qt::CaseInsensitive)==0)
|
||||
m_symbs.append(new Symb(rx.cap(),pos));
|
||||
text.remove(pos,rx.matchedLength());
|
||||
}
|
||||
|
||||
foreach(QString pattern,m_symbPatterns){
|
||||
rx.setPattern(pattern);
|
||||
while (text.contains(rx)){
|
||||
int pos=rx.indexIn(text);
|
||||
m_symbs.append(new Symb(rx.cap(0),pos));
|
||||
text.replace(rx.cap(0)," ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HtmlContext::initSymbPatterns()
|
||||
{
|
||||
m_symbPatterns<<"&[^&]*;"<<"<[^<]*/>";
|
||||
}
|
||||
|
||||
HtmlContext::HtmlContext(QString html)
|
||||
{
|
||||
fillTagVector(html);
|
||||
parseSymbs(html);
|
||||
initSymbPatterns();
|
||||
}
|
||||
|
||||
HtmlContext::~HtmlContext()
|
||||
{
|
||||
clearTags();
|
||||
clearSymbs();
|
||||
}
|
||||
|
||||
QString HtmlContext::extractWord(QString text, int index)
|
||||
{
|
||||
text.remove('<');
|
||||
text.remove('>');
|
||||
text.remove('/');
|
||||
int counter=1;
|
||||
QString retWord("");
|
||||
for (int i=0;i<text.length();i++){
|
||||
if (text.at(i)==' '){
|
||||
if (counter==index) {return retWord;}
|
||||
else {retWord="";counter++;}
|
||||
}
|
||||
retWord+=text.at(i);
|
||||
}
|
||||
if (counter==index) return retWord;
|
||||
else return "";
|
||||
}
|
||||
|
||||
QVector<TagDiff> HtmlContext::tagVectDiff(QVector<Tag *> source, QVector<Tag *> dest)
|
||||
{
|
||||
QVector<TagDiff> resVect;
|
||||
for(int i=0;i<source.count();++i){
|
||||
if (!dest.contains(source.at(i))){
|
||||
TagDiff tagDiff;
|
||||
tagDiff.tag=source.at(i);
|
||||
tagDiff.direction=TagDiff::Outer;
|
||||
resVect.append(tagDiff);
|
||||
}
|
||||
}
|
||||
for(int i=0;i<dest.count();++i){
|
||||
if (!source.contains(dest.at(i))){
|
||||
TagDiff tagDiff;
|
||||
tagDiff.tag=dest.at(i);
|
||||
tagDiff.direction=TagDiff::Inner;
|
||||
resVect.append(tagDiff);
|
||||
}
|
||||
}
|
||||
return resVect;
|
||||
}
|
||||
|
||||
bool HtmlContext::isVectorEqual(QVector<Tag *> source, QVector<Tag *> dest)
|
||||
{
|
||||
if (source.count()!=dest.count()) return false;
|
||||
foreach(Tag* tag,source){
|
||||
if (!dest.contains(tag)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QString HtmlContext::extendTextByTags(QString text, int pos)
|
||||
{
|
||||
QString curText="";
|
||||
QVector<Tag*> curTags=tagsAt(pos);
|
||||
for(int i=0;i<curTags.count();i++){
|
||||
curText+='<'+curTags.at(i)->tagText()+'>';
|
||||
}
|
||||
|
||||
for(int i=0;i<text.length();i++,pos++){
|
||||
QVector<Tag*> tagsAtPos=tagsAt(pos);
|
||||
if (!HtmlContext::isVectorEqual(curTags,tagsAtPos)){
|
||||
QVector<TagDiff> diffs=HtmlContext::tagVectDiff(curTags,tagsAtPos);
|
||||
foreach(TagDiff diff,diffs){
|
||||
if (diff.direction==TagDiff::Inner){
|
||||
curText+='<'+diff.tag->tagText()+'>';
|
||||
curTags.append(diff.tag);
|
||||
}
|
||||
else{
|
||||
curText+="</"+HtmlContext::extractWord(diff.tag->tagText(),1)+'>';
|
||||
curTags.remove(curTags.indexOf(diff.tag));
|
||||
}
|
||||
}
|
||||
}
|
||||
Symb s=symbAt(pos);
|
||||
if (s.isValid()){
|
||||
if (s.isTag()) curText+=s.text()+text.at(i);
|
||||
else curText+=s.text();
|
||||
} else curText+=text.at(i);
|
||||
}
|
||||
|
||||
curTags=tagsAt(pos);
|
||||
for(int i=0;i<curTags.count();i++){
|
||||
curText+="</"+HtmlContext::extractWord(curTags.at(i)->tagText(),1)+'>';
|
||||
}
|
||||
|
||||
return curText;
|
||||
}
|
||||
|
||||
QVector<Tag *> HtmlContext::tagsAt(int pos)
|
||||
{
|
||||
QVector<Tag*> result;
|
||||
foreach(Tag* tag,m_tags){
|
||||
if ((pos>=tag->begin())&&(pos<=tag->end())) result.append(tag);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Symb HtmlContext::symbAt(int pos)
|
||||
{
|
||||
foreach(Symb* symb,m_symbs){
|
||||
if (pos==symb->pos()) return *symb;
|
||||
}
|
||||
return Symb();
|
||||
}
|
||||
|
||||
void HtmlContext::clearTags()
|
||||
{
|
||||
foreach(Tag* tag,m_tags) delete tag;
|
||||
m_tags.clear();
|
||||
}
|
||||
|
||||
void HtmlContext::clearSymbs()
|
||||
{
|
||||
foreach(Symb* symb,m_symbs) delete symb;
|
||||
m_tags.clear();
|
||||
}
|
||||
|
||||
}
|
100
limereport/items/lrsimpletagparser.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRSIMPLETAGPARSER_H
|
||||
#define LRSIMPLETAGPARSER_H
|
||||
|
||||
#include <QVector>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
class Tag{
|
||||
public:
|
||||
Tag(QString text,int beginPos,int endPos)
|
||||
:m_tagText(text),m_beginPos(beginPos),m_endPos(endPos){}
|
||||
Tag():m_tagText(""),m_beginPos(-1),m_endPos(-1){}
|
||||
bool isValid(){return (!m_tagText.isEmpty())&&(m_beginPos>0)&&(m_endPos>0);}
|
||||
QString tagText() const {return m_tagText;}
|
||||
int begin() const {return m_beginPos;}
|
||||
int end() const {return m_endPos;}
|
||||
private:
|
||||
QString m_tagText;
|
||||
int m_beginPos;
|
||||
int m_endPos;
|
||||
};
|
||||
|
||||
class Symb{
|
||||
public:
|
||||
Symb(QString text, int pos):m_text(text),m_pos(pos){}
|
||||
Symb():m_text(""),m_pos(-1){}
|
||||
bool isValid(){return (!m_text.isEmpty())&&(m_pos>0);}
|
||||
bool isTag(){return isValid()&&m_text.at(0)=='<';}
|
||||
QString text(){return m_text;}
|
||||
int pos(){return m_pos;}
|
||||
private:
|
||||
QString m_text;
|
||||
int m_pos;
|
||||
};
|
||||
|
||||
struct TagDiff{
|
||||
enum Direction {
|
||||
Inner=0,
|
||||
Outer=1
|
||||
};
|
||||
Tag* tag;
|
||||
Direction direction;
|
||||
};
|
||||
|
||||
class HtmlContext
|
||||
{
|
||||
public:
|
||||
HtmlContext(QString html);
|
||||
~HtmlContext();
|
||||
static QString extractWord(QString text,int index);
|
||||
static QVector<TagDiff> tagVectDiff(QVector<Tag*> source, QVector<Tag*> dest);
|
||||
static bool isVectorEqual(QVector<Tag*> source, QVector<Tag*> dest);
|
||||
void fillTagVector(QString html);
|
||||
QString extendTextByTags(QString text, int pos);
|
||||
QVector<Tag *> tagsAt(int pos);
|
||||
Symb symbAt(int pos);
|
||||
void clearTags();
|
||||
void clearSymbs();
|
||||
private:
|
||||
static QString parseTag(QVector<Tag*>& storage,QString text,int& curPos, bool createTag=true);
|
||||
void parseSymbs(QString text);
|
||||
void initSymbPatterns();
|
||||
private:
|
||||
QVector<Tag*> m_tags;
|
||||
QVector<Symb*> m_symbs;
|
||||
QStringList m_symbPatterns;
|
||||
};
|
||||
}
|
||||
#endif // LRSIMPLETAGPARSER_H
|
97
limereport/items/lrsubitemparentpropitem.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "lrsubitemparentpropitem.h"
|
||||
#include "../objectinspector/editors/lrcomboboxeditor.h"
|
||||
#include "lrbasedesignintf.h"
|
||||
#include "lritemdesignintf.h"
|
||||
#include "lrpagedesignintf.h"
|
||||
#include "lrobjectpropitem.h"
|
||||
|
||||
|
||||
namespace{
|
||||
LimeReport::ObjectPropItem * createLocationPropItem(
|
||||
QObject *object, LimeReport::ObjectPropItem::ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& data, LimeReport::ObjectPropItem* parent, bool readonly)
|
||||
{
|
||||
return new LimeReport::ItemLocationPropItem(object, objects, name, displayName, data, parent, readonly);
|
||||
}
|
||||
bool registred = LimeReport::ObjectPropFactory::instance().registerCreator(
|
||||
LimeReport::APropIdent("itemLocation","LimeReport::ItemDesignIntf"),QObject::tr("itemLocation"),createLocationPropItem
|
||||
);
|
||||
}
|
||||
|
||||
LimeReport::ItemLocationPropItem::ItemLocationPropItem(QObject* object, ObjectsList* objects, const QString &name, const QString &displayName, const QVariant &value, ObjectPropItem* parent, bool readonly)
|
||||
:LimeReport::ObjectPropItem(object, objects, name, displayName, value, parent, readonly){
|
||||
m_locationMap.insert("Band",LimeReport::ItemDesignIntf::Band);
|
||||
m_locationMap.insert("Page",LimeReport::ItemDesignIntf::Page);
|
||||
}
|
||||
|
||||
|
||||
QWidget * LimeReport::ItemLocationPropItem::createProperyEditor(QWidget *parent) const{
|
||||
ComboBoxEditor *editor = new ComboBoxEditor(parent);
|
||||
connect(editor,SIGNAL(currentIndexChanged(QString)),this,SLOT(slotLocationChanged(QString)));
|
||||
LimeReport::BaseDesignIntf *item=dynamic_cast<LimeReport::BaseDesignIntf*>(object());
|
||||
if (item){
|
||||
QStringList locationTypes;
|
||||
foreach(QString location,m_locationMap.keys()){
|
||||
locationTypes.append(location);
|
||||
}
|
||||
editor->addItems(locationTypes);
|
||||
}
|
||||
return editor;
|
||||
}
|
||||
|
||||
QString LimeReport::ItemLocationPropItem::displayValue() const{
|
||||
return locationToString(static_cast<LimeReport::ItemDesignIntf::LocationType>(propertyValue().toInt()));
|
||||
}
|
||||
|
||||
void LimeReport::ItemLocationPropItem::setPropertyEditorData(QWidget *propertyEditor, const QModelIndex &) const{
|
||||
ComboBoxEditor *editor=qobject_cast<ComboBoxEditor *>(propertyEditor);
|
||||
editor->setTextValue(locationToString(propertyValue().toInt()));
|
||||
}
|
||||
|
||||
void LimeReport::ItemLocationPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index){
|
||||
object()->setProperty(propertyName().toLatin1(),stringToLocation(qobject_cast<ComboBoxEditor*>(propertyEditor)->text()));
|
||||
model->setData(index,object()->property(propertyName().toLatin1()));
|
||||
}
|
||||
|
||||
QString LimeReport::ItemLocationPropItem::locationToString(LimeReport::ItemDesignIntf::LocationType location) const{
|
||||
return m_locationMap.key(location);
|
||||
}
|
||||
|
||||
LimeReport::ItemDesignIntf::LocationType LimeReport::ItemLocationPropItem::stringToLocation(const QString &locationName){
|
||||
return m_locationMap.value(locationName);
|
||||
}
|
||||
|
||||
void LimeReport::ItemLocationPropItem::slotLocationChanged(const QString &text){
|
||||
if ( locationToString(object()->property(propertyName().toLatin1()).toInt())!=text){
|
||||
object()->setProperty(propertyName().toLatin1(),stringToLocation(text));
|
||||
dynamic_cast<ComboBoxEditor*>(sender())->setTextValue(locationToString(object()->property(propertyName().toLatin1()).toInt()));
|
||||
}
|
||||
}
|
58
limereport/items/lrsubitemparentpropitem.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRSUBITEMPARENTPROPITEM_H
|
||||
#define LRSUBITEMPARENTPROPITEM_H
|
||||
|
||||
#include <QMap>
|
||||
|
||||
#include "lrobjectpropitem.h"
|
||||
#include "lritemdesignintf.h"
|
||||
|
||||
namespace LimeReport{
|
||||
class ItemLocationPropItem : public LimeReport::ObjectPropItem{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ItemLocationPropItem():ObjectPropItem(){}
|
||||
ItemLocationPropItem(QObject* object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value, ObjectPropItem* parent, bool readonly);
|
||||
QWidget* createProperyEditor(QWidget *parent) const;
|
||||
QString displayValue() const;
|
||||
void setPropertyEditorData(QWidget *, const QModelIndex &) const;
|
||||
void setModelData(QWidget *, QAbstractItemModel *, const QModelIndex &);
|
||||
private slots:
|
||||
void slotLocationChanged(const QString& text);
|
||||
private:
|
||||
QString locationToString(LimeReport::ItemDesignIntf::LocationType location) const;
|
||||
QString locationToString(int location) const {return locationToString(static_cast<LimeReport::ItemDesignIntf::LocationType>(location));}
|
||||
LimeReport::ItemDesignIntf::LocationType stringToLocation(const QString& locationName);
|
||||
private:
|
||||
QMap<QString,LimeReport::ItemDesignIntf::LocationType> m_locationMap;
|
||||
};
|
||||
}
|
||||
#endif // LRSUBITEMPARENTPROPITEM_H
|
552
limereport/items/lrtextitem.cpp
Normal file
@@ -0,0 +1,552 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include <QtGui>
|
||||
#include <QTextLayout>
|
||||
#include <QScriptEngine>
|
||||
#include <math.h>
|
||||
|
||||
#include "lrpagedesignintf.h"
|
||||
#include "lrtextitem.h"
|
||||
#include "lrdesignelementsfactory.h"
|
||||
#include "lrglobal.h"
|
||||
#include "lrdatasourcemanager.h"
|
||||
#include "lrsimpletagparser.h"
|
||||
#include "lrtextitemeditor.h"
|
||||
#include "lrreportengine_p.h"
|
||||
|
||||
namespace{
|
||||
|
||||
const QString xmlTag = "TextItem";
|
||||
|
||||
LimeReport::BaseDesignIntf * createTextItem(QObject* owner, LimeReport::BaseDesignIntf* parent){
|
||||
return new LimeReport::TextItem(owner,parent);
|
||||
}
|
||||
bool registred = LimeReport::DesignElementsFactory::instance().registerCreator(xmlTag, LimeReport::ItemAttribs(QObject::tr("Text Item"),"TextItem"), createTextItem);
|
||||
|
||||
}
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
TextItem::TextItem(QObject *owner, QGraphicsItem *parent)
|
||||
: ContentItemDesignIntf(xmlTag,owner,parent), m_angle(Angle0), m_trimValue(true), m_allowHTML(false){
|
||||
m_text = new QTextDocument();
|
||||
Init();
|
||||
}
|
||||
|
||||
TextItem::~TextItem()
|
||||
{
|
||||
delete m_text;
|
||||
}
|
||||
|
||||
int TextItem::fakeMarginSize(){
|
||||
return marginSize()+5;
|
||||
}
|
||||
|
||||
void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, QWidget* widget) {
|
||||
Q_UNUSED(widget);
|
||||
Q_UNUSED(style);
|
||||
|
||||
painter->save();
|
||||
|
||||
setupPainter(painter);
|
||||
prepareRect(painter,style,widget);
|
||||
|
||||
QSizeF tmpSize = rect().size()-m_textSize;
|
||||
|
||||
if (!painter->clipRegion().isEmpty()){
|
||||
QRegion clipReg=painter->clipRegion().xored(painter->clipRegion().subtracted(rect().toRect()));
|
||||
painter->setClipRegion(clipReg);
|
||||
} else {
|
||||
painter->setClipRect(rect());
|
||||
}
|
||||
|
||||
qreal hOffset = 0, vOffset=0;
|
||||
switch (m_angle){
|
||||
case Angle0:
|
||||
hOffset = fakeMarginSize();
|
||||
if ((tmpSize.height()>0) && (m_alignment & Qt::AlignVCenter)){
|
||||
vOffset = tmpSize.height()/2;
|
||||
}
|
||||
if ((tmpSize.height()>0) && (m_alignment & Qt::AlignBottom)) // allow html
|
||||
vOffset = tmpSize.height();
|
||||
painter->translate(hOffset,vOffset);
|
||||
break;
|
||||
case Angle90:
|
||||
hOffset = width()-fakeMarginSize();
|
||||
vOffset = fakeMarginSize();
|
||||
if ((tmpSize.width()>0) && (m_alignment & Qt::AlignVCenter)){
|
||||
hOffset = (width()-m_text->size().height())/2+m_text->size().height();
|
||||
}
|
||||
|
||||
if ((tmpSize.height()>0) && (m_alignment & Qt::AlignBottom)){
|
||||
hOffset = (m_text->size().height());
|
||||
}
|
||||
painter->translate(hOffset,vOffset);
|
||||
painter->rotate(90);
|
||||
break;
|
||||
case Angle180:
|
||||
hOffset = width()-fakeMarginSize();
|
||||
vOffset = height()-fakeMarginSize();
|
||||
if ((tmpSize.width()>0) && (m_alignment & Qt::AlignVCenter)){
|
||||
vOffset = tmpSize.height()/2+m_text->size().height();
|
||||
}
|
||||
if ((tmpSize.height()>0) && (m_alignment & Qt::AlignBottom)){
|
||||
vOffset = (m_text->size().height());
|
||||
}
|
||||
painter->translate(hOffset,vOffset);
|
||||
painter->rotate(180);
|
||||
break;
|
||||
case Angle270:
|
||||
hOffset = fakeMarginSize();
|
||||
vOffset = height()-fakeMarginSize();
|
||||
if ((tmpSize.width()>0) && (m_alignment & Qt::AlignVCenter)){
|
||||
hOffset = (width()-m_text->size().height())/2;
|
||||
}
|
||||
|
||||
if ((tmpSize.height()>0) && (m_alignment & Qt::AlignBottom)){
|
||||
hOffset = (width()-m_text->size().height());
|
||||
}
|
||||
painter->translate(hOffset,vOffset);
|
||||
painter->rotate(270);
|
||||
break;
|
||||
case Angle45:
|
||||
painter->translate(width()/2,0);
|
||||
painter->rotate(45);
|
||||
m_text->setTextWidth(sqrt(2*(pow(width()/2,2))));
|
||||
break;
|
||||
case Angle315:
|
||||
painter->translate(0,height()/2);
|
||||
painter->rotate(315);
|
||||
m_text->setTextWidth(sqrt(2*(pow(height()/2,2))));
|
||||
break;
|
||||
}
|
||||
|
||||
// for(QTextBlock it=m_text->begin();it!=m_text->end();it=it.next()){
|
||||
// for (int i=0;i<it.layout()->lineCount();i++){
|
||||
// painter->setOpacity(qreal(foregroundOpacity())/100);
|
||||
// it.layout()->lineAt(i).draw(painter,QPointF(0,0));
|
||||
// }
|
||||
// }
|
||||
|
||||
painter->setOpacity(qreal(foregroundOpacity())/100);
|
||||
|
||||
//m_text->setDefaultTextOption();
|
||||
QAbstractTextDocumentLayout::PaintContext ctx;
|
||||
ctx.palette.setColor(QPalette::Text, fontColor());
|
||||
m_text->documentLayout()->draw(painter,ctx);
|
||||
|
||||
// m_layout.draw(ppainter,QPointF(marginSize(),0),);
|
||||
// ppainter->setFont(transformToSceneFont(font()));
|
||||
// QTextOption o;
|
||||
// o.setAlignment(alignment());
|
||||
// ppainter->drawText(rect(), content(), o);
|
||||
|
||||
painter->restore();
|
||||
BaseDesignIntf::paint(painter, style, widget);
|
||||
}
|
||||
|
||||
QString TextItem::content() const{
|
||||
return m_strText;
|
||||
}
|
||||
|
||||
void TextItem::Init()
|
||||
{
|
||||
m_autoWidth=NoneAutoWidth;
|
||||
m_alignment= Qt::AlignLeft|Qt::AlignTop;
|
||||
m_autoHeight=false;
|
||||
// m_text->setDefaultFont(transformToSceneFont(font()));
|
||||
m_textSize=QSizeF();
|
||||
m_foregroundOpacity = 100;
|
||||
}
|
||||
|
||||
void TextItem::setContent(const QString &value)
|
||||
{
|
||||
if (m_strText.compare(value)!=0){
|
||||
QString oldValue = m_strText;
|
||||
m_strText=value;
|
||||
if (allowHTML())
|
||||
m_text->setHtml(replaceReturns(value.trimmed()));
|
||||
else
|
||||
m_text->setPlainText(value);
|
||||
//m_text->setTextWidth(width());
|
||||
//m_textSize=m_text->size();
|
||||
if (itemMode() == DesignMode){
|
||||
initText();
|
||||
}
|
||||
|
||||
if (!isLoading()){
|
||||
update(rect());
|
||||
notify("content",oldValue,value);
|
||||
//updateLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight)
|
||||
{
|
||||
if (isNeedExpandContent())
|
||||
expandContent(dataManager, pass);
|
||||
if (!isLoading())
|
||||
initText();
|
||||
|
||||
if (m_textSize.width()>width() && ((m_autoWidth==MaxWordLength)||(m_autoWidth==MaxStringLength))){
|
||||
setWidth(m_textSize.width() + fakeMarginSize()*2);
|
||||
}
|
||||
|
||||
if ((m_textSize.height()>height()) && (m_autoHeight) ){
|
||||
setHeight(m_textSize.height()+5);
|
||||
}
|
||||
BaseDesignIntf::updateItemSize(dataManager, pass, maxHeight);
|
||||
}
|
||||
|
||||
void TextItem::updateLayout()
|
||||
{
|
||||
// m_layout.setFont(transformToSceneFont(font()));
|
||||
// m_layout.setText(content());
|
||||
// qreal linePos = 0;
|
||||
// m_layout.beginLayout();
|
||||
// while(true){
|
||||
// QTextLine line = m_layout.createLine();
|
||||
// if (!line.isValid()) break;
|
||||
// line.setLineWidth(width()-marginSize()*2);
|
||||
// line.setPosition(QPoint(marginSize(),linePos));
|
||||
// linePos+=line.height();
|
||||
// }
|
||||
// m_layout.endLayout();
|
||||
}
|
||||
|
||||
bool TextItem::isNeedExpandContent() const
|
||||
{
|
||||
QRegExp rx("$*\\{[^{]*\\}");
|
||||
return content().contains(rx);
|
||||
}
|
||||
|
||||
QString TextItem::replaceBR(QString text)
|
||||
{
|
||||
return text.replace("<br/>","\n");
|
||||
}
|
||||
|
||||
QString TextItem::replaceReturns(QString text)
|
||||
{
|
||||
QString result = text.replace("\r\n","<br/>");
|
||||
result = result.replace("\n","<br/>");
|
||||
return result;
|
||||
}
|
||||
|
||||
void TextItem::initText()
|
||||
{
|
||||
QTextOption to;
|
||||
to.setAlignment(m_alignment);
|
||||
|
||||
if (m_autoWidth!=MaxStringLength)
|
||||
to.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
|
||||
else to.setWrapMode(QTextOption::NoWrap);
|
||||
|
||||
m_text->setDocumentMargin(0);
|
||||
m_text->setDefaultTextOption(to);
|
||||
m_text->setDefaultFont(transformToSceneFont(font()));
|
||||
if ((m_angle==Angle0)||(m_angle==Angle180)){
|
||||
m_text->setTextWidth(rect().width()-fakeMarginSize()*2);
|
||||
} else {
|
||||
m_text->setTextWidth(rect().height()-fakeMarginSize()*2);
|
||||
}
|
||||
m_textSize=m_text->size();
|
||||
}
|
||||
|
||||
bool TextItem::allowHTML() const
|
||||
{
|
||||
return m_allowHTML;
|
||||
}
|
||||
|
||||
void TextItem::setAllowHTML(bool allowHTML)
|
||||
{
|
||||
if (m_allowHTML!=allowHTML){
|
||||
m_allowHTML = allowHTML;
|
||||
if (m_text){
|
||||
if (allowHTML)
|
||||
m_text->setHtml(m_strText);
|
||||
else
|
||||
m_text->setPlainText(m_strText);
|
||||
update();
|
||||
}
|
||||
notify("allowHTML",!m_allowHTML,allowHTML);
|
||||
}
|
||||
}
|
||||
bool TextItem::trimValue() const
|
||||
{
|
||||
return m_trimValue;
|
||||
}
|
||||
|
||||
void TextItem::setTrimValue(bool trimValue)
|
||||
{
|
||||
m_trimValue = trimValue;
|
||||
}
|
||||
|
||||
|
||||
void TextItem::geometryChangedEvent(QRectF , QRectF)
|
||||
{
|
||||
// if ((m_angle==Angle0)||(m_angle==Angle180)){
|
||||
// m_text->setTextWidth(rect().width()-fakeMarginSize()*2);
|
||||
// } else {
|
||||
// m_text->setTextWidth(rect().height()-fakeMarginSize()*2);
|
||||
// }
|
||||
// m_textSize=m_text->size();
|
||||
if (itemMode() == DesignMode) initText();
|
||||
}
|
||||
|
||||
bool TextItem::isNeedUpdateSize(RenderPass pass) const
|
||||
{
|
||||
Q_UNUSED(pass)
|
||||
bool res = (m_textSize.height()>geometry().height()&&autoHeight()) ||
|
||||
(m_textSize.width()>geometry().width()&&autoWidth()) ||
|
||||
isNeedExpandContent();
|
||||
return res;
|
||||
}
|
||||
|
||||
void TextItem::setAlignment(Qt::Alignment value)
|
||||
{
|
||||
if (m_alignment!=value){
|
||||
Qt::Alignment oldValue = m_alignment;
|
||||
m_alignment=value;
|
||||
//m_layout.setTextOption(QTextOption(m_alignment));
|
||||
if (!isLoading()){
|
||||
initText();
|
||||
update(rect());
|
||||
notify("alignment",QVariant(oldValue),QVariant(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextItem::expandContent(DataSourceManager* dataManager, RenderPass pass)
|
||||
{
|
||||
QString context=content();
|
||||
ExpandType expandType = allowHTML()?ReplaceHTMLSymbols:NoEscapeSymbols;
|
||||
switch(pass){
|
||||
case FirstPass:
|
||||
context=expandUserVariables(context, pass, expandType, dataManager);
|
||||
context=expandScripts(context, dataManager);
|
||||
context=expandDataFields(context, expandType, dataManager);
|
||||
break;
|
||||
case SecondPass:;
|
||||
context=expandUserVariables(context, pass, expandType, dataManager);
|
||||
context=expandScripts(context, dataManager);
|
||||
}
|
||||
setContent(context);
|
||||
}
|
||||
|
||||
void TextItem::setAutoHeight(bool value)
|
||||
{
|
||||
if (m_autoHeight!=value){
|
||||
bool oldValue = m_autoHeight;
|
||||
m_autoHeight=value;
|
||||
notify("autoHeight",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
void TextItem::setAutoWidth(TextItem::AutoWidth value)
|
||||
{
|
||||
if (m_autoWidth!=value){
|
||||
TextItem::AutoWidth oldValue = m_autoWidth;
|
||||
m_autoWidth=value;
|
||||
notify("autoWidth",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
bool TextItem::canBeSplitted(int height) const
|
||||
{
|
||||
return height>(m_text->begin().layout()->lineAt(0).height());
|
||||
}
|
||||
|
||||
BaseDesignIntf *TextItem::cloneUpperPart(int height, QObject *owner, QGraphicsItem *parent)
|
||||
{
|
||||
int linesHeight=0;
|
||||
initText();
|
||||
QString tmpText="";
|
||||
TextItem* upperPart = dynamic_cast<TextItem*>(cloneItem(itemMode(),owner,parent));
|
||||
|
||||
for (QTextBlock it=m_text->begin();it!=m_text->end();it=it.next()){
|
||||
for (int i=0;i<it.layout()->lineCount();i++){
|
||||
linesHeight+=it.layout()->lineAt(i).height();
|
||||
if (linesHeight>(height-(fakeMarginSize()*2+borderLineSize()*2))) {linesHeight-=it.layout()->lineAt(i).height(); goto loop_exit;}
|
||||
tmpText+=it.text().mid(it.layout()->lineAt(i).textStart(),it.layout()->lineAt(i).textLength())+'\n';
|
||||
}
|
||||
}
|
||||
loop_exit:
|
||||
upperPart->setHeight(linesHeight+fakeMarginSize()*2+borderLineSize()*2);
|
||||
QScopedPointer<HtmlContext> context(new HtmlContext(m_strText));
|
||||
upperPart->setContent(context->extendTextByTags(tmpText,0));
|
||||
return upperPart;
|
||||
}
|
||||
|
||||
BaseDesignIntf *TextItem::cloneBottomPart(int height, QObject *owner, QGraphicsItem *parent)
|
||||
{
|
||||
TextItem* bottomPart = dynamic_cast<TextItem*>(cloneItem(itemMode(),owner,parent));
|
||||
int linesHeight=0;
|
||||
int curLine=0;
|
||||
QTextBlock curBlock;
|
||||
|
||||
QString tmpText="";
|
||||
|
||||
for (curBlock=m_text->begin();curBlock!=m_text->end();curBlock=curBlock.next()){
|
||||
for (curLine=0;curLine<curBlock.layout()->lineCount();curLine++){
|
||||
linesHeight+=curBlock.layout()->lineAt(curLine).height();
|
||||
if (linesHeight>(height-(fakeMarginSize()*2+borderLineSize()*2))) {goto loop_exit;}
|
||||
}
|
||||
}
|
||||
loop_exit:;
|
||||
int textPos=0;
|
||||
for (;curBlock!=m_text->end();curBlock=curBlock.next()){
|
||||
for (;curLine<curBlock.layout()->lineCount();curLine++){
|
||||
if (tmpText=="") textPos= curBlock.layout()->lineAt(curLine).textStart();
|
||||
tmpText+=curBlock.text().mid(curBlock.layout()->lineAt(curLine).textStart(),
|
||||
curBlock.layout()->lineAt(curLine).textLength())+"\n";
|
||||
}
|
||||
}
|
||||
|
||||
QScopedPointer<HtmlContext> context(new HtmlContext(m_strText));
|
||||
bottomPart->setContent(context->extendTextByTags(tmpText,textPos));
|
||||
bottomPart->setHeight(bottomPart->m_textSize.height()+borderLineSize()*2);
|
||||
return bottomPart;
|
||||
}
|
||||
|
||||
BaseDesignIntf *TextItem::createSameTypeItem(QObject *owner, QGraphicsItem *parent)
|
||||
{
|
||||
return new TextItem(owner,parent);
|
||||
}
|
||||
|
||||
BaseDesignIntf *TextItem::cloneEmpty(int height, QObject *owner, QGraphicsItem *parent)
|
||||
{
|
||||
TextItem* empty=dynamic_cast<TextItem*>(cloneItem(itemMode(),owner,parent));
|
||||
empty->setContent("");
|
||||
empty->setHeight(height);
|
||||
return empty;
|
||||
}
|
||||
|
||||
void TextItem::objectLoadFinished()
|
||||
{
|
||||
ItemDesignIntf::objectLoadFinished();
|
||||
if (itemMode() == DesignMode || !isNeedExpandContent()){
|
||||
initText();
|
||||
}
|
||||
}
|
||||
|
||||
void TextItem::setTextItemFont(QFont value)
|
||||
{
|
||||
if (font()!=value){
|
||||
QFont oldValue = font();
|
||||
setFont(value);
|
||||
m_text->setDefaultFont(transformToSceneFont(value));
|
||||
notify("font",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
QWidget *TextItem::defaultEditor()
|
||||
{
|
||||
QSettings* l_settings = (page()->settings() != 0) ?
|
||||
page()->settings() :
|
||||
(page()->reportEditor()!=0) ? page()->reportEditor()->settings() : 0;
|
||||
QWidget* editor = new TextItemEditor(this,page(),l_settings);
|
||||
editor->setAttribute(Qt::WA_DeleteOnClose);
|
||||
return editor;
|
||||
}
|
||||
|
||||
void TextItem::setBackgroundOpacity(int value)
|
||||
{
|
||||
if (opacity()!=value){
|
||||
int oldValue = opacity();
|
||||
setOpacity(value);
|
||||
notify("backgroundOpacity",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
void TextItem::setBackgroundModeProperty(BaseDesignIntf::BGMode value)
|
||||
{
|
||||
if (value!=backgroundMode()){
|
||||
BaseDesignIntf::BGMode oldValue = backgroundMode();
|
||||
setBackgroundMode(value);
|
||||
notify("backgroundMode",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
void TextItem::setBackgroundColorProperty(QColor value)
|
||||
{
|
||||
if(value!=backgroundColor()){
|
||||
QColor oldValue = backgroundColor();
|
||||
setBackgroundColor(value);
|
||||
notify("backgroundColor",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
void TextItem::setFontColorProperty(QColor value)
|
||||
{
|
||||
if(value!=fontColor()){
|
||||
QColor oldValue = fontColor();
|
||||
setFontColor(value);
|
||||
notify("fontColor",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
TextItem::AngleType TextItem::angle() const
|
||||
{
|
||||
return m_angle;
|
||||
}
|
||||
|
||||
void TextItem::setAngle(const AngleType& value)
|
||||
{
|
||||
if (m_angle!=value){
|
||||
AngleType oldValue = m_angle;
|
||||
m_angle = value;
|
||||
if (!isLoading()){
|
||||
initText();
|
||||
update();
|
||||
notify("angle",oldValue,value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextItem::setForegroundOpacity(int value)
|
||||
{
|
||||
if (value>100){
|
||||
value=100;
|
||||
} else if(value<0){
|
||||
value=0;
|
||||
}
|
||||
if (m_foregroundOpacity != value){
|
||||
int oldValue = m_foregroundOpacity;
|
||||
m_foregroundOpacity = value;
|
||||
update();
|
||||
notify("foregroundOpacity",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace LimeReport
|
||||
|
||||
|
||||
|
141
limereport/items/lrtextitem.h
Normal file
@@ -0,0 +1,141 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRTEXTITEM_H
|
||||
#define LRTEXTITEM_H
|
||||
#include <QGraphicsTextItem>
|
||||
#include <QtGui>
|
||||
#include <QLabel>
|
||||
#include "lritemdesignintf.h"
|
||||
#include <qnamespace.h>
|
||||
|
||||
#include <QTextDocument>
|
||||
|
||||
namespace LimeReport {
|
||||
|
||||
class Tag;
|
||||
class TextItem : public LimeReport::ContentItemDesignIntf {
|
||||
Q_OBJECT
|
||||
Q_ENUMS(AutoWidth)
|
||||
Q_ENUMS(AngleType)
|
||||
Q_PROPERTY(QString content READ content WRITE setContent)
|
||||
Q_PROPERTY(int margin READ marginSize WRITE setMarginSize)
|
||||
Q_PROPERTY(Qt::Alignment alignment READ alignment() WRITE setAlignment)
|
||||
Q_PROPERTY(AutoWidth autoWidth READ autoWidth() WRITE setAutoWidth)
|
||||
Q_PROPERTY(bool autoHeight READ autoHeight() WRITE setAutoHeight)
|
||||
Q_PROPERTY(QFont font READ font() WRITE setTextItemFont)
|
||||
Q_PROPERTY(int backgroundOpacity READ opacity WRITE setBackgroundOpacity)
|
||||
Q_PROPERTY(BGMode backgroundMode READ backgroundMode WRITE setBackgroundModeProperty)
|
||||
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColorProperty)
|
||||
Q_PROPERTY(QColor fontColor READ fontColor WRITE setFontColorProperty)
|
||||
Q_PROPERTY(AngleType angle READ angle WRITE setAngle)
|
||||
Q_PROPERTY(int foregroundOpacity READ foregroundOpacity WRITE setForegroundOpacity())
|
||||
Q_PROPERTY(bool trimValue READ trimValue WRITE setTrimValue)
|
||||
Q_PROPERTY(bool allowHTML READ allowHTML WRITE setAllowHTML)
|
||||
public:
|
||||
|
||||
enum AutoWidth{NoneAutoWidth,MaxWordLength,MaxStringLength};
|
||||
enum AngleType{Angle0,Angle90,Angle180,Angle270,Angle45,Angle315};
|
||||
|
||||
void Init();
|
||||
TextItem(QObject* owner=0, QGraphicsItem* parent=0);
|
||||
~TextItem();
|
||||
|
||||
void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*);
|
||||
QString content() const;
|
||||
void setContent(const QString& value);
|
||||
|
||||
//void setMarginSize(int value);
|
||||
|
||||
|
||||
void setAlignment(Qt::Alignment value);
|
||||
Qt::Alignment alignment(){return m_alignment;}
|
||||
|
||||
void geometryChangedEvent(QRectF, QRectF);
|
||||
bool isNeedUpdateSize(RenderPass) const;
|
||||
void updateItemSize(DataSourceManager *dataManager, RenderPass pass, int maxHeight);
|
||||
void expandContent(DataSourceManager *dataManager, RenderPass pass);
|
||||
|
||||
void setAutoHeight(bool value);
|
||||
bool autoHeight() const {return m_autoHeight;}
|
||||
|
||||
void setAutoWidth(AutoWidth value);
|
||||
AutoWidth autoWidth() const {return m_autoWidth;}
|
||||
|
||||
bool canBeSplitted(int height) const;
|
||||
bool isSplittable() const { return true;}
|
||||
bool isEmpty() const{return m_text->isEmpty();}
|
||||
BaseDesignIntf* cloneUpperPart(int height, QObject *owner, QGraphicsItem *parent);
|
||||
BaseDesignIntf* cloneBottomPart(int height, QObject *owner, QGraphicsItem *parent);
|
||||
BaseDesignIntf* createSameTypeItem(QObject* owner=0, QGraphicsItem* parent=0);
|
||||
BaseDesignIntf* cloneEmpty(int height, QObject *owner, QGraphicsItem *parent);
|
||||
void objectLoadFinished();
|
||||
|
||||
void setTextItemFont(QFont value);
|
||||
QWidget* defaultEditor();
|
||||
void setBackgroundOpacity(int value);
|
||||
void setBackgroundModeProperty(BGMode value);
|
||||
void setBackgroundColorProperty(QColor value);
|
||||
void setFontColorProperty(QColor value);
|
||||
AngleType angle() const;
|
||||
void setAngle(const AngleType& value);
|
||||
int foregroundOpacity(){return m_foregroundOpacity;}
|
||||
void setForegroundOpacity(int value);
|
||||
|
||||
bool trimValue() const;
|
||||
void setTrimValue(bool trimValue);
|
||||
|
||||
bool allowHTML() const;
|
||||
void setAllowHTML(bool allowHTML);
|
||||
|
||||
protected:
|
||||
void updateLayout();
|
||||
bool isNeedExpandContent() const;
|
||||
QString replaceBR(QString text);
|
||||
QString replaceReturns(QString text);
|
||||
int fakeMarginSize();
|
||||
private:
|
||||
void initText();
|
||||
private:
|
||||
QString m_strText;
|
||||
|
||||
//QTextLayout m_layout;
|
||||
QTextDocument* m_text;
|
||||
Qt::Alignment m_alignment;
|
||||
bool m_autoHeight;
|
||||
AutoWidth m_autoWidth;
|
||||
QSizeF m_textSize;
|
||||
AngleType m_angle;
|
||||
int m_foregroundOpacity;
|
||||
bool m_trimValue;
|
||||
bool m_allowHTML;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // LRTEXTITEM_H
|
381
limereport/items/lrtextitemeditor.cpp
Normal file
@@ -0,0 +1,381 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "lrtextitemeditor.h"
|
||||
#include "ui_lrtextitemeditor.h"
|
||||
|
||||
#include "lrdatasourcemanager.h"
|
||||
#include "lrscriptenginemanager.h"
|
||||
#include "lrdatadesignintf.h"
|
||||
#include "lrdatasourcemanager.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QScrollBar>
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
TextItemEditor::TextItemEditor(LimeReport::TextItem *item, LimeReport::PageDesignIntf *page, QSettings* settings, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::TextItemEditor), m_textItem(item), m_page(page), m_settings(settings), m_ownedSettings(false), m_isReadingSetting(false)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
initUI();
|
||||
m_teContent->setPlainText(item->content());
|
||||
m_teContent->setFocus();
|
||||
setWindowIcon(QIcon(":/items/images/TextItem"));
|
||||
readSetting();
|
||||
}
|
||||
|
||||
TextItemEditor::~TextItemEditor()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
writeSetting();
|
||||
#endif
|
||||
#ifdef Q_OS_MAC
|
||||
writeSetting();
|
||||
#endif
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void TextItemEditor::setSettings(QSettings* value)
|
||||
{
|
||||
if (m_ownedSettings)
|
||||
delete m_settings;
|
||||
m_settings=value;
|
||||
m_ownedSettings=false;
|
||||
readSetting();
|
||||
}
|
||||
|
||||
QSettings*TextItemEditor::settings()
|
||||
{
|
||||
if (m_settings){
|
||||
return m_settings;
|
||||
} else {
|
||||
m_settings = new QSettings("LimeReport",QApplication::applicationName());
|
||||
m_ownedSettings = true;
|
||||
return m_settings;
|
||||
}
|
||||
}
|
||||
|
||||
void TextItemEditor::resizeEvent(QResizeEvent*)
|
||||
{
|
||||
#ifdef Q_OS_UNIX
|
||||
writeSetting();
|
||||
#endif
|
||||
}
|
||||
|
||||
void TextItemEditor::moveEvent(QMoveEvent*)
|
||||
{
|
||||
#ifdef Q_OS_UNIX
|
||||
writeSetting();
|
||||
#endif
|
||||
}
|
||||
|
||||
void TextItemEditor::on_pbOk_clicked()
|
||||
{
|
||||
if (m_textItem->content()!=m_teContent->toPlainText()){
|
||||
m_textItem->setContent(m_teContent->toPlainText());
|
||||
}
|
||||
close();
|
||||
}
|
||||
|
||||
void TextItemEditor::initUI()
|
||||
{
|
||||
QStringList dataWords;
|
||||
m_teContent = ui->textEdit;
|
||||
m_completer = new QCompleter(this);
|
||||
m_teContent->setCompleter(m_completer);
|
||||
|
||||
m_datasourcesMenu = new QMenu(this);
|
||||
|
||||
LimeReport::DataSourceManager* dm = m_page->datasourceManager();
|
||||
LimeReport::ScriptEngineManager& se = LimeReport::ScriptEngineManager::instance();
|
||||
se.setDataManager(dm);
|
||||
|
||||
if (dm){
|
||||
ui->twData->setModel(dm->datasourcesModel());
|
||||
ui->twScriptEngine->setModel(se.model());
|
||||
|
||||
foreach(QString dsName,dm->dataSourceNames()){
|
||||
foreach(QString field, dm->fieldNames(dsName)){
|
||||
dataWords<<dsName+"."+field;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ui->tabWidget->setVisible(false);
|
||||
}
|
||||
|
||||
foreach (LimeReport::ScriptFunctionDesc functionDesc, se.functionsDescriber()) {
|
||||
dataWords<<functionDesc.name;
|
||||
}
|
||||
|
||||
m_completer->setModel(new QStringListModel(dataWords,m_completer));
|
||||
ui->gbSettings->setVisible(false);
|
||||
connect(ui->twScriptEngine->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
||||
this, SLOT(slotScriptItemsSelectionChanged(QModelIndex,QModelIndex)));
|
||||
}
|
||||
|
||||
QStringListModel *TextItemEditor::getDataSources()
|
||||
{
|
||||
LimeReport::DataSourceManager* dm = m_page->datasourceManager();
|
||||
QStringList dataSources;
|
||||
foreach(QString dsName,dm->dataSourceNames()){
|
||||
dataSources<<dsName;
|
||||
}
|
||||
return new QStringListModel(dataSources, m_completer);
|
||||
}
|
||||
|
||||
QStringListModel *TextItemEditor::getPrefixes()
|
||||
{
|
||||
QStringList prefixes;
|
||||
prefixes<<"D{"<<"S{";
|
||||
return new QStringListModel(prefixes, m_completer);
|
||||
}
|
||||
|
||||
QStringListModel *TextItemEditor::getColumns(QString datasource)
|
||||
{
|
||||
QStringList fields;
|
||||
LimeReport::DataSourceManager* dm = m_page->datasourceManager();
|
||||
foreach(QString field, dm->fieldNames(datasource)){
|
||||
fields<<field;
|
||||
}
|
||||
return new QStringListModel(fields, m_completer);
|
||||
}
|
||||
|
||||
void TextItemEditor::on_pbCancel_clicked()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void TextItemEditor::slotFieldSelected()
|
||||
{
|
||||
QAction* action = dynamic_cast<QAction*>(sender());
|
||||
m_teContent->insertPlainText(action->whatsThis());
|
||||
}
|
||||
|
||||
void TextItemEditor::readSetting()
|
||||
{
|
||||
if (settings()==0) return;
|
||||
|
||||
m_isReadingSetting = true;
|
||||
|
||||
settings()->beginGroup("TextItemEditor");
|
||||
QVariant v = settings()->value("Geometry");
|
||||
if (v.isValid()){
|
||||
restoreGeometry(v.toByteArray());
|
||||
}
|
||||
v = settings()->value("State");
|
||||
if (v.isValid()){
|
||||
ui->splitter->restoreState(v.toByteArray());
|
||||
}
|
||||
|
||||
QVariant fontName = settings()->value("FontName");
|
||||
if (fontName.isValid()){
|
||||
QVariant fontSize = settings()->value("FontSize");
|
||||
ui->textEdit->setFont(QFont(fontName.toString(),fontSize.toInt()));
|
||||
ui->editorFont->setCurrentFont(ui->textEdit->font());
|
||||
ui->editorFontSize->setValue(fontSize.toInt());
|
||||
}
|
||||
settings()->endGroup();
|
||||
|
||||
m_isReadingSetting = false;
|
||||
}
|
||||
|
||||
void TextItemEditor::writeSetting()
|
||||
{
|
||||
if (settings()!=0){
|
||||
settings()->beginGroup("TextItemEditor");
|
||||
settings()->setValue("Geometry",saveGeometry());
|
||||
settings()->setValue("State",ui->splitter->saveState());
|
||||
settings()->endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CompleaterTextEditor::CompleaterTextEditor(QWidget *parent)
|
||||
: QTextEdit(parent),m_compleater(0)
|
||||
{
|
||||
}
|
||||
|
||||
void CompleaterTextEditor::setCompleter(QCompleter *value)
|
||||
{
|
||||
if (value) disconnect(value,0,this,0);
|
||||
m_compleater = value;
|
||||
if (!m_compleater) return;
|
||||
m_compleater->setWidget(this);
|
||||
m_compleater->setCompletionMode(QCompleter::PopupCompletion);
|
||||
m_compleater->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
connect(m_compleater,SIGNAL(activated(QString)),this,SLOT(insertCompletion(QString)));
|
||||
}
|
||||
|
||||
void CompleaterTextEditor::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
if (m_compleater && m_compleater->popup()->isVisible()) {
|
||||
switch (e->key()) {
|
||||
case Qt::Key_Enter:
|
||||
case Qt::Key_Return:
|
||||
case Qt::Key_Escape:
|
||||
case Qt::Key_Tab:
|
||||
case Qt::Key_Backtab:
|
||||
e->ignore();
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E);
|
||||
if (!m_compleater || !isShortcut) QTextEdit::keyPressEvent(e);
|
||||
|
||||
const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
|
||||
if (!m_compleater || (ctrlOrShift && e->text().isEmpty()))
|
||||
return;
|
||||
|
||||
static QString eow("~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-="); // end of word
|
||||
bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
|
||||
|
||||
QString completionPrefix = textUnderCursor();
|
||||
|
||||
if (!isShortcut && (hasModifier || e->text().isEmpty()|| completionPrefix.length() < 3
|
||||
|| eow.contains(e->text().right(1)))) {
|
||||
m_compleater->popup()->hide();
|
||||
return;
|
||||
}
|
||||
|
||||
if (completionPrefix != m_compleater->completionPrefix()) {
|
||||
m_compleater->setCompletionPrefix(completionPrefix);
|
||||
m_compleater->popup()->setCurrentIndex(m_compleater->completionModel()->index(0, 0));
|
||||
}
|
||||
|
||||
QRect cr = cursorRect();
|
||||
cr.setWidth(m_compleater->popup()->sizeHintForColumn(0)
|
||||
+ m_compleater->popup()->verticalScrollBar()->sizeHint().width());
|
||||
m_compleater->complete(cr);
|
||||
|
||||
}
|
||||
|
||||
void CompleaterTextEditor::focusInEvent(QFocusEvent *e)
|
||||
{
|
||||
if (m_compleater) m_compleater->setWidget(this);
|
||||
QTextEdit::focusInEvent(e);
|
||||
}
|
||||
|
||||
QString CompleaterTextEditor::textUnderCursor() const
|
||||
{
|
||||
QTextCursor tc = textCursor();
|
||||
tc.select(QTextCursor::WordUnderCursor);
|
||||
return tc.selectedText();
|
||||
}
|
||||
|
||||
|
||||
void CompleaterTextEditor::insertCompletion(const QString &completion)
|
||||
{
|
||||
if (m_compleater->widget() != this)
|
||||
return;
|
||||
QTextCursor tc = textCursor();
|
||||
int extra = completion.length() - m_compleater->completionPrefix().length();
|
||||
tc.movePosition(QTextCursor::Left);
|
||||
tc.movePosition(QTextCursor::EndOfWord);
|
||||
tc.insertText(completion.right(extra));
|
||||
setTextCursor(tc);
|
||||
}
|
||||
|
||||
void TextItemEditor::on_twData_doubleClicked(const QModelIndex &index)
|
||||
{
|
||||
if (!index.isValid()) return;
|
||||
LimeReport::DataNode* node = static_cast<LimeReport::DataNode*>(index.internalPointer());
|
||||
if (node->type()==LimeReport::DataNode::Field){
|
||||
m_teContent->insertPlainText(QString("$D{%1.%2}").arg(node->parent()->name()).arg(node->name()));
|
||||
}
|
||||
if (node->type()==LimeReport::DataNode::Variable){
|
||||
m_teContent->insertPlainText(QString("$V{%1}").arg(node->name()));
|
||||
}
|
||||
}
|
||||
|
||||
void TextItemEditor::on_twScriptEngine_doubleClicked(const QModelIndex &index)
|
||||
{
|
||||
if (!index.isValid()) return;
|
||||
LimeReport::ScriptEngineNode* node = static_cast<LimeReport::ScriptEngineNode*>(index.internalPointer());
|
||||
if (node->type()==LimeReport::ScriptEngineNode::Function){
|
||||
m_teContent->insertPlainText(node->name()+"()");
|
||||
}
|
||||
}
|
||||
|
||||
void TextItemEditor::on_splitter_splitterMoved(int , int )
|
||||
{
|
||||
#ifdef unix
|
||||
writeSetting();
|
||||
#endif
|
||||
}
|
||||
|
||||
void TextItemEditor::on_editorFont_currentFontChanged(const QFont &f)
|
||||
{
|
||||
if (m_isReadingSetting) return;
|
||||
QFont tmp = f;
|
||||
tmp.setPointSize(ui->editorFontSize->value());
|
||||
ui->textEdit->setFont(tmp);
|
||||
settings()->beginGroup("TextItemEditor");
|
||||
settings()->setValue("FontName",ui->textEdit->font().family());
|
||||
settings()->setValue("FontSize",ui->editorFontSize->value());
|
||||
settings()->endGroup();
|
||||
}
|
||||
|
||||
void TextItemEditor::on_editorFontSize_valueChanged(int arg1)
|
||||
{
|
||||
if (m_isReadingSetting) return;
|
||||
ui->textEdit->setFont(QFont(ui->textEdit->font().family(),arg1));
|
||||
settings()->beginGroup("TextItemEditor");
|
||||
settings()->setValue("FontName",ui->textEdit->font().family());
|
||||
settings()->setValue("FontSize",ui->editorFontSize->value());
|
||||
settings()->endGroup();
|
||||
}
|
||||
|
||||
void TextItemEditor::on_toolButton_clicked(bool checked)
|
||||
{
|
||||
ui->gbSettings->setVisible(checked);
|
||||
}
|
||||
|
||||
|
||||
void TextItemEditor::on_twScriptEngine_activated(const QModelIndex &index)
|
||||
{
|
||||
LimeReport::ScriptEngineNode* node = static_cast<LimeReport::ScriptEngineNode*>(index.internalPointer());
|
||||
if (node->type()==LimeReport::ScriptEngineNode::Function){
|
||||
ui->lblDescription->setText(node->name());
|
||||
}
|
||||
}
|
||||
|
||||
void TextItemEditor::slotScriptItemsSelectionChanged(const QModelIndex &to, const QModelIndex)
|
||||
{
|
||||
LimeReport::ScriptEngineNode* node = static_cast<LimeReport::ScriptEngineNode*>(to.internalPointer());
|
||||
if (node->type()==LimeReport::ScriptEngineNode::Function){
|
||||
ui->lblDescription->setText(node->description());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace LimeReport
|
109
limereport/items/lrtextitemeditor.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* arin_a@bk.ru *
|
||||
* *
|
||||
** GNU General Public License Usage **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
** GNU Lesser General Public License **
|
||||
* *
|
||||
* This library is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library. *
|
||||
* If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#ifndef LRTEXTITEMEDITOR_H
|
||||
#define LRTEXTITEMEDITOR_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTextEdit>
|
||||
#include <QCompleter>
|
||||
|
||||
#include "lrtextitem.h"
|
||||
#include "lrpagedesignintf.h"
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
namespace Ui {
|
||||
class TextItemEditor;
|
||||
}
|
||||
|
||||
class CompleaterTextEditor :public QTextEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CompleaterTextEditor(QWidget* parent=0);
|
||||
void setCompleter(QCompleter* value);
|
||||
QCompleter* compleater() const{ return m_compleater;}
|
||||
protected:
|
||||
virtual void keyPressEvent(QKeyEvent *e);
|
||||
virtual void focusInEvent(QFocusEvent *e);
|
||||
private:
|
||||
QString textUnderCursor() const;
|
||||
private slots:
|
||||
void insertCompletion(const QString& completion);
|
||||
private:
|
||||
QCompleter* m_compleater;
|
||||
};
|
||||
|
||||
class TextItemEditor : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TextItemEditor(LimeReport::TextItem* item, LimeReport::PageDesignIntf* page,
|
||||
QSettings* settings=0, QWidget *parent = 0);
|
||||
~TextItemEditor();
|
||||
void setSettings(QSettings* value);
|
||||
QSettings* settings();
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *);
|
||||
void moveEvent(QMoveEvent *);
|
||||
private slots:
|
||||
void on_pbOk_clicked();
|
||||
void on_pbCancel_clicked();
|
||||
void slotFieldSelected();
|
||||
void on_twData_doubleClicked(const QModelIndex &index);
|
||||
void on_twScriptEngine_doubleClicked(const QModelIndex &index);
|
||||
void on_splitter_splitterMoved(int, int);
|
||||
void on_editorFont_currentFontChanged(const QFont &f);
|
||||
void on_editorFontSize_valueChanged(int arg1);
|
||||
void on_toolButton_clicked(bool checked);
|
||||
void on_twScriptEngine_activated(const QModelIndex &index);
|
||||
void slotScriptItemsSelectionChanged(const QModelIndex &to, const QModelIndex);
|
||||
private:
|
||||
void initUI();
|
||||
void readSetting();
|
||||
void writeSetting();
|
||||
QStringListModel* getDataSources();
|
||||
QStringListModel* getPrefixes();
|
||||
QStringListModel* getColumns(QString datasource);
|
||||
private:
|
||||
Ui::TextItemEditor *ui;
|
||||
LimeReport::TextItem* m_textItem;
|
||||
LimeReport::PageDesignIntf* m_page;
|
||||
QMenu* m_datasourcesMenu;
|
||||
CompleaterTextEditor* m_teContent;
|
||||
QCompleter* m_completer;
|
||||
QSettings* m_settings;
|
||||
bool m_ownedSettings;
|
||||
bool m_isReadingSetting;
|
||||
};
|
||||
|
||||
} // namespace LimeReport
|
||||
|
||||
#endif // LRTEXTITEMEDITOR_H
|
249
limereport/items/lrtextitemeditor.ui
Normal file
@@ -0,0 +1,249 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>LimeReport::TextItemEditor</class>
|
||||
<widget class="QWidget" name="LimeReport::TextItemEditor">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::ApplicationModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>539</width>
|
||||
<height>436</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Text Item Editor</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="items.qrc">
|
||||
<normaloff>:/items/images/insert-text_3.png</normaloff>:/items/images/insert-text_3.png</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Content</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="CompleaterTextEditor" name="textEdit">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="tabPosition">
|
||||
<enum>QTabWidget::South</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>Data</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTreeView" name="twData">
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Functions</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<widget class="QTreeView" name="twScriptEngine">
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QLabel" name="lblDescription">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gbSettings">
|
||||
<property name="title">
|
||||
<string>Editor settings</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Editor font</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFontComboBox" name="editorFont"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="editorFontSize">
|
||||
<property name="value">
|
||||
<number>11</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="items.qrc">
|
||||
<normaloff>:/items/images/settings.png</normaloff>:/items/images/settings.png</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pbOk">
|
||||
<property name="text">
|
||||
<string>Ok</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Return</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pbCancel">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Esc</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>CompleaterTextEditor</class>
|
||||
<extends>QTextEdit</extends>
|
||||
<header>lrtextitemeditor.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>pbOk</tabstop>
|
||||
<tabstop>pbCancel</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="items.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|