From 86e207514240920863aa1946f22075003afdfdf8 Mon Sep 17 00:00:00 2001 From: huxingyi Date: Sat, 12 Dec 2020 23:29:13 +0930 Subject: [PATCH] Add status bar tab buttons --- dust3d.pro | 3 ++ src/documentwindow.cpp | 41 ++++++++++++--- src/main.cpp | 2 +- src/statusbarlabel.cpp | 113 +++++++++++++++++++++++++++++++++++++++++ src/statusbarlabel.h | 38 ++++++++++++++ src/theme.cpp | 15 +++++- src/theme.h | 6 ++- 7 files changed, 207 insertions(+), 11 deletions(-) create mode 100644 src/statusbarlabel.cpp create mode 100644 src/statusbarlabel.h diff --git a/dust3d.pro b/dust3d.pro index 0ff700b9..32e6526f 100644 --- a/dust3d.pro +++ b/dust3d.pro @@ -535,6 +535,9 @@ HEADERS += src/ragdoll.h SOURCES += src/motionbuilder.cpp HEADERS += src/motionbuilder.h +SOURCES += src/statusbarlabel.cpp +HEADERS += src/statusbarlabel.h + SOURCES += src/main.cpp HEADERS += src/version.h diff --git a/src/documentwindow.cpp b/src/documentwindow.cpp index 129a750d..46c90747 100644 --- a/src/documentwindow.cpp +++ b/src/documentwindow.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "documentwindow.h" #include "skeletongraphicswidget.h" #include "theme.h" @@ -50,6 +51,7 @@ #include "documentsaver.h" #include "objectxml.h" #include "rigxml.h" +#include "statusbarlabel.h" int DocumentWindow::m_autoRecovered = false; @@ -325,12 +327,8 @@ DocumentWindow::DocumentWindow() : containerWidget->setLayout(containerLayout); containerWidget->setMinimumSize(400, 400); - { - QPalette palette = containerWidget->palette(); - palette.setColor(QPalette::Background, QColor(25, 25, 25)); - containerWidget->setAutoFillBackground(true); - containerWidget->setPalette(palette); - } + containerWidget->setAutoFillBackground(true); + containerWidget->setPalette(Theme::statusBarActivePalette); m_graphicsContainerWidget = containerWidget; @@ -501,17 +499,43 @@ DocumentWindow::DocumentWindow() : partsDocker->raise(); QWidget *titleBarWidget = new QWidget; - titleBarWidget->setFixedHeight(3); + titleBarWidget->setFixedHeight(1); QHBoxLayout *titleBarLayout = new QHBoxLayout; titleBarLayout->addStretch(); titleBarWidget->setLayout(titleBarLayout); + + /////////////////////// Status Bar Begin //////////////////////////// QWidget *statusBarWidget = new QWidget; - statusBarWidget->setFixedHeight(30); + statusBarWidget->setContentsMargins(0, 0, 0, 0); + + StatusBarLabel *boneLabel = new StatusBarLabel; + boneLabel->updateText(tr("Bone")); + + StatusBarLabel *shapeLabel = new StatusBarLabel; + shapeLabel->setSelected(true); + shapeLabel->updateText(tr("Shape")); + + connect(boneLabel, &StatusBarLabel::clicked, this, [=]() { + boneLabel->setSelected(true); + shapeLabel->setSelected(false); + // TODO: + }); + connect(shapeLabel, &StatusBarLabel::clicked, this, [=]() { + shapeLabel->setSelected(true); + boneLabel->setSelected(false); + // TODO: + }); + + /////////////////////// Status Bar End //////////////////////////// QHBoxLayout *statusBarLayout = new QHBoxLayout; + statusBarLayout->setSpacing(0); + statusBarLayout->setContentsMargins(0, 0, 0, 0); statusBarLayout->addStretch(); + statusBarLayout->addWidget(boneLabel); + statusBarLayout->addWidget(shapeLabel); statusBarWidget->setLayout(statusBarLayout); QVBoxLayout *canvasLayout = new QVBoxLayout; @@ -520,6 +544,7 @@ DocumentWindow::DocumentWindow() : canvasLayout->addWidget(titleBarWidget); canvasLayout->addWidget(containerWidget); canvasLayout->addWidget(statusBarWidget); + canvasLayout->setStretch(1, 1); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->setSpacing(0); diff --git a/src/main.cpp b/src/main.cpp index fd66e37b..4a90f537 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,7 +58,7 @@ int main(int argc, char ** argv) font.setBold(false); QApplication::setFont(font); - Theme::initAwsomeBaseSizes(); + Theme::initAwsome(); DocumentWindow *firstWindow = DocumentWindow::createDocumentWindow(); diff --git a/src/statusbarlabel.cpp b/src/statusbarlabel.cpp new file mode 100644 index 00000000..e3f4e66d --- /dev/null +++ b/src/statusbarlabel.cpp @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include "theme.h" +#include "statusbarlabel.h" + +StatusBarLabel::StatusBarLabel(QWidget *parent) : + QWidget(parent) +{ + setAttribute(Qt::WA_Hover); + + setAutoFillBackground(true); + + QFont font; + font.setWeight(QFont::Light); + font.setBold(false); + setFont(font); + + m_label = new QLabel; + + QGridLayout *mainLayout = new QGridLayout; + mainLayout->setSpacing(0); + mainLayout->setContentsMargins(15, 3, 15, 5); + mainLayout->addWidget(m_label); + + setLayout(mainLayout); + + updateBackground(); +} + +void StatusBarLabel::setSelected(bool selected) +{ + if (m_selected == selected) + return; + + m_selected = selected; + updateBackground(); +} + +void StatusBarLabel::updateText(const QString &text) +{ + m_label->setText(text); +} + +bool StatusBarLabel::event(QEvent *event) +{ + switch (event->type()) { + case QEvent::HoverEnter: { + hoverEnter(static_cast(event)); + return true; + } + break; + case QEvent::HoverLeave: { + hoverLeave(static_cast(event)); + return true; + } + break; + case QEvent::HoverMove: { + hoverMove(static_cast(event)); + return true; + } + break; + default: + break; + } + return QWidget::event(event); +} + +void StatusBarLabel::mousePressEvent(QMouseEvent *event) +{ + if (m_selected) + return; + + emit clicked(); +} + +void StatusBarLabel::enterEvent(QEvent *event) +{ +} + +void StatusBarLabel::leaveEvent(QEvent *event) +{ +} + + +void StatusBarLabel::hoverEnter(QHoverEvent *event) +{ + m_hovered = true; + updateBackground(); +} + +void StatusBarLabel::hoverLeave(QHoverEvent *event) +{ + m_hovered = false; + updateBackground(); +} + +void StatusBarLabel::hoverMove(QHoverEvent *event) +{ +} + +void StatusBarLabel::updateBackground() +{ + if (m_selected) { + setPalette(Theme::statusBarActivePalette); + } else if (m_hovered) { + setPalette(Theme::statusBarHoverPalette); + } else { + setPalette(Theme::statusBarNormalPalette); + } +} + diff --git a/src/statusbarlabel.h b/src/statusbarlabel.h new file mode 100644 index 00000000..ed30a001 --- /dev/null +++ b/src/statusbarlabel.h @@ -0,0 +1,38 @@ +#ifndef STATUS_BAR_LABEL_H +#define STATUS_BAR_LABEL_H +#include +#include +#include +#include +#include +#include + +class StatusBarLabel: public QWidget +{ + Q_OBJECT +signals: + void clicked(); +public: + explicit StatusBarLabel(QWidget *parent=0); + + void updateText(const QString &text); + void setSelected(bool selected); + +protected: + void mousePressEvent(QMouseEvent *event); + void enterEvent(QEvent *event); + void leaveEvent(QEvent *event); + bool event(QEvent *event); + void hoverEnter(QHoverEvent *event); + void hoverLeave(QHoverEvent *event); + void hoverMove(QHoverEvent *event); + +private: + QLabel *m_label = nullptr; + bool m_selected = false; + bool m_hovered = false; + + void updateBackground(); +}; + +#endif diff --git a/src/theme.cpp b/src/theme.cpp index 34c39ec2..6cc7ef9d 100644 --- a/src/theme.cpp +++ b/src/theme.cpp @@ -47,7 +47,11 @@ int Theme::motionPreviewImageSize = 0; int Theme::sidebarPreferredWidth = 0; int Theme::normalButtonSize = 0; -void Theme::initAwsomeBaseSizes() +QPalette Theme::statusBarActivePalette; +QPalette Theme::statusBarHoverPalette; +QPalette Theme::statusBarNormalPalette; + +void Theme::initAwsome() { QFontMetrics fontMetrics(QApplication::font()); Theme::toolIconFontSize = fontMetrics.height(); @@ -62,6 +66,15 @@ void Theme::initAwsomeBaseSizes() Theme::cutFacePreviewImageSize = Theme::posePreviewImageSize; Theme::motionPreviewImageSize = Theme::posePreviewImageSize; Theme::normalButtonSize = Theme::toolIconSize * 2; + + Theme::statusBarActivePalette.setColor(QPalette::Window, QColor(25, 25, 25)); + Theme::statusBarActivePalette.setColor(QPalette::WindowText, QColor(0x91, 0x91, 0x91)); + + Theme::statusBarHoverPalette.setColor(QPalette::Window, Theme::black); + Theme::statusBarHoverPalette.setColor(QPalette::WindowText, Qt::white); + + Theme::statusBarNormalPalette.setColor(QPalette::Window, Theme::black); + Theme::statusBarNormalPalette.setColor(QPalette::WindowText, QColor(0x91, 0x91, 0x91)); } QtAwesome *Theme::awesome() diff --git a/src/theme.h b/src/theme.h index c2a78d1e..60606608 100644 --- a/src/theme.h +++ b/src/theme.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "QtAwesome.h" class Theme @@ -44,6 +45,9 @@ public: static int miniIconSize; static int sidebarPreferredWidth; static int normalButtonSize; + static QPalette statusBarActivePalette; + static QPalette statusBarHoverPalette; + static QPalette statusBarNormalPalette; public: static void initAwesomeButton(QPushButton *button); static void initAwesomeLabel(QLabel *label); @@ -51,7 +55,7 @@ public: static void updateAwesomeMiniButton(QPushButton *button, QChar icon, bool highlighted, bool enabled, bool unnormal=false); static void initAwesomeToolButton(QPushButton *button); static void initAwesomeToolButtonWithoutFont(QPushButton *button); - static void initAwsomeBaseSizes(); + static void initAwsome(); static void initToolButton(QPushButton *button); static void initCheckbox(QCheckBox *checkbox); };