File indexing completed on 2024-05-12 04:58:25

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2018 David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program 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
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #pragma once
0019 
0020 #include <QIcon>
0021 #include <QObject>
0022 
0023 #include <functional>
0024 
0025 #include "qzcommon.h"
0026 
0027 class WebView;
0028 
0029 class FALKON_EXPORT AbstractButtonInterface : public QObject
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034     struct ClickController {
0035         QWidget *visualParent;
0036         std::function<QPoint(QSize)> popupPosition;
0037         bool popupOpened = false;
0038         std::function<void()> popupClosed;
0039 
0040         QPoint callPopupPosition(const QSize &size) const {
0041             return popupPosition(size);
0042         }
0043 
0044         void callPopupClosed() const {
0045             popupClosed();
0046         }
0047     };
0048 
0049     explicit AbstractButtonInterface(QObject *parent = nullptr);
0050 
0051     virtual QString id() const = 0;
0052     virtual QString name() const = 0;
0053 
0054     bool isValid() const;
0055 
0056     bool isActive() const;
0057     void setActive(bool active);
0058 
0059     bool isVisible() const;
0060     void setVisible(bool visible);
0061 
0062     QString title() const;
0063     void setTitle(const QString &text);
0064 
0065     QString toolTip() const;
0066     void setToolTip(const QString &toolTip);
0067 
0068     QIcon icon() const;
0069     void setIcon(const QIcon &icon);
0070 
0071     QString badgeText() const;
0072     void setBadgeText(const QString &badgeText);
0073 
0074     WebView *webView() const;
0075     void setWebView(WebView *view);
0076 
0077 Q_SIGNALS:
0078     void activeChanged(bool active);
0079     void visibleChanged(bool visible);
0080     void titleChanged(const QString &title);
0081     void toolTipChanged(const QString &toolTip);
0082     void iconChanged(const QIcon &icon);
0083     void badgeTextChanged(const QString &badgeText);
0084     void webViewChanged(WebView *view);
0085     void clicked(AbstractButtonInterface::ClickController *controller);
0086 
0087 private:
0088     bool m_active = true;
0089     bool m_visible = true;
0090     QString m_title;
0091     QString m_toolTip;
0092     QIcon m_icon;
0093     QString m_badgeText;
0094     WebView *m_view = nullptr;
0095 };