Libksieve

sievescripttabwidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
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 
16 using namespace KSieveUi;
17 
18 SieveScriptTabWidget::SieveScriptTabWidget(QWidget *parent)
19  : QTabWidget(parent)
20 {
21  setElideMode(Qt::ElideRight);
22  tabBar()->setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab);
23  setDocumentMode(true);
25  connect(this, &SieveScriptTabWidget::customContextMenuRequested, this, &SieveScriptTabWidget::slotTabContextMenuRequest);
26 }
27 
28 SieveScriptTabWidget::~SieveScriptTabWidget()
29 {
30 }
31 
32 void SieveScriptTabWidget::slotTabContextMenuRequest(const QPoint &pos)
33 {
34  QTabBar *bar = tabBar();
35  const int indexBar = bar->tabAt(bar->mapFrom(this, pos));
36  QWidget *w = widget(indexBar);
37  if (!w) {
38  return;
39  }
40 
41  auto page = qobject_cast<SieveWidgetPageAbstract *>(w);
42  if (!page) {
43  return;
44  }
45  if ((page->pageType() == SieveWidgetPageAbstract::BlockElsIf) || page->pageType() == SieveWidgetPageAbstract::BlockElse) {
46  QMenu menu(this);
47  QAction *closeTab = menu.addAction(i18nc("@action:inmenu", "Close Tab"));
48  closeTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-close")));
49 
50  QAction *action = menu.exec(mapToGlobal(pos));
51 
52  if (action == closeTab) {
53  Q_EMIT tabCloseRequested(indexBar);
54  }
55  }
56 }
void setIcon(const QIcon &icon)
QPoint mapToGlobal(const QPoint &pos) const const
CustomContextMenu
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QPoint pos() const const
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
ElideRight
int tabAt(const QPoint &position) const const
QIcon fromTheme(const QString &name)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
T qobject_cast(QObject *object)
Q_EMITQ_EMIT
QPoint mapFrom(const QWidget *parent, const QPoint &pos) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Apr 11 2021 23:09:37 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.