Commit 3255ef8f authored by CABEL Tristan's avatar CABEL Tristan

square items in dataManager

parent da198535
......@@ -32,7 +32,7 @@ dtkWidgetsDataManagerPrivate::dtkWidgetsDataManagerPrivate(QWidget *parent) : QS
QHBoxLayout *layout = new QHBoxLayout(this->contents);
layout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
layout->addSpacing(50); // for the menu bar
this->setFrameShape(QFrame::NoFrame);
this->setWidget(this->contents);
this->setWidgetResizable(true);
......@@ -57,7 +57,15 @@ dtkWidgetsDataManagerItem *dtkWidgetsDataManagerPrivate::create(dtkWidgetsDataMa
QPixmap pixmap;
if(!img.isNull()) {
pixmap = QPixmap::fromImage(img);
// we want a square image
int w = img.width();
int h = img.height();
int length = w < h ? w : h; // std::min(w, h);
int ori_x = w < h ? 0 : w/2 - length/2;
int ori_y = w < h ? h/2 - length/2 : 0;
pixmap = QPixmap::fromImage(img.copy( ori_x, ori_y, length, length));
} else {
if (data_serie->metadata.contains(dtkWidgetsDataManagerData::ICON)) {
pixmap = QPixmap(data_serie->metadata[dtkWidgetsDataManagerData::ICON].toString());
......@@ -177,6 +185,7 @@ dtkWidgetsDataManager::dtkWidgetsDataManager(QWidget *parent) : QFrame(parent)
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setAlignment(Qt::AlignTop);
layout->addSpacing(10); // for the title bar
layout->setContentsMargins(0, 0, 0, 0);
layout->addLayout(t_layout);
......@@ -237,6 +246,8 @@ void dtkWidgetsDataManager::present(dtkWidgetsDataManagerItem *item)
});
connect(s_animation, &QVariantAnimation::valueChanged, [=](const QVariant &value) {
int min_v = value.toSize().width() < value.toSize().height() ? value.toSize().width() : value.toSize().height();
d->focus_item->scalePixmap(min_v, min_v);
d->focus_item->resize(value.toSize());
});
......@@ -255,16 +266,16 @@ void dtkWidgetsDataManager::present(dtkWidgetsDataManagerItem *item)
d->focus_item->move(item->pos());
d->focus_item->resize(item->size());
d->focus_item->setStyleSheet("border: 2px solid white;");
//d->focus_item->setStyleSheet("border: 2px solid white;");
d->focus_item->show();
d->focus_item->source = d->focus_item->pos();
d->focus_item->destnt = QPoint(this->size().width() * 0.2,
d->focus_item->destnt = QPoint(this->size().width() * 0.15,
this->size().height() * 0.25);
d->focus_item->s_size = d->focus_item->size();
d->focus_item->d_size = QSize(this->size().width() * 0.6,
d->focus_item->d_size = QSize(this->size().width() * 0.7,
this->size().height() * 0.5);
//p = position
......@@ -292,6 +303,8 @@ void dtkWidgetsDataManager::present(dtkWidgetsDataManagerItem *item)
connect(s_animation, &QVariantAnimation::valueChanged, [=] (const QVariant &value)
{
int min_v = value.toSize().width() < value.toSize().height() ? value.toSize().width() : value.toSize().height();
d->focus_item->scalePixmap(min_v, min_v);
d->focus_item->resize(value.toSize());
});
......@@ -327,12 +340,18 @@ void dtkWidgetsDataManager::mousePressEvent(QMouseEvent *event)
if (handle.contains(event->pos())) {
if (this->size().height() < 150) {
if (d->state == dtkWidgetsDataManagerPrivate::Collapsed) {
emit expand();
d->state = dtkWidgetsDataManagerPrivate::Expanded;
} else {
emit shrink();
d->state = dtkWidgetsDataManagerPrivate::Collapsed;
// un present the focus item if it's presented
if(d->focus_item) {
delete d->focus_item;
d->focus_item = nullptr;
}
}
}
}
......
......@@ -80,6 +80,11 @@ void dtkWidgetsDataManagerFocus::setItem(dtkWidgetsDataManagerItem *item, const
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();
......
......@@ -28,6 +28,7 @@ public:
public:
void setItem(dtkWidgetsDataManagerItem *item, const QVariantMap& metadata);
void hideMetaData(void);
void scalePixmap(int w, int h);
void showMetadata(void);
public:
......
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