From 091463e51f70f374dbe39daa0b862ad623bf753e Mon Sep 17 00:00:00 2001 From: Victor Tran Date: Thu, 14 Sep 2023 20:16:25 +1000 Subject: [PATCH] Add tTouchBarActionItem --- lib/CMakeLists.txt | 2 ++ lib/touchbar/ttouchbar.cpp | 3 +++ lib/touchbar/ttouchbar.h | 3 +++ lib/touchbar/ttouchbar_objc.mm | 11 ++++++++ lib/touchbar/ttouchbaractionitem.cpp | 39 ++++++++++++++++++++++++++++ lib/touchbar/ttouchbaractionitem.h | 26 +++++++++++++++++++ lib/translations/ar_SA.ts | 8 ++++++ lib/translations/bg.ts | 8 ++++++ lib/translations/cs_CZ.ts | 8 ++++++ lib/translations/cy_GB.ts | 8 ++++++ lib/translations/da_DK.ts | 8 ++++++ lib/translations/de_DE.ts | 8 ++++++ lib/translations/en_GB.ts | 8 ++++++ lib/translations/en_US.ts | 8 ++++++ lib/translations/fr_CA.ts | 8 ++++++ lib/translations/he_IL.ts | 8 ++++++ lib/translations/id_ID.ts | 8 ++++++ lib/translations/ja_JP.ts | 8 ++++++ lib/translations/nl_NL.ts | 8 ++++++ lib/translations/pl_PL.ts | 8 ++++++ lib/translations/pt_BR.ts | 8 ++++++ lib/translations/ro_RO.ts | 8 ++++++ lib/translations/sl_SI.ts | 8 ++++++ lib/translations/ta.ts | 8 ++++++ lib/translations/th_TH.ts | 8 ++++++ lib/translations/tr_TR.ts | 8 ++++++ lib/translations/ur_PK.ts | 8 ++++++ lib/translations/vi_VN.ts | 8 ++++++ lib/translations/zh_CN.ts | 8 ++++++ 29 files changed, 268 insertions(+) create mode 100644 lib/touchbar/ttouchbaractionitem.cpp create mode 100644 lib/touchbar/ttouchbaractionitem.h diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f11ef21..26b8db3 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -119,6 +119,7 @@ cntp_sourcelist( touchbar/ttouchbarsegmentedcontrolitem.cpp touchbar/ttouchbarlabelitem.cpp touchbar/tcompositetouchbar.cpp + touchbar/ttouchbaractionitem.cpp touchbar/ttouchbargroupitem.cpp taboutdialog.ui @@ -214,6 +215,7 @@ cntp_sourcelist( touchbar/tcompositetouchbar.h touchbar/ttouchbargroupitem.h touchbar/ttouchbardialogalertitem.h + touchbar/ttouchbaractionitem.h touchbar/ttouchbar_forwarddeclares.h tsettingswindow/tsettingswindow.h diff --git a/lib/touchbar/ttouchbar.cpp b/lib/touchbar/ttouchbar.cpp index e944876..bddb022 100644 --- a/lib/touchbar/ttouchbar.cpp +++ b/lib/touchbar/ttouchbar.cpp @@ -62,4 +62,7 @@ void tTouchBar::invalidateTouchBar() { NSTouchBar* tTouchBar::makeTouchBar() { return nullptr; } + +void tTouchBar::addCustomizationMenuItem(QMenu* menu) { +} #endif diff --git a/lib/touchbar/ttouchbar.h b/lib/touchbar/ttouchbar.h index 9299a46..773c6fb 100644 --- a/lib/touchbar/ttouchbar.h +++ b/lib/touchbar/ttouchbar.h @@ -11,12 +11,15 @@ struct tTouchBarPrivate; class tTouchBarPopoverItem; class tTouchBarGroupItem; class QAction; +class QMenu; class tTouchBar : public QObject { Q_OBJECT public: explicit tTouchBar(QObject* parent = nullptr); ~tTouchBar(); + static void addCustomizationMenuItem(QMenu* menu); + virtual void attach(QWidget* widget); virtual void detach(); diff --git a/lib/touchbar/ttouchbar_objc.mm b/lib/touchbar/ttouchbar_objc.mm index 6f7e8b4..ef3bef5 100644 --- a/lib/touchbar/ttouchbar_objc.mm +++ b/lib/touchbar/ttouchbar_objc.mm @@ -5,6 +5,7 @@ #include "private/ttouchbar_p.h" #include "ranges/trange.h" #include +#include @interface TTouchBarMainWindowDelegate: NSResponder @property QWidget* parent; @@ -145,3 +146,13 @@ - (void)forwardInvocation: (NSInvocation *)invocation { { return [d->delegate makeTouchBar]; } + + +void tTouchBar::addCustomizationMenuItem(QMenu *menu) +{ + NSMenuItem *customizeTouchBarItem = [[NSMenuItem alloc] initWithTitle:tr("Customize Touch Bar...").toNSString() + action:@selector(toggleTouchBarCustomizationPalette:) + keyEquivalent:@""]; + [customizeTouchBarItem setTarget:nil]; + [menu->toNSMenu() addItem:customizeTouchBarItem]; +} diff --git a/lib/touchbar/ttouchbaractionitem.cpp b/lib/touchbar/ttouchbaractionitem.cpp new file mode 100644 index 0000000..4760267 --- /dev/null +++ b/lib/touchbar/ttouchbaractionitem.cpp @@ -0,0 +1,39 @@ +#include "ttouchbaractionitem.h" + +#include + +struct tTouchBarActionItemPrivate { + QAction* action; + QIcon icon; +}; + +tTouchBarActionItem::tTouchBarActionItem(QString identifier, QAction* action, QString customizationLabel, QIcon icon, QObject* parent) : + tTouchBarButtonItem{identifier, customizationLabel.isEmpty() ? action->text() : customizationLabel, parent} { + d = new tTouchBarActionItemPrivate(); + d->action = action; + d->icon = icon; + + connect(action, &QAction::changed, this, &tTouchBarActionItem::updateItem); + connect(action, &QAction::enabledChanged, this, &tTouchBarActionItem::setEnabled); + connect(this, &tTouchBarActionItem::clicked, action, &QAction::trigger); + + this->updateItem(); +} + +tTouchBarActionItem::~tTouchBarActionItem() { + delete d; +} + +void tTouchBarActionItem::setTouchBarIcon(QIcon touchBarIcon) { + d->icon = touchBarIcon; + this->updateItem(); +} + +QIcon tTouchBarActionItem::touchBarIcon() { + return d->icon; +} + +void tTouchBarActionItem::updateItem() { + this->setText(d->action->text()); + this->setIcon(d->icon.isNull() ? d->action->icon() : d->icon); +} diff --git a/lib/touchbar/ttouchbaractionitem.h b/lib/touchbar/ttouchbaractionitem.h new file mode 100644 index 0000000..8b52220 --- /dev/null +++ b/lib/touchbar/ttouchbaractionitem.h @@ -0,0 +1,26 @@ +#ifndef TTOUCHBARACTIONITEM_H +#define TTOUCHBARACTIONITEM_H + +#include "ttouchbarbuttonitem.h" +#include + +class QAction; +struct tTouchBarActionItemPrivate; +class tTouchBarActionItem : public tTouchBarButtonItem { + Q_OBJECT + public: + explicit tTouchBarActionItem(QString identifier, QAction* action, QString customizationLabel = "", QIcon icon = {}, QObject* parent = nullptr); + ~tTouchBarActionItem(); + + void setTouchBarIcon(QIcon touchBarIcon); + QIcon touchBarIcon(); + + signals: + + private: + tTouchBarActionItemPrivate* d; + + void updateItem(); +}; + +#endif // TTOUCHBARACTIONITEM_H diff --git a/lib/translations/ar_SA.ts b/lib/translations/ar_SA.ts index 1d59275..cd02fe7 100644 --- a/lib/translations/ar_SA.ts +++ b/lib/translations/ar_SA.ts @@ -812,6 +812,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/bg.ts b/lib/translations/bg.ts index b6235fb..6890ca3 100644 --- a/lib/translations/bg.ts +++ b/lib/translations/bg.ts @@ -801,6 +801,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/cs_CZ.ts b/lib/translations/cs_CZ.ts index 1a2fbce..0855619 100644 --- a/lib/translations/cs_CZ.ts +++ b/lib/translations/cs_CZ.ts @@ -837,6 +837,14 @@ Nastavení + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/cy_GB.ts b/lib/translations/cy_GB.ts index be9f2e4..814bed8 100644 --- a/lib/translations/cy_GB.ts +++ b/lib/translations/cy_GB.ts @@ -805,6 +805,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/da_DK.ts b/lib/translations/da_DK.ts index ff2d924..67dfe9c 100644 --- a/lib/translations/da_DK.ts +++ b/lib/translations/da_DK.ts @@ -812,6 +812,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/de_DE.ts b/lib/translations/de_DE.ts index f5df0ff..6b12d8b 100644 --- a/lib/translations/de_DE.ts +++ b/lib/translations/de_DE.ts @@ -812,6 +812,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/en_GB.ts b/lib/translations/en_GB.ts index 19c480d..3679135 100644 --- a/lib/translations/en_GB.ts +++ b/lib/translations/en_GB.ts @@ -812,6 +812,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/en_US.ts b/lib/translations/en_US.ts index 9a030b4..8e3eb7f 100644 --- a/lib/translations/en_US.ts +++ b/lib/translations/en_US.ts @@ -801,6 +801,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/fr_CA.ts b/lib/translations/fr_CA.ts index 262e08d..4906426 100644 --- a/lib/translations/fr_CA.ts +++ b/lib/translations/fr_CA.ts @@ -837,6 +837,14 @@ Paramètres + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/he_IL.ts b/lib/translations/he_IL.ts index 6d7d222..6cd94da 100644 --- a/lib/translations/he_IL.ts +++ b/lib/translations/he_IL.ts @@ -837,6 +837,14 @@ הגדרות + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/id_ID.ts b/lib/translations/id_ID.ts index 77953af..1b032f2 100644 --- a/lib/translations/id_ID.ts +++ b/lib/translations/id_ID.ts @@ -805,6 +805,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/ja_JP.ts b/lib/translations/ja_JP.ts index dce6666..390008c 100644 --- a/lib/translations/ja_JP.ts +++ b/lib/translations/ja_JP.ts @@ -801,6 +801,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/nl_NL.ts b/lib/translations/nl_NL.ts index 8bb1c55..2e14ef6 100644 --- a/lib/translations/nl_NL.ts +++ b/lib/translations/nl_NL.ts @@ -812,6 +812,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/pl_PL.ts b/lib/translations/pl_PL.ts index 16b2946..d1fbd10 100644 --- a/lib/translations/pl_PL.ts +++ b/lib/translations/pl_PL.ts @@ -801,6 +801,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/pt_BR.ts b/lib/translations/pt_BR.ts index 1ab9bb3..24973e2 100644 --- a/lib/translations/pt_BR.ts +++ b/lib/translations/pt_BR.ts @@ -805,6 +805,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/ro_RO.ts b/lib/translations/ro_RO.ts index f4937c0..bcea0d1 100644 --- a/lib/translations/ro_RO.ts +++ b/lib/translations/ro_RO.ts @@ -817,6 +817,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/sl_SI.ts b/lib/translations/sl_SI.ts index 2928893..02bb4c0 100644 --- a/lib/translations/sl_SI.ts +++ b/lib/translations/sl_SI.ts @@ -812,6 +812,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/ta.ts b/lib/translations/ta.ts index d87b3e4..91fc2a5 100644 --- a/lib/translations/ta.ts +++ b/lib/translations/ta.ts @@ -838,6 +838,14 @@ அமைப்புகள் + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/th_TH.ts b/lib/translations/th_TH.ts index 973f38a..37f9fa2 100644 --- a/lib/translations/th_TH.ts +++ b/lib/translations/th_TH.ts @@ -812,6 +812,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/tr_TR.ts b/lib/translations/tr_TR.ts index 1a47a41..3a092a1 100644 --- a/lib/translations/tr_TR.ts +++ b/lib/translations/tr_TR.ts @@ -812,6 +812,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/ur_PK.ts b/lib/translations/ur_PK.ts index 4684c37..5286360 100644 --- a/lib/translations/ur_PK.ts +++ b/lib/translations/ur_PK.ts @@ -801,6 +801,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/vi_VN.ts b/lib/translations/vi_VN.ts index 99b2ee9..1e2af7b 100644 --- a/lib/translations/vi_VN.ts +++ b/lib/translations/vi_VN.ts @@ -844,6 +844,14 @@ Cài đặt + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber diff --git a/lib/translations/zh_CN.ts b/lib/translations/zh_CN.ts index faba0e6..f5fb169 100644 --- a/lib/translations/zh_CN.ts +++ b/lib/translations/zh_CN.ts @@ -805,6 +805,14 @@ + + tTouchBar + + + Customize Touch Bar... + + + tWindowTabber