mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
Merge pull request #2297 from srazi/improve_tabmanager
Improve TabManager
This commit is contained in:
commit
1d8b2345ac
@ -6,13 +6,13 @@ SOURCES += tabmanagerplugin.cpp \
|
||||
tabmanagerwidget.cpp \
|
||||
tabmanagerwidgetcontroller.cpp \
|
||||
tabmanagersettings.cpp \
|
||||
tabfilterdelegate.cpp
|
||||
tabmanagerdelegate.cpp
|
||||
|
||||
HEADERS += tabmanagerplugin.h \
|
||||
tabmanagerwidget.h \
|
||||
tabmanagerwidgetcontroller.h \
|
||||
tabmanagersettings.h \
|
||||
tabfilterdelegate.h
|
||||
tabmanagerdelegate.h
|
||||
|
||||
RESOURCES += tabmanagerplugin.qrc
|
||||
|
||||
|
BIN
src/plugins/TabManager/data/addtab.png
Normal file
BIN
src/plugins/TabManager/data/addtab.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 657 B |
BIN
src/plugins/TabManager/data/closetab.png
Normal file
BIN
src/plugins/TabManager/data/closetab.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 696 B |
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* QupZilla - Qt web browser
|
||||
* Copyright (C) 2016 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
||||
* Copyright (C) 2016-2017 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
||||
* Copyright (C) 2017 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@ -16,25 +16,26 @@
|
||||
* 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 "tabfilterdelegate.h"
|
||||
#include "tabmanagerdelegate.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QApplication>
|
||||
#include <QTextLayout>
|
||||
|
||||
TabFilterDelegate::TabFilterDelegate(QObject* parent)
|
||||
TabManagerDelegate::TabManagerDelegate(QObject* parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
// most of codes taken from QCommonStyle::drawControl() and add our custom text drawer
|
||||
void TabFilterDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
void TabManagerDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
QStyleOptionViewItem opt = option;
|
||||
initStyleOption(&opt, index);
|
||||
|
||||
const QWidget* w = opt.widget;
|
||||
const QStyle* style = w ? w->style() : QApplication::style();
|
||||
const Qt::LayoutDirection direction = w ? w->layoutDirection() : QApplication::layoutDirection();
|
||||
|
||||
const QPalette::ColorRole colorRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text;
|
||||
|
||||
@ -61,6 +62,21 @@ void TabFilterDelegate::paint(QPainter* painter, const QStyleOptionViewItem &opt
|
||||
// draw the background
|
||||
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, w);
|
||||
|
||||
// draw close button
|
||||
if (index.column() == 1) {
|
||||
if (opt.state & QStyle::State_MouseOver) {
|
||||
static const int buttonSize = 16;
|
||||
static const QPixmap closeTabButton(":tabmanager/data/closetab.png");
|
||||
static const QPixmap addTabButton(":tabmanager/data/addtab.png");
|
||||
|
||||
const QRect rect(opt.rect.right() - buttonSize, (opt.rect.height() - buttonSize) / 2 + opt.rect.y(), buttonSize, buttonSize);
|
||||
painter->drawPixmap(style->visualRect(direction, opt.rect, rect), (index.parent().isValid() ? closeTabButton : addTabButton));
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
return;
|
||||
}
|
||||
|
||||
// draw the check mark
|
||||
if (opt.features & QStyleOptionViewItem::HasCheckIndicator) {
|
||||
QStyleOptionViewItem opt2(opt);
|
||||
@ -140,7 +156,7 @@ static QSizeF viewItemTextLayout(QTextLayout &textLayout, int lineWidth)
|
||||
|
||||
// most of codes taken from QCommonStylePrivate::viewItemDrawText()
|
||||
// added highlighting and simplified for single-line textlayouts
|
||||
void TabFilterDelegate::viewItemDrawText(QPainter *p, const QStyleOptionViewItem *option, const QRect &rect,
|
||||
void TabManagerDelegate::viewItemDrawText(QPainter *p, const QStyleOptionViewItem *option, const QRect &rect,
|
||||
const QString &text, const QColor &color, const QString &searchText) const
|
||||
{
|
||||
if (text.isEmpty()) {
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2016 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
||||
* Copyright (C) 2016-2017 S. Razi Alavizadeh <s.r.alavizadeh@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
|
||||
@ -15,15 +15,15 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#ifndef TABFILTERDELEGATE_H
|
||||
#define TABFILTERDELEGATE_H
|
||||
#ifndef TABMANAGERDELEGATE_H
|
||||
#define TABMANAGERDELEGATE_H
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class TabFilterDelegate : public QStyledItemDelegate
|
||||
class TabManagerDelegate : public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
explicit TabFilterDelegate(QObject* parent = 0);
|
||||
explicit TabManagerDelegate(QObject* parent = 0);
|
||||
|
||||
void paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
|
||||
@ -36,4 +36,4 @@ private:
|
||||
|
||||
};
|
||||
|
||||
#endif // TABFILTERDELEGATE_H
|
||||
#endif // TABMANAGERDELEGATE_H
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* TabManager plugin for QupZilla
|
||||
* Copyright (C) 2013-2016 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
||||
* Copyright (C) 2013-2017 S. Razi Alavizadeh <s.r.alavizadeh@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
|
||||
@ -51,7 +51,7 @@ PluginSpec TabManagerPlugin::pluginSpec()
|
||||
spec.name = "Tab Manager";
|
||||
spec.info = "Simple yet powerful tab manager for QupZilla";
|
||||
spec.description = "Adds ability to managing tabs and windows";
|
||||
spec.version = "0.6.0";
|
||||
spec.version = "0.7.0";
|
||||
spec.author = "Razi Alavizadeh <s.r.alavizadeh@gmail.com>";
|
||||
spec.icon = QPixmap(":tabmanager/data/tabmanager.png");
|
||||
spec.hasSettings = true;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* TabManager plugin for QupZilla
|
||||
* Copyright (C) 2013 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
||||
* Copyright (C) 2013-2017 S. Razi Alavizadeh <s.r.alavizadeh@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
|
||||
|
@ -7,6 +7,8 @@
|
||||
<file>data/tab-loading.png</file>
|
||||
<file>data/tab-pinned.png</file>
|
||||
<file>data/side-by-side.png</file>
|
||||
<file>data/closetab.png</file>
|
||||
<file>data/addtab.png</file>
|
||||
<file>locale/ar_SA.qm</file>
|
||||
<file>locale/bg_BG.qm</file>
|
||||
<file>locale/ca_ES.qm</file>
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* TabManager plugin for QupZilla
|
||||
* Copyright (C) 2013-2016 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
||||
* Copyright (C) 2013-2017 S. Razi Alavizadeh <s.r.alavizadeh@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
|
||||
@ -29,7 +29,7 @@
|
||||
#include "bookmarks.h"
|
||||
#include "tabmanagerplugin.h"
|
||||
#include "tldextractor/tldextractor.h"
|
||||
#include "tabfilterdelegate.h"
|
||||
#include "tabmanagerdelegate.h"
|
||||
|
||||
|
||||
#include <QDesktopWidget>
|
||||
@ -59,6 +59,14 @@ TabManagerWidget::TabManagerWidget(BrowserWindow* mainClass, QWidget* parent, bo
|
||||
}
|
||||
|
||||
ui->setupUi(this);
|
||||
ui->treeWidget->setUniformRowHeights(true);
|
||||
ui->treeWidget->setColumnCount(2);
|
||||
ui->treeWidget->header()->hide();
|
||||
ui->treeWidget->header()->setStretchLastSection(false);
|
||||
ui->treeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
ui->treeWidget->header()->setSectionResizeMode(1, QHeaderView::Fixed);
|
||||
ui->treeWidget->header()->resizeSection(1, 16);
|
||||
|
||||
ui->treeWidget->setExpandsOnDoubleClick(false);
|
||||
ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
@ -71,11 +79,11 @@ TabManagerWidget::TabManagerWidget(BrowserWindow* mainClass, QWidget* parent, bo
|
||||
ui->filterBar->addWidget(closeButton, LineEdit::RightSide);
|
||||
ui->filterBar->hide();
|
||||
|
||||
ui->treeWidget->setItemDelegate(new TabFilterDelegate(ui->treeWidget));
|
||||
ui->treeWidget->setItemDelegate(new TabManagerDelegate(ui->treeWidget));
|
||||
|
||||
connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(filterBarClosed()));
|
||||
connect(ui->filterBar, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString)));
|
||||
connect(ui->treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(itemDoubleClick(QTreeWidgetItem*,int)));
|
||||
connect(ui->treeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(onItemActivated(QTreeWidgetItem*,int)));
|
||||
connect(ui->treeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested(QPoint)));
|
||||
}
|
||||
|
||||
@ -201,7 +209,7 @@ void TabManagerWidget::refreshTree()
|
||||
m_waitForRefresh = false;
|
||||
}
|
||||
|
||||
void TabManagerWidget::itemDoubleClick(QTreeWidgetItem* item, int)
|
||||
void TabManagerWidget::onItemActivated(QTreeWidgetItem* item, int column)
|
||||
{
|
||||
if (!item) {
|
||||
return;
|
||||
@ -214,6 +222,14 @@ void TabManagerWidget::itemDoubleClick(QTreeWidgetItem* item, int)
|
||||
return;
|
||||
}
|
||||
|
||||
if (column == 1) {
|
||||
if (item->childCount() == 0 && tabWidget)
|
||||
mainWindow->tabWidget()->requestCloseTab(mainWindow->tabWidget()->indexOf(tabWidget));
|
||||
else if (item->childCount() > 0)
|
||||
QMetaObject::invokeMethod(mainWindow, "addTab");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainWindow->isMinimized()) {
|
||||
mainWindow->showNormal();
|
||||
}
|
||||
@ -345,7 +361,7 @@ bool TabManagerWidget::eventFilter(QObject* obj, QEvent* event)
|
||||
if (obj == ui->treeWidget) {
|
||||
// switch to tab/window on enter
|
||||
if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) {
|
||||
itemDoubleClick(ui->treeWidget->currentItem(), 0);
|
||||
onItemActivated(ui->treeWidget->currentItem(), 0);
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
@ -377,6 +393,9 @@ bool TabManagerWidget::eventFilter(QObject* obj, QEvent* event)
|
||||
}
|
||||
}
|
||||
|
||||
if (obj == ui->treeWidget && (event->type() == QEvent::Resize || event->type() == QEvent::Show))
|
||||
ui->treeWidget->setColumnHidden(1, ui->treeWidget->viewport()->width() < 150);
|
||||
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* TabManager plugin for QupZilla
|
||||
* Copyright (C) 2013-2016 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
||||
* Copyright (C) 2013-2017 S. Razi Alavizadeh <s.r.alavizadeh@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
|
||||
@ -91,7 +91,7 @@ private:
|
||||
private slots:
|
||||
void refreshTree();
|
||||
void processActions();
|
||||
void itemDoubleClick(QTreeWidgetItem* item, int);
|
||||
void onItemActivated(QTreeWidgetItem* item, int column);
|
||||
bool isTabSelected();
|
||||
void customContextMenuRequested(const QPoint &pos);
|
||||
void filterChanged(const QString &filter, bool force = false);
|
||||
|
Loading…
Reference in New Issue
Block a user