| 1 | # ----------------------------------------------------------------------------- | ||||||||||||||
| 2 | |||||||||||||||
| 3 | =encoding utf8 | ||||||||||||||
| 4 | |||||||||||||||
| 5 | =head1 NAME | ||||||||||||||
| 6 | |||||||||||||||
| 7 | Quiq::Html::Widget::SelectMenuColor - Selectmenü mit farbigen Einträgen | ||||||||||||||
| 8 | |||||||||||||||
| 9 | =head1 BASE CLASS | ||||||||||||||
| 10 | |||||||||||||||
| 11 | L<Quiq::Html::Widget::SelectMenu> | ||||||||||||||
| 12 | |||||||||||||||
| 13 | =head1 ATTRIBUTES | ||||||||||||||
| 14 | |||||||||||||||
| 15 | Siehe Basisklasse. Zusätzlich: | ||||||||||||||
| 16 | |||||||||||||||
| 17 | =over 4 | ||||||||||||||
| 18 | |||||||||||||||
| 19 | =item applyColorsTo => 'fg' | 'bg' (Default: 'fg') | ||||||||||||||
| 20 | |||||||||||||||
| 21 | Wende die Farben (siehe Attribut C<colors>) auf den Vordergrund oder | ||||||||||||||
| 22 | auf den Hintergrund an. | ||||||||||||||
| 23 | |||||||||||||||
| 24 | =item colors=> \@colors (Default: []) | ||||||||||||||
| 25 | |||||||||||||||
| 26 | Liste der Farbwerte für die Elemente der Auswahlliste. Es sind | ||||||||||||||
| 27 | alle Farbwerte (außer ($r,$g,$b)) möglich, die der Konstruktor | ||||||||||||||
| 28 | der Klasse Quiq::Color akzeptiert. | ||||||||||||||
| 29 | |||||||||||||||
| 30 | =item undefIf => $bool (Default: 0) | ||||||||||||||
| 31 | |||||||||||||||
| 32 | Wenn wahr, liefere C<undef> als Widget-Code. | ||||||||||||||
| 33 | |||||||||||||||
| 34 | =back | ||||||||||||||
| 35 | |||||||||||||||
| 36 | =head1 EXAMPLES | ||||||||||||||
| 37 | |||||||||||||||
| 38 | Erzeuge Auswahlmenü mit farbigen Texten: | ||||||||||||||
| 39 | |||||||||||||||
| 40 | $w = Quiq::Html::Widget::SelectMenuColor->new( | ||||||||||||||
| 41 | id => 'smc1', | ||||||||||||||
| 42 | name => 'smc1', | ||||||||||||||
| 43 | applyColorsTo => 'fg', | ||||||||||||||
| 44 | options => [qw/Apfel Birne Orange/], | ||||||||||||||
| 45 | colors => [qw/ff0000 006400 ff8c00/], | ||||||||||||||
| 46 | value => 'Birne', | ||||||||||||||
| 47 | ); | ||||||||||||||
| 48 | print $w->html($h); | ||||||||||||||
| 49 | |||||||||||||||
| 50 | Erzeuge Auswahlmenü mit farbigen Hintergründen: | ||||||||||||||
| 51 | |||||||||||||||
| 52 | $w = Quiq::Html::Widget::SelectMenuColor->new( | ||||||||||||||
| 53 | id => 'smc1', | ||||||||||||||
| 54 | name => 'smc1', | ||||||||||||||
| 55 | applyColorsTo => 'bg', | ||||||||||||||
| 56 | options => [qw/Apfel Birne Orange/], | ||||||||||||||
| 57 | colors => [qw/ff0000 006400 ff8c00/], | ||||||||||||||
| 58 | value => 'Birne', | ||||||||||||||
| 59 | ); | ||||||||||||||
| 60 | print $w->html($h); | ||||||||||||||
| 61 | |||||||||||||||
| 62 | =cut | ||||||||||||||
| 63 | |||||||||||||||
| 64 | # ----------------------------------------------------------------------------- | ||||||||||||||
| 65 | |||||||||||||||
| 66 | package Quiq::Html::Widget::SelectMenuColor; | ||||||||||||||
| 67 | 1 | ▶ | use base qw/Quiq::Html::Widget::SelectMenu/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 68 | |||||||||||||||
| 69 | 1 | ▶ | use v5.10; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 70 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 71 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 72 | |||||||||||||||
| 73 | 1 | our $VERSION = '1.240'; | |||||||||||||
| 74 | |||||||||||||||
| 75 | 1 | ▶ | use Quiq::Color; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 76 | 1 | ▶ | use Quiq::String; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 77 | |||||||||||||||
| 78 | # ----------------------------------------------------------------------------- | ||||||||||||||
| 79 | |||||||||||||||
| 80 | =head1 METHODS | ||||||||||||||
| 81 | |||||||||||||||
| 82 | =head2 Konstruktor | ||||||||||||||
| 83 | |||||||||||||||
| 84 | =head3 new() - Konstruktor | ||||||||||||||
| 85 | |||||||||||||||
| 86 | =head4 Synopsis | ||||||||||||||
| 87 | |||||||||||||||
| 88 | $e = $class->new(@keyVal); | ||||||||||||||
| 89 | |||||||||||||||
| 90 | =cut | ||||||||||||||
| 91 | |||||||||||||||
| 92 | # ----------------------------------------------------------------------------- | ||||||||||||||
| 93 | |||||||||||||||
| 94 | 0 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 95 | 0 | my $class = shift; | |||||||||||||
| 96 | # @_: @keyVal | ||||||||||||||
| 97 | |||||||||||||||
| 98 | # Defaultwerte | ||||||||||||||
| 99 | |||||||||||||||
| 100 | 0 | my $self = $class->SUPER::new; | |||||||||||||
| 101 | 0 | $self->add( | |||||||||||||
| 102 | applyColorsTo => 'fg', # 'bg' -or- 'fg' | ||||||||||||||
| 103 | colors => [], | ||||||||||||||
| 104 | undefIf => 0, | ||||||||||||||
| 105 | ); | ||||||||||||||
| 106 | |||||||||||||||
| 107 | # Werte Konstruktoraufruf | ||||||||||||||
| 108 | 0 | $self->set(@_); | |||||||||||||
| 109 | |||||||||||||||
| 110 | 0 | return $self; | |||||||||||||
| 111 | } | ||||||||||||||
| 112 | |||||||||||||||
| 113 | # ----------------------------------------------------------------------------- | ||||||||||||||
| 114 | |||||||||||||||
| 115 | =head2 Objektmethoden | ||||||||||||||
| 116 | |||||||||||||||
| 117 | =head3 html() - Generiere HTML-Code | ||||||||||||||
| 118 | |||||||||||||||
| 119 | =head4 Synopsis | ||||||||||||||
| 120 | |||||||||||||||
| 121 | $html = $e->html($h); | ||||||||||||||
| 122 | $html = $class->html($h,@keyVal); | ||||||||||||||
| 123 | |||||||||||||||
| 124 | =cut | ||||||||||||||
| 125 | |||||||||||||||
| 126 | # ----------------------------------------------------------------------------- | ||||||||||||||
| 127 | |||||||||||||||
| 128 | 0 | ▶ | sub html { | ||||||||||||
|
Subroutine
html: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||
| 129 | 0 | my $this = shift; | |||||||||||||
| 130 | 0 | my $h = shift; | |||||||||||||
| 131 | # @_: @keyVal | ||||||||||||||
| 132 | |||||||||||||||
| 133 | 0 | ▶ | my $self = ref $this? $this: $this->new(@_); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 134 | |||||||||||||||
| 135 | # Attribute | ||||||||||||||
| 136 | |||||||||||||||
| 137 | 0 | my ($applyColorsTo,$colors,$id,$javaScript,$onChange,$styles,$undefIf) = | |||||||||||||
| 138 | $self->get(qw/applyColorsTo colors id javaScript onChange styles | ||||||||||||||
| 139 | undeiF/); | ||||||||||||||
| 140 | |||||||||||||||
| 141 | # Generierung | ||||||||||||||
| 142 | |||||||||||||||
| 143 | 0 | ▶ | if ($undefIf) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 144 | 0 | return undef; | |||||||||||||
| 145 | } | ||||||||||||||
| 146 | |||||||||||||||
| 147 | 0 | ▶ | for (my $i = 0; $i < @$colors; $i++) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 148 | 0 | ▶ | my $color = $colors->[$i] || next; | ||||||||||||
|
Condition0%0/2
$colors->[$i] || (next)
MC/DC0%0/1
$colors->[$i] || (next)
$colors->[$i]
Truth table0%0/2
A
A= $colors->[$i]
| |||||||||||||||
| 149 | 0 | my $col = Quiq::Color->new($color); | |||||||||||||
| 150 | 0 | my $rgb = $col->hexString; | |||||||||||||
| 151 | |||||||||||||||
| 152 | 0 | ▶ | if ($styles->[$i]) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 153 | 0 | $styles->[$i] .= ';'; | |||||||||||||
| 154 | } | ||||||||||||||
| 155 | 0 | ▶ | if ($applyColorsTo eq 'fg') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 156 | 0 | $styles->[$i] .= "color: #$rgb"; | |||||||||||||
| 157 | } | ||||||||||||||
| 158 | elsif ($applyColorsTo eq 'bg') { | ||||||||||||||
| 159 | 0 | ▶ | my $fgColor = $col->brightness < 128? 'white': 'black'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 160 | 0 | $styles->[$i] .= "background: #$rgb; color: $fgColor"; | |||||||||||||
| 161 | } | ||||||||||||||
| 162 | else { | ||||||||||||||
| 163 | 0 | $self->throw; | |||||||||||||
| 164 | } | ||||||||||||||
| 165 | } | ||||||||||||||
| 166 | |||||||||||||||
| 167 | 0 | ▶ | if (!$id) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 168 | 0 | $self->throw; | |||||||||||||
| 169 | } | ||||||||||||||
| 170 | 0 | ▶ | if ($javaScript) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 171 | 0 | $javaScript .= ";\n\n"; | |||||||||||||
| 172 | } | ||||||||||||||
| 173 | 0 | $javaScript .= Quiq::String->removeIndentation(<<" __JS__"); | |||||||||||||
| 174 | var e = document.getElementById('$id'); | ||||||||||||||
| 175 | e.setColors = function () { | ||||||||||||||
| 176 | var i = this.selectedIndex; | ||||||||||||||
| 177 | this.style.background = this.options[i].style.background; | ||||||||||||||
| 178 | this.style.color = this.options[i].style.color; | ||||||||||||||
| 179 | } | ||||||||||||||
| 180 | e.setColors(); | ||||||||||||||
| 181 | __JS__ | ||||||||||||||
| 182 | 0 | $self->set(javaScript=>$javaScript); | |||||||||||||
| 183 | |||||||||||||||
| 184 | 0 | ▶ | if ($onChange) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 185 | 0 | $onChange .= '; '; | |||||||||||||
| 186 | } | ||||||||||||||
| 187 | 0 | $onChange .= 'this.setColors()'; | |||||||||||||
| 188 | 0 | $self->set(onChange=>$onChange); | |||||||||||||
| 189 | |||||||||||||||
| 190 | 0 | return $self->SUPER::html($h); | |||||||||||||
| 191 | } | ||||||||||||||
| 192 | |||||||||||||||
| 193 | # ----------------------------------------------------------------------------- | ||||||||||||||
| 194 | |||||||||||||||
| 195 | =head1 VERSION | ||||||||||||||
| 196 | |||||||||||||||
| 197 | 1.240 | ||||||||||||||
| 198 | |||||||||||||||
| 199 | =head1 AUTHOR | ||||||||||||||
| 200 | |||||||||||||||
| 201 | Frank Seitz, L<http://fseitz.de/> | ||||||||||||||
| 202 | |||||||||||||||
| 203 | =head1 COPYRIGHT | ||||||||||||||
| 204 | |||||||||||||||
| 205 | Copyright (C) 2026 Frank Seitz | ||||||||||||||
| 206 | |||||||||||||||
| 207 | =head1 LICENSE | ||||||||||||||
| 208 | |||||||||||||||
| 209 | This code is free software; you can redistribute it and/or modify | ||||||||||||||
| 210 | it under the same terms as Perl itself. | ||||||||||||||
| 211 | |||||||||||||||
| 212 | =cut | ||||||||||||||
| 213 | |||||||||||||||
| 214 | # ----------------------------------------------------------------------------- | ||||||||||||||
| 215 | |||||||||||||||
| 216 | 1 | 1; | |||||||||||||
| 217 | |||||||||||||||
| 218 | # eof | ||||||||||||||