Skip to content
Extraits de code Groupes Projets
Vérifiée Valider dc860b69 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

UI: Add clean title bars for dock widgets (transparent to avoid some ugly spaces on the right side)

parent b3cab52d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!18Implement the VivyDocument specification
#include "DockWidgetTitleBar.hh"
#include <QLabel>
#include <QHBoxLayout>
#include <QPushButton>
using namespace Vivy;
DockWidgetTitleBar::DockWidgetTitleBar(QDockWidget *parent) noexcept
: QWidget(parent)
, attachedDock(parent)
{
if (parent == nullptr)
qFatal("Can't pass a nullptr as a parent widget pointer");
auto *box = new QHBoxLayout(this);
box->addWidget(new QLabel(parent->windowTitle(), this));
qobject_cast<QHBoxLayout *>(layout())->setStretch(0, 1);
}
void
DockWidgetTitleBar::handleFeaturesChanged(QDockWidget::DockWidgetFeatures feature) noexcept
{
clearControls();
if (feature & QDockWidget::DockWidgetFloatable) {
QPushButton *const button = new QPushButton("float", this);
button->setEnabled(true);
connect(button, &QPushButton::clicked, attachedDock,
[this](bool) { attachedDock->setFloating(!attachedDock->isFloating()); });
layout()->addWidget(button);
}
if (feature & QDockWidget::DockWidgetClosable) {
QPushButton *const button = new QPushButton("close", this);
button->setEnabled(true);
connect(button, &QPushButton::clicked, attachedDock, [this](bool) {
QAction *const act = attachedDock->toggleViewAction();
Q_ASSERT(act->isCheckable());
act->trigger();
});
layout()->addWidget(button);
}
}
void
DockWidgetTitleBar::clearControls() noexcept
{
QHBoxLayout *const box = qobject_cast<QHBoxLayout *>(layout());
QLayoutItem *item = nullptr;
for (int i = 1; i < box->count(); ++i) {
item = box->takeAt(i);
delete item->widget();
delete item;
}
}
void
DockWidgetTitleBar::addToDock(QDockWidget *const dock) noexcept
{
DockWidgetTitleBar *const titleBar = new DockWidgetTitleBar(dock);
Utils::setTransparentBackgroundForWidget(titleBar);
connect(dock, &QDockWidget::featuresChanged, titleBar,
&DockWidgetTitleBar::handleFeaturesChanged);
dock->setTitleBarWidget(titleBar);
titleBar->handleFeaturesChanged(dock->features());
}
#pragma once
#include "Utils.hh"
#include "../Lib/Utils.hh"
class QDockWidget;
namespace Vivy
{
class DockWidgetTitleBar final : public QWidget {
Q_OBJECT
VIVY_UNMOVABLE_OBJECT(DockWidgetTitleBar)
QDockWidget *attachedDock{ nullptr };
QDockWidget::DockWidgetFeature currentFeatures{ QDockWidget::NoDockWidgetFeatures };
explicit DockWidgetTitleBar(QDockWidget *parent) noexcept;
void handleFeaturesChanged(QDockWidget::DockWidgetFeatures) noexcept;
void clearControls() noexcept;
void addCloseButton() noexcept;
void addFloatButton() noexcept;
public:
static void addToDock(QDockWidget *const) noexcept;
};
}
#include "VivyDocumentView.hh" #include "VivyDocumentView.hh"
#include "PropertyModel.hh" #include "PropertyModel.hh"
#include "DockWidgetTitleBar.hh"
#include "Utils.hh" #include "Utils.hh"
#include "DocumentViews/AudioVisualizer.hh" #include "DocumentViews/AudioVisualizer.hh"
#include "DocumentViews/AssLinesView.hh" #include "DocumentViews/AssLinesView.hh"
...@@ -92,8 +93,7 @@ VivyDocumentView::loadVideoView() noexcept ...@@ -92,8 +93,7 @@ VivyDocumentView::loadVideoView() noexcept
QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetFloatable |
QDockWidget::DockWidgetClosable); QDockWidget::DockWidgetClosable);
addDockWidget(Qt::BottomDockWidgetArea, videoView, Qt::Vertical); addDockWidget(Qt::BottomDockWidgetArea, videoView, Qt::Vertical);
videoView->setTitleBarWidget(new QWidget(this)); DockWidgetTitleBar::addToDock(videoView);
Utils::setTransparentBackgroundForWidget(videoView->titleBarWidget());
} }
// Kubat: because the dock is "closable", when closed the widget itself // Kubat: because the dock is "closable", when closed the widget itself
...@@ -115,8 +115,7 @@ VivyDocumentView::loadAssView() noexcept ...@@ -115,8 +115,7 @@ VivyDocumentView::loadAssView() noexcept
assLines->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | assLines->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea |
Qt::BottomDockWidgetArea); Qt::BottomDockWidgetArea);
addDockWidget(Qt::BottomDockWidgetArea, assLines, Qt::Vertical); addDockWidget(Qt::BottomDockWidgetArea, assLines, Qt::Vertical);
assLines->setTitleBarWidget(new QWidget(this)); DockWidgetTitleBar::addToDock(assLines);
Utils::setTransparentBackgroundForWidget(assLines->titleBarWidget());
} }
assModel.reset(new AssLinesModel(document->getAssSubDocument()->getLines())); assModel.reset(new AssLinesModel(document->getAssSubDocument()->getLines()));
...@@ -147,8 +146,7 @@ VivyDocumentView::loadAudioView() noexcept ...@@ -147,8 +146,7 @@ VivyDocumentView::loadAudioView() noexcept
visualizer->setFeatures(QDockWidget::DockWidgetMovable | visualizer->setFeatures(QDockWidget::DockWidgetMovable |
QDockWidget::DockWidgetClosable); QDockWidget::DockWidgetClosable);
addDockWidget(Qt::LeftDockWidgetArea, visualizer, Qt::Horizontal); addDockWidget(Qt::LeftDockWidgetArea, visualizer, Qt::Horizontal);
visualizer->setTitleBarWidget(new QWidget(this)); DockWidgetTitleBar::addToDock(visualizer);
Utils::setTransparentBackgroundForWidget(visualizer->titleBarWidget());
} }
// Kubat: don't check, may throw an error but don't think we can // Kubat: don't check, may throw an error but don't think we can
...@@ -196,8 +194,7 @@ VivyDocumentView::openProperties() noexcept ...@@ -196,8 +194,7 @@ VivyDocumentView::openProperties() noexcept
property = new QDockWidget("Properties", this); property = new QDockWidget("Properties", this);
property->setAllowedAreas(Qt::AllDockWidgetAreas); property->setAllowedAreas(Qt::AllDockWidgetAreas);
addDockWidget(Qt::RightDockWidgetArea, property, Qt::Vertical); addDockWidget(Qt::RightDockWidgetArea, property, Qt::Vertical);
property->setTitleBarWidget(new QWidget(this)); DockWidgetTitleBar::addToDock(property);
Utils::setTransparentBackgroundForWidget(property->titleBarWidget());
} }
property->setWidget(view); property->setWidget(view);
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter