KHtml

khtmlviewbar.cpp
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2008 Bernhard Beschow <bbeschow AT cs DOT tu-berlin DOT de>
4  *
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.
9  *
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.
14  *
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.
19  */
20 #include "khtmlviewbar.h"
21 
22 #include "khtmlview.h"
23 #include "khtmlviewbarwidget.h"
24 
25 #include "khtml_debug.h"
26 
27 #include <QBoxLayout>
28 #include <QKeyEvent>
29 
30 KHTMLViewBar::KHTMLViewBar(Position position, KHTMLView *view, QWidget *parent) :
31  QWidget(parent),
32  m_view(view),
33  m_permanentBarWidget(nullptr)
34 {
36 
37  setLayout(new QBoxLayout(direction, this));
38  layout()->setContentsMargins(0, 0, 0, 0);
39  layout()->setSpacing(0);
40 }
41 
42 void KHTMLViewBar::addBarWidget(KHTMLViewBarWidget *newBarWidget)
43 {
44  if (hasWidget(newBarWidget)) {
45  // qCDebug(KHTML_LOG) << "this bar widget is already added";
46  return;
47  }
48  // add new widget, invisible...
49  newBarWidget->hide();
50  layout()->addWidget(newBarWidget);
51  connect(newBarWidget, SIGNAL(hideMe()), SLOT(hideCurrentBarWidget()));
52 
53  // qCDebug(KHTML_LOG) << "add barwidget " << newBarWidget;
54 }
55 
56 void KHTMLViewBar::addPermanentBarWidget(KHTMLViewBarWidget *barWidget)
57 {
58  // remove old widget from layout (if any)
59  if (m_permanentBarWidget) {
60  m_permanentBarWidget->hide();
61  layout()->removeWidget(m_permanentBarWidget);
62  }
63 
64  layout()->addWidget(barWidget /*, 0, Qt::AlignBottom*/); // FIXME
65  m_permanentBarWidget = barWidget;
66  m_permanentBarWidget->show();
67 
68  setViewBarVisible(true);
69 }
70 
71 void KHTMLViewBar::removePermanentBarWidget(KHTMLViewBarWidget *barWidget)
72 {
73  if (m_permanentBarWidget != barWidget) {
74  // qCDebug(KHTML_LOG) << "no such permanent widget exists in bar";
75  return;
76  }
77 
78  if (!m_permanentBarWidget) {
79  return;
80  }
81 
82  m_permanentBarWidget->hide();
83  layout()->removeWidget(m_permanentBarWidget);
84  m_permanentBarWidget = nullptr;
85 }
86 
87 bool KHTMLViewBar::hasPermanentWidget(KHTMLViewBarWidget *barWidget) const
88 {
89  return (m_permanentBarWidget == barWidget);
90 }
91 
92 void KHTMLViewBar::showBarWidget(KHTMLViewBarWidget *barWidget)
93 {
94  // raise correct widget
95 // TODO m_stack->setCurrentWidget (barWidget);
96  barWidget->show();
97 
98  // if we have any permanent widget, bar is always visible,
99  // no need to show it
100  if (!m_permanentBarWidget) {
101  setViewBarVisible(true);
102  }
103 }
104 
105 bool KHTMLViewBar::hasWidget(KHTMLViewBarWidget *wid) const
106 {
107  Q_UNUSED(wid);
108  return layout()->count() != 0;
109 }
110 
111 void KHTMLViewBar::hideCurrentBarWidget()
112 {
113 // m_stack->hide();
114 
115  // if we have any permanent widget, bar is always visible,
116  // no need to hide it
117  if (!m_permanentBarWidget) {
118  setViewBarVisible(false);
119  }
120 
121  m_view->setFocus();
122  // qCDebug(KHTML_LOG)<<"hide barwidget";
123 }
124 
125 void KHTMLViewBar::setViewBarVisible(bool visible)
126 {
127  setVisible(visible);
128 }
129 
130 void KHTMLViewBar::keyPressEvent(QKeyEvent *event)
131 {
132  if (event->key() == Qt::Key_Escape) {
133  hideCurrentBarWidget();
134  return;
135  }
136  QWidget::keyPressEvent(event);
137 
138 }
139 
140 void KHTMLViewBar::hideEvent(QHideEvent *event)
141 {
142  Q_UNUSED(event);
143 // if (!event->spontaneous())
144 // m_view->setFocus();
145 }
Renders and displays HTML in a QScrollArea.
Definition: khtmlview.h:97
void layout()
ensure the display is up to date
Definition: khtmlview.cpp:981
void setLayout(QLayout *layout)
int key() const const
Top
virtual void keyPressEvent(QKeyEvent *event)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Key_Escape
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 22:47:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.