swift
menudelegate.h
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #ifndef SWIFT_GUI_MENUS_MENUDELEGATE_H
5 #define SWIFT_GUI_MENUS_MENUDELEGATE_H
6 
7 #include <QMenu>
8 #include <QObject>
9 
10 #include "gui/menus/menuaction.h"
11 #include "misc/logcategories.h"
12 
13 class QWidget;
14 
15 namespace swift::gui::menus
16 {
20  class IMenuDelegate : public QObject
21  {
22  Q_OBJECT
23 
24  public:
26  virtual void customMenu(CMenuActions &menuActions) = 0;
27 
29  void setNestedDelegate(IMenuDelegate *nestedDelegate) { m_nestedDelegate = nestedDelegate; }
30 
33 
35  virtual ~IMenuDelegate() {}
36 
38  const QStringList &getLogCategories()
39  {
40  static const QStringList cats({ swift::misc::CLogCategories::guiComponent() });
41  return cats;
42  }
43 
44  protected:
46  IMenuDelegate(QWidget *parent = nullptr) : QObject(parent) {}
47 
49  void nestedCustomMenu(CMenuActions &menuActions) const
50  {
51  if (!m_nestedDelegate) { return; }
52  m_nestedDelegate->customMenu(menuActions);
53  }
54 
56  bool previousMenuItemContains(const QString &str, const QMenu &menu,
57  Qt::CaseSensitivity cs = Qt::CaseSensitive) const
58  {
59  if (menu.isEmpty() || str.isEmpty()) { return false; }
60  const QString t(menu.actions().last()->text());
61  return t.contains(str, cs);
62  }
63 
65  };
66 } // namespace swift::gui::menus
67 
68 #endif // SWIFT_GUI_MENUS_MENUDELEGATE_H
Bunch of CMenuAction objects.
Definition: menuaction.h:384
Interface to implement a custom menu.
Definition: menudelegate.h:21
IMenuDelegate * getNestedDelegate() const
Nested delegate.
Definition: menudelegate.h:32
virtual void customMenu(CMenuActions &menuActions)=0
Display custom menu.
const QStringList & getLogCategories()
Log categories.
Definition: menudelegate.h:38
virtual ~IMenuDelegate()
Destructor.
Definition: menudelegate.h:35
bool previousMenuItemContains(const QString &str, const QMenu &menu, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Does the previous (menu) item contain string?
Definition: menudelegate.h:56
void nestedCustomMenu(CMenuActions &menuActions) const
Delegate down one level.
Definition: menudelegate.h:49
IMenuDelegate(QWidget *parent=nullptr)
Constructor.
Definition: menudelegate.h:46
void setNestedDelegate(IMenuDelegate *nestedDelegate)
Set nested delegate.
Definition: menudelegate.h:29
IMenuDelegate * m_nestedDelegate
nested delegate if any
Definition: menudelegate.h:64
static const QString & guiComponent()
GUI components.
Definition: logcategories.h:94