Skip to content

Commit

Permalink
Add tTouchBarActionItem
Browse files Browse the repository at this point in the history
  • Loading branch information
vicr123 committed Sep 14, 2023
1 parent a5f6a23 commit 091463e
Show file tree
Hide file tree
Showing 29 changed files with 268 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ cntp_sourcelist(
touchbar/ttouchbarsegmentedcontrolitem.cpp
touchbar/ttouchbarlabelitem.cpp
touchbar/tcompositetouchbar.cpp
touchbar/ttouchbaractionitem.cpp
touchbar/ttouchbargroupitem.cpp

taboutdialog.ui
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/touchbar/ttouchbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@ void tTouchBar::invalidateTouchBar() {
NSTouchBar* tTouchBar::makeTouchBar() {
return nullptr;
}

void tTouchBar::addCustomizationMenuItem(QMenu* menu) {
}
#endif
3 changes: 3 additions & 0 deletions lib/touchbar/ttouchbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
11 changes: 11 additions & 0 deletions lib/touchbar/ttouchbar_objc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "private/ttouchbar_p.h"
#include "ranges/trange.h"
#include <QWidget>
#include <QMenu>

@interface TTouchBarMainWindowDelegate: NSResponder<NSTouchBarDelegate, NSApplicationDelegate, NSWindowDelegate>
@property QWidget* parent;
Expand Down Expand Up @@ -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];
}
39 changes: 39 additions & 0 deletions lib/touchbar/ttouchbaractionitem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "ttouchbaractionitem.h"

#include <QAction>

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);
}
26 changes: 26 additions & 0 deletions lib/touchbar/ttouchbaractionitem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef TTOUCHBARACTIONITEM_H
#define TTOUCHBARACTIONITEM_H

#include "ttouchbarbuttonitem.h"
#include <QIcon>

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
8 changes: 8 additions & 0 deletions lib/translations/ar_SA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,14 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
8 changes: 8 additions & 0 deletions lib/translations/bg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,14 @@
<translation></translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
8 changes: 8 additions & 0 deletions lib/translations/cs_CZ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,14 @@
<translation>Nastavení</translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
8 changes: 8 additions & 0 deletions lib/translations/cy_GB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,14 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
8 changes: 8 additions & 0 deletions lib/translations/da_DK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,14 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
8 changes: 8 additions & 0 deletions lib/translations/de_DE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,14 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
8 changes: 8 additions & 0 deletions lib/translations/en_GB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,14 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
8 changes: 8 additions & 0 deletions lib/translations/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,14 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
8 changes: 8 additions & 0 deletions lib/translations/fr_CA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,14 @@
<translation>Paramètres</translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
8 changes: 8 additions & 0 deletions lib/translations/he_IL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,14 @@
<translation>הגדרות</translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
8 changes: 8 additions & 0 deletions lib/translations/id_ID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,14 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
8 changes: 8 additions & 0 deletions lib/translations/ja_JP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,14 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
8 changes: 8 additions & 0 deletions lib/translations/nl_NL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,14 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
8 changes: 8 additions & 0 deletions lib/translations/pl_PL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,14 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
8 changes: 8 additions & 0 deletions lib/translations/pt_BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,14 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
8 changes: 8 additions & 0 deletions lib/translations/ro_RO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,14 @@
<translation></translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
8 changes: 8 additions & 0 deletions lib/translations/sl_SI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,14 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
8 changes: 8 additions & 0 deletions lib/translations/ta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,14 @@
<translation>அமைப்புகள்</translation>
</message>
</context>
<context>
<name>tTouchBar</name>
<message>
<location filename="../touchbar/ttouchbar_objc.mm" line="153"/>
<source>Customize Touch Bar...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>tWindowTabber</name>
<message>
Expand Down
Loading

0 comments on commit 091463e

Please sign in to comment.