Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
ThemePreviewPick Class Reference

#include <theme_preview_pick.h>

Classes

struct  Layer

Public Types

enum class  Role { Text , Background , Border }
using TokenMap = QHash<ThemeManager::ThemeToken, ThemeColorPair>

Static Public Member Functions

static QColor keyColor (int key)
static Layer decode (QRgb rgb)
static TokenMap keyTokens ()
static QPalette keyPalette ()
static QFont keyFont (const QFont &font)
static QImage keyCanvas (const QSize &size)
static void paintKeyGlyph (QPainter *painter, const QString &svg_path, const QRect &rect, ThemeManager::ThemeToken token)
static Layer layerAt (const QImage &keys, const QPoint &pos, int text_height)
static QList< Layer > layersAt (const QImage &keys, const QPoint &pos, int text_height)
static QString roleName (const Layer &layer)
static void saveImage (QWidget *source, const QString &suggested_name, const std::function< void()> &dialog_closed)

Static Public Attributes

static constexpr int kLinkKey = 0x3fff

Detailed Description

Shared support for picking theme colors by clicking a Theme Designer sample.

A sample finds out which theme token painted a pixel by rendering a second, never shown copy of itself into an image ("key render"). That copy is themed with keyTokens() and keyPalette(): every token gets its own unique opaque key color, so each pixel of the key image names the token that painted it. The sample's own paint code and Qt's style sheet cascade decide the token; nothing here mirrors that logic. Fonts of the copy go through keyFont() so text is drawn without antialiasing and glyph pixels keep their exact key.

Text, background and border of one spot are told apart from the shape of the key regions around the pixel (see layerAt() and layersAt()), so a single key image is enough.

The class also holds the "Save Image As..." flow shared by the samples.

Member Enumeration Documentation

◆ Role

enum class ThemePreviewPick::Role
strong

What part of a spot a color paints.

Member Function Documentation

◆ decode()

ThemePreviewPick::Layer ThemePreviewPick::decode ( QRgb rgb)
static

The token a key image pixel names.

Returns
the layer; its token is NoRole when rgb is not a key color. The role is Text for the link key, else Background.

◆ keyCanvas()

QImage ThemePreviewPick::keyCanvas ( const QSize & size)
static

A blank, transparent image of size for a key render. It is premultiplied because CoreGraphics cannot paint native style elements into non-premultiplied ARGB images; key decoding only reads opaque pixels, which are the same in both formats.

◆ keyColor()

QColor ThemePreviewPick::keyColor ( int key)
static

The opaque key color of key.

Parameters
keya ThemeManager::ThemeToken value, or kLinkKey.

◆ keyFont()

QFont ThemePreviewPick::keyFont ( const QFont & font)
static

font with antialiasing turned off, for the key render.

◆ keyPalette()

QPalette ThemePreviewPick::keyPalette ( )
static

A palette for the key render: each role with a Palette<Role> token gets that token's key color in all groups, Link gets kLinkKey when it has no token, and every other role is opaque black (never a key).

◆ keyTokens()

ThemePreviewPick::TokenMap ThemePreviewPick::keyTokens ( )
static

Every token but NoRole, mapped to its key color on both sides.

◆ layerAt()

ThemePreviewPick::Layer ThemePreviewPick::layerAt ( const QImage & keys,
const QPoint & pos,
int text_height )
static

The color a click at pos picks: the token of the pixel, or of the nearest key pixel within 2 pixels, and whether it paints text, a border line or a background.

Parameters
keysthe key image.
posposition in keys.
text_heighttallest line height of the key fonts, in image pixels.
Returns
the layer; its token is NoRole when no key is near pos.

◆ layersAt()

QList< ThemePreviewPick::Layer > ThemePreviewPick::layersAt ( const QImage & keys,
const QPoint & pos,
int text_height )
static

All colors of the spot at pos: the picked color (layerAt()), the background under a text or line, and the border around a background.

Returns
the layers ordered Text, Background, Border, no token twice; empty when no key is near pos.

◆ paintKeyGlyph()

void ThemePreviewPick::paintKeyGlyph ( QPainter * painter,
const QString & svg_path,
const QRect & rect,
ThemeManager::ThemeToken token )
static

Paints the shape of an icon in the key color of token, without antialiasing, so every pixel of the glyph names the token.

Parameters
painterpainter of the key render.
svg_pathQt resource path of the icon.
rectwhere the icon goes.
tokenthe color the icon paints.

◆ roleName()

QString ThemePreviewPick::roleName ( const Layer & layer)
static

The translated role word: "Text", "Background", "Border" or "Link text".

◆ saveImage()

void ThemePreviewPick::saveImage ( QWidget * source,
const QString & suggested_name,
const std::function< void()> & dialog_closed )
static

Asks for a file name and saves a PNG image of source.

Parameters
sourcethe widget to grab; also the dialogs' parent.
suggested_namefile name proposed in the save dialog.
dialog_closedcalled each time a dialog of this flow closes, so the caller can restore focus or state; may be empty.

Member Data Documentation

◆ kLinkKey

int ThemePreviewPick::kLinkKey = 0x3fff
staticconstexpr

The key value QPalette::Link gets in keyPalette(). Link has no token of its own; it is derived from ThemePaletteBuilder::kLinkSourceRole.


The documentation for this class was generated from the following files: