1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the Qt Designer of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 #include "gridpanel_p.h"
30 #include "ui_gridpanel.h"
31 #include "grid_p.h"
32 
33 QT_BEGIN_NAMESPACE
34 
35 namespace qdesigner_internal {
36 
GridPanel(QWidget * parentWidget)37 GridPanel::GridPanel(QWidget *parentWidget) :
38     QWidget(parentWidget)
39 {
40     m_ui = new Ui::GridPanel;
41     m_ui->setupUi(this);
42 
43     connect(m_ui->m_resetButton, &QAbstractButton::clicked, this, &GridPanel::reset);
44 }
45 
~GridPanel()46 GridPanel::~GridPanel()
47 {
48     delete m_ui;
49 }
50 
setGrid(const Grid & g)51 void GridPanel::setGrid(const Grid &g)
52 {
53     m_ui->m_deltaXSpinBox->setValue(g.deltaX());
54     m_ui->m_deltaYSpinBox->setValue(g.deltaY());
55     m_ui->m_visibleCheckBox->setCheckState(g.visible() ? Qt::Checked : Qt::Unchecked);
56     m_ui->m_snapXCheckBox->setCheckState(g.snapX()  ? Qt::Checked : Qt::Unchecked);
57     m_ui->m_snapYCheckBox->setCheckState(g.snapY()  ? Qt::Checked : Qt::Unchecked);
58 }
59 
setTitle(const QString & title)60 void GridPanel::setTitle(const QString &title)
61 {
62     m_ui->m_gridGroupBox->setTitle(title);
63 }
64 
grid() const65 Grid GridPanel::grid() const
66 {
67     Grid rc;
68     rc.setDeltaX(m_ui->m_deltaXSpinBox->value());
69     rc.setDeltaY(m_ui->m_deltaYSpinBox->value());
70     rc.setSnapX(m_ui->m_snapXCheckBox->checkState() == Qt::Checked);
71     rc.setSnapY(m_ui->m_snapYCheckBox->checkState() == Qt::Checked);
72     rc.setVisible(m_ui->m_visibleCheckBox->checkState() == Qt::Checked);
73     return rc;
74 }
75 
reset()76 void GridPanel::reset()
77 {
78     setGrid(Grid());
79 }
80 
setCheckable(bool c)81 void GridPanel::setCheckable (bool c)
82 {
83     m_ui->m_gridGroupBox->setCheckable(c);
84 }
85 
isCheckable() const86 bool GridPanel::isCheckable () const
87 {
88     return m_ui->m_gridGroupBox->isCheckable ();
89 }
90 
isChecked() const91 bool GridPanel::isChecked () const
92 {
93     return m_ui->m_gridGroupBox->isChecked ();
94 }
95 
setChecked(bool c)96 void GridPanel::setChecked(bool c)
97 {
98     m_ui->m_gridGroupBox->setChecked(c);
99 }
100 
setResetButtonVisible(bool v)101 void GridPanel::setResetButtonVisible(bool v)
102 {
103     m_ui->m_resetButton->setVisible(v);
104 }
105 
106 }
107 
108 QT_END_NAMESPACE
109