mirror of
https://github.com/YACReader/yacreader
synced 2025-07-23 15:35:03 -04:00
added enabled/disabled items to the new toolbar for macosx
This commit is contained in:
@ -17,6 +17,7 @@ public:
|
|||||||
void addWidget(QWidget * widget);
|
void addWidget(QWidget * widget);
|
||||||
void show();
|
void show();
|
||||||
void hide();
|
void hide();
|
||||||
|
QMap<QString, QAction *> actions;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
@ -24,6 +25,8 @@ public slots:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
NSToolbar * nativeToolBar;
|
NSToolbar * nativeToolBar;
|
||||||
|
void *delegate;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,12 +2,16 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QMacNativeWidget>
|
#include <QMacNativeWidget>
|
||||||
|
#include <qmacfunctions.h>
|
||||||
|
|
||||||
|
#include <QsLog.h>
|
||||||
|
|
||||||
#import <AppKit/AppKit.h>
|
#import <AppKit/AppKit.h>
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
//----------------------------
|
||||||
|
|
||||||
@interface CustomSeparator : NSView
|
@interface CustomSeparator : NSView
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@ -23,15 +27,121 @@
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
//----------------------------
|
||||||
|
@interface MyToolbarDelegate : NSObject <NSToolbarDelegate>
|
||||||
|
{
|
||||||
|
@public
|
||||||
|
YACReaderMacOSXToolbar * mytoolbar;
|
||||||
|
}
|
||||||
|
|
||||||
YACReaderMacOSXToolbar::YACReaderMacOSXToolbar(QObject *parent) :
|
- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted;
|
||||||
QMacToolBar(parent)
|
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar;
|
||||||
|
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar;
|
||||||
|
//- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar;
|
||||||
|
- (IBAction)itemClicked:(id)sender;
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation MyToolbarDelegate
|
||||||
|
|
||||||
|
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
|
||||||
|
{
|
||||||
|
Q_UNUSED(toolbar);
|
||||||
|
|
||||||
|
NSMutableArray *array = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
|
QList<QMacToolBarItem *> items = mytoolbar->items();
|
||||||
|
foreach (const QMacToolBarItem * item, items) {
|
||||||
|
[array addObject : item->nativeToolBarItem().itemIdentifier];
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
//return toolbarPrivate->getItemIdentifiers(toolbarPrivate->items, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
|
||||||
|
{
|
||||||
|
Q_UNUSED(toolbar);
|
||||||
|
|
||||||
|
NSMutableArray *array = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
|
QList<QMacToolBarItem *> items = mytoolbar->items();
|
||||||
|
foreach (const QMacToolBarItem * item, items) {
|
||||||
|
[array addObject : item->nativeToolBarItem().itemIdentifier];
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
//return toolbarPrivate->getItemIdentifiers(toolbarPrivate->allowedItems, false);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
- (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar
|
||||||
|
{
|
||||||
|
Q_UNUSED(toolbar);
|
||||||
|
|
||||||
|
NSMutableArray *array = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
|
QList<QMacToolBarItem *> items = mytoolbar->items();
|
||||||
|
foreach (const QMacToolBarItem * item, items) {
|
||||||
|
[array addObject : item->nativeToolBarItem().itemIdentifier];
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
//NSMutableArray *array = toolbarPrivate->getItemIdentifiers(toolbarPrivate->items, true);
|
||||||
|
//[array addObjectsFromArray:toolbarPrivate->getItemIdentifiers(toolbarPrivate->allowedItems, true)];
|
||||||
|
//return array;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
- (IBAction)itemClicked:(id)sender
|
||||||
|
{
|
||||||
|
NSToolbarItem *item = reinterpret_cast<NSToolbarItem *>(sender);
|
||||||
|
//toolbarPrivate->itemClicked(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier: (NSString *) itemIdentifier willBeInsertedIntoToolbar:(BOOL) willBeInserted
|
||||||
|
{
|
||||||
|
Q_UNUSED(toolbar);
|
||||||
|
Q_UNUSED(willBeInserted);
|
||||||
|
QList<QMacToolBarItem *> items = mytoolbar->items();
|
||||||
|
|
||||||
|
int i = [itemIdentifier intValue];
|
||||||
|
|
||||||
|
foreach (const QMacToolBarItem * item, items) {
|
||||||
|
NSToolbarItem *toolbarItem = item->nativeToolBarItem();
|
||||||
|
if([toolbarItem.itemIdentifier isEqual:itemIdentifier])
|
||||||
|
{
|
||||||
|
|
||||||
|
[toolbarItem setTarget:self];
|
||||||
|
[toolbarItem setAction:@selector(itemClicked:)];
|
||||||
|
|
||||||
|
return toolbarItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
|
||||||
|
{
|
||||||
|
int i = -1;
|
||||||
|
|
||||||
|
QString identifier = QString::fromNSString(theItem.itemIdentifier);
|
||||||
|
|
||||||
|
if(mytoolbar->actions.contains(identifier))
|
||||||
|
{
|
||||||
|
return mytoolbar->actions.value(identifier)->isEnabled();
|
||||||
|
}
|
||||||
|
else return NO;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
//----------------------------
|
||||||
|
|
||||||
|
YACReaderMacOSXToolbar::YACReaderMacOSXToolbar(QObject *parent)
|
||||||
{
|
{
|
||||||
//setup native toolbar
|
//setup native toolbar
|
||||||
nativeToolBar= nativeToolbar();
|
nativeToolBar= nativeToolbar();
|
||||||
[nativeToolBar setSizeMode:NSToolbarSizeModeSmall];
|
[nativeToolBar setSizeMode:NSToolbarSizeModeSmall];
|
||||||
[nativeToolBar setDisplayMode:NSToolbarDisplayModeIconOnly];
|
[nativeToolBar setDisplayMode:NSToolbarDisplayModeIconOnly];
|
||||||
|
|
||||||
|
delegate = [[MyToolbarDelegate alloc] init];
|
||||||
|
((MyToolbarDelegate *)delegate)->mytoolbar = this;
|
||||||
|
[nativeToolBar setDelegate:(MyToolbarDelegate *)delegate];
|
||||||
//button testing
|
//button testing
|
||||||
/*QPixmap p(100,100);
|
/*QPixmap p(100,100);
|
||||||
|
|
||||||
@ -56,6 +166,12 @@ void YACReaderMacOSXToolbar::addAction(QAction *action)
|
|||||||
connect(toolBarItem,SIGNAL(activated()),action, SIGNAL(triggered()));
|
connect(toolBarItem,SIGNAL(activated()),action, SIGNAL(triggered()));
|
||||||
|
|
||||||
//TODO add support for enable/disable toolbaritems
|
//TODO add support for enable/disable toolbaritems
|
||||||
|
NSToolbarItem * nativeItem = toolBarItem->nativeToolBarItem();
|
||||||
|
//[nativeItem setTarget:[[MyToolbarDelegate alloc] init]];
|
||||||
|
|
||||||
|
[nativeToolBar validateVisibleItems];
|
||||||
|
|
||||||
|
actions.insert(QString::fromNSString(nativeItem.itemIdentifier),action);
|
||||||
}
|
}
|
||||||
|
|
||||||
void YACReaderMacOSXToolbar::addDropDownItem(const QList<QAction *> &actions, const QAction *defaultAction)
|
void YACReaderMacOSXToolbar::addDropDownItem(const QList<QAction *> &actions, const QAction *defaultAction)
|
||||||
|
Reference in New Issue
Block a user