0
0
mirror of https://github.com/fralx/LimeReport.git synced 2025-09-23 08:29:07 +03:00

Translation has been updated

This commit is contained in:
Arin Alexander
2017-08-05 01:38:19 +03:00
parent 881089fd2f
commit 8c5a9fcd91
21 changed files with 575 additions and 38 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 655 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 867 B

View File

@@ -0,0 +1,165 @@
#include "translationeditor.h"
#include "ui_translationeditor.h"
#include "lrreportengine.h"
#include "lrreportengine_p.h"
#include "lrreporttranslation.h"
namespace LimeReport {
TranslationEditor::TranslationEditor(QWidget *parent) :
QWidget(parent),
ui(new Ui::TranslationEditor), m_translationContainer(0)
{
ui->setupUi(this);
ui->splitter_3->setStretchFactor(1,10);
ui->splitter_3->setStretchFactor(0,2);
ui->splitter_2->setStretchFactor(1,2);
ui->splitter->setStretchFactor(0,2);
QTableWidgetItem* item = new QTableWidgetItem();
item->setIcon(QIcon(":/translationeditor/images/checked.png"));
ui->tbStrings->setColumnCount(4);
ui->tbStrings->setColumnWidth(0,30);
ui->tbStrings->setColumnWidth(1,100);
ui->tbStrings->setColumnWidth(2,100);
ui->tbStrings->setHorizontalHeaderItem(0,item);
ui->tbStrings->setHorizontalHeaderItem(1,new QTableWidgetItem(tr("Report Item")));
ui->tbStrings->setHorizontalHeaderItem(2,new QTableWidgetItem(tr("Property")));
ui->tbStrings->setHorizontalHeaderItem(3,new QTableWidgetItem(tr("Source text")));
//ui->tbStrings->setSortingEnabled(true);
}
void TranslationEditor::setReportEngine(ITranslationContainer* translationContainer)
{
m_translationContainer = translationContainer;
if (m_translationContainer){
m_translationContainer->updateTranslations();
updateUi();
}
}
TranslationEditor::~TranslationEditor()
{
delete ui;
}
void TranslationEditor::updateUi()
{
ui->lvLanguages->clear();
Q_ASSERT(m_translationContainer != 0);
if (m_translationContainer){
Translations* translations = m_translationContainer->translations();
Q_ASSERT(translations != 0);
if (translations){
foreach(QLocale::Language language, translations->keys()){
ui->lvLanguages->addItem(QLocale::languageToString(language));
}
if (!translations->keys().isEmpty()){
ui->lvLanguages->item(0)->setSelected(true);
activateLanguage(translations->keys().at(0));
}
}
}
}
void TranslationEditor::activateLanguage(QLocale::Language language)
{
ui->teTranslation->setEnabled(false);
ui->cbChecked->setEnabled(false);
ui->twPages->clear();
Translations* translations = m_translationContainer->translations();
Q_ASSERT(translations != 0);
if (translations){
m_currentReportTranslation = translations->value(language);
Q_ASSERT(m_currentReportTranslation != 0);
if (m_currentReportTranslation){
foreach(PageTranslation* pageTranslation, m_currentReportTranslation->pagesTranslation()){
QTreeWidgetItem* pageItem = new QTreeWidgetItem();
pageItem->setText(0,pageTranslation->pageName);
ui->twPages->addTopLevelItem(pageItem);
}
}
if (ui->twPages->topLevelItem(0)){
ui->twPages->topLevelItem(0)->setSelected(true);
activatePage(m_currentReportTranslation->findPageTranslation(ui->twPages->topLevelItem(0)->text(0)));
}
}
}
void TranslationEditor::activatePage(PageTranslation* pageTranslation)
{
ui->teTranslation->setEnabled(false);
ui->cbChecked->setEnabled(false);
Q_ASSERT(pageTranslation != 0);
if(pageTranslation){
ui->tbStrings->clearContents();
ui->tbStrings->setRowCount(0);
m_currentPageTranslation = pageTranslation;
QStringList items = pageTranslation->itemsTranslation.keys();
items.sort();
foreach(QString itemName, items){
ItemTranslation* itemTranslation = pageTranslation->itemsTranslation.value(itemName);
int rowIndex = ui->tbStrings->rowCount();
ui->tbStrings->setRowCount(rowIndex+1);
foreach(PropertyTranslation* propertyTranslation, itemTranslation->propertyesTranslation){
QTableWidgetItem* checkItem = new QTableWidgetItem();
if (propertyTranslation->checked)
checkItem->setIcon(QIcon(":/translationeditor/images/checked.png"));
ui->tbStrings->setItem(rowIndex,0,checkItem);
ui->tbStrings->setItem(rowIndex,1,new QTableWidgetItem(itemTranslation->itemName));
ui->tbStrings->setItem(rowIndex,2,new QTableWidgetItem(propertyTranslation->propertyName));
ui->tbStrings->setItem(rowIndex,3,new QTableWidgetItem(propertyTranslation->sourceValue));
}
}
}
}
void TranslationEditor::activateTranslation(const QString& itemName, const QString& propertyName)
{
Q_ASSERT(m_currentPageTranslation != 0);
if (m_currentPageTranslation){
ItemTranslation* itemTranslation = m_currentPageTranslation->itemsTranslation.value(itemName);
Q_ASSERT(itemTranslation !=0 );
if (itemTranslation){
m_currentPropertyTranslation = m_currentPageTranslation->itemsTranslation.value(itemName)->findProperty(propertyName);
Q_ASSERT(m_currentPropertyTranslation != 0);
if (m_currentPropertyTranslation){
ui->teTranslation->setEnabled(true);
ui->cbChecked->setEnabled(true);
ui->teTranslation->setText(m_currentPropertyTranslation->value);
ui->cbChecked->setChecked(m_currentPropertyTranslation->checked);
}
}
}
}
void TranslationEditor::on_tbStrings_itemSelectionChanged()
{
activateTranslation(ui->tbStrings->item(ui->tbStrings->currentRow(),1)->text(), ui->tbStrings->item(ui->tbStrings->currentRow(),2)->text());
}
void TranslationEditor::on_teTranslation_textChanged()
{
m_currentPropertyTranslation->value = ui->teTranslation->toPlainText();
}
void TranslationEditor::on_cbChecked_toggled(bool checked)
{
m_currentPropertyTranslation->checked = checked;
ui->tbStrings->item(ui->tbStrings->currentRow(),0)->setIcon(checked ? QIcon(":/translationeditor/images/checked.png"):QIcon());
}
void TranslationEditor::on_twPages_itemSelectionChanged()
{
if (!ui->twPages->selectedItems().isEmpty()){
activatePage(m_currentReportTranslation->findPageTranslation(ui->twPages->selectedItems().at(0)->text(0)));
}
}
} //namespace LimeReport

View File

@@ -0,0 +1,45 @@
#ifndef TRANSLATIONEDITOR_H
#define TRANSLATIONEDITOR_H
#include <QWidget>
#include <QLocale>
#include <QTreeWidgetItem>
#include "lrreporttranslation.h"
namespace LimeReport {
namespace Ui {
class TranslationEditor;
}
class TranslationEditor : public QWidget
{
Q_OBJECT
public:
explicit TranslationEditor(QWidget *parent = 0);
void setReportEngine(ITranslationContainer* translationContainer);
~TranslationEditor();
void updateUi();
void activateLanguage(QLocale::Language language);
void activatePage(PageTranslation* pageTranslation);
void activateTranslation(const QString& itemName, const QString& propertyName);
private slots:
void on_tbStrings_itemSelectionChanged();
void on_teTranslation_textChanged();
void on_cbChecked_toggled(bool checked);
void on_twPages_itemSelectionChanged();
private:
Ui::TranslationEditor *ui;
ITranslationContainer* m_translationContainer;
QMap<QString, ReportTranslation*> m_reportTranslations;
QMap<QString, PageTranslation> m_pageTranslations;
ReportTranslation* m_currentReportTranslation;
PageTranslation* m_currentPageTranslation;
PropertyTranslation* m_currentPropertyTranslation;
};
} //namespace LimeReport
#endif // TRANSLATIONEDITOR_H

View File

@@ -0,0 +1,8 @@
<RCC>
<qresource prefix="/translationeditor">
<file>images/add.png</file>
<file>images/remove.png</file>
<file>images/checked.png</file>
<file>images/question.png</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,214 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LimeReport::TranslationEditor</class>
<widget class="QWidget" name="LimeReport::TranslationEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>873</width>
<height>525</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSplitter" name="splitter_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QFrame" name="frame_2">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QSplitter" name="splitter_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Languages</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<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="QToolButton" name="toolButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="translationeditor.qrc">
<normaloff>:/translationeditor/images/add.png</normaloff>:/translationeditor/images/add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_2">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="translationeditor.qrc">
<normaloff>:/translationeditor/images/remove.png</normaloff>:/translationeditor/images/remove.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="lvLanguages"/>
</item>
</layout>
</widget>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Pages</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTreeWidget" name="twPages">
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Strings</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QTableWidget" name="tbStrings">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="columnCount">
<number>2</number>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string/>
</property>
</column>
<column>
<property name="text">
<string>Source Text</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Translation</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QTextEdit" name="teTranslation"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<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>
<item>
<widget class="QCheckBox" name="cbChecked">
<property name="text">
<string>Checked</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="translationeditor.qrc"/>
</resources>
<connections/>
</ui>