Make ViewContainerTabBar and TabbedViewContainer less coupled

In general, those two classes are coupled too closely. Ideally,
TabbedViewContainer should be transformed into a generic enhanced tabbar
which knows nothing about TabbedViewContainer or its user.
wilder-portage
Jekyll Wu 14 years ago
parent daa99b67fd
commit 73d7da6d87
  1. 31
      src/ViewContainer.cpp
  2. 4
      src/ViewContainer.h

@ -357,22 +357,15 @@ int ViewContainerTabBar::dropIndex(const QPoint& pos) const
}
bool ViewContainerTabBar::proposedDropIsSameTab(const QDropEvent* event) const
{
const int index = dropIndex(event->pos());
const int droppedId = ViewProperties::decodeMimeData(event->mimeData());
const bool sameTabBar = event->source() == this;
if (!sameTabBar)
return false;
const QList<QWidget*> viewList = _container->views();
const int index = dropIndex(event->pos());
int sourceIndex = -1;
for (int i = 0; i < count(); i++) {
int idAtIndex = _container->viewProperties(viewList[i])->identifier();
if (idAtIndex == droppedId)
sourceIndex = i;
}
emit querySourceIndex(event, sourceIndex);
bool sourceAndDropAreLast = sourceIndex == count() - 1 && index == -1;
const bool sourceAndDropAreLast = sourceIndex == count() - 1 && index == -1;
if (sourceIndex == index || sourceIndex == index - 1 || sourceAndDropAreLast)
return true;
else
@ -442,6 +435,8 @@ TabbedViewContainer::TabbedViewContainer(NavigationPosition position , QObject*
connect(_tabBar, SIGNAL(newTabRequest()), this, SIGNAL(newViewRequest()));
connect(_tabBar, SIGNAL(wheelDelta(int)), this, SLOT(wheelScrolled(int)));
connect(_tabBar, SIGNAL(initiateDrag(int)), this, SLOT(startTabDrag(int)));
connect(_tabBar, SIGNAL(querySourceIndex(const QDropEvent*,int&)),
this, SLOT(querySourceIndex(const QDropEvent*,int&)));
connect(_tabBar, SIGNAL(contextMenu(int,QPoint)), this,
SLOT(openTabContextMenu(int,QPoint)));
@ -673,6 +668,22 @@ void TabbedViewContainer::startTabDrag(int tab)
}
}
void TabbedViewContainer::querySourceIndex(const QDropEvent* event ,int& sourceIndex)
{
const int droppedId = ViewProperties::decodeMimeData(event->mimeData());
const QList<QWidget*> viewList = views();
const int count = viewList.count();
int index = -1 ;
for (index = 0; index < count; index++) {
const int id = viewProperties(viewList[index])->identifier();
if (id == droppedId)
break;
}
sourceIndex = index;
}
void TabbedViewContainer::tabDoubleClicked(int index)
{
renameTab(index);

@ -362,6 +362,9 @@ public:
// returns a pixmap image of a tab for use with QDrag
QPixmap dragDropPixmap(int tab);
signals:
void querySourceIndex(const QDropEvent* event, int& sourceIndex) const;
protected:
virtual void dragEnterEvent(QDragEnterEvent* event);
virtual void dragLeaveEvent(QDragLeaveEvent* event);
@ -434,6 +437,7 @@ private slots:
void tabContextMenuRenameTab();
void tabContextMenuDetachTab();
void startTabDrag(int index);
void querySourceIndex(const QDropEvent* event, int& sourceIndex);
signals:
void detachTab(ViewContainer * self, QWidget * activeView);

Loading…
Cancel
Save