mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
TabManager: show close button on tab item under mouse.
This commit is contained in:
parent
56c737d836
commit
3a7e843677
|
@ -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
|
||||
|
@ -35,6 +35,7 @@ void TabFilterDelegate::paint(QPainter* painter, const QStyleOptionViewItem &opt
|
|||
|
||||
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 (index.parent().isValid() && opt.state & QStyle::State_MouseOver) {
|
||||
static const int buttonSize = 16;
|
||||
static const QPixmap closeButton = style->standardIcon(QStyle::SP_TitleBarCloseButton)
|
||||
.pixmap(buttonSize, buttonSize).scaled(buttonSize, buttonSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
|
||||
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), closeButton);
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
return;
|
||||
}
|
||||
|
||||
// draw the check mark
|
||||
if (opt.features & QStyleOptionViewItem::HasCheckIndicator) {
|
||||
QStyleOptionViewItem opt2(opt);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -201,7 +209,7 @@ void TabManagerWidget::refreshTree()
|
|||
m_waitForRefresh = false;
|
||||
}
|
||||
|
||||
void TabManagerWidget::onItemActivated(QTreeWidgetItem* item, int)
|
||||
void TabManagerWidget::onItemActivated(QTreeWidgetItem* item, int column)
|
||||
{
|
||||
if (!item) {
|
||||
return;
|
||||
|
@ -214,6 +222,11 @@ void TabManagerWidget::onItemActivated(QTreeWidgetItem* item, int)
|
|||
return;
|
||||
}
|
||||
|
||||
if (column == 1 && item->childCount() == 0 && tabWidget) {
|
||||
mainWindow->tabWidget()->requestCloseTab(mainWindow->tabWidget()->indexOf(tabWidget));
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainWindow->isMinimized()) {
|
||||
mainWindow->showNormal();
|
||||
}
|
||||
|
@ -377,6 +390,9 @@ bool TabManagerWidget::eventFilter(QObject* obj, QEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
if (obj == ui->treeWidget && event->type() == QEvent::Resize)
|
||||
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 onItemActivated(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