Commit f9befbe1 authored by WINTZ Julien's avatar WINTZ Julien

Towards custom items.

parent 4f0b0021
......@@ -80,7 +80,7 @@ void setup(dtkApplication *application)
placeholder += "Sub";
m->addItem(fa::home, QString("%1Level1").arg(placeholder));
dtkWidgetsMenu *menu = m->addMenu(fa::home, QString("%1Level2").arg(placeholder));
dtkWidgetsMenu *menu = m->addMenu(fa::home, QString("%1").arg(placeholder));
m->addItem(fa::home, QString("%1Level3").arg(placeholder));
m->addSeparator();
m->addItem(fa::home, QString("%1Level4").arg(placeholder));
......
......@@ -230,7 +230,7 @@ install(TARGETS ${PROJECT_NAME}
COMPONENT widgets)
## ###################################################################
##
## Language server protocol
## ###################################################################
add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_SOURCE_DIR}/compile_commands.json)
......
......@@ -18,6 +18,7 @@
#include "dtkWidgetsMenuItem.h"
#include <dtkFonts>
#include <dtkThemes>
class dtkWidgetsMainWindowPrivate
{
......@@ -61,7 +62,12 @@ dtkWidgetsMenuBar *dtkWidgetsMainWindow::menubar(void)
d->menu_themes = d->menubar->addMenu(fa::paintbrush, "Themes");
// for
foreach (const QString theme, dtkThemesEngine::instance()->themes()) {
connect(static_cast<dtkWidgetsMenuItem *>(d->menu_themes->addItem(new dtkWidgetsMenuItemTheme(theme))), &dtkWidgetsMenuItem::clicked, [=] (void) -> void {
qDebug() << Q_FUNC_INFO << "Logging ..."<< theme;
dtkThemesEngine::instance()->apply(theme);
});
}
d->menu_about = d->menubar->addMenu(fa::question, "About");
d->menu_about->addMenu(fa::question, "dtk");
......
......@@ -203,8 +203,15 @@ dtkWidgetsMenuItemParameterFacade::dtkWidgetsMenuItemParameterFacade(dtkWidgetsM
dtkWidgetsMenuItemCustomFacade::dtkWidgetsMenuItemCustomFacade(dtkWidgetsMenuItemCustom *source, QWidget *parent) : dtkWidgetsMenuItemFacade(source, parent)
{
qDebug() << Q_FUNC_INFO << "Source" << source;
QVBoxLayout *layout = new QVBoxLayout(this);
qDebug() << Q_FUNC_INFO << "Here we go ...";
layout->addWidget(source->widget());
connect(this, SIGNAL(clicked()), this, SLOT(clicked()));
}
// ///////////////////////////////////////////////////////////////////
......
......@@ -40,8 +40,7 @@ QWidget *build(QObject *source)
} else if (item->isCustom()) {
if(dtkWidgetsMenuItemWorkspace *custom = dynamic_cast<dtkWidgetsMenuItemWorkspace *>(item))
return new dtkWidgetsMenuItemCustomFacade(custom);
return new dtkWidgetsMenuItemCustomFacade(static_cast<dtkWidgetsMenuItemCustom *>(item));
} else if (item->isSeparator()) {
......
......@@ -18,6 +18,8 @@
#include "dtkWidgetsParameterFactory.h"
#include "dtkWidgetsWorkspaceStackBar.h"
#include <dtkThemes>
#include <dtkThemesWidgets>
#include <dtkCore>
// ///////////////////////////////////////////////////////////////////
......@@ -105,7 +107,7 @@ public:
};
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsMenuItem
// dtkWidgetsMenuItemWorkspace
// ///////////////////////////////////////////////////////////////////
dtkWidgetsMenuItemWorkspace::dtkWidgetsMenuItemWorkspace(const QString& title, dtkWidgetsWorkspaceStackBar *bar) : dtkWidgetsMenuItemCustom(title)
......@@ -125,5 +127,41 @@ QWidget *dtkWidgetsMenuItemWorkspace::widget(void)
return d->widget;
}
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsMenuItemThemePrivate
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsMenuItemThemePrivate
{
public:
dtkThemesWidget *widget = nullptr;
};
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsMenuItemTheme
// ///////////////////////////////////////////////////////////////////
dtkWidgetsMenuItemTheme::dtkWidgetsMenuItemTheme(const QString& theme) : dtkWidgetsMenuItemCustom(theme)
{
d = new dtkWidgetsMenuItemThemePrivate;
d->widget = new dtkThemesWidget(theme);
connect(this, &dtkWidgetsMenuItemTheme::clicked, [=] (void) -> void {
qDebug() << "Oh yeah" << theme;
});
}
dtkWidgetsMenuItemTheme::~dtkWidgetsMenuItemTheme(void)
{
delete d;
}
QWidget *dtkWidgetsMenuItemTheme::widget(void)
{
return d->widget;
}
//
// dtkWidgetsMenuItem.cpp ends here
......@@ -46,6 +46,9 @@ public:
dtkWidgetsMenuItem(int, const QString&, QObject * = nullptr);
~dtkWidgetsMenuItem(void);
signals:
void clicked(void);
public:
const QString& title(void) const;
......@@ -95,6 +98,9 @@ public:
public:
virtual QWidget *widget(void) = 0;
signals:
void clicked(void);
protected:
dtkWidgetsMenuItemCustom(const QString& title) : dtkWidgetsMenuItem(0, title, 0) {}
virtual ~dtkWidgetsMenuItemCustom(void) {}
......@@ -119,5 +125,24 @@ private:
class dtkWidgetsMenuItemWorkspacePrivate *d;
};
// /////////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////////
class DTKWIDGETS_EXPORT dtkWidgetsMenuItemTheme : public dtkWidgetsMenuItemCustom
{
Q_OBJECT
public:
dtkWidgetsMenuItemTheme(const QString& theme);
~dtkWidgetsMenuItemTheme(void);
public:
QWidget *widget(void) override;
private:
class dtkWidgetsMenuItemThemePrivate *d;
};
//
// dtkWidgetsMenuItem.h ends here
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