From 105f9ec4013ee5e5c96b261507b1e658dc49bdfb Mon Sep 17 00:00:00 2001 From: jenli669 Date: Sat, 29 Jun 2019 13:14:38 +0200 Subject: [PATCH] refactor(widget): remove Widget::getInstance --- src/nexus.cpp | 9 +++++---- src/widget/tool/callconfirmwidget.cpp | 17 +++++++---------- src/widget/widget.cpp | 17 ----------------- 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/src/nexus.cpp b/src/nexus.cpp index bb7a60ac7..ff3f76f79 100644 --- a/src/nexus.cpp +++ b/src/nexus.cpp @@ -34,8 +34,8 @@ #include #include #include -#include #include +#include #ifdef Q_OS_MAC #include @@ -169,7 +169,7 @@ int Nexus::showLogin(const QString& profileName) return returnval; } -void Nexus::bootstrapWithProfile(Profile *p) +void Nexus::bootstrapWithProfile(Profile* p) { // kriby: This is a hack until a proper controller is written @@ -222,7 +222,7 @@ void Nexus::showMainGUI() assert(profile); // Create GUI - widget = Widget::getInstance(audioControl.get()); + widget = new Widget(*audioControl); // Start GUI widget->init(); @@ -309,7 +309,8 @@ void Nexus::onLoadProfile(const QString& name, const QString& pass) * Changes the loaded profile and notifies listeners. * @param p */ -void Nexus::setProfile(Profile* p) { +void Nexus::setProfile(Profile* p) +{ if (!p) { emit profileLoadFailed(); // Warnings are issued during respective createNew/load calls diff --git a/src/widget/tool/callconfirmwidget.cpp b/src/widget/tool/callconfirmwidget.cpp index cf5322c9a..19db6b861 100644 --- a/src/widget/tool/callconfirmwidget.cpp +++ b/src/widget/tool/callconfirmwidget.cpp @@ -22,6 +22,7 @@ #include "src/widget/style.h" #include "src/widget/widget.h" #include +#include #include #include #include @@ -30,7 +31,6 @@ #include #include #include -#include #include /** @@ -76,12 +76,12 @@ CallConfirmWidget::CallConfirmWidget(const QWidget* anchor) // Note: At the moment this may not work properly. For languages written // from right to left, there is no translation for the phrase "Incoming call...". // In this situation, the phrase "Incoming call..." looks as "...oming call..." - Qt::TextElideMode elideMode = (QGuiApplication::layoutDirection() == Qt::LeftToRight) - ? Qt::ElideRight : Qt::ElideLeft; + Qt::TextElideMode elideMode = + (QGuiApplication::layoutDirection() == Qt::LeftToRight) ? Qt::ElideRight : Qt::ElideLeft; int marginSize = 12; QFontMetrics fontMetrics(callLabel->font()); - QString elidedText = fontMetrics.elidedText(callLabel->text(), elideMode, - rectW - marginSize * 2 - 4); + QString elidedText = + fontMetrics.elidedText(callLabel->text(), elideMode, rectW - marginSize * 2 - 4); callLabel->setText(elidedText); QDialogButtonBox* buttonBox = new QDialogButtonBox(Qt::Horizontal, this); @@ -154,14 +154,11 @@ void CallConfirmWidget::paintEvent(QPaintEvent*) void CallConfirmWidget::showEvent(QShowEvent*) { + // Kriby: Legacy comment, is this still true? // If someone does show() from Widget or lower, the event will reach us // because it's our parent, and we could show up in the wrong form. // So check here if our friend's form is actually the active one. - // if (!Widget::getInstance()->isFriendWidgetCurActiveWidget(&f)) - { - // QWidget::hide(); - // return; - } + reposition(); update(); } diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 195dfba70..75d2fd142 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -601,23 +601,6 @@ Widget::~Widget() instance = nullptr; } -/** - * @param audio Only used for initialization from Nexus, to pass IAudioControl - * @brief Returns the singleton instance. - */ -Widget* Widget::getInstance(IAudioControl* audio) -{ - if (!instance) { - // Passing audio via pointer here is a hack - // to allow for default paramters. - // once Widget::getInstance is removed it won't be neccessary - assert(audio != nullptr); - instance = new Widget(*audio); - } - - return instance; -} - /** * @brief Switches to the About settings page. */