KHTML
khtmlviewbar.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
00059 if (m_permanentBarWidget) {
00060 m_permanentBarWidget->hide();
00061 layout()->removeWidget(m_permanentBarWidget);
00062 }
00063
00064 layout()->addWidget(barWidget );
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
00094
00095 barWidget->show();
00096
00097
00098
00099 if (!m_permanentBarWidget) {
00100 setViewBarVisible(true);
00101 }
00102 }
00103
00104 bool KHTMLViewBar::hasWidget(KHTMLViewBarWidget* wid) const
00105 {
00106 return layout()->count() != 0;
00107 }
00108
00109 void KHTMLViewBar::hideCurrentBarWidget ()
00110 {
00111
00112
00113
00114
00115 if (!m_permanentBarWidget) {
00116 setViewBarVisible(false);
00117 }
00118
00119 m_view->setFocus();
00120 kDebug(6050)<<"hide barwidget";
00121 }
00122
00123 void KHTMLViewBar::setViewBarVisible (bool visible)
00124 {
00125 setVisible( visible );
00126 }
00127
00128 void KHTMLViewBar::keyPressEvent(QKeyEvent* event)
00129 {
00130 if (event->key() == Qt::Key_Escape) {
00131 hideCurrentBarWidget();
00132 return;
00133 }
00134 QWidget::keyPressEvent(event);
00135
00136 }
00137
00138 void KHTMLViewBar::hideEvent(QHideEvent* event)
00139 {
00140
00141
00142 }