main.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the Qt Solutions component.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
10 **
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
13 ** met:
14 ** * Redistributions of source code must retain the above copyright
15 ** notice, this list of conditions and the following disclaimer.
16 ** * Redistributions in binary form must reproduce the above copyright
17 ** notice, this list of conditions and the following disclaimer in
18 ** the documentation and/or other materials provided with the
19 ** distribution.
20 ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21 ** of its contributors may be used to endorse or promote products derived
22 ** from this software without specific prior written permission.
23 **
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40 
41 #include <QAction>
42 #include <QApplication>
43 #include <QBoxLayout>
44 #include <QCalendarWidget>
45 #include <QComboBox>
46 #include <QDesktopWidget>
47 #include <QDialog>
48 #include <QDialogButtonBox>
49 #include <QLineEdit>
50 #include <QPushButton>
51 #include <QSpinBox>
52 #include <QTextDocument>
53 #include <QTimeLine>
54 #include <QToolButton>
55 #include <QTreeWidget>
56 
57 #include "objectcontroller.h"
58 
59 class MyController : public QDialog
60 {
61  Q_OBJECT
62 public:
63  MyController(QWidget* parent = 0);
64  ~MyController();
65 private slots:
66  void createAndControl();
67 
68 private:
69  QComboBox* theClassCombo;
70  ObjectController* theController;
71  QStringList theClassNames;
72  QObject* theControlledObject;
73 };
74 
75 MyController::MyController(QWidget* parent) : QDialog(parent), theControlledObject(0)
76 {
77  theClassCombo = new QComboBox(this);
78  QToolButton* button = new QToolButton(this);
79  theController = new ObjectController(this);
80  QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
81 
82  connect(button, SIGNAL(clicked()), this, SLOT(createAndControl()));
83  connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
84 
85  button->setText(tr("Create And Control"));
86  buttonBox->setStandardButtons(QDialogButtonBox::Close);
87 
88  QVBoxLayout* layout = new QVBoxLayout(this);
89  QHBoxLayout* internalLayout = new QHBoxLayout();
90  internalLayout->addWidget(theClassCombo);
91  internalLayout->addWidget(button);
92  layout->addLayout(internalLayout);
93  layout->addWidget(theController);
94  layout->addWidget(buttonBox);
95 
96  theClassNames.append(QLatin1String("QWidget"));
97  theClassNames.append(QLatin1String("QPushButton"));
98  theClassNames.append(QLatin1String("QDialogButtonBox"));
99  theClassNames.append(QLatin1String("QTreeWidget"));
100  theClassNames.append(QLatin1String("QCalendarWidget"));
101  theClassNames.append(QLatin1String("QAction"));
102  theClassNames.append(QLatin1String("QTimeLine"));
103  theClassNames.append(QLatin1String("QTextDocument"));
104 
105  theClassCombo->addItems(theClassNames);
106 }
107 
109 {
110  if (theControlledObject)
111  {
112  delete theControlledObject;
113  }
114 }
115 
116 void
117 MyController::createAndControl()
118 {
119  QObject* newObject = 0;
120  QString className = theClassNames.at(theClassCombo->currentIndex());
121 
122  if (className == QLatin1String("QWidget"))
123  {
124  newObject = new QWidget();
125  }
126  else if (className == QLatin1String("QPushButton"))
127  {
128  newObject = new QPushButton();
129  }
130  else if (className == QLatin1String("QDialogButtonBox"))
131  {
132  newObject = new QDialogButtonBox();
133  }
134  else if (className == QLatin1String("QTreeWidget"))
135  {
136  newObject = new QTreeWidget();
137  }
138  else if (className == QLatin1String("QCalendarWidget"))
139  {
140  newObject = new QCalendarWidget();
141  }
142  else if (className == QLatin1String("QAction"))
143  {
144  newObject = new QAction(0);
145  }
146  else if (className == QLatin1String("QTimeLine"))
147  {
148  newObject = new QTimeLine();
149  }
150  else if (className == QLatin1String("QTextDocument"))
151  {
152  newObject = new QTextDocument();
153  }
154 
155  if (!newObject)
156  {
157  return;
158  }
159 
160  QWidget* newWidget = qobject_cast<QWidget*>(newObject);
161 
162  if (newWidget)
163  {
164  QRect r = newWidget->geometry();
165  r.setSize(newWidget->sizeHint());
166  r.setWidth(qMax(r.width(), 150));
167  r.setHeight(qMax(r.height(), 50));
168  r.moveCenter(QApplication::desktop()->geometry().center());
169  newWidget->setGeometry(r);
170  newWidget->setWindowTitle(tr("Controlled Object: %1").arg(className));
171  newWidget->show();
172  }
173 
174  if (theControlledObject)
175  {
176  delete theControlledObject;
177  }
178 
179  theControlledObject = newObject;
180  theController->setObject(theControlledObject);
181 }
182 
183 int
184 main(int argc, char** argv)
185 {
186  QApplication app(argc, argv);
187 
189  controller->show();
190 
191  int ret = app.exec();
192 
193  return ret;
194 }
195 
196 #include "main.moc"
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:13
ObjectController
Definition: objectcontroller.h:47
MyController
Definition: main.cpp:59
controller
Definition: AddOperation.h:39
main
int main(int argc, char *argv[])
Definition: main.cpp:32
MyController::MyController
MyController(QWidget *parent=0)
Definition: main.cpp:75
MyController::~MyController
~MyController()
Definition: main.cpp:108
armarx::view_selection::skills::direction::state::center
state::Type center(state::Type previous)
Definition: LookDirection.cpp:233
objectcontroller.h
ObjectController::setObject
void setObject(QObject *object)
Definition: objectcontroller.cpp:509