Add status bar tab buttons

master
huxingyi 2020-12-12 23:29:13 +09:30
parent 84cd377b52
commit 86e2075142
7 changed files with 207 additions and 11 deletions

View File

@ -535,6 +535,9 @@ HEADERS += src/ragdoll.h
SOURCES += src/motionbuilder.cpp SOURCES += src/motionbuilder.cpp
HEADERS += src/motionbuilder.h HEADERS += src/motionbuilder.h
SOURCES += src/statusbarlabel.cpp
HEADERS += src/statusbarlabel.h
SOURCES += src/main.cpp SOURCES += src/main.cpp
HEADERS += src/version.h HEADERS += src/version.h

View File

@ -20,6 +20,7 @@
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <qtsingleapplication.h> #include <qtsingleapplication.h>
#include <QFormLayout>
#include "documentwindow.h" #include "documentwindow.h"
#include "skeletongraphicswidget.h" #include "skeletongraphicswidget.h"
#include "theme.h" #include "theme.h"
@ -50,6 +51,7 @@
#include "documentsaver.h" #include "documentsaver.h"
#include "objectxml.h" #include "objectxml.h"
#include "rigxml.h" #include "rigxml.h"
#include "statusbarlabel.h"
int DocumentWindow::m_autoRecovered = false; int DocumentWindow::m_autoRecovered = false;
@ -325,12 +327,8 @@ DocumentWindow::DocumentWindow() :
containerWidget->setLayout(containerLayout); containerWidget->setLayout(containerLayout);
containerWidget->setMinimumSize(400, 400); containerWidget->setMinimumSize(400, 400);
{
QPalette palette = containerWidget->palette();
palette.setColor(QPalette::Background, QColor(25, 25, 25));
containerWidget->setAutoFillBackground(true); containerWidget->setAutoFillBackground(true);
containerWidget->setPalette(palette); containerWidget->setPalette(Theme::statusBarActivePalette);
}
m_graphicsContainerWidget = containerWidget; m_graphicsContainerWidget = containerWidget;
@ -501,17 +499,43 @@ DocumentWindow::DocumentWindow() :
partsDocker->raise(); partsDocker->raise();
QWidget *titleBarWidget = new QWidget; QWidget *titleBarWidget = new QWidget;
titleBarWidget->setFixedHeight(3); titleBarWidget->setFixedHeight(1);
QHBoxLayout *titleBarLayout = new QHBoxLayout; QHBoxLayout *titleBarLayout = new QHBoxLayout;
titleBarLayout->addStretch(); titleBarLayout->addStretch();
titleBarWidget->setLayout(titleBarLayout); titleBarWidget->setLayout(titleBarLayout);
/////////////////////// Status Bar Begin ////////////////////////////
QWidget *statusBarWidget = new QWidget; 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; QHBoxLayout *statusBarLayout = new QHBoxLayout;
statusBarLayout->setSpacing(0);
statusBarLayout->setContentsMargins(0, 0, 0, 0);
statusBarLayout->addStretch(); statusBarLayout->addStretch();
statusBarLayout->addWidget(boneLabel);
statusBarLayout->addWidget(shapeLabel);
statusBarWidget->setLayout(statusBarLayout); statusBarWidget->setLayout(statusBarLayout);
QVBoxLayout *canvasLayout = new QVBoxLayout; QVBoxLayout *canvasLayout = new QVBoxLayout;
@ -520,6 +544,7 @@ DocumentWindow::DocumentWindow() :
canvasLayout->addWidget(titleBarWidget); canvasLayout->addWidget(titleBarWidget);
canvasLayout->addWidget(containerWidget); canvasLayout->addWidget(containerWidget);
canvasLayout->addWidget(statusBarWidget); canvasLayout->addWidget(statusBarWidget);
canvasLayout->setStretch(1, 1);
QHBoxLayout *mainLayout = new QHBoxLayout; QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->setSpacing(0); mainLayout->setSpacing(0);

View File

@ -58,7 +58,7 @@ int main(int argc, char ** argv)
font.setBold(false); font.setBold(false);
QApplication::setFont(font); QApplication::setFont(font);
Theme::initAwsomeBaseSizes(); Theme::initAwsome();
DocumentWindow *firstWindow = DocumentWindow::createDocumentWindow(); DocumentWindow *firstWindow = DocumentWindow::createDocumentWindow();

113
src/statusbarlabel.cpp Normal file
View File

@ -0,0 +1,113 @@
#include <QDebug>
#include <QPalette>
#include <QFont>
#include <QGridLayout>
#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<QHoverEvent*>(event));
return true;
}
break;
case QEvent::HoverLeave: {
hoverLeave(static_cast<QHoverEvent*>(event));
return true;
}
break;
case QEvent::HoverMove: {
hoverMove(static_cast<QHoverEvent*>(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);
}
}

38
src/statusbarlabel.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef STATUS_BAR_LABEL_H
#define STATUS_BAR_LABEL_H
#include <QWidget>
#include <QLabel>
#include <QEvent>
#include <QHoverEvent>
#include <QString>
#include <QMouseEvent>
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

View File

@ -47,7 +47,11 @@ int Theme::motionPreviewImageSize = 0;
int Theme::sidebarPreferredWidth = 0; int Theme::sidebarPreferredWidth = 0;
int Theme::normalButtonSize = 0; int Theme::normalButtonSize = 0;
void Theme::initAwsomeBaseSizes() QPalette Theme::statusBarActivePalette;
QPalette Theme::statusBarHoverPalette;
QPalette Theme::statusBarNormalPalette;
void Theme::initAwsome()
{ {
QFontMetrics fontMetrics(QApplication::font()); QFontMetrics fontMetrics(QApplication::font());
Theme::toolIconFontSize = fontMetrics.height(); Theme::toolIconFontSize = fontMetrics.height();
@ -62,6 +66,15 @@ void Theme::initAwsomeBaseSizes()
Theme::cutFacePreviewImageSize = Theme::posePreviewImageSize; Theme::cutFacePreviewImageSize = Theme::posePreviewImageSize;
Theme::motionPreviewImageSize = Theme::posePreviewImageSize; Theme::motionPreviewImageSize = Theme::posePreviewImageSize;
Theme::normalButtonSize = Theme::toolIconSize * 2; 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() QtAwesome *Theme::awesome()

View File

@ -6,6 +6,7 @@
#include <QPushButton> #include <QPushButton>
#include <QLabel> #include <QLabel>
#include <QCheckBox> #include <QCheckBox>
#include <QPalette>
#include "QtAwesome.h" #include "QtAwesome.h"
class Theme class Theme
@ -44,6 +45,9 @@ public:
static int miniIconSize; static int miniIconSize;
static int sidebarPreferredWidth; static int sidebarPreferredWidth;
static int normalButtonSize; static int normalButtonSize;
static QPalette statusBarActivePalette;
static QPalette statusBarHoverPalette;
static QPalette statusBarNormalPalette;
public: public:
static void initAwesomeButton(QPushButton *button); static void initAwesomeButton(QPushButton *button);
static void initAwesomeLabel(QLabel *label); 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 updateAwesomeMiniButton(QPushButton *button, QChar icon, bool highlighted, bool enabled, bool unnormal=false);
static void initAwesomeToolButton(QPushButton *button); static void initAwesomeToolButton(QPushButton *button);
static void initAwesomeToolButtonWithoutFont(QPushButton *button); static void initAwesomeToolButtonWithoutFont(QPushButton *button);
static void initAwsomeBaseSizes(); static void initAwsome();
static void initToolButton(QPushButton *button); static void initToolButton(QPushButton *button);
static void initCheckbox(QCheckBox *checkbox); static void initCheckbox(QCheckBox *checkbox);
}; };