more updates
This commit is contained in:
@@ -6,7 +6,7 @@ set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
|
||||
@@ -25,7 +25,7 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
MANUAL_FINALIZATION
|
||||
${PROJECT_SOURCES}
|
||||
tiercard.hpp tiercard.cpp
|
||||
flowlayout.cpp flowlayout.h flowlayout.pro
|
||||
flowlayout.cpp flowlayout.h
|
||||
tiercardlayout.hpp tiercardlayout.cpp
|
||||
aspectratiopixmaplabel.hpp aspectratiopixmaplabel.cpp
|
||||
fullsizelayout.hpp fullsizelayout.cpp
|
||||
@@ -35,6 +35,8 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
utils.hpp
|
||||
rowholder.hpp rowholder.cpp
|
||||
settings.hpp settings.cpp
|
||||
invalididexception.hpp invalididexception.cpp
|
||||
tierplaceholder.hpp tierplaceholder.cpp
|
||||
|
||||
)
|
||||
# Define target properties for Android with Qt 6 as:
|
||||
|
||||
@@ -102,6 +102,8 @@ QSize FlowLayout::minimumSize() const
|
||||
|
||||
const QMargins margins = contentsMargins();
|
||||
size += QSize(margins.left() + margins.right(), margins.top() + margins.bottom());
|
||||
if (size.height() < minimumHeight())
|
||||
size.rheight() = minimumHeight();
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -143,12 +145,41 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
|
||||
int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
|
||||
{
|
||||
QObject* parent = this->parent();
|
||||
if (!parent) {
|
||||
if (!parent)
|
||||
{
|
||||
return -1;
|
||||
} else if (parent->isWidgetType()) {
|
||||
}
|
||||
else if (parent->isWidgetType())
|
||||
{
|
||||
QWidget* pw = static_cast<QWidget*>(parent);
|
||||
return pw->style()->pixelMetric(pm, nullptr, pw);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return static_cast<QLayout*>(parent)->spacing();
|
||||
}
|
||||
}
|
||||
|
||||
void FlowLayout::setIndex(QWidget* wid, int index)
|
||||
{
|
||||
if (itemAt(index)->widget() == wid)
|
||||
return;
|
||||
wid->setParent(nullptr);
|
||||
addWidget(wid);
|
||||
if (index < 0)
|
||||
return;
|
||||
for (int i = count()-1; i > index; i--)
|
||||
{
|
||||
itemList.swapItemsAt(i-1, i);
|
||||
}
|
||||
}
|
||||
|
||||
void FlowLayout::setMinimumHeight(int minh)
|
||||
{
|
||||
_minimumHeight = minh;
|
||||
}
|
||||
|
||||
int FlowLayout::minimumHeight() const
|
||||
{
|
||||
return _minimumHeight;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <QLayout>
|
||||
#include <QRect>
|
||||
#include <QStyle>
|
||||
//! [0]
|
||||
|
||||
class FlowLayout : public QLayout
|
||||
{
|
||||
public:
|
||||
@@ -27,15 +27,17 @@ public:
|
||||
void setGeometry(const QRect &rect) override;
|
||||
QSize sizeHint() const override;
|
||||
QLayoutItem* takeAt(int index) override;
|
||||
void setIndex(QWidget* wid, int index);
|
||||
void setMinimumHeight(int minh);
|
||||
int minimumHeight() const;
|
||||
|
||||
private:
|
||||
int doLayout(const QRect &rect, bool testOnly) const;
|
||||
int smartSpacing(QStyle::PixelMetric pm) const;
|
||||
|
||||
int _minimumHeight = 0;
|
||||
QList<QLayoutItem*> itemList;
|
||||
int m_hSpace;
|
||||
int m_vSpace;
|
||||
};
|
||||
//! [0]
|
||||
|
||||
#endif // FLOWLAYOUT_H
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
QT += widgets
|
||||
|
||||
HEADERS = flowlayout.h \
|
||||
window.h
|
||||
SOURCES = flowlayout.cpp \
|
||||
main.cpp \
|
||||
window.cpp
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/layouts/flowlayout
|
||||
INSTALLS += target
|
||||
@@ -41,7 +41,7 @@ bool FullSizeLayout::hasHeightForWidth() const
|
||||
}
|
||||
int FullSizeLayout::heightForWidth(int width) const
|
||||
{
|
||||
int h = -1;
|
||||
int h = 0;
|
||||
for (auto child : itemList)
|
||||
{
|
||||
h = std::max(h, child->heightForWidth(width));
|
||||
@@ -58,7 +58,7 @@ QLayoutItem* FullSizeLayout::itemAt(int index) const
|
||||
}
|
||||
QSize FullSizeLayout::minimumSize() const
|
||||
{
|
||||
QSize size;
|
||||
QSize size(0, 0);
|
||||
for (auto child : itemList)
|
||||
{
|
||||
// auto wid = child->widget();
|
||||
|
||||
38
invalididexception.cpp
Normal file
38
invalididexception.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "invalididexception.hpp"
|
||||
|
||||
InvalidIdException::InvalidIdException()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
InvalidRowIdException::InvalidRowIdException(TierRow::IdType id)
|
||||
: _id(id), _what(std::format("id: {}", _id))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TierRow::IdType InvalidRowIdException::id() const
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
const char* InvalidRowIdException::what() const noexcept
|
||||
{
|
||||
return _what.c_str();
|
||||
}
|
||||
|
||||
InvalidCardIdException::InvalidCardIdException(TierCard::IdType id)
|
||||
: _id(id), _what(std::format("id: {}", _id))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TierCard::IdType InvalidCardIdException::id() const
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
const char* InvalidCardIdException::what() const noexcept
|
||||
{
|
||||
return _what.c_str();
|
||||
}
|
||||
39
invalididexception.hpp
Normal file
39
invalididexception.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef INVALIDIDEXCEPTION_HPP
|
||||
#define INVALIDIDEXCEPTION_HPP
|
||||
|
||||
#include "tierrow.hpp"
|
||||
#include "tiercard.hpp"
|
||||
|
||||
#include <QException>
|
||||
|
||||
class InvalidIdException : public QException
|
||||
{
|
||||
public:
|
||||
InvalidIdException();
|
||||
};
|
||||
|
||||
class InvalidRowIdException : public InvalidIdException
|
||||
{
|
||||
public:
|
||||
InvalidRowIdException(TierRow::IdType id);
|
||||
TierRow::IdType id() const;
|
||||
const char* what() const noexcept override;
|
||||
|
||||
private:
|
||||
const TierRow::IdType _id;
|
||||
const std::string _what;
|
||||
};
|
||||
|
||||
class InvalidCardIdException : public InvalidIdException
|
||||
{
|
||||
public:
|
||||
InvalidCardIdException(TierCard::IdType id);
|
||||
TierCard::IdType id() const;
|
||||
const char* what() const noexcept override;
|
||||
|
||||
private:
|
||||
const TierCard::IdType _id;
|
||||
const std::string _what;
|
||||
};
|
||||
|
||||
#endif // INVALIDIDEXCEPTION_HPP
|
||||
19
main.cpp
19
main.cpp
@@ -4,6 +4,7 @@
|
||||
#include "tiercardlayout.hpp"
|
||||
#include "utils.hpp"
|
||||
#include "rowholder.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QNetworkAccessManager>
|
||||
@@ -56,8 +57,12 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
auto settings = Settings::getSettable();
|
||||
settings->setCardSize(150, 150);
|
||||
settings->setRowFade(.8f);
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
settings->setMainWindow(&w);
|
||||
// QDockWidget dock;
|
||||
QScrollArea scroll;
|
||||
TierRow* row = TierRow::create();
|
||||
@@ -67,11 +72,9 @@ int main(int argc, char *argv[])
|
||||
row->setStyleSheet(makeBgColorString(QColor(35,35,35)));
|
||||
card1->setText("CARD1");
|
||||
card1->setBgColor(QColor(64,255,64));
|
||||
card1->setFixedSize(150,150);
|
||||
TierCard* card2 = TierCard::create();
|
||||
card2->setText("CARD2");
|
||||
card2->setBgColor(QColor(64,64,255));
|
||||
card2->setFixedSize(150,150);
|
||||
row->addCard(card1);
|
||||
row->addCard(card2);
|
||||
|
||||
@@ -81,13 +84,10 @@ int main(int argc, char *argv[])
|
||||
TierCard* card3 = TierCard::create();
|
||||
card3->setText("CARD1");
|
||||
card3->setBgColor(QColor(64,12,164));
|
||||
card3->setFixedSize(150,150);
|
||||
TierCard* card4 = TierCard::create();
|
||||
card4->setText("CARD2");
|
||||
card4->setBgColor(QColor(164,64,155));
|
||||
card4->setFixedSize(150,150);
|
||||
auto card5 = TierCard::clone(card4);
|
||||
card5->setFixedSize(150,150);
|
||||
row->addCard(card5);
|
||||
row2->addCard(card3);
|
||||
row2->addCard(card4);
|
||||
@@ -115,11 +115,12 @@ int main(int argc, char *argv[])
|
||||
// a.setFont()
|
||||
// QTimer bg_changer;
|
||||
// bg_changer.setTimerType(Qt::PreciseTimer);
|
||||
// bg_changer.setSingleShot(false);
|
||||
// bg_changer.setInterval(1000);
|
||||
// QObject::connect(&bg_changer, &QTimer::timeout, [&row]()
|
||||
// bg_changer.setSingleShot(true);
|
||||
// bg_changer.setInterval(2000);
|
||||
// QObject::connect(&bg_changer, &QTimer::timeout, [&settings]()
|
||||
// {
|
||||
// row.updateGeometry();
|
||||
// // row.updateGeometry();
|
||||
// settings->setCardSize(250,100);
|
||||
// });
|
||||
// bg_changer.start();
|
||||
// w.show();
|
||||
|
||||
56
settings.cpp
56
settings.cpp
@@ -1,5 +1,59 @@
|
||||
#include "settings.hpp"
|
||||
|
||||
#include <QMutexLocker>
|
||||
|
||||
Settings::Settings(QObject *parent)
|
||||
: QObject{parent}
|
||||
{}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const Settings* Settings::get()
|
||||
{
|
||||
return getSettable();
|
||||
}
|
||||
|
||||
Settings* Settings::getSettable()
|
||||
{
|
||||
QMutexLocker locker(&lock);
|
||||
if (!instance)
|
||||
instance = new Settings();
|
||||
return instance;
|
||||
}
|
||||
|
||||
QSize Settings::cardSize() const
|
||||
{
|
||||
return _cardSize;
|
||||
}
|
||||
|
||||
void Settings::setCardSize(QSize newSize)
|
||||
{
|
||||
_cardSize = newSize;
|
||||
emit cardSizeChange(newSize);
|
||||
}
|
||||
|
||||
void Settings::setCardSize(int w, int h)
|
||||
{
|
||||
setCardSize(QSize(w, h));
|
||||
}
|
||||
|
||||
void Settings::setMainWindow(QWidget* wid)
|
||||
{
|
||||
_mainWindow = wid;
|
||||
}
|
||||
|
||||
QWidget* Settings::mainWindow() const
|
||||
{
|
||||
return _mainWindow;
|
||||
}
|
||||
|
||||
void Settings::setRowFade(float fade)
|
||||
{
|
||||
_rowFade = fade;
|
||||
emit rowFadeChange(fade);
|
||||
}
|
||||
|
||||
float Settings::rowFade() const
|
||||
{
|
||||
return _rowFade;
|
||||
}
|
||||
|
||||
20
settings.hpp
20
settings.hpp
@@ -2,14 +2,34 @@
|
||||
#define SETTINGS_HPP
|
||||
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
#include <QRect>
|
||||
|
||||
class Settings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static const Settings* get();
|
||||
static Settings* getSettable();
|
||||
QSize cardSize() const;
|
||||
void setCardSize(QSize size);
|
||||
void setCardSize(int w, int h);
|
||||
QWidget* mainWindow() const;
|
||||
void setMainWindow(QWidget* wid);
|
||||
float rowFade() const;
|
||||
void setRowFade(float trans);
|
||||
|
||||
private:
|
||||
explicit Settings(QObject *parent = nullptr);
|
||||
inline static Settings* instance;
|
||||
inline static QMutex lock;
|
||||
QSize _cardSize;
|
||||
QWidget* _mainWindow = nullptr;
|
||||
float _rowFade = 0;
|
||||
|
||||
signals:
|
||||
void cardSizeChange(QSize newSize);
|
||||
void rowFadeChange(float newFade);
|
||||
};
|
||||
|
||||
#endif // SETTINGS_HPP
|
||||
|
||||
48
tiercard.cpp
48
tiercard.cpp
@@ -2,40 +2,10 @@
|
||||
#include "fullsizelayout.hpp"
|
||||
#include "qmimedata.h"
|
||||
#include "utils.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
|
||||
// TierCard::TierCard(QWidget *parent)
|
||||
// : QWidget{parent}
|
||||
// {
|
||||
// auto bg_layout= new QVBoxLayout(this);
|
||||
// bg_layout->setSpacing(0);
|
||||
// bg_layout->setContentsMargins(0, 0, 0, 0);
|
||||
// background = new QWidget();
|
||||
// bg_layout->addWidget(background);
|
||||
// auto img_layout = new QVBoxLayout(background);
|
||||
// img_layout->setSpacing(0);
|
||||
// img_layout->setContentsMargins(0, 0, 0, 0);
|
||||
// image = new AspectRatioPixmapLabel();
|
||||
// img_layout->addWidget(image, 0, Qt::AlignCenter);
|
||||
// image->setAttribute(Qt::WA_TranslucentBackground);
|
||||
// image->setAlignment(Qt::AlignCenter);
|
||||
// auto txt_layout = new QVBoxLayout(image);
|
||||
// txt_layout->setSpacing(0);
|
||||
// txt_layout->setContentsMargins(0, 0, 0, 0);
|
||||
// text_label = new QLabel();
|
||||
// id_label = new QLabel("4");
|
||||
// text_label->setWordWrap(true);
|
||||
// // text_label->setTextFormat(Qt::RichText);
|
||||
// text_label->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
|
||||
// id_label->setAlignment(Qt::AlignLeft | Qt::AlignBottom);
|
||||
// text_label->setAttribute(Qt::WA_TranslucentBackground);
|
||||
// id_label->setAttribute(Qt::WA_TranslucentBackground);
|
||||
// txt_layout->addWidget(text_label, Qt::AlignTop | Qt::AlignHCenter);
|
||||
// txt_layout->addWidget(id_label, Qt::AlignBottom, Qt::AlignLeft);
|
||||
// text_label->setProperty("cssClass", "tierCardText");
|
||||
// id_label->setProperty("cssClass", "tierCardId");
|
||||
// }
|
||||
#include <QDrag>
|
||||
|
||||
TierCard::IdType TierCard::getAvailableId()
|
||||
{
|
||||
@@ -72,6 +42,7 @@ TierCard* TierCard::clone(TierCard *other, QWidget* parent)
|
||||
card = new TierCard(id, parent);
|
||||
card->setText(other->getText());
|
||||
auto img = other->getImage();
|
||||
if (!img.isNull())
|
||||
card->setImage(img);
|
||||
card->setBgColor(other->getBgColor());
|
||||
idMap[id] = card;
|
||||
@@ -81,6 +52,9 @@ TierCard* TierCard::clone(TierCard *other, QWidget* parent)
|
||||
TierCard::TierCard(IdType id, QWidget* parent)
|
||||
: QWidget{parent}
|
||||
{
|
||||
auto settings = Settings::get();
|
||||
connect(settings, SIGNAL(cardSizeChange(QSize)),
|
||||
this, SLOT(cardResize(QSize)));
|
||||
background = new QWidget();
|
||||
image = new AspectRatioPixmapLabel();
|
||||
image->setAttribute(Qt::WA_TranslucentBackground);
|
||||
@@ -102,6 +76,7 @@ TierCard::TierCard(IdType id, QWidget* parent)
|
||||
layout->addWidget(textLabel);
|
||||
layout->addWidget(idLabel);
|
||||
this->setLayout(layout);
|
||||
cardResize(settings->cardSize());
|
||||
}
|
||||
|
||||
TierCard::~TierCard()
|
||||
@@ -158,9 +133,11 @@ void TierCard::mousePressEvent(QMouseEvent* event)
|
||||
render(&pix);
|
||||
QDrag drag(this);
|
||||
drag.setPixmap(pix);
|
||||
drag.setHotSpot(QPoint(pix.size().width() / 2,
|
||||
pix.size().height() / 2));
|
||||
QByteArray itemData;
|
||||
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
|
||||
auto _id = getId();
|
||||
TierCard::IdType _id = getId();
|
||||
dataStream.writeRawData(reinterpret_cast<char*>(&_id), sizeof(_id));
|
||||
QMimeData *mimeData = new QMimeData;
|
||||
mimeData->setData(MimeType, itemData);
|
||||
@@ -183,3 +160,8 @@ TierCard* TierCard::getFromId(IdType id)
|
||||
return nullptr;
|
||||
return &(*iter->second);
|
||||
}
|
||||
|
||||
void TierCard::cardResize(QSize newSize)
|
||||
{
|
||||
setFixedSize(newSize);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@ private:
|
||||
static void releaseId(IdType id);
|
||||
inline static std::unordered_map<IdType, TierCard*> idMap;
|
||||
|
||||
public slots:
|
||||
void cardResize(QSize newSize);
|
||||
|
||||
signals:
|
||||
};
|
||||
|
||||
|
||||
24
tierplaceholder.cpp
Normal file
24
tierplaceholder.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "tierplaceholder.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
TierPlaceholder::TierPlaceholder(QWidget *parent)
|
||||
: QWidget{parent}
|
||||
{
|
||||
auto settings = Settings::get();
|
||||
connect(settings, SIGNAL(cardSizeChange(QSize)),
|
||||
this, SLOT(cardResize(QSize)));
|
||||
QSizePolicy sp;
|
||||
sp.setRetainSizeWhenHidden(true);
|
||||
sp.setHorizontalPolicy(QSizePolicy::Fixed);
|
||||
sp.setVerticalPolicy(QSizePolicy::Fixed);
|
||||
setSizePolicy(sp);
|
||||
//TODO potentially a race condition if card size is
|
||||
//changed between settings->cardSize() being evaluated
|
||||
//and cardResize() being called
|
||||
cardResize(settings->cardSize());
|
||||
}
|
||||
|
||||
void TierPlaceholder::cardResize(QSize newSize)
|
||||
{
|
||||
setFixedSize(newSize);
|
||||
}
|
||||
18
tierplaceholder.hpp
Normal file
18
tierplaceholder.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef TIERPLACEHOLDER_HPP
|
||||
#define TIERPLACEHOLDER_HPP
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class TierPlaceholder : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TierPlaceholder(QWidget *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void cardResize(QSize newSize);
|
||||
|
||||
signals:
|
||||
};
|
||||
|
||||
#endif // TIERPLACEHOLDER_HPP
|
||||
139
tierrow.cpp
139
tierrow.cpp
@@ -1,49 +1,44 @@
|
||||
#include "tierrow.hpp"
|
||||
#include "fullsizelayout.hpp"
|
||||
// #include "fullsizelayout.hpp"
|
||||
#include "qmimedata.h"
|
||||
#include "utils.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "invalididexception.hpp"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
|
||||
TierRow::TierRow(IdType id, QWidget *parent)
|
||||
: QWidget{parent}
|
||||
: QWidget{parent}, _id(id)
|
||||
{
|
||||
auto settings = Settings::get();
|
||||
setAcceptDrops(true);
|
||||
auto fadeLayout = new FullSizeLayout();
|
||||
fadeLayout->setSizeConstraint(QLayout::SetMinimumSize);
|
||||
fadeLayout->setContentsMargins(0, 0, 0, 0);
|
||||
fadeLayout->setSpacing(0);
|
||||
bgFadeContainer = new QWidget();
|
||||
bgFadeContainer->setStyleSheet(makeBgColorString(QColor(255,255,255,100)));
|
||||
bgFadeContainer->setMinimumSize(0, 0);
|
||||
fadeLayout->addWidget(bgFadeContainer);
|
||||
this->setLayout(fadeLayout);
|
||||
auto splitLayout = new QHBoxLayout();
|
||||
splitLayout->setSizeConstraint(QLayout::SetMinimumSize);
|
||||
splitLayout->setContentsMargins(0, 0, 0, 0);
|
||||
splitLayout->setSpacing(0);
|
||||
this->setLayout(splitLayout);
|
||||
titleCard = new TierRowTitleCard(id);
|
||||
cardContainer = new QWidget();
|
||||
cardContainer->setMinimumSize(0, 0);
|
||||
titleCard->setFixedSize(150, 150);
|
||||
cardContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
splitLayout->addWidget(titleCard, 0, Qt::AlignLeft | Qt::AlignTop);
|
||||
splitLayout->addWidget(cardContainer, 1, Qt::AlignTop);
|
||||
|
||||
cardContainer->setStyleSheet(makeBgColorString(QColor(60,60,60,100)));
|
||||
|
||||
bgFadeContainer->setLayout(splitLayout);
|
||||
cardLayout = new FlowLayout();
|
||||
// cardContainer->setStyleSheet(makeBgColorString(QColor(60,60,60,100)));
|
||||
cardLayout = new FlowLayout(nullptr, 0, 0, 0);
|
||||
cardLayout->setSizeConstraint(QLayout::SetMinimumSize);
|
||||
cardLayout->setContentsMargins(0, 0, 0, 0);
|
||||
cardLayout->setSpacing(0);
|
||||
cardContainer->setLayout(cardLayout);
|
||||
// setMinimumSize(0, 0);
|
||||
connect(settings, SIGNAL(cardSizeChange(QSize)),
|
||||
this, SLOT(cardResize(QSize)));
|
||||
connect(settings, SIGNAL(rowFadeChange(float)),
|
||||
this, SLOT(fadeChange(float)));
|
||||
cardResize(settings->cardSize());
|
||||
}
|
||||
|
||||
TierRow::~TierRow()
|
||||
{
|
||||
qDebug() << "Row destructor called " << id();
|
||||
// qDebug() << "Row destructor called " << id();
|
||||
if (idMap.erase(id()) == 0)
|
||||
{
|
||||
qDebug() << "Row id not found during destructor";
|
||||
@@ -60,12 +55,20 @@ void TierRow::addCard(TierCard* card)
|
||||
// }
|
||||
void TierRow::setColor(QColor color)
|
||||
{
|
||||
auto settings = Settings::get();
|
||||
auto fade = settings->rowFade();
|
||||
if (fade < 0)
|
||||
fade = 0;
|
||||
if (fade > 1)
|
||||
fade = 1;
|
||||
_color = color;
|
||||
const QColor wh(255,255,255);
|
||||
titleCard->setColor(color);
|
||||
auto str = makeBgColorString(color);
|
||||
auto fadedColor = blend(wh, color, fade);
|
||||
auto str = makeBgColorString(fadedColor);
|
||||
setStyleSheet(str);
|
||||
}
|
||||
QColor TierRow::color()
|
||||
QColor TierRow::color() const
|
||||
{
|
||||
return _color;
|
||||
}
|
||||
@@ -73,13 +76,13 @@ void TierRow::setText(QString text)
|
||||
{
|
||||
titleCard->setText(text);
|
||||
}
|
||||
QString TierRow::text()
|
||||
QString TierRow::text() const
|
||||
{
|
||||
return titleCard->text();
|
||||
}
|
||||
uint32_t TierRow::id()
|
||||
uint32_t TierRow::id() const
|
||||
{
|
||||
return titleCard->id();
|
||||
return _id;
|
||||
}
|
||||
|
||||
void TierRow::resizeEvent(QResizeEvent* event)
|
||||
@@ -90,7 +93,8 @@ void TierRow::resizeEvent(QResizeEvent* event)
|
||||
|
||||
void TierRow::recalcMaxHeight()
|
||||
{
|
||||
setMaximumHeight(cardLayout->totalMinimumHeightForWidth(cardContainer->width()));
|
||||
setMaximumHeight(cardLayout->totalMinimumHeightForWidth(
|
||||
cardContainer->width()));
|
||||
}
|
||||
|
||||
TierRow* TierRow::create(QWidget* parent)
|
||||
@@ -120,18 +124,22 @@ TierRow* TierRow::getFromId(IdType id)
|
||||
void TierRow::dropEvent(QDropEvent* event)
|
||||
{
|
||||
qDebug() << "drop event";
|
||||
// auto source = event->source();
|
||||
//card dragged to this row
|
||||
if (event->mimeData()->hasFormat(TierCard::MimeType))
|
||||
{
|
||||
if (event->proposedAction() == Qt::MoveAction)
|
||||
{
|
||||
clearPlaceholder();
|
||||
auto data = event->mimeData()->data(TierCard::MimeType);
|
||||
QDataStream stream(&data, QIODevice::ReadOnly);
|
||||
TierCard::IdType cardId;
|
||||
uint dataLen = 0;
|
||||
stream.readRawData(reinterpret_cast<char*>(&cardId), dataLen);
|
||||
stream.readRawData(reinterpret_cast<char*>(&cardId), sizeof(cardId));
|
||||
auto card = TierCard::getFromId(cardId);
|
||||
addCard(card);
|
||||
if (!card)
|
||||
throw InvalidCardIdException(cardId);
|
||||
// addCard(card);
|
||||
cardLayout->setIndex(card, calculateIndex(event->position()));
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
else
|
||||
@@ -149,10 +157,21 @@ void TierRow::dropEvent(QDropEvent *event)
|
||||
void TierRow::dragEnterEvent(QDragEnterEvent* event)
|
||||
{
|
||||
qDebug() << "drag enter event";
|
||||
if (cardCount() == 0)
|
||||
{
|
||||
qDebug() << "enter empty";
|
||||
}
|
||||
if (event->mimeData()->hasFormat(TierCard::MimeType))
|
||||
{
|
||||
if (event->proposedAction() == Qt::MoveAction)
|
||||
{
|
||||
if (placeholder != nullptr)
|
||||
{
|
||||
qDebug() << "placeholder not previously cleared";
|
||||
clearPlaceholder();
|
||||
}
|
||||
placeholder = new TierPlaceholder();
|
||||
cardLayout->setIndex(placeholder, calculateIndex(event->position()));
|
||||
event->setDropAction(Qt::MoveAction);
|
||||
event->accept(cardContainer->rect());
|
||||
}
|
||||
@@ -174,11 +193,16 @@ void TierRow::dragEnterEvent(QDragEnterEvent *event)
|
||||
|
||||
void TierRow::dragMoveEvent(QDragMoveEvent* event)
|
||||
{
|
||||
qDebug() << "drag move event";
|
||||
if (event->mimeData()->hasFormat(TierCard::MimeType))
|
||||
{
|
||||
if (event->proposedAction() == Qt::MoveAction)
|
||||
{
|
||||
if (cardCount() == 1)
|
||||
{
|
||||
qDebug() << "moving in empty";
|
||||
}
|
||||
if (placeholder)
|
||||
cardLayout->setIndex(placeholder, calculateIndex(event->position()));
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
else
|
||||
@@ -190,9 +214,62 @@ void TierRow::dragMoveEvent(QDragMoveEvent *event)
|
||||
else if (event->mimeData()->hasImage())
|
||||
{
|
||||
event->setDropAction(Qt::CopyAction);
|
||||
event->accept();
|
||||
//TODO event->accept();
|
||||
event->ignore();
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void TierRow::dragLeaveEvent(QDragLeaveEvent* event)
|
||||
{
|
||||
clearPlaceholder();
|
||||
}
|
||||
|
||||
void TierRow::clearPlaceholder()
|
||||
{
|
||||
placeholder->setParent(nullptr);
|
||||
placeholder->deleteLater();
|
||||
placeholder = nullptr;
|
||||
}
|
||||
|
||||
int TierRow::calculateIndex(QPointF loc)
|
||||
{
|
||||
auto settings = Settings::get();
|
||||
auto cardSize = settings->cardSize();
|
||||
auto cardCenter = loc + QPointF(cardSize.width() / 2,
|
||||
cardSize.height() / 2);
|
||||
auto lastBefore = 0;
|
||||
for (int i = 0; i < cardLayout->count(); i++)
|
||||
{
|
||||
auto refCard = cardLayout->itemAt(i);
|
||||
auto refPos = refCard->widget()->pos();
|
||||
if (cardCenter.y() > refPos.y()
|
||||
&& cardCenter.x() > refPos.x())
|
||||
lastBefore = i;
|
||||
else
|
||||
break;
|
||||
}
|
||||
return lastBefore;
|
||||
}
|
||||
|
||||
void TierRow::cardResize(QSize newSize)
|
||||
{
|
||||
titleCard->setFixedSize(newSize);
|
||||
cardContainer->setMinimumHeight(newSize.height());
|
||||
cardContainer->updateGeometry();
|
||||
updateGeometry();
|
||||
Settings::get()->mainWindow()->updateGeometry();
|
||||
}
|
||||
|
||||
void TierRow::fadeChange(float newFade)
|
||||
{
|
||||
setColor(_color);
|
||||
}
|
||||
|
||||
int TierRow::cardCount() const
|
||||
{
|
||||
return cardLayout->count();
|
||||
}
|
||||
|
||||
21
tierrow.hpp
21
tierrow.hpp
@@ -4,10 +4,13 @@
|
||||
#include "tiercard.hpp"
|
||||
#include "tierrowtitlecard.hpp"
|
||||
#include "flowlayout.h"
|
||||
#include "tierplaceholder.hpp"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QDrag>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
class TierRow : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -18,31 +21,37 @@ public:
|
||||
~TierRow();
|
||||
void addCard(TierCard* card);
|
||||
TierCard* takeCard(uint32_t id);
|
||||
int cardCount() const;
|
||||
void setColor(QColor color);
|
||||
QColor color();
|
||||
QColor color() const;
|
||||
void setText(QString text);
|
||||
QString text();
|
||||
uint32_t id();
|
||||
QString text() const;
|
||||
uint32_t id() const;
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent* event) override;
|
||||
// void mousePressEvent(QMouseEvent* event) override;
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
void dragLeaveEvent(QDragLeaveEvent* event) override;
|
||||
void dragMoveEvent(QDragMoveEvent* event) override;
|
||||
|
||||
private:
|
||||
explicit TierRow(IdType id, QWidget* parent = nullptr);
|
||||
TierRowTitleCard* titleCard;
|
||||
QWidget* bgFadeContainer;
|
||||
QWidget* cardContainer;
|
||||
QLayout* cardLayout;
|
||||
FlowLayout* cardLayout;
|
||||
QColor _color;
|
||||
const IdType _id;
|
||||
TierPlaceholder* placeholder = nullptr;
|
||||
void recalcMaxHeight();
|
||||
void clearPlaceholder();
|
||||
int calculateIndex(QPointF loc);
|
||||
inline static std::unordered_map<IdType, TierRow*> idMap;
|
||||
|
||||
public slots:
|
||||
void cardResize(QRect newSize);
|
||||
void cardResize(QSize newSize);
|
||||
void fadeChange(float newFade);
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <QFrame>
|
||||
|
||||
TierRowTitleCard::TierRowTitleCard(IdType id, QWidget *parent)
|
||||
: QFrame{parent}
|
||||
: QFrame{parent}, _id(id)
|
||||
{
|
||||
this->setFrameStyle(QFrame::Box | QFrame::Plain);
|
||||
auto layout = new FullSizeLayout();
|
||||
@@ -38,5 +38,5 @@ void TierRowTitleCard::setColor(QColor color)
|
||||
|
||||
uint32_t TierRowTitleCard::id() const
|
||||
{
|
||||
return static_cast<uint32_t>(idLabel->text().toUInt());
|
||||
return _id;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ private:
|
||||
QColor _color;
|
||||
QLabel* titleLabel;
|
||||
QLabel* idLabel;
|
||||
const IdType _id;
|
||||
|
||||
signals:
|
||||
};
|
||||
|
||||
13
utils.hpp
13
utils.hpp
@@ -1,7 +1,7 @@
|
||||
#ifndef UTILS_HPP
|
||||
#define UTILS_HPP
|
||||
|
||||
#include "tierrow.hpp"
|
||||
// #include "tierrow.hpp"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QString>
|
||||
@@ -53,4 +53,15 @@ T* findParentOfType(QObject* obj)
|
||||
}
|
||||
}
|
||||
|
||||
inline QColor blend(QColor first, QColor second, float portionFirst)
|
||||
{
|
||||
const float& pf = portionFirst;
|
||||
const float ps = 1 - pf;
|
||||
return QColor(
|
||||
first.red()*pf + second.red()*ps,
|
||||
first.green()*pf + second.green()*ps,
|
||||
first.blue()*pf + second.blue()*ps
|
||||
);
|
||||
}
|
||||
|
||||
#endif // UTILS_HPP
|
||||
|
||||
Reference in New Issue
Block a user