File indexing completed on 2025-04-27 03:58:30
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 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 DMultiTabBar::DMultiTabBar(Qt::Edge pos, QWidget* const parent) 0024 : QWidget(parent), 0025 d (new Private) 0026 { 0027 if ((pos == Qt::LeftEdge) || (pos == Qt::RightEdge)) 0028 { 0029 d->layout = new QVBoxLayout(this); 0030 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); 0031 } 0032 else 0033 { 0034 d->layout = new QHBoxLayout(this); 0035 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); 0036 } 0037 0038 d->layout->setContentsMargins(QMargins()); 0039 d->layout->setSpacing(0); 0040 0041 d->internal = new DMultiTabBarFrame(this, pos); 0042 setPosition(pos); 0043 setStyle(ActiveIconText); 0044 d->layout->insertWidget(0, d->internal); 0045 d->layout->insertWidget(0, d->btnTabSep = new QFrame(this)); 0046 d->btnTabSep->setFixedHeight(4); 0047 d->btnTabSep->setFrameStyle(QFrame::Panel | QFrame::Sunken); 0048 d->btnTabSep->setLineWidth(2); 0049 d->btnTabSep->hide(); 0050 0051 updateGeometry(); 0052 } 0053 0054 DMultiTabBar::~DMultiTabBar() 0055 { 0056 qDeleteAll(d->buttons); 0057 d->buttons.clear(); 0058 delete d; 0059 } 0060 0061 void DMultiTabBar::appendButton(const QIcon& pic, int id, QMenu* const popup, const QString&) 0062 { 0063 DMultiTabBarButton* const btn = new DMultiTabBarButton(pic, QString(), id, this); 0064 0065 // a button with a QMenu can have another size. Make sure the button has always the same size. 0066 0067 btn->setFixedWidth(btn->height()); 0068 btn->setMenu(popup); 0069 d->buttons.append(btn); 0070 d->layout->insertWidget(0, btn); 0071 btn->show(); 0072 d->btnTabSep->show(); 0073 } 0074 0075 void DMultiTabBar::updateSeparator() 0076 { 0077 bool hideSep = true; 0078 QListIterator<DMultiTabBarButton*> it(d->buttons); 0079 0080 while (it.hasNext()) 0081 { 0082 if (it.next()->isVisibleTo(this)) 0083 { 0084 hideSep = false; 0085 break; 0086 } 0087 } 0088 0089 if (hideSep) 0090 { 0091 d->btnTabSep->hide(); 0092 } 0093 else 0094 { 0095 d->btnTabSep->show(); 0096 } 0097 } 0098 0099 void DMultiTabBar::appendTab(const QIcon& pic, int id, const QString& text) 0100 { 0101 d->internal->appendTab(pic, id, text); 0102 } 0103 0104 DMultiTabBarButton* DMultiTabBar::button(int id) const 0105 { 0106 QListIterator<DMultiTabBarButton*> it(d->buttons); 0107 0108 while (it.hasNext()) 0109 { 0110 DMultiTabBarButton* const button = it.next(); 0111 0112 if (button->id() == id) 0113 { 0114 return button; 0115 } 0116 } 0117 0118 return nullptr; 0119 } 0120 0121 DMultiTabBarTab* DMultiTabBar::tab(int id) const 0122 { 0123 return d->internal->tab(id); 0124 } 0125 0126 void DMultiTabBar::removeButton(int id) 0127 { 0128 for (int pos = 0 ; pos < d->buttons.count() ; ++pos) 0129 { 0130 if (d->buttons.at(pos)->id() == id) 0131 { 0132 d->buttons.takeAt(pos)->deleteLater(); 0133 break; 0134 } 0135 } 0136 0137 if (d->buttons.count() == 0) 0138 { 0139 d->btnTabSep->hide(); 0140 } 0141 } 0142 0143 void DMultiTabBar::removeTab(int id) 0144 { 0145 d->internal->removeTab(id); 0146 } 0147 0148 void DMultiTabBar::setTab(int id,bool state) 0149 { 0150 DMultiTabBarTab* const ttab = tab(id); 0151 0152 if (ttab) 0153 { 0154 ttab->setState(state); 0155 } 0156 } 0157 0158 bool DMultiTabBar::isTabRaised(int id) const 0159 { 0160 DMultiTabBarTab* const ttab = tab(id); 0161 0162 if (ttab) 0163 { 0164 return ttab->isChecked(); 0165 } 0166 0167 return false; 0168 } 0169 0170 void DMultiTabBar::setStyle(TextStyle style) 0171 { 0172 d->internal->setStyle(style); 0173 } 0174 0175 DMultiTabBar::TextStyle DMultiTabBar::tabStyle() const 0176 { 0177 return d->internal->d->style; 0178 } 0179 0180 void DMultiTabBar::setPosition(Qt::Edge pos) 0181 { 0182 d->position = pos; 0183 d->internal->setPosition(pos); 0184 } 0185 0186 Qt::Edge DMultiTabBar::position() const 0187 { 0188 return d->position; 0189 } 0190 0191 void DMultiTabBar::fontChange(const QFont&) 0192 { 0193 updateGeometry(); 0194 } 0195 0196 } // namespace Digikam