Fix QSearchField on macOS

This commit is contained in:
Jonas Kvinge 2021-03-15 22:38:06 +01:00
parent d84aebd8f4
commit f5bb15f72e
5 changed files with 32 additions and 14 deletions

View File

@ -248,6 +248,8 @@ void AlbumCoverManager::showEvent(QShowEvent *e) {
Reset();
}
QMainWindow::showEvent(e);
}
void AlbumCoverManager::closeEvent(QCloseEvent *e) {
@ -270,6 +272,8 @@ void AlbumCoverManager::closeEvent(QCloseEvent *e) {
ui_->artists->clear();
ui_->albums->clear();
QMainWindow::closeEvent(e);
}
void AlbumCoverManager::LoadGeometry() {

View File

@ -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();

View File

@ -5,6 +5,9 @@
#include <QPointer>
#include <QMenu>
class QShowEvent;
class QCloseEvent;
class QSearchFieldPrivate;
class QSearchField : public QWidget {
Q_OBJECT
@ -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;

View File

@ -32,6 +32,7 @@ THE SOFTWARE.
#include <QString>
#include <QClipboard>
#include <QBoxLayout>
#include <QShowEvent>
#include <QKeyEvent>
class QSearchFieldPrivate : public QObject {
@ -164,15 +165,12 @@ QSearchField::QSearchField(QWidget *parent) : QWidget(parent) {
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];
}
@ -232,6 +230,21 @@ void QSearchField::setFocus() {
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);
}
@ -239,4 +252,3 @@ void QSearchField::resizeEvent(QResizeEvent *resizeEvent) {
bool QSearchField::eventFilter(QObject *o, QEvent *e) {
return QWidget::eventFilter(o, e);
}

View File

@ -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_);