Skip to content

Commit

Permalink
feat: styleHint tweak
Browse files Browse the repository at this point in the history
SH_UnderlineShortcut
Whether shortcuts are underlined.

SH_Menu_KeyboardSearch
Whether disable the typing to search for menu items
  • Loading branch information
kegechen committed Oct 25, 2023
1 parent a694fae commit 61e33a1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
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 @@ class DStyle : public QCommonStyle
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);
static bool isMenuKeyboardSearchDisabled();

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

0 comments on commit 61e33a1

Please sign in to comment.