dtkWidgetsManager.cpp 2.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Version: $Id: a5d71ac667471276e2d9bd802e088357b82a5b0f $
//
//

// Commentary:
//
//

// Change Log:
//
//

// Code:

#include "dtkWidgetsManager.h"
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
16

17
#include "dtkWidgetsLayout.h"
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
18
#include "dtkWidgetsList.h"
19 20 21 22 23
#include "dtkWidgetsListControl.h"
#include "dtkWidgetsWidget.h"

#include <QtWidgets>

KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
24 25 26 27
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsManagerPrivate
// ///////////////////////////////////////////////////////////////////

28 29 30
class dtkWidgetsManagerPrivate
{
public:
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
31 32 33
    dtkWidgetsList *view_list = nullptr;
    dtkWidgetsLayout *view_layout = nullptr;
    QStackedWidget *view_inspector = nullptr;
34 35
};

KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
36 37 38 39
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsManager
// ///////////////////////////////////////////////////////////////////

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
dtkWidgetsManager::dtkWidgetsManager(QWidget *parent) : QFrame(parent), d(new dtkWidgetsManagerPrivate)
{
    d->view_list = new dtkWidgetsList;
    d->view_layout = new dtkWidgetsLayout;
    d->view_inspector = new QStackedWidget;

    dtkWidgetsListControl *view_control = new dtkWidgetsListControl(this);
    view_control->setLayout(d->view_layout);
    view_control->setList(d->view_list);

    QSplitter *inner = new QSplitter(Qt::Vertical, this);
    inner->setHandleWidth(2);
    inner->addWidget(view_control);
    inner->addWidget(d->view_list);
    inner->addWidget(d->view_inspector);
    inner->setSizes(QList<int>() << 32  << (parent->size().height()-32)/8 << (parent->size().height()-32)/2);

    QSplitter *splitter = new QSplitter(this);
    splitter->setHandleWidth(2);
    splitter->addWidget(inner);
    splitter->addWidget(d->view_layout);
    splitter->setSizes(QList<int>() << 300 << parent->size().width() - 300);

    QHBoxLayout *main_layout = new QHBoxLayout(this);
    main_layout->setContentsMargins(0, 0, 0, 0);
    main_layout->setSpacing(0);
    main_layout->addWidget(splitter);

    connect(d->view_layout, SIGNAL(focused(dtkWidgetsWidget *)), this, SIGNAL(focused(dtkWidgetsWidget *)));
    connect(d->view_layout, SIGNAL(focused(dtkWidgetsWidget *)), this, SLOT(onViewFocused(dtkWidgetsWidget *)));
    connect(d->view_layout, SIGNAL(unfocused(dtkWidgetsWidget *)), this, SLOT(onViewUnfocused(dtkWidgetsWidget *)));
}

dtkWidgetsManager::~dtkWidgetsManager(void)
{
    delete d;

KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
77
    d = nullptr;
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
}

void dtkWidgetsManager::clear(void)
{
    d->view_list->clear();
    d->view_layout->clear();
}

void dtkWidgetsManager::onViewFocused(dtkWidgetsWidget *widget)
{
    if (!widget->inspector())
        return;

    d->view_inspector->addWidget(widget->inspector());
    d->view_inspector->setCurrentWidget(widget->inspector());
}

void dtkWidgetsManager::onViewUnfocused(dtkWidgetsWidget *widget)
{
    if (!widget->inspector())
        return;

    d->view_inspector->removeWidget(widget->inspector());
}

dtkWidgetsLayout *dtkWidgetsManager::layout(void)
{
    return d->view_layout;
}

//
// dtkWidgetsManager.cpp ends here