2 Copyright (c) 2013-2016 Montel Laurent <montel@kde.org>
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License, version 2, as
6 published by the Free Software Foundation.
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #include "poststabwidget.h"
20 #include <KLocalizedString>
24 #include <QToolButton>
27 PostsTabWidget::PostsTabWidget(QWidget
*parent
)
30 setElideMode(Qt::ElideRight
);
31 setTabsClosable(true);
32 tabBar()->setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab
);
33 setDocumentMode(true);
37 mNewTabButton
= new QToolButton(this);
38 mNewTabButton
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
39 mNewTabButton
->adjustSize();
40 mNewTabButton
->setToolTip(i18nc("@info:tooltip", "Open a new tab"));
41 #ifndef QT_NO_ACCESSIBILITY
42 mNewTabButton
->setAccessibleName(i18n("New tab"));
44 setCornerWidget(mNewTabButton
, Qt::TopLeftCorner
);
45 connect(mNewTabButton
, &QToolButton::clicked
, this, &PostsTabWidget::createNewPost
);
47 mCloseTabButton
= new QToolButton(this);
48 mCloseTabButton
->setIcon(QIcon::fromTheme(QStringLiteral("tab-close")));
49 mCloseTabButton
->adjustSize();
50 mCloseTabButton
->setToolTip(i18nc("@info:tooltip", "Close the current tab"));
51 #ifndef QT_NO_ACCESSIBILITY
52 mCloseTabButton
->setAccessibleName(i18n("Close tab"));
54 setCornerWidget(mCloseTabButton
, Qt::TopRightCorner
);
55 connect(mCloseTabButton
, &QToolButton::clicked
, this, &PostsTabWidget::closeTabClicked
);
57 setContextMenuPolicy(Qt::CustomContextMenu
);
58 connect(this, &PostsTabWidget::customContextMenuRequested
, this, &PostsTabWidget::slotTabContextMenuRequest
);
61 PostsTabWidget::~PostsTabWidget()
65 void PostsTabWidget::slotTabContextMenuRequest(const QPoint
&pos
)
67 QTabBar
*bar
= tabBar();
72 const int indexBar
= bar
->tabAt(bar
->mapFrom(this, pos
));
78 QAction
*closeTab
= menu
.addAction(i18nc("@action:inmenu", "Close Tab"));
79 closeTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-close")));
81 QAction
*allOther
= menu
.addAction(i18nc("@action:inmenu", "Close All Other Tabs"));
82 allOther
->setEnabled(count() > 1);
83 allOther
->setIcon(QIcon::fromTheme(QStringLiteral("tab-close-other")));
85 QAction
*action
= menu
.exec(mapToGlobal(pos
));
87 if (action
== allOther
) { // Close all other tabs
88 Q_EMIT
tabRemoveAllExclude(indexBar
);
89 } else if (action
== closeTab
) {
90 Q_EMIT
tabCloseRequested(indexBar
);