mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
[QtUtils] Adopt shared Qt helpers across the client (#7618)
* [QtUtils] Add parent lookup, layout clearing, scroll area and monospace helpers * [QtUtils] Adopt shared Qt helpers across the client --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
1e0fc35d94
commit
ab13a6748f
25 changed files with 60 additions and 178 deletions
|
|
@ -6,8 +6,6 @@
|
|||
#include "libcockatrice/protocol/pb/serverinfo_report.pb.h"
|
||||
|
||||
#include <QAbstractItemView>
|
||||
#include <QFont>
|
||||
#include <QFontDatabase>
|
||||
#include <QGroupBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
|
|
@ -26,6 +24,7 @@
|
|||
#include <libcockatrice/protocol/pb/response_report_details.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_report_my_list.pb.h>
|
||||
#include <libcockatrice/protocol/pending_command.h>
|
||||
#include <libcockatrice/utility/qt_utils.h>
|
||||
#include <qnamespace.h>
|
||||
#include <string>
|
||||
|
||||
|
|
@ -70,13 +69,7 @@ DlgMyReports::DlgMyReports(AbstractClient *_client, QWidget *parent)
|
|||
auto *chatGroup = new QGroupBox(tr("Chat Log Context"));
|
||||
chatLogEdit = new QTextEdit;
|
||||
chatLogEdit->setReadOnly(true);
|
||||
QFont monoFont("monospace");
|
||||
monoFont.setStyleHint(QFont::Monospace);
|
||||
const int systemPointSize = QFontDatabase::systemFont(QFontDatabase::GeneralFont).pointSize();
|
||||
if (systemPointSize > 0) {
|
||||
monoFont.setPointSize(systemPointSize);
|
||||
}
|
||||
chatLogEdit->setFont(monoFont);
|
||||
chatLogEdit->setFont(QtUtils::monospaceFont());
|
||||
auto *chatLayout = new QVBoxLayout(chatGroup);
|
||||
chatLayout->setContentsMargins(4, 4, 4, 4);
|
||||
chatLayout->addWidget(chatLogEdit);
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@
|
|||
|
||||
#include <QComboBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFont>
|
||||
#include <QFontDatabase>
|
||||
#include <QGridLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
|
|
@ -21,6 +19,7 @@
|
|||
#include <QVariant>
|
||||
#include <libcockatrice/protocol/pb/command_report.pb.h>
|
||||
#include <libcockatrice/protocol/pending_command.h>
|
||||
#include <libcockatrice/utility/qt_utils.h>
|
||||
#include <libcockatrice/utility/report_categories.h>
|
||||
#include <qnamespace.h>
|
||||
#include <string>
|
||||
|
|
@ -92,13 +91,7 @@ DlgReportUser::DlgReportUser(AbstractClient *_client,
|
|||
auto *chatLayout = new QVBoxLayout(chatGroup);
|
||||
chatLogEdit = new QTextEdit;
|
||||
chatLogEdit->setReadOnly(true);
|
||||
QFont monoFont("monospace");
|
||||
monoFont.setStyleHint(QFont::Monospace);
|
||||
const int systemPointSize = QFontDatabase::systemFont(QFontDatabase::GeneralFont).pointSize();
|
||||
if (systemPointSize > 0) {
|
||||
monoFont.setPointSize(systemPointSize);
|
||||
}
|
||||
chatLogEdit->setFont(monoFont);
|
||||
chatLogEdit->setFont(QtUtils::monospaceFont());
|
||||
if (!_autoChatLog.isEmpty()) {
|
||||
chatLogEdit->setPlainText(_autoChatLog);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@
|
|||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <libcockatrice/card/database/card_database_manager.h>
|
||||
#include <libcockatrice/utility/qt_utils.h>
|
||||
#include <qalgorithms.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qobjectdefs.h>
|
||||
|
|
@ -71,10 +72,7 @@ DlgSelectSetForCards::DlgSelectSetForCards(QWidget *parent, DeckStateManager *de
|
|||
QSplitter *splitter = new QSplitter(Qt::Vertical, this);
|
||||
|
||||
// Top scroll area
|
||||
scrollArea = new QScrollArea(this);
|
||||
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
scrollArea->setWidgetResizable(true);
|
||||
scrollArea = QtUtils::makeScrollArea(this);
|
||||
|
||||
listContainer = new QWidget(scrollArea);
|
||||
listLayout = new QVBoxLayout(listContainer);
|
||||
|
|
@ -90,10 +88,7 @@ DlgSelectSetForCards::DlgSelectSetForCards(QWidget *parent, DeckStateManager *de
|
|||
leftLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
uneditedCardsLabel = new QLabel(this);
|
||||
uneditedCardsArea = new QScrollArea(this);
|
||||
uneditedCardsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
uneditedCardsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
uneditedCardsArea->setWidgetResizable(true);
|
||||
uneditedCardsArea = QtUtils::makeScrollArea(this);
|
||||
|
||||
uneditedCardsFlowWidget =
|
||||
new FlowWidget(uneditedCardsArea, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded);
|
||||
|
|
@ -109,10 +104,7 @@ DlgSelectSetForCards::DlgSelectSetForCards(QWidget *parent, DeckStateManager *de
|
|||
rightLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
modifiedCardsLabel = new QLabel(this);
|
||||
modifiedCardsArea = new QScrollArea(this);
|
||||
modifiedCardsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
modifiedCardsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
modifiedCardsArea->setWidgetResizable(true);
|
||||
modifiedCardsArea = QtUtils::makeScrollArea(this);
|
||||
|
||||
modifiedCardsFlowWidget =
|
||||
new FlowWidget(modifiedCardsArea, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded);
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@
|
|||
#include <QWidget>
|
||||
#include <QtGlobal>
|
||||
#include <libcockatrice/settings/personal_settings.h>
|
||||
#include <libcockatrice/utility/qt_utils.h>
|
||||
#include <qnamespace.h>
|
||||
|
||||
/**
|
||||
|
|
@ -71,10 +72,8 @@ static QScrollArea *makeScrollable(QWidget *widget)
|
|||
{
|
||||
widget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Maximum);
|
||||
|
||||
auto *scrollArea = new QScrollArea;
|
||||
scrollArea->setWidgetResizable(true);
|
||||
auto *scrollArea = QtUtils::makeScrollArea();
|
||||
scrollArea->setContentsMargins(0, 0, 0, 0);
|
||||
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
scrollArea->horizontalScrollBar()->setEnabled(false);
|
||||
scrollArea->setWidget(widget);
|
||||
return scrollArea;
|
||||
|
|
@ -625,13 +624,8 @@ void SettingsView::scrollToAndFlash(QWidget *target)
|
|||
if (!target) {
|
||||
return;
|
||||
}
|
||||
QWidget *widget = target;
|
||||
while (widget) {
|
||||
if (auto *scrollArea = qobject_cast<QScrollArea *>(widget)) {
|
||||
scrollArea->ensureWidgetVisible(target);
|
||||
break;
|
||||
}
|
||||
widget = widget->parentWidget();
|
||||
if (auto *scrollArea = QtUtils::findParentOfType<QScrollArea>(target, true)) {
|
||||
scrollArea->ensureWidgetVisible(target);
|
||||
}
|
||||
flashWidget(target);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue