Libksieve

sievescripttabwidget.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "sievescripttabwidget.h"
8#include "sievewidgetpageabstract.h"
9
10#include <KLocalizedString>
11#include <QIcon>
12#include <QMenu>
13
14#include <QTabBar>
15
16using namespace KSieveUi;
17
18SieveScriptTabWidget::SieveScriptTabWidget(QWidget *parent)
19 : QTabWidget(parent)
20{
21 setElideMode(Qt::ElideRight);
22 tabBar()->setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab);
23 setDocumentMode(true);
24 setContextMenuPolicy(Qt::CustomContextMenu);
25 connect(this, &SieveScriptTabWidget::customContextMenuRequested, this, &SieveScriptTabWidget::slotTabContextMenuRequest);
26}
27
28SieveScriptTabWidget::~SieveScriptTabWidget() = default;
29
30void SieveScriptTabWidget::slotTabContextMenuRequest(const QPoint &pos)
31{
32 QTabBar *bar = tabBar();
33 const int indexBar = bar->tabAt(bar->mapFrom(this, pos));
34 QWidget *w = widget(indexBar);
35 if (!w) {
36 return;
37 }
38
40 if (!page) {
41 return;
42 }
43 if ((page->pageType() == SieveWidgetPageAbstract::BlockElsIf) || page->pageType() == SieveWidgetPageAbstract::BlockElse) {
44 QMenu menu(this);
45 QAction *closeTab = menu.addAction(i18nc("@action:inmenu", "Close Tab"));
46 closeTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-close")));
47
48 QAction *action = menu.exec(mapToGlobal(pos));
49
50 if (action == closeTab) {
51 Q_EMIT tabCloseRequested(indexBar);
52 }
53 }
54}
55
56#include "moc_sievescripttabwidget.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setIcon(const QIcon &icon)
QIcon fromTheme(const QString &name)
Q_EMITQ_EMIT
T qobject_cast(QObject *object)
CustomContextMenu
ElideRight
int tabAt(const QPoint &position) const const
QTabBar * tabBar() const const
void tabCloseRequested(int index)
QWidget * widget(int index) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QPoint mapFrom(const QWidget *parent, const QPoint &pos) const const
QPoint mapToGlobal(const QPoint &pos) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.