mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
first working version of the search edit in YACReaderLibrary when native NSToolbar is used, //TODO add search modifiers
This commit is contained in:
parent
aaa53c9456
commit
fb8b87cbd9
@ -176,7 +176,10 @@ void LibraryWindow::doLayout()
|
|||||||
|
|
||||||
//FOLDERS FILTER-------------------------------------------------------------
|
//FOLDERS FILTER-------------------------------------------------------------
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
#ifndef Q_OS_MAC
|
||||||
|
//in MacOSX the searchEdit is created using the toolbar wrapper
|
||||||
searchEdit = new YACReaderSearchLineEdit();
|
searchEdit = new YACReaderSearchLineEdit();
|
||||||
|
#endif
|
||||||
|
|
||||||
//SIDEBAR--------------------------------------------------------------------
|
//SIDEBAR--------------------------------------------------------------------
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@ -825,7 +828,8 @@ void LibraryWindow::createToolBars()
|
|||||||
|
|
||||||
//Native toolbar search edit
|
//Native toolbar search edit
|
||||||
//libraryToolBar->addWidget(searchEdit);
|
//libraryToolBar->addWidget(searchEdit);
|
||||||
libraryToolBar->addSearchEdit();
|
searchEdit = libraryToolBar->addSearchEdit();
|
||||||
|
//connect(libraryToolBar,SIGNAL(searchTextChanged(YACReader::SearchModifiers,QString)),this,SLOT(setSearchFilter(YACReader::SearchModifiers, QString)));
|
||||||
|
|
||||||
//libraryToolBar->setMovable(false);
|
//libraryToolBar->setMovable(false);
|
||||||
|
|
||||||
|
@ -99,7 +99,11 @@ private:
|
|||||||
QSize slideSizeW;
|
QSize slideSizeW;
|
||||||
QSize slideSizeF;
|
QSize slideSizeF;
|
||||||
//search filter
|
//search filter
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
YACReaderMacOSXSearchLineEdit * searchEdit;
|
||||||
|
#else
|
||||||
YACReaderSearchLineEdit * searchEdit;
|
YACReaderSearchLineEdit * searchEdit;
|
||||||
|
#endif
|
||||||
FolderItem * index; //index al que hay que hacer scroll despu<70>s de pulsar sobre un folder filtrado
|
FolderItem * index; //index al que hay que hacer scroll despu<70>s de pulsar sobre un folder filtrado
|
||||||
int column;
|
int column;
|
||||||
QString previousFilter;
|
QString previousFilter;
|
||||||
|
@ -4,6 +4,31 @@
|
|||||||
#include <QMacToolBar>
|
#include <QMacToolBar>
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
|
|
||||||
|
#include "yacreader_global.h"
|
||||||
|
|
||||||
|
//Wrapper for NSTextField
|
||||||
|
class YACReaderMacOSXSearchLineEdit : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
YACReaderMacOSXSearchLineEdit();
|
||||||
|
void * getNSTextField();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
QString text();
|
||||||
|
void clear();
|
||||||
|
void setDisabled(bool disabled);
|
||||||
|
void setEnabled(bool enabled);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void * nstextfield;
|
||||||
|
|
||||||
|
|
||||||
|
signals:
|
||||||
|
//convenience signal for YACReaderLibrary search edit
|
||||||
|
void filterChanged(YACReader::SearchModifiers, QString);
|
||||||
|
};
|
||||||
|
|
||||||
class YACReaderMacOSXToolbar : public QMacToolBar
|
class YACReaderMacOSXToolbar : public QMacToolBar
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -20,11 +45,10 @@ public:
|
|||||||
QMap<QString, QAction *> actions;
|
QMap<QString, QAction *> actions;
|
||||||
|
|
||||||
//convenience method for YACReaderLibrary search edit
|
//convenience method for YACReaderLibrary search edit
|
||||||
void addSearchEdit();
|
YACReaderMacOSXSearchLineEdit *addSearchEdit();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
//convenience signal for YACReaderLibrary search edit
|
|
||||||
void searchTextChanged(QString);
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
//----------------------------
|
//----------------------------
|
||||||
|
//A custom items separator for NSToolbar
|
||||||
@interface CustomSeparator : NSView
|
@interface CustomSeparator : NSView
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@ -28,6 +28,7 @@
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
//----------------------------
|
//----------------------------
|
||||||
|
//Toolbar delegate, needed for allow disabled/enabled items
|
||||||
@interface MyToolbarDelegate : NSObject <NSToolbarDelegate>
|
@interface MyToolbarDelegate : NSObject <NSToolbarDelegate>
|
||||||
{
|
{
|
||||||
@public
|
@public
|
||||||
@ -39,6 +40,7 @@
|
|||||||
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar;
|
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar;
|
||||||
//- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar;
|
//- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar;
|
||||||
- (IBAction)itemClicked:(id)sender;
|
- (IBAction)itemClicked:(id)sender;
|
||||||
|
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@ -55,7 +57,6 @@
|
|||||||
[array addObject : item->nativeToolBarItem().itemIdentifier];
|
[array addObject : item->nativeToolBarItem().itemIdentifier];
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
//return toolbarPrivate->getItemIdentifiers(toolbarPrivate->items, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
|
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
|
||||||
@ -69,8 +70,9 @@
|
|||||||
[array addObject : item->nativeToolBarItem().itemIdentifier];
|
[array addObject : item->nativeToolBarItem().itemIdentifier];
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
//return toolbarPrivate->getItemIdentifiers(toolbarPrivate->allowedItems, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
- (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar
|
- (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar
|
||||||
{
|
{
|
||||||
@ -119,8 +121,6 @@
|
|||||||
|
|
||||||
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
|
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
|
||||||
{
|
{
|
||||||
int i = -1;
|
|
||||||
|
|
||||||
QString identifier = QString::fromNSString(theItem.itemIdentifier);
|
QString identifier = QString::fromNSString(theItem.itemIdentifier);
|
||||||
|
|
||||||
if(mytoolbar->actions.contains(identifier))
|
if(mytoolbar->actions.contains(identifier))
|
||||||
@ -131,6 +131,24 @@
|
|||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
//----------------------------
|
||||||
|
//detect changes in native text field
|
||||||
|
//TODO implement validation and auto completion
|
||||||
|
@interface MyTextFieldDelegate : NSObject <NSTextFieldDelegate>
|
||||||
|
{
|
||||||
|
@public
|
||||||
|
YACReaderMacOSXSearchLineEdit * mylineedit;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation MyTextFieldDelegate
|
||||||
|
|
||||||
|
- (void)controlTextDidChange:(NSNotification *)notification {
|
||||||
|
NSTextField *textField = [notification object];
|
||||||
|
Q_EMIT mylineedit->filterChanged(YACReader::NoModifiers, QString::fromNSString([textField stringValue]));
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
//----------------------------
|
//----------------------------
|
||||||
|
|
||||||
YACReaderMacOSXToolbar::YACReaderMacOSXToolbar(QObject *parent)
|
YACReaderMacOSXToolbar::YACReaderMacOSXToolbar(QObject *parent)
|
||||||
@ -143,44 +161,19 @@ YACReaderMacOSXToolbar::YACReaderMacOSXToolbar(QObject *parent)
|
|||||||
delegate = [[MyToolbarDelegate alloc] init];
|
delegate = [[MyToolbarDelegate alloc] init];
|
||||||
((MyToolbarDelegate *)delegate)->mytoolbar = this;
|
((MyToolbarDelegate *)delegate)->mytoolbar = this;
|
||||||
[nativeToolBar setDelegate:(MyToolbarDelegate *)delegate];
|
[nativeToolBar setDelegate:(MyToolbarDelegate *)delegate];
|
||||||
//button testing
|
|
||||||
/*QPixmap p(100,100);
|
|
||||||
|
|
||||||
QIcon icon(p);
|
|
||||||
QMacToolBarItem *toolBarItem = addItem(icon,"hola");
|
|
||||||
NSToolbarItem * nativeItem = toolBarItem->nativeToolBarItem();
|
|
||||||
|
|
||||||
|
|
||||||
[nativeItem setMaxSize:NSMakeSize(10,50)];
|
|
||||||
[nativeItem setMinSize:NSMakeSize(10,50)];*/
|
|
||||||
//toolBarItem->setStandardItem(QMacToolBarItem::FlexibleSpace);
|
|
||||||
//connect(toolButton, SIGNAL(activated()), this, SLOT(fooClicked()))
|
|
||||||
|
|
||||||
//window->window()->winId(); // create window->windowhandle()
|
|
||||||
//attachToWindow(window->window()->windowHandle());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void YACReaderMacOSXToolbar::addAction(QAction *action)
|
void YACReaderMacOSXToolbar::addAction(QAction *action)
|
||||||
{
|
{
|
||||||
QMacToolBarItem *toolBarItem = addItem(action->icon(),action->text());
|
QMacToolBarItem *toolBarItem = addItem(action->icon(),action->text());
|
||||||
|
|
||||||
connect(toolBarItem,SIGNAL(activated()),action, SIGNAL(triggered()));
|
connect(toolBarItem,SIGNAL(activated()),action, SIGNAL(triggered()));
|
||||||
|
|
||||||
//TODO add support for enable/disable toolbaritems
|
|
||||||
NSToolbarItem * nativeItem = toolBarItem->nativeToolBarItem();
|
NSToolbarItem * nativeItem = toolBarItem->nativeToolBarItem();
|
||||||
//[nativeItem setTarget:[[MyToolbarDelegate alloc] init]];
|
|
||||||
|
|
||||||
[nativeToolBar validateVisibleItems];
|
|
||||||
|
|
||||||
actions.insert(QString::fromNSString(nativeItem.itemIdentifier),action);
|
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)
|
||||||
{
|
{
|
||||||
foreach(QAction * action, actions)
|
//TODO
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void YACReaderMacOSXToolbar::addSpace(int size)
|
void YACReaderMacOSXToolbar::addSpace(int size)
|
||||||
@ -194,8 +187,11 @@ void YACReaderMacOSXToolbar::addSpace(int size)
|
|||||||
//TODO this doesn't work
|
//TODO this doesn't work
|
||||||
[nativeItem setMaxSize:NSMakeSize(size,24)];
|
[nativeItem setMaxSize:NSMakeSize(size,24)];
|
||||||
[nativeItem setMinSize:NSMakeSize(size,24)];
|
[nativeItem setMinSize:NSMakeSize(size,24)];
|
||||||
|
|
||||||
|
//if a fix isn't found probably it is better to use QMacToolBar::
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//reimplemented for convenience
|
||||||
void YACReaderMacOSXToolbar::addSeparator()
|
void YACReaderMacOSXToolbar::addSeparator()
|
||||||
{
|
{
|
||||||
//QMacToolBar::addSeparator();
|
//QMacToolBar::addSeparator();
|
||||||
@ -240,15 +236,54 @@ void YACReaderMacOSXToolbar::hide()
|
|||||||
[nativeToolBar setVisible:NO];
|
[nativeToolBar setVisible:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
void YACReaderMacOSXToolbar::addSearchEdit()
|
YACReaderMacOSXSearchLineEdit * YACReaderMacOSXToolbar::addSearchEdit()
|
||||||
{
|
{
|
||||||
QMacToolBarItem *toolBarItem = addItem(QIcon(),"");
|
QMacToolBarItem *toolBarItem = addItem(QIcon(),"");
|
||||||
NSToolbarItem * nativeItem = toolBarItem->nativeToolBarItem();
|
NSToolbarItem * nativeItem = toolBarItem->nativeToolBarItem();
|
||||||
|
|
||||||
static const NSRect searchEditFrameRect = { { 0.0, 0.0 }, { 150, 24.0 } };
|
YACReaderMacOSXSearchLineEdit * searchEdit = new YACReaderMacOSXSearchLineEdit();
|
||||||
|
[nativeItem setView:((NSTextField *)searchEdit->getNSTextField())];
|
||||||
|
|
||||||
|
return searchEdit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
YACReaderMacOSXSearchLineEdit::YACReaderMacOSXSearchLineEdit()
|
||||||
|
:QObject()
|
||||||
|
{
|
||||||
|
static const NSRect searchEditFrameRect = { { 0.0, 0.0 }, { 165, 24.0 } };
|
||||||
NSTextField * searchEdit = [[NSTextField alloc] initWithFrame:searchEditFrameRect];
|
NSTextField * searchEdit = [[NSTextField alloc] initWithFrame:searchEditFrameRect];
|
||||||
|
|
||||||
[searchEdit setBezelStyle:NSTextFieldRoundedBezel];
|
[searchEdit setBezelStyle:NSTextFieldRoundedBezel];
|
||||||
|
|
||||||
[nativeItem setView:searchEdit];
|
MyTextFieldDelegate * delegate = [[MyTextFieldDelegate alloc] init];
|
||||||
|
delegate->mylineedit = this;
|
||||||
|
[searchEdit setDelegate:delegate];
|
||||||
|
|
||||||
|
nstextfield = searchEdit;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *YACReaderMacOSXSearchLineEdit::getNSTextField()
|
||||||
|
{
|
||||||
|
return nstextfield;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString YACReaderMacOSXSearchLineEdit::text()
|
||||||
|
{
|
||||||
|
return QString::fromNSString([((NSTextField *)nstextfield) stringValue]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void YACReaderMacOSXSearchLineEdit::clear()
|
||||||
|
{
|
||||||
|
[((NSTextField *)nstextfield) setStringValue:@""];
|
||||||
|
}
|
||||||
|
|
||||||
|
void YACReaderMacOSXSearchLineEdit::setDisabled(bool disabled)
|
||||||
|
{
|
||||||
|
[((NSTextField *)nstextfield) setEnabled:!disabled];
|
||||||
|
}
|
||||||
|
|
||||||
|
void YACReaderMacOSXSearchLineEdit::setEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
[((NSTextField *)nstextfield) setEnabled:enabled];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user