fix logic
[personal-kdelibs.git] / khtml / khtmlviewbar.cpp
blob17f772597e97ac7854e58433ecd18bb466c7e005
1 /* This file is part of the KDE project
3 * Copyright (C) 2008 Bernhard Beschow <bbeschow cs tu berlin de>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
20 #include "khtmlviewbar.h"
22 #include "khtmlview.h"
23 #include "khtmlviewbarwidget.h"
25 #include <kdebug.h>
27 #include <QtGui/QBoxLayout>
28 #include <QtGui/QKeyEvent>
30 KHTMLViewBar::KHTMLViewBar( Position position, KHTMLView *view, QWidget *parent ) :
31 QWidget( parent ),
32 m_view( view ),
33 m_permanentBarWidget( false )
35 const QBoxLayout::Direction direction = ( position == Top ? QBoxLayout::TopToBottom : QBoxLayout::BottomToTop );
37 setLayout( new QBoxLayout( direction, this ) );
38 layout()->setContentsMargins( 0, 0, 0, 0 );
39 layout()->setSpacing( 0 );
42 void KHTMLViewBar::addBarWidget (KHTMLViewBarWidget *newBarWidget)
44 if (hasWidget(newBarWidget)) {
45 kDebug(6050) << "this bar widget is already added";
46 return;
48 // add new widget, invisible...
49 newBarWidget->hide();
50 layout()->addWidget( newBarWidget );
51 connect(newBarWidget, SIGNAL(hideMe()), SLOT(hideCurrentBarWidget()));
53 kDebug(6050) << "add barwidget " << newBarWidget;
56 void KHTMLViewBar::addPermanentBarWidget (KHTMLViewBarWidget *barWidget)
58 // remove old widget from layout (if any)
59 if (m_permanentBarWidget) {
60 m_permanentBarWidget->hide();
61 layout()->removeWidget(m_permanentBarWidget);
64 layout()->addWidget(barWidget /*, 0, Qt::AlignBottom*/ ); // FIXME
65 m_permanentBarWidget = barWidget;
66 m_permanentBarWidget->show();
68 setViewBarVisible(true);
71 void KHTMLViewBar::removePermanentBarWidget (KHTMLViewBarWidget *barWidget)
73 if (m_permanentBarWidget != barWidget) {
74 kDebug(6050) << "no such permanent widget exists in bar";
75 return;
78 if (!m_permanentBarWidget)
79 return;
81 m_permanentBarWidget->hide();
82 layout()->removeWidget(m_permanentBarWidget);
83 m_permanentBarWidget = 0;
86 bool KHTMLViewBar::hasPermanentWidget (KHTMLViewBarWidget *barWidget ) const
88 return (m_permanentBarWidget == barWidget);
91 void KHTMLViewBar::showBarWidget (KHTMLViewBarWidget *barWidget)
93 // raise correct widget
94 // TODO m_stack->setCurrentWidget (barWidget);
95 barWidget->show();
97 // if we have any permanent widget, bar is always visible,
98 // no need to show it
99 if (!m_permanentBarWidget) {
100 setViewBarVisible(true);
104 bool KHTMLViewBar::hasWidget(KHTMLViewBarWidget* wid) const
106 return layout()->count() != 0;
109 void KHTMLViewBar::hideCurrentBarWidget ()
111 // m_stack->hide();
113 // if we have any permanent widget, bar is always visible,
114 // no need to hide it
115 if (!m_permanentBarWidget) {
116 setViewBarVisible(false);
119 m_view->setFocus();
120 kDebug(6050)<<"hide barwidget";
123 void KHTMLViewBar::setViewBarVisible (bool visible)
125 setVisible( visible );
128 void KHTMLViewBar::keyPressEvent(QKeyEvent* event)
130 if (event->key() == Qt::Key_Escape) {
131 hideCurrentBarWidget();
132 return;
134 QWidget::keyPressEvent(event);
138 void KHTMLViewBar::hideEvent(QHideEvent* event)
140 // if (!event->spontaneous())
141 // m_view->setFocus();