mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Converted the "project properties" dialog to ConfigDialog.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@1882 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
00affb107e
commit
70dd359f25
252
sources/projectconfigpages.cpp
Normal file
252
sources/projectconfigpages.cpp
Normal file
@ -0,0 +1,252 @@
|
||||
#include "projectconfigpages.h"
|
||||
#include "qeticons.h"
|
||||
#include "qetproject.h"
|
||||
#include "borderpropertieswidget.h"
|
||||
#include "conductorpropertieswidget.h"
|
||||
#include "titleblockpropertieswidget.h"
|
||||
#include <QtGui>
|
||||
|
||||
/**
|
||||
Constructor
|
||||
@param project Project this page is editing.
|
||||
@param parent Parent QWidget
|
||||
*/
|
||||
ProjectConfigPage::ProjectConfigPage(QETProject *project, QWidget *parent) :
|
||||
ConfigPage(parent),
|
||||
project_(project)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
Destructor
|
||||
*/
|
||||
ProjectConfigPage::~ProjectConfigPage() {
|
||||
}
|
||||
|
||||
/**
|
||||
@return the project being edited by this page
|
||||
*/
|
||||
QETProject *ProjectConfigPage::project() const {
|
||||
return(project_);
|
||||
}
|
||||
|
||||
/**
|
||||
Set \a new_project as the project being edited by this page.
|
||||
@param read_values True to read values from the project into widgets before setting them read only accordingly, false otherwise. Defaults to true.
|
||||
@return the former project
|
||||
*/
|
||||
QETProject *ProjectConfigPage::setProject(QETProject *new_project, bool read_values) {
|
||||
if (new_project == project_) return(project_);
|
||||
|
||||
QETProject *former_project = project_;
|
||||
project_ = new_project;
|
||||
if (project_ && read_values) {
|
||||
readValuesFromProject();
|
||||
adjustReadOnly();
|
||||
}
|
||||
return(former_project);
|
||||
}
|
||||
|
||||
/**
|
||||
Apply the configuration after user input
|
||||
*/
|
||||
void ProjectConfigPage::applyConf() {
|
||||
if (!project_ || project_ -> isReadOnly()) return;
|
||||
applyProjectConf();
|
||||
}
|
||||
|
||||
/**
|
||||
Initialize the page by calling initWidgets() and initLayout(). Also call
|
||||
readValuesFromProject() and adjustReadOnly() if a non-zero project has been
|
||||
set. Typically, you should call this function in your subclass constructor.
|
||||
*/
|
||||
void ProjectConfigPage::init() {
|
||||
initWidgets();
|
||||
initLayout();
|
||||
if (project_) {
|
||||
readValuesFromProject();
|
||||
adjustReadOnly();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Constructor
|
||||
@param project Project this page is editing.
|
||||
@param parent Parent QWidget
|
||||
*/
|
||||
ProjectMainConfigPage::ProjectMainConfigPage(QETProject *project, QWidget *parent) :
|
||||
ProjectConfigPage(project, parent)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
Destructor
|
||||
*/
|
||||
ProjectMainConfigPage::~ProjectMainConfigPage() {
|
||||
}
|
||||
|
||||
/**
|
||||
@return the title for this page
|
||||
*/
|
||||
QString ProjectMainConfigPage::title() const {
|
||||
return(tr("G\351n\351ral", "configuration page title"));
|
||||
}
|
||||
|
||||
/**
|
||||
@return the icon for this page
|
||||
*/
|
||||
QIcon ProjectMainConfigPage::icon() const {
|
||||
return(QET::Icons::Settings);
|
||||
}
|
||||
|
||||
/**
|
||||
Apply the configuration after user input
|
||||
*/
|
||||
void ProjectMainConfigPage::applyProjectConf() {
|
||||
project_ -> setTitle(title_value_ -> text());
|
||||
}
|
||||
|
||||
/**
|
||||
@return the project title entered by the user
|
||||
*/
|
||||
QString ProjectMainConfigPage::projectTitle() const {
|
||||
return(title_value_ -> text());
|
||||
}
|
||||
|
||||
/**
|
||||
Initialize widgets displayed by the page.
|
||||
*/
|
||||
void ProjectMainConfigPage::initWidgets() {
|
||||
title_label_ = new QLabel(tr("Titre du projet\240:", "label when configuring"));
|
||||
title_value_ = new QLineEdit();
|
||||
}
|
||||
|
||||
/**
|
||||
Initialize the layout of this page.
|
||||
*/
|
||||
void ProjectMainConfigPage::initLayout() {
|
||||
QVBoxLayout *main_layout0 = new QVBoxLayout();
|
||||
QHBoxLayout *title_layout0 = new QHBoxLayout();
|
||||
title_layout0 -> addWidget(title_label_);
|
||||
title_layout0 -> addWidget(title_value_);
|
||||
main_layout0 -> addLayout(title_layout0);
|
||||
main_layout0 -> addStretch();
|
||||
setLayout(main_layout0);
|
||||
}
|
||||
|
||||
/**
|
||||
Read properties from the edited project then fill widgets with them.
|
||||
*/
|
||||
void ProjectMainConfigPage::readValuesFromProject() {
|
||||
title_value_ -> setText(project_ -> title());
|
||||
}
|
||||
|
||||
/**
|
||||
Set the content of this page read only if the project is read only,
|
||||
editable if the project is editable.
|
||||
*/
|
||||
void ProjectMainConfigPage::adjustReadOnly() {
|
||||
bool is_read_only = project_ -> isReadOnly();
|
||||
title_value_ -> setReadOnly(is_read_only);
|
||||
}
|
||||
|
||||
/**
|
||||
Constructor
|
||||
@param project Project this page is editing.
|
||||
@param parent Parent QWidget
|
||||
*/
|
||||
ProjectNewDiagramConfigPage::ProjectNewDiagramConfigPage(QETProject *project, QWidget *parent) :
|
||||
ProjectConfigPage(project, parent)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
Destructor
|
||||
*/
|
||||
ProjectNewDiagramConfigPage::~ProjectNewDiagramConfigPage() {
|
||||
}
|
||||
|
||||
/**
|
||||
@return the title for this page
|
||||
*/
|
||||
QString ProjectNewDiagramConfigPage::title() const {
|
||||
return(tr("Nouveau sch\351ma", "project configuration page title"));
|
||||
}
|
||||
|
||||
/**
|
||||
@return the icon for this page
|
||||
*/
|
||||
QIcon ProjectNewDiagramConfigPage::icon() const {
|
||||
return(QET::Icons::NewDiagram);
|
||||
}
|
||||
|
||||
/**
|
||||
Apply the configuration after user input
|
||||
*/
|
||||
void ProjectNewDiagramConfigPage::applyProjectConf() {
|
||||
project_ -> setDefaultBorderProperties(border_ -> borderProperties());
|
||||
project_ -> setDefaultTitleBlockProperties(titleblock_ -> titleBlockProperties());
|
||||
project_ -> setDefaultConductorProperties(conductor_ -> conductorProperties());
|
||||
}
|
||||
|
||||
/**
|
||||
Initialize widgets displayed by the page.
|
||||
*/
|
||||
void ProjectNewDiagramConfigPage::initWidgets() {
|
||||
informative_label_ = new QLabel(
|
||||
tr(
|
||||
"Propri\351t\351s \340 utiliser lors de l'ajout d'un nouveau sch\351ma au projet :",
|
||||
"explicative label"
|
||||
)
|
||||
);
|
||||
border_ = new BorderPropertiesWidget(BorderProperties());
|
||||
titleblock_ = new TitleBlockPropertiesWidget(TitleBlockProperties(), true);
|
||||
conductor_ = new ConductorPropertiesWidget();
|
||||
conductor_ -> setContentsMargins(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
Initialize the layout of this page.
|
||||
*/
|
||||
void ProjectNewDiagramConfigPage::initLayout() {
|
||||
// put border properties above title block properties
|
||||
QVBoxLayout *vlayout2 = new QVBoxLayout();
|
||||
vlayout2 -> addWidget(border_);
|
||||
vlayout2 -> addWidget(titleblock_);
|
||||
vlayout2 -> setSpacing(5);
|
||||
|
||||
// add conductor properties on the right
|
||||
QHBoxLayout *hlayout1 = new QHBoxLayout();
|
||||
hlayout1 -> addLayout(vlayout2);
|
||||
hlayout1 -> addWidget(conductor_);
|
||||
hlayout1 -> setAlignment(conductor_, Qt::AlignTop);
|
||||
|
||||
// add the informative label above previous widgets
|
||||
QVBoxLayout *vlayout1 = new QVBoxLayout();
|
||||
vlayout1 -> addWidget(informative_label_);
|
||||
vlayout1 -> addLayout(hlayout1);
|
||||
vlayout1 -> addStretch();
|
||||
setLayout(vlayout1);
|
||||
}
|
||||
|
||||
/**
|
||||
Read properties from the edited project then fill widgets with them.
|
||||
*/
|
||||
void ProjectNewDiagramConfigPage::readValuesFromProject() {
|
||||
border_ -> setEditedBorder(project_ -> defaultBorderProperties());
|
||||
conductor_ -> setConductorProperties(project_ -> defaultConductorProperties());
|
||||
titleblock_ -> setTitleBlockProperties(project_ -> defaultTitleBlockProperties());
|
||||
}
|
||||
|
||||
/**
|
||||
Set the content of this page read only if the project is read only,
|
||||
editable if the project is editable.
|
||||
*/
|
||||
void ProjectNewDiagramConfigPage::adjustReadOnly() {
|
||||
bool is_read_only = project_ -> isReadOnly();
|
||||
border_ -> setReadOnly(is_read_only);
|
||||
titleblock_ -> setReadOnly(is_read_only);
|
||||
conductor_ -> setReadOnly(is_read_only);
|
||||
}
|
126
sources/projectconfigpages.h
Normal file
126
sources/projectconfigpages.h
Normal file
@ -0,0 +1,126 @@
|
||||
#ifndef PROJECTCONFIGPAGES_H
|
||||
#define PROJECTCONFIGPAGES_H
|
||||
#include "configpage.h"
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
class QETProject;
|
||||
class BorderPropertiesWidget;
|
||||
class TitleBlockPropertiesWidget;
|
||||
class ConductorPropertiesWidget;
|
||||
|
||||
/**
|
||||
This class, derived from ConfigPage, aims at providing the basic skeleton
|
||||
for a project configuration page.
|
||||
*/
|
||||
class ProjectConfigPage : public ConfigPage {
|
||||
Q_OBJECT
|
||||
// Constructor, destructor
|
||||
public:
|
||||
ProjectConfigPage(QETProject *, QWidget * = 0);
|
||||
virtual ~ProjectConfigPage();
|
||||
private:
|
||||
ProjectConfigPage(const ProjectConfigPage &);
|
||||
|
||||
// methods
|
||||
public:
|
||||
virtual QETProject *project() const;
|
||||
virtual QETProject *setProject(QETProject *project, bool = true);
|
||||
virtual void applyConf();
|
||||
/**
|
||||
Apply configuration to the project after user input. This method is
|
||||
automatically called when the ConfigDialog is validated, and only if the
|
||||
project is both non-zero and not read-only.
|
||||
*/
|
||||
virtual void applyProjectConf() = 0;
|
||||
|
||||
protected:
|
||||
virtual void init();
|
||||
/**
|
||||
Use this pure virtual method to initialize your page widgets.
|
||||
*/
|
||||
virtual void initWidgets() = 0;
|
||||
/**
|
||||
Use this pure virtual method to initialize your page layout. This method is
|
||||
always called after initWidgets().
|
||||
*/
|
||||
virtual void initLayout() = 0;
|
||||
/**
|
||||
Use this pure virtual method to fill widgets with project values.
|
||||
*/
|
||||
virtual void readValuesFromProject() = 0;
|
||||
/**
|
||||
Use this pure virtual method to adjust the "read only" state of your page
|
||||
widgets according to the currently edited project.
|
||||
*/
|
||||
virtual void adjustReadOnly() = 0;
|
||||
|
||||
// attributes
|
||||
protected:
|
||||
QETProject *project_; ///< Currently edited project
|
||||
};
|
||||
|
||||
/**
|
||||
This page enables users to configure the main properties of a project.
|
||||
*/
|
||||
class ProjectMainConfigPage : public ProjectConfigPage {
|
||||
Q_OBJECT
|
||||
// Constructor, destructor
|
||||
public:
|
||||
ProjectMainConfigPage(QETProject *, QWidget * = 0);
|
||||
virtual ~ProjectMainConfigPage();
|
||||
private:
|
||||
ProjectMainConfigPage(const ProjectMainConfigPage &);
|
||||
|
||||
// methods
|
||||
public:
|
||||
QString title() const;
|
||||
QIcon icon() const;
|
||||
void applyProjectConf();
|
||||
QString projectTitle() const;
|
||||
|
||||
protected:
|
||||
void initWidgets();
|
||||
void initLayout();
|
||||
void readValuesFromProject();
|
||||
void adjustReadOnly();
|
||||
|
||||
// attributes
|
||||
protected:
|
||||
QLabel *title_label_;
|
||||
QLineEdit *title_value_;
|
||||
};
|
||||
|
||||
/**
|
||||
This page enables users to configure the default properties of diagrams
|
||||
newly added to the edited project.
|
||||
*/
|
||||
class ProjectNewDiagramConfigPage : public ProjectConfigPage {
|
||||
Q_OBJECT
|
||||
// Constructor, destructor
|
||||
public:
|
||||
ProjectNewDiagramConfigPage(QETProject *, QWidget * = 0);
|
||||
virtual ~ProjectNewDiagramConfigPage();
|
||||
private:
|
||||
ProjectNewDiagramConfigPage(const ProjectNewDiagramConfigPage &);
|
||||
|
||||
// methods
|
||||
public:
|
||||
QString title() const;
|
||||
QIcon icon() const;
|
||||
void applyProjectConf();
|
||||
|
||||
protected:
|
||||
void initWidgets();
|
||||
void initLayout();
|
||||
void readValuesFromProject();
|
||||
void adjustReadOnly();
|
||||
|
||||
// attributes
|
||||
private:
|
||||
QLabel *informative_label_;
|
||||
BorderPropertiesWidget *border_;
|
||||
TitleBlockPropertiesWidget *titleblock_;
|
||||
ConductorPropertiesWidget *conductor_;
|
||||
};
|
||||
|
||||
#endif
|
@ -17,6 +17,8 @@
|
||||
*/
|
||||
#include "projectview.h"
|
||||
#include "qetproject.h"
|
||||
#include "configdialog.h"
|
||||
#include "projectconfigpages.h"
|
||||
#include "diagramview.h"
|
||||
#include "diagram.h"
|
||||
#include "diagramprintdialog.h"
|
||||
@ -400,85 +402,18 @@ void ProjectView::showDiagram(Diagram *diagram) {
|
||||
}
|
||||
|
||||
/**
|
||||
Affiche un dialogue permettant a l'utilisateur d'editer les proprietes du
|
||||
projet.
|
||||
Enable the user to edit properties of the current project through a
|
||||
configuration dialog.
|
||||
*/
|
||||
void ProjectView::editProjectProperties() {
|
||||
if (!project_) return;
|
||||
|
||||
bool project_is_read_only = project_ -> isReadOnly();
|
||||
|
||||
// dialogue d'edition des proprietes du projet
|
||||
QDialog properties_dialog(parentWidget());
|
||||
#ifdef Q_WS_MAC
|
||||
properties_dialog.setWindowFlags(Qt::Sheet);
|
||||
#endif
|
||||
|
||||
properties_dialog.setMinimumWidth(786);
|
||||
properties_dialog.setMinimumHeight(585);
|
||||
ConfigDialog properties_dialog(parentWidget());
|
||||
properties_dialog.setMinimumSize(786, 585);
|
||||
properties_dialog.setWindowTitle(tr("Propri\351t\351s du projet", "window title"));
|
||||
|
||||
// titre du projet
|
||||
QLabel *title_label = new QLabel(tr("Titre du projet :"));
|
||||
QLineEdit *title_field = new QLineEdit(project_ -> title());
|
||||
title_field -> setReadOnly(project_is_read_only);
|
||||
|
||||
// proprietes des nouveaux schemas
|
||||
QLabel *new_diagrams_prop = new QLabel(tr("Propri\351t\351s \340 utiliser lors de l'ajout d'un nouveau sch\351ma au projet :"));
|
||||
|
||||
// dimensions par defaut d'un schema
|
||||
BorderPropertiesWidget *bpw = new BorderPropertiesWidget(project_ -> defaultBorderProperties());
|
||||
bpw -> setReadOnly(project_is_read_only);
|
||||
|
||||
// proprietes par defaut d'un cartouche
|
||||
TitleBlockPropertiesWidget *ipw = new TitleBlockPropertiesWidget(project_ -> defaultTitleBlockProperties(), true);
|
||||
ipw -> setReadOnly(project_is_read_only);
|
||||
|
||||
// proprietes par defaut des conducteurs
|
||||
ConductorPropertiesWidget *cpw = new ConductorPropertiesWidget(project_ -> defaultConductorProperties());
|
||||
cpw -> setContentsMargins(0, 0, 0, 0);
|
||||
cpw -> setReadOnly(project_is_read_only);
|
||||
|
||||
// boutons pour valider le dialogue
|
||||
QDialogButtonBox *buttons = new QDialogButtonBox(project_is_read_only ? QDialogButtonBox::Ok : QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
|
||||
connect(buttons, SIGNAL(accepted()), &properties_dialog, SLOT(accept()));
|
||||
connect(buttons, SIGNAL(rejected()), &properties_dialog, SLOT(reject()));
|
||||
|
||||
// agencement avec deux layouts : un vertical, un horizontal
|
||||
QHBoxLayout *horiz_layout = new QHBoxLayout();
|
||||
horiz_layout -> addWidget(title_label);
|
||||
horiz_layout -> addWidget(title_field);
|
||||
|
||||
QVBoxLayout *vlayout1 = new QVBoxLayout();
|
||||
|
||||
vlayout1 -> addWidget(new_diagrams_prop);
|
||||
|
||||
QHBoxLayout *hlayout1 = new QHBoxLayout();
|
||||
QVBoxLayout *vlayout2 = new QVBoxLayout();
|
||||
|
||||
vlayout2 -> addWidget(bpw);
|
||||
vlayout2 -> addWidget(ipw);
|
||||
vlayout2 -> setSpacing(5);
|
||||
hlayout1 -> addLayout(vlayout2);
|
||||
hlayout1 -> addWidget(cpw);
|
||||
vlayout1 -> addLayout(hlayout1);
|
||||
vlayout1 -> addStretch(1);
|
||||
hlayout1 -> setAlignment(cpw, Qt::AlignTop);
|
||||
|
||||
QVBoxLayout *vert_layout = new QVBoxLayout(&properties_dialog);
|
||||
vert_layout -> addLayout(horiz_layout);
|
||||
vert_layout -> addLayout(vlayout1);
|
||||
vert_layout -> addStretch();
|
||||
vert_layout -> addWidget(buttons);
|
||||
|
||||
// si le dialogue est accepte
|
||||
if (properties_dialog.exec() == QDialog::Accepted && !project_is_read_only) {
|
||||
project_ -> setTitle(title_field -> text());
|
||||
project_ -> setDefaultBorderProperties(bpw -> borderProperties());
|
||||
project_ -> setDefaultTitleBlockProperties(ipw -> titleBlockProperties());
|
||||
project_ -> setDefaultConductorProperties(cpw -> conductorProperties());
|
||||
}
|
||||
properties_dialog.addPage(new ProjectMainConfigPage(project_));
|
||||
properties_dialog.addPage(new ProjectNewDiagramConfigPage(project_));
|
||||
properties_dialog.exec();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user