KHTML
khtmlviewbar.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 * 00003 * Copyright (C) 2008 Bernhard Beschow <bbeschow AT cs DOT tu-berlin DOT de> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 */ 00020 #include "khtmlviewbar.h" 00021 00022 #include "khtmlview.h" 00023 #include "khtmlviewbarwidget.h" 00024 00025 #include <kdebug.h> 00026 00027 #include <QtGui/QBoxLayout> 00028 #include <QtGui/QKeyEvent> 00029 00030 KHTMLViewBar::KHTMLViewBar( Position position, KHTMLView *view, QWidget *parent ) : 00031 QWidget( parent ), 00032 m_view( view ), 00033 m_permanentBarWidget( false ) 00034 { 00035 const QBoxLayout::Direction direction = ( position == Top ? QBoxLayout::TopToBottom : QBoxLayout::BottomToTop ); 00036 00037 setLayout( new QBoxLayout( direction, this ) ); 00038 layout()->setContentsMargins( 0, 0, 0, 0 ); 00039 layout()->setSpacing( 0 ); 00040 } 00041 00042 void KHTMLViewBar::addBarWidget (KHTMLViewBarWidget *newBarWidget) 00043 { 00044 if (hasWidget(newBarWidget)) { 00045 kDebug(6050) << "this bar widget is already added"; 00046 return; 00047 } 00048 // add new widget, invisible... 00049 newBarWidget->hide(); 00050 layout()->addWidget( newBarWidget ); 00051 connect(newBarWidget, SIGNAL(hideMe()), SLOT(hideCurrentBarWidget())); 00052 00053 kDebug(6050) << "add barwidget " << newBarWidget; 00054 } 00055 00056 void KHTMLViewBar::addPermanentBarWidget (KHTMLViewBarWidget *barWidget) 00057 { 00058 // remove old widget from layout (if any) 00059 if (m_permanentBarWidget) { 00060 m_permanentBarWidget->hide(); 00061 layout()->removeWidget(m_permanentBarWidget); 00062 } 00063 00064 layout()->addWidget(barWidget /*, 0, Qt::AlignBottom*/ ); // FIXME 00065 m_permanentBarWidget = barWidget; 00066 m_permanentBarWidget->show(); 00067 00068 setViewBarVisible(true); 00069 } 00070 00071 void KHTMLViewBar::removePermanentBarWidget (KHTMLViewBarWidget *barWidget) 00072 { 00073 if (m_permanentBarWidget != barWidget) { 00074 kDebug(6050) << "no such permanent widget exists in bar"; 00075 return; 00076 } 00077 00078 if (!m_permanentBarWidget) 00079 return; 00080 00081 m_permanentBarWidget->hide(); 00082 layout()->removeWidget(m_permanentBarWidget); 00083 m_permanentBarWidget = 0; 00084 } 00085 00086 bool KHTMLViewBar::hasPermanentWidget (KHTMLViewBarWidget *barWidget ) const 00087 { 00088 return (m_permanentBarWidget == barWidget); 00089 } 00090 00091 void KHTMLViewBar::showBarWidget (KHTMLViewBarWidget *barWidget) 00092 { 00093 // raise correct widget 00094 // TODO m_stack->setCurrentWidget (barWidget); 00095 barWidget->show(); 00096 00097 // if we have any permanent widget, bar is always visible, 00098 // no need to show it 00099 if (!m_permanentBarWidget) { 00100 setViewBarVisible(true); 00101 } 00102 } 00103 00104 bool KHTMLViewBar::hasWidget(KHTMLViewBarWidget* wid) const 00105 { 00106 Q_UNUSED(wid); 00107 return layout()->count() != 0; 00108 } 00109 00110 void KHTMLViewBar::hideCurrentBarWidget () 00111 { 00112 // m_stack->hide(); 00113 00114 // if we have any permanent widget, bar is always visible, 00115 // no need to hide it 00116 if (!m_permanentBarWidget) { 00117 setViewBarVisible(false); 00118 } 00119 00120 m_view->setFocus(); 00121 kDebug(6050)<<"hide barwidget"; 00122 } 00123 00124 void KHTMLViewBar::setViewBarVisible (bool visible) 00125 { 00126 setVisible( visible ); 00127 } 00128 00129 void KHTMLViewBar::keyPressEvent(QKeyEvent* event) 00130 { 00131 if (event->key() == Qt::Key_Escape) { 00132 hideCurrentBarWidget(); 00133 return; 00134 } 00135 QWidget::keyPressEvent(event); 00136 00137 } 00138 00139 void KHTMLViewBar::hideEvent(QHideEvent* event) 00140 { 00141 Q_UNUSED(event); 00142 // if (!event->spontaneous()) 00143 // m_view->setFocus(); 00144 }
KDE 4.6 API Reference