Skip to content

Commit

Permalink
Fix QSearchField on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaski committed Mar 15, 2021
1 parent d84aebd commit f5bb15f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/covermanager/albumcovermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ void AlbumCoverManager::showEvent(QShowEvent *e) {
Reset();
}

QMainWindow::showEvent(e);

}

void AlbumCoverManager::closeEvent(QCloseEvent *e) {
Expand All @@ -270,6 +272,8 @@ void AlbumCoverManager::closeEvent(QCloseEvent *e) {
ui_->artists->clear();
ui_->albums->clear();

QMainWindow::closeEvent(e);

}

void AlbumCoverManager::LoadGeometry() {
Expand Down
8 changes: 0 additions & 8 deletions src/covermanager/albumcoversearcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,6 @@ void AlbumCoverSearcher::Init(AlbumCoverFetcher *fetcher) {

AlbumCoverImageResult AlbumCoverSearcher::Exec(const QString &artist, const QString &album) {

#ifdef Q_OS_MACOS
ui_->artist->clear();
ui_->album->clear();
model_->clear();
cover_loading_tasks_.clear();
show();
#endif

ui_->artist->setText(artist);
ui_->album->setText(album);
ui_->artist->setFocus();
Expand Down
4 changes: 4 additions & 0 deletions src/widgets/qsearchfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <QPointer>
#include <QMenu>

class QShowEvent;
class QCloseEvent;

class QSearchFieldPrivate;
class QSearchField : public QWidget {
Q_OBJECT
Expand Down Expand Up @@ -34,6 +37,7 @@ class QSearchField : public QWidget {
void returnPressed();

protected:
void showEvent(QShowEvent *e) override;
void resizeEvent(QResizeEvent*) override;
bool eventFilter(QObject*, QEvent*) override;

Expand Down
24 changes: 18 additions & 6 deletions src/widgets/qsearchfield_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ of this software and associated documentation files (the "Software"), to deal
#include <QString>
#include <QClipboard>
#include <QBoxLayout>
#include <QShowEvent>
#include <QKeyEvent>

class QSearchFieldPrivate : public QObject {
Expand Down Expand Up @@ -164,15 +165,12 @@ -(BOOL)performKeyEquivalent:(NSEvent*)event {
pimpl = delegate->pimpl = new QSearchFieldPrivate(this, search);
[search setDelegate:(id<NSSearchFieldDelegate>)delegate];

QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(QWidget::createWindowContainer(QWindow::fromWinId(WId(search)), this));

new QVBoxLayout(this);
layout()->setContentsMargins(0, 0, 0, 0);
setAttribute(Qt::WA_NativeWindow);
setFixedHeight(24);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

[search release];
[pool drain];

}
Expand Down Expand Up @@ -232,11 +230,25 @@ -(BOOL)performKeyEquivalent:(NSEvent*)event {
setFocus(Qt::OtherFocusReason);
}

void QSearchField::showEvent(QShowEvent *e) {

if (!e->spontaneous()) {
for (int i = 0 ; i < layout()->count() ; ++i) {
QWidget *widget = layout()->itemAt(i)->widget();
layout()->removeWidget(widget);
delete widget;
}
layout()->addWidget(QWidget::createWindowContainer(QWindow::fromWinId(WId(pimpl->nsSearchField)), this));
}

QWidget::showEvent(e);

}

void QSearchField::resizeEvent(QResizeEvent *resizeEvent) {
QWidget::resizeEvent(resizeEvent);
}

bool QSearchField::eventFilter(QObject *o, QEvent *e) {
return QWidget::eventFilter(o, e);
}

6 changes: 6 additions & 0 deletions src/widgets/qsearchfield_nonmac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ QString QSearchField::text() const {

}

void QSearchField::showEvent(QShowEvent *e) {

QWidget::showEvent(e);

}

void QSearchField::resizeEvent(QResizeEvent *resizeEvent) {

Q_ASSERT(pimpl && pimpl->clearbutton_ && pimpl->lineedit_);
Expand Down

0 comments on commit f5bb15f

Please sign in to comment.