mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
TabManager: Port icon to AbstractButtonInterface
It is now available from both NavigationBar and StatusBar
This commit is contained in:
parent
cc55c0ad02
commit
32e7ec1826
|
@ -18,12 +18,13 @@
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "tabmanagerwidgetcontroller.h"
|
#include "tabmanagerwidgetcontroller.h"
|
||||||
#include "tabmanagerwidget.h"
|
#include "tabmanagerwidget.h"
|
||||||
#include "clickablelabel.h"
|
#include "abstractbuttoninterface.h"
|
||||||
#include "browserwindow.h"
|
#include "browserwindow.h"
|
||||||
#include "tabwidget.h"
|
#include "tabwidget.h"
|
||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
#include "tabbar.h"
|
#include "tabbar.h"
|
||||||
#include "statusbar.h"
|
#include "statusbar.h"
|
||||||
|
#include "navigationbar.h"
|
||||||
|
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
@ -31,6 +32,26 @@
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
class TabManagerButton : public AbstractButtonInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit TabManagerButton(QObject *parent = nullptr)
|
||||||
|
: AbstractButtonInterface(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QString id() const override
|
||||||
|
{
|
||||||
|
return QSL("tabmanager-icon");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString name() const override
|
||||||
|
{
|
||||||
|
return tr("Tab Manager button");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
TabManagerWidgetController::TabManagerWidgetController(QObject* parent)
|
TabManagerWidgetController::TabManagerWidgetController(QObject* parent)
|
||||||
: SideBarInterface(parent)
|
: SideBarInterface(parent)
|
||||||
, m_defaultTabManager(0)
|
, m_defaultTabManager(0)
|
||||||
|
@ -63,7 +84,7 @@ QWidget* TabManagerWidgetController::createSideBarWidget(BrowserWindow* mainWind
|
||||||
return createTabManagerWidget(mainWindow, mainWindow);
|
return createTabManagerWidget(mainWindow, mainWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* TabManagerWidgetController::createStatusBarIcon(BrowserWindow* mainWindow)
|
AbstractButtonInterface* TabManagerWidgetController::createStatusBarIcon(BrowserWindow* mainWindow)
|
||||||
{
|
{
|
||||||
if (!defaultTabManager()) {
|
if (!defaultTabManager()) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -73,11 +94,27 @@ QWidget* TabManagerWidgetController::createStatusBarIcon(BrowserWindow* mainWind
|
||||||
return m_statusBarIcons.value(mainWindow);
|
return m_statusBarIcons.value(mainWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
ClickableLabel* icon = new ClickableLabel(mainWindow);
|
TabManagerButton* icon = new TabManagerButton(this);
|
||||||
icon->setCursor(Qt::PointingHandCursor);
|
icon->setIcon(QPixmap(":tabmanager/data/tabmanager.png"));
|
||||||
QPixmap p(":tabmanager/data/tabmanager.png");
|
icon->setTitle(tr("Tab Manager"));
|
||||||
icon->setPixmap(p.scaledToHeight(16));
|
|
||||||
icon->setToolTip(tr("Show Tab Manager"));
|
icon->setToolTip(tr("Show Tab Manager"));
|
||||||
|
connect(icon, &AbstractButtonInterface::clicked, this, [=](AbstractButtonInterface::ClickController *c) {
|
||||||
|
if (!defaultTabManager()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int frameWidth = (defaultTabManager()->frameGeometry().width() - defaultTabManager()->geometry().width()) / 2;
|
||||||
|
static int titleBarHeight = defaultTabManager()->style()->pixelMetric(QStyle::PM_TitleBarHeight);
|
||||||
|
|
||||||
|
QSize newSize(defaultTabManager()->width(), mainWindow->height() - titleBarHeight - frameWidth);
|
||||||
|
QRect newGeo(c->popupPosition(newSize), newSize);
|
||||||
|
defaultTabManager()->setGeometry(newGeo);
|
||||||
|
raiseTabManager();
|
||||||
|
|
||||||
|
QTimer::singleShot(0, this, [=]() {
|
||||||
|
c->popupClosed();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
QAction* showAction = createMenuAction();
|
QAction* showAction = createMenuAction();
|
||||||
showAction->setCheckable(false);
|
showAction->setCheckable(false);
|
||||||
|
@ -85,8 +122,6 @@ QWidget* TabManagerWidgetController::createStatusBarIcon(BrowserWindow* mainWind
|
||||||
mainWindow->addAction(showAction);
|
mainWindow->addAction(showAction);
|
||||||
connect(showAction, SIGNAL(triggered()), this, SLOT(raiseTabManager()));
|
connect(showAction, SIGNAL(triggered()), this, SLOT(raiseTabManager()));
|
||||||
|
|
||||||
connect(icon, SIGNAL(clicked(QPoint)), this, SLOT(raiseTabManager()));
|
|
||||||
|
|
||||||
m_statusBarIcons.insert(mainWindow, icon);
|
m_statusBarIcons.insert(mainWindow, icon);
|
||||||
m_actions.insert(mainWindow, showAction);
|
m_actions.insert(mainWindow, showAction);
|
||||||
|
|
||||||
|
@ -137,14 +172,16 @@ TabManagerWidget* TabManagerWidgetController::defaultTabManager()
|
||||||
void TabManagerWidgetController::addStatusBarIcon(BrowserWindow* window)
|
void TabManagerWidgetController::addStatusBarIcon(BrowserWindow* window)
|
||||||
{
|
{
|
||||||
if (window) {
|
if (window) {
|
||||||
window->statusBar()->addPermanentWidget(createStatusBarIcon(window));
|
window->statusBar()->addButton(createStatusBarIcon(window));
|
||||||
|
window->navigationBar()->addToolButton(createStatusBarIcon(window));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabManagerWidgetController::removeStatusBarIcon(BrowserWindow* window)
|
void TabManagerWidgetController::removeStatusBarIcon(BrowserWindow* window)
|
||||||
{
|
{
|
||||||
if (window) {
|
if (window) {
|
||||||
window->statusBar()->removeWidget(m_statusBarIcons.value(window));
|
window->statusBar()->removeButton(m_statusBarIcons.value(window));
|
||||||
|
window->navigationBar()->removeToolButton(m_statusBarIcons.value(window));
|
||||||
window->removeAction(m_actions.value(window));
|
window->removeAction(m_actions.value(window));
|
||||||
delete m_actions.value(window);
|
delete m_actions.value(window);
|
||||||
delete m_statusBarIcons.value(window);
|
delete m_statusBarIcons.value(window);
|
||||||
|
@ -166,20 +203,6 @@ void TabManagerWidgetController::raiseTabManager()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClickableLabel* icon = qobject_cast<ClickableLabel*>(sender());
|
|
||||||
if (icon) {
|
|
||||||
static int frameWidth = (defaultTabManager()->frameGeometry().width() - defaultTabManager()->geometry().width()) / 2;
|
|
||||||
static int titleBarHeight = defaultTabManager()->style()->pixelMetric(QStyle::PM_TitleBarHeight);
|
|
||||||
|
|
||||||
int y = qMax(0, icon->mapToGlobal(QPoint(0, 0)).y() - 1 - icon->window()->height() + titleBarHeight - frameWidth);
|
|
||||||
int x = icon->mapToGlobal(QPoint(0, 0)).x();
|
|
||||||
if (!mApp->isRightToLeft()) {
|
|
||||||
x -= defaultTabManager()->width();
|
|
||||||
}
|
|
||||||
QRect newGeo(x, y, defaultTabManager()->width(), icon->window()->height() - titleBarHeight - frameWidth);
|
|
||||||
defaultTabManager()->setGeometry(newGeo);
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultTabManager()->activateWindow();
|
defaultTabManager()->activateWindow();
|
||||||
defaultTabManager()->showNormal();
|
defaultTabManager()->showNormal();
|
||||||
defaultTabManager()->raise();
|
defaultTabManager()->raise();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/* ============================================================
|
/* ============================================================
|
||||||
* TabManager plugin for Falkon
|
* TabManager plugin for Falkon
|
||||||
* Copyright (C) 2013-2017 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
* Copyright (C) 2013-2017 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
||||||
|
* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -22,6 +23,7 @@
|
||||||
#include "tabmanagerwidget.h"
|
#include "tabmanagerwidget.h"
|
||||||
|
|
||||||
class WebPage;
|
class WebPage;
|
||||||
|
class AbstractButtonInterface;
|
||||||
|
|
||||||
class TabManagerWidgetController : public SideBarInterface
|
class TabManagerWidgetController : public SideBarInterface
|
||||||
{
|
{
|
||||||
|
@ -34,7 +36,7 @@ public:
|
||||||
QAction* createMenuAction();
|
QAction* createMenuAction();
|
||||||
QWidget* createSideBarWidget(BrowserWindow* mainWindow);
|
QWidget* createSideBarWidget(BrowserWindow* mainWindow);
|
||||||
|
|
||||||
QWidget* createStatusBarIcon(BrowserWindow* mainWindow);
|
AbstractButtonInterface* createStatusBarIcon(BrowserWindow* mainWindow);
|
||||||
|
|
||||||
TabManagerWidget::GroupType groupType();
|
TabManagerWidget::GroupType groupType();
|
||||||
TabManagerWidget* createTabManagerWidget(BrowserWindow* mainClass, QWidget* parent = 0, bool defaultWidget = false);
|
TabManagerWidget* createTabManagerWidget(BrowserWindow* mainClass, QWidget* parent = 0, bool defaultWidget = false);
|
||||||
|
@ -55,7 +57,7 @@ private:
|
||||||
TabManagerWidget* m_defaultTabManager;
|
TabManagerWidget* m_defaultTabManager;
|
||||||
TabManagerWidget::GroupType m_groupType;
|
TabManagerWidget::GroupType m_groupType;
|
||||||
|
|
||||||
QHash<BrowserWindow*, QWidget*> m_statusBarIcons;
|
QHash<BrowserWindow*, AbstractButtonInterface*> m_statusBarIcons;
|
||||||
QHash<BrowserWindow*, QAction*> m_actions;
|
QHash<BrowserWindow*, QAction*> m_actions;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user