...
 
Commits (26)
# ChangeLog
## version 2.16.0 - 2019-11-29
- first version of dtkWidgetsDataManager
## version 2.15.2 - 2019-11-12
- Fixed workspace bar count.
## version 2.15.1 - 2019-10-18
- Allow menu framework to tweak an existing Qt menu bar.
## version 2.15.0 - 2019-10-18
......
......@@ -23,8 +23,8 @@ project(dtkWidgets)
## ###################################################################
set(${PROJECT_NAME}_VERSION_MAJOR 2)
set(${PROJECT_NAME}_VERSION_MINOR 15)
set(${PROJECT_NAME}_VERSION_PATCH 2)
set(${PROJECT_NAME}_VERSION_MINOR 16)
set(${PROJECT_NAME}_VERSION_PATCH 0)
set(${PROJECT_NAME}_VERSION
${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH})
......
......@@ -12,6 +12,8 @@
##
### Code:
add_subdirectory(dtkWidgetsDataManager)
add_subdirectory(dtkWidgetsFinder)
add_subdirectory(dtkWidgetsLayout)
add_subdirectory(dtkWidgetsMenu)
add_subdirectory(dtkWidgetsOverlayPaneItems)
......
## Version: $Id$
##
######################################################################
##
### Commentary:
##
######################################################################
##
### Change Log:
##
######################################################################
##
### Code:
project(dtkWidgetsDataManager)
## #################################################################
## Sources
## #################################################################
set(CMAKE_AUTORCC ON)
## #################################################################
## Build rules
## #################################################################
add_executable(${PROJECT_NAME} MACOSX_BUNDLE main.cpp main.qrc)
set_target_properties(${PROJECT_NAME} PROPERTIES AUTOMOC TRUE)
target_link_libraries(${PROJECT_NAME} Qt5::Core)
target_link_libraries(${PROJECT_NAME} Qt5::Gui)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} dtkCore)
target_link_libraries(${PROJECT_NAME} dtkFonts)
target_link_libraries(${PROJECT_NAME} dtkThemes)
target_link_libraries(${PROJECT_NAME} dtkWidgets)
## ###################################################################
## Bundle setup
## ###################################################################
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
#include <QLabel>
#include <QMimeData>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QDragLeaveEvent>
<?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.@PROJECT_NAME@</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 <dtkThemes>
#include <dtkWidgets>
// /////////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////////
class DropArea : public QLabel
{
Q_OBJECT
public:
explicit DropArea(QWidget *parent = nullptr) {
setMinimumSize(200, 200);
setFrameStyle(QFrame::Sunken | QFrame::StyledPanel);
setAlignment(Qt::AlignCenter);
setAcceptDrops(true);
setAutoFillBackground(true);
clear();
}
public slots:
void clear(void) {
setText(tr("<drop content>"));
setBackgroundRole(QPalette::Dark);
emit changed();
}
signals:
void changed(const QMimeData *mimeData = nullptr);
protected:
void dragEnterEvent(QDragEnterEvent *event) override {
setText(tr("<drop content>"));
setBackgroundRole(QPalette::Highlight);
event->acceptProposedAction();
emit changed(event->mimeData());
}
void dragMoveEvent(QDragMoveEvent *event) override {
event->acceptProposedAction();
}
void dropEvent(QDropEvent *event) override {
const QMimeData *mimeData = event->mimeData();
setText(mimeData->text());
long idWorld = std::stol(mimeData->text().toStdString().substr(1));
setBackgroundRole(QPalette::Dark);
event->acceptProposedAction();
}
void dragLeaveEvent(QDragLeaveEvent *event) override {
clear();
event->accept();
}
};
// /////////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////////
class dtkFinderExamplePrivate
{
public:
dtkWidgetsFinder *finder;
dtkWidgetsFinderPathBar *path;
dtkWidgetsFinderToolBar *toolbar;
dtkWidgetsFinderSideView *sideView;
};
// /////////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////////
class dtkFinderExample : public QFrame
{
public:
dtkFinderExample(QWidget *parent = nullptr)
{
d = new dtkFinderExamplePrivate;
d->finder = new dtkWidgetsFinder(this);
d->finder->switchToTreeView();
d->finder->setPath(QDir::currentPath());
d->path = new dtkWidgetsFinderPathBar(this);
d->path->setPath(QDir::currentPath());
d->path->setFixedHeight(32);
d->toolbar = new dtkWidgetsFinderToolBar(this);
d->toolbar->setPath(QDir::currentPath());
d->sideView = new dtkWidgetsFinderSideView(this);
QHBoxLayout *toolbar_layout = new QHBoxLayout;
toolbar_layout->setContentsMargins(0, 0, 0, 0);
toolbar_layout->setSpacing(0);
toolbar_layout->addWidget(d->toolbar);
toolbar_layout->addWidget(d->path);
QVBoxLayout *finder_layout = new QVBoxLayout;
finder_layout->setContentsMargins(0, 0, 0, 0);
finder_layout->setSpacing(0);
finder_layout->addLayout(toolbar_layout);
finder_layout->addWidget(d->finder);
QHBoxLayout *finder_with_sider_layout = new QHBoxLayout;
finder_with_sider_layout->setContentsMargins(0, 0, 0, 0);
finder_with_sider_layout->setSpacing(0);
finder_with_sider_layout->addWidget(d->sideView);
finder_with_sider_layout->addLayout(finder_layout);
QWidget *finder = new QWidget(this);
finder->setLayout(finder_with_sider_layout);
QWidget* emitters[] = {d->finder, d->path, d->sideView, d->toolbar};
for (auto emitter: emitters) {
for (auto receiver: emitters) {
if (emitter != receiver) {
connect(emitter, SIGNAL(changed(QString)), receiver, SLOT(setPath(QString)));
}
}
}
connect(d->toolbar, SIGNAL(treeView()), d->finder, SLOT(switchToTreeView()));
connect(d->toolbar, SIGNAL(listView()), d->finder, SLOT(switchToListView()));
QSplitter *splitter = new QSplitter(this);
splitter->addWidget(finder);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(splitter);
}
~dtkFinderExample(void) {
delete d;
}
private:
dtkFinderExamplePrivate *d;
};
// /////////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
dtk::core::registerParameters();
dtk::widgets::initialize("");
dtkThemesEngine::instance()->apply();
dtkApplication *application = dtkApplication::create(argc, argv);
application->setApplicationName("dtkDataManager");
application->setOrganizationName("inria");
application->setOrganizationDomain("fr");
application->initialize();
auto data1 = new dtkWidgetsDataManagerData;
data1->addMetadata(dtkWidgetsDataManagerData::ICON, ":earth");
data1->addMetadata("creation", QDate(2007, 5, 3));
data1->setData(QString("Hello data1"));
dtkWidgetsDataManager *manager = dtkWidgetsDataManager::instance();
manager->addData(data1, Qt::red);
//auto metadataModel = new QStandardItemModel;
//auto metadataView = new QTableView;
//metadataView->setModel(metadataModel);
// QObject::connect(manager, &dtkWidgetsDataManager::itemClickedSignal, [=] (dtkWidgetsDataManagerItem *item)
// {
// long dataId = item->id;
// qDebug() << Q_FUNC_INFO << "item = " << dataId;
// auto data = manager->get(dataId);
// metadataModel->clear();
// int row = 0;
// for (auto it = data->metadata.begin(); it != data->metadata.end(); ++it, ++row) {
// auto key = new QStandardItem(it.key());
// auto value = new QStandardItem(it.value().toString());
// metadataModel->setItem(row, 0, key);
// metadataModel->setItem(row, 1, value);
// }
// });
auto dropArea = new DropArea;
auto vlayout = new QVBoxLayout;
vlayout->addWidget(manager);
//vlayout->addWidget(metadataView);
vlayout->addWidget(dropArea);
static int l_h = 0;
QObject::connect(manager, &dtkWidgetsDataManager::expand, [&](void)
{
if(dropArea->height() < 10)
return;
int m_h = manager->height();
int d_h = dropArea->height();
l_h = d_h;
QVariantAnimation *animation = new QVariantAnimation();
animation->setDuration(500);
animation->setStartValue(d_h);
animation->setEndValue(0);
animation->setEasingCurve(QEasingCurve::OutQuad);
QObject::connect(animation, &QVariantAnimation::valueChanged, [=] (const QVariant& value)
{
dropArea->setFixedHeight(value.toInt());
manager->setFixedHeight(m_h + d_h - value.toInt());
});
animation->start(QAbstractAnimation::DeleteWhenStopped);
});
QObject::connect(manager, &dtkWidgetsDataManager::shrink, [&](void)
{
if(manager->height() < 10)
return;
int m_h = manager->height();
QVariantAnimation *animation = new QVariantAnimation();
animation->setDuration(500);
animation->setStartValue(0);
animation->setEndValue(l_h);
animation->setEasingCurve(QEasingCurve::OutQuad);
QObject::connect(animation, &QVariantAnimation::valueChanged, [=] (const QVariant& value)
{
dropArea->setFixedHeight(value.toInt());
manager->setFixedHeight(m_h - value.toInt());
});
animation->start(QAbstractAnimation::DeleteWhenStopped);
});
auto hlayout = new QHBoxLayout;
hlayout->addWidget(new dtkFinderExample);
hlayout->addLayout(vlayout);
auto frame = new QFrame;
frame->setLayout(hlayout);
frame->show();
frame->raise();
return QApplication::exec();
}
// /////////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////////
#include "main.moc"
//
// main.cpp ends here
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>earth.jpg</file>
<file>mars.jpg</file>
</qresource>
</RCC>
\ No newline at end of file
## Version: $Id$
##
######################################################################
##
### Commentary:
##
######################################################################
##
### Change Log:
##
######################################################################
##
### Code:
project(dtkWidgetsFinder)
## #################################################################
## 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} dtkThemes)
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.@PROJECT_NAME@</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 <QtWidgets>
#include <dtkWidgets>
// /////////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////////
class dtkFinderExample : public QFrame
{
public:
dtkFinderExample(QWidget *parent = nullptr) {
this->finder = new dtkWidgetsFinder(this);
this->finder->switchToTreeView();
this->path = new dtkWidgetsFinderPathBar(this);
this->path->setPath(QDir::currentPath());
this->path->setFixedHeight(32);
this->toolbar = new dtkWidgetsFinderToolBar(this);
this->toolbar->setPath(QDir::currentPath());
this->sideView = new dtkWidgetsFinderSideView(this);
QHBoxLayout *toolbar_layout = new QHBoxLayout;
toolbar_layout->setContentsMargins(0, 0, 0, 0);
toolbar_layout->setSpacing(0);
toolbar_layout->addWidget(this->toolbar);
toolbar_layout->addWidget(this->path);
QVBoxLayout *finder_layout = new QVBoxLayout;
finder_layout->setContentsMargins(0, 0, 0, 0);
finder_layout->setSpacing(0);
finder_layout->addLayout(toolbar_layout);
finder_layout->addWidget(this->finder);
QHBoxLayout *finder_with_sider_layout = new QHBoxLayout;
finder_with_sider_layout->setContentsMargins(0, 0, 0, 0);
finder_with_sider_layout->setSpacing(0);
finder_with_sider_layout->addWidget(this->sideView);
finder_with_sider_layout->addLayout(finder_layout);
QWidget *finder = new QWidget(this);
finder->setLayout(finder_with_sider_layout);
connect(this->finder, SIGNAL(changed(QString)), this->path, SLOT(setPath(QString)));
connect(this->finder, SIGNAL(changed(QString)), this->toolbar, SLOT(setPath(QString)));
connect(this->path, SIGNAL(changed(QString)), this->finder, SLOT(setPath(QString)));
connect(this->path, SIGNAL(changed(QString)), this->toolbar, SLOT(setPath(QString)));
connect(this->toolbar, SIGNAL(changed(QString)), this->finder, SLOT(setPath(QString)));
connect(this->toolbar, SIGNAL(changed(QString)), this->path, SLOT(setPath(QString)));
connect(this->toolbar, SIGNAL(treeView()), this->finder, SLOT(switchToTreeView()));
connect(this->toolbar, SIGNAL(listView()), this->finder, SLOT(switchToListView()));
QSplitter *splitter = new QSplitter(this);
splitter->addWidget(finder);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(splitter);
}
private:
dtkWidgetsFinder *finder;
dtkWidgetsFinderPathBar *path;
dtkWidgetsFinderToolBar *toolbar;
dtkWidgetsFinderSideView *sideView;
};
// /////////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
QApplication application(argc, argv);
dtkFinderExample *finder = new dtkFinderExample;
finder->show();
finder->raise();
return application.exec();
}
//
// main.cpp ends here
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
<file>logo.jpg</file>
</qresource>
</RCC>
......@@ -38,7 +38,6 @@ int main(int argc, char **argv)
dtkApplication *application = dtkApplication::create(argc, argv);
application->setApplicationName("dtkWidgetsMenu");
application->setApplicationVersion("2.0.0");
application->setOrganizationName("inria");
application->setOrganizationDomain("fr");
application->initialize();
......
......@@ -26,6 +26,19 @@ set(${PROJECT_NAME}_HEADERS
dtkWidgetsColorButton.h
dtkWidgetsController
dtkWidgetsController.h
dtkWidgetsDataManager
dtkWidgetsDataManager.h
dtkWidgetsDataManager_p.h
dtkWidgetsDataManagerData
dtkWidgetsDataManagerData.h
dtkWidgetsDataManagerFocus
dtkWidgetsDataManagerFocus.h
dtkWidgetsDataManagerItem
dtkWidgetsDataManagerItem.h
dtkWidgetsDataManagerItemButton
dtkWidgetsDataManagerItemButton.h
dtkWidgetsFinder
dtkWidgetsFinder.h
dtkWidgetsLayout
dtkWidgetsLayout.h
dtkWidgetsLayoutItem
......@@ -116,6 +129,12 @@ set(${PROJECT_NAME}_SOURCES
dtkWidgets.cpp
dtkWidgetsColorButton.cpp
dtkWidgetsController.cpp
dtkWidgetsDataManager.cpp
dtkWidgetsDataManagerData.cpp
dtkWidgetsDataManagerFocus.cpp
dtkWidgetsDataManagerItem.cpp
dtkWidgetsDataManagerItemButton.cpp
dtkWidgetsFinder.cpp
dtkWidgetsLayout.cpp
dtkWidgetsLayoutItem.cpp
dtkWidgetsLayoutReader.cpp
......
......@@ -17,6 +17,13 @@
#include "dtkWidgets.h"
#include "dtkWidgetsColorButton.h"
#include "dtkWidgetsController.h"
#include "dtkWidgetsDataManager.h"
#include "dtkWidgetsDataManager_p.h"
#include "dtkWidgetsDataManagerData.h"
#include "dtkWidgetsDataManagerFocus.h"
#include "dtkWidgetsDataManagerItem.h"
#include "dtkWidgetsDataManagerItemButton.h"
#include "dtkWidgetsFinder.h"
#include "dtkWidgetsLayout.h"
#include "dtkWidgetsLayoutItem.h"
#include "dtkWidgetsLayoutReader.h"
......
#include "dtkWidgetsColorButton.h"
\ No newline at end of file
#include "dtkWidgetsColorButton.h"
#include "dtkWidgetsController.h"
\ No newline at end of file
#include "dtkWidgetsController.h"
#include "dtkWidgetsDataManager.h"
This diff is collapsed.
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkWidgetsExport>
#include <dtkWidgetsDataManagerData.h>
#include <QtCore>
#include <QtWidgets>
class dtkWidgetsDataManagerItem;
class DTKWIDGETS_EXPORT dtkWidgetsDataManager : public QFrame
{
Q_OBJECT
public:
static dtkWidgetsDataManager *instance(void);
signals:
void shrink(void);
void expand(void);
protected:
void itemClicked(dtkWidgetsDataManagerItem *);
signals:
void itemClickedSignal(dtkWidgetsDataManagerItem *);
public:
QSize sizeHint(void) const override;
public slots:
int addData(dtkWidgetsDataManagerDataPtr, const QColor &, const QImage& img = QImage());
public slots:
void present(dtkWidgetsDataManagerItem *);
public slots:
QVector<int> getDataIds(void);
public:
dtkWidgetsDataManagerDataPtr get(int index);
dtkWidgetsDataManagerItem *getItem(int index);
public:
QPixmap thumbnail(int index);
protected:
dtkWidgetsDataManager(QWidget *parent = nullptr);
~dtkWidgetsDataManager(void);
protected:
void enterEvent(QEvent *) override;
void leaveEvent(QEvent *) override;
protected:
void mousePressEvent(QMouseEvent *) override;
protected:
void paintEvent(QPaintEvent *) override;
private:
class dtkWidgetsDataManagerPrivate *d;
private:
static dtkWidgetsDataManager *s_instance;
protected:
void dropEvent(QDropEvent *event) override;
void dragEnterEvent(QDragEnterEvent *event) override;
};
//
// dtkWidgetsDataManager.h ends here
#include "dtkWidgetsDataManagerData.h"
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsDataManagerData.h"
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
QWidget *dtkWidgetsDataManagerDataCreate(const QVariant& v)
{
QLabel *label = new QLabel;
if(v.type() == QVariant::Int)
label->setText(QString::number(v.toInt()));
if(v.type() == QVariant::Double)
label->setText(QString::number(v.toDouble()));
if(v.type() == QVariant::String)
label->setText(v.toString());
if(v.type() == QVariant::Color) {
QPixmap pixmap(16, 16);
QPainter painter(&pixmap);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(Qt::white);
painter.setBrush(v.value<QColor>());
painter.drawRoundedRect(0, 0, 16, 16, 8, 8);
label->setPixmap(pixmap);
}
return label;
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsDataManagerDataPrivate : public QScrollArea
{
public:
dtkWidgetsDataManagerDataPrivate(dtkWidgetsDataManagerData *data);
~dtkWidgetsDataManagerDataPrivate(void);
public:
QWidget *contents;
};
dtkWidgetsDataManagerDataPrivate::dtkWidgetsDataManagerDataPrivate(dtkWidgetsDataManagerData *data) : QScrollArea(0)
{
QFormLayout *layout = new QFormLayout;
for(QString key : data->metadata.keys())
layout->addRow(key, dtkWidgetsDataManagerDataCreate(data->metadata.value(key)));
this->contents = new QWidget(this);
this->contents->setLayout(layout);
this->setWidget(this->contents);
this->setWidgetResizable(true);
}
dtkWidgetsDataManagerDataPrivate::~dtkWidgetsDataManagerDataPrivate(void)
{
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
dtkWidgetsDataManagerData::dtkWidgetsDataManagerData(QObject *parent) : QObject(parent)
{
}
dtkWidgetsDataManagerData::~dtkWidgetsDataManagerData(void)
{
}
const QString dtkWidgetsDataManagerData::ICON = "icon";
//
// dtkWidgetsDataManagerData.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <QtCore>
#include <QtWidgets>
class dtkWidgetsDataManagerItem;
class dtkWidgetsDataManagerData : public QObject
{
Q_OBJECT
public:
dtkWidgetsDataManagerData(QObject *parent = nullptr);
~dtkWidgetsDataManagerData(void);
public:
virtual long count(void) const {
return 0;
}
public:
static const QString ICON;
public:
inline void addMetadata(const QString& key, QVariant value) {
this->metadata[key] = value;
}
inline void setData(QVariant data) {
this->data = data;
}
public: // TODO: protected
dtkWidgetsDataManagerItem *reference;
public: // TODO: protected
QVariantMap metadata;
QVariant data;
private:
class dtkWidgetsDataManagerDataPrivate *d;
// /////////////////////////////////////////////////////////////////////////////
// TODO
// /////////////////////////////////////////////////////////////////////////////
// private:
// friend class dtkWidgetsDataManager;
// friend class dtkWidgetsDataManagerDataPrivate;
// friend class dtkWidgetsDataManagerItem;
// friend class dtkWidgetsDataManagerPrivate;
};
using dtkWidgetsDataManagerDataPtr = QPointer<dtkWidgetsDataManagerData>;
//
// dtkWidgetsDataManagerData.h ends here
#include "dtkWidgetsDataManagerFocus.h"
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsDataManagerFocus.h"
#include "dtkWidgetsDataManagerItem.h"
class dtkWidgetsDataManagerFocusPrivate {
public:
QHBoxLayout *layout = nullptr;
QLabel *label = nullptr;
QStandardItemModel *model = nullptr;
QTableView *metadata_table = nullptr;
public:
dtkWidgetsDataManagerItem *previous_item = nullptr;
};
dtkWidgetsDataManagerFocus::dtkWidgetsDataManagerFocus(QWidget *parent) : QWidget(parent)
{
d = new dtkWidgetsDataManagerFocusPrivate();
d->label = new QLabel(this);
d->model = new QStandardItemModel;
d->metadata_table = new QTableView(this);
d->metadata_table->setSortingEnabled(true);
d->metadata_table->setShowGrid(false);
d->metadata_table->horizontalHeader()->hide();
d->metadata_table->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
d->metadata_table->verticalHeader()->hide();
d->metadata_table->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
d->metadata_table->setModel(d->model);
d->layout = new QHBoxLayout(this);
d->layout->setContentsMargins(0, 0, 0, 0);
d->layout->setSpacing(0);
d->layout->addWidget(d->label);
d->layout->addWidget(d->metadata_table);
d->metadata_table->hide();
}
dtkWidgetsDataManagerFocus::~dtkWidgetsDataManagerFocus(void)
{
delete d;
}
void dtkWidgetsDataManagerFocus::setItem(dtkWidgetsDataManagerItem *item, const QVariantMap& metadata)
{
if(item == d->previous_item) {
return; // item already set, nothing to do
}
d->previous_item = item;
this->presented = false; // new item so not yet presented
this->hideMetaData();
d->label->setPixmap(*item->pixmap());
d->model->clear();
int row = 0;
for (auto it = metadata.begin(); it != metadata.end(); ++it, ++row) {
auto key = new QStandardItem(it.key());
auto value = new QStandardItem(it.value().toString());
d->model->setItem(row, 0, key);
d->model->setItem(row, 1, value);
}
d->metadata_table->updateGeometry();
}
void dtkWidgetsDataManagerFocus::scalePixmap(int w, int h)
{
d->label->pixmap()->scaled(w, h);
}
void dtkWidgetsDataManagerFocus::hideMetaData(void)
{
d->metadata_table->hide();
//d->layout->removeWidget(d->metadata_table);
}
void dtkWidgetsDataManagerFocus::showMetadata(void)
{
d->metadata_table->show();
}
void dtkWidgetsDataManagerFocus::mouseReleaseEvent(QMouseEvent *ev) {
QWidget::mouseReleaseEvent(ev);
emit clicked();
}
//
// dtkWidgetsDataManagerFocus.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <QtWidgets>
class dtkWidgetsDataManagerItem;
class dtkWidgetsDataManagerFocus : public QWidget {
Q_OBJECT
public:
dtkWidgetsDataManagerFocus(QWidget *parent = nullptr);
~dtkWidgetsDataManagerFocus(void);
public:
void setItem(dtkWidgetsDataManagerItem *item, const QVariantMap& metadata);
void hideMetaData(void);
void scalePixmap(int w, int h);
void showMetadata(void);
public:
QPoint source;
QPoint destnt;
public:
QSize s_size;
QSize d_size;
public:
bool presented = false;
protected:
void mouseReleaseEvent(QMouseEvent *ev) override;
signals:
void clicked(void);
private:
class dtkWidgetsDataManagerFocusPrivate *d;
};
//
// dtkWidgetsDataManagerFocus.h ends here
#include "dtkWidgetsDataManagerItem.h"
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsDataManager.h"
#include "dtkWidgetsDataManager_p.h"
#include "dtkWidgetsDataManagerItem.h"
#include "dtkWidgetsDataManagerItemButton.h"
#include <dtkFonts>
dtkWidgetsDataManagerItem::dtkWidgetsDataManagerItem(const QColor &color, const QPixmap &thumbnail, dtkWidgetsDataManagerPrivate *parent)
: QLabel(parent) {
this->parent = parent;
this->button_destroy = new dtkWidgetsDataManagerItemButton(color, fa::times, this);
this->button_destroy->move(79, 5);
this->button_destroy->setVisible(false);
this->button_save = new dtkWidgetsDataManagerItemButton(color, fa::save, this);
this->button_save->move(5, 5);
this->button_save->setVisible(false);
int size = 100;
int space = 3;
QPixmap pix;
bool multi_images = parent->data_series.count() > 1;
if (multi_images) {
this->setBaseSize(size, size);
pix = thumbnail.scaled(size, size, Qt::KeepAspectRatio);
QPixmap pix2(100, 100);
pix2.fill(Qt::transparent);
QImage image = pix.toImage();;
QPainter paint(&pix2);
paint.setPen(color);
paint.drawRect(2 * space, 0, size - 2 * space - 1, size - 2 * space - 1);
paint.fillRect(2 * space + 1, 1, size - 2 * space - 2, size - 2 * space - 2, Qt::black);
paint.drawRect(space, space, size - 2 * space - 1, size - 2 * space - 1);
paint.fillRect(space + 1, space + 1, size - 2 * space - 2, size - 2 * space - 2, Qt::black);
paint.drawRect(0, 2 * space, size - 2 * space - 1, size - 2 * space - 1);
QRectF target(1, 2 * space + 1, size - 2 * space - 2, size - 2 * space - 2);
QRectF source(0, 0, size - 2 * space - 3, size - 2 * space - 3);
paint.drawImage(target, image, source);
paint.end();
this->setPixmap(pix2);
this->thumbnail = pix2;
this->transparent_thumbnail = pix2;
this->transparent_thumbnail.fill();
} else {
pix = thumbnail.scaled(size, size, Qt::KeepAspectRatio);
this->setPixmap(pix);
this->thumbnail = *this->pixmap();
this->transparent_thumbnail = *this->pixmap();
this->transparent_thumbnail.fill();
}
QPainter painter;
painter.begin(&transparent_thumbnail);
painter.setOpacity(0.5);
painter.drawPixmap(0, 0, *this->pixmap());
painter.end();
if (!multi_images) {
this->setStyleSheet(
QString("border: 1px solid rgb(%1, %2, %3);").arg(color.red()).arg(color.green()).arg(color.blue()));
}
connect(this->button_destroy, SIGNAL(clicked()), this, SIGNAL(destroy()));
connect(this->button_save, SIGNAL(clicked()), this, SIGNAL(save()));
this->setMouseTracking(false);
this->setAcceptDrops(true);
}
dtkWidgetsDataManagerItem::~dtkWidgetsDataManagerItem(void) {
}
void dtkWidgetsDataManagerItem::enterEvent(QEvent *) {
this->button_destroy->setVisible(true);
this->button_save->setVisible(true);
this->setPixmap(this->transparent_thumbnail);
}
void dtkWidgetsDataManagerItem::leaveEvent(QEvent *) {
this->button_destroy->setVisible(false);
this->button_save->setVisible(false);
this->setPixmap(this->thumbnail);
}
void dtkWidgetsDataManagerItem::mouseMoveEvent(QMouseEvent *event)
{
QMimeData *mimeData = new QMimeData;
mimeData->setText(QString(":%1").arg(this->id));
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setPixmap(*(this->pixmap()));
drag->setHotSpot(QPoint(drag->pixmap().width() / 2, drag->pixmap().height() / 2));
Qt::DropAction dropAction = drag->exec();
}
void dtkWidgetsDataManagerItem::dropEvent(QDropEvent *event)
{
QVariant& data = dtkWidgetsDataManager::instance()->get(id)->data;
auto path = event->mimeData()->text();
auto label = new QLabel(path);
QVariantMap map = data.toMap();
map[path] = QVariant::fromValue(label);
data.setValue(map);
}
void dtkWidgetsDataManagerItem::dragEnterEvent(QDragEnterEvent *event)
{
event->acceptProposedAction();
}
void dtkWidgetsDataManagerItem::mouseReleaseEvent(QMouseEvent *event)
{
emit clicked();
}
//
// dtkWidgetsDataManagerItem.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <QtCore>
#include <QtWidgets>
class dtkWidgetsDataManagerPrivate;
class dtkWidgetsDataManagerItemButton;
class dtkWidgetsDataManagerItem : public QLabel {
Q_OBJECT
public:
dtkWidgetsDataManagerItem(const QColor &, const QPixmap &thumbnail, dtkWidgetsDataManagerPrivate *parent);
~dtkWidgetsDataManagerItem(void) override;
signals:
void clicked(void);
void destroy(void);
void save(void);
public:
int id;
public:
dtkWidgetsDataManagerPrivate *parent;
public:
dtkWidgetsDataManagerItemButton *button_destroy;
dtkWidgetsDataManagerItemButton *button_save;
public:
QPixmap thumbnail;
QPixmap transparent_thumbnail;
protected:
void enterEvent(QEvent *) override;
void leaveEvent(QEvent *) override;
void mouseReleaseEvent(QMouseEvent *) override;
void mouseMoveEvent(QMouseEvent *event) override;
void dropEvent(QDropEvent *event) override;
void dragEnterEvent(QDragEnterEvent *event) override;
};
//
// dtkWidgetsDataManagerItem.h ends here
#include "dtkWidgetsDataManagerItemButton.h"
\ No newline at end of file
#include "dtkWidgetsDataManagerItemButton.h"
#include <QApplication>
#include <QStyle>
#include <dtkFontAwesome>
dtkWidgetsDataManagerItemButton::dtkWidgetsDataManagerItemButton(const QColor& color, int icon, QWidget *parent) : QLabel(parent)
{
this->font = dtkFontAwesome::instance();
this->font->initFontAwesome();
this->font->setDefaultOption("color", color);
this->setPixmap(this->font->icon(icon).pixmap(16, 16));
this->setStyleSheet("background: none; border: none;");
}
dtkWidgetsDataManagerItemButton::~dtkWidgetsDataManagerItemButton(void)
{
}
void dtkWidgetsDataManagerItemButton::mousePressEvent(QMouseEvent *)
{
emit clicked();
}
#pragma once
#include <dtkWidgetsExport>
#include <QtCore>
#include <QLabel>
class dtkFontAwesome;
// ///////////////////////////////////////////////////////////////////
// gnomonItemButton
// ///////////////////////////////////////////////////////////////////
class DTKWIDGETS_EXPORT dtkWidgetsDataManagerItemButton : public QLabel
{
Q_OBJECT
public:
dtkWidgetsDataManagerItemButton(const QColor& color, int icon, QWidget *parent = nullptr);
~dtkWidgetsDataManagerItemButton(void);
signals:
void clicked(void);
protected:
void mousePressEvent(QMouseEvent *);
private:
dtkFontAwesome *font;
};
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include "dtkWidgets"
#include <QtCore>
#include <QtWidgets>
class dtkWidgetsDataManager;
class dtkWidgetsDataManagerItem;
class dtkWidgetsDataManagerFocus;
class dtkWidgetsDataManagerPrivate : public QScrollArea
{
public:
enum State {
Collapsed,
Expanded
};
public:
dtkWidgetsDataManagerPrivate(QWidget *parent = nullptr);
~dtkWidgetsDataManagerPrivate(void);
public:
QSize sizeHint(void) const;
public:
dtkWidgetsDataManagerItem *create(dtkWidgetsDataManagerDataPtr, const QColor&, const QImage &img = QImage());
public:
QHash<dtkWidgetsDataManagerItem *, dtkWidgetsDataManagerDataPtr> data_series;
public:
dtkWidgetsDataManager *q;
public:
dtkWidgetsDataManagerFocus *focus_item = nullptr;
public:
static int item_counter;
public:
bool inside = false;
public:
QWidget *contents;
public:
State state = Collapsed;
};
//
// dtkWidgetsDataManager_p.h ends here
#include "dtkWidgetsDataManager"