LimeReport/limereport/lrreportdesignwidget.cpp

1281 lines
40 KiB
C++
Raw Normal View History

2016-02-17 10:11:00 +03:00
/***************************************************************************
* This file is part of the Lime Report project *
2021-08-18 20:21:36 +03:00
* Copyright (C) 2021 by Alexander Arin *
2016-02-17 10:11:00 +03:00
* 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 "lrreportdesignwidget.h"
#include "serializators/lrxmlreader.h"
#include "serializators/lrxmlwriter.h"
#include "lrreportengine_p.h"
#include "lrbasedesignintf.h"
#include "lrsettingdialog.h"
#include "dialogdesigner/lrdialogdesigner.h"
2017-08-05 01:38:19 +03:00
#include "translationeditor/translationeditor.h"
2017-09-13 17:16:54 +03:00
#include "scripteditor/lrscripteditor.h"
2016-02-17 10:11:00 +03:00
#include <QDebug>
#include <QObject>
#include <QDockWidget>
#include <QtXml>
#include <QVBoxLayout>
#include <QFileDialog>
2016-02-17 10:19:50 +03:00
#include <QApplication>
2016-06-10 18:05:18 +03:00
#include <QTabWidget>
#include <QMessageBox>
2016-02-17 10:11:00 +03:00
namespace LimeReport {
// ReportDesignIntf
2019-01-29 23:18:24 +03:00
ReportDesignWidget::ReportDesignWidget(ReportEnginePrivateInterface* report, QSettings* settings, QMainWindow *mainWindow, QWidget *parent) :
QWidget(parent),
#ifdef HAVE_QTDESIGNER_INTEGRATION
m_dialogDesignerManager(new DialogDesignerManager(this)),
#endif
2019-01-29 23:18:24 +03:00
m_mainWindow(mainWindow), m_verticalGridStep(10), m_horizontalGridStep(10), m_useGrid(false),
m_dialogChanged(false), m_theme("Default"), m_settings(settings), m_defaultUnits(BaseDesignIntf::Millimeters)
2016-02-17 10:11:00 +03:00
{
2021-08-23 08:07:08 +03:00
#if QT_VERSION < 0x050000
2017-10-26 12:11:33 +03:00
m_tabWidget = new LimeReportTabWidget(this);
2021-08-23 08:07:08 +03:00
#else
2017-10-26 12:24:06 +03:00
m_tabWidget = new QTabWidget(this);
2017-10-26 12:11:33 +03:00
#endif
2016-06-10 18:05:18 +03:00
m_tabWidget->setTabPosition(QTabWidget::South);
2017-08-19 00:16:55 +03:00
m_tabWidget->setMovable(true);
connect(m_tabWidget->tabBar(), SIGNAL(tabMoved(int,int)), this, SLOT(slotTabMoved(int,int)));
2016-06-10 18:05:18 +03:00
QVBoxLayout* mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(m_tabWidget);
2016-02-17 10:11:00 +03:00
setLayout(mainLayout);
2018-05-08 10:58:43 +03:00
m_report=report;
2016-02-17 10:11:00 +03:00
m_settings->beginGroup("DesignerWidget");
QVariant v = m_settings->value("DefaultUnits");
if (v.isValid()){
m_defaultUnits = static_cast<BaseDesignIntf::UnitType>(v.toInt());
}
m_settings->endGroup();
2016-06-10 18:05:18 +03:00
if (!m_report->pageCount()){
createStartPage();
}
createTabs();
2017-11-24 00:13:47 +03:00
connect(dynamic_cast<QObject*>(m_report), SIGNAL(pagesLoadFinished()),this,SLOT(slotPagesLoadFinished()));
2018-05-08 10:58:43 +03:00
connect(dynamic_cast<QObject*>(m_report), SIGNAL(cleared()), this, SIGNAL(cleared()));
connect(dynamic_cast<QObject*>(m_report), SIGNAL(loadFinished()), this, SLOT(slotReportLoaded()));
2018-05-08 10:58:43 +03:00
2016-06-10 18:05:18 +03:00
connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentTabChanged(int)));
#ifdef HAVE_UI_LOADER
connect(m_report->scriptContext(), SIGNAL(dialogDeleted(QString)), this, SLOT(slotDialogDeleted(QString)));
#endif
//m_instance=this;
m_scriptEditor->setPlainText(m_report->scriptContext()->initScript());
2016-06-10 18:05:18 +03:00
m_zoomer = new GraphicsViewZoomer(activeView());
#ifdef Q_OS_WIN
m_defaultFont = QFont("Arial",10);
#endif
#ifdef HAVE_QTDESIGNER_INTEGRATION
connect(m_dialogDesignerManager, SIGNAL(dialogChanged(QString)),
this, SLOT(slotDialogChanged(QString)));
connect(m_dialogDesignerManager, SIGNAL(dialogNameChanged(QString,QString)),
this, SLOT(slotDialogNameChanged(QString,QString)));
#endif
2019-05-26 15:15:06 +03:00
m_themes.insert("Default","");
m_localToEng.insert(QObject::tr("Dark"), "Dark");
m_localToEng.insert(QObject::tr("Light"), "Light");
2019-05-26 15:15:06 +03:00
initThemeIfExist("Dark", ":/qdarkstyle/style.qss");
initThemeIfExist("Light", ":/qlightstyle/lightstyle.qss");
}
#ifdef HAVE_QTDESIGNER_INTEGRATION
DialogDesignerManager *ReportDesignWidget::dialogDesignerManager() const
{
return m_dialogDesignerManager;
}
QString ReportDesignWidget::activeDialogName()
{
if (activeDialogPage())
return activeDialogPage()->dialogName();
return "";
}
QWidget *ReportDesignWidget::toolWindow(ReportDesignWidget::ToolWindowType windowType)
{
switch (windowType) {
case WidgetBox:
return dialogDesignerManager()->widgetBox();
case PropertyEditor:
return dialogDesignerManager()->propertyEditor();
case ObjectInspector:
return dialogDesignerManager()->objectInspector();
case ActionEditor:
return dialogDesignerManager()->actionEditor();
case ResourceEditor:
return dialogDesignerManager()->resourcesEditor();
case SignalSlotEditor:
return dialogDesignerManager()->signalSlotEditor();
}
2021-08-18 04:20:38 +03:00
return NULL;
}
#endif
ReportDesignWidget::EditorTabType ReportDesignWidget::activeTabType()
{
QString tabType = m_tabWidget->tabWhatsThis(m_tabWidget->currentIndex());
if ( tabType.compare("dialog") == 0) return Dialog;
if ( tabType.compare("script") == 0) return Script;
2017-08-05 01:38:19 +03:00
if ( tabType.compare("translations") == 0) return Translations;
return Page;
}
#ifdef HAVE_QTDESIGNER_INTEGRATION
void ReportDesignWidget::initDialogDesignerToolBar(QToolBar *toolBar)
{
m_dialogDesignerManager->initToolBar(toolBar);
}
void ReportDesignWidget::updateDialogs()
{
for ( int i = 0; i<m_tabWidget->count(); ++i ){
if (m_tabWidget->tabWhatsThis(i).compare("dialog") == 0){
m_report->scriptContext()->changeDialog(m_tabWidget->tabText(i), m_dialogDesignerManager->getDialogDescription(m_tabWidget->widget(i)));
}
}
}
#endif
2016-02-21 01:08:54 +03:00
bool ReportDesignWidget::useMagnet() const
{
return m_useMagnet;
}
void ReportDesignWidget::setUseMagnet(bool useMagnet)
{
m_useMagnet = useMagnet;
for (int i=0;i<m_report->pageCount();++i){
m_report->pageAt(i)->setMagneticMovement(useMagnet);
}
}
void ReportDesignWidget::saveState()
{
m_settings->beginGroup("DesignerWidget");
m_settings->setValue("hGridStep",m_horizontalGridStep);
m_settings->setValue("vGridStep",m_verticalGridStep);
m_settings->setValue("defaultFont",m_defaultFont);
m_settings->setValue("useGrid",m_useGrid);
2019-05-26 15:15:06 +03:00
m_settings->setValue("theme",m_theme);
m_settings->setValue("ScriptEditorState", m_scriptEditor->saveState());
m_settings->setValue("DefaultUnits", m_defaultUnits);
m_settings->endGroup();
}
void ReportDesignWidget::applySettings()
{
for (int i=0;i<m_report->pageCount();++i){
m_report->pageAt(i)->pageItem()->setFont(m_defaultFont);
}
applyUseGrid();
2019-05-26 15:15:06 +03:00
if (m_themes.contains(m_theme)){
parentWidget()->setStyleSheet(m_themes.value(m_theme));
m_report->setStyleSheet(m_themes.value(m_theme));
2018-04-09 22:03:22 +03:00
} else {
2019-05-26 15:15:06 +03:00
m_theme = "Default";
2018-04-09 22:03:22 +03:00
parentWidget()->setStyleSheet("");
m_report->setStyleSheet("");
}
2019-01-29 23:18:24 +03:00
2019-05-26 15:15:06 +03:00
// if (m_theme.compare("Dark") == 0) {
// QFile theme(":/qdarkstyle/style.qss");
// theme.open(QIODevice::ReadOnly);
// QString styleSheet = theme.readAll();
// parentWidget()->setStyleSheet(styleSheet);
// m_report->setStyleSheet(styleSheet);
// } else {
// parentWidget()->setStyleSheet("");
// m_report->setStyleSheet("");
// }
2019-01-29 23:18:24 +03:00
if (m_settings){
m_settings->beginGroup("ScriptEditor");
QVariant v = m_settings->value("DefaultFontName");
if (v.isValid()){
QVariant fontSize = m_settings->value("DefaultFontSize");
m_scriptEditor->setEditorFont(QFont(v.toString(),fontSize.toInt()));
}
v = m_settings->value("TabIndention");
if (v.isValid()){
m_scriptEditor->setTabIndention(v.toInt());
}
m_settings->endGroup();
}
}
2019-01-29 23:18:24 +03:00
void ReportDesignWidget::loadState()
{
2019-01-29 23:18:24 +03:00
m_settings->beginGroup("DesignerWidget");
QVariant v = m_settings->value("hGridStep");
if (v.isValid()){
m_horizontalGridStep = v.toInt();
}
2019-01-29 23:18:24 +03:00
v = m_settings->value("vGridStep");
if (v.isValid()){
m_verticalGridStep = v.toInt();
}
2019-01-29 23:18:24 +03:00
v = m_settings->value("defaultFont");
if (v.isValid()){
m_defaultFont = v.value<QFont>();
}
2019-01-29 23:18:24 +03:00
v = m_settings->value("useGrid");
if (v.isValid()){
m_useGrid = v.toBool();
}
2017-09-20 00:51:17 +03:00
2019-05-26 15:15:06 +03:00
v = m_settings->value("theme");
2017-12-11 16:48:00 +03:00
if (v.isValid()){
2019-05-26 15:15:06 +03:00
m_theme = v.toString();
2017-12-11 16:48:00 +03:00
}
2019-01-29 23:18:24 +03:00
v = m_settings->value("ScriptEditorState");
if (v.isValid() && m_scriptEditor){
2017-09-20 00:51:17 +03:00
m_scriptEditor->restoreState(v.toByteArray());
}
v = m_settings->value("DefaultUnits");
if (v.isValid()){
m_defaultUnits = static_cast<BaseDesignIntf::UnitType>(v.toInt());
}
2019-01-29 23:18:24 +03:00
m_settings->endGroup();
applySettings();
2016-02-17 10:11:00 +03:00
}
2019-07-23 17:06:07 +03:00
PageView* ReportDesignWidget::createPageView(PageDesignIntf* page){
PageView* view = new PageView(this);
view->setBackgroundBrush(QBrush(Qt::gray));
view->setFrameShape(QFrame::NoFrame);
view->setScene(page);
view->setPageItem(page->pageItem());
view->scale(0.5, 0.5);
view->centerOn(0, 0);
return view;
}
2016-06-10 18:05:18 +03:00
void ReportDesignWidget::createTabs(){
2018-05-08 10:58:43 +03:00
m_tabWidget->clear();
int pageIndex = -1;
2019-07-23 17:06:07 +03:00
for (int i = 0; i < m_report->pageCount(); ++i){
2019-07-23 17:06:07 +03:00
PageDesignIntf* page = m_report->pageAt(i);
page->clearSelection();
connectPage(page);
PageView* view = createPageView(page);
int pageIndex = m_tabWidget->addTab(view, QIcon(), page->pageItem()->objectName());
m_tabWidget->setTabWhatsThis(pageIndex, "page");
2016-06-10 18:05:18 +03:00
}
2017-09-20 00:51:17 +03:00
m_scriptEditor = new ScriptEditor(this);
2019-02-05 21:51:46 +03:00
connect(m_scriptEditor, SIGNAL(textChanged()), this, SLOT(slotScriptTextChanged()));
2017-09-20 00:51:17 +03:00
m_scriptEditor->setReportEngine(m_report);
pageIndex = m_tabWidget->addTab(m_scriptEditor,QIcon(),tr("Script"));
m_tabWidget->setTabWhatsThis(pageIndex,"script");
2016-06-10 18:05:18 +03:00
m_tabWidget->setCurrentIndex(0);
#ifdef HAVE_QTDESIGNER_INTEGRATION
QWidget* dialogDesigner;
foreach(DialogDescriber::Ptr dialogDesc, m_report->scriptContext()->dialogDescribers()){
dialogDesigner = m_dialogDesignerManager->createFormEditor(dialogDesc->description());
pageIndex = m_tabWidget->addTab(dialogDesigner,QIcon(),dialogDesc->name());
m_tabWidget->setTabWhatsThis(pageIndex,"dialog");
2016-06-10 18:05:18 +03:00
}
#endif
2017-08-05 01:38:19 +03:00
m_traslationEditor = new TranslationEditor(this);
pageIndex = m_tabWidget->addTab(m_traslationEditor,QIcon(),tr("Translations"));
m_tabWidget->setTabWhatsThis(pageIndex,"translations");
2016-06-10 18:05:18 +03:00
}
#ifdef HAVE_QTDESIGNER_INTEGRATION
void ReportDesignWidget::createNewDialogTab(const QString& dialogName, const QByteArray& description)
{
QWidget* dialogDesigner = m_dialogDesignerManager->createFormEditor(description);
int pageIndex = m_tabWidget->addTab(dialogDesigner,QIcon(),dialogName);
m_tabWidget->setTabWhatsThis(pageIndex,"dialog");
2017-04-18 20:00:59 +03:00
m_tabWidget->setCurrentIndex(pageIndex);
m_dialogDesignerManager->setActiveEditor(dialogDesigner);
}
DialogDesigner*ReportDesignWidget::activeDialogPage()
{
return dynamic_cast<DialogDesigner*>(m_tabWidget->currentWidget());
}
#endif
2016-02-17 10:11:00 +03:00
ReportDesignWidget::~ReportDesignWidget()
{
delete m_zoomer;
}
2016-02-17 10:11:00 +03:00
2016-06-10 18:05:18 +03:00
QGraphicsView* ReportDesignWidget::activeView(){
return dynamic_cast<QGraphicsView*>(m_tabWidget->currentWidget());
}
void ReportDesignWidget::connectPage(PageDesignIntf *page)
2016-02-17 10:11:00 +03:00
{
2019-07-24 03:13:23 +03:00
connect(page, SIGNAL(itemInserted(LimeReport::PageDesignIntf*, QPointF, QString)),
this, SIGNAL(itemInserted(LimeReport::PageDesignIntf*, QPointF, QString)));
connect(page, SIGNAL(itemInsertCanceled(QString)),this,SIGNAL(itemInsertCanceled(QString)));
connect(page, SIGNAL(itemPropertyChanged(QString, QString, QVariant, QVariant)),
this, SIGNAL(itemPropertyChanged(QString, QString, QVariant, QVariant)));
connect(page, SIGNAL(itemPropertyObjectNameChanged(QString, QString)),
this, SLOT(slotItemPropertyObjectNameChanged(QString, QString)));
connect(page, SIGNAL(selectionChanged()), this, SLOT(slotSelectionChanged()));
connect(page, SIGNAL(insertModeStarted()), this, SIGNAL(insertModeStarted()));
connect(page, SIGNAL(commandHistoryChanged()), this, SIGNAL(commandHistoryChanged()));
connect(page, SIGNAL(sceneRectChanged(QRectF)), this, SLOT(slotSceneRectChanged(QRectF)));
connect(page, SIGNAL(itemAdded(LimeReport::PageDesignIntf*, LimeReport::BaseDesignIntf*)),
this, SIGNAL(itemAdded(LimeReport::PageDesignIntf*, LimeReport::BaseDesignIntf*)));
connect(page, SIGNAL(itemRemoved(LimeReport::PageDesignIntf*, LimeReport::BaseDesignIntf*)),
this, SIGNAL(itemDeleted(LimeReport::PageDesignIntf*, LimeReport::BaseDesignIntf*)));
connect(page, SIGNAL(bandAdded(LimeReport::PageDesignIntf*, LimeReport::BandDesignIntf*)),
this, SIGNAL(bandAdded(LimeReport::PageDesignIntf*, LimeReport::BandDesignIntf*)));
connect(page, SIGNAL(bandRemoved(LimeReport::PageDesignIntf*, LimeReport::BandDesignIntf*)),
this, SIGNAL(bandDeleted(LimeReport::PageDesignIntf*, LimeReport::BandDesignIntf*)));
connect(page, SIGNAL(pageUpdateFinished(LimeReport::PageDesignIntf*)),
this, SIGNAL(activePageUpdated(LimeReport::PageDesignIntf*)));
2019-07-24 03:13:23 +03:00
connect(page->pageItem(), SIGNAL(propertyObjectNameChanged(QString, QString)),
this, SLOT(slotPagePropertyObjectNameChanged(QString, QString)));
2016-02-17 10:11:00 +03:00
emit activePageChanged();
}
PageDesignIntf* ReportDesignWidget::createStartPage()
2016-02-17 10:11:00 +03:00
{
PageDesignIntf* page = m_report->appendPage("page1");
page->pageItem()->setUnitType(m_defaultUnits);
// createTabs();
return page;
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::removeDatasource(const QString &datasourceName)
{
2016-06-10 18:05:18 +03:00
if (m_report->dataManager())
m_report->dataManager()->removeDatasource(datasourceName);
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::addBand(const QString &bandType)
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->addBand(bandType);
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::addBand(BandDesignIntf::BandsType bandType)
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->addBand(bandType);
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::startInsertMode(const QString &itemType)
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->startInsertMode(itemType);
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::startEditMode()
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->startEditMode();
2016-02-17 10:11:00 +03:00
}
PageDesignIntf * ReportDesignWidget::activePage()
{
2016-06-10 18:05:18 +03:00
if (activeView())
2017-12-08 00:26:47 +03:00
return dynamic_cast<PageDesignIntf*>(activeView()->scene());
2016-06-10 18:05:18 +03:00
return 0;
2016-02-17 10:11:00 +03:00
}
QList<QGraphicsItem *> ReportDesignWidget::selectedItems(){
2016-06-10 18:05:18 +03:00
return activePage()->selectedItems();
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::deleteItem(QGraphicsItem *item){
activePage()->removeReportItem(dynamic_cast<BaseDesignIntf*>(item));
}
void ReportDesignWidget::deleteSelectedItems(){
activePage()->deleteSelected();
2016-02-17 10:11:00 +03:00
}
QStringList ReportDesignWidget::datasourcesNames(){
return m_report->dataManager()->dataSourceNames();
}
void ReportDesignWidget::slotItemSelected(BaseDesignIntf *item){
emit itemSelected(item);
}
bool ReportDesignWidget::saveToFile(const QString &fileName){
bool result = false;
2017-09-21 22:02:13 +03:00
prepareReport();
#ifdef HAVE_QTDESIGNER_INTEGRATION
updateDialogs();
#endif
if (m_report->saveToFile(fileName)) {
m_report->emitSaveFinished();
result = true;
}
#ifdef HAVE_QTDESIGNER_INTEGRATION
if (result){
m_dialogChanged = false;
m_dialogDesignerManager->setDirty(false);
}
#endif
return result;
2016-02-17 10:11:00 +03:00
}
bool ReportDesignWidget::save()
{
2017-09-21 22:02:13 +03:00
prepareReport();
#ifdef HAVE_QTDESIGNER_INTEGRATION
updateDialogs();
#endif
bool result = false;
if (emitSaveReport()) {
2024-07-18 21:46:54 +03:00
result = true;
} else if (!m_report->reportFileName().isEmpty()) {
if (m_report->saveToFile()){
m_report->emitSaveFinished();
result = true;
}
} else {
if (m_report->isSaved()) {
m_report->emitSaveFinished();
result = true;
}
2024-07-18 21:46:54 +03:00
else if (
m_report->saveToFile(
QFileDialog::getSaveFileName(
this, tr("Report file name"),
m_report->currentReportsDir(),
"Report files (*.lrxml);; All files (*)"
)
)
){
m_report->emitSaveFinished();
result = true;
};
2016-02-17 10:11:00 +03:00
}
#ifdef HAVE_QTDESIGNER_INTEGRATION
if (result){
m_dialogChanged = false;
m_dialogDesignerManager->setDirty(false);
}
#endif
return result;
2016-02-17 10:11:00 +03:00
}
bool ReportDesignWidget::loadFromFile(const QString &fileName)
2016-02-17 10:11:00 +03:00
{
if (m_report->loadFromFile(fileName,false)){
2018-05-08 10:58:43 +03:00
// QByteArray editorState = m_scriptEditor->saveState();
// createTabs();
// m_scriptEditor->setPlainText(m_report->scriptContext()->initScript());
// m_scriptEditor->restoreState(editorState);
// emit loaded();
// m_dialogChanged = false;
2018-05-24 14:31:10 +03:00
return true;
2016-06-10 18:05:18 +03:00
} else {
QMessageBox::critical(this,tr("Error"),tr("Wrong file format"));
return false;
}
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::scale(qreal sx, qreal sy)
{
2016-06-10 18:05:18 +03:00
//m_view->scale(sx,sy);
if (activeView()) activeView()->scale(sx,sy);
2016-02-17 10:11:00 +03:00
}
QString ReportDesignWidget::reportFileName()
{
2016-06-10 18:05:18 +03:00
if (m_report)
return m_report->reportFileName();
return QString();
2016-02-17 10:11:00 +03:00
}
bool ReportDesignWidget::isNeedToSave()
{
2016-06-10 18:05:18 +03:00
if(m_report)
return (m_report->isNeedToSave() || m_dialogChanged);
2016-06-10 18:05:18 +03:00
return false;
2016-02-17 10:11:00 +03:00
}
bool ReportDesignWidget::emitSaveReport()
{
return m_report->emitSaveReport();
}
bool ReportDesignWidget::emitSaveReportAs()
{
return m_report->emitSaveReportAs();
}
2016-02-17 10:39:17 +03:00
bool ReportDesignWidget::emitLoadReport()
{
return m_report->emitLoadReport();
}
2016-02-17 10:11:00 +03:00
void ReportDesignWidget::updateSize()
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->slotUpdateItemSize();
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::undo()
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->undo();
#ifdef HAVE_QTDESIGNER_INTEGRATION
if (activeDialogPage())
activeDialogPage()->undo();
#endif
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::redo()
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->redo();
#ifdef HAVE_QTDESIGNER_INTEGRATION
if (activeDialogPage())
activeDialogPage()->redo();
#endif
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::copy()
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->copy();
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::paste()
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->paste();
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::cut()
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->cut();
2016-02-17 10:11:00 +03:00
}
2018-12-23 11:41:24 +03:00
void ReportDesignWidget::bringToFront()
2016-02-17 10:11:00 +03:00
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->bringToFront();
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::sendToBack()
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->sendToBack();
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::alignToLeft()
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->alignToLeft();
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::alignToRight()
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->alignToRigth();
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::alignToVCenter()
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->alignToVCenter();
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::alignToTop()
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->alignToTop();
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::alignToBottom()
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->alignToBottom();
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::alignToHCenter()
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->alignToHCenter();
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::sameHeight()
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->sameHeight();
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::sameWidth()
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->sameWidth();
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::editLayoutMode(bool value)
{
if (value ){
activePage()->pageItem()->setItemMode(activePage()->pageItem()->itemMode() | LayoutEditMode);
} else if (activePage()->pageItem()->itemMode() & LayoutEditMode){
activePage()->pageItem()->setItemMode(activePage()->pageItem()->itemMode() ^ LayoutEditMode);
}
}
void ReportDesignWidget::addHLayout()
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->addHLayout();
2016-02-17 10:11:00 +03:00
}
2018-06-21 14:29:00 +03:00
void ReportDesignWidget::addVLayout()
{
if (activePage())
activePage()->addVLayout();
}
2016-02-17 10:11:00 +03:00
void ReportDesignWidget::setFont(const QFont& font)
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->setFont(font);
2016-02-17 10:11:00 +03:00
}
2016-02-17 10:39:17 +03:00
void ReportDesignWidget::setTextAlign(const bool& horizontalAlign, const Qt::AlignmentFlag& alignment)
2016-02-17 10:11:00 +03:00
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->changeSelectedGrpoupTextAlignPropperty(horizontalAlign, alignment);
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::setBorders(const BaseDesignIntf::BorderLines& borders)
{
2016-06-10 18:05:18 +03:00
if (activePage())
activePage()->setBorders(borders);
}
2022-10-31 21:20:24 +03:00
void ReportDesignWidget::setBordersExt(
const BaseDesignIntf::BorderLines& border,
const double borderWidth,
const LimeReport::BaseDesignIntf::BorderStyle style,
const QString color
){
if (activePage())
activePage()->setBordersExt(border, borderWidth, style, color);
}
2017-09-21 22:02:13 +03:00
void ReportDesignWidget::prepareReport()
{
m_report->scriptContext()->setInitScript(m_scriptEditor->toPlainText());
report()->clearSelection();
}
2019-05-26 15:15:06 +03:00
void ReportDesignWidget::initThemeIfExist(const QString &themeName, const QString &path)
{
QFile theme(path);
if (theme.exists()){
theme.open(QIODevice::ReadOnly);
QString styleSheet = theme.readAll();
m_themes.insert(themeName, styleSheet);
}
}
2016-06-10 18:05:18 +03:00
void ReportDesignWidget::previewReport()
{
2020-02-03 21:50:28 +03:00
if (report()->isBusy()) return;
2017-09-21 22:02:13 +03:00
prepareReport();
#ifdef HAVE_QTDESIGNER_INTEGRATION
updateDialogs();
#endif
bool showProgressDialog = report()->isShowProgressDialog();
report()->setShowProgressDialog(false);
2016-06-10 18:05:18 +03:00
report()->previewReport();
report()->setShowProgressDialog(showProgressDialog);
2016-06-10 18:05:18 +03:00
}
void ReportDesignWidget::printReport()
{
2020-02-03 21:50:28 +03:00
if (report()->isBusy()) return;
2017-09-21 22:02:13 +03:00
prepareReport();
#ifdef HAVE_QTDESIGNER_INTEGRATION
updateDialogs();
#endif
2016-06-10 18:05:18 +03:00
setCursor(Qt::WaitCursor);
report()->printReport();
setCursor(Qt::ArrowCursor);
}
void ReportDesignWidget::addPage()
{
PageDesignIntf* page = m_report->appendPage("page"+QString::number(m_report->pageCount()+1));
2019-07-23 17:06:07 +03:00
connectPage(page);
PageView* view = createPageView(page);
2016-06-10 18:05:18 +03:00
int index = m_report->pageCount()-1;
2019-07-23 17:06:07 +03:00
m_tabWidget->insertTab(index, view, QIcon(), page->pageItem()->objectName());
m_tabWidget->setTabWhatsThis(index, "page");
2016-06-10 18:05:18 +03:00
m_tabWidget->setCurrentIndex(index);
applyUseGrid();
2016-06-10 18:05:18 +03:00
emit pageAdded(page);
}
void ReportDesignWidget::deleteCurrentPage()
{
if (m_report->pageCount()>1){
QGraphicsView* view = dynamic_cast<QGraphicsView*>(m_tabWidget->currentWidget());
if (view){
PageDesignIntf* page = dynamic_cast<PageDesignIntf*>(view->scene());
if (page){
if (m_report->deletePage(page)){
int index = m_tabWidget->currentIndex();
m_tabWidget->removeTab(m_tabWidget->currentIndex());
if (index>0) m_tabWidget->setCurrentIndex(index-1);
emit pageDeleted();
}
}
}
}
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::editSetting()
{
SettingDialog setting(this);
2019-01-29 23:18:24 +03:00
setting.setSettings(m_settings);
setting.setVerticalGridStep(m_verticalGridStep);
setting.setHorizontalGridStep(m_horizontalGridStep);
setting.setDefaultFont(m_defaultFont);
setting.setSuppressAbsentFieldsAndVarsWarnings(m_report->suppressFieldAndVarError());
setting.setBaseItemPadding(m_report->baseItemPadding());
2019-05-26 15:15:06 +03:00
QStringList themes;
themes.append(QObject::tr("Default"));
foreach(QString theme, m_themes.keys())
if (!themes.contains(QObject::tr(theme.toLatin1())))
themes.append(QObject::tr(theme.toLatin1()));
setting.setDesignerThemes(themes, QObject::tr(m_theme.toLatin1()));
2018-04-10 16:28:48 +03:00
setting.setDesignerLanguages(m_report->designerLanguages(), m_report->currentDesignerLanguage());
QList<QString> unitTypes;
unitTypes << QObject::tr("Millimeters") << QObject::tr("Inches");
setting.setDesignerUnites(unitTypes,
m_defaultUnits == BaseDesignIntf::Millimeters ?
QObject::tr("Millimeters") :
QObject::tr("Inches"));
if (setting.exec()){
m_horizontalGridStep = setting.horizontalGridStep();
m_verticalGridStep = setting.verticalGridStep();
m_defaultFont = setting.defaultFont();
if (setting.reportUnits().compare(QObject::tr("Millimeters")) == 0)
m_defaultUnits = BaseDesignIntf::Millimeters;
else {
m_defaultUnits = BaseDesignIntf::Inches;
}
2019-05-26 15:15:06 +03:00
if (m_localToEng.contains(setting.theme())){
m_theme = m_localToEng.value(setting.theme());
} else {
m_theme = "Default";
}
m_report->setSuppressFieldAndVarError(setting.suppressAbsentFieldsAndVarsWarnings());
m_report->setBaseItemPadding(setting.baseItemPadding());
if (m_report->currentDesignerLanguage() != setting.designerLanguage() ){
m_report->setCurrentDesignerLanguage(setting.designerLanguage());
}
applySettings();
}
}
void ReportDesignWidget::applyUseGrid()
{
int hGridStep = m_useGrid ? m_horizontalGridStep : Const::DEFAULT_GRID_STEP;
int vGridStep = m_useGrid ? m_verticalGridStep : Const::DEFAULT_GRID_STEP;
2019-07-23 17:06:07 +03:00
for(int i = 0; i < m_report->pageCount(); ++i){
m_report->pageAt(i)->setVerticalGridStep(hGridStep);
m_report->pageAt(i)->setHorizontalGridStep(vGridStep);
}
}
void ReportDesignWidget::setUseGrid(bool value)
{
m_useGrid = value;
applyUseGrid();
}
2016-02-17 10:11:00 +03:00
bool ReportDesignWidget::isCanUndo()
{
2016-06-10 18:05:18 +03:00
if (activePage())
return activePage()->isCanUndo();
return false;
2016-02-17 10:11:00 +03:00
}
bool ReportDesignWidget::isCanRedo()
{
2016-06-10 18:05:18 +03:00
if (activePage())
return activePage()->isCanRedo();
return false;
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::slotSelectionChanged()
{
QGraphicsScene* page=dynamic_cast<QGraphicsScene*>(sender());
if (page){
if (page->selectedItems().count()==1){
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(page->selectedItems().at(0));
if (item)
emit (itemSelected(item));
}
else if (page->selectedItems().count()>1){
emit (multiItemSelected());
}
}
}
DataSourceManager* ReportDesignWidget::dataManager()
{
return m_report->dataManager();
}
2016-06-10 18:05:18 +03:00
ScriptEngineManager* ReportDesignWidget::scriptManager()
{
return m_report->scriptManager();
}
ScriptEngineContext*ReportDesignWidget::scriptContext()
{
return m_report->scriptContext();
}
2016-02-17 10:11:00 +03:00
void ReportDesignWidget::slotPagesLoadFinished()
{
applySettings();
2016-06-10 18:05:18 +03:00
//setActivePage(m_report->pageAt(0));
2018-05-31 18:49:57 +03:00
emit loadFinished();
2016-02-17 10:11:00 +03:00
}
void ReportDesignWidget::slotDialogDeleted(QString dialogName)
{
for (int i = 0; i<m_tabWidget->count(); ++i ){
if (m_tabWidget->tabText(i).compare(dialogName) == 0){
delete m_tabWidget->widget(i);
break;
}
}
}
void ReportDesignWidget::lockSelectedItems()
{
if (activePage())
activePage()->lockSelectedItems();
}
void ReportDesignWidget::unlockSelectedItems()
{
if (activePage())
activePage()->unlockSelectedItems();
}
void ReportDesignWidget::selectOneLevelItems()
{
if (activePage())
activePage()->selectOneLevelItems();
}
2016-02-17 10:11:00 +03:00
void ReportDesignWidget::slotDatasourceCollectionLoaded(const QString & /*collectionName*/)
{
}
void ReportDesignWidget::slotSceneRectChanged(QRectF)
{
2016-06-10 18:05:18 +03:00
if (activeView()) activeView()->centerOn(0,0);
}
void ReportDesignWidget::slotCurrentTabChanged(int index)
{
QGraphicsView* view = dynamic_cast<QGraphicsView*>(m_tabWidget->widget(index));
if (view) {
if (view->scene()){
2017-11-24 00:13:47 +03:00
//foreach (QGraphicsItem* item, view->scene()->selectedItems()) item->setSelected(false);
view->scene()->clearSelection();
2016-06-10 18:05:18 +03:00
}
m_zoomer->setView(view);
}
#ifdef HAVE_QTDESIGNER_INTEGRATION
if (activeTabType() == Dialog){
m_dialogDesignerManager->setActiveEditor(m_tabWidget->widget(index));
}
updateDialogs();
#endif
2017-08-05 01:38:19 +03:00
if (activeTabType() == Translations){
2017-11-24 00:13:47 +03:00
m_traslationEditor->setReportEngine(dynamic_cast<ITranslationContainer*>(report()));
2017-08-05 01:38:19 +03:00
}
2017-09-13 17:16:54 +03:00
if (activeTabType() == Script){
2017-09-20 00:51:17 +03:00
m_scriptEditor->initCompleter();
m_scriptEditor->setFocus();
2017-09-13 17:16:54 +03:00
}
2016-06-10 18:05:18 +03:00
emit activePageChanged();
2017-11-24 00:13:47 +03:00
if (view) view->centerOn(0,0);
2016-02-17 10:11:00 +03:00
}
2018-05-08 10:58:43 +03:00
void ReportDesignWidget::slotReportLoaded()
{
QByteArray editorState = m_scriptEditor->saveState();
createTabs();
m_scriptEditor->setPlainText(m_report->scriptContext()->initScript());
m_scriptEditor->restoreState(editorState);
2018-05-31 18:49:57 +03:00
emit loadFinished();
2018-05-08 10:58:43 +03:00
m_dialogChanged = false;
}
2019-02-05 21:51:46 +03:00
void ReportDesignWidget::slotScriptTextChanged()
{
m_report->scriptContext()->setInitScript(m_scriptEditor->toPlainText());
}
2019-07-24 03:13:23 +03:00
void ReportDesignWidget::slotItemPropertyObjectNameChanged(const QString& oldName, const QString& newName)
{
PageDesignIntf* page = qobject_cast<PageDesignIntf*>(sender());
if (page){
ITranslationContainer* tc = dynamic_cast<ITranslationContainer*>(report());
for (int i = 0; i < tc->translations()->values().count(); ++i){
PageTranslation* pt = tc->translations()->values().at(i)->findPageTranslation(page->pageItem()->objectName());
if (pt) pt->renameItem(oldName, newName);
}
}
}
#ifdef HAVE_QTDESIGNER_INTEGRATION
void ReportDesignWidget::addNewDialog()
{
QFile templateUi(":/templates/templates/Dialog.ui");
templateUi.open(QIODevice::ReadOnly|QIODevice::Text);
QString templateStr = templateUi.readAll();
QString dialogName = m_report->scriptContext()->getNewDialogName();
templateStr.replace("$ClassName$", dialogName);
m_report->scriptContext()->addDialog(dialogName,templateStr.toUtf8());
createNewDialogTab(dialogName, templateStr.toUtf8());
}
void ReportDesignWidget::slotDialogChanged(QString )
{
m_dialogChanged = true;
}
void ReportDesignWidget::slotDialogNameChanged(QString oldName, QString newName)
{
for (int i = 0; i < m_tabWidget->count(); ++i){
if (m_tabWidget->tabText(i).compare(oldName) == 0)
m_tabWidget->setTabText(i, newName);
}
m_report->scriptContext()->changeDialogName(oldName, newName);
}
#endif
2017-08-19 00:16:55 +03:00
void ReportDesignWidget::slotPagePropertyObjectNameChanged(const QString &oldValue, const QString &newValue)
{
2019-07-24 03:13:23 +03:00
ITranslationContainer* tc = dynamic_cast<ITranslationContainer*>(report());
foreach(ReportTranslation* translation, tc->translations()->values()){
translation->renamePage(oldValue, newValue);
}
2017-08-19 00:16:55 +03:00
for (int i = 0; i < m_tabWidget->count(); ++i ){
if (m_tabWidget->tabText(i).compare(oldValue) == 0){
2017-08-19 01:24:20 +03:00
QGraphicsView* view = dynamic_cast<QGraphicsView*>(m_tabWidget->widget(i));
if (view){
PageDesignIntf* page = dynamic_cast<PageDesignIntf*>(view->scene());
if (page->pageItem() == sender())
m_tabWidget->setTabText(i, newValue);
}
2017-08-19 00:16:55 +03:00
}
}
}
void ReportDesignWidget::slotTabMoved(int from, int to)
{
Q_UNUSED(from)
Q_UNUSED(to)
2017-08-19 00:16:55 +03:00
QList<PageDesignIntf*> pages;
for ( int i = 0; i < m_tabWidget->tabBar()->count(); ++i){
QGraphicsView* view = dynamic_cast<QGraphicsView*>(m_tabWidget->widget(i));
if (view){
PageDesignIntf* page = dynamic_cast<PageDesignIntf*>(view->scene());
if (page){
pages.append(page);
}
}
}
m_report->reorderPages(pages);
}
2016-02-17 10:19:50 +03:00
bool ReportDesignWidget::eventFilter(QObject *target, QEvent *event)
{
if (event->type() == QEvent::Wheel){
QWheelEvent* we = dynamic_cast<QWheelEvent*>(event);
if (QApplication::keyboardModifiers()==Qt::ControlModifier){
#if QT_VERSION < QT_VERSION_CHECK(5,12,3)
2016-02-17 10:19:50 +03:00
if(we->delta()<0) scale(1.2,1.2);
else scale(1/1.2,1/1.2);
2021-08-24 08:37:40 +03:00
#else
if(we->pixelDelta().x()<0) scale(1.2,1.2);
else scale(1/1.2,1/1.2);
#endif
2016-02-17 10:19:50 +03:00
}
}
return QWidget::eventFilter(target,event);
}
2016-02-17 10:11:00 +03:00
void ReportDesignWidget::clear()
{
m_report->clearReport();
2016-06-10 18:05:18 +03:00
m_tabWidget->clear();
m_report->setReportFileName("");
m_report->scriptContext()->setInitScript("");
m_scriptEditor->setPlainText("");
2016-02-17 10:11:00 +03:00
}
void PageView::setPageItem(PageItemDesignIntf *pageItem)
{
if (!pageItem) return;
m_pageItem = pageItem;
if (!m_horizontalRuller){
m_horizontalRuller = new Ruler(Ruler::Horizontal, this);
m_horizontalRuller->setPage(pageItem);
}
if (!m_verticalRuller){
m_verticalRuller = new Ruler(Ruler::Vertical, this);
m_verticalRuller->setPage(pageItem);
}
}
bool PageView::viewportEvent(QEvent *event)
{
switch (event->type()) {
case QEvent::MouseMove:
2019-07-23 17:06:07 +03:00
if (m_horizontalRuller && m_verticalRuller){
m_horizontalRuller->setMousePos(dynamic_cast<QMouseEvent*>(event)->pos());
m_verticalRuller->setMousePos(dynamic_cast<QMouseEvent*>(event)->pos());
m_horizontalRuller->update();
m_verticalRuller->update();
}
break;
//case QEvent::Resize:
case QEvent::Paint:
2019-07-23 17:06:07 +03:00
if (m_horizontalRuller && m_verticalRuller){
int x = mapFromScene(m_pageItem->boundingRect().x(),m_pageItem->boundingRect().y()).x();
int y = mapFromScene(m_pageItem->boundingRect().x(),m_pageItem->boundingRect().y()).y();
int width = mapFromScene(m_pageItem->boundingRect().bottomRight().x(),m_pageItem->boundingRect().bottomRight().y()).x();
int height = mapFromScene(m_pageItem->boundingRect().bottomRight().x(),m_pageItem->boundingRect().bottomRight().y()).y();
x = x < 0 ? 0 : x;
y = y < 0 ? 0 : y;
m_horizontalRuller->setGeometry(x+20, 0, (width-x), 20);
m_verticalRuller->setGeometry(0, y+20, 20, (height - y));
m_verticalRuller->update();
m_horizontalRuller->update();
2022-04-30 14:46:49 +03:00
}
break;
default:
break;
}
return QGraphicsView::viewportEvent(event);
}
void Ruler::setPage(PageItemDesignIntf *page)
{
m_page = page;
}
void Ruler::paintEvent(QPaintEvent *event){
QPainter painter(this);
2021-08-23 08:07:08 +03:00
painter.setBrush(palette().window());
painter.setPen(Qt::NoPen);
painter.drawRect(event->rect());
2021-08-23 08:07:08 +03:00
// painter.setPen(palette().windowText().color());
if (m_page){
qreal rulerWidth = m_page->geometry().width() / m_page->unitFactor();
qreal rulerHeight = m_page->geometry().height() / m_page->unitFactor();
QGraphicsView* view = qobject_cast<QGraphicsView*>(parent());
int hStartPos = view->mapFromScene(0,0).x();
int vStartPos = view->mapFromScene(0,0).y();
QFont font = painter.font();
font.setPointSize(7);
painter.setFont(font);
switch (m_type) {
case Horizontal:
painter.setPen(Qt::NoPen);
2021-08-23 08:07:08 +03:00
if (isColorDark(palette().window().color()))
painter.setBrush(QColor("#64893d"));
else
painter.setBrush(QColor("#b5da91"));
drawItemWithChildren(&painter, m_page);
2021-08-23 08:07:08 +03:00
painter.setPen(palette().windowText().color());
for (int i = 0; i < rulerWidth / 10; ++i){
int hs10 = view->mapFromScene(QPointF(m_page->geometry().topLeft().x() + i * 10 * m_page->unitFactor(), 0)).x();
int hs5 = view->mapFromScene(QPointF(m_page->geometry().topLeft().x() + i * 10 * m_page->unitFactor() + 5 * m_page->unitFactor(), 0)).x();
if (hs10 > 0){
if (hStartPos > 0){
hs10 -= hStartPos;
hs5 -= hStartPos;
}
painter.drawLine(hs10, 15, hs10, 20);
painter.drawLine(hs5, 10, hs5, 20);
if ( i > 0)
2021-08-23 08:07:08 +03:00
painter.drawText(QPoint(hs10 - (painter.fontMetrics().boundingRect(QString::number(i)).width()/2), 12),
QString::number(i));
}
}
2021-08-23 08:07:08 +03:00
painter.setPen(palette().windowText().color());
painter.drawLine(m_mousePos.x() - (hStartPos > 0 ? hStartPos : 0) , 0,
m_mousePos.x() - (hStartPos > 0 ? hStartPos : 0) , 20);
break;
case Vertical:
painter.setPen(Qt::NoPen);
2021-08-23 08:07:08 +03:00
if (isColorDark(palette().window().color()))
painter.setBrush(QColor("#64893d"));
else
painter.setBrush(QColor("#b5da91"));
drawItemWithChildren(&painter, m_page);
2021-08-23 08:07:08 +03:00
painter.setPen(palette().windowText().color());
for (int i = 0; i < rulerHeight / 10; ++i){
int vs10 = view->mapFromScene(QPointF(0, m_page->geometry().topLeft().y()+i * 10 * m_page->unitFactor())).y();
int vs5 = view->mapFromScene(QPointF(0, m_page->geometry().topLeft().y()+i * 10 * m_page->unitFactor() + 5 * m_page->unitFactor())).y();
if (vs10 > 0){
if (vStartPos > 0){
vs10 -= vStartPos;
vs5 -= vStartPos;
}
painter.drawLine(15, vs10, 20, vs10);
if ( i > 0 )
2021-08-23 08:07:08 +03:00
painter.drawText(QPoint( (15 - painter.fontMetrics().boundingRect(QString::number(i)).width()) / 2 ,
vs10 + (painter.fontMetrics().height()/2)), QString::number(i));
painter.drawLine(10, vs5, 20, vs5);
}
}
2021-08-23 08:07:08 +03:00
painter.setPen(palette().windowText().color());
painter.drawLine(0, m_mousePos.y() - (vStartPos > 0 ? vStartPos : 0),
20, m_mousePos.y() - (vStartPos > 0 ? vStartPos : 0));
break;
}
}
}
void Ruler::drawItemWithChildren(QPainter* painter, BaseDesignIntf *item)
{
foreach(BaseDesignIntf* child, item->childBaseItems()){
if (!child->childBaseItems().isEmpty())
drawItemWithChildren(painter, child);
else drawItem(painter, child);
}
drawItem(painter, item);
}
void Ruler::drawItem(QPainter* painter, BaseDesignIntf *item)
{
if (!item->isSelected()) return;
QGraphicsView* view = qobject_cast<QGraphicsView*>(parent());
int hStartPos = view->mapFromScene(0,0).x();
int vStartPos = view->mapFromScene(0,0).y();
2019-06-26 02:23:12 +03:00
int itemWidth = view->mapFromScene(item->mapToScene(item->geometry().width(),0).x() - item->mapToScene(0,0).x(), 0).x() - hStartPos;
int itemHeight = view->mapFromScene(0, item->mapToScene(0, item->geometry().height()).y() - item->mapToScene(0,0).y()).y() - vStartPos;
switch (m_type) {
case Horizontal:
if (item->isSelected())
2019-06-26 02:23:12 +03:00
painter->drawRect(view->mapFromScene(item->mapToScene(0,0)).x() - (hStartPos > 0 ? hStartPos : 0) , 0,
itemWidth, 20);
break;
case Vertical:
if (item->isSelected())
2019-06-26 02:23:12 +03:00
painter->drawRect(0, view->mapFromScene(item->mapToScene(0, 0)).y() - (vStartPos > 0 ? vStartPos : 0),
20, itemHeight);
break;
}
}
2016-02-17 10:11:00 +03:00
}