Commit 87dffafb authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

wip: add dtkWidgetsWorkspace abstraction and implement workspace bar

parent 4609d3d1
......@@ -21,6 +21,7 @@ add_subdirectory(dtkWidgetsOverlayPaneItems)
add_subdirectory(dtkWidgetsParameter)
add_subdirectory(dtkWidgetsParameterMenuBarGenerator)
add_subdirectory(dtkWidgetsScroller)
add_subdirectory(dtkWidgetsWorkspace)
######################################################################
### CMakeLists.txt ends here
## Version: $Id$
##
######################################################################
##
### Commentary:
##
######################################################################
##
### Change Log:
##
######################################################################
##
### Code:
project(dtkWidgetsWorkspace)
## #################################################################
## Sources
## #################################################################
set(${PROJECT_NAME}_SOURCES main.cpp)
## #################################################################
## Build rules
## #################################################################
add_executable(${PROJECT_NAME}
${${PROJECT_NAME}_SOURCES})
target_link_libraries(${PROJECT_NAME} Qt5::Core)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} dtkWidgets)
target_link_libraries(${PROJECT_NAME} dtkCore)
######################################################################
### CMakeLists.txt ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include <QtWidgets>
#include <dtkWidgets>
#include <dtkFonts>
// ///////////////////////////////////////////////////////////////////
// dummy workspace
// ///////////////////////////////////////////////////////////////////
class dummyWorkspace: public dtkWidgetsWorkspace
{
Q_OBJECT
public:
dummyWorkspace(QWidget *parent = nullptr) {
QLabel *label = new QLabel("my dummy workspace");
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(label);
};
~dummyWorkspace(void) {};
public:
void enter(void) override {}
void leave(void) override {}
public slots:
void apply(void) override {};
};
inline dummyWorkspace *dummyWorkspaceCreator(void) {
return new dummyWorkspace;
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dummyWindow : public QFrame
{
Q_OBJECT
public:
dummyWindow(QWidget *parent = nullptr);
public:
dtkWidgetsLayout *layout;
};
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->layout = new dtkWidgetsLayout(this);
QVBoxLayout *l = new QVBoxLayout(this);
l->setContentsMargins(0, 0, 0, 0);
l->setSpacing(0);
l->addWidget(this->layout);
}
class dummyWindowBar : public QFrame
{
Q_OBJECT
public:
dummyWindowBar(QWidget *parent = nullptr);
// public:
// static dtkWidgetsWidget *create(const QString&);
public:
dtkWidgetsLayout *layout;
};
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);
dtkWidgetsWorkspaceBar *bar = new dtkWidgetsWorkspaceBar;
dtk::widgets::workspace::pluginFactory().record("dummyWorkspace", dummyWorkspaceCreator);
bar->addWorkspace("My Dummy Workspace", fa::sitemap, "dummyWorkspace" );
QVBoxLayout *l = new QVBoxLayout(this);
l->setContentsMargins(0, 0, 0, 0);
l->setSpacing(0);
l->addWidget(this->layout);
l->addWidget(bar);
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
QApplication application(argc, argv);
dtkFontAwesome::instance()->initFontAwesome();
dummyWindow *window = new dummyWindow;
window->show();
window->raise();
dummyWindowBar *windowBar = new dummyWindowBar;
windowBar->show();
windowBar->raise();
return application.exec();
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
#include "main.moc"
//
// main.cpp ends here
......@@ -82,7 +82,11 @@ set(${PROJECT_NAME}_HEADERS
dtkWidgetsSettings
dtkWidgetsSettings.h
dtkWidgetsWidget
dtkWidgetsWidget.h)
dtkWidgetsWidget.h
dtkWidgetsWorkspace
dtkWidgetsWorkspace.h
dtkWidgetsWorkspaceBar
dtkWidgetsWorkspaceBar.h)
set(${PROJECT_NAME}_SOURCES
dtkApplication.cpp
......@@ -116,7 +120,9 @@ set(${PROJECT_NAME}_SOURCES
dtkWidgetsParameterMenuBarGenerator.cpp
dtkWidgetsParameterStringListComboBox.cpp
dtkWidgetsSettings.cpp
dtkWidgetsWidget.cpp)
dtkWidgetsWidget.cpp
dtkWidgetsWorkspace.cpp
dtkWidgetsWorkspaceBar.cpp)
## #################################################################
## Build rules
......
......@@ -28,3 +28,5 @@
#include "dtkWidgetsParameterStringListComboBox.h"
#include "dtkWidgetsSettings.h"
#include "dtkWidgetsWidget.h"
#include "dtkWidgetsWorkspace.h"
#include "dtkWidgetsWorkspaceBar.h"
......@@ -27,6 +27,8 @@
#include "dtkWidgetsParameterFactory.h"
#include "dtkWidgetsWorkspace.h"
// /////////////////////////////////////////////////////////////////
// Layer methods implementations
// /////////////////////////////////////////////////////////////////
......
#include "dtkWidgetsWorkspace.h"
#include "dtkWidgetsWorkspace.h"
#include "dtkWidgets.h"
dtkWidgetsWorkspace::dtkWidgetsWorkspace(QWidget *parent): QWidget(parent)
{
}
namespace dtk {
namespace widgets {
DTK_DEFINE_CONCEPT(dtkWidgetsWorkspace, workspace, dtk::widgets);
}
}
#pragma once
#include <dtkWidgetsExport>
#include <dtkCore>
#include <QtWidgets>
class DTKWIDGETS_EXPORT dtkWidgetsWorkspace: public QWidget
{
Q_OBJECT
public:
dtkWidgetsWorkspace(QWidget *parent = nullptr);
public:
virtual void enter(void) = 0;
virtual void leave(void) = 0;
public slots:
virtual void apply(void) = 0;
};
// ///////////////////////////////////////////////////////////////////
// Give the concept the plugin machinery
// ///////////////////////////////////////////////////////////////////
DTK_DECLARE_OBJECT (dtkWidgetsWorkspace *)
DTK_DECLARE_PLUGIN (dtkWidgetsWorkspace, DTKWIDGETS_EXPORT)
DTK_DECLARE_PLUGIN_FACTORY(dtkWidgetsWorkspace, DTKWIDGETS_EXPORT)
DTK_DECLARE_PLUGIN_MANAGER(dtkWidgetsWorkspace, DTKWIDGETS_EXPORT)
namespace dtk {
namespace widgets {
DTK_DECLARE_CONCEPT(dtkWidgetsWorkspace, DTKWIDGETS_EXPORT, workspace);
}
}
#include "dtkWidgetsWorkspaceBar.h"
#include <dtkFonts>
#include "dtkWidgets.h"
#include "dtkWidgetsWorkspace.h"
// ///////////////////////////////////////////////////////////////////
// Button
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsWorkspaceBarButton : public QLabel
{
Q_OBJECT
public:
dtkWidgetsWorkspaceBarButton(QWidget *parent = nullptr);
public slots:
void create(QAction *);
protected:
void mousePressEvent(QMouseEvent *);
public:
QMenu *menu;
};
dtkWidgetsWorkspaceBarButton::dtkWidgetsWorkspaceBarButton(QWidget *parent): QLabel(parent)
{
dtkFontAwesome::instance()->setDefaultOption("color", QColor("#ff0000"));
this->setAlignment(Qt::AlignCenter);
this->setPixmap(dtkFontAwesome::instance()->icon(fa::plussquare).pixmap(32, 32));
this->setFixedWidth(32);
this->menu = new QMenu(this);
this->menu->setStyleSheet("QMenu::item {padding: 2px 20px 2px 30px; border: 1px solid transparent; spacing: 10px; height: 50px; width: 300px; font-size: 16pt;} QMenu::icon {width: 50px; height:50px;}");
}
void dtkWidgetsWorkspaceBarButton::create(QAction *action)
{
//TODO
}
void dtkWidgetsWorkspaceBarButton::mousePressEvent(QMouseEvent *event)
{
this->menu->exec(event->globalPos());
}
// ///////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////
// gnomonItemButton
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsWorkspaceItemButton : public QLabel
{
Q_OBJECT
public:
dtkWidgetsWorkspaceItemButton(const QColor& color, int icon, QWidget *parent = nullptr);
signals:
void clicked(void);
protected:
void mousePressEvent(QMouseEvent *);
};
dtkWidgetsWorkspaceItemButton::dtkWidgetsWorkspaceItemButton(const QColor& color, int icon, QWidget *parent): QLabel(parent)
{
dtkFontAwesome::instance()->setDefaultOption("color", color);
this->setPixmap(dtkFontAwesome::instance()->icon(icon).pixmap(16, 16));
this->setStyleSheet("background: none; border: none;");
}
void dtkWidgetsWorkspaceItemButton::mousePressEvent(QMouseEvent *e)
{
emit clicked();
};
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsWorkspaceBarItem
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsWorkspaceBarItem : public QLabel
{
Q_OBJECT
public:
dtkWidgetsWorkspaceBarItem(const QColor& color, const QString& label, QWidget *parent = nullptr, bool display_destroy = true) : QLabel(label, parent) {
m_color = color;
if (display_destroy) {
this->button_destroy = new dtkWidgetsWorkspaceItemButton(color, fa::times, this);
this->button_destroy->setAlignment(Qt::AlignRight);
this->button_destroy->setVisible(false);
connect(this->button_destroy, SIGNAL(clicked()), this, SIGNAL(destroy()));
}
this->setAlignment(Qt::AlignCenter);
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
this->setMouseTracking(true);
this->setStyleSheet(QString("color: rgb(%1,%2,%3);").arg(color.red()).arg(color.green()).arg(color.blue()));
};
signals:
void clicked(void);
void destroy(void);
public:
dtkWidgetsWorkspaceItemButton *button_destroy = nullptr;
public:
const QColor& color(void) { return m_color; } ;
protected:
void mousePressEvent(QMouseEvent *) {
emit clicked();
}
void enterEvent(QEvent *)
{
if (this->button_destroy)
this->button_destroy->setVisible(true);
}
void leaveEvent(QEvent *)
{
if (this->button_destroy)
this->button_destroy->setVisible(false);
}
private:
QColor m_color;
};
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsWorkspaceBarSeparator
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsWorkspaceBarSeparator : public QLabel
{
public:
dtkWidgetsWorkspaceBarSeparator(QWidget *parent) : QLabel(parent) {
dtkFontAwesome::instance()->setDefaultOption("color", QColor("#777777"));
this->setAlignment(Qt::AlignCenter);
this->setPixmap(dtkFontAwesome::instance()->icon(fa::chevronright).pixmap(32, 32));
this->setFixedWidth(32);
}
};
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsWorkspaceBarPrivate
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsWorkspaceBarPrivate: public QObject
{
Q_OBJECT
public:
dtkWidgetsWorkspaceBar *q;
public:
QList<dtkWidgetsWorkspaceBarItem *> items;
QList<dtkWidgetsWorkspaceBarSeparator *> separators;
public:
dtkWidgetsWorkspaceBarButton *button;
public:
bool inside = false;
public:
QHBoxLayout *layout;
public slots:
void onItemClicked(int);
signals:
void indexDeleted(int);
public:
void createWorkspace(const QColor &, const QString &);
};
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);
this->layout->insertWidget(this->layout->count()-1, item);
this->items << item;
this->separators << separator;
connect(item, &dtkWidgetsWorkspaceBarItem::clicked, [=] () {
int index = this->items.indexOf(item);
this->onItemClicked(index);
});
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);
this->layout->removeWidget(item);
delete item;
delete separator;
emit indexDeleted(index);
});
this->onItemClicked(this->items.count()-1);
}
void dtkWidgetsWorkspaceBarPrivate::onItemClicked(int index)
{
q->emit indexChanged(index);
//TODO highlight index
}
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsWorkspaceBar
// ///////////////////////////////////////////////////////////////////
dtkWidgetsWorkspaceBar::dtkWidgetsWorkspaceBar(QWidget *parent): QFrame(parent), d(new dtkWidgetsWorkspaceBarPrivate)
{
d->button = new dtkWidgetsWorkspaceBarButton(this);
d->layout = new QHBoxLayout(this);
d->layout->addWidget(d->button);
// 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);
}
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);
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::onCreateWorkspace(const QString& type)
{
}
dtkWidgetsWorkspaceBar::~dtkWidgetsWorkspaceBar(void)
{
delete d;
}
void dtkWidgetsWorkspaceBar::enterEvent(QEvent *)
{
d->inside = true;
this->update();
}
void dtkWidgetsWorkspaceBar::leaveEvent(QEvent *)
{
d->inside = false;
this->update();
}
QSize dtkWidgetsWorkspaceBar::sizeHint(void) const
{
return QSize(200, 24);
}
void dtkWidgetsWorkspaceBar::setCurrentIndex(int i)
{
d->onItemClicked(i);
}
#include "dtkWidgetsWorkspaceBar.moc"
#pragma once
#include <dtkWidgetsExport.h>
#include <QtWidgets>
class dtkWidgetsWorkspace;
class DTKWIDGETS_EXPORT dtkWidgetsWorkspaceBar: public QFrame
{
Q_OBJECT
public:
dtkWidgetsWorkspaceBar(QWidget *parent = nullptr);
virtual ~dtkWidgetsWorkspaceBar();
signals:
void indexChanged(int);
void indexDeleted(int);
public slots:
void addWorkspace(const QString& workspace_name, int icon, const QString& type);
public slots:
void onCreateWorkspace(const QString& type);
protected:
void enterEvent(QEvent *);
void leaveEvent(QEvent *);
public:
void setCurrentIndex(int);
public:
QSize sizeHint(void) const;
private:
class dtkWidgetsWorkspaceBarPrivate *d;
};
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