Added close buttons to "closable" tabs.

This commit is contained in:
Martin Rotter 2014-01-19 12:22:50 +01:00
parent 0c26e31f29
commit a455d21356
4 changed files with 58 additions and 7 deletions

View File

@ -16,6 +16,49 @@ TabBar::~TabBar() {
qDebug("Destroying TabBar instance.");
}
void TabBar::setTabType(int index, const TabBar::TabType &type) {
switch (type) {
case TabBar::Closable: {
QToolButton *close_button = new QToolButton();
close_button->setIcon(IconThemeFactory::instance()->fromTheme("application-exit"));
close_button->setToolTip(tr("Close this tab."));
close_button->setText(tr("Close tab"));
close_button->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
close_button->setFixedSize(iconSize());
connect(close_button, SIGNAL(clicked()),
this, SLOT(closeTabViaButton()));
setTabButton(index, QTabBar::RightSide, close_button);
break;
}
case TabBar::NonClosable:
case TabBar::FeedReader:
default:
setTabButton(index, QTabBar::RightSide, 0);
break;
}
setTabData(index, QVariant(type));
}
void TabBar::closeTabViaButton() {
QToolButton *close_button = qobject_cast<QToolButton*>(sender());
if (close_button != NULL) {
// Find index of tab for this close button.
for (int i = 0; i < count(); i++) {
if (tabButton(i, QTabBar::RightSide) == close_button) {
emit tabCloseRequested(i);
return;
}
}
}
}
void TabBar::wheelEvent(QWheelEvent *event) {
int current_index = currentIndex();
int number_of_tabs = count();

View File

@ -1,8 +1,11 @@
#ifndef TABBAR_H
#define TABBAR_H
#include "gui/iconthemefactory.h"
#include <QTabBar>
#include <QVariant>
#include <QToolButton>
class TabBar : public QTabBar {
@ -20,14 +23,16 @@ class TabBar : public QTabBar {
virtual ~TabBar();
// Getter/setter for tab type.
inline void setTabType(int index, const TabBar::TabType &type) {
setTabData(index, QVariant(type));
}
void setTabType(int index, const TabBar::TabType &type);
inline TabBar::TabType tabType(int index) {
return static_cast<TabBar::TabType>(tabData(index).value<int>());
}
protected slots:
// Called when user selects to close tab via close button.
void closeTabViaButton();
protected:
// Reimplementations.
void mouseDoubleClickEvent(QMouseEvent *event);
@ -36,7 +41,7 @@ class TabBar : public QTabBar {
signals:
// Emmited if empty space on tab bar is double clicked.
void emptySpaceDoubleClicked();
void emptySpaceDoubleClicked();
};
#endif // TABBAR_H

View File

@ -16,6 +16,8 @@
TabWidget::TabWidget(QWidget *parent) : QTabWidget(parent) {
setTabBar(new TabBar(this));
setupCornerButton();
//setTabsClosable(true);
createConnections();
}
@ -52,8 +54,6 @@ void TabWidget::createConnections() {
connect(tabBar(), SIGNAL(currentChanged(int)), this, SLOT(fixContentAfterIndexChange(int)));
}
void TabWidget::initializeTabs() {
// Create widget for "Feeds" page and add it.
m_feedMessageViewer = new FeedMessageViewer(this);

View File

@ -23,6 +23,9 @@
#include <QDebug>
// TODO: lepsi paint bez framu balloontip
// http://windowdetective.sourceforge.net/files/Window%20Detective/src/ui/custom_widgets/BalloonTip.cpp
// TODO: Check if extra UNIX signalling is needed.
// Use <csignal> header for it - signal function and catch SIGHUP
// void my_terminate (int param) {