QElectroTech  0.70
alignmenttextdialog.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "alignmenttextdialog.h"
19 #include "ui_alignmenttextdialog.h"
20 #include "dynamicelementtextitem.h"
21 
22 AlignmentTextDialog::AlignmentTextDialog(Qt::Alignment alignment, QWidget *parent) :
23  QDialog(parent),
24  ui(new Ui::AlignmentTextDialog)
25 {
26  ui->setupUi(this);
27 
28  if(alignment == (Qt::AlignTop|Qt::AlignLeft))
29  ui->top_left->setChecked(true);
30  else if(alignment == (Qt::AlignTop|Qt::AlignHCenter))
31  ui->top->setChecked(true);
32  else if(alignment == (Qt::AlignTop|Qt::AlignRight))
33  ui->top_right->setChecked(true);
34  else if(alignment == (Qt::AlignVCenter|Qt::AlignLeft))
35  ui->left->setChecked(true);
36  else if(alignment == Qt::AlignCenter)
37  ui->center->setChecked(true);
38  else if(alignment == (Qt::AlignVCenter|Qt::AlignRight))
39  ui->right->setChecked(true);
40  else if(alignment == (Qt::AlignBottom|Qt::AlignLeft))
41  ui->bottom_left->setChecked(true);
42  else if(alignment == (Qt::AlignBottom|Qt::AlignHCenter))
43  ui->bottom->setChecked(true);
44  else if(alignment == (Qt::AlignBottom|Qt::AlignRight))
45  ui->bottom_right->setChecked(true);
46 }
47 
49 {
50  delete ui;
51 }
52 
57 Qt::Alignment AlignmentTextDialog::alignment() const
58 {
59  if(ui->top_left->isChecked())
60  return (Qt::AlignTop|Qt::AlignLeft);
61  else if(ui->top->isChecked())
62  return (Qt::AlignTop|Qt::AlignHCenter);
63  else if(ui->top_right->isChecked())
64  return (Qt::AlignTop|Qt::AlignRight);
65  else if(ui->left->isChecked())
66  return (Qt::AlignVCenter|Qt::AlignLeft);
67  else if (ui->center->isChecked())
68  return Qt::AlignCenter;
69  else if(ui->right->isChecked())
70  return (Qt::AlignVCenter|Qt::AlignRight);
71  else if(ui->bottom_left->isChecked())
72  return (Qt::AlignBottom|Qt::AlignLeft);
73  else if(ui->bottom->isChecked())
74  return (Qt::AlignBottom|Qt::AlignHCenter);
75  else if(ui->bottom_right->isChecked())
76  return (Qt::AlignBottom|Qt::AlignRight);
77  else
78  return (Qt::AlignTop|Qt::AlignLeft);
79 }
80 
81 bool AlignmentTextDialog::event(QEvent *event)
82 {
83  //Little hack when this dialog is called from a QAbstractItemModel, to set focus to a radio button
84  //if we not do that, when the user click on the title bar (for move the dialog) or try to resize the dialog,
85  //the dialog lose focus and close.
86  if(event->type() == QEvent::Show && m_first_show)
87  {
88  QTimer::singleShot(50, [this](){ui->top_left->setFocus();});
89  m_first_show = false;
90  }
91 
92  return QDialog::event(event);
93 }
AlignmentTextDialog(Qt::Alignment alignment, QWidget *parent=nullptr)
Qt::Alignment alignment() const
AlignmentTextDialog::alignment.
Ui::AlignmentTextDialog * ui
bool event(QEvent *event)