Commit 8a36011b authored by WINTZ Julien's avatar WINTZ Julien

Adding new overlay pane item type: slides.

Full width and fully featured multi-modal overlay pane item.

Comes with an example.
parent 0c5eaca8
......@@ -14,6 +14,7 @@
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/examples)
add_subdirectory(dtkWidgetsOverlayPaneItems)
add_subdirectory(dtkWidgetsStylesheetParser)
######################################################################
......
## Version: $Id$
##
######################################################################
##
### Commentary:
##
######################################################################
##
### Change Log:
##
######################################################################
##
### Code:
project(dtkWidgetsOverlayPaneItems)
## #################################################################
## 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}
${${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} dtkWidgets)
######################################################################
### CMakeLists.txt ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include <QtCore>
#include <QtWidgets>
#include <dtkWidgets>
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
QString dtkReadFile(const QString& path)
{
QFile file(path);
if(!file.open(QIODevice::ReadOnly))
return QString();
QString contents = file.readAll();
file.close();
return contents;
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dummy : public QFrame
{
Q_OBJECT
public:
dummy(void);
~dummy(void) {}
protected:
void resizeEvent(QResizeEvent *event);
private:
dtkWidgetsOverlayPane *pane;
dtkWidgetsOverlayPaneItem *item_1;
dtkWidgetsOverlayPaneItem *item_2;
dtkWidgetsOverlayPaneSlider *slide_1;
dtkWidgetsHUD *hud;
};
dummy::dummy(void) : QFrame()
{
QFrame *frame_1 = new QFrame(this);
QFrame *frame_2 = new QFrame(this);
QFrame *frame_3 = new QFrame(this);
QFrame *frame_4 = new QFrame(this);
QFrame *frame_5 = new QFrame(this);
frame_1->setStyleSheet("background: #ff0000;"); frame_1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
frame_2->setStyleSheet("background: #ffff00;"); frame_2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
frame_3->setStyleSheet("background: #ffffff;"); frame_3->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
frame_4->setStyleSheet("background: #00ff00;"); frame_4->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
frame_5->setStyleSheet("background: #00ffff;"); frame_5->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
this->item_1 = new dtkWidgetsOverlayPaneItem(this);
this->item_1->setTitle("Item 1");
this->item_1->addWidget(frame_1);
this->item_2 = new dtkWidgetsOverlayPaneItem(this);
this->item_2->setTitle("Item 2");
this->item_2->addWidget(frame_2);
this->slide_1 = new dtkWidgetsOverlayPaneSlider(this);
this->slide_1->setTitle("Slide 1");
this->slide_1->addSlide(fa::dotcircleo, frame_3);
this->slide_1->addSlide(fa::dotcircleo, frame_4);
this->slide_1->addSlide(fa::dotcircleo, frame_5);
this->pane = new dtkWidgetsOverlayPane(this);
this->pane->addWidget(this->item_1);
this->pane->addWidget(this->item_2);
this->pane->addWidget(this->slide_1);
this->hud = new dtkWidgetsHUD(this);
connect(this->hud->addItem(fa::paw), SIGNAL(clicked()), this->pane, SLOT(toggle()));
this->pane->toggle();
}
void dummy::resizeEvent(QResizeEvent *event)
{
this->hud->resize(event->size());
this->pane->setFixedHeight(event->size().height());
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
QApplication application(argc, argv);
dummy *window = new dummy;
window->resize(1024, 600);
window->show();
window->raise();
window->setStyleSheet(dtkReadFile(":main.qss"));
return application.exec();
}
// ///////////////////////////////////////////////////////////////////
#include "main.moc"
//
// main.cpp ends here
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
<file>main.qss</file>
</qresource>
</RCC>
/*
;; Version: $Id$
;;
*/
/* Commentary:
;;
*/
/* Change Log:
;;
*/
/* Code: */
QScrollArea {
background: transparent;
}
QScrollArea > QWidget > QWidget {
background: transparent;
}
QScrollArea > QWidget > QScrollBar {
background: palette(base);
}
QScrollBar:horizontal {
background: transparent;
height: 6px;
margin: 0px 0px 0px 0px;
}
QScrollBar::handle:horizontal {
background: #cccccc;
border: 1px solid #cccccc;
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: #cccccc;
border: 1px solid #cccccc;
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;
}
QToolButton {
border: none;
}
/* *****************************************************************
;;
;; ******************************************************************/
dtkWidgetsOverlayPaneItemHeader
{
background: "#88181818";
}
/* *****************************************************************
;;
;; ******************************************************************/
dummy
{
background: "#aaaaff";
}
/* main.qss ends here */
......@@ -44,6 +44,8 @@ set(${PROJECT_NAME}_HEADERS
dtkWidgetsOverlayPane.h
dtkWidgetsOverlayPaneItem
dtkWidgetsOverlayPaneItem.h
dtkWidgetsOverlayPaneSlider
dtkWidgetsOverlayPaneSlider.h
dtkWidgetsOverlayRope
dtkWidgetsOverlayRope.h
dtkWidgetsSettings
......@@ -66,6 +68,7 @@ set(${PROJECT_NAME}_SOURCES
dtkWidgetsManager.cpp
dtkWidgetsOverlayPane.cpp
dtkWidgetsOverlayPaneItem.cpp
dtkWidgetsOverlayPaneSlider.cpp
dtkWidgetsOverlayRope.cpp
dtkWidgetsSettings.cpp
dtkWidgetsStylesheetParser.cpp
......
......@@ -10,6 +10,7 @@
#include "dtkWidgetsManager.h"
#include "dtkWidgetsOverlayPane.h"
#include "dtkWidgetsOverlayPaneItem.h"
#include "dtkWidgetsOverlayPaneSlider.h"
#include "dtkWidgetsOverlayRope.h"
#include "dtkWidgetsSettings.h"
#include "dtkWidgetsStylesheetParser.h"
......
......@@ -12,9 +12,8 @@
// Code:
#include "dtkWidgetsHUDItem.h"
#include <dtkFonts>
#include <dtkWidgets>
class dtkWidgetsHUDItemPrivate
{
......@@ -28,7 +27,7 @@ dtkWidgetsHUDItem::dtkWidgetsHUDItem(fa::icon icon, QWidget *parent) : QFrame(pa
dtkFontAwesome::instance()->initFontAwesome();
dtkFontAwesome::instance()->setDefaultOption("scale-factor", 1.0);
dtkFontAwesome::instance()->setDefaultOption("color", QColor(200, 200, 200));
dtkFontAwesome::instance()->setDefaultOption("color", dtkWidgetsLayoutItemProxy::color);
d->label = new QLabel(this);
d->label->setPixmap(dtkFontAwesome::instance()->icon(icon).pixmap(16, 16));
......
......@@ -82,7 +82,7 @@ public:
bool dirty = true;
};
QColor dtkWidgetsLayoutItemProxy::color = QColor("#171819");
QColor dtkWidgetsLayoutItemProxy::color = QColor("#eeeeee");
// /////////////////////////////////////////////////////////////////
// dtkWidgetsLayoutItemPrivate
......
......@@ -131,6 +131,9 @@ public slots:
void addLayout(QLayout *);
void addWidget(QWidget *);
public slots:
void clear(void);
private:
QGroupBox *box;
};
......@@ -167,6 +170,11 @@ void dtkWidgetsOverlayPaneItemFooter::addWidget(QWidget *widget)
dynamic_cast<QBoxLayout *>(this->box->layout())->addWidget(widget);
}
void dtkWidgetsOverlayPaneItemFooter::clear(void)
{
this->layout()->removeWidget(this->box);
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
......@@ -219,6 +227,13 @@ void dtkWidgetsOverlayPaneItem::addWidget(QWidget *widget)
d->footer->addWidget(widget);
}
void dtkWidgetsOverlayPaneItem::setSlider(QWidget *slider)
{
d->footer->clear();
d->footer->layout()->setContentsMargins(0, 0, 0, 0);
d->footer->layout()->addWidget(slider);
}
// ///////////////////////////////////////////////////////////////////
#include "dtkWidgetsOverlayPaneItem.moc"
......
......@@ -36,6 +36,9 @@ public slots:
void addLayout(QLayout *);
void addWidget(QWidget *);
protected:
void setSlider(QWidget *);
private:
class dtkWidgetsOverlayPaneItemPrivate *d;
};
......
#include "dtkWidgetsOverlayPaneSlider.h"
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsOverlayPaneSlider"
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsOverlayPaneSliderBar : public QFrame
{
Q_OBJECT
public:
dtkWidgetsOverlayPaneSliderBar(QWidget *parent = nullptr);
~dtkWidgetsOverlayPaneSliderBar(void);
signals:
void clicked(int);
public:
void addItem(fa::icon);
public:
QVBoxLayout *layout;
public:
QList<QToolButton *> buttons;
};
dtkWidgetsOverlayPaneSliderBar::dtkWidgetsOverlayPaneSliderBar(QWidget *parent) : QFrame(parent)
{
this->layout = new QVBoxLayout(this);
this->layout->setAlignment(Qt::AlignTop);
this->layout->setContentsMargins(0, 0, 0, 0);
this->layout->setSpacing(0);
this->setFixedWidth(50);
this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
}
dtkWidgetsOverlayPaneSliderBar::~dtkWidgetsOverlayPaneSliderBar(void)
{
}
void dtkWidgetsOverlayPaneSliderBar::addItem(fa::icon icon)
{
dtkFontAwesome::instance()->setProperty("color", dtkWidgetsLayoutItemProxy::color);
QToolButton *button = new QToolButton(this);
button->setToolButtonStyle(Qt::ToolButtonIconOnly);
button->setIcon(dtkFontAwesome::instance()->icon(icon).pixmap(QSize(50, 50)));
button->setFixedWidth(50);
button->setFixedHeight(50);
this->buttons << button;
this->layout->addWidget(button);
connect(button, &QToolButton::clicked, [=] (void) {
emit clicked(this->buttons.indexOf(button));
});
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsOverlayPaneSliderViewPort : public QFrame
{
Q_OBJECT
public:
dtkWidgetsOverlayPaneSliderViewPort(QWidget *parent = nullptr);
~dtkWidgetsOverlayPaneSliderViewPort(void);
public slots:
void addWidget(QWidget *);
public:
QHBoxLayout *layout;
public:
int count = 0;
};
dtkWidgetsOverlayPaneSliderViewPort::dtkWidgetsOverlayPaneSliderViewPort(QWidget *parent) : QFrame(parent)
{
this->layout = new QHBoxLayout(this);
this->layout->setContentsMargins(0, 0, 0, 0);
this->layout->setSpacing(0);
}
dtkWidgetsOverlayPaneSliderViewPort::~dtkWidgetsOverlayPaneSliderViewPort(void)
{
}
void dtkWidgetsOverlayPaneSliderViewPort::addWidget(QWidget *widget)
{
widget->setFixedWidth(250);
this->layout->addWidget(widget);
this->count++;
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsOverlayPaneSliderArea : public QScrollArea
{
Q_OBJECT
public:
dtkWidgetsOverlayPaneSliderArea(QWidget *parent = nullptr);
~dtkWidgetsOverlayPaneSliderArea(void);
public:
void slide(int dx);
};
dtkWidgetsOverlayPaneSliderArea::dtkWidgetsOverlayPaneSliderArea(QWidget *parent) : QScrollArea(parent)
{
this->setFrameShape(QFrame::NoFrame);
}
dtkWidgetsOverlayPaneSliderArea::~dtkWidgetsOverlayPaneSliderArea(void)
{
}
void dtkWidgetsOverlayPaneSliderArea::slide(int dx)
{
this->horizontalScrollBar()->setValue(dx);
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsOverlayPaneSliderPrivate : public QFrame
{
Q_OBJECT
public:
dtkWidgetsOverlayPaneSliderPrivate(QWidget *parent = nullptr);
~dtkWidgetsOverlayPaneSliderPrivate(void);
public:
void addWidget(fa::icon, QWidget *);
public slots:
void slideTo(int);
public:
dtkWidgetsOverlayPaneSliderBar *bar;
dtkWidgetsOverlayPaneSliderArea *area;
dtkWidgetsOverlayPaneSliderViewPort *viewport;
public:
int from = 0;
};
dtkWidgetsOverlayPaneSliderPrivate::dtkWidgetsOverlayPaneSliderPrivate(QWidget *parent) : QFrame(parent)
{
this->viewport = new dtkWidgetsOverlayPaneSliderViewPort(this);
this->bar = new dtkWidgetsOverlayPaneSliderBar(this);
this->area = new dtkWidgetsOverlayPaneSliderArea(this);
this->area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->area->setWidgetResizable(true);
this->area->setWidget(this->viewport);
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(this->bar);
layout->addWidget(this->area);
connect(this->bar, SIGNAL(clicked(int)), this, SLOT(slideTo(int)));
}
dtkWidgetsOverlayPaneSliderPrivate::~dtkWidgetsOverlayPaneSliderPrivate(void)
{
}
void dtkWidgetsOverlayPaneSliderPrivate::addWidget(fa::icon icon, QWidget *widget)
{
this->bar->addItem(icon);
this->viewport->addWidget(widget);
this->area->setWidget(this->viewport);
}
void dtkWidgetsOverlayPaneSliderPrivate::slideTo(int to)
{
if(this->viewport->count <= 1)
return;
double xf = this->from; this->from = to;
double xt = to;
double ss = this->area->horizontalScrollBar()->value();
double sm = this->area->horizontalScrollBar()->maximum();
double sc = this->viewport->count - 1;
// --
QVariantAnimation *animation = new QVariantAnimation;
animation->setEasingCurve(QEasingCurve::OutBounce);
animation->setStartValue(xf);
animation->setEndValue(xt);
animation->setDuration(500);
connect(animation, &QVariantAnimation::valueChanged, [=] (const QVariant& value) {
this->area->slide(ss + (value.toDouble() - xf) * sm / sc);
});
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
dtkWidgetsOverlayPaneSlider::dtkWidgetsOverlayPaneSlider(QWidget *parent) : dtkWidgetsOverlayPaneItem(parent)
{
d = new dtkWidgetsOverlayPaneSliderPrivate;
this->setSlider(d);
}
dtkWidgetsOverlayPaneSlider::~dtkWidgetsOverlayPaneSlider(void)
{
delete d;
}
void dtkWidgetsOverlayPaneSlider::addSlide(fa::icon icon, QWidget *contents)
{
d->addWidget(icon, contents);
}
// ///////////////////////////////////////////////////////////////////
#include "dtkWidgetsOverlayPaneSlider.moc"
//
// dtkWidgetsOverlayPaneSlider.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkFonts>
#include <dtkWidgets>
#include <dtkWidgetsExport>
#include <QtWidgets>
class DTKWIDGETS_EXPORT dtkWidgetsOverlayPaneSlider : public dtkWidgetsOverlayPaneItem
{
Q_OBJECT
public:
dtkWidgetsOverlayPaneSlider(QWidget *parent = nullptr);
~dtkWidgetsOverlayPaneSlider(void);
public:
void addSlide(fa::icon, QWidget *);
private:
class dtkWidgetsOverlayPaneSliderPrivate *d;
};
//
// dtkWidgetsOverlayPaneSlider.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