Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: styleHint tweak #530

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/widgets/dstyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@
static void setFrameRadius(QWidget *widget, int radius);
static void setUncheckedItemIndicatorVisible(QWidget *widget, bool visible);
static void setRedPointVisible(QObject *object, bool visible);

static void setShortcutUnderlineVisible(bool visible);
static bool shortcutUnderlineVisible();
static void setMenuKeyboardSearchDisabled(bool disabled);

Check warning on line 235 in include/widgets/dstyle.h

View workflow job for this annotation

GitHub Actions / check_job / DOXYGEN_CHECK

function void DStyle::setMenuKeyboardSearchDisabled is not documented!
static bool isMenuKeyboardSearchDisabled();

Check warning on line 236 in include/widgets/dstyle.h

View workflow job for this annotation

GitHub Actions / check_job / DOXYGEN_CHECK

function bool DStyle::isMenuKeyboardSearchDisabled is not documented!

DStyle();

static void drawPrimitive(const QStyle *style, DStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w = nullptr);
Expand Down
61 changes: 59 additions & 2 deletions src/widgets/dstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <DGuiApplicationHelper>
#include <DIconTheme>
#include <DConfig>

#include <QStyleOption>
#include <QTextLayout>
Expand All @@ -33,6 +34,7 @@ QT_BEGIN_NAMESPACE
extern Q_WIDGETS_EXPORT void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0);
QT_END_NAMESPACE

DCORE_USE_NAMESPACE
DGUI_USE_NAMESPACE
DWIDGET_BEGIN_NAMESPACE

Expand Down Expand Up @@ -169,6 +171,57 @@ void DStyle::setRedPointVisible(QObject *object, bool visible)
object->setProperty("_d_menu_item_redpoint", visible);
}

void DStyle::setShortcutUnderlineVisible(bool visible)
{
qApp->setProperty("_d_menu_underlineshortcut", visible);
}

static inline bool hasConfig(const QString &key, bool fallback = false)
{
DConfig config("org.deepin.dtk.preference");
return config.value(key, fallback).toBool();
}

static inline bool hasProperty(const char *key, std::function<bool()> fallback)
{
const QVariant &prop = qApp->property(key);
if (prop.isValid())
return prop.toBool();

return fallback();
}

static inline bool hasEnv(const char *key, std::function<bool()> fallback)
{
if (qEnvironmentVariableIsSet(key))
return true;

return fallback();
}

bool DStyle::shortcutUnderlineVisible()
{
return hasEnv("D_MENU_UNDERLINESHORTCUT", []()->bool {
return hasProperty("_d_menu_underlineshortcut", []()->bool {
return hasConfig("underlineShortcut");
});
});
}

void DStyle::setMenuKeyboardSearchDisabled(bool disabled)
{
qApp->setProperty("_d_menu_keyboardsearch_disabled", disabled);
}

bool DStyle::isMenuKeyboardSearchDisabled()
{
return hasEnv("D_MENU_DISABLE_KEYBOARDSEARCH", []()->bool {
return hasProperty("_d_menu_keyboardsearch_disabled", []()->bool {
return hasConfig("keyboardsearchDisabled");
});
});
}

namespace DDrawUtils {
static QImage dropShadow(const QPixmap &px, qreal radius, const QColor &color)
{
Expand Down Expand Up @@ -1922,9 +1975,14 @@ case static_cast<uint32_t>(SP_##Value): { \
int DStyle::styleHint(QStyle::StyleHint sh, const QStyleOption *opt, const QWidget *w, QStyleHintReturn *shret) const
{
switch (sh) {
case SH_UnderlineShortcut: {
return shortcutUnderlineVisible();
}
case SH_Menu_KeyboardSearch: {
return !isMenuKeyboardSearchDisabled();
}
case SH_ScrollBar_MiddleClickAbsolutePosition:
case SH_FontDialog_SelectAssociatedText:
case SH_Menu_KeyboardSearch:
case SH_Menu_Scrollable:
case SH_Menu_SloppySubMenus:
case SH_ComboBox_ListMouseTracking:
Expand All @@ -1947,7 +2005,6 @@ int DStyle::styleHint(QStyle::StyleHint sh, const QStyleOption *opt, const QWidg
case SH_Slider_SnapToValue:
case SH_Menu_AllowActiveAndDisabled:
case SH_BlinkCursorWhenTextSelected:
case SH_UnderlineShortcut:
case SH_ItemView_PaintAlternatingRowColorsForEmptyArea:
case SH_ComboBox_AllowWheelScrolling:
return false;
Expand Down