File indexing completed on 2022-09-27 16:29:12

0001 /**
0002  * SPDX-FileCopyrightText: (C) 2003 by Sébastien Laoût <slaout@linux62.org>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "decoratedbasket.h"
0008 
0009 #include <QGraphicsView>
0010 #include <QVBoxLayout>
0011 #include <KMessageWidget>
0012 
0013 #include "basketscene.h"
0014 #include "filter.h"
0015 #include "settings.h"
0016 
0017 /** Class DecoratedBasket: */
0018 
0019 DecoratedBasket::DecoratedBasket(QWidget *parent, const QString &folderName)
0020     : QWidget(parent)
0021 {
0022     m_layout = new QVBoxLayout(this);
0023     m_filter = new FilterBar(this);
0024     m_filter->hide();
0025 
0026     m_basket = new BasketScene(this, folderName);
0027     m_basket->graphicsView()->setParent(this);
0028     m_layout->addWidget(m_basket->graphicsView());
0029     m_basket->setFocus(); // To avoid the filter bar have focus on load
0030 
0031     m_messageWidget = new KMessageWidget(this);
0032     m_messageWidget->setCloseButtonVisible(true);
0033     m_messageWidget->setMessageType(KMessageWidget::MessageType::Error);
0034     m_messageWidget->hide();
0035     m_layout->addWidget(m_messageWidget);
0036 
0037     setFilterBarPosition(Settings::filterOnTop());
0038 
0039     connect(m_filter, SIGNAL(newFilter(const FilterData &)), m_basket, SLOT(newFilter(const FilterData &)));
0040     connect(m_basket, &BasketScene::postMessage, Global::bnpView, &BNPView::postStatusbarMessage);
0041     connect(m_basket, &BasketScene::setStatusBarText, Global::bnpView, &BNPView::setStatusBarHint);
0042     connect(m_basket, &BasketScene::resetStatusBarText, Global::bnpView, &BNPView::updateStatusBarHint);
0043 }
0044 
0045 void DecoratedBasket::setFilterBarPosition(bool onTop)
0046 {
0047     m_layout->removeWidget(m_filter);
0048     if (onTop) {
0049         m_layout->insertWidget(0, m_filter);
0050         setTabOrder(this /*(QWidget*)parent()*/, m_filter);
0051         setTabOrder(m_filter, m_basket->graphicsView());
0052         setTabOrder(m_basket->graphicsView(), m_messageWidget);
0053         setTabOrder(m_messageWidget, (QWidget *)parent());
0054     } else {
0055         m_layout->addWidget(m_filter);
0056         setTabOrder(this /*(QWidget*)parent()*/, m_basket->graphicsView());
0057         setTabOrder(m_basket->graphicsView(), m_filter);
0058         setTabOrder(m_filter, m_messageWidget);
0059         setTabOrder(m_messageWidget, (QWidget *)parent());
0060     }
0061 }
0062 
0063 void DecoratedBasket::setFilterBarVisible(bool show, bool switchFocus)
0064 {
0065     //  m_basket->setShowFilterBar(true);//show);
0066     //  m_basket->save();
0067     // In this order (m_basket and then m_filter) because setShown(false)
0068     //  will call resetFilter() that will update actions, and then check the
0069     //  Ctrl+F action whereas it should be unchecked
0070     //  FIXME: It's very uggly all those things
0071     m_filter->setVisible(show);
0072     if (show) {
0073         if (switchFocus)
0074             m_filter->setEditFocus();
0075     } else if (m_filter->hasEditFocus())
0076         m_basket->setFocus();
0077 }
0078 
0079 void DecoratedBasket::resetFilter()
0080 {
0081     m_filter->reset();
0082 }
0083 
0084 void DecoratedBasket::resizeEvent(QResizeEvent *event)
0085 {
0086     QWidget::resizeEvent(event);
0087     m_basket->relayoutNotes();
0088 }
0089 
0090 void DecoratedBasket::showErrorMessage(const QString &errorMessage)
0091 {
0092     m_messageWidget->setText(errorMessage);
0093     m_messageWidget->show();
0094 }