Refactoring.
This commit is contained in:
parent
5adcdb9b67
commit
4b985b4ecc
|
@ -33,20 +33,14 @@
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
FancyTab::FancyTab(QWidget *tabbar)
|
FancyTab::FancyTab(QWidget *tabbar)
|
||||||
: m_icon(),
|
: m_TabBar(tabbar)
|
||||||
m_text(),
|
|
||||||
m_toolTip(),
|
|
||||||
m_enabled(false),
|
|
||||||
m_Animator(),
|
|
||||||
m_TabBar(tabbar),
|
|
||||||
m_Fader(0)
|
|
||||||
{
|
{
|
||||||
m_Animator.setPropertyName("fader");
|
m_Animator.setPropertyName("fader");
|
||||||
m_Animator.setTargetObject(this);
|
m_Animator.setTargetObject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
auto FancyTab::fader() -> double
|
auto FancyTab::fader() const -> double
|
||||||
{
|
{
|
||||||
return m_Fader;
|
return m_Fader;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,9 @@ class FancyTab final : public QObject
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FancyTab(QWidget *tabbar);
|
explicit FancyTab(QWidget *tabbar);
|
||||||
|
~FancyTab() override = default;
|
||||||
|
|
||||||
auto fader() -> double;
|
auto fader() const -> double;
|
||||||
void setFader(double value);
|
void setFader(double value);
|
||||||
|
|
||||||
void fadeIn();
|
void fadeIn();
|
||||||
|
@ -52,13 +53,13 @@ public:
|
||||||
private:
|
private:
|
||||||
// cppcheck-suppress unknownMacro
|
// cppcheck-suppress unknownMacro
|
||||||
Q_DISABLE_COPY_MOVE(FancyTab) // NOLINT
|
Q_DISABLE_COPY_MOVE(FancyTab) // NOLINT
|
||||||
QIcon m_icon;
|
QIcon m_icon{};
|
||||||
QString m_text;
|
QString m_text{};
|
||||||
QString m_toolTip;
|
QString m_toolTip{};
|
||||||
bool m_enabled;
|
bool m_enabled{false};
|
||||||
QPropertyAnimation m_Animator;
|
QPropertyAnimation m_Animator{};
|
||||||
QWidget *m_TabBar;
|
QWidget *m_TabBar;
|
||||||
double m_Fader;
|
double m_Fader{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FANCYTAB_H
|
#endif // FANCYTAB_H
|
||||||
|
|
|
@ -42,14 +42,9 @@ using namespace Qt::Literals::StringLiterals;
|
||||||
const int FancyTabBar::m_rounding = 22;
|
const int FancyTabBar::m_rounding = 22;
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
FancyTabBar::FancyTabBar(const TabBarPosition position, QWidget *parent)
|
FancyTabBar::FancyTabBar(TabBarPosition position, QWidget *parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
m_position(position),
|
m_position(position)
|
||||||
m_hoverRect(),
|
|
||||||
m_hoverIndex(-1),
|
|
||||||
m_currentIndex(-1),
|
|
||||||
m_attachedTabs(),
|
|
||||||
m_timerTriggerChangedSignal()
|
|
||||||
{
|
{
|
||||||
if (m_position == FancyTabBar::Above || m_position == FancyTabBar::Below)
|
if (m_position == FancyTabBar::Above || m_position == FancyTabBar::Below)
|
||||||
{
|
{
|
||||||
|
@ -115,11 +110,11 @@ auto FancyTabBar::TabSizeHint(bool minimum) const -> QSize
|
||||||
int const width = 60 + spacing + 2;
|
int const width = 60 + spacing + 2;
|
||||||
int const iconHeight = minimum ? 0 : 32;
|
int const iconHeight = minimum ? 0 : 32;
|
||||||
|
|
||||||
return QSize(qMax(width, maxLabelwidth + 4), iconHeight + spacing + fm.height());
|
return {qMax(width, maxLabelwidth + 4), iconHeight + spacing + fm.height()};
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
auto FancyTabBar::GetCorner(const QRect &rect, const Corner corner) const -> QPoint
|
auto FancyTabBar::GetCorner(const QRect &rect, Corner corner) const -> QPoint
|
||||||
{
|
{
|
||||||
switch (m_position)
|
switch (m_position)
|
||||||
{
|
{
|
||||||
|
@ -189,7 +184,7 @@ auto FancyTabBar::GetCorner(const QRect &rect, const Corner corner) const -> QPo
|
||||||
|
|
||||||
qFatal("that's impossible!");
|
qFatal("that's impossible!");
|
||||||
|
|
||||||
return QPoint();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -201,8 +196,8 @@ auto FancyTabBar::GetCorner(const QRect &rect, const Corner corner) const -> QPo
|
||||||
// gives
|
// gives
|
||||||
//
|
//
|
||||||
// QRect(-3, -1, 9, 13) // 9 by 13 rect, starting at -3/-1.
|
// QRect(-3, -1, 9, 13) // 9 by 13 rect, starting at -3/-1.
|
||||||
auto FancyTabBar::AdjustRect(const QRect &rect, const qint8 offsetOutside, const qint8 offsetInside,
|
auto FancyTabBar::AdjustRect(const QRect &rect, qint8 offsetOutside, qint8 offsetInside, qint8 offsetBeginning,
|
||||||
const qint8 offsetBeginning, const qint8 offsetEnd) const -> QRect
|
qint8 offsetEnd) const -> QRect
|
||||||
{
|
{
|
||||||
switch (m_position)
|
switch (m_position)
|
||||||
{
|
{
|
||||||
|
@ -219,13 +214,12 @@ auto FancyTabBar::AdjustRect(const QRect &rect, const qint8 offsetOutside, const
|
||||||
}
|
}
|
||||||
|
|
||||||
qFatal("that's impossible!");
|
qFatal("that's impossible!");
|
||||||
return QRect();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
// Same with a point: + means towards Outside/End, - means towards Inside/Beginning
|
// Same with a point: + means towards Outside/End, - means towards Inside/Beginning
|
||||||
auto FancyTabBar::AdjustPoint(const QPoint &point, const qint8 offsetInsideOutside,
|
auto FancyTabBar::AdjustPoint(const QPoint &point, qint8 offsetInsideOutside, qint8 offsetBeginningEnd) const -> QPoint
|
||||||
const qint8 offsetBeginningEnd) const -> QPoint
|
|
||||||
{
|
{
|
||||||
switch (m_position)
|
switch (m_position)
|
||||||
{
|
{
|
||||||
|
@ -242,7 +236,7 @@ auto FancyTabBar::AdjustPoint(const QPoint &point, const qint8 offsetInsideOutsi
|
||||||
}
|
}
|
||||||
|
|
||||||
qFatal("that's impossible!");
|
qFatal("that's impossible!");
|
||||||
return QPoint();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -370,7 +364,7 @@ auto FancyTabBar::ValidIndex(int index) const -> bool
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void FancyTabBar::SetOrientation(const FancyTabBar::TabBarPosition p)
|
void FancyTabBar::SetOrientation(TabBarPosition p)
|
||||||
{
|
{
|
||||||
m_position = p;
|
m_position = p;
|
||||||
}
|
}
|
||||||
|
@ -383,10 +377,10 @@ auto FancyTabBar::sizeHint() const -> QSize
|
||||||
|
|
||||||
if (m_position == Above || m_position == Below)
|
if (m_position == Above || m_position == Below)
|
||||||
{
|
{
|
||||||
return QSize(sh.width() * static_cast<int>(m_attachedTabs.count()), sh.height());
|
return {sh.width() * static_cast<int>(m_attachedTabs.count()), sh.height()};
|
||||||
}
|
}
|
||||||
|
|
||||||
return QSize(sh.width(), sh.height() * static_cast<int>(m_attachedTabs.count()));
|
return {sh.width(), sh.height() * static_cast<int>(m_attachedTabs.count())};
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -397,10 +391,10 @@ auto FancyTabBar::minimumSizeHint() const -> QSize
|
||||||
|
|
||||||
if (m_position == Above || m_position == Below)
|
if (m_position == Above || m_position == Below)
|
||||||
{
|
{
|
||||||
return QSize(sh.width() * static_cast<int>(m_attachedTabs.count()), sh.height());
|
return {sh.width() * static_cast<int>(m_attachedTabs.count()), sh.height()};
|
||||||
}
|
}
|
||||||
|
|
||||||
return QSize(sh.width(), sh.height() * static_cast<int>(m_attachedTabs.count()));
|
return {sh.width(), sh.height() * static_cast<int>(m_attachedTabs.count())};
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -415,17 +409,15 @@ auto FancyTabBar::TabRect(int index) const -> QRect
|
||||||
sh.setWidth(width() / static_cast<int>(m_attachedTabs.count()));
|
sh.setWidth(width() / static_cast<int>(m_attachedTabs.count()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return QRect(index * sh.width(), 0, sh.width(), sh.height());
|
return {index * sh.width(), 0, sh.width(), sh.height()};
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if (sh.height() * m_attachedTabs.count() > height())
|
|
||||||
{
|
|
||||||
sh.setHeight(height() / static_cast<int>(m_attachedTabs.count()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return QRect(0, index * sh.height(), sh.width(), sh.height());
|
if (sh.height() * m_attachedTabs.count() > height())
|
||||||
|
{
|
||||||
|
sh.setHeight(height() / static_cast<int>(m_attachedTabs.count()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {0, index * sh.height(), sh.width(), sh.height()};
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -536,7 +528,7 @@ void FancyTabBar::PaintTab(QPainter *painter, int tabIndex) const
|
||||||
if (!selected && enabled)
|
if (!selected && enabled)
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
int const fader = int(m_attachedTabs[tabIndex]->fader());
|
int const fader = static_cast<int>(m_attachedTabs[tabIndex]->fader());
|
||||||
QLinearGradient grad(GetCorner(rect, OutsideBeginning), GetCorner(rect, InsideBeginning));
|
QLinearGradient grad(GetCorner(rect, OutsideBeginning), GetCorner(rect, InsideBeginning));
|
||||||
|
|
||||||
grad.setColorAt(0, Qt::transparent);
|
grad.setColorAt(0, Qt::transparent);
|
||||||
|
|
|
@ -53,13 +53,13 @@ public:
|
||||||
Right
|
Right
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit FancyTabBar(const TabBarPosition position, QWidget *parent = nullptr);
|
explicit FancyTabBar(TabBarPosition position, QWidget *parent = nullptr);
|
||||||
virtual ~FancyTabBar() = default;
|
~FancyTabBar() override = default;
|
||||||
|
|
||||||
virtual auto sizeHint() const -> QSize override;
|
auto sizeHint() const -> QSize override;
|
||||||
virtual auto minimumSizeHint() const -> QSize override;
|
auto minimumSizeHint() const -> QSize override;
|
||||||
|
|
||||||
void SetOrientation(const TabBarPosition p);
|
void SetOrientation(TabBarPosition p);
|
||||||
|
|
||||||
void SetTabEnabled(int index, bool enable);
|
void SetTabEnabled(int index, bool enable);
|
||||||
auto IsTabEnabled(int index) const -> bool;
|
auto IsTabEnabled(int index) const -> bool;
|
||||||
|
@ -85,16 +85,16 @@ signals:
|
||||||
void CurrentChanged(int);
|
void CurrentChanged(int);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual auto event(QEvent *event) -> bool override;
|
auto event(QEvent *event) -> bool override;
|
||||||
virtual void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
virtual void mousePressEvent(QMouseEvent *) override;
|
void mousePressEvent(QMouseEvent *e) override;
|
||||||
virtual void mouseMoveEvent(QMouseEvent *) override;
|
void mouseMoveEvent(QMouseEvent *e) override;
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
virtual void enterEvent(QEnterEvent *) override;
|
void enterEvent(QEnterEvent *e) override;
|
||||||
#else
|
#else
|
||||||
virtual void enterEvent(QEvent *) override;
|
void enterEvent(QEvent *e) override;
|
||||||
#endif
|
#endif
|
||||||
virtual void leaveEvent(QEvent *) override;
|
void leaveEvent(QEvent *e) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void EmitCurrentIndex();
|
void EmitCurrentIndex();
|
||||||
|
@ -113,20 +113,19 @@ private:
|
||||||
static const int m_rounding;
|
static const int m_rounding;
|
||||||
|
|
||||||
TabBarPosition m_position;
|
TabBarPosition m_position;
|
||||||
QRect m_hoverRect;
|
QRect m_hoverRect{};
|
||||||
int m_hoverIndex;
|
int m_hoverIndex{-1};
|
||||||
int m_currentIndex;
|
int m_currentIndex{-1};
|
||||||
QList<FancyTab *> m_attachedTabs;
|
QList<FancyTab *> m_attachedTabs{};
|
||||||
QTimer m_timerTriggerChangedSignal;
|
QTimer m_timerTriggerChangedSignal{};
|
||||||
|
|
||||||
auto GetCorner(const QRect &rect, const Corner corner) const -> QPoint;
|
auto GetCorner(const QRect &rect, Corner corner) const -> QPoint;
|
||||||
|
|
||||||
auto AdjustRect(const QRect &rect, const qint8 offsetOutside, const qint8 offsetInside, const qint8 offsetBeginning,
|
auto AdjustRect(const QRect &rect, qint8 offsetOutside, qint8 offsetInside, qint8 offsetBeginning,
|
||||||
const qint8 offsetEnd) const -> QRect;
|
qint8 offsetEnd) const -> QRect;
|
||||||
|
|
||||||
// Same with a point. + means towards Outside/End, - means towards Inside/Beginning
|
// Same with a point. + means towards Outside/End, - means towards Inside/Beginning
|
||||||
auto AdjustPoint(const QPoint &point, const qint8 offsetInsideOutside, const qint8 offsetBeginningEnd) const
|
auto AdjustPoint(const QPoint &point, qint8 offsetInsideOutside, qint8 offsetBeginningEnd) const -> QPoint;
|
||||||
-> QPoint;
|
|
||||||
|
|
||||||
auto TabSizeHint(bool minimum = false) const -> QSize;
|
auto TabSizeHint(bool minimum = false) const -> QSize;
|
||||||
void PaintTab(QPainter *painter, int tabIndex) const;
|
void PaintTab(QPainter *painter, int tabIndex) const;
|
||||||
|
|
|
@ -39,6 +39,12 @@
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
QColor m_baseColor;
|
||||||
|
QColor m_requestedBaseColor;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
auto StyleHelper::sidebarFontSize() -> qreal
|
auto StyleHelper::sidebarFontSize() -> qreal
|
||||||
{
|
{
|
||||||
|
@ -61,11 +67,6 @@ auto StyleHelper::panelTextColor(bool lightColored) -> QColor
|
||||||
return Qt::black;
|
return Qt::black;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Invalid by default, setBaseColor needs to be called at least once
|
|
||||||
QColor StyleHelper::m_baseColor;
|
|
||||||
QColor StyleHelper::m_requestedBaseColor;
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
auto StyleHelper::baseColor(bool lightColored) -> QColor
|
auto StyleHelper::baseColor(bool lightColored) -> QColor
|
||||||
{
|
{
|
||||||
|
@ -88,7 +89,7 @@ auto StyleHelper::borderColor(bool lightColored) -> QColor
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
auto StyleHelper::sidebarHighlight() -> QColor
|
auto StyleHelper::sidebarHighlight() -> QColor
|
||||||
{
|
{
|
||||||
return QColor(255, 255, 255, 40);
|
return {255, 255, 255, 40};
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -59,10 +59,6 @@ public:
|
||||||
static void drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode,
|
static void drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode,
|
||||||
int dipRadius = 3, const QColor &color = QColor(0, 0, 0, 130),
|
int dipRadius = 3, const QColor &color = QColor(0, 0, 0, 130),
|
||||||
const QPoint &dipOffset = QPoint(1, -2));
|
const QPoint &dipOffset = QPoint(1, -2));
|
||||||
|
|
||||||
private:
|
|
||||||
static QColor m_baseColor;
|
|
||||||
static QColor m_requestedBaseColor;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // STYLEHELPER_H
|
#endif // STYLEHELPER_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user