Commit 4b0b24eb authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

update example app; add dtkWidgetsStackBar

parent aed6eb54
......@@ -228,7 +228,7 @@ bool dummyEventFilter::eventFilter(QObject *object, QEvent *event)
qDebug() << "Ate key mouse event for" << object;
return true;
} else {
return QObject::eventFilter(object, event);
......@@ -303,11 +303,11 @@ dummy::dummy(void) : QMainWindow(0)
QString placeholder = "SubSub";
dtkWidgetsMenu *m = this->menu_22->addMenu(fa::home, QString("%1Level3").arg(placeholder));
for(int i = 0; i < 10; i++) {
placeholder += "Sub";
m->addItem(fa::home, QString("%1Level1").arg(placeholder));
dtkWidgetsMenu *menu = m->addMenu(fa::home, QString("%1Level2").arg(placeholder));
m->addItem(fa::home, QString("%1Level3").arg(placeholder));
......@@ -316,13 +316,14 @@ dummy::dummy(void) : QMainWindow(0)
m = menu;
}
this->menubar = new dtkWidgetsMenuBar(this);
this->menubar->addMenu(this->menu_1);
this->menubar->addMenu(this->menu_2);
this->menubar->addMenu(this->menu_3);
for(int i = 0; i < 15; i++) {
dtkWidgetsMenu *menu = this->menubar->addMenu(fa::circlethin, QString("Dummy %1").arg(i));
for(int j = 0; j < 5; j++)
......@@ -333,7 +334,7 @@ dummy::dummy(void) : QMainWindow(0)
for(int j = 0; j < 5; j++)
menu->addItem(fa::circleo, QString("DummyItem %1").arg(j + 5));
}
this->menubar->build();
this->setStyleSheet(m_style);
......
......@@ -19,13 +19,17 @@ project(dtkWidgetsWorkspace)
## #################################################################
set(${PROJECT_NAME}_SOURCES main.cpp)
set(${PROJECT_NAME}_SOURCES_QRC main.qrc)
## #################################################################
## Build rules
## #################################################################
add_executable(${PROJECT_NAME}
${${PROJECT_NAME}_SOURCES})
qt5_add_resources(${PROJECT_NAME}_SOURCES_RCC ${${PROJECT_NAME}_SOURCES_QRC})
add_executable(${PROJECT_NAME} MACOSX_BUNDLE
${${PROJECT_NAME}_SOURCES}
${${PROJECT_NAME}_SOURCES_RCC})
target_link_libraries(${PROJECT_NAME} Qt5::Core)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
......
......@@ -16,6 +16,200 @@
#include <dtkWidgets>
#include <dtkFonts>
// ///////////////////////////////////////////////////////////////////
// TODO: Use dtkThemeEngine instead
// ///////////////////////////////////////////////////////////////////
static const QString bg_color = "#88999999";
static const QString fg_color = "#88dddddd";
static const QString bd_color = "#88555555";
static const QString hl_color = "#88999999";
static const QString bl_color = "#88000000";
static const QString altbg_color = "#88111111";
static const QString m_style = QString(""
"QScrollArea"
"{"
"background: transparent;"
"}"
""
"QScrollArea > QWidget > QWidget"
"{"
" background: transparent;"
"}"
""
"QScrollArea > QWidget > QScrollBar"
"{"
" background: palette(base);"
"}"
""
"dtkWidgetsOverlayPaneItemHeader"
"{"
" background: %1;"
" color: %2;"
"}"
""
"dtkWidgetsOverlayPaneItemFooter QLabel"
"{"
" color: %2;"
"}"
"QScrollBar:horizontal {"
" background: transparent;"
" height: 6px;"
" margin: 0px 0px 0px 0px;"
"}"
""
"QScrollBar::handle:horizontal {"
" background: %1;"
" border: 1px solid %3;"
" border-radius: 2px;"
" min-height: 20px;"
"}"
""
"QScrollBar::add-line:horizontal {"
" height: 0px;"
"}"
""
"QScrollBar::sub-line:horizontal {"
" height: 0px;"
"}"
""
"QScrollBar::up-arrow:horizontal, QScrollBar::down-arrow:horizontal {"
" width: 0px;"
" height: 0px;"
" background: none;"
"}"
""
"QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal {"
" background: none;"
"}"
""
"QScrollBar:vertical {"
" background: transparent;"
" width: 6px;"
" margin: 0px 0px 0px 0px;"
"}"
""
"QScrollBar::handle:vertical {"
" background: %1;"
" border: 1px solid %3;"
" border-radius: 2px;"
" min-height: 20px;"
"}"
""
"QScrollBar::add-line:vertical {"
" height: 0px;"
"}"
""
"QScrollBar::sub-line:vertical {"
" height: 0px;"
"}"
""
"QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {"
" width: 0px;"
" height: 0px;"
" background: none;"
"}"
""
"QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {"
" background: none;"
"}"
""
"dtkWidgetsMenuNavigationFacade"
"{"
" padding-left: 5px;"
" padding-right: 5px;"
" background: #11000000;"
" border-bottom: 1px solid #88222222;"
"}"
""
"dtkWidgetsMenuInnerFacade"
"{"
" margin-left: 5px;"
" margin-right: 5px;"
" background: %1;"
" border-radius: 5px;"
"}"
""
"dtkWidgetsMenuInnerFacade[state=\"first\"]"
"{"
" border-bottom-left-radius: 0;"
" border-bottom-right-radius: 0;"
"}"
""
"dtkWidgetsMenuInnerFacade[state=\"inner\"]"
"{"
" border-top-left-radius: 0;"
" border-top-right-radius: 0;"
" border-bottom-left-radius: 0;"
" border-bottom-right-radius: 0;"
"}"
""
"dtkWidgetsMenuInnerFacade[state=\"last\"]"
"{"
" border-top-left-radius: 0;"
" border-top-right-radius: 0;"
"}"
""
"dtkWidgetsMenuItemFacade"
"{"
" background: %1;"
" border-radius: 5px;"
" margin-left: 5px;"
" margin-right: 5px;"
"}"
""
"dtkWidgetsMenuItemFacade[state=\"prout\"]"
"{"
" background: %1;"
"}"
""
"dtkWidgetsMenuItemFacade[state=\"first\"]"
"{"
" border-bottom-left-radius: 0;"
" border-bottom-right-radius: 0;"
"}"
""
"dtkWidgetsMenuItemFacade[state=\"inner\"]"
"{"
" border-top-left-radius: 0;"
" border-top-right-radius: 0;"
" border-bottom-left-radius: 0;"
" border-bottom-right-radius: 0;"
"}"
""
"dtkWidgetsMenuItemFacade[state=\"last\"]"
"{"
" border-top-left-radius: 0;"
" border-top-right-radius: 0;"
"}"
""
"dtkWidgetsMenuBar"
"{"
" background: %6;"
" border-right: 1px solid %5;"
"}"
""
"dtkWidgetsMenuBarButtonCollapse"
"{"
" border-top: 1px solid %5;"
"}"
""
"dtkWidgetsMenuBarButton:hover"
"{"
" background: %4;"
" border-radius: 5px;"
"}"
""
"dtkWidgetsMenuBarButton[state=\"current\"]"
"{"
" background: %4;"
" border-radius: 5px;"
"}"
"").arg(bg_color).arg(fg_color).arg(bd_color).arg(hl_color).arg(bl_color).arg(altbg_color);
// ///////////////////////////////////////////////////////////////////
// dummy workspace
// ///////////////////////////////////////////////////////////////////
......@@ -27,15 +221,29 @@ class dummyWorkspaceA: public dtkWidgetsWorkspace
public:
dummyWorkspaceA(QWidget *parent = nullptr) {
QLabel *label = new QLabel("my dummy workspace");
this->menubar = new dtkWidgetsMenuBar(this);
dtkWidgetsMenu *menu_1 = new dtkWidgetsMenu(fa::circlethin, "MainLevel 1");
dtkWidgetsMenu *menu_2 = new dtkWidgetsMenu(fa::circlethin, "MainLevel 2");
dtkWidgetsMenu *menu_3 = new dtkWidgetsMenu(fa::circlethin, "MainLevel 3");
menubar->addMenu(menu_1);
menubar->addMenu(menu_2);
menubar->addMenu(menu_3);
menubar->build();
QLabel *label = new QLabel("my dummy workspace with menu");
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setContentsMargins(30, 30, 30, 30);
layout->setSpacing(0);
layout->addWidget(label);
};
~dummyWorkspaceA(void) {};
public:
void resizeEvent(QResizeEvent *event);
public:
void enter(void) override {}
void leave(void) override {}
......@@ -43,8 +251,17 @@ public:
public slots:
void apply(void) override {};
private:
dtkWidgetsMenuBar *menubar;
};
void dummyWorkspaceA::resizeEvent(QResizeEvent *event)
{
QWidget::resizeEvent(event);
this->menubar->setFixedHeight(event->size().height());
}
static dtkWidgetsWorkspace *dummyWorkspaceCreatorA(void) {
return new dummyWorkspaceA;
}
......@@ -60,6 +277,7 @@ public:
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(label);
this->setStyleSheet(m_style);
};
~dummyWorkspaceB(void) {};
......@@ -77,6 +295,35 @@ static dtkWidgetsWorkspace *dummyWorkspaceCreatorB(void) {
return new dummyWorkspaceB;
}
class dummyWorkspaceC: public dtkWidgetsWorkspace
{
Q_OBJECT
public:
dummyWorkspaceC(QWidget *parent = nullptr) {
QLabel *label = new QLabel;
label->setPixmap(QPixmap(":/logo.jpg"));
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(label);
};
~dummyWorkspaceC(void) {};
public:
void enter(void) override {}
void leave(void) override {}
public slots:
void apply(void) override {};
};
static dtkWidgetsWorkspace *dummyWorkspaceCreatorC(void) {
return new dummyWorkspaceC;
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
......@@ -91,6 +338,16 @@ public:
public:
QSize sizeHint(void) const { return QSize(640, 480); }
private:
dtkWidgetsMenuBar *menubar;
dtkWidgetsMenu *menu_1;
dtkWidgetsMenu *menu_2;
dtkWidgetsMenu *menu_3;
public:
void resizeEvent(QResizeEvent *event);
public:
QStackedWidget *stack;
};
......@@ -99,15 +356,39 @@ dummyWindow::dummyWindow(QWidget *parent) : QFrame(parent)
{
this->stack = new QStackedWidget(this);
this->stack->addWidget(dtk::widgets::workspace::pluginFactory().create("dummyWorkspaceA"));
// this->menubar = new dtkWidgetsMenuBar(this);
// this->menu_1 = new dtkWidgetsMenu(fa::circlethin, "MainLevel 1");
// this->menu_2 = new dtkWidgetsMenu(fa::circlethin, "MainLevel 2");
// this->menu_3 = new dtkWidgetsMenu(fa::circlethin, "MainLevel 3");
// this->menubar->addMenu(this->menu_1);
// this->menubar->addMenu(this->menu_2);
// this->menubar->addMenu(this->menu_3);
// this->menubar->build();
this->stack->addWidget(dtk::widgets::workspace::pluginFactory().create("dummyWorkspaceB"));
this->stack->addWidget(dtk::widgets::workspace::pluginFactory().create("dummyWorkspaceC"));
QVBoxLayout *l = new QVBoxLayout(this);
dtkWidgetsStackBar *stack_bar = new dtkWidgetsStackBar(this);
stack_bar->setStack(this->stack);
QHBoxLayout *l = new QHBoxLayout(this);
l->setContentsMargins(0, 0, 0, 0);
l->setSpacing(0);
l->addWidget(stack_bar);
l->addWidget(this->stack);
this->setStyleSheet(m_style);
}
void dummyWindow::resizeEvent(QResizeEvent *event)
{
QFrame::resizeEvent(event);
// this->menubar->setFixedHeight(event->size().height());
}
class dummyWindowBar : public QFrame
{
Q_OBJECT
......@@ -132,12 +413,15 @@ dummyWindowBar::dummyWindowBar(QWidget *parent) : QFrame(parent)
bar->addWorkspaceInMenu("My Dummy Workspace A", fa::sitemap, "dummyWorkspaceA" );
bar->addWorkspaceInMenu("My Dummy Workspace B", fa::image, "dummyWorkspaceB" );
bar->addWorkspaceInMenu("dtk", fa::image, "dummyWorkspaceC" );
QVBoxLayout *l = new QVBoxLayout(this);
l->setContentsMargins(0, 0, 0, 0);
l->setSpacing(0);
l->addWidget(stack);
l->addWidget(bar);
this->setStyleSheet(m_style);
}
......@@ -153,6 +437,7 @@ int main(int argc, char **argv)
dtk::widgets::workspace::pluginFactory().record("dummyWorkspaceA", dummyWorkspaceCreatorA);
dtk::widgets::workspace::pluginFactory().record("dummyWorkspaceB", dummyWorkspaceCreatorB);
dtk::widgets::workspace::pluginFactory().record("dummyWorkspaceC", dummyWorkspaceCreatorC);
dummyWindow *window = new dummyWindow;
window->show();
......
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
<file>logo.jpg</file>
</qresource>
</RCC>
......@@ -81,6 +81,8 @@ set(${PROJECT_NAME}_HEADERS
dtkWidgetsParameterStringListComboBox.h
dtkWidgetsSettings
dtkWidgetsSettings.h
dtkWidgetsStackBar
dtkWidgetsStackBar.h
dtkWidgetsWidget
dtkWidgetsWidget.h
dtkWidgetsWorkspace
......@@ -120,6 +122,7 @@ set(${PROJECT_NAME}_SOURCES
dtkWidgetsParameterMenuBarGenerator.cpp
dtkWidgetsParameterStringListComboBox.cpp
dtkWidgetsSettings.cpp
dtkWidgetsStackBar.cpp
dtkWidgetsWidget.cpp
dtkWidgetsWorkspace.cpp
dtkWidgetsWorkspaceBar.cpp)
......
......@@ -27,6 +27,7 @@
#include "dtkWidgetsParameterMenuBarGenerator.h"
#include "dtkWidgetsParameterStringListComboBox.h"
#include "dtkWidgetsSettings.h"
#include "dtkWidgetsStackBar.h"
#include "dtkWidgetsWidget.h"
#include "dtkWidgetsWorkspace.h"
#include "dtkWidgetsWorkspaceBar.h"
#include "dtkWidgetsStackBar.h"
#include "dtkWidgetsStackBar.h"
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsStackBarItem : public QFrame
{
Q_OBJECT
Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
public:
dtkWidgetsStackBarItem(int index, QWidget *parent = nullptr);
~dtkWidgetsStackBarItem(void);
signals:
void clicked(int);
signals:
void activeChanged(void);
public:
bool active(void) {
return this->on;
}
void setActive(bool active) {
this->on = active;
emit activeChanged();
}
public:
void setSource(QWidget *);
protected:
void mousePressEvent(QMouseEvent *);
private:
QWidget *source = nullptr;
private:
QLabel *name;
QLabel *overview;
private:
int index = -1;
private:
bool on = false;
};
dtkWidgetsStackBarItem::dtkWidgetsStackBarItem(int index, QWidget *parent) : QFrame(parent)
{
this->index = index;
this->name = new QLabel(this);
this->name->setAlignment(Qt::AlignCenter);
this->overview = new QLabel(this);
this->overview->setObjectName("overview");
this->overview->setAlignment(Qt::AlignCenter);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addStretch();
layout->addWidget(this->name);
layout->addWidget(this->overview);
layout->addStretch();
}
dtkWidgetsStackBarItem::~dtkWidgetsStackBarItem(void)
{
}
void dtkWidgetsStackBarItem::setSource(QWidget *source)
{
this->source = source;
this->name->setText(this->source->objectName());
QTimer *timer = new QTimer(this);
timer->setInterval(250);
timer->setSingleShot(false);
connect(timer, &QTimer::timeout, [=] (void) {
QPixmap pixmap(this->source->size());
this->source->render(&pixmap);
this->overview->setPixmap(pixmap.scaledToWidth(280));
});
timer->start();
}
void dtkWidgetsStackBarItem::mousePressEvent(QMouseEvent *event)
{
Q_UNUSED(event);
emit clicked(this->index);
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsStackBarPrivate
{
public:
QStackedWidget *stack = nullptr;
public:
QList<dtkWidgetsStackBarItem *> items;
public:
QVBoxLayout *layout;
};
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
dtkWidgetsStackBar::dtkWidgetsStackBar(QWidget *parent) : QFrame(parent)
{
d = new dtkWidgetsStackBarPrivate;
d->layout = new QVBoxLayout(this);
d->layout->setContentsMargins(0, 0, 1, 0);
d->layout->setSpacing(0);
this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
}
dtkWidgetsStackBar::~dtkWidgetsStackBar(void)
{
delete d;
}
QSize dtkWidgetsStackBar::sizeHint(void) const
{
return QSize(300, 100);
}
void dtkWidgetsStackBar::setStack(QStackedWidget *stack)
{
d->stack = stack;
if(!d->stack->count())
qDebug() << "Please setup stack before computing the bar.";
for (int i = 0; i < d->stack->count(); i++) {
dtkWidgetsStackBarItem *item = new dtkWidgetsStackBarItem(i, this);
item->setSource(d->stack->widget(i));
connect(item, SIGNAL(clicked(int)), d->stack, SLOT(setCurrentIndex(int)));
connect(item, &dtkWidgetsStackBarItem::clicked, [=] (int) {
foreach(dtkWidgetsStackBarItem *it, d->items) {
this->style()->unpolish(it);
it->setActive(it == item);
this->style()->polish(it);
}
});
d->layout->addWidget(item);
d->items << item;
}
d->items.first()->setActive(true);
}
// ///////////////////////////////////////////////////////////////////
#include "dtkWidgetsStackBar.moc"
//
// dtkWidgetsStackBar.cpp ends here
#pragma once
#include <dtkWidgetsExport.h>
#include <QtWidgets>
class DTKWIDGETS_EXPORT dtkWidgetsStackBar : public QFrame
{
Q_OBJECT
public:
dtkWidgetsStackBar(QWidget *parent = nullptr);
~dtkWidgetsStackBar(void);
public:
QSize sizeHint(void) const override;
public:
void setStack(QStackedWidget *);
private:
class dtkWidgetsStackBarPrivate *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