Commit 0962cd65 authored by WINTZ Julien's avatar WINTZ Julien

Source tree continued. Needs proper font layer.

parent 865ce7de
......@@ -12,7 +12,7 @@
##
### Code:
# add_subdirectory(dtkWidgets)
add_subdirectory(dtkWidgets)
## #################################################################
## Target definition
......
## Version: $Id$
##
######################################################################
##
### Commentary:
##
######################################################################
##
### Change Log:
##
######################################################################
##
### Code:
project(dtkWidgets)
## #################################################################
## Sources
## #################################################################
set(${PROJECT_NAME}_HEADERS
dtkWidgetsColorButton
dtkWidgetsColorButton.h
dtkWidgetsController
dtkWidgetsController.h
dtkWidgetsLayout
dtkWidgetsLayout.h
dtkWidgetsLayoutItem
dtkWidgetsLayoutItem.h
dtkWidgetsList
dtkWidgetsList.h
dtkWidgetsListControl
dtkWidgetsListControl.h
dtkWidgetsHUD
dtkWidgetsHUD.h
dtkWidgetsHUDInfo
dtkWidgetsHUDInfo.h
dtkWidgetsHUDItem
dtkWidgetsHUDItem.h
dtkWidgetsOverlayPane
dtkWidgetsOverlayPane.h
dtkWidgetsOverlayPaneItem
dtkWidgetsOverlayPaneItem.h
dtkWidgetsOverlayRope
dtkWidgetsOverlayRope.h
dtkWidgetsSettings
dtkWidgetsSettings.h
dtkWidgetsWidget
dtkWidgetsWidget.h)
set(${PROJECT_NAME}_SOURCES
dtkWidgetsColorButton.cpp
dtkWidgetsController.cpp
dtkWidgetsLayout.cpp
dtkWidgetsLayoutItem.cpp
dtkWidgetsList.cpp
dtkWidgetsListControl.cpp
dtkWidgetsHUD.cpp
dtkWidgetsHUDInfo.cpp
dtkWidgetsHUDItem.cpp
dtkWidgetsOverlayPane.cpp
dtkWidgetsOverlayPaneItem.cpp
dtkWidgetsOverlayRope.cpp
dtkWidgetsSettings.cpp
dtkWidgetsWidget.cpp)
## #################################################################
## Build rules
## #################################################################
add_library(${PROJECT_NAME} SHARED
${${PROJECT_NAME}_SOURCES}
${${PROJECT_NAME}_HEADERS})
target_link_libraries(${PROJECT_NAME} Qt5::Core)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} Qt5::Xml)
# target_link_libraries(${PROJECT_NAME} dtkFonts)
## #################################################################
## Export header file
## #################################################################
generate_export_header(${PROJECT_NAME} EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/${PROJECT_NAME}Export")
generate_export_header(${PROJECT_NAME} EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/${PROJECT_NAME}Export.h")
set(${PROJECT_NAME}_HEADERS
${${PROJECT_NAME}_HEADERS}
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}Export"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}Export.h")
## ###################################################################
## Install rules - files
## ###################################################################
install(FILES ${${PROJECT_NAME}_HEADERS}
DESTINATION include/${PROJECT_NAME}
COMPONENT widgets)
## ###################################################################
## Install rules - targets
## ###################################################################
install(TARGETS ${PROJECT_NAME}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT widgets
EXPORT dtkWidgetsDepends)
######################################################################
### CMakeLists.txt ends here
#include "dtkWidgetsColorButton.h"
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsColorButton.h"
class dtkWidgetsColorButtonPrivate
{
public:
QColor color;
};
dtkWidgetsColorButton::dtkWidgetsColorButton(const QColor& color, QWidget *parent) : QPushButton(parent)
{
d = new dtkWidgetsColorButtonPrivate;
d->color = color;
}
dtkWidgetsColorButton::dtkWidgetsColorButton(QWidget *parent) : QPushButton(parent)
{
d = new dtkWidgetsColorButtonPrivate;
}
dtkWidgetsColorButton::~dtkWidgetsColorButton(void)
{
delete d;
}
const QColor& dtkWidgetsColorButton::color(void)
{
return d->color;
}
void dtkWidgetsColorButton::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setPen(QColor("#c7c7c7"));
painter.setBrush(d->color);
painter.drawRoundedRect(event->rect().adjusted(5, 5-2, -5, -5-2), 2, 2);
}
void dtkWidgetsColorButton::mousePressEvent(QMouseEvent *event)
{
d->color = QColorDialog::getColor(d->color, this);
if (d->color.isValid())
emit colorChosen(d->color);
QPushButton::mousePressEvent(event);
}
//
// dtkWidgetsColorButton.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include <dtkWidgetsExport>
#include <QtWidgets>
class DTKWIDGETS_EXPORT dtkWidgetsColorButton : public QPushButton
{
Q_OBJECT
public:
dtkWidgetsColorButton(const QColor& color, QWidget *parent = Q_NULLPTR);
dtkWidgetsColorButton(QWidget *parent = Q_NULLPTR);
~dtkWidgetsColorButton(void);
signals:
void colorChosen(QColor);
public:
const QColor& color(void);
protected:
void paintEvent(QPaintEvent *);
protected:
void mousePressEvent(QMouseEvent *);
private:
class dtkWidgetsColorButtonPrivate *d;
};
//
// dtkWidgetsColorButton.h ends here
#include "dtkWidgetsController.h"
\ No newline at end of file
// Version: $Id: 0e2e50291261ff5b3901993a758480c0eff9b2c7 $
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsController.h"
#include "dtkWidgetsWidget.h"
class dtkWidgetsControllerPrivate
{
public:
QHash<QString, dtkWidgetsWidget *> views;
};
dtkWidgetsController *dtkWidgetsController::instance(void)
{
if(!s_instance)
s_instance = new dtkWidgetsController;
return s_instance;
}
void dtkWidgetsController::insert(dtkWidgetsWidget *view)
{
QString name = view->objectName();
if (name.isEmpty())
name = QString("View %1").arg(d->views.count()+1);
d->views.insert(name, view);
emit inserted(view, name);
}
dtkWidgetsWidget *dtkWidgetsController::view(const QString& name)
{
return d->views.value(name);
}
QStringList dtkWidgetsController::viewNames(void)
{
QStringList viewNames = d->views.keys();;
viewNames.append("");
viewNames.sort();
return viewNames;
}
void dtkWidgetsController::clear(void)
{
qDeleteAll(d->views);
}
dtkWidgetsController::dtkWidgetsController(void) : QObject()
{
d = new dtkWidgetsControllerPrivate;
}
dtkWidgetsController::~dtkWidgetsController(void)
{
delete d;
}
dtkWidgetsController *dtkWidgetsController::s_instance = NULL;
//
// dtkWidgetsController.cpp ends here
// Version: $Id: 4384c2157c9496657db37ecde9a97dc87d97f95b $
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkWidgetsExport.h>
#include <QtCore>
class dtkWidgetsWidget;
class DTKWIDGETS_EXPORT dtkWidgetsController : public QObject
{
Q_OBJECT
public:
static dtkWidgetsController *instance(void);
public:
void insert(dtkWidgetsWidget *);
public:
dtkWidgetsWidget *view(const QString& name);
public:
QStringList viewNames(void);
public slots:
void clear(void);
signals:
void inserted(dtkWidgetsWidget *, const QString&);
protected:
dtkWidgetsController(void);
~dtkWidgetsController(void);
private:
static dtkWidgetsController *s_instance;
private:
class dtkWidgetsControllerPrivate *d;
};
//
// dtkWidgetsController.h ends here
#include "dtkWidgetsHUD.h"
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsHUD.h"
#include "dtkWidgetsHUDInfo.h"
#include "dtkWidgetsHUDItem.h"
class dtkWidgetsHUDPrivate
{
public:
QList<dtkWidgetsHUDItem *> items;
QList<dtkWidgetsHUDInfo *> infos;
};
dtkWidgetsHUD::dtkWidgetsHUD(QWidget *parent) : QFrame(parent)
{
d = new dtkWidgetsHUDPrivate;
this->setAttribute(Qt::WA_NoSystemBackground);
this->setAttribute(Qt::WA_TranslucentBackground);
}
dtkWidgetsHUD::~dtkWidgetsHUD(void)
{
qDeleteAll(d->items);
delete d;
}
dtkWidgetsHUDInfo *dtkWidgetsHUD::addInfo(const QString& text)
{
dtkWidgetsHUDInfo *info = new dtkWidgetsHUDInfo(text, this);
d->infos << info;
qApp->postEvent(this, new QResizeEvent(this->size(), this->size()*0.9));
QTimer *timer = new QTimer(info);
timer->setSingleShot(true);
timer->setInterval(1500);
connect(timer, &QTimer::timeout, [=] () {
d->infos.removeOne(info);
delete info;
});
timer->start();
return info;
}
dtkWidgetsHUDItem *dtkWidgetsHUD::addItem(fa::icon icon)
{
dtkWidgetsHUDItem *item = new dtkWidgetsHUDItem(icon, this);
d->items << item;
return item;
}
void dtkWidgetsHUD::mousePressEvent(QMouseEvent *event)
{
event->ignore();
}
void dtkWidgetsHUD::resizeEvent(QResizeEvent *event)
{
QPoint items_origin = QPoint(event->size().width() - 50, 25);
QPoint infos_origin = QPoint(event->size().width() / 2, 25);
for(int i = 0; i < d->items.count(); i++)
d->items[i]->move(items_origin.x(), items_origin.y() + i*50);
for(int i = 0; i < d->infos.count(); i++)
d->infos[i]->move(infos_origin.x() - 100, infos_origin.y() + i*100);
QFrame::resizeEvent(event);
}
//
// dtkWidgetsHUD.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkFonts>
#include <dtkWidgetsExport>
#include <QtWidgets>
class dtkWidgetsHUDInfo;
class dtkWidgetsHUDItem;
class DTKWIDGETS_EXPORT dtkWidgetsHUD : public QFrame
{
public:
dtkWidgetsHUD(QWidget *parent = Q_NULLPTR);
~dtkWidgetsHUD(void);
public:
dtkWidgetsHUDInfo *addInfo(const QString& text);
dtkWidgetsHUDItem *addItem(fa::icon icon);
public:
void mousePressEvent(QMouseEvent *event);
void resizeEvent(QResizeEvent *event);
private:
class dtkWidgetsHUDPrivate *d;
};
//
// dtkWidgetsHUD.h ends here
#include "dtkWidgetsHUDInfo.h"
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsHUDInfo.h"
class dtkWidgetsHUDInfoPrivate
{
public:
QString text;
};
dtkWidgetsHUDInfo::dtkWidgetsHUDInfo(const QString& text, QWidget *parent) : QFrame(parent)
{
d = new dtkWidgetsHUDInfoPrivate;
d->text = text;
this->setVisible(true);
}
dtkWidgetsHUDInfo::~dtkWidgetsHUDInfo(void)
{
delete d;
}
QSize dtkWidgetsHUDInfo::sizeHint(void) const
{
return QSize(200, 50);
}
void dtkWidgetsHUDInfo::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(QColor("#cc2d2e2e"));
painter.setBrush(QColor("#cc2d2e2e"));
painter.drawRoundedRect(event->rect(), 25 + 2, 25 + 2);
painter.setPen(QColor("#bebfbf"));
painter.drawText(event->rect(), d->text, QTextOption(Qt::AlignCenter));
QFrame::paintEvent(event);
}
//
// dtkWidgetsHUDInfo.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkWidgetsExport.h>
#include <QtWidgets>
class DTKWIDGETS_EXPORT dtkWidgetsHUDInfo : public QFrame
{
Q_OBJECT
public:
dtkWidgetsHUDInfo(const QString& text, QWidget *parent = Q_NULLPTR);
~dtkWidgetsHUDInfo(void);
public:
QSize sizeHint(void) const;
protected:
void paintEvent(QPaintEvent *);
private:
class dtkWidgetsHUDInfoPrivate *d;
};
//
// dtkWidgetsHUDInfo.h ends here
#include "dtkWidgetsHUDItem.h"
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsHUDItem.h"
#include <dtkFonts>
class dtkWidgetsHUDItemPrivate
{
public:
QLabel *label;
};
dtkWidgetsHUDItem::dtkWidgetsHUDItem(fa::icon icon, QWidget *parent) : QFrame(parent)
{
d = new dtkWidgetsHUDItemPrivate;
dtkFontAwesome::instance()->initFontAwesome();
dtkFontAwesome::instance()->setDefaultOption("scale-factor", 1.0);
dtkFontAwesome::instance()->setDefaultOption("color", QColor(200, 200, 200));
d->label = new QLabel(this);
d->label->setPixmap(dtkFontAwesome::instance()->icon(icon).pixmap(16, 16));
QHBoxLayout *layout = new QHBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
layout->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
layout->addWidget(d->label);
this->setLayout(layout);
}
dtkWidgetsHUDItem::~dtkWidgetsHUDItem(void)
{
delete d;
}
QSize dtkWidgetsHUDItem::sizeHint(void) const
{
return QSize(30, 30);
}
void dtkWidgetsHUDItem::mousePressEvent(QMouseEvent *event)
{
emit clicked();
}
void dtkWidgetsHUDItem::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setPen(QColor("#242525"));
painter.setBrush(QColor("#242525"));
painter.drawRoundedRect(event->rect(), event->rect().size().width()/2, event->rect().size().height()/2);
QFrame::paintEvent(event);
}
//
// dtkWidgetsHUDItem.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkFonts>
#include <dtkWidgetsExport>
#include <QtWidgets>
class DTKWIDGETS_EXPORT dtkWidgetsHUDItem : public QFrame
{
Q_OBJECT
public:
dtkWidgetsHUDItem(fa::icon icon, QWidget *parent = Q_NULLPTR);
~dtkWidgetsHUDItem(void);
signals:
void clicked(void);
public:
QSize sizeHint(void) const;
protected:
void mousePressEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *event);
private:
class dtkWidgetsHUDItemPrivate *d;
};