0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-25 00:54:39 +03:00
LimeReport/limereport/items/lrtextitemeditor.cpp

202 lines
6.4 KiB
C++
Raw Permalink Normal View History

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