parent
c0ac5ce0a2
commit
6824ea17f2
8 changed files with 434 additions and 27 deletions
@ -0,0 +1,55 @@ |
||||
/* ============================================================
|
||||
* QupZilla - Qt web browser |
||||
* Copyright (C) 2018 David Rosca <nowrep@gmail.com> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */ |
||||
#include "navigationbartoolbutton.h" |
||||
#include "abstractbuttoninterface.h" |
||||
|
||||
#include <QApplication> |
||||
|
||||
NavigationBarToolButton::NavigationBarToolButton(AbstractButtonInterface *button, QWidget *parent) |
||||
: ToolButton(parent) |
||||
, m_button(button) |
||||
{ |
||||
setAutoRaise(true); |
||||
setToolbarButtonLook(true); |
||||
setFocusPolicy(Qt::NoFocus); |
||||
|
||||
setToolTip(button->toolTip()); |
||||
setIcon(button->icon()); |
||||
|
||||
connect(button, &AbstractButtonInterface::iconChanged, this, &ToolButton::setIcon); |
||||
connect(button, &AbstractButtonInterface::toolTipChanged, this, &ToolButton::setToolTip); |
||||
connect(this, &ToolButton::clicked, this, &NavigationBarToolButton::clicked); |
||||
} |
||||
|
||||
void NavigationBarToolButton::clicked() |
||||
{ |
||||
AbstractButtonInterface::ClickController c; |
||||
c.visualParent = this; |
||||
c.popupPosition = [this](const QSize &size) { |
||||
QPoint pos = mapToGlobal(rect().bottomRight()); |
||||
if (QApplication::isRightToLeft()) { |
||||
pos.setX(pos.x() - rect().width()); |
||||
} else { |
||||
pos.setX(pos.x() - size.width()); |
||||
} |
||||
return pos; |
||||
}; |
||||
setDown(true); |
||||
emit m_button->clicked(&c); |
||||
setDown(false); |
||||
} |
||||
@ -0,0 +1,34 @@ |
||||
/* ============================================================
|
||||
* QupZilla - Qt web browser |
||||
* Copyright (C) 2018 David Rosca <nowrep@gmail.com> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */ |
||||
#pragma once |
||||
|
||||
#include "qzcommon.h" |
||||
#include "toolbutton.h" |
||||
|
||||
class AbstractButtonInterface; |
||||
|
||||
class QUPZILLA_EXPORT NavigationBarToolButton : public ToolButton |
||||
{ |
||||
public: |
||||
explicit NavigationBarToolButton(AbstractButtonInterface *button, QWidget *parent = nullptr); |
||||
|
||||
private: |
||||
void clicked(); |
||||
|
||||
AbstractButtonInterface *m_button; |
||||
}; |
||||
@ -0,0 +1,114 @@ |
||||
/* ============================================================
|
||||
* QupZilla - Qt web browser |
||||
* Copyright (C) 2018 David Rosca <nowrep@gmail.com> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */ |
||||
#include "abstractbuttoninterface.h" |
||||
|
||||
AbstractButtonInterface::AbstractButtonInterface(QObject *parent) |
||||
: QObject(parent) |
||||
{ |
||||
} |
||||
|
||||
bool AbstractButtonInterface::isValid() const |
||||
{ |
||||
return !id().isEmpty() && !name().isEmpty(); |
||||
} |
||||
|
||||
bool AbstractButtonInterface::isActive() const |
||||
{ |
||||
return m_active; |
||||
} |
||||
|
||||
void AbstractButtonInterface::setActive(bool active) |
||||
{ |
||||
if (m_active == active) { |
||||
return; |
||||
} |
||||
|
||||
m_active = active; |
||||
emit activeChanged(m_active); |
||||
} |
||||
|
||||
QString AbstractButtonInterface::title() const |
||||
{ |
||||
return m_title; |
||||
} |
||||
|
||||
void AbstractButtonInterface::setTitle(const QString &title) |
||||
{ |
||||
if (m_title == title) { |
||||
return; |
||||
} |
||||
|
||||
m_title = title; |
||||
emit titleChanged(m_title); |
||||
} |
||||
|
||||
QString AbstractButtonInterface::toolTip() const |
||||
{ |
||||
return m_toolTip; |
||||
} |
||||
|
||||
void AbstractButtonInterface::setToolTip(const QString &toolTip) |
||||
{ |
||||
if (m_toolTip == toolTip) { |
||||
return; |
||||
} |
||||
|
||||
m_toolTip = toolTip; |
||||
emit toolTipChanged(m_toolTip); |
||||
} |
||||
|
||||
QIcon AbstractButtonInterface::icon() const |
||||
{ |
||||
return m_icon; |
||||
} |
||||
|
||||
void AbstractButtonInterface::setIcon(const QIcon &icon) |
||||
{ |
||||
m_icon = icon; |
||||
emit iconChanged(icon); |
||||
} |
||||
|
||||
QString AbstractButtonInterface::badgeLabelText() const |
||||
{ |
||||
return m_badgeLabelText; |
||||
} |
||||
|
||||
void AbstractButtonInterface::setBadgeLabelText(const QString &badgeLabelText) |
||||
{ |
||||
if (m_badgeLabelText == badgeLabelText) { |
||||
return; |
||||
} |
||||
|
||||
m_badgeLabelText = badgeLabelText; |
||||
emit badgeLabelTextChanged(m_badgeLabelText); |
||||
} |
||||
|
||||
WebPage *AbstractButtonInterface::webPage() const |
||||
{ |
||||
return m_page; |
||||
} |
||||
|
||||
void AbstractButtonInterface::setWebPage(WebPage *page) |
||||
{ |
||||
if (m_page == page) { |
||||
return; |
||||
} |
||||
|
||||
m_page = page; |
||||
emit webPageChanged(m_page); |
||||
} |
||||
@ -0,0 +1,80 @@ |
||||
/* ============================================================
|
||||
* QupZilla - Qt web browser |
||||
* Copyright (C) 2018 David Rosca <nowrep@gmail.com> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */ |
||||
#pragma once |
||||
|
||||
#include <QIcon> |
||||
#include <QObject> |
||||
|
||||
#include <functional> |
||||
|
||||
#include "qzcommon.h" |
||||
|
||||
class WebPage; |
||||
|
||||
class QUPZILLA_EXPORT AbstractButtonInterface : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
struct ClickController { |
||||
QWidget *visualParent; |
||||
std::function<QPoint(QSize)> popupPosition; |
||||
}; |
||||
|
||||
explicit AbstractButtonInterface(QObject *parent = nullptr); |
||||
|
||||
virtual QString id() const = 0; |
||||
virtual QString name() const = 0; |
||||
|
||||
bool isValid() const; |
||||
|
||||
bool isActive() const; |
||||
void setActive(bool active); |
||||
|
||||
QString title() const; |
||||
void setTitle(const QString &text); |
||||
|
||||
QString toolTip() const; |
||||
void setToolTip(const QString &toolTip); |
||||
|
||||
QIcon icon() const; |
||||
void setIcon(const QIcon &icon); |
||||
|
||||
QString badgeLabelText() const; |
||||
void setBadgeLabelText(const QString &badgeLabelText); |
||||
|
||||
WebPage *webPage() const; |
||||
void setWebPage(WebPage *page); |
||||
|
||||
signals: |
||||
void activeChanged(bool active); |
||||
void titleChanged(const QString &title); |
||||
void toolTipChanged(const QString &toolTip); |
||||
void iconChanged(const QIcon &icon); |
||||
void badgeLabelTextChanged(const QString &badgeLabelText); |
||||
void webPageChanged(WebPage *page); |
||||
void clicked(ClickController *controller); |
||||
|
||||
private: |
||||
bool m_active = true; |
||||
QString m_title; |
||||
QString m_toolTip; |
||||
QIcon m_icon; |
||||
QString m_badgeLabelText; |
||||
WebPage *m_page = nullptr; |
||||
}; |
||||
Loading…
Reference in new issue