1 /***************************************************************************
2 * Copyright (C) 2003 by Sébastien Laoût *
3 * slaout@linux62.org *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21 #include "decoratedbasket.h"
22
23 #include <QGraphicsView>
24 #include <QVBoxLayout>
25
26 #include "basketscene.h"
27 #include "filter.h"
28 #include "settings.h"
29
30 /** Class DecoratedBasket: */
31
DecoratedBasket(QWidget * parent,const QString & folderName,Qt::WindowFlags fl)32 DecoratedBasket::DecoratedBasket(QWidget *parent, const QString &folderName, Qt::WindowFlags fl)
33 : QWidget(parent, fl)
34 {
35 m_layout = new QVBoxLayout(this);
36 m_filter = new FilterBar(this);
37 m_basket = new BasketScene(this, folderName);
38 m_basket->graphicsView()->setParent(this);
39 m_layout->addWidget(m_basket->graphicsView());
40 setFilterBarPosition(Settings::filterOnTop());
41
42 m_filter->hide();
43 m_basket->setFocus(); // To avoid the filter bar have focus on load
44
45 connect(m_filter, SIGNAL(newFilter(const FilterData&)), m_basket, SLOT(newFilter(const FilterData&)));
46
47 connect(m_basket, SIGNAL(postMessage(const QString&)), Global::bnpView, SLOT(postStatusbarMessage(const QString&)));
48 connect(m_basket, SIGNAL(setStatusBarText(const QString&)), Global::bnpView, SLOT(setStatusBarHint(const QString&)));
49 connect(m_basket, SIGNAL(resetStatusBarText()), Global::bnpView, SLOT(updateStatusBarHint()));
50 }
51
~DecoratedBasket()52 DecoratedBasket::~DecoratedBasket()
53 {
54 }
55
setFilterBarPosition(bool onTop)56 void DecoratedBasket::setFilterBarPosition(bool onTop)
57 {
58 m_layout->removeWidget(m_filter);
59 if (onTop) {
60 m_layout->insertWidget(0, m_filter);
61 setTabOrder(this/*(QWidget*)parent()*/, m_filter);
62 setTabOrder(m_filter, m_basket->graphicsView());
63 setTabOrder(m_basket->graphicsView(), (QWidget*)parent());
64 } else {
65 m_layout->addWidget(m_filter);
66 setTabOrder(this/*(QWidget*)parent()*/, m_basket->graphicsView());
67 setTabOrder(m_basket->graphicsView(), m_filter);
68 setTabOrder(m_filter, (QWidget*)parent());
69 }
70 }
71
setFilterBarVisible(bool show,bool switchFocus)72 void DecoratedBasket::setFilterBarVisible(bool show, bool switchFocus)
73 {
74 // m_basket->setShowFilterBar(true);//show);
75 // m_basket->save();
76 // In this order (m_basket and then m_filter) because setShown(false)
77 // will call resetFilter() that will update actions, and then check the
78 // Ctrl+F action whereas it should be unchecked
79 // FIXME: It's very uggly all those things
80 m_filter->setVisible(show);
81 if (show) {
82 if (switchFocus)
83 m_filter->setEditFocus();
84 } else if (m_filter->hasEditFocus())
85 m_basket->setFocus();
86 }
87
resetFilter()88 void DecoratedBasket::resetFilter()
89 {
90 m_filter->reset();
91 }
92
resizeEvent(QResizeEvent * event)93 void DecoratedBasket::resizeEvent(QResizeEvent *event)
94 {
95 QWidget::resizeEvent(event);
96 m_basket->relayoutNotes(true);
97 }
98