mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 02:53:25 -08:00
[Client] Flat moderation headers and detail tab shape
This commit is contained in:
parent
2b4019ccaf
commit
e8ebadf0bd
7 changed files with 180 additions and 0 deletions
|
|
@ -387,6 +387,8 @@ set(cockatrice_SOURCES
|
||||||
src/interface/widgets/tabs/api/edhrec/tab_edhrec.cpp
|
src/interface/widgets/tabs/api/edhrec/tab_edhrec.cpp
|
||||||
src/interface/widgets/tabs/api/edhrec/tab_edhrec_main.cpp
|
src/interface/widgets/tabs/api/edhrec/tab_edhrec_main.cpp
|
||||||
src/interface/widgets/tabs/alt_table_delegate.cpp
|
src/interface/widgets/tabs/alt_table_delegate.cpp
|
||||||
|
src/interface/widgets/tabs/moderation_header_style.cpp
|
||||||
|
src/interface/widgets/tabs/moderation_tab_style.cpp
|
||||||
src/interface/widgets/tabs/report_status_delegate.cpp
|
src/interface/widgets/tabs/report_status_delegate.cpp
|
||||||
src/interface/widgets/tabs/tab.cpp
|
src/interface/widgets/tabs/tab.cpp
|
||||||
src/interface/widgets/tabs/tab_account.cpp
|
src/interface/widgets/tabs/tab_account.cpp
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
#include "moderation_header_style.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPalette>
|
||||||
|
#include <QStyleOption>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
constexpr qreal HOVER_WASH_ALPHA = 0.12;
|
||||||
|
constexpr int SORT_ARROW_GAP = 4;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
ModerationHeaderStyle::ModerationHeaderStyle(QStyle *base) : QProxyStyle(base)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModerationHeaderStyle::drawControl(ControlElement element,
|
||||||
|
const QStyleOption *option,
|
||||||
|
QPainter *painter,
|
||||||
|
const QWidget *widget) const
|
||||||
|
{
|
||||||
|
if (element != CE_Header || option == nullptr || painter == nullptr) {
|
||||||
|
QProxyStyle::drawControl(element, option, painter, widget);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto *headerOpt = qstyleoption_cast<const QStyleOptionHeader *>(option);
|
||||||
|
if (headerOpt == nullptr || !headerOpt->icon.isNull()) {
|
||||||
|
QProxyStyle::drawControl(element, option, painter, widget);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
painter->save();
|
||||||
|
painter->fillRect(headerOpt->rect, headerOpt->palette.window());
|
||||||
|
|
||||||
|
const bool enabled = (headerOpt->state & State_Enabled) != 0;
|
||||||
|
if (enabled && (headerOpt->state & State_MouseOver) != 0) {
|
||||||
|
QColor wash = headerOpt->palette.color(QPalette::Highlight);
|
||||||
|
wash.setAlphaF(HOVER_WASH_ALPHA);
|
||||||
|
painter->fillRect(headerOpt->rect, wash);
|
||||||
|
}
|
||||||
|
|
||||||
|
painter->setPen(headerOpt->palette.color(QPalette::Mid));
|
||||||
|
painter->drawLine(headerOpt->rect.bottomLeft(), headerOpt->rect.bottomRight());
|
||||||
|
painter->restore();
|
||||||
|
|
||||||
|
QRect textRect = headerOpt->rect.adjusted(4, 0, -4, 0);
|
||||||
|
|
||||||
|
const bool hasSortIndicator = headerOpt->sortIndicator != QStyleOptionHeader::None;
|
||||||
|
QStyleOptionHeader arrowOpt;
|
||||||
|
if (hasSortIndicator) {
|
||||||
|
arrowOpt = *headerOpt;
|
||||||
|
arrowOpt.rect = proxy()->subElementRect(SE_HeaderArrow, headerOpt, widget);
|
||||||
|
textRect.setRight(qMin(textRect.right(), arrowOpt.rect.left() - SORT_ARROW_GAP));
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString elided = headerOpt->fontMetrics.elidedText(headerOpt->text, Qt::ElideRight, textRect.width());
|
||||||
|
QStyle *style = widget != nullptr ? widget->style() : QApplication::style();
|
||||||
|
style->drawItemText(painter, textRect, headerOpt->textAlignment, headerOpt->palette, enabled, elided,
|
||||||
|
QPalette::WindowText);
|
||||||
|
|
||||||
|
if (hasSortIndicator) {
|
||||||
|
proxy()->drawPrimitive(PE_IndicatorHeaderArrow, &arrowOpt, painter, widget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef MODERATION_HEADER_STYLE_H
|
||||||
|
#define MODERATION_HEADER_STYLE_H
|
||||||
|
|
||||||
|
#include <QProxyStyle>
|
||||||
|
#include <qtmetamacros.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flat header sections for the moderation tables (report queue, user alts).
|
||||||
|
* Replaces the native gradient header with the palette Window background, a
|
||||||
|
* 1px Mid bottom rule, and WindowText labels, so headers follow the active
|
||||||
|
* theme. Sort indicators are still drawn by the base style. Headers with
|
||||||
|
* icons fall back to the base style untouched.
|
||||||
|
*/
|
||||||
|
class ModerationHeaderStyle : public QProxyStyle
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ModerationHeaderStyle(QStyle *base = nullptr);
|
||||||
|
void drawControl(ControlElement element,
|
||||||
|
const QStyleOption *option,
|
||||||
|
QPainter *painter,
|
||||||
|
const QWidget *widget = nullptr) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MODERATION_HEADER_STYLE_H
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
#include "moderation_tab_style.h"
|
||||||
|
|
||||||
|
#include <QPalette>
|
||||||
|
#include <QStyleOption>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
constexpr int UNDERLINE_HEIGHT = 2;
|
||||||
|
constexpr qreal HOVER_WASH_ALPHA = 0.08;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
ModerationTabStyle::ModerationTabStyle(QStyle *base) : QProxyStyle(base)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModerationTabStyle::drawControl(ControlElement element,
|
||||||
|
const QStyleOption *option,
|
||||||
|
QPainter *painter,
|
||||||
|
const QWidget *widget) const
|
||||||
|
{
|
||||||
|
if (element != CE_TabBarTabShape || option == nullptr || painter == nullptr) {
|
||||||
|
QProxyStyle::drawControl(element, option, painter, widget);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto *tabOpt = qstyleoption_cast<const QStyleOptionTab *>(option);
|
||||||
|
if (tabOpt == nullptr) {
|
||||||
|
QProxyStyle::drawControl(element, option, painter, widget);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
painter->save();
|
||||||
|
painter->fillRect(tabOpt->rect, tabOpt->palette.window());
|
||||||
|
|
||||||
|
const bool enabled = (tabOpt->state & State_Enabled) != 0;
|
||||||
|
if ((tabOpt->state & State_Selected) != 0) {
|
||||||
|
const QRect underline(tabOpt->rect.left(), tabOpt->rect.bottom() - UNDERLINE_HEIGHT + 1, tabOpt->rect.width(),
|
||||||
|
UNDERLINE_HEIGHT);
|
||||||
|
painter->fillRect(underline, tabOpt->palette.color(QPalette::Highlight));
|
||||||
|
} else if (enabled && (tabOpt->state & State_MouseOver) != 0) {
|
||||||
|
QColor wash = tabOpt->palette.color(QPalette::Highlight);
|
||||||
|
wash.setAlphaF(HOVER_WASH_ALPHA);
|
||||||
|
painter->fillRect(tabOpt->rect, wash);
|
||||||
|
}
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
25
cockatrice/src/interface/widgets/tabs/moderation_tab_style.h
Normal file
25
cockatrice/src/interface/widgets/tabs/moderation_tab_style.h
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef MODERATION_TAB_STYLE_H
|
||||||
|
#define MODERATION_TAB_STYLE_H
|
||||||
|
|
||||||
|
#include <QProxyStyle>
|
||||||
|
#include <qtmetamacros.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flat tab shapes for the moderation detail tabs (report queue detailTabs).
|
||||||
|
* Replaces the native tab frame with the palette Window background plus a
|
||||||
|
* 2px Highlight underline on the selected tab and a faint Highlight wash on
|
||||||
|
* hover. Labels (text, elide, focus) are left to the base style, so keyboard
|
||||||
|
* focus stays distinguishable.
|
||||||
|
*/
|
||||||
|
class ModerationTabStyle : public QProxyStyle
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ModerationTabStyle(QStyle *base = nullptr);
|
||||||
|
void drawControl(ControlElement element,
|
||||||
|
const QStyleOption *option,
|
||||||
|
QPainter *painter,
|
||||||
|
const QWidget *widget = nullptr) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MODERATION_TAB_STYLE_H
|
||||||
|
|
@ -6,8 +6,10 @@
|
||||||
#include "alt_table_delegate.h"
|
#include "alt_table_delegate.h"
|
||||||
#include "libcockatrice/protocol/pb/response.pb.h"
|
#include "libcockatrice/protocol/pb/response.pb.h"
|
||||||
#include "libcockatrice/protocol/pb/response_user_alts.pb.h"
|
#include "libcockatrice/protocol/pb/response_user_alts.pb.h"
|
||||||
|
#include "moderation_header_style.h"
|
||||||
|
|
||||||
#include <QAbstractItemView>
|
#include <QAbstractItemView>
|
||||||
|
#include <QApplication>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
|
|
@ -21,6 +23,7 @@
|
||||||
#include <QSignalBlocker>
|
#include <QSignalBlocker>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
|
#include <QStyleFactory>
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
#include <QTableWidgetItem>
|
#include <QTableWidgetItem>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
|
|
@ -78,6 +81,9 @@ void configureAltTable(QTableWidget *table)
|
||||||
table->setAlternatingRowColors(true);
|
table->setAlternatingRowColors(true);
|
||||||
table->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
table->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||||
table->horizontalHeader()->setStretchLastSection(true);
|
table->horizontalHeader()->setStretchLastSection(true);
|
||||||
|
auto *headerStyle = new ModerationHeaderStyle(QStyleFactory::create(QApplication::style()->objectName()));
|
||||||
|
headerStyle->setParent(table->horizontalHeader());
|
||||||
|
table->horizontalHeader()->setStyle(headerStyle);
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,13 @@
|
||||||
#include "../utility/report_utils.h"
|
#include "../utility/report_utils.h"
|
||||||
#include "abstract_client.h"
|
#include "abstract_client.h"
|
||||||
#include "libcockatrice/protocol/pb/response.pb.h"
|
#include "libcockatrice/protocol/pb/response.pb.h"
|
||||||
|
#include "moderation_header_style.h"
|
||||||
|
#include "moderation_tab_style.h"
|
||||||
#include "report_status_delegate.h"
|
#include "report_status_delegate.h"
|
||||||
#include "tab_supervisor.h"
|
#include "tab_supervisor.h"
|
||||||
|
|
||||||
#include <QAbstractItemView>
|
#include <QAbstractItemView>
|
||||||
|
#include <QApplication>
|
||||||
#include <QChar>
|
#include <QChar>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
|
|
@ -25,6 +28,7 @@
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QSignalBlocker>
|
#include <QSignalBlocker>
|
||||||
|
#include <QStyleFactory>
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
#include <QTableWidgetItem>
|
#include <QTableWidgetItem>
|
||||||
|
|
@ -124,6 +128,9 @@ TabReport::TabReport(TabSupervisor *_tabSupervisor, AbstractClient *_client) : T
|
||||||
table->horizontalHeader()->setSectionResizeMode(COL_TIME, QHeaderView::ResizeToContents);
|
table->horizontalHeader()->setSectionResizeMode(COL_TIME, QHeaderView::ResizeToContents);
|
||||||
table->horizontalHeader()->setSectionResizeMode(COL_REPORTED, QHeaderView::Stretch);
|
table->horizontalHeader()->setSectionResizeMode(COL_REPORTED, QHeaderView::Stretch);
|
||||||
table->horizontalHeader()->setSectionResizeMode(COL_REPORTER, QHeaderView::ResizeToContents);
|
table->horizontalHeader()->setSectionResizeMode(COL_REPORTER, QHeaderView::ResizeToContents);
|
||||||
|
auto *headerStyle = new ModerationHeaderStyle(QStyleFactory::create(QApplication::style()->objectName()));
|
||||||
|
headerStyle->setParent(table->horizontalHeader());
|
||||||
|
table->horizontalHeader()->setStyle(headerStyle);
|
||||||
connect(table, &QTableWidget::itemSelectionChanged, this, &TabReport::onSelectionChanged);
|
connect(table, &QTableWidget::itemSelectionChanged, this, &TabReport::onSelectionChanged);
|
||||||
table->setContextMenuPolicy(Qt::CustomContextMenu);
|
table->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(table, &QTableWidget::customContextMenuRequested, this, &TabReport::showTableContextMenu);
|
connect(table, &QTableWidget::customContextMenuRequested, this, &TabReport::showTableContextMenu);
|
||||||
|
|
@ -241,6 +248,9 @@ TabReport::TabReport(TabSupervisor *_tabSupervisor, AbstractClient *_client) : T
|
||||||
});
|
});
|
||||||
|
|
||||||
detailTabs = new QTabWidget;
|
detailTabs = new QTabWidget;
|
||||||
|
auto *tabStyle = new ModerationTabStyle(QStyleFactory::create(QApplication::style()->objectName()));
|
||||||
|
tabStyle->setParent(detailTabs->tabBar());
|
||||||
|
detailTabs->tabBar()->setStyle(tabStyle);
|
||||||
detailTabs->addTab(descPage, QString());
|
detailTabs->addTab(descPage, QString());
|
||||||
detailTabs->addTab(chatPage, QString());
|
detailTabs->addTab(chatPage, QString());
|
||||||
detailTabs->addTab(commentsPage, QString());
|
detailTabs->addTab(commentsPage, QString());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue