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 <QApplication>
42 #include <QSpinBox>
43 #include <QDialogButtonBox>
44 #include <QLineEdit>
45 #include <QDialog>
46 #include <QComboBox>
47 #include <QToolButton>
48 #include <QPushButton>
49 #include <QBoxLayout>
50 #include <QTreeWidget>
51 #include <QAction>
52 #include <QDesktopWidget>
53 #include <QTextDocument>
54 #include <QCalendarWidget>
55 #include <QTimeLine>
56 #include "objectcontroller.h"
57 
58 class MyController : public QDialog
59 {
60  Q_OBJECT
61 public:
62  MyController(QWidget* parent = 0);
63  ~MyController();
64 private slots:
65  void createAndControl();
66 private:
67  QComboBox* theClassCombo;
68  ObjectController* theController;
69  QStringList theClassNames;
70  QObject* theControlledObject;
71 };
72 
74  : QDialog(parent), theControlledObject(0)
75 {
76  theClassCombo = new QComboBox(this);
77  QToolButton* button = new QToolButton(this);
78  theController = new ObjectController(this);
79  QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
80 
81  connect(button, SIGNAL(clicked()), this, SLOT(createAndControl()));
82  connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
83 
84  button->setText(tr("Create And Control"));
85  buttonBox->setStandardButtons(QDialogButtonBox::Close);
86 
87  QVBoxLayout* layout = new QVBoxLayout(this);
88  QHBoxLayout* internalLayout = new QHBoxLayout();
89  internalLayout->addWidget(theClassCombo);
90  internalLayout->addWidget(button);
91  layout->addLayout(internalLayout);
92  layout->addWidget(theController);
93  layout->addWidget(buttonBox);
94 
95  theClassNames.append(QLatin1String("QWidget"));
96  theClassNames.append(QLatin1String("QPushButton"));
97  theClassNames.append(QLatin1String("QDialogButtonBox"));
98  theClassNames.append(QLatin1String("QTreeWidget"));
99  theClassNames.append(QLatin1String("QCalendarWidget"));
100  theClassNames.append(QLatin1String("QAction"));
101  theClassNames.append(QLatin1String("QTimeLine"));
102  theClassNames.append(QLatin1String("QTextDocument"));
103 
104  theClassCombo->addItems(theClassNames);
105 }
106 
108 {
109  if (theControlledObject)
110  {
111  delete theControlledObject;
112  }
113 }
114 
115 void MyController::createAndControl()
116 {
117  QObject* newObject = 0;
118  QString className = theClassNames.at(theClassCombo->currentIndex());
119 
120  if (className == QLatin1String("QWidget"))
121  {
122  newObject = new QWidget();
123  }
124  else if (className == QLatin1String("QPushButton"))
125  {
126  newObject = new QPushButton();
127  }
128  else if (className == QLatin1String("QDialogButtonBox"))
129  {
130  newObject = new QDialogButtonBox();
131  }
132  else if (className == QLatin1String("QTreeWidget"))
133  {
134  newObject = new QTreeWidget();
135  }
136  else if (className == QLatin1String("QCalendarWidget"))
137  {
138  newObject = new QCalendarWidget();
139  }
140  else if (className == QLatin1String("QAction"))
141  {
142  newObject = new QAction(0);
143  }
144  else if (className == QLatin1String("QTimeLine"))
145  {
146  newObject = new QTimeLine();
147  }
148  else if (className == QLatin1String("QTextDocument"))
149  {
150  newObject = new QTextDocument();
151  }
152 
153  if (!newObject)
154  {
155  return;
156  }
157 
158  QWidget* newWidget = qobject_cast<QWidget*>(newObject);
159 
160  if (newWidget)
161  {
162  QRect r = newWidget->geometry();
163  r.setSize(newWidget->sizeHint());
164  r.setWidth(qMax(r.width(), 150));
165  r.setHeight(qMax(r.height(), 50));
166  r.moveCenter(QApplication::desktop()->geometry().center());
167  newWidget->setGeometry(r);
168  newWidget->setWindowTitle(tr("Controlled Object: %1").arg(className));
169  newWidget->show();
170  }
171 
172  if (theControlledObject)
173  {
174  delete theControlledObject;
175  }
176 
177  theControlledObject = newObject;
178  theController->setObject(theControlledObject);
179 }
180 
181 int main(int argc, char** argv)
182 {
183  QApplication app(argc, argv);
184 
186  controller->show();
187 
188  int ret = app.exec();
189 
190  return ret;
191 }
192 
193 #include "main.moc"
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:21
ObjectController
Definition: objectcontroller.h:47
MyController
Definition: main.cpp:58
controller
Definition: AddOperation.h:39
main
int main(int argc, char *argv[])
Definition: main.cpp:31
MyController::MyController
MyController(QWidget *parent=0)
Definition: main.cpp:73
MyController::~MyController
~MyController()
Definition: main.cpp:107
objectcontroller.h
ObjectController::setObject
void setObject(QObject *object)
Definition: objectcontroller.cpp:484