File indexing completed on 2025-04-27 03:58:31
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2005-03-22 0007 * Description : a widget to manage sidebar in GUI - Multi-tab bar frame implementation. 0008 * 0009 * SPDX-FileCopyrightText: 2005-2006 by Joern Ahrens <joern dot ahrens at kdemail dot net> 0010 * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * SPDX-FileCopyrightText: 2008-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0012 * SPDX-FileCopyrightText: 2001-2003 by Joseph Wenninger <jowenn at kde dot org> 0013 * 0014 * SPDX-License-Identifier: GPL-2.0-or-later 0015 * 0016 * ============================================================ */ 0017 0018 #include "sidebar_p.h" 0019 0020 namespace Digikam 0021 { 0022 0023 DMultiTabBarButton::DMultiTabBarButton(const QIcon& pic, const QString& text, 0024 int id, QWidget* const parent) 0025 : QPushButton(pic, text, parent), 0026 m_id (id) 0027 { 0028 // --- NOTE: use dynamic binding as slotClicked() is a virtual method which can be re-implemented in derived classes. 0029 0030 connect(this, &QPushButton::clicked, 0031 this, &DMultiTabBarButton::slotClicked); 0032 0033 // we can't see the focus, so don't take focus. #45557 0034 // If keyboard navigation is wanted, then only the bar should take focus, 0035 // and arrows could change the focused button; but generally, tabbars don't take focus anyway. 0036 0037 setFocusPolicy(Qt::NoFocus); 0038 0039 // See RB #128005 0040 0041 setAttribute(Qt::WA_LayoutUsesWidgetRect); 0042 } 0043 0044 DMultiTabBarButton::~DMultiTabBarButton() 0045 { 0046 } 0047 0048 void DMultiTabBarButton::setText(const QString& text) 0049 { 0050 QPushButton::setText(text); 0051 } 0052 0053 void DMultiTabBarButton::slotClicked() 0054 { 0055 updateGeometry(); 0056 Q_EMIT signalClicked(m_id); 0057 } 0058 0059 int DMultiTabBarButton::id() const 0060 { 0061 return m_id; 0062 } 0063 0064 void DMultiTabBarButton::hideEvent(QHideEvent* e) 0065 { 0066 QPushButton::hideEvent(e); 0067 DMultiTabBar* const tb = dynamic_cast<DMultiTabBar*>(parentWidget()); 0068 0069 if (tb) 0070 { 0071 tb->updateSeparator(); 0072 } 0073 } 0074 0075 void DMultiTabBarButton::showEvent(QShowEvent* e) 0076 { 0077 QPushButton::showEvent(e); 0078 DMultiTabBar* const tb = dynamic_cast<DMultiTabBar*>(parentWidget()); 0079 0080 if (tb) 0081 { 0082 tb->updateSeparator(); 0083 } 0084 } 0085 0086 void DMultiTabBarButton::paintEvent(QPaintEvent*) 0087 { 0088 QStyleOptionButton opt; 0089 opt.initFrom(this); 0090 opt.icon = icon(); 0091 opt.iconSize = iconSize(); 0092 0093 // removes the QStyleOptionButton::HasMenu ButtonFeature 0094 0095 opt.features = QStyleOptionButton::Flat; 0096 QPainter painter(this); 0097 style()->drawControl(QStyle::CE_PushButton, &opt, &painter, this); 0098 } 0099 0100 } // namespace Digikam