mirror-chatterino2/src/widgets/AccountSwitchPopupWidget.cpp
Leon Richardt 4a1712f9a2 Fix "Manage Accounts" button
This commit fixes the unresponsiveness of the "Manage Account" button
(described in #1188).

Apparently, focus was lost when pressing down the mouse button. This is
circumvented by setting the focus policy of the button to `Qt::NoFocus`.
The button then works as expected and opens the "Account" page in the
preferences.
2019-08-17 01:35:24 +02:00

65 lines
1.7 KiB
C++

#include "widgets/AccountSwitchPopupWidget.hpp"
#include "debug/Log.hpp"
#include "widgets/dialogs/SettingsDialog.hpp"
#include <QHBoxLayout>
#include <QLayout>
#include <QPainter>
#include <QPushButton>
#include <QVBoxLayout>
namespace chatterino {
AccountSwitchPopupWidget::AccountSwitchPopupWidget(QWidget *parent)
: QWidget(parent)
{
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
#ifdef Q_OS_LINUX
this->setWindowFlag(Qt::Popup);
#endif
this->setContentsMargins(0, 0, 0, 0);
this->ui_.accountSwitchWidget = new AccountSwitchWidget(this);
QVBoxLayout *vbox = new QVBoxLayout(this);
this->ui_.accountSwitchWidget->setFocusPolicy(Qt::NoFocus);
vbox->addWidget(this->ui_.accountSwitchWidget);
// vbox->setSizeConstraint(QLayout::SetMinimumSize);
auto hbox = new QHBoxLayout();
auto manageAccountsButton = new QPushButton(this);
manageAccountsButton->setText("Manage Accounts");
manageAccountsButton->setFocusPolicy(Qt::NoFocus);
hbox->addWidget(manageAccountsButton);
vbox->addLayout(hbox);
connect(manageAccountsButton, &QPushButton::clicked, []() {
SettingsDialog::showDialog(SettingsDialogPreference::Accounts); //
});
this->setLayout(vbox);
// this->setStyleSheet("background: #333");
}
void AccountSwitchPopupWidget::refresh()
{
this->ui_.accountSwitchWidget->refresh();
}
void AccountSwitchPopupWidget::focusOutEvent(QFocusEvent *)
{
this->hide();
}
void AccountSwitchPopupWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(QColor("#999"));
painter.drawRect(0, 0, this->width() - 1, this->height() - 1);
}
} // namespace chatterino