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 "lrtextitemeditor.h"
|
|
|
|
#include "ui_lrtextitemeditor.h"
|
|
|
|
|
|
|
|
#include "lrdatadesignintf.h"
|
2024-09-04 17:31:16 +03:00
|
|
|
#include "lrdatasourcemanager.h"
|
2017-09-21 00:44:09 +03:00
|
|
|
#include "lrscripteditor.h"
|
2024-09-04 17:31:16 +03:00
|
|
|
#include "lrscriptenginemanager.h"
|
2016-02-17 10:28:27 +03:00
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QScrollBar>
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
namespace LimeReport {
|
2016-03-04 04:53:34 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
TextItemEditor::TextItemEditor(LimeReport::TextItem* item, LimeReport::PageDesignIntf* page,
|
|
|
|
QSettings* settings, QWidget* parent):
|
2016-02-17 10:11:00 +03:00
|
|
|
QWidget(parent),
|
2024-09-04 17:31:16 +03:00
|
|
|
ui(new Ui::TextItemEditor),
|
|
|
|
m_textItem(item),
|
|
|
|
m_page(page),
|
|
|
|
m_settings(settings),
|
|
|
|
m_ownedSettings(false),
|
|
|
|
m_isReadingSetting(false)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
initUI();
|
|
|
|
setWindowIcon(QIcon(":/items/images/TextItem"));
|
|
|
|
readSetting();
|
2024-09-04 17:31:16 +03:00
|
|
|
connect(ui->codeEditor, SIGNAL(splitterMoved(int, int)), this,
|
|
|
|
SLOT(slotSplitterMoved(int, int)));
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2024-09-04 17:31:16 +03:00
|
|
|
m_settings = value;
|
|
|
|
m_ownedSettings = false;
|
2016-02-17 10:11:00 +03:00
|
|
|
readSetting();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QSettings* TextItemEditor::settings()
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_settings) {
|
2016-02-17 10:11:00 +03:00
|
|
|
return m_settings;
|
|
|
|
} else {
|
2024-09-04 17:31:16 +03:00
|
|
|
m_settings = new QSettings("LimeReport", QCoreApplication::applicationName());
|
2016-02-17 10:11:00 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-09-21 00:44:09 +03:00
|
|
|
void TextItemEditor::closeEvent(QCloseEvent* event)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (settings() != 0) {
|
2017-09-21 00:44:09 +03:00
|
|
|
settings()->beginGroup("TextItemEditor");
|
2024-09-04 17:31:16 +03:00
|
|
|
settings()->setValue("CodeEditorState", ui->codeEditor->saveState());
|
2017-09-21 00:44:09 +03:00
|
|
|
settings()->endGroup();
|
|
|
|
}
|
|
|
|
QWidget::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
void TextItemEditor::on_pbOk_clicked()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_textItem->content() != ui->codeEditor->toPlainText()) {
|
2017-09-21 00:44:09 +03:00
|
|
|
m_textItem->setContent(ui->codeEditor->toPlainText());
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextItemEditor::initUI()
|
|
|
|
{
|
|
|
|
QStringList dataWords;
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
LimeReport::DataSourceManager* dm = m_page->datasourceManager();
|
2016-02-17 10:28:27 +03:00
|
|
|
LimeReport::ScriptEngineManager& se = LimeReport::ScriptEngineManager::instance();
|
|
|
|
se.setDataManager(dm);
|
|
|
|
|
2017-09-21 00:44:09 +03:00
|
|
|
ScriptEditor* scriptEditor = dynamic_cast<ScriptEditor*>(ui->codeEditor);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (scriptEditor) {
|
2017-09-21 00:44:09 +03:00
|
|
|
scriptEditor->setReportPage(m_page);
|
|
|
|
scriptEditor->setPageBand(findParentBand());
|
|
|
|
scriptEditor->setPlainText(m_textItem->content());
|
2016-04-21 01:15:15 +03:00
|
|
|
}
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void TextItemEditor::on_pbCancel_clicked() { close(); }
|
2016-02-17 10:11:00 +03:00
|
|
|
|
|
|
|
void TextItemEditor::readSetting()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (settings() == 0)
|
|
|
|
return;
|
2016-02-17 10:11:00 +03:00
|
|
|
|
|
|
|
m_isReadingSetting = true;
|
|
|
|
|
|
|
|
settings()->beginGroup("TextItemEditor");
|
|
|
|
QVariant v = settings()->value("Geometry");
|
2024-09-04 17:31:16 +03:00
|
|
|
if (v.isValid()) {
|
2016-02-17 10:11:00 +03:00
|
|
|
restoreGeometry(v.toByteArray());
|
|
|
|
}
|
2017-09-21 00:44:09 +03:00
|
|
|
v = settings()->value("CodeEditorState");
|
2024-09-04 17:31:16 +03:00
|
|
|
if (v.isValid()) {
|
2017-09-21 00:44:09 +03:00
|
|
|
ui->codeEditor->restoreState(v.toByteArray());
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
2019-01-29 23:18:24 +03:00
|
|
|
settings()->endGroup();
|
|
|
|
settings()->beginGroup("ScriptEditor");
|
|
|
|
QVariant fontName = settings()->value("DefaultFontName");
|
2024-09-04 17:31:16 +03:00
|
|
|
if (fontName.isValid()) {
|
2019-01-29 23:18:24 +03:00
|
|
|
QVariant fontSize = settings()->value("DefaultFontSize");
|
2024-09-04 17:31:16 +03:00
|
|
|
ui->codeEditor->setEditorFont(QFont(fontName.toString(), fontSize.toInt()));
|
2019-01-29 23:18:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant tabIndention = settings()->value("TabIndention");
|
2024-09-04 17:31:16 +03:00
|
|
|
if (tabIndention.isValid()) {
|
2019-01-29 23:18:24 +03:00
|
|
|
ui->codeEditor->setTabIndention(tabIndention.toInt());
|
|
|
|
} else {
|
|
|
|
ui->codeEditor->setTabIndention(LimeReport::Const::DEFAULT_TAB_INDENTION);
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
settings()->endGroup();
|
|
|
|
|
|
|
|
m_isReadingSetting = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextItemEditor::writeSetting()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (settings() != 0) {
|
2016-02-17 10:11:00 +03:00
|
|
|
settings()->beginGroup("TextItemEditor");
|
2024-09-04 17:31:16 +03:00
|
|
|
settings()->setValue("Geometry", saveGeometry());
|
|
|
|
settings()->setValue("CodeEditorState", ui->codeEditor->saveState());
|
2016-02-17 10:11:00 +03:00
|
|
|
settings()->endGroup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void TextItemEditor::slotSplitterMoved(int, int) { writeSetting(); }
|
2016-02-17 10:18:19 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
BandDesignIntf* TextItemEditor::findParentBand()
|
2016-04-21 01:15:15 +03:00
|
|
|
{
|
|
|
|
BandDesignIntf* result = 0;
|
|
|
|
BaseDesignIntf* item = m_textItem;
|
2024-09-04 17:31:16 +03:00
|
|
|
while (true) {
|
2016-04-21 01:15:15 +03:00
|
|
|
item = dynamic_cast<BaseDesignIntf*>(item->parentItem());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (item) {
|
2016-04-21 01:15:15 +03:00
|
|
|
result = dynamic_cast<BandDesignIntf*>(item);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (result)
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
break;
|
2016-04-21 01:15:15 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-04 04:53:34 +03:00
|
|
|
} // namespace LimeReport
|