diff --git a/src/plugins/TabManager/TabManager.pro b/src/plugins/TabManager/TabManager.pro index 7ede630bf..a80a2feac 100644 --- a/src/plugins/TabManager/TabManager.pro +++ b/src/plugins/TabManager/TabManager.pro @@ -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 diff --git a/src/plugins/TabManager/data/addtab.png b/src/plugins/TabManager/data/addtab.png new file mode 100644 index 000000000..4dd036574 Binary files /dev/null and b/src/plugins/TabManager/data/addtab.png differ diff --git a/src/plugins/TabManager/data/closetab.png b/src/plugins/TabManager/data/closetab.png new file mode 100644 index 000000000..e3db6da5b Binary files /dev/null and b/src/plugins/TabManager/data/closetab.png differ diff --git a/src/plugins/TabManager/tabfilterdelegate.cpp b/src/plugins/TabManager/tabmanagerdelegate.cpp similarity index 89% rename from src/plugins/TabManager/tabfilterdelegate.cpp rename to src/plugins/TabManager/tabmanagerdelegate.cpp index 816a6f56b..21add9118 100644 --- a/src/plugins/TabManager/tabfilterdelegate.cpp +++ b/src/plugins/TabManager/tabmanagerdelegate.cpp @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - Qt web browser -* Copyright (C) 2016 S. Razi Alavizadeh +* Copyright (C) 2016-2017 S. Razi Alavizadeh * Copyright (C) 2017 David Rosca * * 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 . * ============================================================ */ -#include "tabfilterdelegate.h" +#include "tabmanagerdelegate.h" #include #include #include -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()) { diff --git a/src/plugins/TabManager/tabfilterdelegate.h b/src/plugins/TabManager/tabmanagerdelegate.h similarity index 81% rename from src/plugins/TabManager/tabfilterdelegate.h rename to src/plugins/TabManager/tabmanagerdelegate.h index 449a295a3..5b76db256 100644 --- a/src/plugins/TabManager/tabfilterdelegate.h +++ b/src/plugins/TabManager/tabmanagerdelegate.h @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - WebKit based browser -* Copyright (C) 2016 S. Razi Alavizadeh +* Copyright (C) 2016-2017 S. Razi Alavizadeh * * 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 . * ============================================================ */ -#ifndef TABFILTERDELEGATE_H -#define TABFILTERDELEGATE_H +#ifndef TABMANAGERDELEGATE_H +#define TABMANAGERDELEGATE_H #include -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 diff --git a/src/plugins/TabManager/tabmanagerplugin.cpp b/src/plugins/TabManager/tabmanagerplugin.cpp index abc3f13e1..98c7512f1 100644 --- a/src/plugins/TabManager/tabmanagerplugin.cpp +++ b/src/plugins/TabManager/tabmanagerplugin.cpp @@ -1,6 +1,6 @@ /* ============================================================ * TabManager plugin for QupZilla -* Copyright (C) 2013-2016 S. Razi Alavizadeh +* Copyright (C) 2013-2017 S. Razi Alavizadeh * * 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 "; spec.icon = QPixmap(":tabmanager/data/tabmanager.png"); spec.hasSettings = true; diff --git a/src/plugins/TabManager/tabmanagerplugin.h b/src/plugins/TabManager/tabmanagerplugin.h index bf0b70d3f..b0a410485 100644 --- a/src/plugins/TabManager/tabmanagerplugin.h +++ b/src/plugins/TabManager/tabmanagerplugin.h @@ -1,6 +1,6 @@ /* ============================================================ * TabManager plugin for QupZilla -* Copyright (C) 2013 S. Razi Alavizadeh +* Copyright (C) 2013-2017 S. Razi Alavizadeh * * 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 diff --git a/src/plugins/TabManager/tabmanagerplugin.qrc b/src/plugins/TabManager/tabmanagerplugin.qrc index 7fd730ece..357dde820 100644 --- a/src/plugins/TabManager/tabmanagerplugin.qrc +++ b/src/plugins/TabManager/tabmanagerplugin.qrc @@ -7,6 +7,8 @@ data/tab-loading.png data/tab-pinned.png data/side-by-side.png + data/closetab.png + data/addtab.png locale/ar_SA.qm locale/bg_BG.qm locale/ca_ES.qm diff --git a/src/plugins/TabManager/tabmanagerwidget.cpp b/src/plugins/TabManager/tabmanagerwidget.cpp index 541a992e4..f65e69459 100644 --- a/src/plugins/TabManager/tabmanagerwidget.cpp +++ b/src/plugins/TabManager/tabmanagerwidget.cpp @@ -1,6 +1,6 @@ /* ============================================================ * TabManager plugin for QupZilla -* Copyright (C) 2013-2016 S. Razi Alavizadeh +* Copyright (C) 2013-2017 S. Razi Alavizadeh * * 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 @@ -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); } diff --git a/src/plugins/TabManager/tabmanagerwidget.h b/src/plugins/TabManager/tabmanagerwidget.h index ad6e64d49..a2918f25f 100644 --- a/src/plugins/TabManager/tabmanagerwidget.h +++ b/src/plugins/TabManager/tabmanagerwidget.h @@ -1,6 +1,6 @@ /* ============================================================ * TabManager plugin for QupZilla -* Copyright (C) 2013-2016 S. Razi Alavizadeh +* Copyright (C) 2013-2017 S. Razi Alavizadeh * * 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);