Commit 3b642169 authored by WINTZ Julien's avatar WINTZ Julien

Factorize examples.

parent 33615390
......@@ -16,7 +16,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/examples)
add_subdirectory(dtkWidgetsLayout)
add_subdirectory(dtkWidgetsMenu)
add_subdirectory(dtkWidgetsMenuParameters)
add_subdirectory(dtkWidgetsOverlayPaneItems)
add_subdirectory(dtkWidgetsParameter)
add_subdirectory(dtkWidgetsScroller)
......
......@@ -15,6 +15,7 @@
#include <QtCore>
#include <QtWidgets>
#include <dtkCore>
#include <dtkFonts>
#include <dtkWidgets>
......@@ -30,6 +31,9 @@ void setup(dtkApplication *);
int main(int argc, char **argv)
{
dtk::core::registerParameters();
dtk::widgets::initialize("");
dtkApplication *application = dtkApplication::create(argc, argv);
application->setApplicationName("dtkWidgetsMenu");
application->setApplicationVersion("2.0.0");
......@@ -95,10 +99,17 @@ void setup(dtkApplication *application)
bg->setPixmap(QPixmap(QString(":/main_%1.jpg").arg((count++ % 5) + 1)));
});
dtkWidgetsParameterMenuBarGenerator menubar_generator_1(":parameters_nature_1.json", ":parameters_definition_1.json");
dtkWidgetsParameterMenuBarGenerator menubar_generator_2(":parameters_nature_2.json", ":parameters_definition_2.json");
application->window()->setCentralWidget(area);
application->window()->menubar()->addMenu(menu_1);
application->window()->menubar()->addMenu(menu_2);
application->window()->menubar()->addMenu(menu_3);
menubar_generator_1.populate(application->window()->menubar());
menubar_generator_2.populate(application->window()->menubar());
application->window()->menubar()->build();
}
......
......@@ -6,5 +6,11 @@
<file>main_3.jpg</file>
<file>main_4.jpg</file>
<file>main_5.jpg</file>
<file>parameters_nature_1.json</file>
<file>parameters_nature_2.json</file>
<file>parameters_definition_1.json</file>
<file>parameters_definition_2.json</file>
</qresource>
</RCC>
## Version: $Id$
##
######################################################################
##
### Commentary:
##
######################################################################
##
### Change Log:
##
######################################################################
##
### Code:
project(dtkWidgetsMenuParameters)
## #################################################################
## Sources
## #################################################################
set(${PROJECT_NAME}_SOURCES main.cpp)
set(${PROJECT_NAME}_SOURCES_QRC main.qrc)
## #################################################################
## Build rules
## #################################################################
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)
target_link_libraries(${PROJECT_NAME} dtkCore)
target_link_libraries(${PROJECT_NAME} dtkWidgets)
## ###################################################################
## Bundle setup
## ###################################################################
if(APPLE)
set(${PROJECT_NAME}_RESOURCE_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/Resources)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E make_directory ${${PROJECT_NAME}_RESOURCE_DIR})
endif(APPLE)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.plist.in ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.plist)
if(APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.plist)
endif(APPLE)
######################################################################
### CMakeLists.txt ends here
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>@PROJECT_NAME@</string>
<key>CFBundleGetInfoString</key>
<string></string>
<key>CFBundleIconFile</key>
<string>@PROJECT_NAME@</string>
<key>CFBundleIdentifier</key>
<string>fr.inria.dtkWidgetsMenu</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLongVersionString</key>
<string>@dtkWidgets_VERSION@</string>
<key>CFBundleName</key>
<string>@PROJECT_NAME@</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>@dtkWidgets_VERSION@</string>
<key>CFBundleVersion</key>
<string>@dtkWidgets_VERSION@</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>Inria</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include <QtCore>
#include <QtWidgets>
#include <dtkCore>
#include <dtkFonts>
#include <dtkWidgets>
// ///////////////////////////////////////////////////////////////////
// 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);
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dummy : public QMainWindow
{
Q_OBJECT
public:
dummy(void);
~dummy(void) {}
protected:
void resizeEvent(QResizeEvent *event);
public:
dtkWidgetsMenuBar *menubar;
};
// /////////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////////
dummy::dummy(void) : QMainWindow(0)
{
// /////////////////////////////////////////////////////////////////////////////
// Initialize widgets parameters factory
// /////////////////////////////////////////////////////////////////////////////
dtk::widgets::initialize("");
// /////////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////////
this->menubar = new dtkWidgetsMenuBar(this);
dtkWidgetsParameterMenuBarGenerator menubar_generator(":parameters_nature.json", ":parameters_definition.json");
menubar_generator.populate(this->menubar);
dtkWidgetsParameterMenuBarGenerator menubar_generator_2(":parameters_nature_2.json", ":parameters_definition_2.json");
menubar_generator_2.populate(this->menubar);
this->menubar->build();
this->setStyleSheet(m_style);
}
void dummy::resizeEvent(QResizeEvent *event)
{
QMainWindow::resizeEvent(event);
this->menubar->setFixedHeight(event->size().height());
}
// ///////////////////////////////////////////////////////////////////
// main
// ///////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
dtk::core::registerParameters();
QApplication application(argc, argv);
application.setAttribute(Qt::AA_EnableHighDpiScaling);
dummy *window = new dummy;
window->setWindowTitle("dtkWidgetsMenuParameters");
window->resize(1024, 600);
window->show();
window->raise();
// /////////////////////////////////////////////////////////////////////////////
return application.exec();
}
// ///////////////////////////////////////////////////////////////////
#include "main.moc"
//
// main.cpp ends here
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource prefix="">
<file>parameters_nature.json</file>
<file>parameters_definition.json</file>
<file>parameters_nature_2.json</file>
<file>parameters_definition_2.json</file>
</qresource>
</RCC>
## Version: $Id$
##
######################################################################
##
### Commentary:
##
######################################################################
##
### Change Log:
##
######################################################################
##
### Code:
project(dtkWidgetsParameterMenuBarGenerator)
## #################################################################
## Sources
## #################################################################
set(${PROJECT_NAME}_SOURCES main.cpp)
set(${PROJECT_NAME}_SOURCES_QRC dtkWidgetsParameterMenuBarGenerator.qrc)
set_property(SOURCE qrc_dtkWidgetsParameterMenuBarGenerator.cpp PROPERTY SKIP_AUTOMOC ON)
## #################################################################
## Build rules
## #################################################################
qt5_add_resources(${PROJECT_NAME}_SOURCES_RCC ${${PROJECT_NAME}_SOURCES_QRC})
add_executable(${PROJECT_NAME}
${${PROJECT_NAME}_SOURCES_RCC}
${${PROJECT_NAME}_SOURCES})
target_link_libraries(${PROJECT_NAME} Qt5::Core)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} dtkWidgets)
######################################################################
### CMakeLists.txt ends here
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource prefix="">
<file>parameters_nature.json</file>
<file>parameters_definition.json</file>
</qresource>
</RCC>
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include <QtWidgets>
#include <dtkWidgets>
#include <dtkWidgets/dtkWidgetsParameterMenuBarGenerator>
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
qRegisterMetaTypeStreamOperators<dtk::d_bool>("dtk::d_bool");
qRegisterMetaTypeStreamOperators<dtk::d_real>("dtk::d_real");
qRegisterMetaTypeStreamOperators<dtk::d_int>("dtk::d_int");
qRegisterMetaTypeStreamOperators<dtk::d_string>("dtk::d_string");
qRegisterMetaType<dtk::d_bool *>();
qRegisterMetaType<dtk::d_real *>();
qRegisterMetaType<dtk::d_int *>();
qRegisterMetaType<dtk::d_string *>();
dtk::widgets::initialize("");
QApplication application(argc, argv);
QMainWindow *window = new QMainWindow;
dtkWidgetsParameterMenuBarGenerator menu_bar_generator(":parameters_nature.json", ":parameters_definition.json");
QVBoxLayout *central_layout = new QVBoxLayout;
for(auto widget : menu_bar_generator.widgets()) {
central_layout->addWidget(widget);
}
QWidget *central_widget = new QWidget;
central_widget->setLayout(central_layout);
window->setCentralWidget(central_widget);
window->show();
window->raise();
return application.exec();
}
//
// main.cpp ends here
......@@ -13,200 +13,10 @@
// Code:
#include <QtWidgets>
#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;"
"}"