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

UI DockWidgetTitleBar: Disable float and close buttons

Those buttons seems to only work with the MPV view for some strange
reasons (don't hover with other views), so disable them for all. Now the
'float' operation is done by double-clicking and the close is done with
the view menu.
parent eb3ac10b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!18Implement the VivyDocument specification
...@@ -14,51 +14,11 @@ DockWidgetTitleBar::DockWidgetTitleBar(QDockWidget *parent) noexcept ...@@ -14,51 +14,11 @@ DockWidgetTitleBar::DockWidgetTitleBar(QDockWidget *parent) noexcept
qobject_cast<QHBoxLayout *>(layout())->setStretch(0, 1); 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 void
DockWidgetTitleBar::addToDock(QDockWidget *const dock) noexcept DockWidgetTitleBar::addToDock(QDockWidget *const dock) noexcept
{ {
DockWidgetTitleBar *const titleBar = new DockWidgetTitleBar(dock); DockWidgetTitleBar *const titleBar = new DockWidgetTitleBar(dock);
qDebug() << "Adding" << dock->windowTitle() << "to dock...";
Utils::setTransparentBackgroundForWidget(titleBar); Utils::setTransparentBackgroundForWidget(titleBar);
connect(dock, &QDockWidget::featuresChanged, titleBar,
&DockWidgetTitleBar::handleFeaturesChanged);
dock->setTitleBarWidget(titleBar); dock->setTitleBarWidget(titleBar);
titleBar->handleFeaturesChanged(dock->features());
} }
...@@ -12,13 +12,7 @@ class DockWidgetTitleBar final : public QWidget { ...@@ -12,13 +12,7 @@ class DockWidgetTitleBar final : public QWidget {
VIVY_UNMOVABLE_OBJECT(DockWidgetTitleBar) VIVY_UNMOVABLE_OBJECT(DockWidgetTitleBar)
QDockWidget *attachedDock{ nullptr }; QDockWidget *attachedDock{ nullptr };
QDockWidget::DockWidgetFeature currentFeatures{ QDockWidget::NoDockWidgetFeatures };
explicit DockWidgetTitleBar(QDockWidget *parent) noexcept; explicit DockWidgetTitleBar(QDockWidget *parent) noexcept;
void handleFeaturesChanged(QDockWidget::DockWidgetFeatures) noexcept;
void clearControls() noexcept;
void addCloseButton() noexcept;
void addFloatButton() noexcept;
public: public:
static void addToDock(QDockWidget *const) noexcept; static void addToDock(QDockWidget *const) noexcept;
......
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