This repository has been archived by the owner on Aug 13, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4498031
Showing
9 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (C) 2011 by Mike McQuaid | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Qocoa | ||
===== | ||
|
||
Qocoa is a collection of Qt wrappers for OSX's Cocoa widgets. | ||
|
||
They have the following features/goals: | ||
|
||
- Fallback to sensible Qt types on non-OSX platforms | ||
- A shared header which exposes no implementation details | ||
- Signal/slot based API | ||
|
||
Qocoa is licensed under the MIT license. | ||
The full license text is available in LICENSE.txt. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "gallery.h" | ||
|
||
#include <QVBoxLayout> | ||
|
||
#include "qsearchfield.h" | ||
|
||
Gallery::Gallery(QWidget *parent) : QWidget(parent) | ||
{ | ||
QVBoxLayout *layout = new QVBoxLayout(this); | ||
layout->addWidget(new QSearchField(this)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef GALLERY_H | ||
#define GALLERY_H | ||
|
||
#include <QWidget> | ||
|
||
class Gallery : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit Gallery(QWidget *parent = 0); | ||
}; | ||
|
||
#endif // WIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <QtGui/QApplication> | ||
#include "gallery.h" | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication application(argc, argv); | ||
|
||
Gallery gallery; | ||
gallery.show(); | ||
|
||
return application.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
SOURCES += main.cpp\ | ||
gallery.cpp | ||
|
||
HEADERS += gallery.h \ | ||
qsearchfield.h | ||
|
||
!mac:SOURCES += qsearchfield.cpp | ||
mac:SOURCES += qsearchfield_mac.mm | ||
mac:LIBS += -framework Foundation -framework Appkit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "qsearchfield.h" | ||
|
||
#include <QLineEdit> | ||
#include <QVBoxLayout> | ||
|
||
class QSearchFieldPrivate | ||
{ | ||
public: | ||
QSearchFieldPrivate(QLineEdit *lineEdit) : lineEdit(lineEdit) {} | ||
QLineEdit *lineEdit; | ||
}; | ||
|
||
QSearchField::QSearchField(QWidget *parent) : QWidget(parent) | ||
{ | ||
QLineEdit *lineEdit = new QLineEdit(this); | ||
connect(lineEdit, SIGNAL(textChanged(QString)), | ||
this, SIGNAL(textChanged(QString))); | ||
pimpl = new QSearchFieldPrivate(lineEdit); | ||
|
||
QVBoxLayout *layout = new QVBoxLayout(this); | ||
layout->setMargin(0); | ||
layout->addWidget(lineEdit); | ||
} | ||
|
||
void QSearchField::setText(const QString &text) | ||
{ | ||
pimpl->lineEdit->setText(text); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef QSEARCHFIELD_H | ||
#define QSEARCHFIELD_H | ||
|
||
#include <QWidget> | ||
|
||
class QSearchFieldPrivate; | ||
class QSearchField : public QWidget | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit QSearchField(QWidget *parent); | ||
|
||
public slots: | ||
void setText(const QString &text); | ||
|
||
signals: | ||
void textChanged(const QString &text); | ||
|
||
private: | ||
friend class QSearchFieldPrivate; | ||
QSearchFieldPrivate *pimpl; | ||
}; | ||
|
||
#endif // QSEARCHFIELD_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include "qsearchfield.h" | ||
|
||
#include <QMacCocoaViewContainer> | ||
#include <QVBoxLayout> | ||
|
||
#import "Foundation/NSAutoreleasePool.h" | ||
#import "Foundation/NSNotification.h" | ||
#import "AppKit/NSTextField.h" | ||
#import "AppKit/NSSearchField.h" | ||
|
||
NSString* fromQString(const QString &string) | ||
{ | ||
char* cString = string.toUtf8().data(); | ||
return [[NSString alloc] initWithUTF8String:cString]; | ||
} | ||
|
||
QString toQString(NSString *string) | ||
{ | ||
if (!string) | ||
return QString(); | ||
return QString::fromUtf8([string UTF8String]); | ||
} | ||
|
||
class QSearchFieldPrivate | ||
{ | ||
public: | ||
QSearchFieldPrivate(QSearchField *qSearchField, NSSearchField *nsSearchField) | ||
: qSearchField(qSearchField), nsSearchField(nsSearchField) {} | ||
|
||
void textDidChange(const QString &text) | ||
{ | ||
emit qSearchField->textChanged(text); | ||
} | ||
QSearchField *qSearchField; | ||
NSSearchField *nsSearchField; | ||
}; | ||
|
||
@interface QSearchFieldDelegate : NSObject<NSTextFieldDelegate> | ||
{ | ||
@public | ||
QSearchFieldPrivate* pimpl; | ||
} | ||
-(void)controlTextDidChange:(NSNotification*)notification; | ||
@end | ||
|
||
@implementation QSearchFieldDelegate | ||
-(void)controlTextDidChange:(NSNotification*)notification { | ||
pimpl->textDidChange(toQString([[notification object] stringValue])); | ||
} | ||
@end | ||
|
||
QSearchField::QSearchField(QWidget *parent) : QWidget(parent) | ||
{ | ||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||
|
||
NSSearchField *search = [[NSSearchField alloc] init]; | ||
pimpl = new QSearchFieldPrivate(this, search); | ||
[search sizeToFit]; | ||
|
||
QSearchFieldDelegate *delegate = [[QSearchFieldDelegate alloc] init]; | ||
delegate->pimpl = pimpl; | ||
[search setDelegate:delegate]; | ||
|
||
QVBoxLayout *layout = new QVBoxLayout(this); | ||
layout->setMargin(0); | ||
layout->addWidget(new QMacCocoaViewContainer(search, this)); | ||
|
||
setFixedHeight(20); | ||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); | ||
|
||
[search release]; | ||
|
||
[pool release]; | ||
} | ||
|
||
void QSearchField::setText(const QString &text) | ||
{ | ||
[pimpl->nsSearchField setStringValue:fromQString(text)]; | ||
} |