File: viewcontainer.cpp

package info (click to toggle)
khelpcenter 4%3A25.04.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,176 kB
  • sloc: cpp: 6,271; xml: 394; python: 51; perl: 25; makefile: 5; sh: 3
file content (72 lines) | stat: -rw-r--r-- 1,558 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
    SPDX-FileCopyrightText: 2024 Friedrich W. H. Kossebau <kossebau@kde.org>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "viewcontainer.h"

#include <QShortcut>
#include <QVBoxLayout>

namespace KHC
{

ViewContainer::ViewContainer(QWidget *parentWidget)
    : QWidget(parentWidget)
{
    auto *l = new QVBoxLayout(this);
    l->setContentsMargins(0, 0, 0, 0);
    l->setSpacing(0);

    auto *closeBottomBarShortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this);
    closeBottomBarShortcut->setContext(Qt::WidgetWithChildrenShortcut);
    connect(closeBottomBarShortcut, &QShortcut::activated, this, &ViewContainer::hideBottomBar);
}

void ViewContainer::setView(QWidget *view)
{
    auto *l = static_cast<QVBoxLayout *>(layout());
    if (m_view) {
        l->removeWidget(m_view.data());
    }
    m_view = view;
    if (m_view) {
        // insert at start, stretching
        l->insertWidget(0, m_view.data(), 1);
    }
}

void ViewContainer::setBottomBar(QWidget *bottomBar)
{
    auto *l = static_cast<QVBoxLayout *>(layout());
    if (m_bottomBar) {
        l->removeWidget(m_bottomBar.data());
    }
    m_bottomBar = bottomBar;
    if (m_bottomBar) {
        // append without stretch facror
        l->addWidget(m_bottomBar.data());
    }
}

void ViewContainer::hideBottomBar()
{
    if (m_bottomBar) {
        m_bottomBar->hide();
    }
}

QWidget *ViewContainer::view() const
{
    return m_view.data();
}

QWidget *ViewContainer::bottomBar() const
{
    return m_bottomBar.data();
}

}

#include "moc_viewcontainer.cpp"