rock_widget_collection  0.1
MultiViewPlugin.cc
Go to the documentation of this file.
1 
2 #include <QtGui/qwidget.h>
3 #include <QtDesigner/abstractformeditor.h>
4 #include <QtDesigner/abstractformwindowmanager.h>
5 #include <QtDesigner/abstractformwindowcursor.h>
6 #include <QtGui/qabstractbutton.h>
7 
8 #include "MultiViewPlugin.h"
9 //#include <QtPlugin>
10 #include <typeinfo>
11 
12 MultiViewPlugin::MultiViewPlugin(QObject* parent) : QObject(parent)
13 {
14  widget = NULL;
15  initialized = false;
16  designerMode = false;
17 }
18 
20 {
21 }
22 
24 {
25  return true;
26 }
27 
29 {
30  return initialized;
31 }
32 
33 QIcon MultiViewPlugin::icon() const
34 {
35  return QIcon();
36 }
37 
38 QString MultiViewPlugin::group() const
39 {
40  return "Rock-Robotics";
41 }
42 
44 {
45  return "MultiViewWidget.h";
46 }
47 
48 QString MultiViewPlugin::name() const
49 {
50  return "MultiViewWidget";
51 }
52 
53 QString MultiViewPlugin::toolTip() const
54 {
55  return "Widget for displaying multiple widgets";
56 }
57 
59 {
60  return "Container widget for other widgets";
61 }
62 
63 void MultiViewPlugin::initialize(QDesignerFormEditorInterface* core)
64 {
65  // initialize will only be called wehn qt designer is used
66  // when loading via an ui file, this will not be called
67  designerMode = true;
68  if (initialized)
69  {
70  return;
71  }
72  formInterface = core;
73  connect(formInterface->formWindowManager(), SIGNAL(activeFormWindowChanged(QDesignerFormWindowInterface*)),
74  this, SLOT(activeFormWindowChanged(QDesignerFormWindowInterface*)));
75  initialized = true;
76 }
77 
78 void MultiViewPlugin::manageWidget(QWidget* widget)
79 {
80  if(!this->widget->isDesignerMode())
81  {
82  return;
83  }
84  // when designer loads a ui file it will call manage widget BEFORE
85  // setting the active Form Window, save what shall be added
86  // and wait for the activeFormWindow signal and add everything up
87  // to that point
88  if(formInterface->formWindowManager()->activeFormWindow() == NULL)
89  {
90  lastWidgets.push_back(widget);
91  return;
92  }
93  //formInterface->formWindowManager()->activeFormWindow()->manageWidget(widget);
94  WidgetButton* button = dynamic_cast<WidgetButton*>(widget);
95  if(button != NULL)
96  {
97  button->setIconAlternative(QIcon(), true);
98  printf("We have here an element in button: %s\n",typeid(*button->getWidget()).name());
99  printf("Adding this to: %s\n",typeid(*formInterface->formWindowManager()->activeFormWindow()).name());
100  printf("Filename for current one is: %s\n",formInterface->formWindowManager()->activeFormWindow()->fileName().toStdString().c_str());
101  formInterface->formWindowManager()->activeFormWindow()->manageWidget(button->getWidget());
102  }else{
103  printf("We have here an non-button: %s\n",typeid(*widget).name());
104  }
105  connect(formInterface->formWindowManager()->activeFormWindow(), SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
106 }
107 
108 void MultiViewPlugin::activeFormWindowChanged(QDesignerFormWindowInterface* formWindow)
109 {
110  // needs to be done for reloading as widgets will be added before the
111  // active form window is set by the designer
112  if(formWindow != NULL && lastWidgets.size() > 0)
113  {
114  for(unsigned int i=0;i<lastWidgets.size();i++)
115  {
116  manageWidget(lastWidgets[i]);
117  }
118  lastWidgets.clear();
119  }
120 
121 }
122 
124 {
125 
126  QWidget* selected = formInterface->formWindowManager()->activeFormWindow()->cursor()->selectedWidget(0);
127  WidgetButton* button = dynamic_cast<WidgetButton*>(selected);
128  if(button != NULL)
129  {
130  printf("It's an button selected with contains: %s\n",typeid(*button->getWidget()).name());
131  button->click();
132  }
133  else
134  {
135  if(selected != NULL)
136  {
137  button = widget->getButtonForWidget(selected);
138  if(button != NULL)
139  {
140  printf("It's an button selected with contains: %s\n",typeid(*button->getWidget()).name());
141  button->click();
142  }else{
143  printf("Cannot find Button for: %s\n",typeid(*selected).name());
144  }
145  }
146  }
147 
148  if(button != NULL)
149  {
150  QList<WidgetButton*> buttons = widget->getAllWidgetButtons();
151  for(int i=0;i<buttons.size();i++)
152  {
153  if(button != buttons[i])
154  {
155  buttons[i]->getWidget()->setMaximumSize(0, 0);
156  }
157  else
158  {
159  buttons[i]->getWidget()->setMaximumSize(1000000, 1000000);
160  }
161 
162  }
163  }
164 
165  //printf("Curent content: %s\n",formInterface->formWindowManager()->activeFormWindow()->contents().toStdString().c_str());
166 }
167 
168 QWidget* MultiViewPlugin::createWidget(QWidget* parent)
169 {
170  widget = new MultiViewWidget(parent);
171  widget->setDesignerMode(designerMode);
172  connect(widget, SIGNAL(widgetButtonAdded(QWidget*)), this, SLOT(manageWidget(QWidget*)));
173  return widget;
174 }
175 
176 QString MultiViewPlugin::domXml() const
177 {
178  return "<widget class=\"MultiViewWidget\" name=\"MultiViewWidget\">\n"
179  " <property name=\"geometry\">\n"
180  " <rect>\n"
181  " <x>0</x>\n"
182  " <y>0</y>\n"
183  " <width>400</width>\n"
184  " <height>300</height>\n"
185  " </rect>\n"
186  " </property>\n"
187  " <property name=\"toolTip\" >\n"
188  " <string>MultiView</string>\n"
189  " </property>\n"
190  " <property name=\"whatsThis\" >\n"
191  " <string>Displays multiple widgets in a container.</string>\n"
192  " </property>\n"
193  "</widget>\n";
194 
195 }
196 
197 // Q_EXPORT_PLUGIN2(MultiViewPlugin, MultiViewPlugin)
void initialize(QDesignerFormEditorInterface *core)
void setDesignerMode(bool designerMode)
QIcon icon() const
virtual ~MultiViewPlugin()
QString whatsThis() const
QList< WidgetButton * > getAllWidgetButtons()
QString domXml() const
void activeFormWindowChanged(QDesignerFormWindowInterface *formWindow)
MultiViewPlugin(QObject *parent)
QString toolTip() const
void setIconAlternative(const QIcon &icon, bool isAlternative=false)
void manageWidget(QWidget *widget)
QWidget * createWidget(QWidget *parent)
QString group() const
bool isContainer() const
QWidget * getWidget()
QString name() const
bool isInitialized() const
QString includeFile() const
WidgetButton * getButtonForWidget(QWidget *widget)