author | sandman <sandman> | 2002-09-21 01:37:32 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-09-21 01:37:32 (UTC) |
commit | 4b0a34a494dbea653b79a945b8c59ee0be62ac75 (patch) (unidiff) | |
tree | 7b9e091423487ed7e4c590b340b84b9ad9d81f44 /noncore/settings/appearance2/colorlistitem.h | |
parent | 1a8d7cd34db3b9f443bcb956f85c41336a60e948 (diff) | |
download | opie-4b0a34a494dbea653b79a945b8c59ee0be62ac75.zip opie-4b0a34a494dbea653b79a945b8c59ee0be62ac75.tar.gz opie-4b0a34a494dbea653b79a945b8c59ee0be62ac75.tar.bz2 |
- Improved style and color preview
- color schemes can be editied now
Diffstat (limited to 'noncore/settings/appearance2/colorlistitem.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/appearance2/colorlistitem.h | 93 |
1 files changed, 89 insertions, 4 deletions
diff --git a/noncore/settings/appearance2/colorlistitem.h b/noncore/settings/appearance2/colorlistitem.h index c7318a6..1ff6ecc 100644 --- a/noncore/settings/appearance2/colorlistitem.h +++ b/noncore/settings/appearance2/colorlistitem.h | |||
@@ -1,28 +1,113 @@ | |||
1 | #ifndef COLORLISTITEM_H | 1 | #ifndef COLORLISTITEM_H |
2 | #define COLORLISTITEM_H | 2 | #define COLORLISTITEM_H |
3 | 3 | ||
4 | #include <qlistbox.h> | 4 | #include <qlistbox.h> |
5 | #include <qpalette.h> | 5 | #include <qpalette.h> |
6 | #include <qapplication.h> | ||
7 | |||
8 | #include <qpe/config.h> | ||
9 | |||
10 | class Appearance; | ||
6 | 11 | ||
7 | class ColorListItem : public QListBoxText { | 12 | class ColorListItem : public QListBoxText { |
8 | public: | 13 | public: |
9 | ColorListItem ( const QString &t, const QPalette &pal ) : QListBoxText ( t ) | 14 | ColorListItem ( const QString &t, Config &cfg ) : QListBoxText ( t ) |
10 | { | 15 | { |
11 | m_pal = pal; | 16 | m_colors = new QColor [s_colorcount]; |
17 | load ( cfg ); | ||
12 | } | 18 | } |
13 | 19 | ||
14 | virtual ~ColorListItem ( ) | 20 | virtual ~ColorListItem ( ) |
15 | { | 21 | { |
22 | delete [] m_colors; | ||
16 | } | 23 | } |
17 | 24 | ||
18 | QPalette palette ( ) | 25 | QPalette palette ( ) |
19 | { | 26 | { |
20 | return m_pal; | 27 | return m_palette; |
28 | } | ||
29 | |||
30 | bool load ( Config &cfg ) | ||
31 | { | ||
32 | for ( int i = 0; i < s_colorcount; i++ ) | ||
33 | m_colors [i] = QColor ( cfg. readEntry ( s_colorlut [i]. m_key, s_colorlut [i]. m_def )); | ||
34 | |||
35 | buildPalette ( ); | ||
36 | return true; | ||
37 | } | ||
38 | |||
39 | void buildPalette ( ) | ||
40 | { | ||
41 | m_palette = QPalette ( m_colors [r2i(QColorGroup::Button)], m_colors [r2i(QColorGroup::Background)] ); | ||
42 | m_palette. setColor ( QColorGroup::Highlight, m_colors [r2i(QColorGroup::Highlight)] ); | ||
43 | m_palette. setColor ( QColorGroup::HighlightedText, m_colors [r2i(QColorGroup::HighlightedText)] ); | ||
44 | m_palette. setColor ( QColorGroup::Text, m_colors [r2i(QColorGroup::Text)] ); | ||
45 | m_palette. setColor ( QPalette::Active, QColorGroup::ButtonText, m_colors [r2i(QColorGroup::ButtonText)] ); | ||
46 | m_palette. setColor ( QColorGroup::Base, m_colors [r2i(QColorGroup::Base)] ); | ||
47 | m_palette. setColor ( QPalette::Disabled, QColorGroup::Text, m_palette. color ( QPalette::Active, QColorGroup::Background ). dark ( )); | ||
48 | } | ||
49 | |||
50 | bool save ( Config &cfg ) | ||
51 | { | ||
52 | for ( int i = 0; i < s_colorcount; i++ ) | ||
53 | cfg. writeEntry ( s_colorlut [i]. m_key, m_colors [i]. name ( )); | ||
54 | return true; | ||
55 | } | ||
56 | |||
57 | QColor color ( QColorGroup::ColorRole role ) | ||
58 | { | ||
59 | int i = r2i ( role ); | ||
60 | return i >= 0 ? m_colors [i] : QColor ( ); | ||
61 | } | ||
62 | |||
63 | void setColor ( QColorGroup::ColorRole role, QColor c ) | ||
64 | { | ||
65 | int i = r2i ( role ); | ||
66 | if ( i >= 0 ) { | ||
67 | m_colors [i] = c; | ||
68 | buildPalette ( ); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | QString label ( QColorGroup::ColorRole role ) | ||
73 | { | ||
74 | int i = r2i ( role ); | ||
75 | return i >= 0 ? qApp-> translate ( "Appearance", s_colorlut [i]. m_label ) : QString::null; | ||
21 | } | 76 | } |
22 | 77 | ||
23 | private: | 78 | private: |
24 | QPalette m_pal; | 79 | QPalette m_palette; |
80 | QColor *m_colors; | ||
81 | |||
82 | static struct colorlut { | ||
83 | QColorGroup::ColorRole m_role; | ||
84 | const char * m_key; | ||
85 | const char * m_def; | ||
86 | const char * m_label; | ||
87 | } const s_colorlut []; | ||
88 | static const int s_colorcount; | ||
89 | |||
90 | static int r2i ( QColorGroup::ColorRole role ) | ||
91 | { | ||
92 | for ( int i = 0; i < s_colorcount; i++ ) { | ||
93 | if ( s_colorlut [i]. m_role == role ) | ||
94 | return i; | ||
95 | } | ||
96 | return -1; | ||
97 | } | ||
25 | }; | 98 | }; |
26 | 99 | ||
100 | const ColorListItem::colorlut ColorListItem::s_colorlut [] = { | ||
101 | { QColorGroup::Base, "Base", "#FFFFFF", QT_TRANSLATE_NOOP( "Appearance", "Base" ) }, | ||
102 | { QColorGroup::Background, "Background", "#E5E1D5", QT_TRANSLATE_NOOP( "Appearance", "Background" ) }, | ||
103 | { QColorGroup::Button, "Button", "#D6CDBB", QT_TRANSLATE_NOOP( "Appearance", "Button" ) }, | ||
104 | { QColorGroup::ButtonText, "ButtonText", "#000000", QT_TRANSLATE_NOOP( "Appearance", "Button Text" ) }, | ||
105 | { QColorGroup::Highlight, "Highlight", "#800000", QT_TRANSLATE_NOOP( "Appearance", "Highlight" ) }, | ||
106 | { QColorGroup::HighlightedText, "HighlightedText", "#FFFFFF", QT_TRANSLATE_NOOP( "Appearance", "Highlighted Text" ) }, | ||
107 | { QColorGroup::Text, "Text", "#000000", QT_TRANSLATE_NOOP( "Appearance", "Text" ) } | ||
108 | }; | ||
109 | |||
110 | const int ColorListItem::s_colorcount = sizeof( s_colorlut ) / sizeof ( s_colorlut [0] ); | ||
111 | |||
27 | 112 | ||
28 | #endif | 113 | #endif |