Commit 551e2129 authored by Julien Wintz's avatar Julien Wintz
Browse files

Fixed view management framework.

parent 90173b78
......@@ -46,7 +46,7 @@ if(SWIG_FOUND)
"-outdir" ${CMAKE_CURRENT_BINARY_DIR}
"-o" ${wrap_output}
${input}
MAIN_DEPENDENCY ${input}
MAIN_DEPENDENCY ${deps}
COMMENT "Wrapping ${input} to ${language}")
set(${target} ${${target}} ${wrap_output})
......
......@@ -44,7 +44,7 @@ if(DTK_BUILD_WRAPPERS AND SWIG_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dtkLog.i ${CMAKE_BINARY_DIR}/dtkLog.i COPYONLY)
set(${PROJECT_NAME}_WRAP_DEPENDS ${${PROJECT_NAME}_HEADERS})
set(${PROJECT_NAME}_WRAP_DEPENDS ${CMAKE_BINARY_DIR}/dtkLog.i ${${PROJECT_NAME}_HEADERS})
if (DTK_WRAPPING_PYTHON)
if (PYTHONLIBS_FOUND)
......@@ -170,8 +170,6 @@ if(DTK_BUILD_WRAPPERS AND SWIG_FOUND)
endif(DTK_BUILD_WRAPPERS AND SWIG_FOUND)
## ###################################################################
## Install rules - files
## ###################################################################
......
......@@ -46,6 +46,8 @@ set(${PROJECT_NAME}_HEADERS
dtkViewListControl.h
dtkViewManager
dtkViewManager.h
dtkViewWidget
dtkViewWidget.h
dtkWidgets
dtkWidgetsLogView.h
dtkWidgetsLogView_p.h
......@@ -87,6 +89,7 @@ set(${PROJECT_NAME}_SOURCES
dtkViewList.cpp
dtkViewListControl.cpp
dtkViewManager.cpp
dtkViewWidget.cpp
dtkWidgetsLogView.cpp
dtkWidgetsTag.cpp
dtkWidgetsTagCloud.cpp
......@@ -204,7 +207,6 @@ set(${PROJECT_NAME}_HEADERS
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}Export"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}Export.h")
## #################################################################
## Handling of generated script modules
## #################################################################
......@@ -257,7 +259,6 @@ if(DTK_BUILD_WRAPPERS AND SWIG_FOUND)
endif(DTK_BUILD_WRAPPERS AND SWIG_FOUND)
## ###################################################################
## Install rules - files
## ###################################################################
......
#include "dtkViewController.h"
#include "dtkViewController.h"
\ No newline at end of file
......@@ -13,22 +13,23 @@
// Code:
#include "dtkViewController.h"
#include "dtkViewWidget.h"
class dtkViewControllerPrivate
{
public:
QMap<QString, QWidget *> views;
QHash<QString, dtkViewWidget *> views;
};
dtkViewController *dtkViewController::instance(void)
{
if(!s_instance)
if (!s_instance)
s_instance = new dtkViewController;
return s_instance;
}
void dtkViewController::add(QWidget *view)
void dtkViewController::insert(dtkViewWidget *view)
{
QString name = view->objectName();
......@@ -37,20 +38,20 @@ void dtkViewController::add(QWidget *view)
d->views.insert(name, view);
emit created(view, name);
emit inserted(view, name);
}
QStringList dtkViewController::viewNames(void)
dtkViewWidget *dtkViewController::view(const QString& name)
{
return d->views.keys();
return d->views.value(name);
}
QWidget *dtkViewController::view(const QString& name)
QStringList dtkViewController::viewNames(void)
{
return d->views.value(name, Q_NULLPTR);
return d->views.keys();
}
dtkViewController::dtkViewController(void)
dtkViewController::dtkViewController(void) : QObject()
{
d = new dtkViewControllerPrivate;
}
......@@ -60,7 +61,7 @@ dtkViewController::~dtkViewController(void)
delete d;
}
dtkViewController *dtkViewController::s_instance = Q_NULLPTR;
dtkViewController *dtkViewController::s_instance = NULL;
//
// dtkViewController.cpp ends here
......@@ -14,10 +14,11 @@
#pragma once
#include <dtkWidgetsExport.h>
#include <QtCore>
#include <QtWidgets>
#include <dtkWidgetsExport.h>
class dtkViewWidget;
class DTKWIDGETS_EXPORT dtkViewController : public QObject
{
......@@ -26,26 +27,25 @@ class DTKWIDGETS_EXPORT dtkViewController : public QObject
public:
static dtkViewController *instance(void);
signals:
void created(QWidget *, const QString&);
void cleared(void);
public:
void insert(dtkViewWidget *);
public slots:
void add(QWidget *view);
public:
dtkViewWidget *view(const QString& name);
public:
QStringList viewNames(void);
public:
QWidget *view(const QString& name);
signals:
void inserted(dtkViewWidget *, const QString&);
protected:
static dtkViewController *s_instance;
private:
dtkViewController(void);
~dtkViewController(void);
private:
static dtkViewController *s_instance;
private:
class dtkViewControllerPrivate *d;
};
......
......@@ -35,8 +35,8 @@ dtkViewLayout::dtkViewLayout(QWidget *parent) : QFrame(parent), d(new dtkViewLay
layout->setSpacing(0);
layout->addWidget(d->root);
connect(d->root, SIGNAL(focused(QWidget *)), this, SIGNAL(focused(QWidget *)));
connect(d->root, SIGNAL(unfocused(QWidget *)), this, SIGNAL(unfocused(QWidget *)));
connect(d->root, SIGNAL(focused(dtkViewWidget *)), this, SIGNAL(focused(dtkViewWidget *)));
connect(d->root, SIGNAL(unfocused(dtkViewWidget *)), this, SIGNAL(unfocused(dtkViewWidget *)));
}
dtkViewLayout::~dtkViewLayout(void)
......
......@@ -20,6 +20,7 @@
class dtkViewLayoutItem;
class dtkViewLayoutPrivate;
class dtkViewWidget;
class DTKWIDGETS_EXPORT dtkViewLayout : public QFrame
{
......@@ -37,8 +38,8 @@ public:
void setCurrent(dtkViewLayoutItem *item);
signals:
void focused(QWidget *view);
void unfocused(QWidget *view);
void focused(dtkViewWidget *view);
void unfocused(dtkViewWidget *view);
public slots:
void clear(void);
......
......@@ -15,9 +15,9 @@
#include "dtkViewController.h"
#include "dtkViewLayout.h"
#include "dtkViewLayoutItem.h"
#include "dtkViewWidget.h"
#include <QtWidgets>
#include <QtGlobal>
// /////////////////////////////////////////////////////////////////
// dtkViewLayoutItemProxyPrivate
......@@ -26,7 +26,7 @@
class dtkViewLayoutItemProxyPrivate
{
public:
QWidget *view;
dtkViewWidget *view;
};
// /////////////////////////////////////////////////////////////////
......@@ -77,7 +77,7 @@ public:
dtkViewLayoutItemProxy::dtkViewLayoutItemProxy(QWidget *parent) : QFrame(parent), d(new dtkViewLayoutItemProxyPrivate)
{
d->view = Q_NULLPTR;
d->view = NULL;
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
......@@ -91,18 +91,21 @@ dtkViewLayoutItemProxy::~dtkViewLayoutItemProxy(void)
if (!d->view)
goto finalize;
if (!d->view->parentWidget())
if (!d->view->widget())
goto finalize;
if (dtkViewLayoutItemProxy *proxy = dynamic_cast<dtkViewLayoutItemProxy *>(d->view->parentWidget())) {
if (!d->view->widget()->parentWidget())
goto finalize;
if (dtkViewLayoutItemProxy *proxy = dynamic_cast<dtkViewLayoutItemProxy *>(d->view->widget()->parentWidget())) {
if (proxy == this) {
layout()->removeWidget(d->view);
d->view->setParent(0);
d->view->widget()->setParent(0);
d->view->disconnect();
disconnect(d->view, SIGNAL(focused()), proxy, SIGNAL(focusedIn()));
d->view = NULL;
}
......@@ -115,42 +118,36 @@ finalize:
d = NULL;
}
QWidget *dtkViewLayoutItemProxy::view(void)
dtkViewWidget *dtkViewLayoutItemProxy::view(void)
{
return d->view;
}
void dtkViewLayoutItemProxy::setView(QWidget *view)
void dtkViewLayoutItemProxy::setView(dtkViewWidget *view)
{
if (!view)
return;
if (dtkViewLayoutItemProxy *proxy = dynamic_cast<dtkViewLayoutItemProxy *>(view->parentWidget())) {
proxy->layout()->removeWidget(view);
if (dtkViewLayoutItemProxy *proxy = dynamic_cast<dtkViewLayoutItemProxy *>(view->widget()->parentWidget())) {
proxy->layout()->removeWidget(view->widget());
proxy->d->view = NULL;
if (dtkViewLayoutItem *item = dynamic_cast<dtkViewLayoutItem *>(proxy->parentWidget()->parentWidget())) {
item->d->label->clear();
}
view->disconnect();
disconnect(view, SIGNAL(focused()), proxy, SIGNAL(focusedIn()));
}
else {
this->layout()->addWidget(view);
this->layout()->addWidget(view->widget());
d->view = view;
d->view->setParent(this);
d->view->show();
d->view = view;
}
connect(view, SIGNAL(focused()), this, SIGNAL(focusedIn()));
if (dtkViewLayoutItem *item = dynamic_cast<dtkViewLayoutItem *>(this->parentWidget()->parentWidget())) {
this->updateLabel();
if (dtkViewLayoutItem *item = dynamic_cast<dtkViewLayoutItem *>(this->parentWidget()->parentWidget())) {
item->d->label->setText(d->view->objectName());
item->d->close->setEnabled(true);
item->d->vertc->setEnabled(true);
item->d->horzt->setEnabled(true);
......@@ -160,19 +157,6 @@ void dtkViewLayoutItemProxy::setView(QWidget *view)
}
}
void dtkViewLayoutItemProxy::updateLabel(void)
{
if(!d->view)
return;
if (dtkViewLayoutItem *item = dynamic_cast<dtkViewLayoutItem *>(this->parentWidget()->parentWidget())) {
QString text = d->view->objectName();
item->d->label->setText(text);
}
}
void dtkViewLayoutItemProxy::focusInEvent(QFocusEvent *event)
{
QFrame::focusInEvent(event);
......@@ -206,6 +190,7 @@ dtkViewLayoutItemProxy *dtkViewLayoutItemPrivate::firstViewChild(dtkViewLayoutIt
}
// /////////////////////////////////////////////////////////////////
// dtkViewLayoutItem
// /////////////////////////////////////////////////////////////////
dtkViewLayoutItem::dtkViewLayoutItem(dtkViewLayoutItem *parent) : QFrame(parent), d(new dtkViewLayoutItemPrivate)
......@@ -216,7 +201,7 @@ dtkViewLayoutItem::dtkViewLayoutItem(dtkViewLayoutItem *parent) : QFrame(parent)
d->layout = NULL;
if((d->parent = parent)) {
if ((d->parent = parent)) {
d->root = d->parent->d->root;
d->layout = d->parent->d->layout;
} else {
......@@ -279,7 +264,7 @@ dtkViewLayoutItem::~dtkViewLayoutItem(void)
d = NULL;
}
QWidget *dtkViewLayoutItem::view(void)
dtkViewWidget *dtkViewLayoutItem::view(void)
{
if (this->proxy())
return proxy()->view();
......@@ -401,7 +386,8 @@ void dtkViewLayoutItem::split(void)
d->a->d->proxy->setFocus(Qt::OtherFocusReason);
d->a->d->proxy->setView(d->proxy->view());
d->proxy->disconnect();
disconnect(d->proxy, SIGNAL(focusedIn()), this, SLOT(onFocusedIn()));
disconnect(d->proxy, SIGNAL(focusedOut()), this, SLOT(onFocusedOut()));
delete d->proxy;
......@@ -447,8 +433,8 @@ void dtkViewLayoutItem::unsplit(void)
dtkViewLayoutItemProxy *child = NULL;
if(!(child = dtkViewLayoutItemPrivate::firstViewChild(d->a)))
child = dtkViewLayoutItemPrivate::firstViewChild(d->b);
if (!(child = dtkViewLayoutItemPrivate::firstViewChild(d->a)))
child = dtkViewLayoutItemPrivate::firstViewChild(d->b);
if (child)
child->setFocus(Qt::OtherFocusReason);
......@@ -502,8 +488,8 @@ void dtkViewLayoutItem::unsplit(void)
dtkViewLayoutItemProxy *child = NULL;
if(!(child = dtkViewLayoutItemPrivate::firstViewChild(d->a)))
child = dtkViewLayoutItemPrivate::firstViewChild(d->b);
if (!(child = dtkViewLayoutItemPrivate::firstViewChild(d->a)))
child = dtkViewLayoutItemPrivate::firstViewChild(d->b);
if (child)
child->setFocus(Qt::OtherFocusReason);
......@@ -579,7 +565,7 @@ void dtkViewLayoutItem::onFocusedIn(void)
d->footer->style()->polish(d->footer);
d->footer->update();
if(d->proxy->view())
if (d->proxy->view())
d->root->notify(d->proxy->view());
}
......@@ -651,12 +637,12 @@ void dtkViewLayoutItem::dropEvent(QDropEvent *event)
if (d->proxy->view())
return;
QWidget *view = dtkViewController::instance()->view(event->mimeData()->text());
dtkViewWidget *view = dtkViewController::instance()->view(event->mimeData()->text());
d->proxy->setView(view);
}
void dtkViewLayoutItem::notify(QWidget *view)
void dtkViewLayoutItem::notify(dtkViewWidget *view)
{
if (d->root == this)
emit focused(view);
......
......@@ -20,6 +20,7 @@
class dtkViewLayout;
class dtkViewLayoutItemPrivate;
class dtkViewWidget;
// /////////////////////////////////////////////////////////////////
// dtkViewLayoutItemProxy
......@@ -36,10 +37,10 @@ public:
~dtkViewLayoutItemProxy(void);
public:
QWidget *view(void);
dtkViewWidget *view(void);
public:
void setView(QWidget *view);
void setView(dtkViewWidget *view);
signals:
void focusedIn(void);
......@@ -49,9 +50,6 @@ protected:
void focusInEvent(QFocusEvent *event);
void focusOutEvent(QFocusEvent *event);
protected slots:
void updateLabel(void);
private:
dtkViewLayoutItemProxyPrivate *d;
};
......@@ -69,7 +67,7 @@ public:
~dtkViewLayoutItem(void);
public:
QWidget *view(void);
dtkViewWidget *view(void);
public:
dtkViewLayoutItem *parent(void);
......@@ -102,8 +100,8 @@ public slots:
void maximize(void);
signals:
void focused(QWidget *view);
void unfocused(QWidget *view);
void focused(dtkViewWidget *view);
void unfocused(dtkViewWidget *view);
protected slots:
void close(void);
......@@ -122,7 +120,7 @@ protected:
void dropEvent(QDropEvent *);
private:
void notify(QWidget *view);
void notify(dtkViewWidget *view);
private:
dtkViewLayoutItemPrivate *d;
......
......@@ -14,6 +14,7 @@
#include "dtkViewController.h"
#include "dtkViewList.h"
#include "dtkViewWidget.h"
class dtkViewListPrivate
{
......@@ -26,43 +27,32 @@ dtkViewList::dtkViewList(QWidget *parent) : QListWidget(parent), d(new dtkViewLi
this->setAttribute(Qt::WA_MacShowFocusRect, false);
this->setDragEnabled(true);
this->setFrameStyle(QFrame::NoFrame);
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
connect(dtkViewController::instance(), SIGNAL(created(QWidget *, const QString&)), this, SLOT(update()));
connect(dtkViewController::instance(), SIGNAL(cleared()), this, SLOT(clear()));
connect(dtkViewController::instance(), SIGNAL(inserted(dtkViewWidget *, const QString&)), this, SLOT(update()));
this->update();
}
dtkViewList::~dtkViewList(void)
{
foreach (QWidget *view, d->connected_views) {
disconnect(view, SIGNAL(objectNameChanged(const QString&)), this, SLOT(update()));
}
delete d;
d = NULL;
};
}
void dtkViewList::update(void)
{
this->clear();
foreach(QString objectName, dtkViewController::instance()->viewNames()) {
foreach (QString objectName, dtkViewController::instance()->viewNames()) {
QWidget *view = dtkViewController::instance()->view(objectName);
QListWidgetItem *item = new QListWidgetItem;
QString text = objectName;
item->setText(objectName);
item->setText(text);
this->addItem(item);
if (!d->connected_views.contains(view)) {
connect(view, SIGNAL(objectNameChanged(const QString&)), this, SLOT(update()));
if(!d->connected_views.contains(view)) {
d->connected_views.append(view);
}
}
......
......@@ -12,8 +12,6 @@
// Code:
#pragma once
#include <dtkWidgetsExport.h>
#include <QtWidgets>
......@@ -25,7 +23,7 @@ class DTKWIDGETS_EXPORT dtkViewList : public QListWidget
Q_OBJECT
public:
dtkViewList(QWidget *parent = 0);
dtkViewList(QWidget *parent = 0);
~dtkViewList(void);
public slots:
......
......@@ -60,11 +60,6 @@ dtkViewListControl::~dtkViewListControl(void)
d = NULL;
}
QSize dtkViewListControl::sizeHint(void) const
{
return QSize(100, 40);
}
void dtkViewListControl::setLayout(dtkViewLayout *layout)
{
d->layout = layout;
......@@ -94,7 +89,7 @@ void dtkViewListControl::onActorStarted(QString view_name)
if (!d->layout)
return;
QWidget *view = dtkViewController::instance()->view(view_name);
dtkViewWidget *view = dtkViewController::instance()->view(view_name);
if (view && !d->layout->current()->proxy()->view())
d->layout->current()->proxy()->setView(view);
......@@ -121,7 +116,6 @@ void dtkViewListControl::layoutHorizontally(void)
current->proxy()->setView(dtkViewController::instance()->view(d->list->item(i - 1)->text().split(" ").first()));
if (i != n) {
QList<int> sizes = QList<int>() << v << current->width() - s - v;
current->split();
current->setSizes(sizes);
......@@ -158,7 +152,6 @@ void dtkViewListControl::layoutVertically(void)
current->proxy()->setView(dtkViewController::instance()->view(d->list->item(i - 1)->text().split(" ").first()));
if (i != n) {
QList<int> sizes = QList<int>() << v + f << current->height() - s - v - f;
current->split();
current->setSizes(sizes);
......
......@@ -27,12 +27,9 @@ class DTKWIDGETS_EXPORT dtkViewListControl : public QFrame
Q_OBJECT
public:
dtkViewListControl(QWidget *parent = 0);
dtkViewListControl(QWidget *parent = 0);
~dtkViewListControl(void);
public:
QSize sizeHint(void) const;
public:
void setLayout(dtkViewLayout *layout);
void setList(dtkViewList *list);
......
......@@ -16,6 +16,7 @@
#include "dtkViewList.h"
#include "dtkViewLayout.h"
#include "dtkViewListControl.h"
#include "dtkViewWidget.h"
#include <QtWidgets>
......@@ -24,31 +25,29 @@ class dtkViewManagerPrivate
public:
dtkViewList *view_list;
dtkViewLayout *view_layout;
QStackedWidget *view_inspector;
};
dtkViewManager::dtkViewManager(QWidget *parent) : QFrame(parent), d(new dtkViewManagerPrivate)
{