Commit aed6eb54 authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

workspaceBar more or less working

parent 87dffafb
......@@ -21,12 +21,12 @@
// ///////////////////////////////////////////////////////////////////
class dummyWorkspace: public dtkWidgetsWorkspace
class dummyWorkspaceA: public dtkWidgetsWorkspace
{
Q_OBJECT
public:
dummyWorkspace(QWidget *parent = nullptr) {
dummyWorkspaceA(QWidget *parent = nullptr) {
QLabel *label = new QLabel("my dummy workspace");
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
......@@ -34,7 +34,7 @@ public:
layout->addWidget(label);
};
~dummyWorkspace(void) {};
~dummyWorkspaceA(void) {};
public:
void enter(void) override {}
......@@ -45,8 +45,36 @@ public slots:
};
inline dummyWorkspace *dummyWorkspaceCreator(void) {
return new dummyWorkspace;
static dtkWidgetsWorkspace *dummyWorkspaceCreatorA(void) {
return new dummyWorkspaceA;
}
class dummyWorkspaceB: public dtkWidgetsWorkspace
{
Q_OBJECT
public:
dummyWorkspaceB(QWidget *parent = nullptr) {
QLabel *label = new QLabel("dummy workspace B");
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(label);
};
~dummyWorkspaceB(void) {};
public:
void enter(void) override {}
void leave(void) override {}
public slots:
void apply(void) override {};
};
static dtkWidgetsWorkspace *dummyWorkspaceCreatorB(void) {
return new dummyWorkspaceB;
}
// ///////////////////////////////////////////////////////////////////
......@@ -61,25 +89,23 @@ public:
dummyWindow(QWidget *parent = nullptr);
public:
dtkWidgetsLayout *layout;
QSize sizeHint(void) const { return QSize(640, 480); }
public:
QStackedWidget *stack;
};
dummyWindow::dummyWindow(QWidget *parent) : QFrame(parent)
{
dtkWidgetsLayoutItem::Actions actions;
actions["1"] = "1";
actions["2"] = "2";
actions["3"] = "3";
actions["4"] = "4";
dtkWidgetsLayoutItem::setActions(actions);
this->stack = new QStackedWidget(this);
this->layout = new dtkWidgetsLayout(this);
this->stack->addWidget(dtk::widgets::workspace::pluginFactory().create("dummyWorkspaceA"));
this->stack->addWidget(dtk::widgets::workspace::pluginFactory().create("dummyWorkspaceB"));
QVBoxLayout *l = new QVBoxLayout(this);
l->setContentsMargins(0, 0, 0, 0);
l->setSpacing(0);
l->addWidget(this->layout);
l->addWidget(this->stack);
}
class dummyWindowBar : public QFrame
......@@ -89,35 +115,28 @@ class dummyWindowBar : public QFrame
public:
dummyWindowBar(QWidget *parent = nullptr);
// public:
// static dtkWidgetsWidget *create(const QString&);
public:
QSize sizeHint(void) const { return QSize(640, 480); }
public:
dtkWidgetsLayout *layout;
QStackedWidget *stack;
};
dummyWindowBar::dummyWindowBar(QWidget *parent) : QFrame(parent)
{
dtkWidgetsLayoutItem::Actions actions;
actions["1"] = "1";
actions["2"] = "2";
actions["3"] = "3";
actions["4"] = "4";
dtkWidgetsLayoutItem::setActions(actions);
this->layout = new dtkWidgetsLayout(this);
// this->layout->setCreator(create);
this->stack = new QStackedWidget(this);
dtkWidgetsWorkspaceBar *bar = new dtkWidgetsWorkspaceBar;
bar->setStack(this->stack);
dtk::widgets::workspace::pluginFactory().record("dummyWorkspace", dummyWorkspaceCreator);
bar->addWorkspace("My Dummy Workspace", fa::sitemap, "dummyWorkspace" );
bar->addWorkspaceInMenu("My Dummy Workspace A", fa::sitemap, "dummyWorkspaceA" );
bar->addWorkspaceInMenu("My Dummy Workspace B", fa::image, "dummyWorkspaceB" );
QVBoxLayout *l = new QVBoxLayout(this);
l->setContentsMargins(0, 0, 0, 0);
l->setSpacing(0);
l->addWidget(this->layout);
l->addWidget(stack);
l->addWidget(bar);
}
......@@ -132,6 +151,9 @@ int main(int argc, char **argv)
dtkFontAwesome::instance()->initFontAwesome();
dtk::widgets::workspace::pluginFactory().record("dummyWorkspaceA", dummyWorkspaceCreatorA);
dtk::widgets::workspace::pluginFactory().record("dummyWorkspaceB", dummyWorkspaceCreatorB);
dummyWindow *window = new dummyWindow;
window->show();
window->raise();
......
......@@ -181,9 +181,11 @@ public:
public:
bool inside = false;
int n_workspace = 0;
public:
QHBoxLayout *layout;
QHBoxLayout *layout;
QStackedWidget *stack;
public slots:
void onItemClicked(int);
......@@ -193,18 +195,24 @@ signals:
public:
void createWorkspace(const QColor &, const QString &);
public:
QList<QColor> colors;
QStringList workspaces;
};
void dtkWidgetsWorkspaceBarPrivate::createWorkspace(const QColor & color, const QString& name)
{
dtkWidgetsWorkspaceBarItem *item = new dtkWidgetsWorkspaceBarItem(color, name, q);
dtkWidgetsWorkspaceBarSeparator *separator = new dtkWidgetsWorkspaceBarSeparator(q);
this->layout->insertWidget(this->layout->count()-1, separator);
if (this->items.count() > 0) {
dtkWidgetsWorkspaceBarSeparator *separator = new dtkWidgetsWorkspaceBarSeparator(q);
this->layout->insertWidget(this->layout->count()-1, separator);
this->separators << separator;
}
this->layout->insertWidget(this->layout->count()-1, item);
this->items << item;
this->separators << separator;
connect(item, &dtkWidgetsWorkspaceBarItem::clicked, [=] () {
int index = this->items.indexOf(item);
......@@ -213,12 +221,15 @@ void dtkWidgetsWorkspaceBarPrivate::createWorkspace(const QColor & color, const
connect(item, &dtkWidgetsWorkspaceBarItem::destroy, [=] () {
int index = this->items.indexOf(item);
this->items.takeAt(index);
auto separator = this->separators.takeAt(index-1);
this->layout->removeWidget(separator);
if (index > 0) {
auto separator = this->separators.takeAt(index-1);
this->layout->removeWidget(separator);
delete separator;
}
this->layout->removeWidget(item);
delete item;
delete separator;
emit indexDeleted(index);
});
......@@ -231,6 +242,14 @@ void dtkWidgetsWorkspaceBarPrivate::onItemClicked(int index)
q->emit indexChanged(index);
//TODO highlight index
this->stack->setCurrentIndex(index);
for (dtkWidgetsWorkspaceBarItem *item : items) {
int current_index = items.indexOf(item);
QColor color = this->colors.at(this->workspaces.indexOf(item->text(),0));
item->setStyleSheet(QString("font-size: %1px; font-style: %2; color: rgb(%3,%4,%5);").arg(current_index == index ? "24" : "12").arg(current_index == index ? "bold" : "normal").arg(color.red()).arg(color.green()).arg(color.blue()));
}
}
// ///////////////////////////////////////////////////////////////////
......@@ -239,6 +258,9 @@ void dtkWidgetsWorkspaceBarPrivate::onItemClicked(int index)
dtkWidgetsWorkspaceBar::dtkWidgetsWorkspaceBar(QWidget *parent): QFrame(parent), d(new dtkWidgetsWorkspaceBarPrivate)
{
d->q = this;
d->colors << QColor("#ff3b30") << QColor("#89a348") << QColor("#a38948") << QColor("#ff9500") << QColor("#ffcc00") << QColor("#5f9ea0") << QColor("#4cd964") << QColor("#4c64d9") << QColor("#5ac8fa") << QColor("#dc143c") << QColor("#dc143c") << QColor("#5856d6") << QColor("#734906");
d->button = new dtkWidgetsWorkspaceBarButton(this);
......@@ -248,34 +270,54 @@ dtkWidgetsWorkspaceBar::dtkWidgetsWorkspaceBar(QWidget *parent): QFrame(parent),
// connect(item, &dtkWidgetsWorkspaceBarItem::clicked, [=] () { d->onItemClicked(0); });
connect(d, SIGNAL(indexDeleted(int)), this, SIGNAL(indexDeleted(int)));
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
this->setMouseTracking(true);
QShortcut *nextWS = new QShortcut(QKeySequence(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_PageDown), this);
QShortcut *prevWS = new QShortcut(QKeySequence(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_PageUp), this);
}
connect(nextWS, &QShortcut::activated, [=] (void) {
int count = d->stack->count();
int index = (d->stack->currentIndex()+1) % count ;
this->setCurrentIndex(index);
});
connect(prevWS, &QShortcut::activated, [=] (void) {
int count = d->stack->count();
int index = (d->stack->currentIndex()+count-1) % count;
this->setCurrentIndex(index);
});
void dtkWidgetsWorkspaceBar::addWorkspace(const QString& workspace_name, int icon, const QString & type)
{
d->q = this;
QAction *action = d->button->menu->addAction(dtkFontAwesome::instance()->icon(fa::image),workspace_name);
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
this->setMouseTracking(true);
}
connect(action, &QAction::triggered, [=] (bool triggered)
{
QColor color = Qt::red; //FIXME
d->createWorkspace(color, workspace_name);
dtkWidgetsWorkspace *workspace = dtk::widgets::workspace::pluginFactory().create(type);
//TODO: add workspace in stack
}
);
void dtkWidgetsWorkspaceBar::setStack(QStackedWidget *stack)
{
d->stack = stack;
}
void dtkWidgetsWorkspaceBar::addWorkspaceInMenu(const QString& workspace_name, int icon, const QString & type)
{
d->workspaces << workspace_name;
QAction *action = d->button->menu->addAction(dtkFontAwesome::instance()->icon(icon), workspace_name);
connect(action, &QAction::triggered, [=] (bool triggered) {
this->createWorkspace(workspace_name, type);
});
}
void dtkWidgetsWorkspaceBar::onCreateWorkspace(const QString& type)
void dtkWidgetsWorkspaceBar::createWorkspace(const QString &name, const QString& type)
{
QColor color = d->colors.at(d->workspaces.indexOf(name,0) % d->colors.count()) ;
d->createWorkspace(color, name);
dtkWidgetsWorkspace *workspace = dtk::widgets::workspace::pluginFactory().create(type);
if (!workspace) {
qWarning() << "can't create workspace of type" << type << dtk::widgets::workspace::pluginFactory().keys();
return;
}
d->stack->addWidget(workspace);
d->stack->setCurrentWidget(workspace);
}
dtkWidgetsWorkspaceBar::~dtkWidgetsWorkspaceBar(void)
......
......@@ -14,15 +14,18 @@ public:
dtkWidgetsWorkspaceBar(QWidget *parent = nullptr);
virtual ~dtkWidgetsWorkspaceBar();
public:
void setStack(QStackedWidget *stack);
signals:
void indexChanged(int);
void indexDeleted(int);
public slots:
void addWorkspace(const QString& workspace_name, int icon, const QString& type);
void addWorkspaceInMenu(const QString& workspace_name, int icon, const QString& type);
public slots:
void onCreateWorkspace(const QString& type);
void createWorkspace(const QString &name, const QString& type);
protected:
void enterEvent(QEvent *);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment