KDDockWidgets API Documentation 1.7
Loading...
Searching...
No Matches
TabBarQuick.cpp
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2019-2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5 Author: SĂ©rgio Martins <sergio.martins@kdab.com>
6
7 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
8
9 Contact KDAB at <info@kdab.com> for commercial licensing options.
10*/
11
20#include "TabBarQuick_p.h"
21
22#include <QMetaObject>
23#include <QMouseEvent>
24
25using namespace KDDockWidgets;
26
27TabBarQuick::TabBarQuick(TabWidget *parent)
28 : QWidgetAdapter(parent->asWidget())
29 , TabBar(this, parent)
30{
31}
32
33int TabBarQuick::tabAt(QPoint p) const
34{
35 // QtQuick's TabBar doesn't provide any API for this.
36 // So ask its *internal* ListView instead.
37
38 if (!m_tabBarQmlItem) {
39 qWarning() << Q_FUNC_INFO << "No visual tab bar item yet";
40 return -1;
41 }
42
43 if (QQuickItem *internalListView = listView()) {
44 int index = -1;
45 QMetaObject::invokeMethod(internalListView, "indexAt", Q_RETURN_ARG(int, index),
46 Q_ARG(double, p.x()), Q_ARG(double, p.y()));
47
48 return index;
49 } else {
50 qWarning() << Q_FUNC_INFO << "Couldn't find the internal ListView";
51 }
52
53 return -1;
54}
55
56QQuickItem *TabBarQuick::tabBarQmlItem() const
57{
58 return m_tabBarQmlItem;
59}
60
61void TabBarQuick::setTabBarQmlItem(QQuickItem *item)
62{
63 m_tabBarQmlItem = item;
64}
65
66QString TabBarQuick::text(int index) const
67{
68 if (QQuickItem *item = tabAt(index))
69 return item->property("text").toString();
70
71 return {};
72}
73
74QRect TabBarQuick::rectForTab(int index) const
75{
76 if (QQuickItem *item = tabAt(index))
77 return item->boundingRect().toRect();
78
79 return {};
80}
81
82bool TabBarQuick::event(QEvent *ev)
83{
84 switch (ev->type()) {
87 if (m_tabBarQmlItem) {
88 auto me = static_cast<QMouseEvent *>(ev);
89 m_tabBarQmlItem->setProperty("currentIndex", tabAt(me->pos()));
90 if (ev->type() == QEvent::MouseButtonPress)
91 TabBar::onMousePress(me->pos());
92 else
93 TabBar::onMouseDoubleClick(me->pos());
94 }
95
96 break;
97 }
98 default:
99 break;
100 }
101
102 return QWidgetAdapter::event(ev);
103}
104
105QQuickItem *TabBarQuick::tabAt(int index) const
106{
107 QQuickItem *view = listView();
108 if (!view)
109 return nullptr;
110
111 QQuickItem *item = nullptr;
112 QMetaObject::invokeMethod(view, "itemAtIndex", Q_RETURN_ARG(QQuickItem *, item),
113 Q_ARG(int, index));
114
115 return item;
116}
117
118QQuickItem *TabBarQuick::listView() const
119{
120 // Returns the internal ListView of the TabBar
121
122 if (!m_tabBarQmlItem)
123 return nullptr;
124
125 const QList<QQuickItem *> children = m_tabBarQmlItem->childItems();
126 for (QQuickItem *child : children) {
127 if (qstrcmp(child->metaObject()->className(), "QQuickListView") == 0)
128 return child;
129 }
130
131 return nullptr;
132}
133
134void TabBarQuick::moveTabTo(int from, int to)
135{
136 Q_UNUSED(from);
137 Q_UNUSED(to);
138 // Not implemented yet
139}
MouseButtonDblClick
QEvent::Type type() const const
bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QGenericReturnArgument ret, QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3, QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7, QGenericArgument val8, QGenericArgument val9)
int x() const const
int y() const const

© 2019-2023 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDDockWidgets
Advanced Dock Widget Framework for Qt
https://www.kdab.com/development-resources/qt-tools/kddockwidgets/
Generated on Wed Nov 1 2023 00:02:31 for KDDockWidgets API Documentation by doxygen 1.9.8