mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-01-31 16:39:59 +01:00
NameList widget : add a combo box for easily paste texts, like the variables for title block.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5687 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
67
sources/NameList/ui/namelistdialog.cpp
Normal file
67
sources/NameList/ui/namelistdialog.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
Copyright 2006-2018 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "namelistdialog.h"
|
||||
#include "ui_namelistdialog.h"
|
||||
#include "namelistwidget.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
|
||||
NameListDialog::NameListDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::NameListDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
m_namelist_widget = new NameListWidget(this);
|
||||
ui->m_main_layout->insertWidget(1, m_namelist_widget);
|
||||
#ifdef Q_OS_MAC
|
||||
this->setWindowFlags(Qt::Sheet);
|
||||
#endif
|
||||
}
|
||||
|
||||
NameListDialog::~NameListDialog() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void NameListDialog::setInformationText(const QString &text) {
|
||||
ui->m_top_label->setText(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NameListDialog::namelistWidget
|
||||
* @return the name list widget used by this dialog.
|
||||
* The ownership of the namelistwidget stay to this dialog
|
||||
*/
|
||||
NameListWidget *NameListDialog::namelistWidget() const {
|
||||
return m_namelist_widget;
|
||||
}
|
||||
|
||||
void NameListDialog::setHelpText(const QString &text)
|
||||
{
|
||||
m_help_text = text;
|
||||
if (!m_help_text.isEmpty())
|
||||
{
|
||||
QPushButton *button = ui->m_button_box->addButton(QDialogButtonBox::Help);
|
||||
connect(button, &QPushButton::clicked, this, &NameListDialog::showHelpDialog);
|
||||
}
|
||||
}
|
||||
|
||||
void NameListDialog::showHelpDialog() {
|
||||
QMessageBox::information(this, tr("Variables de cartouche"), m_help_text);
|
||||
}
|
||||
52
sources/NameList/ui/namelistdialog.h
Normal file
52
sources/NameList/ui/namelistdialog.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
Copyright 2006-2018 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef NAMELISTDIALOG_H
|
||||
#define NAMELISTDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class NameListWidget;
|
||||
|
||||
namespace Ui {
|
||||
class NameListDialog;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The NameListDialog class
|
||||
* Provide a dialog for let user define localized string;
|
||||
*/
|
||||
class NameListDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NameListDialog(QWidget *parent = nullptr);
|
||||
~NameListDialog();
|
||||
|
||||
void setInformationText(const QString &text);
|
||||
NameListWidget *namelistWidget() const;
|
||||
void setHelpText(const QString &text);
|
||||
void showHelpDialog();
|
||||
|
||||
private:
|
||||
Ui::NameListDialog *ui;
|
||||
NameListWidget *m_namelist_widget = nullptr;
|
||||
QString m_help_text;
|
||||
};
|
||||
|
||||
#endif // NAMELISTDIALOG_H
|
||||
77
sources/NameList/ui/namelistdialog.ui
Normal file
77
sources/NameList/ui/namelistdialog.ui
Normal file
@@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>NameListDialog</class>
|
||||
<widget class="QDialog" name="NameListDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>507</width>
|
||||
<height>370</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="m_main_layout">
|
||||
<item>
|
||||
<widget class="QLabel" name="m_top_label">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::RichText</enum>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="m_button_box">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>m_button_box</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>NameListDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>m_button_box</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>NameListDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
168
sources/NameList/ui/namelistwidget.cpp
Normal file
168
sources/NameList/ui/namelistwidget.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
Copyright 2006-2018 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "namelistwidget.h"
|
||||
#include "ui_namelistwidget.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QClipboard>
|
||||
|
||||
NameListWidget::NameListWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::NameListWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->m_clipboard_cb->setHidden(true);
|
||||
connect(ui->m_add_line_pb, &QPushButton::clicked, this, &NameListWidget::addLine);
|
||||
}
|
||||
|
||||
NameListWidget::~NameListWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NameListWidget::addLine
|
||||
* Add a new line to the name list widget
|
||||
*/
|
||||
void NameListWidget::addLine()
|
||||
{
|
||||
clean();
|
||||
if (m_read_only) {
|
||||
return;
|
||||
}
|
||||
QTreeWidgetItem *qtwi = new QTreeWidgetItem();
|
||||
qtwi->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||
ui->m_tree->addTopLevelItem(qtwi);
|
||||
ui->m_tree->setCurrentItem(qtwi);
|
||||
ui->m_tree->editItem(qtwi);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NameListWidget::setNames
|
||||
* Set the current names of this dialog from @name_list
|
||||
* @param name_list
|
||||
*/
|
||||
void NameListWidget::setNames(const NamesList &name_list)
|
||||
{
|
||||
for (QString lang : name_list.langs())
|
||||
{
|
||||
QString value = name_list[lang];
|
||||
QStringList values;
|
||||
values << lang << value;
|
||||
QTreeWidgetItem *qtwi = new QTreeWidgetItem(values);
|
||||
if (!m_read_only) {
|
||||
qtwi->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||
}
|
||||
ui->m_tree->addTopLevelItem(qtwi);
|
||||
ui->m_tree->sortItems(0, Qt::AscendingOrder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NameListWidget::names
|
||||
* @return the current name list edited by this dialog
|
||||
*/
|
||||
NamesList NameListWidget::names() const
|
||||
{
|
||||
NamesList nl_;
|
||||
|
||||
int names_count = ui->m_tree->topLevelItemCount();
|
||||
for (int i = 0 ; i < names_count ; ++ i)
|
||||
{
|
||||
QString lang = ui->m_tree->topLevelItem(i)->text(0);
|
||||
QString value = ui->m_tree->topLevelItem(i)->text(1);
|
||||
if (lang != "" && value != "") {
|
||||
nl_.addName(lang, value);
|
||||
}
|
||||
}
|
||||
|
||||
return nl_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NameListWidget::setReadOnly
|
||||
* Set this dialog to read only or not.
|
||||
* @param ro
|
||||
*/
|
||||
void NameListWidget::setReadOnly(bool ro)
|
||||
{
|
||||
m_read_only = ro;
|
||||
|
||||
int names_count = ui->m_tree->topLevelItemCount() - 1;
|
||||
for (int i = names_count ; i >= 0 ; -- i)
|
||||
{
|
||||
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
if (!m_read_only) {
|
||||
flags |= Qt::ItemIsEditable;
|
||||
}
|
||||
ui->m_tree->topLevelItem(i)->setFlags(flags);
|
||||
}
|
||||
ui->m_add_line_pb->setEnabled(!ro);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NameListWidget::isEmpty
|
||||
* @return true if empty.
|
||||
* An empty dialog, is a dialog without any edited lang.
|
||||
*/
|
||||
bool NameListWidget::isEmpty() const {
|
||||
return names().isEmpty();
|
||||
}
|
||||
|
||||
void NameListWidget::setClipboardValue(QHash<QString, QString> value)
|
||||
{
|
||||
if (value.isEmpty()) {
|
||||
ui->m_clipboard_cb->setHidden(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->m_clipboard_cb->setVisible(true);
|
||||
|
||||
QStringList list = value.keys();
|
||||
list.sort();
|
||||
for (QString key : list) {
|
||||
ui->m_clipboard_cb->addItem(key, value.value(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NameListWidget::clean
|
||||
* Clean the lists of names by removing the emtpy lines
|
||||
*/
|
||||
void NameListWidget::clean()
|
||||
{
|
||||
int names_count = ui->m_tree->topLevelItemCount() - 1;
|
||||
for (int i = names_count ; i >= 0 ; -- i)
|
||||
{
|
||||
if (ui->m_tree->topLevelItem(i)->text(0).isEmpty() &&
|
||||
ui->m_tree->topLevelItem(i)->text(1).isEmpty())
|
||||
{
|
||||
ui->m_tree->takeTopLevelItem(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NameListWidget::on_m_clipboard_cb_activated(int index)
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
clipboard->setText(ui->m_clipboard_cb->currentData().toString());
|
||||
ui->m_clipboard_cb->setCurrentIndex(0);
|
||||
}
|
||||
58
sources/NameList/ui/namelistwidget.h
Normal file
58
sources/NameList/ui/namelistwidget.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
Copyright 2006-2018 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef NAMELISTWIDGET_H
|
||||
#define NAMELISTWIDGET_H
|
||||
|
||||
#include "nameslist.h"
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class NameListWidget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The NameListWidget class
|
||||
* Provide a widget for let user define localized string;
|
||||
*/
|
||||
class NameListWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NameListWidget(QWidget *parent = nullptr);
|
||||
~NameListWidget();
|
||||
|
||||
void addLine();
|
||||
void setNames (const NamesList &name_list);
|
||||
NamesList names() const;
|
||||
void setReadOnly(bool ro);
|
||||
bool isEmpty() const;
|
||||
void setClipboardValue (QHash <QString, QString> value);
|
||||
|
||||
private slots:
|
||||
void on_m_clipboard_cb_activated(int index);
|
||||
|
||||
private:
|
||||
void clean();
|
||||
|
||||
private:
|
||||
Ui::NameListWidget *ui;
|
||||
bool m_read_only = false;
|
||||
};
|
||||
|
||||
#endif // NAMELISTWIDGET_H
|
||||
65
sources/NameList/ui/namelistwidget.ui
Normal file
65
sources/NameList/ui/namelistwidget.ui
Normal file
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>NameListWidget</class>
|
||||
<widget class="QWidget" name="NameListWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="m_tree">
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Langue</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Texte</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="m_add_line_pb">
|
||||
<property name="text">
|
||||
<string>Ajouter une ligne</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../qelectrotech.qrc">
|
||||
<normaloff>:/ico/16x16/list-add.png</normaloff>:/ico/16x16/list-add.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="m_clipboard_cb">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Copier dans le presse papier</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../qelectrotech.qrc">
|
||||
<normaloff>:/ico/16x16/edit-paste.png</normaloff>:/ico/16x16/edit-paste.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../../qelectrotech.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user