Commit e45e8ade authored by WINTZ Julien's avatar WINTZ Julien

Towards new UX for scientific applications.

Scroller. Starts as a standalone example. Will be splitted into classes
and integrated into dtkWidgets whenever useful and relevant.

WIP.
parent b0852afa
......@@ -16,6 +16,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/examples)
add_subdirectory(dtkWidgetsOverlayPaneItems)
add_subdirectory(dtkWidgetsStylesheetParser)
add_subdirectory(dtkWidgetsScroller)
######################################################################
### CMakeLists.txt ends here
## Version: $Id$
##
######################################################################
##
### Commentary:
##
######################################################################
##
### Change Log:
##
######################################################################
##
### Code:
project(dtkWidgetsScroller)
## #################################################################
## 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)
######################################################################
### CMakeLists.txt ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include <QtCore>
#include <QtWidgets>
#include <dtkFonts>
#include <dtkWidgets>
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsScrollerHUDItem : public QLabel
{
Q_OBJECT
public:
dtkWidgetsScrollerHUDItem(int id, QWidget *parent = nullptr) : QLabel(parent) {
dtkFontAwesome::instance()->initFontAwesome();
dtkFontAwesome::instance()->setDefaultOption("scale-factor", 1.0);
dtkFontAwesome::instance()->setDefaultOption("color", QColor("#dddddd"));
this->id = id;
this->setPixmap(dtkFontAwesome::instance()->icon(fa::circlethin).pixmap(8, 8));
this->setFixedWidth(8);
this->setFixedHeight(8);
if(!id)
this->toggle(true);
this->setMouseTracking(true);
}
signals:
void clicked(void);
public slots:
void toggle(bool on) {
this->setPixmap(dtkFontAwesome::instance()->icon(on ? fa::circle : fa::circlethin).pixmap(8, 8));
}
protected:
void mousePressEvent(QMouseEvent *) override {
emit clicked();
}
public:
int id = -1;
};
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsScrollerHUD : public QFrame
{
Q_OBJECT
public:
dtkWidgetsScrollerHUD(QWidget *parent = nullptr);
~dtkWidgetsScrollerHUD(void);
signals:
void slide(int);
public:
void increase(void);
void decrease(void);
};
dtkWidgetsScrollerHUD::dtkWidgetsScrollerHUD(QWidget *parent) : QFrame(parent)
{
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setAlignment(Qt::AlignVCenter);
this->setAttribute(Qt::WA_NoSystemBackground);
this->setAttribute(Qt::WA_TranslucentBackground);
}
dtkWidgetsScrollerHUD::~dtkWidgetsScrollerHUD(void)
{
}
void dtkWidgetsScrollerHUD::increase(void)
{
static int count = 0;
dtkWidgetsScrollerHUDItem *item = new dtkWidgetsScrollerHUDItem(count++, this);
connect(item, &dtkWidgetsScrollerHUDItem::clicked, [=] () {
for(int i = 0; i < this->layout()->count(); i++)
if(dtkWidgetsScrollerHUDItem *hud_item = dynamic_cast<dtkWidgetsScrollerHUDItem *>(this->layout()->itemAt(i)->widget()))
hud_item->toggle(hud_item->id == item->id);
emit slide(item->id);
});
this->layout()->addWidget(item);
}
void dtkWidgetsScrollerHUD::decrease(void)
{
// TODO
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dummy : public QFrame
{
Q_OBJECT
public:
dummy(QWidget *parent = nullptr);
protected:
void resizeEvent(QResizeEvent *);
private:
dtkWidgetsScrollerHUD *hud;
};
dummy::dummy(QWidget *parent) : QFrame(parent)
{
this->hud = new dtkWidgetsScrollerHUD(this);
this->hud->increase();
this->hud->increase();
this->hud->increase();
}
void dummy::resizeEvent(QResizeEvent *event)
{
static int size = 8;
static int margin = 4;
this->hud->move(event->size().width() - size - margin, 0);
this->hud->resize(size, event->size().height());
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
QApplication application(argc, argv);
dummy *dummy = new class dummy;
dummy->setAttribute(Qt::WA_DeleteOnClose, true);
dummy->resize(800, 480);
dummy->show();
dummy->raise();
return application.exec();
}
// ///////////////////////////////////////////////////////////////////
#include "main.moc"
//
// main.cpp 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