File indexing completed on 2024-04-21 14:59:00

0001 /* This file is part of the KDE project
0002  *
0003  * Copyright (C) 2008 Bernhard Beschow <bbeschow AT cs DOT tu-berlin DOT de>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Library General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, write to
0017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  */
0020 #ifndef _khtml_viewbar_h_
0021 #define _khtml_viewbar_h_
0022 
0023 #include <QWidget>
0024 
0025 class KHTMLView;
0026 class KHTMLViewBarWidget;
0027 
0028 class KHTMLViewBar : public QWidget
0029 {
0030     Q_OBJECT
0031 public:
0032     enum Position {
0033         Top,
0034         Bottom
0035     };
0036 
0037     KHTMLViewBar(Position position, KHTMLView *view, QWidget *parent);
0038 
0039     /**
0040      * Adds a widget to this viewbar.
0041      * Widget is initially invisible, you should call showBarWidget, to show it.
0042      * Several widgets can be added to the bar, but only one can be visible
0043      */
0044     void addBarWidget(KHTMLViewBarWidget *newBarWidget);
0045 
0046     /**
0047      * Shows barWidget that was previously added with addBarWidget.
0048      * @see hideCurrentBarWidget
0049      */
0050     void showBarWidget(KHTMLViewBarWidget *barWidget);
0051 
0052     /**
0053      * Adds widget that will be always shown in the viewbar.
0054      * After adding permanent widget viewbar is immediately shown.
0055      * ViewBar with permanent widget won't hide itself
0056      * until permanent widget is removed.
0057      * OTOH showing/hiding regular barWidgets will work as usual
0058      * (they will be shown above permanent widget)
0059      *
0060      * If permanent widget already exists, new one replaces old one
0061      * Old widget is not deleted, caller can do it if it wishes
0062      */
0063     void addPermanentBarWidget(KHTMLViewBarWidget *barWidget);
0064 
0065     /**
0066      * Removes permanent bar widget from viewbar.
0067      * If no other viewbar widgets are shown, viewbar gets hidden.
0068      *
0069      * barWidget is not deleted, caller must do it if it wishes
0070      */
0071     void removePermanentBarWidget(KHTMLViewBarWidget *barWidget);
0072 
0073     /**
0074      * @return if viewbar has permanent widget @p barWidget
0075      */
0076     bool hasPermanentWidget(KHTMLViewBarWidget *barWidget) const;
0077 
0078 public Q_SLOTS:
0079     /**
0080      * Hides currently shown bar widget
0081      */
0082     void hideCurrentBarWidget();
0083 
0084 protected:
0085     void keyPressEvent(QKeyEvent *event) override;
0086     void hideEvent(QHideEvent *event) override;
0087 
0088 private:
0089     bool hasWidget(KHTMLViewBarWidget *) const;
0090 
0091     /**
0092      * Shows or hides whole viewbar
0093      */
0094     void setViewBarVisible(bool visible);
0095 
0096 private:
0097     KHTMLView *m_view;
0098     KHTMLViewBarWidget *m_permanentBarWidget;
0099 };
0100 
0101 #endif