2018-05-11 18:14:41 +00:00
|
|
|
/*
|
2020-06-15 17:42:37 +02:00
|
|
|
Copyright 2006-2020 The QElectroTech Team
|
2018-05-11 18:14:41 +00:00
|
|
|
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 "alignmenttextdialog.h"
|
|
|
|
#include "ui_alignmenttextdialog.h"
|
|
|
|
#include "dynamicelementtextitem.h"
|
|
|
|
|
2018-05-13 19:03:38 +00:00
|
|
|
AlignmentTextDialog::AlignmentTextDialog(Qt::Alignment alignment, QWidget *parent) :
|
2018-05-11 18:14:41 +00:00
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::AlignmentTextDialog)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2018-05-13 19:03:38 +00:00
|
|
|
if(alignment == (Qt::AlignTop|Qt::AlignLeft))
|
2018-05-11 18:14:41 +00:00
|
|
|
ui->top_left->setChecked(true);
|
2018-05-13 19:03:38 +00:00
|
|
|
else if(alignment == (Qt::AlignTop|Qt::AlignHCenter))
|
2018-05-11 18:14:41 +00:00
|
|
|
ui->top->setChecked(true);
|
2018-05-13 19:03:38 +00:00
|
|
|
else if(alignment == (Qt::AlignTop|Qt::AlignRight))
|
2018-05-11 18:14:41 +00:00
|
|
|
ui->top_right->setChecked(true);
|
2018-05-13 19:03:38 +00:00
|
|
|
else if(alignment == (Qt::AlignVCenter|Qt::AlignLeft))
|
2018-05-11 18:14:41 +00:00
|
|
|
ui->left->setChecked(true);
|
2018-05-13 19:03:38 +00:00
|
|
|
else if(alignment == Qt::AlignCenter)
|
2018-05-11 18:14:41 +00:00
|
|
|
ui->center->setChecked(true);
|
2018-05-13 19:03:38 +00:00
|
|
|
else if(alignment == (Qt::AlignVCenter|Qt::AlignRight))
|
2018-05-11 18:14:41 +00:00
|
|
|
ui->right->setChecked(true);
|
2018-05-13 19:03:38 +00:00
|
|
|
else if(alignment == (Qt::AlignBottom|Qt::AlignLeft))
|
2018-05-11 18:14:41 +00:00
|
|
|
ui->bottom_left->setChecked(true);
|
2018-05-13 19:03:38 +00:00
|
|
|
else if(alignment == (Qt::AlignBottom|Qt::AlignHCenter))
|
2018-05-11 18:14:41 +00:00
|
|
|
ui->bottom->setChecked(true);
|
2018-05-13 19:03:38 +00:00
|
|
|
else if(alignment == (Qt::AlignBottom|Qt::AlignRight))
|
2018-05-11 18:14:41 +00:00
|
|
|
ui->bottom_right->setChecked(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
AlignmentTextDialog::~AlignmentTextDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief AlignmentTextDialog::alignment
|
|
|
|
@return the selected alignment
|
|
|
|
*/
|
2018-05-11 18:14:41 +00:00
|
|
|
Qt::Alignment AlignmentTextDialog::alignment() const
|
|
|
|
{
|
|
|
|
if(ui->top_left->isChecked())
|
|
|
|
return (Qt::AlignTop|Qt::AlignLeft);
|
|
|
|
else if(ui->top->isChecked())
|
|
|
|
return (Qt::AlignTop|Qt::AlignHCenter);
|
|
|
|
else if(ui->top_right->isChecked())
|
|
|
|
return (Qt::AlignTop|Qt::AlignRight);
|
|
|
|
else if(ui->left->isChecked())
|
|
|
|
return (Qt::AlignVCenter|Qt::AlignLeft);
|
|
|
|
else if (ui->center->isChecked())
|
|
|
|
return Qt::AlignCenter;
|
|
|
|
else if(ui->right->isChecked())
|
|
|
|
return (Qt::AlignVCenter|Qt::AlignRight);
|
|
|
|
else if(ui->bottom_left->isChecked())
|
|
|
|
return (Qt::AlignBottom|Qt::AlignLeft);
|
|
|
|
else if(ui->bottom->isChecked())
|
|
|
|
return (Qt::AlignBottom|Qt::AlignHCenter);
|
|
|
|
else if(ui->bottom_right->isChecked())
|
|
|
|
return (Qt::AlignBottom|Qt::AlignRight);
|
|
|
|
else
|
|
|
|
return (Qt::AlignTop|Qt::AlignLeft);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AlignmentTextDialog::event(QEvent *event)
|
|
|
|
{
|
2018-05-13 19:03:38 +00:00
|
|
|
//Little hack when this dialog is called from a QAbstractItemModel, to set focus to a radio button
|
2018-05-11 18:14:41 +00:00
|
|
|
//if we not do that, when the user click on the title bar (for move the dialog) or try to resize the dialog,
|
|
|
|
//the dialog lose focus and close.
|
|
|
|
if(event->type() == QEvent::Show && m_first_show)
|
|
|
|
{
|
|
|
|
QTimer::singleShot(50, [this](){ui->top_left->setFocus();});
|
|
|
|
m_first_show = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QDialog::event(event);
|
|
|
|
}
|