25#include <tqvaluevector.h>
31#include <tdepopupmenu.h>
37#include "widgetlibrary.h"
38#include "objecttree.h"
40#include "formmanager.h"
43#include "kexiflowlayout.h"
51 m_container = container;
57EventEater::eventFilter(TQObject *, TQEvent *ev)
64 if(ev->type() == TQEvent::MouseButtonRelease && m_widget->inherits( "TQTabWidget"))
66 TQMouseEvent *mev = static_cast<TQMouseEvent* >(ev);
67 if(mev->button() == TQt::LeftButton)
69 TQMouseEvent *myev = new TQMouseEvent(TQEvent::MouseButtonPress, mev->pos(), mev->button(), mev->state());
70 m_container->eventFilter(m_widget, myev);
80 return m_container->eventFilter(m_widget, ev);
83EventEater::~EventEater()
92: TQObject(parent, name)
94, m_mousePressEventReceived(false)
95, m_mouseReleaseEvent(TQEvent::None, TQPoint(), 0, 0)
97 m_container = container;
104 m_layType = NoLayout;
105 m_state = DoingNothing;
107 TQCString classname = container->className();
108 if((classname == "HBox") || (classname == "Grid") || (classname == "VBox") ||
109 (classname == "HFlow") || (classname == "VFlow"))
112 m_margin = m_form ? m_form->defaultMargin() : 0;
113 m_spacing = m_form ? m_form->defaultSpacing() : 0;
121 if(parent->isWidgetType())
123 TQString n = parent->name();
125 m_form->objectTree()->addItem(parent, it);
128 m_form->objectTree()->addItem( toplevel->objectTree(), it);
133 connect(container, TQ_SIGNAL(destroyed()), this, TQ_SLOT( widgetDeleted()));
136Container::~Container()
138 kdDebug() << " Container being deleted this == " << name() << endl;
145 m_margin = m_form ? m_form->defaultMargin() : 0;
146 m_spacing = m_form ? m_form->defaultSpacing() : 0;
155 case TQEvent::MouseButtonPress:
157 m_insertBegin = TQPoint(-1, -1);
158 m_mousePressEventReceived = true;
160 kdDebug() << "TQEvent::MouseButtonPress sender object = " << s->name()
161 << "of type " << s->className() << endl;
162 kdDebug() << "TQEvent::MouseButtonPress this = " << name() << endl;
164 m_moving = static_cast<TQWidget* >(s);
165 TQMouseEvent *mev = static_cast<TQMouseEvent* >(e);
166 m_grab = TQPoint(mev->x(), mev->y());
174 if(((mev->state() == TQt::ControlButton) || (mev->state() == TQt::ShiftButton))
177 if(m_form->selectedWidgets()->findRef(m_moving) != -1)
179 if(m_form->selectedWidgets()->count() > 1)
184 m_state = CopyingWidget;
185 if(m_form->formWidget())
186 m_form->formWidget()->initBuffer();
192 else if((m_form->selectedWidgets()->count() > 1))
194 if(m_form->selectedWidgets()->findRef(m_moving) == -1)
205 if(! FormManager::self()->snapWidgetsToGrid() || (mev->state() == (TQt::LeftButton|TQt::ControlButton|TQt::AltButton)))
212 int gridX = m_form->gridSize();
213 int gridY = m_form->gridSize();
214 tmpx = int( ( float)mev->x() / (( float)gridX) + 0.5 );
216 tmpy = int( ( float)mev->y() / (( float)gridY) + 0.5 );
220 m_insertBegin = ( static_cast<TQWidget* >(s))->mapTo(m_container, TQPoint(tmpx, tmpy));
221 if(m_form->formWidget())
222 m_form->formWidget()->initBuffer();
225 m_state = DrawingSelectionRect;
228 if(s->inherits( "TQTabWidget"))
232 if (m_objectForMouseReleaseEvent) {
233 const bool res = handleMouseReleaseEvent(m_objectForMouseReleaseEvent, &m_mouseReleaseEvent);
234 m_objectForMouseReleaseEvent = 0;
240 case TQEvent::MouseButtonRelease:
242 TQMouseEvent *mev = static_cast<TQMouseEvent* >(e);
243 if (!m_mousePressEventReceived) {
244 m_mouseReleaseEvent = *mev;
245 m_objectForMouseReleaseEvent = s;
248 m_mousePressEventReceived = false;
249 m_objectForMouseReleaseEvent = 0;
250 return handleMouseReleaseEvent(s, mev);
253 case TQEvent::MouseMove:
255 TQMouseEvent *mev = static_cast<TQMouseEvent* >(e);
256 if(m_insertBegin!=TQPoint(-1,-1) && FormManager::self()->isInserting() && ((mev->state() == TQt::LeftButton) || (mev->state() == (TQt::LeftButton|TQt::ControlButton)) ||
257 (mev->state() == (TQt::LeftButton|TQt::ControlButton|TQt::AltButton)) || (mev->state() == (TQt::LeftButton|TQt::ShiftButton)) ) )
260 drawInsertRect(mev, s);
267 if(!tree || !tree->widget())
270 if(m_form->formWidget() && (tree->widget() != s))
271 m_form->formWidget()->highlightWidgets(tree->widget(), static_cast<TQWidget* >(s));
273 else if(m_insertBegin!=TQPoint(-1,-1) && s == m_container && !m_toplevel && (mev->state() != TQt::ControlButton) && ! FormManager::self()->isCreatingConnection())
275 if((mev->state() != TQt::LeftButton) || m_state == InlineEditing)
277 int topx = (m_insertBegin.x() < mev->x()) ? m_insertBegin.x() : mev->x();
278 int topy = (m_insertBegin.y() < mev->y()) ? m_insertBegin.y() : mev->y();
279 int botx = (m_insertBegin.x() > mev->x()) ? m_insertBegin.x() : mev->x();
280 int boty = (m_insertBegin.y() > mev->y()) ? m_insertBegin.y() : mev->y();
281 TQRect r = TQRect(TQPoint(topx, topy), TQPoint(botx, boty));
284 if(m_form->formWidget())
285 m_form->formWidget()->drawRect(r, 1);
287 m_state = DoingNothing;
290 else if(mev->state() == (TQt::LeftButton|TQt::ControlButton))
294 drawCopiedWidgetRect(mev);
297 else if( ( (mev->state() == TQt::LeftButton) || (mev->state() == (TQt::LeftButton|TQt::ControlButton|TQt::AltButton)) )
300 if(!m_toplevel && m_moving == m_container)
302 if((!m_moving) || (!m_moving->parentWidget()))
306 m_state = MovingWidget;
316 int gridX = m_form->gridSize();
317 int gridY = m_form->gridSize();
319 TQPainter p(m_container);
320 p.setPen(TQPen(white, 2));
321 p.setRasterOp(XorROP);
322 int cols = m_container->width() / gridX;
323 int rows = m_container->height() / gridY;
325 for( int rowcursor = 1; rowcursor <= rows; ++rowcursor)
327 for( int colcursor = 1; colcursor <= cols; ++colcursor)
329 p.drawPoint(-1 + colcursor *gridX, -1 + rowcursor *gridY);
336 case TQEvent::Resize:
338 if(m_form->interactiveMode())
339 m_state = MovingWidget;
344 case TQEvent::KeyPress:
346 TQKeyEvent *kev = static_cast<TQKeyEvent* >(e);
348 if(kev->key() == Key_F2)
350 m_state = InlineEditing;
354 if(m_form->selectedWidgets()->count() == 1)
355 w = m_form->selectedWidgets()->first();
356 else if(m_form->selectedWidgets()->findRef(m_moving) != -1)
359 w = m_form->selectedWidgets()->last();
360 m_form->library()->startEditing(w->className(), w, this);
362 else if(kev->key() == Key_Escape)
370 else if((kev->key() == Key_Control) && (m_state == MovingWidget))
375 TQMouseEvent *mev = new TQMouseEvent(TQEvent::MouseMove, m_moving->mapFromGlobal(TQCursor::pos()), TQt::NoButton,
376 TQt::LeftButton|TQt::ControlButton );
385 else if (kev->key() == Key_Delete)
391 else if(kev->key() == Key_Left){
395 else if(kev->key() == Key_Right){
399 else if(kev->key() == Key_Up){
403 else if(kev->key() == Key_Down){
407 else if((kev->key() == Key_Tab) || (kev->key() == Key_BackTab)){
409 if(!item || !item->parent())
412 if(list->count() == 1)
414 int index = list->findRef(item);
416 if(kev->key() == Key_BackTab){
418 index = list->count() - 1;
423 if(index == int(list->count() - 1))
430 if(nextItem && nextItem->widget())
436 case TQEvent::KeyRelease:
438 TQKeyEvent *kev = static_cast<TQKeyEvent* >(e);
439 if((kev->key() == Key_Control) && (m_state == CopyingWidget)) {
442 if(m_form->formWidget())
443 m_form->formWidget()->clearForm();
448 case TQEvent::MouseButtonDblClick:
450 kdDebug() << "Container: Mouse dbl click for widget " << s->name() << endl;
451 TQWidget *w = static_cast<TQWidget* >(s);
456 m_state = InlineEditing;
457 m_form->library()->startEditing(w->className(), w, this);
461 case TQEvent::ContextMenu:
464 case TQEvent::FocusIn:
465 case TQEvent::FocusOut:
478Container::handleMouseReleaseEvent(TQObject *s, TQMouseEvent *mev)
482 if(m_form->formWidget())
483 m_form->formWidget()->clearForm();
485 m_form->addCommand(com, true);
486 m_insertBegin = TQPoint(-1,-1);
487 m_insertRect = TQRect();
490 else if(s == m_container && !m_toplevel && (mev->button() != TQt::RightButton) && m_insertRect.isValid())
495 if(mev->button() == TQt::RightButton)
499 else if(mev->state() == (TQt::LeftButton|TQt::ControlButton))
503 if(m_form->formWidget())
504 m_form->formWidget()->clearForm();
509 if( ( (mev->pos().x() - m_grab.x()) < form()->gridSize() && (m_grab.x() - mev->pos().x()) < form()->gridSize() ) &&
510 ( (mev->pos().y() - m_grab.y()) < form()->gridSize() && (m_grab.y() - mev->pos().y()) < form()->gridSize() ) )
512 kdDebug() << "The widget has not been moved. No copying" << endl;
516 m_form->setInteractiveMode( false);
519 if(m_form->selectedWidgets()->count() > 1)
524 m_form->setInteractiveMode( true);
528 else if(m_state == MovingWidget)
532 m_insertBegin = TQPoint(-1,-1);
533 m_insertRect = TQRect();
534 m_state = DoingNothing;
542 kdDebug() << "slotSelectionChanged " << w->name()<< endl;
546 m_form->setSelectedWidget(m_container);
550 m_form->setSelectedWidget(w, add, dontRaise, moreWillBeSelected);
559 m_form->unSelectWidget(w);
579 m_form->setSelectedWidget(m_container);
594 if(m_layType == type)
605 m_layout = (TQLayout*) new TQHBoxLayout(m_container, m_margin, m_spacing);
611 m_layout = (TQLayout*) new TQVBoxLayout(m_container, m_margin, m_spacing);
624 m_layout = (TQLayout*)flow;
632 m_layout = (TQLayout*)flow;
638 m_layType = NoLayout;
642 m_container->setGeometry(m_container->geometry());
643 m_layout->activate();
649 LayoutType type = m_layType;
657 TQBoxLayout * layout = static_cast<TQBoxLayout* >(m_layout);
659 for( ObjectTreeItem *tree = m_tree->children()->first(); tree; tree = m_tree->children()->next())
660 list->append( tree->widget());
663 for(TQWidget *obj = list->first(); obj; obj = list->next())
672 if(!flow || m_tree->children()->isEmpty())
675 const int offset = 15;
678 list = new VerWidgetList(m_form->toplevelContainer()->widget());
679 list2 = new HorWidgetList(m_form->toplevelContainer()->widget());
682 list = new HorWidgetList(m_form->toplevelContainer()->widget());
683 list2 = new VerWidgetList(m_form->toplevelContainer()->widget());
687 for( ObjectTreeItem *tree = m_tree->children()->first(); tree; tree = m_tree->children()->next())
688 list->append( tree->widget());
692 int y = list->first()->y();
693 for(TQWidget *w = list->first(); w; w = list->next()) {
694 if( (w->y() > y +offset)) {
697 for(TQWidget *obj = list2->first(); obj; obj = list2->next())
706 for(TQWidget *obj = list2->first(); obj; obj = list2->next())
710 int x = list->first()->x();
711 for(TQWidget *w = list->first(); w; w = list->next()) {
712 if( (w->x() > x +offset)) {
715 for(TQWidget *obj = list2->first(); obj; obj = list2->next())
724 for(TQWidget *obj = list2->first(); obj; obj = list2->next())
739 TQValueVector<int> cols;
740 TQValueVector<int> rows;
744 for( ObjectTreeItem *tree = m_tree->children()->first(); tree; tree = m_tree->children()->next())
745 vlist->append( tree->widget());
748 for( ObjectTreeItem *tree = m_tree->children()->first(); tree; tree = m_tree->children()->next())
749 hlist->append( tree->widget());
757 TQWidget *w = it.current();
760 for(; it2.current() != 0; ++it2) {
761 TQWidget *nextw = it2.current();
762 if((w->y() >= nextw->y()) || (nextw->y() >= w->geometry().bottom()))
765 if(!w->geometry().intersects(nextw->geometry()))
769 if((nextw->y() - w->y()) > abs(nextw->x() - w->x()))
770 nextw->move(nextw->x(), w->geometry().bottom()+1);
771 else if(nextw->x() >= w->x())
772 nextw->move(w->geometry().right()+1, nextw->y());
774 w->move(nextw->geometry().right()+1, nextw->y());
782 TQWidget *w = it.current();
785 end = w->geometry().bottom();
795 TQWidget *nextw = it2.current();
796 if(nextw->y() >= end)
799 same = !(same && (nextw->y() >= w->geometry().bottom()));
801 end = w->geometry().bottom();
804 kdDebug() << "the new grid will have n rows: n == " << rows.size() << endl;
811 TQWidget *w = it.current();
814 end = w->geometry().right();
822 TQWidget *nextw = it2.current();
823 if(nextw->x() >= end)
826 same = !(same && (nextw->x() >= w->geometry().right()));
828 end = w->geometry().right();
831 kdDebug() << "the new grid will have n columns: n == " << cols.size() << endl;
836 layout = new TQGridLayout(m_container, rows.size(), cols.size(), m_margin, m_spacing, "grid");
837 m_layout = (TQLayout*) layout;
843 TQWidget *w = it.current();
844 TQRect r = w->geometry();
845 uint wcol=0, wrow=0, endrow=0, endcol=0;
849 while(r.y() >= rows[i])
851 if(rows.size() <= i+1)
856 if(r.y() < rows[i+1])
861 while(rows.size() >= j+1 && r.bottom() > rows[j])
876 while(r.x() >= cols[i])
878 if(cols.size() <= i+1)
883 if(r.x() < cols[i+1])
888 while(cols.size() >= j+1 && r.right() > cols[j])
902 if(!endrow && !endcol) {
904 layout->addWidget(w, wrow, wcol);
905 item->setGridPos(wrow, wcol, 0, 0);
908 if(!endcol) endcol = wcol;
909 if(!endrow) endrow = wrow;
911 layout->addMultiCellWidget(w, wrow, endrow, wcol, endcol);
912 item->setGridPos(wrow, wcol, endrow-wrow+1, endcol-wcol+1);
922 case HBox: return "HBox";
923 case VBox: return "VBox";
924 case Grid: return "Grid";
925 case HFlow: return "HFlow";
926 case VFlow: return "VFlow";
927 default: return "NoLayout";
934 if(name == "HBox") return HBox;
935 if(name == "VBox") return VBox;
936 if(name == "Grid") return Grid;
937 if(name == "HFlow") return HFlow;
938 if(name == "VFlow") return VFlow;
946 if(mev->button() != TQt::LeftButton)
955 if(m_form->formWidget())
957 m_form->formWidget()->initBuffer();
958 m_form->formWidget()->highlightWidgets(m_moving, 0);
974 m_container->repaint();
989 if(m_form->formWidget())
990 m_form->formWidget()->clearForm();
991 int topx = (m_insertBegin.x() < mev->x()) ? m_insertBegin.x() : mev->x();
992 int topy = (m_insertBegin.y() < mev->y()) ? m_insertBegin.y() : mev->y();
993 int botx = (m_insertBegin.x() > mev->x()) ? m_insertBegin.x() : mev->x();
994 int boty = (m_insertBegin.y() > mev->y()) ? m_insertBegin.y() : mev->y();
995 TQRect r = TQRect(TQPoint(topx, topy), TQPoint(botx, boty));
998 TQWidget *widgetToSelect = 0;
1000 for( ObjectTreeItem *item = m_tree->children()->first(); item; item = m_tree->children()->next())
1002 TQWidget *w = item->widget();
1005 if(w->geometry().intersects(r) && w != m_container) {
1014 m_insertRect = TQRect();
1015 m_state = DoingNothing;
1016 m_container->repaint();
1020Container::drawInsertRect(TQMouseEvent *mev, TQObject *s)
1023 TQPoint pos = static_cast<TQWidget* >(s)->mapTo(m_container, mev->pos());
1024 int gridX = m_form->gridSize();
1025 int gridY = m_form->gridSize();
1026 if(! FormManager::self()->snapWidgetsToGrid() || (mev->state() == (TQt::LeftButton|TQt::ControlButton|TQt::AltButton)) )
1033 tmpx = int( ( float) pos.x() / (( float)gridX) + 0.5);
1035 tmpy = int( ( float)pos.y() / (( float)gridY) + 0.5);
1039 int topx = (m_insertBegin.x() < tmpx) ? m_insertBegin.x() : tmpx;
1040 int topy = (m_insertBegin.y() < tmpy) ? m_insertBegin.y() : tmpy;
1041 int botx = (m_insertBegin.x() > tmpx) ? m_insertBegin.x() : tmpx;
1042 int boty = (m_insertBegin.y() > tmpy) ? m_insertBegin.y() : tmpy;
1043 m_insertRect = TQRect(TQPoint(topx, topy), TQPoint(botx, boty));
1045 if(m_insertRect.x() < 0)
1046 m_insertRect.setLeft(0);
1047 if(m_insertRect.y() < 0)
1048 m_insertRect.setTop(0);
1049 if(m_insertRect.right() > m_container->width())
1050 m_insertRect.setRight(m_container->width());
1051 if(m_insertRect.bottom() > m_container->height())
1052 m_insertRect.setBottom(m_container->height());
1056 if(m_form->formWidget())
1058 TQRect drawRect = TQRect(m_container->mapTo(m_form->widget(), m_insertRect.topLeft())
1059 , m_insertRect.size());
1060 m_form->formWidget()->drawRect(drawRect, 2);
1066Container::drawCopiedWidgetRect(TQMouseEvent *mev)
1069 if(m_state == MovingWidget) {
1072 if(m_form->formWidget()) {
1073 m_container->repaint();
1074 m_form->formWidget()->initBuffer();
1076 m_state = CopyingWidget;
1081 if(m_form->formWidget()) {
1082 TQValueList<TQRect> rectList;
1083 for(TQWidget *w = m_form->selectedWidgets()->first(); w; w = m_form->selectedWidgets()->next()) {
1084 TQRect drawRect = w->geometry();
1085 TQPoint p = mev->pos() - m_grab;
1086 drawRect.moveBy(p.x(), p.y());
1087 p = m_container->mapTo(m_form->widget(), TQPoint(0, 0));
1089 drawRect.moveBy(p.x(), p.y());
1090 rectList.append(drawRect);
1093 m_form->formWidget()->drawRects(rectList, 2);
1101 if (m_form->selectedWidget() == m_form->widget())
1104 const int gridX = m_form->gridSize();
1105 const int gridY = m_form->gridSize();
1106 int dx=realdx, dy=realdy;
1108 for(TQWidget *w = m_form->selectedWidgets()->first(); w; w = m_form->selectedWidgets()->next())
1110 if(!w || !w->parent() || w->parent()->inherits( "TQTabWidget") || w->parent()->inherits( "TQWidgetStack"))
1113 if(w->parentWidget() && w->parentWidget()->isA( "TQWidgetStack"))
1115 w = w->parentWidget();
1116 if(w->parentWidget() && w->parentWidget()->inherits( "TQTabWidget"))
1117 w = w->parentWidget();
1120 int tmpx = w->x() + realdx;
1121 int tmpy = w->y() + realdy;
1123 dx = TQMAX(0 - w->x(), dx);
1124 else if(tmpx > w->parentWidget()->width() - gridX)
1125 dx = TQMIN(w->parentWidget()->width() - gridX - w->x(), dx);
1128 dy = TQMAX(0 - w->y(), dy);
1129 else if(tmpy > w->parentWidget()->height() - gridY)
1130 dy = TQMIN(w->parentWidget()->height() - gridY - w->y(), dy);
1133 for(TQWidget *w = m_form->selectedWidgets()->first(); w; w = m_form->selectedWidgets()->next())
1136 if(!w || !w->parent() || w->parent()->inherits( "TQTabWidget") || w->parent()->inherits( "TQWidgetStack"))
1139 if(w->parentWidget() && w->parentWidget()->isA( "TQWidgetStack"))
1141 w = w->parentWidget();
1142 if(w->parentWidget() && w->parentWidget()->inherits( "TQTabWidget"))
1143 w = w->parentWidget();
1147 if(! FormManager::self()->snapWidgetsToGrid() || (mev && mev->state() == (TQt::LeftButton|TQt::ControlButton|TQt::AltButton)) )
1154 tmpx = int( float( w->x() + dx) / float(gridX) + 0.5) * gridX;
1155 tmpy = int( float( w->y() + dy) / float(gridY) + 0.5) * gridY;
1158 if((tmpx != w->x()) || (tmpy != w->y()))
1165DesignTimeDynamicChildWidgetHandler::DesignTimeDynamicChildWidgetHandler()
1170DesignTimeDynamicChildWidgetHandler::~DesignTimeDynamicChildWidgetHandler()
1175DesignTimeDynamicChildWidgetHandler::childWidgetAdded(TQWidget* w)
1182#include "container.moc"
TQt::Orientation orientation() const
void setOrientation(TQt::Orientation orientation)
|